tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TabAttributes.sys.mjs (1151B)


      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 // Tab attributes which are persisted & restored by SessionStore.
      6 const PERSISTED_ATTRIBUTES = ["customizemode"];
      7 
      8 // A set of tab attributes to persist. We will read a given list of tab
      9 // attributes when collecting tab data and will re-set those attributes when
     10 // the given tab data is restored to a new tab.
     11 export var TabAttributes = Object.freeze({
     12  get(tab) {
     13    return TabAttributesInternal.get(tab);
     14  },
     15 
     16  set(tab, data = {}) {
     17    TabAttributesInternal.set(tab, data);
     18  },
     19 });
     20 
     21 var TabAttributesInternal = {
     22  get(tab) {
     23    let data = {};
     24 
     25    for (let name of PERSISTED_ATTRIBUTES) {
     26      if (tab.hasAttribute(name)) {
     27        data[name] = tab.getAttribute(name);
     28      }
     29    }
     30 
     31    return data;
     32  },
     33 
     34  set(tab, data = {}) {
     35    // Clear & Set attributes.
     36    for (let name of PERSISTED_ATTRIBUTES) {
     37      tab.removeAttribute(name);
     38      if (name in data) {
     39        tab.setAttribute(name, data[name]);
     40      }
     41    }
     42  },
     43 };