mirror of
https://github.com/zen-browser/desktop.git
synced 2026-09-18 18:54:43 +00:00
402 lines
16 KiB
C++
402 lines
16 KiB
C++
diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
|
|
index 52fc803050cd257d6de52b1e4a92f3211cbaba88..a9841832ddce540dc0f9b14c29e5eadac7510935 100644
|
|
--- a/browser/components/sessionstore/SessionStore.sys.mjs
|
|
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
|
|
@@ -111,6 +111,11 @@ const TAB_EVENTS = [
|
|
"TabSplitViewActivate",
|
|
"SplitViewRemoved",
|
|
"SplitViewCreated",
|
|
+ "TabAddedToEssentials",
|
|
+ "TabRemovedFromEssentials",
|
|
+ "TabMove",
|
|
+ "TabGroupMoved",
|
|
+ "ZenWorkspaceDataChanged",
|
|
];
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
@@ -185,6 +190,8 @@ const lazy = XPCOMUtils.declareLazy({
|
|
TabStateFlusher:
|
|
"moz-src:///browser/components/sessionstore/TabStateFlusher.sys.mjs",
|
|
setTimeout: "resource://gre/modules/Timer.sys.mjs",
|
|
+ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs",
|
|
+ ZenWindowSync: "resource:///modules/zen/ZenWindowSync.sys.mjs",
|
|
blankURI: () => Services.io.newURI("about:blank"),
|
|
gRestoreWindowsToVirtualDesktop: {
|
|
pref: "browser.sessionstore.restore_windows_to_virtual_desktop",
|
|
@@ -348,6 +355,22 @@ class _SessionStore {
|
|
return this.#shouldRestoreLastSession;
|
|
}
|
|
|
|
+ get _windows() {
|
|
+ return this.#windows;
|
|
+ }
|
|
+
|
|
+ get _browserWindows() {
|
|
+ return this.#browserWindows;
|
|
+ }
|
|
+
|
|
+ set _deferredInitialState(aState) {
|
|
+ this.#deferredInitialState = aState;
|
|
+ }
|
|
+
|
|
+ initializeWindow(aWindow, aInitialState) {
|
|
+ this.#initializeWindow(aWindow, aInitialState);
|
|
+ }
|
|
+
|
|
// whether we will potentially be restoring the session
|
|
// more than once without Firefox restarting in between
|
|
#restoreWithoutRestart = false;
|
|
@@ -515,10 +538,7 @@ class _SessionStore {
|
|
*/
|
|
get willAutoRestore() {
|
|
return (
|
|
- !PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
|
- (Services.prefs.getBoolPref("browser.sessionstore.resume_session_once") ||
|
|
- Services.prefs.getIntPref("browser.startup.page") ==
|
|
- BROWSER_STARTUP_RESUME_SESSION)
|
|
+ true
|
|
);
|
|
}
|
|
|
|
@@ -1215,6 +1235,11 @@ class _SessionStore {
|
|
case "TabPinned":
|
|
case "TabUnpinned":
|
|
case "SwapDocShells":
|
|
+ case "TabRemovedFromEssentials":
|
|
+ case "TabAddedToEssentials":
|
|
+ case "TabMove":
|
|
+ case "TabGroupMoved":
|
|
+ case "ZenWorkspaceDataChanged":
|
|
this.#saveStateDelayed(win);
|
|
break;
|
|
case "TabGroupCreate":
|
|
@@ -1341,6 +1366,10 @@ class _SessionStore {
|
|
this.#windows[aWindow.__SSi].isTaskbarTab = true;
|
|
}
|
|
|
|
+ if (aWindow.document.documentElement.hasAttribute("zen-unsynced-window")) {
|
|
+ this.#windows[aWindow.__SSi].isZenUnsynced = true;
|
|
+ }
|
|
+
|
|
if (lazy.AIWindow.isAIWindowActiveAndEnabled(aWindow)) {
|
|
this.#windows[aWindow.__SSi].isAIWindow = true;
|
|
}
|
|
@@ -1377,7 +1406,7 @@ class _SessionStore {
|
|
let isTaskbarTab = this.#windows[aWindow.__SSi].isTaskbarTab;
|
|
// A regular window is not a private window, taskbar tab window, or popup window
|
|
let isRegularWindow =
|
|
- !isPrivateWindow && !isTaskbarTab && aWindow.toolbar.visible;
|
|
+ !isPrivateWindow && !isTaskbarTab && aWindow.toolbar.visible && !this.#windows[aWindow.__SSi].isZenUnsynced;
|
|
|
|
// perform additional initialization when the first window is loading
|
|
if (lazy.RunState.isStopped) {
|
|
@@ -1389,7 +1418,7 @@ class _SessionStore {
|
|
// to disk to NOW() to enforce a full interval before the next write.
|
|
lazy.SessionSaver.updateLastSaveTime();
|
|
|
|
- if (isPrivateWindow || isTaskbarTab) {
|
|
+ if (isPrivateWindow || isTaskbarTab || aWindow.document.documentElement.hasAttribute("zen-unsynced-window")) {
|
|
this.#log.debug(
|
|
"initializeWindow, the window is private or a web app. Saving SessionStartup.state for possibly restoring later"
|
|
);
|
|
@@ -1433,6 +1462,7 @@ class _SessionStore {
|
|
null,
|
|
"sessionstore-one-or-no-tab-restored"
|
|
);
|
|
+ lazy.ZenSessionStore.onNewEmptySession(aWindow);
|
|
this.#deferredAllWindowsRestored.resolve();
|
|
}
|
|
// this window was opened by #openWindowWithState
|
|
@@ -1482,7 +1512,6 @@ class _SessionStore {
|
|
if (closedWindowState) {
|
|
let newWindowState;
|
|
if (
|
|
- AppConstants.platform == "macosx" ||
|
|
!lazy.SessionStartup.willRestore()
|
|
) {
|
|
// We want to split the window up into pinned tabs and unpinned tabs.
|
|
@@ -1518,6 +1547,7 @@ class _SessionStore {
|
|
}
|
|
|
|
if (newWindowState) {
|
|
+ lazy.ZenSessionStore.onRestoringClosedWindow(newWindowState);
|
|
// Ensure that the window state isn't hidden
|
|
this.#restoreCount = 1;
|
|
let state = { windows: [newWindowState] };
|
|
@@ -1554,6 +1584,9 @@ class _SessionStore {
|
|
});
|
|
this.#shouldRestoreLastSession = false;
|
|
}
|
|
+ else if (!aInitialState && isRegularWindow) {
|
|
+ lazy.ZenSessionStore.restoreNewWindow(aWindow, this);
|
|
+ }
|
|
|
|
if (this.#restoreLastWindow && aWindow.toolbar.visible) {
|
|
// always reset (if not a popup window)
|
|
@@ -1704,7 +1737,7 @@ class _SessionStore {
|
|
|
|
var tabbrowser = aWindow.gBrowser;
|
|
|
|
- let browsers = Array.from(tabbrowser.browsers);
|
|
+ let browsers = aWindow.gZenWorkspaces.allUsedBrowsers;
|
|
|
|
TAB_EVENTS.forEach(function (aEvent) {
|
|
tabbrowser.tabContainer.removeEventListener(aEvent, this, true);
|
|
@@ -1755,7 +1788,7 @@ class _SessionStore {
|
|
|
|
let isLastRegularWindow =
|
|
Object.values(this.#windows).filter(
|
|
- wData => !wData.isPrivate && !wData.isTaskbarTab
|
|
+ wData => !wData.isPrivate && !wData.isTaskbarTab && !wData.isZenUnsynced
|
|
).length == 1;
|
|
this.#log.debug(
|
|
`onClose, closing window isLastRegularWindow? ${isLastRegularWindow}`
|
|
@@ -1812,8 +1845,8 @@ class _SessionStore {
|
|
// 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) {
|
|
- this.#maybeSaveClosedWindow(winData, isLastWindow);
|
|
+ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) {
|
|
+ this.#maybeSaveClosedWindow(winData, isLastWindow, isLastRegularWindow);
|
|
}
|
|
|
|
completionPromise = lazy.TabStateFlusher.flushWindow(aWindow).then(() => {
|
|
@@ -1833,8 +1866,9 @@ class _SessionStore {
|
|
|
|
// Save non-private windows if they have at
|
|
// least one saveable tab or are the last window.
|
|
- if (!winData.isPrivate && !winData.isTaskbarTab) {
|
|
- this.#maybeSaveClosedWindow(winData, isLastWindow);
|
|
+ lazy.ZenWindowSync.on_WindowCloseAndBrowserFlushed(browsers);
|
|
+ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) {
|
|
+ this.#maybeSaveClosedWindow(winData, isLastWindow, isLastRegularWindow);
|
|
|
|
if (!isLastWindow && winData.closedId > -1) {
|
|
this.#addClosedAction(
|
|
@@ -1910,7 +1944,7 @@ class _SessionStore {
|
|
* to call this method again asynchronously (for example, after
|
|
* a window flush).
|
|
*/
|
|
- #maybeSaveClosedWindow(winData, isLastWindow) {
|
|
+ #maybeSaveClosedWindow(winData, isLastWindow, isLastRegularWindow = false) {
|
|
// Make sure SessionStore is still running, and make sure that we
|
|
// haven't chosen to forget this window.
|
|
if (
|
|
@@ -1927,6 +1961,7 @@ class _SessionStore {
|
|
// #closedWindows from a previous call to this function.
|
|
let winIndex = this.#closedWindows.indexOf(winData);
|
|
let alreadyStored = winIndex != -1;
|
|
+ lazy.ZenSessionStore.maybeSaveClosedWindow(winData, isLastRegularWindow);
|
|
// If sidebar command is truthy, i.e. sidebar is open, store sidebar settings
|
|
let shouldStore = hasSaveableTabs || isLastWindow;
|
|
|
|
@@ -2744,7 +2779,7 @@ class _SessionStore {
|
|
if (!isPrivateWindow && tabState.isPrivate) {
|
|
return;
|
|
}
|
|
- if (aTab == aWindow.FirefoxViewHandler.tab) {
|
|
+ if (aTab == aWindow.FirefoxViewHandler.tab || aTab.hasAttribute("zen-empty-tab")) {
|
|
return;
|
|
}
|
|
|
|
@@ -3511,7 +3546,15 @@ class _SessionStore {
|
|
1,
|
|
Math.min(tabState.index, tabState.entries.length)
|
|
);
|
|
- tabState.pinned = false;
|
|
+ tabState.pinned =
|
|
+ newTab.group?.isZenFolder === true &&
|
|
+ Services.prefs.getBoolPref("zen.folders.owned-tabs-in-folder");
|
|
+ tabState.zenEssential = false;
|
|
+ tabState.zenSyncId = null;
|
|
+ tabState.zenIsGlance = false;
|
|
+ tabState.zenGlanceId = null;
|
|
+ tabState.zenHasStaticLabel = false;
|
|
+ tabState.zenWorkspace = aWindow.gZenWorkspaces.activeWorkspace;
|
|
|
|
if (inBackground === false) {
|
|
aWindow.gBrowser.selectedTab = newTab;
|
|
@@ -4036,6 +4079,8 @@ class _SessionStore {
|
|
// Append the tab if we're opening into a different window,
|
|
tabIndex: aSource == aTargetWindow ? pos : Infinity,
|
|
pinned: state.pinned,
|
|
+ essential: state.zenEssential,
|
|
+ zenWorkspaceId: state.zenWorkspace,
|
|
userContextId: state.userContextId,
|
|
skipLoad: true,
|
|
preferredRemoteType,
|
|
@@ -4608,9 +4653,10 @@ class _SessionStore {
|
|
if (activePageData.title && activePageData.title != activePageData.url) {
|
|
win.gBrowser.setInitialTabTitle(tab, activePageData.title, {
|
|
isContentTitle: true,
|
|
+ _zenChangeLabelFlag: true,
|
|
});
|
|
} else {
|
|
- win.gBrowser.setInitialTabTitle(tab, activePageData.url);
|
|
+ win.gBrowser.setInitialTabTitle(tab, activePageData.url, { _zenChangeLabelFlag: true });
|
|
}
|
|
}
|
|
|
|
@@ -4982,7 +5028,7 @@ class _SessionStore {
|
|
|
|
for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) {
|
|
let tab = tabbrowser.tabs[i];
|
|
- if (homePages.includes(tab.linkedBrowser.currentURI.spec)) {
|
|
+ if (homePages.includes(tab.linkedBrowser.currentURI.spec) && !tab.hasAttribute("zen-empty-tab")) {
|
|
removableTabs.push(tab);
|
|
}
|
|
}
|
|
@@ -5095,7 +5141,7 @@ class _SessionStore {
|
|
|
|
// collect the data for all windows
|
|
for (ix in this.#windows) {
|
|
- if (this.#windows[ix]._restoring || this.#windows[ix].isTaskbarTab) {
|
|
+ if (this.#windows[ix]._restoring || this.#windows[ix].isTaskbarTab && !this.#windows[ix].isZenUnsynced) {
|
|
// window data is still in #statesToRestore
|
|
continue;
|
|
}
|
|
@@ -5239,11 +5285,12 @@ class _SessionStore {
|
|
}
|
|
|
|
let tabbrowser = aWindow.gBrowser;
|
|
- let tabs = tabbrowser.tabs;
|
|
+ let tabs = aWindow.gZenWorkspaces.allStoredTabs;
|
|
/** @type {WindowStateData} */
|
|
let winData = this.#windows[aWindow.__SSi];
|
|
let tabsData = (winData.tabs = []);
|
|
|
|
+ winData.splitViewData = aWindow.gZenViewSplitter?.storeDataForSessionStore();
|
|
// update the internal state data for this window
|
|
for (let tab of tabs) {
|
|
if (tab == aWindow.FirefoxViewHandler.tab) {
|
|
@@ -5254,6 +5301,9 @@ class _SessionStore {
|
|
tabsData.push(tabData);
|
|
}
|
|
|
|
+ winData.folders = aWindow.gZenFolders?.storeDataForSessionStore() || [];
|
|
+ winData.activeZenSpace = aWindow.gZenWorkspaces?.activeWorkspace || null;
|
|
+ winData.spaces = aWindow.gZenWorkspaces?.getWorkspacesForSessionStore();
|
|
// update tab group state for this window
|
|
winData.groups = [];
|
|
for (let tabGroup of aWindow.gBrowser.tabGroups) {
|
|
@@ -5270,7 +5320,7 @@ class _SessionStore {
|
|
// 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) {
|
|
- selectedIndex = 1;
|
|
+ selectedIndex = 0;
|
|
winData.title = tabbrowser.tabs[0].label;
|
|
}
|
|
winData.selected = selectedIndex;
|
|
@@ -5472,8 +5522,8 @@ class _SessionStore {
|
|
// selectTab represents.
|
|
let selectTab = 0;
|
|
if (overwriteTabs) {
|
|
- selectTab = parseInt(winData.selected || 1, 10);
|
|
- selectTab = Math.max(selectTab, 1);
|
|
+ selectTab = parseInt(winData.selected || 0, 10);
|
|
+ selectTab = Math.max(selectTab, 0);
|
|
selectTab = Math.min(selectTab, winData.tabs.length);
|
|
}
|
|
|
|
@@ -5495,6 +5545,7 @@ class _SessionStore {
|
|
if (overwriteTabs) {
|
|
for (let i = tabbrowser.browsers.length - 1; i >= 0; i--) {
|
|
if (!tabbrowser.tabs[i].selected) {
|
|
+ aWindow.gZenWorkspaces._shouldOverrideTabs = true;
|
|
tabbrowser.removeTab(tabbrowser.tabs[i]);
|
|
}
|
|
}
|
|
@@ -5529,6 +5580,12 @@ class _SessionStore {
|
|
savedTabGroup => !openTabGroupIdsInWindow.has(savedTabGroup.id)
|
|
);
|
|
}
|
|
+ if (winData.isZenUnsynced) {
|
|
+ aWindow.document.documentElement.setAttribute("zen-unsynced-window", "true");
|
|
+ }
|
|
+ aWindow.gZenFolders?.restoreDataFromSessionStore(winData.folders);
|
|
+ aWindow.gZenWorkspaces?.restoreWorkspacesFromSessionStore(winData);
|
|
+ aWindow.gZenViewSplitter?.restoreDataFromSessionStore(winData.splitViewData);
|
|
|
|
// Move the originally open tabs to the end.
|
|
if (initialTabs) {
|
|
@@ -6098,6 +6155,25 @@ class _SessionStore {
|
|
|
|
// Most of tabData has been restored, now continue with restoring
|
|
// attributes that may trigger external events.
|
|
+ if (tabData.zenEssential) {
|
|
+ tab.setAttribute("zen-essential", "true");
|
|
+ tabData.pinned = true; // Essential tabs are always pinned.
|
|
+ }
|
|
+ if (tabData.zenIsEmpty) {
|
|
+ tab.setAttribute("zen-empty-tab", "true");
|
|
+ }
|
|
+ if (typeof tabData.zenStaticLabel === "string") {
|
|
+ tab.zenStaticLabel = tabData.zenStaticLabel;
|
|
+ }
|
|
+ if (tabData.zenHasStaticIcon && tabData.image) {
|
|
+ tab.zenStaticIcon = tabData.image;
|
|
+ }
|
|
+ if (tabData.zenDefaultUserContextId) {
|
|
+ tab.setAttribute("zenDefaultUserContextId", true);
|
|
+ }
|
|
+ if (tabData.zenWorkspace) {
|
|
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
|
+ }
|
|
|
|
if (tabData.pinned) {
|
|
tabbrowser.pinTab(tab);
|
|
@@ -6272,6 +6348,9 @@ class _SessionStore {
|
|
aWindow.gURLBar.readOnly = false;
|
|
}
|
|
}
|
|
+ if (aWinData.isZenUnsynced) {
|
|
+ this.#windows[aWindow.__SSi].isZenUnsynced = true;
|
|
+ }
|
|
|
|
let promiseParts = Promise.withResolvers();
|
|
const wasMinimized = aWindow.windowState == aWindow.STATE_MINIMIZED;
|
|
@@ -6774,6 +6853,7 @@ class _SessionStore {
|
|
*/
|
|
#isCmdLineEmpty(aWindow, aState) {
|
|
var pinnedOnly =
|
|
+ !Services.prefs.getBoolPref("zen.workspaces.continue-where-left-off") &&
|
|
aState.windows &&
|
|
aState.windows.every(win => win.tabs.every(tab => tab.pinned));
|
|
|
|
@@ -7116,7 +7196,7 @@ class _SessionStore {
|
|
|
|
let groupsToSave = new Map();
|
|
for (let tIndex = 0; tIndex < window.tabs.length; ) {
|
|
- if (window.tabs[tIndex].pinned) {
|
|
+ if (window.tabs[tIndex].pinned && false) {
|
|
// Adjust window.selected
|
|
if (tIndex + 1 < window.selected) {
|
|
window.selected -= 1;
|
|
@@ -7131,7 +7211,7 @@ class _SessionStore {
|
|
);
|
|
// We don't want to increment tIndex here.
|
|
continue;
|
|
- } else if (window.tabs[tIndex].groupId) {
|
|
+ } else if (window.tabs[tIndex].groupId && false) {
|
|
// Convert any open groups into saved groups.
|
|
let groupStateToSave = window.groups.find(
|
|
groupState => groupState.id == window.tabs[tIndex].groupId
|
|
@@ -7691,7 +7771,6 @@ class _SessionStore {
|
|
timer.initWithCallback(
|
|
() => {
|
|
if (beats <= 0) {
|
|
- this.#log.debug(`looseTimer of ${delay} timed out`);
|
|
Glean.sessionRestore.shutdownFlushAllOutcomes.timed_out.add(1);
|
|
deferred.resolve();
|
|
}
|
|
@@ -8174,6 +8253,7 @@ class _SessionStore {
|
|
if (
|
|
!savedTabGroupState.tabs.length ||
|
|
this.getSavedTabGroup(savedTabGroupState.id)
|
|
+ && false
|
|
) {
|
|
return;
|
|
}
|