browser/components/sessionstore/src/DocShellCapabilities.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 = ["DocShellCapabilities"];
     9 /**
    10  * The external API exported by this module.
    11  */
    12 this.DocShellCapabilities = Object.freeze({
    13   collect: function (docShell) {
    14     return DocShellCapabilitiesInternal.collect(docShell);
    15   },
    17   restore: function (docShell, disallow) {
    18     return DocShellCapabilitiesInternal.restore(docShell, disallow);
    19   },
    20 });
    22 /**
    23  * Internal functionality to save and restore the docShell.allow* properties.
    24  */
    25 let DocShellCapabilitiesInternal = {
    26   // List of docShell capabilities to (re)store. These are automatically
    27   // retrieved from a given docShell if not already collected before.
    28   // This is made so they're automatically in sync with all nsIDocShell.allow*
    29   // properties.
    30   caps: null,
    32   allCapabilities: function (docShell) {
    33     if (!this.caps) {
    34       let keys = Object.keys(docShell);
    35       this.caps = keys.filter(k => k.startsWith("allow")).map(k => k.slice(5));
    36     }
    37     return this.caps;
    38   },
    40   collect: function (docShell) {
    41     let caps = this.allCapabilities(docShell);
    42     return caps.filter(cap => !docShell["allow" + cap]);
    43   },
    45   restore: function (docShell, disallow) {
    46     let caps = this.allCapabilities(docShell);
    47     for (let cap of caps)
    48       docShell["allow" + cap] = !disallow.has(cap);
    49   },
    50 };

mercurial