Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = ["TabAttributes"]; |
michael@0 | 8 | |
michael@0 | 9 | // A set of tab attributes to persist. We will read a given list of tab |
michael@0 | 10 | // attributes when collecting tab data and will re-set those attributes when |
michael@0 | 11 | // the given tab data is restored to a new tab. |
michael@0 | 12 | this.TabAttributes = Object.freeze({ |
michael@0 | 13 | persist: function (name) { |
michael@0 | 14 | return TabAttributesInternal.persist(name); |
michael@0 | 15 | }, |
michael@0 | 16 | |
michael@0 | 17 | get: function (tab) { |
michael@0 | 18 | return TabAttributesInternal.get(tab); |
michael@0 | 19 | }, |
michael@0 | 20 | |
michael@0 | 21 | set: function (tab, data = {}) { |
michael@0 | 22 | TabAttributesInternal.set(tab, data); |
michael@0 | 23 | } |
michael@0 | 24 | }); |
michael@0 | 25 | |
michael@0 | 26 | let TabAttributesInternal = { |
michael@0 | 27 | _attrs: new Set(), |
michael@0 | 28 | |
michael@0 | 29 | // We never want to directly read or write those attributes. |
michael@0 | 30 | // 'image' should not be accessed directly but handled by using the |
michael@0 | 31 | // gBrowser.getIcon()/setIcon() methods. |
michael@0 | 32 | // 'pending' is used internal by sessionstore and managed accordingly. |
michael@0 | 33 | _skipAttrs: new Set(["image", "pending"]), |
michael@0 | 34 | |
michael@0 | 35 | persist: function (name) { |
michael@0 | 36 | if (this._attrs.has(name) || this._skipAttrs.has(name)) { |
michael@0 | 37 | return false; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | this._attrs.add(name); |
michael@0 | 41 | return true; |
michael@0 | 42 | }, |
michael@0 | 43 | |
michael@0 | 44 | get: function (tab) { |
michael@0 | 45 | let data = {}; |
michael@0 | 46 | |
michael@0 | 47 | for (let name of this._attrs) { |
michael@0 | 48 | if (tab.hasAttribute(name)) { |
michael@0 | 49 | data[name] = tab.getAttribute(name); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | return data; |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | set: function (tab, data = {}) { |
michael@0 | 57 | // Clear attributes. |
michael@0 | 58 | for (let name of this._attrs) { |
michael@0 | 59 | tab.removeAttribute(name); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // Set attributes. |
michael@0 | 63 | for (let name in data) { |
michael@0 | 64 | tab.setAttribute(name, data[name]); |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | }; |
michael@0 | 68 |