browser/components/sessionstore/src/TabAttributes.jsm

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

mercurial