From 2c0e4a9b913a9f68e8465f989301cfd340a078de Mon Sep 17 00:00:00 2001 From: Ryosuke Asano Date: Tue, 7 Nov 2023 22:12:14 +0900 Subject: [PATCH] [FB] PWA | Refactoring --- .../sessionstore/SessionSaver.sys.mjs | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/browser/components/sessionstore/SessionSaver.sys.mjs b/browser/components/sessionstore/SessionSaver.sys.mjs index fe778a6c9947f..1fca50869786f 100644 --- a/browser/components/sessionstore/SessionSaver.sys.mjs +++ b/browser/components/sessionstore/SessionSaver.sys.mjs @@ -250,37 +250,36 @@ var SessionSaverInternal = { } stopWatchStart("COLLECT_DATA_MS"); - let state = lazy.SessionStore.getCurrentState(forceUpdateAllWindows); - let windows = state.windows; - for (let window of windows) { - for (let tab of window.tabs) { - let ssbEnabled = tab.floorpSSB == "true"; - if (ssbEnabled && windows.length == 1){ - this.updateLastSaveTime(); - return Promise.resolve(); - } else if (ssbEnabled) { - // Remove Window - delete state.windows[window]; - } - } + // Floorp Injections + let state = lazy.SessionStore.getCurrentState(forceUpdateAllWindows); + + function shouldUpdateLastSaveTime(ssbEnabled, windows) { + return ssbEnabled && windows.length === 1; } - - for (let windowKey in state.windows) { - let window = state.windows[windowKey]; + + function shouldRemoveWindow(ssbEnabled) { + return ssbEnabled; + } + + function removeWindowFromState(windowKey) { + delete state.windows[windowKey]; + delete state._closedWindows[windowKey]; + delete state.windows.empty_slot; + } + + for (let window of state.windows) { for (let tab of window.tabs) { - let ssbEnabled = tab.floorpSSB == "true"; - if (ssbEnabled && Object.keys(state.windows).length == 1){ + let ssbEnabled = tab.floorpSSB === "true"; + if (shouldUpdateLastSaveTime(ssbEnabled, state.windows)) { this.updateLastSaveTime(); return Promise.resolve(); - } else if (ssbEnabled) { - // Remove Window - delete state.windows[windowKey]; - delete state._closedWindows[windowKey]; + } else if (shouldRemoveWindow(ssbEnabled)) { + removeWindowFromState(window.key); } } } - + lazy.PrivacyFilter.filterPrivateWindowsAndTabs(state); // Make sure we only write worth saving tabs to disk.