diff --git a/browser/components/customizableui/CustomizeMode.sys.mjs b/browser/components/customizableui/CustomizeMode.sys.mjs index 86c5e1b786b1ee788c95a1452d1e09b61062e27a..72888a7248e70b43dfbd62bd7972f9ead25d6c8b 100644 --- a/browser/components/customizableui/CustomizeMode.sys.mjs +++ b/browser/components/customizableui/CustomizeMode.sys.mjs @@ -27,7 +27,6 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { AddonManager: "resource://gre/modules/AddonManager.sys.mjs", DragPositionManager: "resource:///modules/DragPositionManager.sys.mjs", - SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", URILoadingHelper: "resource:///modules/URILoadingHelper.sys.mjs", }); ChromeUtils.defineModuleGetter( @@ -225,7 +224,6 @@ CustomizeMode.prototype = { gTab = aTab; gTab.setAttribute("customizemode", "true"); - lazy.SessionStore.persistTabAttribute("customizemode"); if (gTab.linkedPanel) { gTab.linkedBrowser.stop(); diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs index 2c50de65f83687bc27292bf1eb850e8d75ca6c9d..82e5b6748175523592bfc48d365f7d0d54be84ee 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -434,10 +434,6 @@ export var SessionStore = { SessionStoreInternal.deleteCustomGlobalValue(aKey); }, - persistTabAttribute: function ss_persistTabAttribute(aName) { - SessionStoreInternal.persistTabAttribute(aName); - }, - restoreLastSession: function ss_restoreLastSession() { SessionStoreInternal.restoreLastSession(); }, @@ -3615,12 +3611,6 @@ var SessionStoreInternal = { this.saveStateDelayed(); }, - persistTabAttribute: function ssi_persistTabAttribute(aName) { - if (lazy.TabAttributes.persist(aName)) { - this.saveStateDelayed(); - } - }, - /** * Undoes the closing of a tab or window which corresponds * to the closedId passed in. @@ -4782,13 +4772,6 @@ var SessionStoreInternal = { tab.updateLastAccessed(tabData.lastAccessed); } - if ("attributes" in tabData) { - // Ensure that we persist tab attributes restored from previous sessions. - Object.keys(tabData.attributes).forEach(a => - lazy.TabAttributes.persist(a) - ); - } - if (!tabData.entries) { tabData.entries = []; } diff --git a/browser/components/sessionstore/TabAttributes.sys.mjs b/browser/components/sessionstore/TabAttributes.sys.mjs index 1c7f54b6abcbe4748617e1895640171d5f71b9c4..ea53156d129cba5309702446a3994747af81c069 100644 --- a/browser/components/sessionstore/TabAttributes.sys.mjs +++ b/browser/components/sessionstore/TabAttributes.sys.mjs @@ -2,27 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -// We never want to directly read or write these attributes. -// 'image' should not be accessed directly but handled by using the -// gBrowser.getIcon()/setIcon() methods. -// 'muted' should not be accessed directly but handled by using the -// tab.linkedBrowser.audioMuted/toggleMuteAudio methods. -// 'pending' is used internal by sessionstore and managed accordingly. -const ATTRIBUTES_TO_SKIP = new Set([ - "image", - "muted", - "pending", - "skipbackgroundnotify", -]); +// Tab attributes which are persisted & restored by SessionStore. +const PERSISTED_ATTRIBUTES = ["customizemode"]; // A set of tab attributes to persist. We will read a given list of tab // attributes when collecting tab data and will re-set those attributes when // the given tab data is restored to a new tab. export var TabAttributes = Object.freeze({ - persist(name) { - return TabAttributesInternal.persist(name); - }, - get(tab) { return TabAttributesInternal.get(tab); }, @@ -33,21 +19,10 @@ export var TabAttributes = Object.freeze({ }); var TabAttributesInternal = { - _attrs: new Set(), - - persist(name) { - if (this._attrs.has(name) || ATTRIBUTES_TO_SKIP.has(name)) { - return false; - } - - this._attrs.add(name); - return true; - }, - get(tab) { let data = {}; - for (let name of this._attrs) { + for (let name of PERSISTED_ATTRIBUTES) { if (tab.hasAttribute(name)) { data[name] = tab.getAttribute(name); } @@ -57,15 +32,11 @@ var TabAttributesInternal = { }, set(tab, data = {}) { - // Clear attributes. - for (let name of this._attrs) { + // Clear & Set attributes. + for (let name of PERSISTED_ATTRIBUTES) { tab.removeAttribute(name); - } - - // Set attributes. - for (let [name, value] of Object.entries(data)) { - if (!ATTRIBUTES_TO_SKIP.has(name)) { - tab.setAttribute(name, value); + if (name in data) { + tab.setAttribute(name, data[name]); } } }, diff --git a/browser/components/sessionstore/test/browser_attributes.js b/browser/components/sessionstore/test/browser_attributes.js index 336573a50862ab8ae271143762c439a977ed542e..db349a31a251420af6795b55c77dd91e8f6be965 100644 --- a/browser/components/sessionstore/test/browser_attributes.js +++ b/browser/components/sessionstore/test/browser_attributes.js @@ -38,45 +38,68 @@ add_task(async function test() { ok(tab.hasAttribute("muted"), "tab.muted exists"); // Make sure we do not persist 'image' and 'muted' attributes. - ss.persistTabAttribute("image"); - ss.persistTabAttribute("muted"); let { attributes } = JSON.parse(ss.getTabState(tab)); ok(!("image" in attributes), "'image' attribute not saved"); ok(!("muted" in attributes), "'muted' attribute not saved"); - ok(!("custom" in attributes), "'custom' attribute not saved"); - - // Test persisting a custom attribute. - tab.setAttribute("custom", "foobar"); - ss.persistTabAttribute("custom"); - - ({ attributes } = JSON.parse(ss.getTabState(tab))); - is(attributes.custom, "foobar", "'custom' attribute is correct"); - - // Make sure we're backwards compatible and restore old 'image' attributes. + ok(!("customizemode" in attributes), "'customizemode' attribute not saved"); + + // Test persisting a customizemode attribute. + { + let customizationReady = BrowserTestUtils.waitForEvent( + gNavToolbox, + "customizationready" + ); + gCustomizeMode.enter(); + await customizationReady; + } + + let customizeIcon = gBrowser.getIcon(gBrowser.selectedTab); + ({ attributes } = JSON.parse(ss.getTabState(gBrowser.selectedTab))); + ok(!("image" in attributes), "'image' attribute not saved"); + is(attributes.customizemode, "true", "'customizemode' attribute is correct"); + + { + let afterCustomization = BrowserTestUtils.waitForEvent( + gNavToolbox, + "aftercustomization" + ); + gCustomizeMode.exit(); + await afterCustomization; + } + + // Test restoring a customizemode tab. let state = { - entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }], - attributes: { custom: "foobaz" }, - image: gBrowser.getIcon(tab), + entries: [], + attributes: { customizemode: "true", nonpersisted: "true" }, }; + // Customize mode doesn't like being restored on top of a non-blank tab. + // For the moment, it appears it isn't possible to restore customizemode onto + // an existing non-blank tab outside of tests, however this may be a latent + // bug if we ever try to do that in the future. + let principal = Services.scriptSecurityManager.createNullPrincipal({}); + tab.linkedBrowser.createAboutBlankContentViewer(principal, principal); + // Prepare a pending tab waiting to be restored. let promise = promiseTabRestoring(tab); ss.setTabState(tab, JSON.stringify(state)); await promise; ok(tab.hasAttribute("pending"), "tab is pending"); - is(gBrowser.getIcon(tab), state.image, "tab has correct icon"); + ok(tab.hasAttribute("customizemode"), "tab is in customizemode"); + ok(!tab.hasAttribute("nonpersisted"), "tab has no nonpersisted attribute"); + is(gBrowser.getIcon(tab), customizeIcon, "tab has correct icon"); ok(!state.attributes.image, "'image' attribute not saved"); // Let the pending tab load. gBrowser.selectedTab = tab; - await promiseTabRestored(tab); // Ensure no 'image' or 'pending' attributes are stored. ({ attributes } = JSON.parse(ss.getTabState(tab))); ok(!("image" in attributes), "'image' attribute not saved"); ok(!("pending" in attributes), "'pending' attribute not saved"); - is(attributes.custom, "foobaz", "'custom' attribute is correct"); + ok(!("nonpersisted" in attributes), "'nonpersisted' attribute not saved"); + is(attributes.customizemode, "true", "'customizemode' attribute is correct"); // Clean up. gBrowser.removeTab(tab);