diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js index fec3dc8129a4d235fdd05e0390145a02064ebaa5..636b56754f48c1ec931152cf34bab8414a75cebc 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -402,11 +402,26 @@ return count; }, + get _numVisiblePinTabs() { + let i = 0; + for (let tab of this.tabs) { + if (!tab.pinned) { + break; + } + if (!tab.hidden) { + i++; + } + } + return i; + }, + get pinnedTabCount() { - for (var i = 0; i < this.tabs.length; i++) { - if (!this.tabs[i].pinned) { + let i = 0; + for (let tab of this.tabs) { + if (!tab.pinned) { break; } + i++; } return i; }, @@ -800,7 +815,7 @@ if (this.tabContainer.verticalMode) { let wasFocused = document.activeElement == this.selectedTab; let oldPosition = aTab._tPos; - this.verticalPinnedTabsContainer.appendChild(aTab); + aTab.hasAttribute("zen-essential") ? document.getElementById("zen-essentials-container").appendChild(aTab) : this.verticalPinnedTabsContainer.appendChild(aTab); this._updateAfterMoveTabTo(aTab, oldPosition, wasFocused); } else { this.moveTabTo(aTab, this.pinnedTabCount); @@ -1047,6 +1062,7 @@ let LOCAL_PROTOCOLS = ["chrome:", "about:", "resource:", "data:"]; + try { if ( aIconURL && !aLoadingPrincipal && @@ -1057,6 +1073,9 @@ ); return; } + } catch (e) { + console.warn(e); + } let browser = this.getBrowserForTab(aTab); browser.mIconURL = aIconURL; @@ -1286,6 +1305,7 @@ if (!this._previewMode) { newTab.recordTimeFromUnloadToReload(); newTab.updateLastAccessed(); + newTab.removeAttribute("unread"); oldTab.updateLastAccessed(); // if this is the foreground window, update the last-seen timestamps. if (this.ownerGlobal == BrowserWindowTracker.getTopWindow()) { @@ -2371,7 +2391,7 @@ let panel = this.getPanel(browser); let uniqueId = this._generateUniquePanelID(); - panel.id = uniqueId; + if (!panel.id?.startsWith("zen-")) panel.id = uniqueId; aTab.linkedPanel = uniqueId; // Inject the into the DOM if necessary. @@ -2431,7 +2451,7 @@ // hasSiblings=false on both the existing browser and the new browser. if (this.tabs.length == 2) { this.tabs[0].linkedBrowser.browsingContext.hasSiblings = true; - this.tabs[1].linkedBrowser.browsingContext.hasSiblings = true; + if (this.tabs[1].linkedBrowser.browsingContext) this.tabs[1].linkedBrowser.browsingContext.hasSiblings = true; } else { aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1; } @@ -2651,6 +2671,11 @@ ); } + let hasZenDefaultUserContextId = false; + if (typeof ZenWorkspaces !== "undefined") { + [userContextId, hasZenDefaultUserContextId] = ZenWorkspaces.getContextIdIfNeeded(userContextId, fromExternal, allowInheritPrincipal); + } + if (!UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.start("browser.tabs.opening", "initting", window); } @@ -2720,6 +2745,9 @@ noInitialLabel, skipBackgroundNotify, }); + if (hasZenDefaultUserContextId) { + t.setAttribute("zenDefaultUserContextId", "true"); + } if (insertTab) { // insert the tab into the tab container in the correct position this._insertTabAtIndex(t, { @@ -3342,6 +3370,23 @@ ) { tabWasReused = true; tab = this.selectedTab; + + if (tabData.zenWorkspace) { + tab.setAttribute("zen-workspace-id", tabData.zenWorkspace); + } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } + if (tabData.zenDefaultUserContextId) { + tab.setAttribute("zenDefaultUserContextId", "true"); + } + if (tabData.zenPinnedEntry) { + tab.setAttribute("zen-pinned-entry", tabData.zenPinnedEntry); + } + if (!tabData.pinned) { this.unpinTab(tab); } else { @@ -3355,6 +3400,9 @@ restoreTabsLazily && !select && !tabData.pinned; let url = "about:blank"; + + gZenPinnedTabManager.resetPinnedTabData(tabData); + if (tabData.entries?.length) { let activeIndex = (tabData.index || tabData.entries.length) - 1; // Ensure the index is in bounds. @@ -3391,6 +3439,21 @@ preferredRemoteType, }); + if (tabData.zenWorkspace) { + tab.setAttribute("zen-workspace-id", tabData.zenWorkspace); + } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } + if (tabData.zenDefaultUserContextId) { + tab.setAttribute("zenDefaultUserContextId", "true"); + } + if (tabData.zenPinnedEntry) { + tab.setAttribute("zen-pinned-entry", tabData.zenPinnedEntry); + } if (select) { tabToSelect = tab; } @@ -3444,7 +3507,6 @@ this.tabContainer._invalidateCachedTabs(); } } - tab.initialize(); } @@ -3992,6 +4054,10 @@ return; } + for (tab of selectedTabs) { + gZenPinnedTabManager._removePinnedAttributes(tab, true); + } + this.removeTabs(selectedTabs); }, @@ -4309,6 +4375,13 @@ TelemetryStopwatch.start("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab); } + if (ZenWorkspaces.workspaceEnabled) { + let newTab = ZenWorkspaces.handleTabBeforeClose(aTab); + if (newTab) { + this.selectedTab = newTab; + } + } + // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { @@ -4324,6 +4397,10 @@ // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; + if (aTab.hasAttribute("zen-glance-tab")) { + gZenGlanceManager.closeGlance(); + return; + } if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, @@ -4472,7 +4549,7 @@ var closeWindow = false; var newTab = false; - if (aTab.visible && this.visibleTabs.length == 1) { + if (aTab.visible && this.visibleTabs.length == 1 && !aTab._closingGlance) { closeWindow = closeWindowWithLastTab != null ? closeWindowWithLastTab @@ -5265,10 +5342,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); }, - hideTab(aTab, aSource) { + hideTab(aTab, aSource, forZenWorkspaces = false) { if ( aTab.hidden || - aTab.pinned || + (aTab.pinned && !forZenWorkspaces) || aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. @@ -7181,6 +7258,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); + if (!this.mTab.selected) this.mTab.setAttribute("unread", "true"); gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; gBrowser.syncThrobberAnimations(this.mTab); @@ -8114,7 +8192,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !multiselectionContext; - + gZenPinnedTabManager.updatePinnedTabContextMenu(this.contextTab); // Move Tab items let contextMoveTabOptions = document.getElementById( "context_moveTabOptions" @@ -8148,7 +8226,7 @@ var TabContextMenu = { let contextMoveTabToStart = document.getElementById("context_moveToStart"); let isFirstTab = tabsToMove[0] == visibleTabs[0] || - tabsToMove[0] == visibleTabs[gBrowser.pinnedTabCount]; + tabsToMove[0] == visibleTabs[gBrowser._numVisiblePinTabs]; contextMoveTabToStart.disabled = isFirstTab && allSelectedTabsAdjacent; document.getElementById("context_openTabInWindow").disabled = @@ -8376,6 +8454,7 @@ var TabContextMenu = { if (this.contextTab.multiselected) { gBrowser.removeMultiSelectedTabs(); } else { + gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true); gBrowser.removeTab(this.contextTab, { animate: true }); } },