mirror of
https://github.com/zen-browser/desktop.git
synced 2026-01-10 15:23:57 +00:00
277 lines
11 KiB
C++
277 lines
11 KiB
C++
diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
|
|
index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..0deff2a0238fa3822387fddd44ddd21451b6e8eb 100644
|
|
--- a/browser/components/sessionstore/SessionStore.sys.mjs
|
|
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
|
|
@@ -127,6 +127,8 @@ const TAB_EVENTS = [
|
|
"TabGroupCollapse",
|
|
"TabGroupExpand",
|
|
"TabSplitViewActivate",
|
|
+ "TabAddedToEssentials",
|
|
+ "TabRemovedFromEssentials",
|
|
];
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
@@ -196,6 +198,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|
TabStateCache: "resource:///modules/sessionstore/TabStateCache.sys.mjs",
|
|
TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.sys.mjs",
|
|
setTimeout: "resource://gre/modules/Timer.sys.mjs",
|
|
+ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs",
|
|
});
|
|
|
|
ChromeUtils.defineLazyGetter(lazy, "blankURI", () => {
|
|
@@ -1238,10 +1241,7 @@ var SessionStoreInternal = {
|
|
*/
|
|
get willAutoRestore() {
|
|
return (
|
|
- !PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
|
- (Services.prefs.getBoolPref("browser.sessionstore.resume_session_once") ||
|
|
- Services.prefs.getIntPref("browser.startup.page") ==
|
|
- BROWSER_STARTUP_RESUME_SESSION)
|
|
+ !PrivateBrowsingUtils.permanentPrivateBrowsing
|
|
);
|
|
},
|
|
|
|
@@ -1911,6 +1911,8 @@ var SessionStoreInternal = {
|
|
case "TabPinned":
|
|
case "TabUnpinned":
|
|
case "SwapDocShells":
|
|
+ case "TabRemovedFromEssentials":
|
|
+ case "TabAddedToEssentials":
|
|
this.saveStateDelayed(win);
|
|
break;
|
|
case "TabGroupCreate":
|
|
@@ -2020,6 +2022,10 @@ var SessionStoreInternal = {
|
|
this._windows[aWindow.__SSi].isTaskbarTab = true;
|
|
}
|
|
|
|
+ if (aWindow.document.documentElement.hasAttribute("zen-unsynced-window")) {
|
|
+ this._windows[aWindow.__SSi].isZenUnsynced = true;
|
|
+ }
|
|
+
|
|
let tabbrowser = aWindow.gBrowser;
|
|
|
|
// add tab change listeners to all already existing tabs
|
|
@@ -2107,6 +2113,7 @@ var SessionStoreInternal = {
|
|
null,
|
|
"sessionstore-one-or-no-tab-restored"
|
|
);
|
|
+ lazy.ZenSessionStore.onNewEmptySession(aWindow);
|
|
this._deferredAllWindowsRestored.resolve();
|
|
}
|
|
// this window was opened by _openWindowWithState
|
|
@@ -2151,7 +2158,6 @@ var SessionStoreInternal = {
|
|
if (closedWindowState) {
|
|
let newWindowState;
|
|
if (
|
|
- AppConstants.platform == "macosx" ||
|
|
!lazy.SessionStartup.willRestore()
|
|
) {
|
|
// We want to split the window up into pinned tabs and unpinned tabs.
|
|
@@ -2215,6 +2221,15 @@ var SessionStoreInternal = {
|
|
});
|
|
this._shouldRestoreLastSession = false;
|
|
}
|
|
+ else if (!aInitialState && isRegularWindow) {
|
|
+ let windowPromises = [];
|
|
+ for (let window of this._browserWindows) {
|
|
+ windowPromises.push(lazy.TabStateFlusher.flushWindow(window));
|
|
+ }
|
|
+ Promise.all(windowPromises).finally(() => {
|
|
+ lazy.ZenSessionStore.restoreNewWindow(aWindow, this);
|
|
+ });
|
|
+ }
|
|
|
|
if (this._restoreLastWindow && aWindow.toolbar.visible) {
|
|
// always reset (if not a popup window)
|
|
@@ -2465,7 +2480,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);
|
|
}
|
|
|
|
@@ -2486,7 +2501,7 @@ var SessionStoreInternal = {
|
|
|
|
// Save non-private windows if they have at
|
|
// least one saveable tab or are the last window.
|
|
- if (!winData.isPrivate && !winData.isTaskbarTab) {
|
|
+ if (!winData.isPrivate && !winData.isTaskbarTab && !winData.isZenUnsynced) {
|
|
this.maybeSaveClosedWindow(winData, isLastWindow);
|
|
|
|
if (!isLastWindow && winData.closedId > -1) {
|
|
@@ -2582,6 +2597,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 => {
|
|
@@ -3373,7 +3389,7 @@ var SessionStoreInternal = {
|
|
if (!isPrivateWindow && tabState.isPrivate) {
|
|
return;
|
|
}
|
|
- if (aTab == aWindow.FirefoxViewHandler.tab) {
|
|
+ if (aTab == aWindow.FirefoxViewHandler.tab || aTab.hasAttribute("zen-empty-tab")) {
|
|
return;
|
|
}
|
|
|
|
@@ -4089,6 +4105,12 @@ var SessionStoreInternal = {
|
|
Math.min(tabState.index, tabState.entries.length)
|
|
);
|
|
tabState.pinned = false;
|
|
+ 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;
|
|
@@ -4525,6 +4547,7 @@ var SessionStoreInternal = {
|
|
// Append the tab if we're opening into a different window,
|
|
tabIndex: aSource == aTargetWindow ? pos : Infinity,
|
|
pinned: state.pinned,
|
|
+ essential: state.zenEssential,
|
|
userContextId: state.userContextId,
|
|
skipLoad: true,
|
|
preferredRemoteType,
|
|
@@ -5032,7 +5055,10 @@ var SessionStoreInternal = {
|
|
!activePageData ||
|
|
(activePageData && activePageData.url != "about:blank")
|
|
) {
|
|
+ let hadZenStaticFlag = tab.hasAttribute("zen-has-static-icon");
|
|
+ tab.removeAttribute("zen-has-static-icon");
|
|
win.gBrowser.setIcon(tab, tabData.image);
|
|
+ if (hadZenStaticFlag) tab.setAttribute("zen-has-static-icon", true);
|
|
}
|
|
lazy.TabStateCache.update(browser.permanentKey, {
|
|
image: null,
|
|
@@ -5374,7 +5400,7 @@ var SessionStoreInternal = {
|
|
|
|
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);
|
|
}
|
|
}
|
|
@@ -5483,7 +5509,7 @@ var SessionStoreInternal = {
|
|
|
|
// 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;
|
|
}
|
|
@@ -5625,11 +5651,12 @@ var SessionStoreInternal = {
|
|
}
|
|
|
|
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) {
|
|
@@ -5640,6 +5667,9 @@ var SessionStoreInternal = {
|
|
tabsData.push(tabData);
|
|
}
|
|
|
|
+ winData.folders = aWindow.gZenFolders?.storeDataForSessionStore() || [];
|
|
+ winData.activeZenSpace = aWindow.gZenWorkspaces?.activeWorkspace || null;
|
|
+ winData.spaces = aWindow.gZenWorkspaces?.getWorkspaces();
|
|
// update tab group state for this window
|
|
winData.groups = [];
|
|
for (let tabGroup of aWindow.gBrowser.tabGroups) {
|
|
@@ -5652,7 +5682,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) {
|
|
- selectedIndex = 1;
|
|
+ selectedIndex = 0;
|
|
winData.title = tabbrowser.tabs[0].label;
|
|
}
|
|
winData.selected = selectedIndex;
|
|
@@ -5765,8 +5795,8 @@ var SessionStoreInternal = {
|
|
// 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);
|
|
}
|
|
|
|
@@ -5788,6 +5818,7 @@ var SessionStoreInternal = {
|
|
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]);
|
|
}
|
|
}
|
|
@@ -5821,6 +5852,9 @@ var SessionStoreInternal = {
|
|
savedTabGroup => !openTabGroupIdsInWindow.has(savedTabGroup.id)
|
|
);
|
|
}
|
|
+ aWindow.gZenFolders?.restoreDataFromSessionStore(winData.folders);
|
|
+ aWindow.gZenViewSplitter?.restoreDataFromSessionStore(winData.splitViewData);
|
|
+ aWindow.gZenWorkspaces?.restoreWorkspacesFromSessionStore(winData);
|
|
|
|
// Move the originally open tabs to the end.
|
|
if (initialTabs) {
|
|
@@ -6372,6 +6406,25 @@ var SessionStoreInternal = {
|
|
|
|
// 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 (tabData.zenStaticLabel) {
|
|
+ tab.zenStaticLabel = tabData.zenStaticLabel;
|
|
+ }
|
|
+ if (tabData.zenHasStaticIcon) {
|
|
+ tab.setAttribute("zen-has-static-icon", "true");
|
|
+ }
|
|
+ if (tabData.zenDefaultUserContextId) {
|
|
+ tab.setAttribute("zenDefaultUserContextId", true);
|
|
+ }
|
|
+ if (tabData.zenWorkspace) {
|
|
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
|
+ }
|
|
|
|
if (tabData.pinned) {
|
|
tabbrowser.pinTab(tab);
|
|
@@ -7290,7 +7343,7 @@ var SessionStoreInternal = {
|
|
|
|
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;
|
|
@@ -7305,7 +7358,7 @@ var SessionStoreInternal = {
|
|
);
|
|
// 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
|