browser/components/sessionstore/src/TabAttributes.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 "use strict";
     7 this.EXPORTED_SYMBOLS = ["TabAttributes"];
     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   },
    17   get: function (tab) {
    18     return TabAttributesInternal.get(tab);
    19   },
    21   set: function (tab, data = {}) {
    22     TabAttributesInternal.set(tab, data);
    23   }
    24 });
    26 let TabAttributesInternal = {
    27   _attrs: new Set(),
    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"]),
    35   persist: function (name) {
    36     if (this._attrs.has(name) || this._skipAttrs.has(name)) {
    37       return false;
    38     }
    40     this._attrs.add(name);
    41     return true;
    42   },
    44   get: function (tab) {
    45     let data = {};
    47     for (let name of this._attrs) {
    48       if (tab.hasAttribute(name)) {
    49         data[name] = tab.getAttribute(name);
    50       }
    51     }
    53     return data;
    54   },
    56   set: function (tab, data = {}) {
    57     // Clear attributes.
    58     for (let name of this._attrs) {
    59       tab.removeAttribute(name);
    60     }
    62     // Set attributes.
    63     for (let name in data) {
    64       tab.setAttribute(name, data[name]);
    65     }
    66   }
    67 };

mercurial