From 2fb5214222caec7611bf931b18c802d615f04434 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Mon, 19 Jan 2026 22:58:31 +0100 Subject: [PATCH] fix: Don't allow private windows to sync new tabs, b=closes #11949, c=no-component --- prefs/zen/session-store.yaml | 6 -- .../sessionstore/SessionSaver-sys-mjs.patch | 23 +----- .../sessionstore/SessionStore-sys-mjs.patch | 70 +++++++++---------- src/zen/sessionstore/ZenWindowSync.sys.mjs | 2 +- 4 files changed, 37 insertions(+), 64 deletions(-) diff --git a/prefs/zen/session-store.yaml b/prefs/zen/session-store.yaml index dc04e27b1..6f6911592 100644 --- a/prefs/zen/session-store.yaml +++ b/prefs/zen/session-store.yaml @@ -10,9 +10,3 @@ - name: zen.session-store.restore-unsynced-windows value: true - -- name: zen.session-store.reduce-sessionstore-write-size - value: true - -- name: zen.session-store.allow-restoring-closed-synced-windows - value: false diff --git a/src/browser/components/sessionstore/SessionSaver-sys-mjs.patch b/src/browser/components/sessionstore/SessionSaver-sys-mjs.patch index d01944035..48e7e2c9b 100644 --- a/src/browser/components/sessionstore/SessionSaver-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionSaver-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionSaver.sys.mjs b/browser/components/sessionstore/SessionSaver.sys.mjs -index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..a4ce5de45f13eaa22803083eccb4e48a054fee39 100644 +index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..6906fd9be7ae6ca4316133e0d6552b797c54a7ec 100644 --- a/browser/components/sessionstore/SessionSaver.sys.mjs +++ b/browser/components/sessionstore/SessionSaver.sys.mjs @@ -20,6 +20,7 @@ ChromeUtils.defineESModuleGetters(lazy, { @@ -27,24 +27,3 @@ index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..a4ce5de45f13eaa22803083eccb4e48a return this._writeState(state); }, -@@ -372,7 +374,19 @@ var SessionSaverInternal = { - // Write (atomically) to a session file, using a tmp file. Once the session - // file is successfully updated, save the time stamp of the last save and - // notify the observers. -- return lazy.SessionFile.write(state).then( -+ let stateToWrite = Cu.cloneInto(state, {}); -+ if (Services.prefs.getBoolPref("zen.session-store.reduce-sessionstore-write-size", true)) { -+ for (let i = 0; i < stateToWrite.windows.length; i++) { -+ let win = stateToWrite.windows[i]; -+ if (win.isPopup || win.isTaskbarTab || win.isZenUnsynced) { -+ continue; -+ } -+ win.tabs = []; -+ win.folders = []; -+ win.groups = []; -+ } -+ } -+ return lazy.SessionFile.write(stateToWrite).then( - () => { - this.updateLastSaveTime(); - if (!lazy.RunState.isRunning) { diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index d236e3c27..3bbdca913 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254fd98c027 100644 +index 2a055f0c5f34f0a2667f659185120c07d38f4e41..1562a49c47f934b3f4372ce8ca74d5c0559b8ae7 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -127,6 +127,9 @@ const TAB_EVENTS = [ @@ -95,34 +95,34 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 TAB_EVENTS.forEach(function (aEvent) { tabbrowser.tabContainer.removeEventListener(aEvent, this, true); -@@ -2477,7 +2495,10 @@ var SessionStoreInternal = { +@@ -2491,7 +2509,7 @@ var SessionStoreInternal = { + // 2) Flush the window. + // 3) When the flush is complete, revisit our decision to store the window + // in _closedWindows, and add/remove as necessary. +- if (!winData.isPrivate && !winData.isTaskbarTab) { ++ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) { + this.maybeSaveClosedWindow(winData, isLastWindow); + } - // This window has the potential to be saved in the _closedWindows - // array (maybeSaveClosedWindows gets the final call on that). -+ if (!Services.prefs.getBoolPref("zen.session-store.allow-restoring-closed-synced-windows", false) -+ && (winData.isTaskbarTab || winData.isPrivate || winData.isZenUnsynced)) { - this._saveableClosedWindowData.add(winData); -+ } - - // Now we have to figure out if this window is worth saving in the _closedWindows - // Object. -@@ -2512,6 +2533,7 @@ var SessionStoreInternal = { +@@ -2512,7 +2530,8 @@ var SessionStoreInternal = { // Save non-private windows if they have at // least one saveable tab or are the last window. +- if (!winData.isPrivate && !winData.isTaskbarTab) { + lazy.ZenWindowSync.on_WindowCloseAndBrowserFlushed(browsers); - if (!winData.isPrivate && !winData.isTaskbarTab) { ++ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) { this.maybeSaveClosedWindow(winData, isLastWindow); -@@ -2590,6 +2612,7 @@ var SessionStoreInternal = { - * a window flush). - */ - maybeSaveClosedWindow(winData, isLastWindow) { -+ lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastWindow); - // Make sure SessionStore is still running, and make sure that we - // haven't chosen to forget this window. - if ( -@@ -3408,7 +3431,7 @@ var SessionStoreInternal = { + if (!isLastWindow && winData.closedId > -1) { +@@ -2608,6 +2627,7 @@ var SessionStoreInternal = { + let alreadyStored = winIndex != -1; + // If sidebar command is truthy, i.e. sidebar is open, store sidebar settings + let shouldStore = hasSaveableTabs || isLastWindow; ++ lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastWindow); + + if (shouldStore && !alreadyStored) { + let index = this._closedWindows.findIndex(win => { +@@ -3408,7 +3428,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -131,7 +131,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 return; } -@@ -4129,6 +4152,12 @@ var SessionStoreInternal = { +@@ -4129,6 +4149,12 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -144,7 +144,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4565,6 +4594,8 @@ var SessionStoreInternal = { +@@ -4565,6 +4591,8 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -153,7 +153,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5414,7 +5445,7 @@ var SessionStoreInternal = { +@@ -5414,7 +5442,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -162,7 +162,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 removableTabs.push(tab); } } -@@ -5525,7 +5556,7 @@ var SessionStoreInternal = { +@@ -5525,7 +5553,7 @@ var SessionStoreInternal = { // collect the data for all windows for (ix in this._windows) { @@ -171,7 +171,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 // window data is still in _statesToRestore continue; } -@@ -5668,11 +5699,12 @@ var SessionStoreInternal = { +@@ -5668,11 +5696,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -185,7 +185,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5683,6 +5715,9 @@ var SessionStoreInternal = { +@@ -5683,6 +5712,9 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -195,7 +195,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5695,7 +5730,7 @@ var SessionStoreInternal = { +@@ -5695,7 +5727,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -204,7 +204,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5810,8 +5845,8 @@ var SessionStoreInternal = { +@@ -5810,8 +5842,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -215,7 +215,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5833,6 +5868,7 @@ var SessionStoreInternal = { +@@ -5833,6 +5865,7 @@ var SessionStoreInternal = { if (overwriteTabs) { for (let i = tabbrowser.browsers.length - 1; i >= 0; i--) { if (!tabbrowser.tabs[i].selected) { @@ -223,7 +223,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 tabbrowser.removeTab(tabbrowser.tabs[i]); } } -@@ -5866,6 +5902,12 @@ var SessionStoreInternal = { +@@ -5866,6 +5899,12 @@ var SessionStoreInternal = { savedTabGroup => !openTabGroupIdsInWindow.has(savedTabGroup.id) ); } @@ -236,7 +236,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 // Move the originally open tabs to the end. if (initialTabs) { -@@ -6419,6 +6461,25 @@ var SessionStoreInternal = { +@@ -6419,6 +6458,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -262,7 +262,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7343,7 +7404,7 @@ var SessionStoreInternal = { +@@ -7343,7 +7401,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { @@ -271,7 +271,7 @@ index 2a055f0c5f34f0a2667f659185120c07d38f4e41..ccdc2f2c9c8384d696e0bb32ddbbe254 // Adjust window.selected if (tIndex + 1 < window.selected) { window.selected -= 1; -@@ -7358,7 +7419,7 @@ var SessionStoreInternal = { +@@ -7358,7 +7416,7 @@ var SessionStoreInternal = { ); // We don't want to increment tIndex here. continue; diff --git a/src/zen/sessionstore/ZenWindowSync.sys.mjs b/src/zen/sessionstore/ZenWindowSync.sys.mjs index 5b98bf477..7497b89cd 100644 --- a/src/zen/sessionstore/ZenWindowSync.sys.mjs +++ b/src/zen/sessionstore/ZenWindowSync.sys.mjs @@ -1012,7 +1012,7 @@ class nsZenWindowSync { on_TabOpen(aEvent) { const tab = aEvent.target; const window = tab.ownerGlobal; - const isUnsyncedWindow = window.document.documentElement.hasAttribute("zen-unsynced-window"); + const isUnsyncedWindow = window.gZenWorkspaces.privateWindowOrDisabled; if (tab.id) { // This tab was opened as part of a sync operation.