2013-10-25 12:06:14 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["TabAttributes"];
|
2013-10-25 12:06:14 +04:00
|
|
|
|
2016-06-01 15:48:18 +03:00
|
|
|
// 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.
|
2017-10-20 04:19:57 +03:00
|
|
|
// 'iconloadingprincipal' is same as 'image' that it should be handled by
|
2016-09-13 16:18:37 +03:00
|
|
|
// using the gBrowser.getIcon()/setIcon() methods.
|
2017-10-20 04:19:57 +03:00
|
|
|
const ATTRIBUTES_TO_SKIP = new Set(["image", "muted", "pending", "iconloadingprincipal",
|
2018-05-04 07:22:16 +03:00
|
|
|
"skipbackgroundnotify"]);
|
2016-06-01 15:48:18 +03:00
|
|
|
|
2013-10-25 12:06:14 +04:00
|
|
|
// 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.
|
2018-02-23 22:50:01 +03:00
|
|
|
var TabAttributes = Object.freeze({
|
2017-03-10 22:51:20 +03:00
|
|
|
persist(name) {
|
2013-10-25 12:06:14 +04:00
|
|
|
return TabAttributesInternal.persist(name);
|
|
|
|
},
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
get(tab) {
|
2013-10-25 12:06:14 +04:00
|
|
|
return TabAttributesInternal.get(tab);
|
|
|
|
},
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
set(tab, data = {}) {
|
2013-10-25 12:06:14 +04:00
|
|
|
TabAttributesInternal.set(tab, data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var TabAttributesInternal = {
|
2015-10-14 20:36:09 +03:00
|
|
|
_attrs: new Set(),
|
2013-10-25 12:06:14 +04:00
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
persist(name) {
|
2016-06-01 15:48:18 +03:00
|
|
|
if (this._attrs.has(name) || ATTRIBUTES_TO_SKIP.has(name)) {
|
2013-10-25 12:06:14 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._attrs.add(name);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
get(tab) {
|
2013-10-25 12:06:14 +04:00
|
|
|
let data = {};
|
|
|
|
|
|
|
|
for (let name of this._attrs) {
|
|
|
|
if (tab.hasAttribute(name)) {
|
|
|
|
data[name] = tab.getAttribute(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
set(tab, data = {}) {
|
2013-10-25 12:06:14 +04:00
|
|
|
// Clear attributes.
|
|
|
|
for (let name of this._attrs) {
|
|
|
|
tab.removeAttribute(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set attributes.
|
|
|
|
for (let name in data) {
|
2016-06-01 15:48:18 +03:00
|
|
|
if (!ATTRIBUTES_TO_SKIP.has(name)) {
|
2015-06-15 11:57:00 +03:00
|
|
|
tab.setAttribute(name, data[name]);
|
|
|
|
}
|
2013-10-25 12:06:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|