michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["TabAttributes"]; michael@0: michael@0: // A set of tab attributes to persist. We will read a given list of tab michael@0: // attributes when collecting tab data and will re-set those attributes when michael@0: // the given tab data is restored to a new tab. michael@0: this.TabAttributes = Object.freeze({ michael@0: persist: function (name) { michael@0: return TabAttributesInternal.persist(name); michael@0: }, michael@0: michael@0: get: function (tab) { michael@0: return TabAttributesInternal.get(tab); michael@0: }, michael@0: michael@0: set: function (tab, data = {}) { michael@0: TabAttributesInternal.set(tab, data); michael@0: } michael@0: }); michael@0: michael@0: let TabAttributesInternal = { michael@0: _attrs: new Set(), michael@0: michael@0: // We never want to directly read or write those attributes. michael@0: // 'image' should not be accessed directly but handled by using the michael@0: // gBrowser.getIcon()/setIcon() methods. michael@0: // 'pending' is used internal by sessionstore and managed accordingly. michael@0: _skipAttrs: new Set(["image", "pending"]), michael@0: michael@0: persist: function (name) { michael@0: if (this._attrs.has(name) || this._skipAttrs.has(name)) { michael@0: return false; michael@0: } michael@0: michael@0: this._attrs.add(name); michael@0: return true; michael@0: }, michael@0: michael@0: get: function (tab) { michael@0: let data = {}; michael@0: michael@0: for (let name of this._attrs) { michael@0: if (tab.hasAttribute(name)) { michael@0: data[name] = tab.getAttribute(name); michael@0: } michael@0: } michael@0: michael@0: return data; michael@0: }, michael@0: michael@0: set: function (tab, data = {}) { michael@0: // Clear attributes. michael@0: for (let name of this._attrs) { michael@0: tab.removeAttribute(name); michael@0: } michael@0: michael@0: // Set attributes. michael@0: for (let name in data) { michael@0: tab.setAttribute(name, data[name]); michael@0: } michael@0: } michael@0: }; michael@0: