mirror of
https://github.com/zen-browser/desktop.git
synced 2025-10-09 11:26:44 +00:00
Refactor ZenTabUnloader and ZenWorkspaces to improve tab unloading logic and enhance session restoration handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
diff --git a/browser/base/content/browser-commands.js b/browser/base/content/browser-commands.js
|
||||
index 352de44dda36e3f6672eb353f42978ede0cd2681..66d1616da17df3430cec0994a346f0f446944f1a 100644
|
||||
index 352de44dda36e3f6672eb353f42978ede0cd2681..0fde717eaf755526ec65b676c43bd34c6a675934 100644
|
||||
--- a/browser/base/content/browser-commands.js
|
||||
+++ b/browser/base/content/browser-commands.js
|
||||
@@ -318,6 +318,10 @@ var BrowserCommands = {
|
||||
@@ -13,7 +13,18 @@ index 352de44dda36e3f6672eb353f42978ede0cd2681..66d1616da17df3430cec0994a346f0f4
|
||||
// A notification intended to be useful for modular peformance tracking
|
||||
// starting as close as is reasonably possible to the time when the user
|
||||
// expressed the intent to open a new tab. Since there are a lot of
|
||||
@@ -407,8 +411,8 @@ var BrowserCommands = {
|
||||
@@ -400,6 +404,10 @@ var BrowserCommands = {
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (gBrowser.selectedTab.hasAttribute("zen-empty-tab")) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
// Keyboard shortcuts that would close a tab that is pinned select the first
|
||||
// unpinned tab instead.
|
||||
if (
|
||||
@@ -407,8 +415,8 @@ var BrowserCommands = {
|
||||
(event.ctrlKey || event.metaKey || event.altKey) &&
|
||||
gBrowser.selectedTab.pinned
|
||||
) {
|
||||
|
@@ -225,6 +225,10 @@
|
||||
|
||||
unloadTab() {
|
||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
this.explicitUnloadTabs(tabs);
|
||||
}
|
||||
|
||||
explicitUnloadTabs(tabs) {
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
if (this.canUnloadTab(tabs[i], Date.now(), this.intervalUnloader.excludedUrls, true)) {
|
||||
this.unload(tabs[i]);
|
||||
@@ -263,7 +267,7 @@
|
||||
(tab.pictureinpicture && !ignoreTimestamp) ||
|
||||
(tab.soundPlaying && !ignoreTimestamp) ||
|
||||
(tab.zenIgnoreUnload && !ignoreTimestamp) ||
|
||||
excludedUrls.some((url) => url.test(tab.linkedBrowser.currentURI.spec))
|
||||
excludedUrls.some((url) => url.test(tab.linkedBrowser?.currentURI.spec))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
`;
|
||||
|
||||
async waitForPromises() {
|
||||
await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized]);
|
||||
await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized, SessionStore.promiseAllWindowsRestored]);
|
||||
}
|
||||
|
||||
async init() {
|
||||
@@ -599,9 +599,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
let showed = false;
|
||||
if (currentTab.pinned) {
|
||||
this.selectEmptyTab();
|
||||
gZenTabUnloader.explicitUnloadTabs([currentTab]);
|
||||
showed = true;
|
||||
} else {
|
||||
if (currentTab.isEmpty) {
|
||||
const currentTabURL = currentTab.linkedBrowser?.currentURI?.spec;
|
||||
// Check for empty tab being restored
|
||||
if (
|
||||
(currentTab.isEmpty &&
|
||||
(currentTab.getAttribute('image') === gPageIcons[currentTabURL] || !currentTab.hasAttribute('image'))) ||
|
||||
currentTab.hasAttribute('zen-empty-tab')
|
||||
) {
|
||||
this.selectEmptyTab();
|
||||
gBrowser.removeTab(currentTab);
|
||||
showed = true;
|
||||
|
@@ -1,20 +1,8 @@
|
||||
diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
index 334c041c1748564094c6a177bb24f146791d96d8..c8f4ad6eeab4bf1ede6f23814d370d839ed83f76 100644
|
||||
index 334c041c1748564094c6a177bb24f146791d96d8..e301cc1df604e4a23fcf260d5952736f5b791803 100644
|
||||
--- a/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
|
||||
@@ -2174,9 +2174,10 @@ var SessionStoreInternal = {
|
||||
TelemetryStopwatch.finish(
|
||||
"FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS"
|
||||
);
|
||||
-
|
||||
+ aWindow.ZenWorkspaces.delayedStartup().then(() => {
|
||||
// Let everyone know we're done.
|
||||
this._deferredInitialized.resolve();
|
||||
+ });
|
||||
}
|
||||
})
|
||||
.catch(ex => {
|
||||
@@ -3848,6 +3849,7 @@ var SessionStoreInternal = {
|
||||
@@ -3848,6 +3848,7 @@ var SessionStoreInternal = {
|
||||
aWindow.gBrowser.selectedTab = newTab;
|
||||
}
|
||||
|
||||
@@ -22,7 +10,7 @@ index 334c041c1748564094c6a177bb24f146791d96d8..c8f4ad6eeab4bf1ede6f23814d370d83
|
||||
// Restore the state into the new tab.
|
||||
this.restoreTab(newTab, tabState, {
|
||||
restoreImmediately: aRestoreImmediately,
|
||||
@@ -5315,14 +5317,14 @@ var SessionStoreInternal = {
|
||||
@@ -5315,14 +5316,14 @@ var SessionStoreInternal = {
|
||||
}
|
||||
|
||||
let tabbrowser = aWindow.gBrowser;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
diff --git a/browser/components/sessionstore/TabState.sys.mjs b/browser/components/sessionstore/TabState.sys.mjs
|
||||
index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..83bf443ca158c07e05075777da02b7f228d83dff 100644
|
||||
index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..05dbb00375523819163bcd225074117ef02b8b37 100644
|
||||
--- a/browser/components/sessionstore/TabState.sys.mjs
|
||||
+++ b/browser/components/sessionstore/TabState.sys.mjs
|
||||
@@ -84,6 +84,13 @@ class _TabState {
|
||||
@@ -84,6 +84,14 @@ class _TabState {
|
||||
tabData.groupId = tab.group.id;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..83bf443ca158c07e05075777da02b7f2
|
||||
+ tabData.zenDefaultUserContextId = tab.getAttribute("zenDefaultUserContextId");
|
||||
+ tabData.zenPinnedEntry = tab.getAttribute("zen-pinned-entry");
|
||||
+ tabData.zenPinnedIcon = tab.getAttribute("zen-pinned-icon");
|
||||
+ tabData.zenIsEmpty = tab.hasAttribute("zen-empty-tab");
|
||||
+
|
||||
tabData.searchMode = tab.ownerGlobal.gURLBar.getSearchMode(browser, true);
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
|
||||
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43a2c676bd 100644
|
||||
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..3523627188284f0af992d29bb0863f8ae20d5094 100644
|
||||
--- a/browser/components/tabbrowser/content/tabbrowser.js
|
||||
+++ b/browser/components/tabbrowser/content/tabbrowser.js
|
||||
@@ -406,11 +406,52 @@
|
||||
@@ -187,13 +187,16 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
// Additionally send pinned tab events
|
||||
if (pinned) {
|
||||
this._notifyPinnedStatus(t);
|
||||
@@ -3403,6 +3469,21 @@
|
||||
@@ -3403,6 +3469,24 @@
|
||||
) {
|
||||
tabWasReused = true;
|
||||
tab = this.selectedTab;
|
||||
+ if (tabData.zenWorkspace) {
|
||||
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
||||
+ }
|
||||
+ if (tabData.zenIsEmpty) {
|
||||
+ tab.setAttribute("zen-empty-tab", "true");
|
||||
+ }
|
||||
+ if (tabData.zenPinnedId) {
|
||||
+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId);
|
||||
+ }
|
||||
@@ -209,7 +212,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (!tabData.pinned) {
|
||||
this.unpinTab(tab);
|
||||
} else {
|
||||
@@ -3416,6 +3497,7 @@
|
||||
@@ -3416,6 +3500,7 @@
|
||||
restoreTabsLazily && !select && !tabData.pinned;
|
||||
|
||||
let url = "about:blank";
|
||||
@@ -217,7 +220,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (tabData.entries?.length) {
|
||||
let activeIndex = (tabData.index || tabData.entries.length) - 1;
|
||||
// Ensure the index is in bounds.
|
||||
@@ -3451,7 +3533,21 @@
|
||||
@@ -3451,7 +3536,24 @@
|
||||
skipLoad: true,
|
||||
preferredRemoteType,
|
||||
});
|
||||
@@ -228,6 +231,9 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
+ if (tabData.zenPinnedId) {
|
||||
+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId);
|
||||
+ }
|
||||
+ if (tabData.zenIsEmpty) {
|
||||
+ tab.setAttribute("zen-empty-tab", "true");
|
||||
+ }
|
||||
+ if (tabData.zenEssential) {
|
||||
+ tab.setAttribute("zen-essential", "true");
|
||||
+ }
|
||||
@@ -240,7 +246,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (select) {
|
||||
tabToSelect = tab;
|
||||
}
|
||||
@@ -3464,8 +3560,8 @@
|
||||
@@ -3464,8 +3566,8 @@
|
||||
// inserted in the DOM. If the tab is not yet in the DOM,
|
||||
// just insert it in the right place from the start.
|
||||
if (!tab.parentNode) {
|
||||
@@ -251,7 +257,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
tab.toggleAttribute("pinned", true);
|
||||
this.tabContainer._invalidateCachedTabs();
|
||||
// Then ensure all the tab open/pinning information is sent.
|
||||
@@ -3729,7 +3825,7 @@
|
||||
@@ -3729,7 +3831,7 @@
|
||||
// Ensure we have an index if one was not provided.
|
||||
if (typeof index != "number") {
|
||||
// Move the new tab after another tab if needed, to the end otherwise.
|
||||
@@ -260,7 +266,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (
|
||||
!bulkOrderedOpen &&
|
||||
((openerTab &&
|
||||
@@ -3780,7 +3876,7 @@
|
||||
@@ -3780,7 +3882,7 @@
|
||||
}
|
||||
|
||||
/** @type {MozTabbrowserTab|undefined} */
|
||||
@@ -269,7 +275,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
this.tabContainer._invalidateCachedTabs();
|
||||
|
||||
if (tabGroup) {
|
||||
@@ -4095,6 +4191,9 @@
|
||||
@@ -4095,6 +4197,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -279,7 +285,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
this.removeTabs(selectedTabs);
|
||||
}
|
||||
|
||||
@@ -4427,6 +4526,7 @@
|
||||
@@ -4427,6 +4532,7 @@
|
||||
skipSessionStore,
|
||||
} = {}
|
||||
) {
|
||||
@@ -287,7 +293,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (UserInteraction.running("browser.tabs.opening", window)) {
|
||||
UserInteraction.finish("browser.tabs.opening", window);
|
||||
}
|
||||
@@ -4443,6 +4543,12 @@
|
||||
@@ -4443,6 +4549,12 @@
|
||||
TelemetryStopwatch.start("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
||||
}
|
||||
|
||||
@@ -300,7 +306,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
// Handle requests for synchronously removing an already
|
||||
// asynchronously closing tab.
|
||||
if (!animate && aTab.closing) {
|
||||
@@ -4457,7 +4563,9 @@
|
||||
@@ -4457,7 +4569,9 @@
|
||||
// frame created for it (for example, by updating the visually selected
|
||||
// state).
|
||||
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
|
||||
@@ -311,7 +317,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (
|
||||
!this._beginRemoveTab(aTab, {
|
||||
closeWindowFastpath: true,
|
||||
@@ -4471,7 +4579,6 @@
|
||||
@@ -4471,7 +4585,6 @@
|
||||
TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
||||
return;
|
||||
}
|
||||
@@ -319,16 +325,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
let lockTabSizing =
|
||||
!this.tabContainer.verticalMode &&
|
||||
!aTab.pinned &&
|
||||
@@ -4550,7 +4657,7 @@
|
||||
skipSessionStore = false,
|
||||
} = {}
|
||||
) {
|
||||
- if (aTab.closing || this._windowIsClosing) {
|
||||
+ if (aTab.closing || this._windowIsClosing || aTab.hasAttribute("zen-empty-tab")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4610,14 +4717,14 @@
|
||||
@@ -4610,14 +4723,14 @@
|
||||
!!this.tabsInCollapsedTabGroups.length;
|
||||
if (
|
||||
aTab.visible &&
|
||||
@@ -345,7 +342,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
|
||||
if (closeWindow) {
|
||||
// We've already called beforeunload on all the relevant tabs if we get here,
|
||||
@@ -4681,9 +4788,7 @@
|
||||
@@ -4681,9 +4794,7 @@
|
||||
aTab._mouseleave();
|
||||
|
||||
if (newTab) {
|
||||
@@ -356,7 +353,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
} else {
|
||||
TabBarVisibility.update();
|
||||
}
|
||||
@@ -4812,6 +4917,8 @@
|
||||
@@ -4812,6 +4923,8 @@
|
||||
this.tabs[i]._tPos = i;
|
||||
}
|
||||
|
||||
@@ -365,7 +362,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (!this._windowIsClosing) {
|
||||
if (wasPinned) {
|
||||
this.tabContainer._positionPinnedTabs();
|
||||
@@ -5025,7 +5132,7 @@
|
||||
@@ -5025,7 +5138,7 @@
|
||||
!excludeTabs.has(aTab.owner) &&
|
||||
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
|
||||
) {
|
||||
@@ -374,7 +371,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
}
|
||||
|
||||
// Try to find a remaining tab that comes after the given tab
|
||||
@@ -5047,7 +5154,7 @@
|
||||
@@ -5047,7 +5160,7 @@
|
||||
}
|
||||
|
||||
if (tab) {
|
||||
@@ -383,7 +380,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
}
|
||||
|
||||
// If no qualifying visible tab was found, see if there is a tab in
|
||||
@@ -5465,10 +5572,10 @@
|
||||
@@ -5465,10 +5578,10 @@
|
||||
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
|
||||
}
|
||||
|
||||
@@ -396,7 +393,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
aTab.selected ||
|
||||
aTab.closing ||
|
||||
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
|
||||
@@ -5706,9 +5813,9 @@
|
||||
@@ -5706,9 +5819,9 @@
|
||||
|
||||
// Don't allow mixing pinned and unpinned tabs.
|
||||
if (aTab.pinned) {
|
||||
@@ -408,7 +405,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
}
|
||||
if (aTab._tPos == aIndex) {
|
||||
return;
|
||||
@@ -5717,7 +5824,7 @@
|
||||
@@ -5717,7 +5830,7 @@
|
||||
this._lastRelatedTabMap = new WeakMap();
|
||||
|
||||
this._handleTabMove(aTab, () => {
|
||||
@@ -417,7 +414,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (forceStandaloneTab && neighbor.group) {
|
||||
neighbor = neighbor.group;
|
||||
}
|
||||
@@ -5802,7 +5909,7 @@
|
||||
@@ -5802,7 +5915,7 @@
|
||||
createLazyBrowser,
|
||||
};
|
||||
|
||||
@@ -426,7 +423,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
if (aIndex < numPinned || (aTab.pinned && aIndex == numPinned)) {
|
||||
params.pinned = true;
|
||||
}
|
||||
@@ -7443,6 +7550,7 @@
|
||||
@@ -7443,6 +7556,7 @@
|
||||
aWebProgress.isTopLevel
|
||||
) {
|
||||
this.mTab.setAttribute("busy", "true");
|
||||
@@ -434,7 +431,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
gBrowser._tabAttrModified(this.mTab, ["busy"]);
|
||||
this.mTab._notselectedsinceload = !this.mTab.selected;
|
||||
gBrowser.syncThrobberAnimations(this.mTab);
|
||||
@@ -8411,7 +8519,7 @@ var TabContextMenu = {
|
||||
@@ -8411,7 +8525,7 @@ var TabContextMenu = {
|
||||
);
|
||||
contextUnpinSelectedTabs.hidden =
|
||||
!this.contextTab.pinned || !multiselectionContext;
|
||||
@@ -443,7 +440,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
// Move Tab items
|
||||
let contextMoveTabOptions = document.getElementById(
|
||||
"context_moveTabOptions"
|
||||
@@ -8444,7 +8552,7 @@ var TabContextMenu = {
|
||||
@@ -8444,7 +8558,7 @@ var TabContextMenu = {
|
||||
let contextMoveTabToStart = document.getElementById("context_moveToStart");
|
||||
let isFirstTab =
|
||||
tabsToMove[0] == visibleTabs[0] ||
|
||||
@@ -452,7 +449,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43
|
||||
contextMoveTabToStart.disabled = isFirstTab && allSelectedTabsAdjacent;
|
||||
|
||||
document.getElementById("context_openTabInWindow").disabled =
|
||||
@@ -8677,6 +8785,7 @@ var TabContextMenu = {
|
||||
@@ -8677,6 +8791,7 @@ var TabContextMenu = {
|
||||
if (this.contextTab.multiselected) {
|
||||
gBrowser.removeMultiSelectedTabs();
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user