browser/components/sessionstore/src/DocShellCapabilities.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/src/DocShellCapabilities.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +* License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 +* You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +this.EXPORTED_SYMBOLS = ["DocShellCapabilities"];
    1.11 +
    1.12 +/**
    1.13 + * The external API exported by this module.
    1.14 + */
    1.15 +this.DocShellCapabilities = Object.freeze({
    1.16 +  collect: function (docShell) {
    1.17 +    return DocShellCapabilitiesInternal.collect(docShell);
    1.18 +  },
    1.19 +
    1.20 +  restore: function (docShell, disallow) {
    1.21 +    return DocShellCapabilitiesInternal.restore(docShell, disallow);
    1.22 +  },
    1.23 +});
    1.24 +
    1.25 +/**
    1.26 + * Internal functionality to save and restore the docShell.allow* properties.
    1.27 + */
    1.28 +let DocShellCapabilitiesInternal = {
    1.29 +  // List of docShell capabilities to (re)store. These are automatically
    1.30 +  // retrieved from a given docShell if not already collected before.
    1.31 +  // This is made so they're automatically in sync with all nsIDocShell.allow*
    1.32 +  // properties.
    1.33 +  caps: null,
    1.34 +
    1.35 +  allCapabilities: function (docShell) {
    1.36 +    if (!this.caps) {
    1.37 +      let keys = Object.keys(docShell);
    1.38 +      this.caps = keys.filter(k => k.startsWith("allow")).map(k => k.slice(5));
    1.39 +    }
    1.40 +    return this.caps;
    1.41 +  },
    1.42 +
    1.43 +  collect: function (docShell) {
    1.44 +    let caps = this.allCapabilities(docShell);
    1.45 +    return caps.filter(cap => !docShell["allow" + cap]);
    1.46 +  },
    1.47 +
    1.48 +  restore: function (docShell, disallow) {
    1.49 +    let caps = this.allCapabilities(docShell);
    1.50 +    for (let cap of caps)
    1.51 +      docShell["allow" + cap] = !disallow.has(cap);
    1.52 +  },
    1.53 +};

mercurial