fix: FIxed restoring pined and essential tabs not being on the correct parent element, b=(bug #8726), c=tests, workspaces

This commit is contained in:
Mr. M
2025-05-31 21:32:51 +02:00
parent 4abb3d2249
commit a710d5949e
5 changed files with 153 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d634dadd4d 100644
index 8c6047e1ada5a22e57e1e665965237c9e22641d7..16b171c56081759e81d3efa6c0c7840fbd7902ff 100644
--- a/browser/components/sessionstore/SessionStore.sys.mjs
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
@@ -2088,7 +2088,6 @@ var SessionStoreInternal = {
@@ -43,7 +43,15 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
if (inBackground === false) {
aWindow.gBrowser.selectedTab = newTab;
@@ -5239,7 +5241,7 @@ var SessionStoreInternal = {
@@ -4361,6 +4363,7 @@ var SessionStoreInternal = {
// Append the tab if we're opening into a different window,
index: aSource == aTargetWindow ? pos : Infinity,
pinned: state.pinned,
+ essential: state.zenEssential,
userContextId: state.userContextId,
skipLoad: true,
preferredRemoteType,
@@ -5239,7 +5242,7 @@ var SessionStoreInternal = {
}
let workspaceID = aWindow.getWorkspaceID();
@@ -52,7 +60,7 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
winData.workspaceID = workspaceID;
}
},
@@ -5430,14 +5432,15 @@ var SessionStoreInternal = {
@@ -5430,14 +5433,15 @@ var SessionStoreInternal = {
}
let tabbrowser = aWindow.gBrowser;
@@ -70,7 +78,7 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
continue;
}
let tabData = lazy.TabState.collect(tab, TAB_CUSTOM_VALUES.get(tab));
@@ -5456,8 +5459,8 @@ var SessionStoreInternal = {
@@ -5456,8 +5460,8 @@ var SessionStoreInternal = {
// We don't store the Firefox View tab in Session Store, so if it was the last selected "tab" when
// 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).
@@ -81,7 +89,7 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
winData.title = tabbrowser.tabs[0].label;
}
winData.selected = selectedIndex;
@@ -5569,8 +5572,8 @@ var SessionStoreInternal = {
@@ -5569,8 +5573,8 @@ var SessionStoreInternal = {
// selectTab represents.
let selectTab = 0;
if (overwriteTabs) {
@@ -92,7 +100,7 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
selectTab = Math.min(selectTab, winData.tabs.length);
}
@@ -5613,6 +5616,7 @@ var SessionStoreInternal = {
@@ -5613,6 +5617,7 @@ var SessionStoreInternal = {
winData.tabs,
winData.groups ?? []
);
@@ -100,7 +108,7 @@ index 8c6047e1ada5a22e57e1e665965237c9e22641d7..8d0585e738a5a758ebbddfa0787c71d6
this._log.debug(
`restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs`
);
@@ -6162,6 +6166,22 @@ var SessionStoreInternal = {
@@ -6162,6 +6167,22 @@ var SessionStoreInternal = {
// Most of tabData has been restored, now continue with restoring
// attributes that may trigger external events.

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861a8911fc9 100644
index d5aa64842a35c6697263c63fd3a0571b64b01344..37c84d1f61e76bfcf4fdead2299f748ac461f6a9 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -413,11 +413,41 @@
@@ -182,15 +182,16 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
} else {
aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1;
}
@@ -2680,6 +2726,7 @@
@@ -2680,6 +2726,8 @@
schemelessInput,
hasValidUserGestureActivation = false,
textDirectiveUserActivation = false,
+ _forZenEmptyTab,
+ essential,
} = {}
) {
// all callers of addTab that pass a params object need to pass
@@ -2690,6 +2737,12 @@
@@ -2690,6 +2738,12 @@
);
}
@@ -203,7 +204,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (!UserInteraction.running("browser.tabs.opening", window)) {
UserInteraction.start("browser.tabs.opening", "initting", window);
}
@@ -2753,6 +2806,16 @@
@@ -2753,6 +2807,19 @@
noInitialLabel,
skipBackgroundNotify,
});
@@ -216,11 +217,22 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
+ }
+ if (_forZenEmptyTab) {
+ t.setAttribute("zen-empty-tab", "true");
+ }
+ if (essential) {
+ t.setAttribute("zen-essential", "true");
+ }
if (insertTab) {
// Insert the tab into the tab container in the correct position.
// For now, we support `index` as an alias for `tabIndex`.
@@ -2783,6 +2846,7 @@
@@ -2765,6 +2832,7 @@
ownerTab,
openerTab,
pinned,
+ essential,
bulkOrderedOpen,
tabGroup: tabGroup ?? openerTab?.group,
});
@@ -2783,6 +2851,7 @@
openWindowInfo,
skipLoad,
triggeringRemoteType,
@@ -228,7 +240,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}));
if (focusUrlBar) {
@@ -2902,6 +2966,12 @@
@@ -2902,6 +2971,12 @@
}
}
@@ -241,7 +253,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// Additionally send pinned tab events
if (pinned) {
this._notifyPinnedStatus(t);
@@ -2990,10 +3060,10 @@
@@ -2990,10 +3065,10 @@
isAdoptingGroup = false,
isUserTriggered = false,
telemetryUserCreateSource = "unknown",
@@ -253,7 +265,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}
if (!color) {
@@ -3014,7 +3084,12 @@
@@ -3014,7 +3089,12 @@
label,
isAdoptingGroup
);
@@ -267,7 +279,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
group,
insertBefore?.group ?? insertBefore
);
@@ -3303,6 +3378,7 @@
@@ -3303,6 +3383,7 @@
openWindowInfo,
skipLoad,
triggeringRemoteType,
@@ -275,7 +287,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}
) {
// If we don't have a preferred remote type (or it is `NOT_REMOTE`), and
@@ -3372,6 +3448,7 @@
@@ -3372,6 +3453,7 @@
openWindowInfo,
name,
skipLoad,
@@ -283,7 +295,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
});
}
@@ -3560,7 +3637,7 @@
@@ -3560,7 +3642,7 @@
// Add a new tab if needed.
if (!tab) {
let createLazyBrowser =
@@ -292,7 +304,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
let url = "about:blank";
if (tabData.entries?.length) {
@@ -3598,7 +3675,8 @@
@@ -3598,7 +3680,8 @@
skipLoad: true,
preferredRemoteType,
});
@@ -302,7 +314,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (select) {
tabToSelect = tab;
}
@@ -3622,7 +3700,8 @@
@@ -3622,7 +3705,8 @@
// needs calling:
shouldUpdateForPinnedTabs = true;
}
@@ -312,7 +324,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
let { groupId } = tabData;
const tabGroup = tabGroupWorkingData.get(groupId);
// if a tab refers to a tab group we don't know, skip any group
@@ -3636,7 +3715,10 @@
@@ -3636,7 +3720,10 @@
tabGroup.stateData.id,
tabGroup.stateData.color,
tabGroup.stateData.collapsed,
@@ -324,7 +336,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
);
tabsFragment.appendChild(tabGroup.node);
}
@@ -3684,8 +3766,16 @@
@@ -3684,8 +3771,16 @@
// to remove the old selected tab.
if (tabToSelect) {
let leftoverTab = this.selectedTab;
@@ -343,7 +355,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}
if (tabs.length > 1 || !tabs[0].selected) {
@@ -3881,7 +3971,7 @@
@@ -3881,7 +3976,7 @@
// Ensure we have an index if one was not provided.
if (typeof elementIndex != "number" && typeof tabIndex != "number") {
// Move the new tab after another tab if needed, to the end otherwise.
@@ -352,7 +364,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (
!bulkOrderedOpen &&
((openerTab &&
@@ -3904,7 +3994,7 @@
@@ -3904,7 +3999,7 @@
) {
elementIndex = Infinity;
} else if (previousTab.visible) {
@@ -361,7 +373,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
} else if (previousTab == FirefoxViewHandler.tab) {
elementIndex = 0;
}
@@ -3932,14 +4022,14 @@
@@ -3932,14 +4027,14 @@
}
// Ensure index is within bounds.
if (tab.pinned) {
@@ -380,7 +392,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// Prevent a flash of unstyled content by setting up the tab content
// and inherited attributes before appending it (see Bug 1592054):
@@ -3947,7 +4037,7 @@
@@ -3947,7 +4042,7 @@
this.tabContainer._invalidateCachedTabs();
@@ -389,7 +401,15 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (this.isTab(itemAfter) && itemAfter.group == tabGroup) {
// Place at the front of, or between tabs in, the same tab group
this.tabContainer.insertBefore(tab, itemAfter);
@@ -4268,6 +4358,9 @@
@@ -3980,6 +4075,7 @@
if (pinned) {
this._updateTabBarForPinnedTabs();
}
+ gZenWorkspaces.fixTabInsertLocation(tab, itemAfter);
TabBarVisibility.update();
}
@@ -4268,6 +4364,9 @@
return;
}
@@ -399,7 +419,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
this.removeTabs(selectedTabs, { telemetrySource });
}
@@ -4520,6 +4613,7 @@
@@ -4520,6 +4619,7 @@
telemetrySource,
} = {}
) {
@@ -407,7 +427,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// When 'closeWindowWithLastTab' pref is enabled, closing all tabs
// can be considered equivalent to closing the window.
if (
@@ -4604,6 +4698,7 @@
@@ -4604,6 +4704,7 @@
if (lastToClose) {
this.removeTab(lastToClose, aParams);
}
@@ -415,7 +435,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
} catch (e) {
console.error(e);
}
@@ -4641,6 +4736,12 @@
@@ -4641,6 +4742,12 @@
aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start();
}
@@ -428,7 +448,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// Handle requests for synchronously removing an already
// asynchronously closing tab.
if (!animate && aTab.closing) {
@@ -4655,7 +4756,9 @@
@@ -4655,7 +4762,9 @@
// frame created for it (for example, by updating the visually selected
// state).
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
@@ -439,7 +459,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (
!this._beginRemoveTab(aTab, {
closeWindowFastpath: true,
@@ -4821,7 +4924,7 @@
@@ -4821,7 +4930,7 @@
closeWindowWithLastTab != null
? closeWindowWithLastTab
: !window.toolbar.visible ||
@@ -448,7 +468,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (closeWindow) {
// We've already called beforeunload on all the relevant tabs if we get here,
@@ -4845,6 +4948,7 @@
@@ -4845,6 +4954,7 @@
newTab = true;
}
@@ -456,7 +476,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
aTab._endRemoveArgs = [closeWindow, newTab];
// swapBrowsersAndCloseOther will take care of closing the window without animation.
@@ -4885,9 +4989,7 @@
@@ -4885,9 +4995,7 @@
aTab._mouseleave();
if (newTab) {
@@ -467,7 +487,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
} else {
TabBarVisibility.update();
}
@@ -5016,6 +5118,8 @@
@@ -5016,6 +5124,8 @@
this.tabs[i]._tPos = i;
}
@@ -476,7 +496,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (!this._windowIsClosing) {
if (wasPinned) {
this.tabContainer._positionPinnedTabs();
@@ -5230,6 +5334,7 @@
@@ -5230,6 +5340,7 @@
}
let excludeTabs = new Set(aExcludeTabs);
@@ -484,7 +504,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// If this tab has a successor, it should be selectable, since
// hiding or closing a tab removes that tab as a successor.
@@ -5242,13 +5347,13 @@
@@ -5242,13 +5353,13 @@
!excludeTabs.has(aTab.owner) &&
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
) {
@@ -500,7 +520,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
);
let tab = this.tabContainer.findNextTab(aTab, {
@@ -5264,7 +5369,7 @@
@@ -5264,7 +5375,7 @@
}
if (tab) {
@@ -509,7 +529,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}
// If no qualifying visible tab was found, see if there is a tab in
@@ -5285,7 +5390,7 @@
@@ -5285,7 +5396,7 @@
});
}
@@ -518,7 +538,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
}
_blurTab(aTab) {
@@ -5686,10 +5791,10 @@
@@ -5686,10 +5797,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
}
@@ -531,7 +551,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
aTab.selected ||
aTab.closing ||
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
@@ -5986,7 +6091,7 @@
@@ -5986,7 +6097,7 @@
// Don't allow mixing pinned and unpinned tabs.
if (this.isTab(element) && element.pinned) {
@@ -540,7 +560,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
} else {
tabIndex = Math.max(tabIndex, this.pinnedTabCount);
}
@@ -6012,10 +6117,16 @@
@@ -6012,10 +6123,16 @@
this.#handleTabMove(
element,
() => {
@@ -559,7 +579,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (neighbor && this.isTab(element) && tabIndex > element._tPos) {
neighbor.after(element);
} else {
@@ -6084,17 +6195,29 @@
@@ -6084,17 +6201,29 @@
targetElement = targetElement.group;
}
}
@@ -593,7 +613,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
if (element.pinned && this.tabContainer.verticalMode) {
return this.tabContainer.verticalPinnedTabsContainer;
}
@@ -6154,7 +6277,7 @@
@@ -6154,7 +6283,7 @@
if (!this.isTab(aTab)) {
throw new Error("Can only move a tab into a tab group");
}
@@ -602,7 +622,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
return;
}
if (aTab.group && aTab.group.id === aGroup.id) {
@@ -6248,6 +6371,10 @@
@@ -6248,6 +6377,10 @@
moveActionCallback();
@@ -613,7 +633,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// Clear tabs cache after moving nodes because the order of tabs may have
// changed.
this.tabContainer._invalidateCachedTabs();
@@ -7145,7 +7272,7 @@
@@ -7145,7 +7278,7 @@
// preventDefault(). It will still raise the window if appropriate.
break;
}
@@ -622,7 +642,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
window.focus();
aEvent.preventDefault();
break;
@@ -8044,6 +8171,7 @@
@@ -8044,6 +8177,7 @@
aWebProgress.isTopLevel
) {
this.mTab.setAttribute("busy", "true");
@@ -630,7 +650,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
gBrowser._tabAttrModified(this.mTab, ["busy"]);
this.mTab._notselectedsinceload = !this.mTab.selected;
}
@@ -9009,7 +9137,7 @@ var TabContextMenu = {
@@ -9009,7 +9143,7 @@ var TabContextMenu = {
);
contextUnpinSelectedTabs.hidden =
!this.contextTab.pinned || !this.multiselected;
@@ -639,7 +659,7 @@ index d5aa64842a35c6697263c63fd3a0571b64b01344..42788853cde2523b4020cb499383f861
// Move Tab items
let contextMoveTabOptions = document.getElementById(
"context_moveTabOptions"
@@ -9278,6 +9406,7 @@ var TabContextMenu = {
@@ -9278,6 +9412,7 @@ var TabContextMenu = {
telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP,
});
} else {

View File

@@ -14,3 +14,4 @@
["browser_pinned_to_essential.js"]
["browser_issue_7654.js"]
["browser_issue_8726.js"]

View File

@@ -0,0 +1,59 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const { TabStateFlusher } = ChromeUtils.importESModule(
'resource:///modules/sessionstore/TabStateFlusher.sys.mjs'
);
add_task(async function test_Restore_Pinned_Tab() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: 'https://example.com/',
},
async function (browser) {
let tab = gBrowser.getTabForBrowser(browser);
gBrowser.pinTab(tab);
ok(tab.pinned, 'The tab should be pinned after being created');
await BrowserTestUtils.removeTab(tab);
await TabStateFlusher.flushWindow(window);
restoreLastClosedTabOrWindowOrSession();
tab = gBrowser.selectedTab;
ok(tab.pinned, 'The tab should be pinned after restore');
ok(
tab.parentElement.closest('.zen-workspace-pinned-tabs-section'),
'The tab should be in the pinned tabs section after restore'
);
await BrowserTestUtils.removeTab(tab);
}
);
});
add_task(async function test_Restore_Essential_Tab() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: 'https://example.com/',
},
async function (browser) {
let tab = gBrowser.getTabForBrowser(browser);
gZenPinnedTabManager.addToEssentials(tab);
ok(
tab.hasAttribute('zen-essential'),
'The tab should be marked as essential after being created'
);
await BrowserTestUtils.removeTab(tab);
await TabStateFlusher.flushWindow(window);
restoreLastClosedTabOrWindowOrSession();
tab = gBrowser.selectedTab;
ok(tab.hasAttribute('zen-essential'), 'The tab should be marked as essential after restore');
ok(
tab.parentElement.closest('.zen-essentials-container'),
'The tab should be in the essentials tabs section after restore'
);
await BrowserTestUtils.removeTab(tab);
}
);
});

View File

@@ -3322,4 +3322,20 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
});
}
fixTabInsertLocation(tab) {
if (tab.hasAttribute('zen-essential')) {
// Essential tabs should always be inserted at the end of the essentials section
const essentialsSection = this.getEssentialsSection(tab);
if (essentialsSection) {
essentialsSection.appendChild(tab);
}
} else if (tab.pinned) {
// Pinned tabs should always be inserted at the end of the pinned tabs container
const pinnedContainer = this.pinnedTabsContainer;
if (pinnedContainer) {
pinnedContainer.insertBefore(tab, pinnedContainer.lastChild);
}
}
}
})();