From 0183de5382a7241411e7c0f4ff01f46beba9af63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Sat, 12 Oct 2024 18:15:09 +0200 Subject: [PATCH] feat: Store triggering principal for pinned tabs This commit adds the ability to store the triggering principal for pinned tabs in the session store. This allows us to correctly restore pinned tabs when a user has multiple profiles open, as the triggering principal will be used to determine which profile the pinned tab belongs to. The following changes were made: - Added a new attribute, "zen-pinned-triggering-principal", to pinned tabs to store the triggering principal. - Updated the session store to store and restore the triggering principal for pinned tabs. - Updated the `ZenPinnedTabManager` to set and get the triggering principal for pinned tabs. This change is necessary to ensure that pinned tabs are correctly restored when reset to pinned URL. --- src/ZenPinnedTabManager.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ZenPinnedTabManager.mjs b/src/ZenPinnedTabManager.mjs index e3a9c48..285e56b 100644 --- a/src/ZenPinnedTabManager.mjs +++ b/src/ZenPinnedTabManager.mjs @@ -9,7 +9,7 @@ constructor() { XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabRestorePinnedTabsToPinnedUrl', 'zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url', false); XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch'); - + ChromeUtils.defineESModuleGetters(lazy, {E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs"}); this.#listenPinnedTabEvents(); } @@ -97,12 +97,14 @@ tab.setAttribute("zen-pinned-url", tab.linkedBrowser.currentURI.spec); tab.setAttribute("zen-pinned-title", tab.getAttribute("label")); tab.setAttribute("zen-pinned-icon", tab.linkedBrowser.mIconURL); + tab.setAttribute("zen-pinned-triggering-principal", lazy.E10SUtils.serializePrincipal(tab.linkedBrowser.contentPrincipal)); } _removePinnedAttributes(tab) { tab.removeAttribute("zen-pinned-url"); tab.removeAttribute("zen-pinned-title"); tab.removeAttribute("zen-pinned-icon"); + tab.removeAttribute("zen-pinned-triggering-principal"); } _initClosePinnedTabShortcut() { @@ -117,12 +119,14 @@ tabData.zenPinnedUrl = tab.getAttribute("zen-pinned-url"); tabData.zenPinnedTitle = tab.getAttribute("zen-pinned-title"); tabData.zenPinnedIcon = tab.getAttribute("zen-pinned-icon"); + tabData.zenPinnedTriggeringPrincipal = tab.getAttribute("zen-pinned-triggering-principal"); } updatePinnedTabForSessionRestore(tabData, tab) { !!tabData.zenPinnedUrl ? tab.setAttribute("zen-pinned-url", tabData.zenPinnedUrl) : tab.removeAttribute("zen-pinned-url"); !!tabData.zenPinnedTitle ? tab.setAttribute("zen-pinned-title", tabData.zenPinnedTitle) : tab.removeAttribute("zen-pinned-title"); !!tabData.zenPinnedIcon ? tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon) : tab.removeAttribute("zen-pinned-icon"); + !!tabData.zenPinnedTriggeringPrincipal ? tab.setAttribute("zen-pinned-triggering-principal", tabData.zenPinnedTriggeringPrincipal) : tab.removeAttribute("zen-pinned-triggering-principal"); } _onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) { @@ -183,12 +187,13 @@ const url = tab.getAttribute("zen-pinned-url"); const title = tab.getAttribute("zen-pinned-title"); const icon = tab.getAttribute("zen-pinned-icon"); + const triggeringPrincipal_base64 = tab.getAttribute("zen-pinned-triggering-principal"); if (url) { const tabState = SessionStore.getTabState(tab); const state = JSON.parse(tabState); - state.entries = [{url, title}]; + state.entries = [{url, title, triggeringPrincipal_base64}]; state.image = icon; state.index = 0; @@ -212,7 +217,7 @@ resetPinnedTabData(tabData) { if (lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && tabData.pinned && tabData.zenPinnedUrl) { - tabData.entries = [{url: tabData.zenPinnedUrl, title: tabData.zenPinnedTitle}]; + tabData.entries = [{url: tabData.zenPinnedUrl, title: tabData.zenPinnedTitle, triggeringPrincipal_base64: tabData.zenPinnedTriggeringPrincipal}]; tabData.image = tabData.zenPinnedIcon; tabData.index = 0; }