michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["DocShellCapabilities"]; michael@0: michael@0: /** michael@0: * The external API exported by this module. michael@0: */ michael@0: this.DocShellCapabilities = Object.freeze({ michael@0: collect: function (docShell) { michael@0: return DocShellCapabilitiesInternal.collect(docShell); michael@0: }, michael@0: michael@0: restore: function (docShell, disallow) { michael@0: return DocShellCapabilitiesInternal.restore(docShell, disallow); michael@0: }, michael@0: }); michael@0: michael@0: /** michael@0: * Internal functionality to save and restore the docShell.allow* properties. michael@0: */ michael@0: let DocShellCapabilitiesInternal = { michael@0: // List of docShell capabilities to (re)store. These are automatically michael@0: // retrieved from a given docShell if not already collected before. michael@0: // This is made so they're automatically in sync with all nsIDocShell.allow* michael@0: // properties. michael@0: caps: null, michael@0: michael@0: allCapabilities: function (docShell) { michael@0: if (!this.caps) { michael@0: let keys = Object.keys(docShell); michael@0: this.caps = keys.filter(k => k.startsWith("allow")).map(k => k.slice(5)); michael@0: } michael@0: return this.caps; michael@0: }, michael@0: michael@0: collect: function (docShell) { michael@0: let caps = this.allCapabilities(docShell); michael@0: return caps.filter(cap => !docShell["allow" + cap]); michael@0: }, michael@0: michael@0: restore: function (docShell, disallow) { michael@0: let caps = this.allCapabilities(docShell); michael@0: for (let cap of caps) michael@0: docShell["allow" + cap] = !disallow.has(cap); michael@0: }, michael@0: };