Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = ["Sandbox"]; |
michael@0 | 8 | |
michael@0 | 9 | const {classes: Cc, interfaces: Ci, utils: Cu} = Components; |
michael@0 | 10 | |
michael@0 | 11 | const XHTML_NS = "http://www.w3.org/1999/xhtml"; |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 14 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 15 | |
michael@0 | 16 | XPCOMUtils.defineLazyModuleGetter(this, |
michael@0 | 17 | "Logger", |
michael@0 | 18 | "resource://gre/modules/identity/LogUtils.jsm"); |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * An object that represents a sandbox in an iframe loaded with aURL. The |
michael@0 | 22 | * callback provided to the constructor will be invoked when the sandbox is |
michael@0 | 23 | * ready to be used. The callback will receive this object as its only argument. |
michael@0 | 24 | * |
michael@0 | 25 | * You must call free() when you are finished with the sandbox to explicitly |
michael@0 | 26 | * free up all associated resources. |
michael@0 | 27 | * |
michael@0 | 28 | * @param aURL |
michael@0 | 29 | * (string) URL to load in the sandbox. |
michael@0 | 30 | * |
michael@0 | 31 | * @param aCallback |
michael@0 | 32 | * (function) Callback to be invoked with a Sandbox, when ready. |
michael@0 | 33 | */ |
michael@0 | 34 | this.Sandbox = function Sandbox(aURL, aCallback) { |
michael@0 | 35 | // Normalize the URL so the comparison in _makeSandboxContentLoaded works |
michael@0 | 36 | this._url = Services.io.newURI(aURL, null, null).spec; |
michael@0 | 37 | this._log("Creating sandbox for:", this._url); |
michael@0 | 38 | this._createFrame(); |
michael@0 | 39 | this._createSandbox(aCallback); |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | this.Sandbox.prototype = { |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Use the outer window ID as the identifier of the sandbox. |
michael@0 | 46 | */ |
michael@0 | 47 | get id() { |
michael@0 | 48 | return this._frame.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 49 | .getInterface(Ci.nsIDOMWindowUtils).outerWindowID; |
michael@0 | 50 | }, |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Reload the URL in the sandbox. This is useful to reuse a Sandbox (same |
michael@0 | 54 | * id and URL). |
michael@0 | 55 | */ |
michael@0 | 56 | reload: function Sandbox_reload(aCallback) { |
michael@0 | 57 | this._log("reload:", this.id, ":", this._url); |
michael@0 | 58 | this._createSandbox(function createdSandbox(aSandbox) { |
michael@0 | 59 | this._log("reloaded sandbox id:", aSandbox.id); |
michael@0 | 60 | aCallback(aSandbox); |
michael@0 | 61 | }.bind(this)); |
michael@0 | 62 | }, |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Frees the sandbox and releases the iframe created to host it. |
michael@0 | 66 | */ |
michael@0 | 67 | free: function Sandbox_free() { |
michael@0 | 68 | this._log("free:", this.id); |
michael@0 | 69 | this._container.removeChild(this._frame); |
michael@0 | 70 | this._frame = null; |
michael@0 | 71 | this._container = null; |
michael@0 | 72 | this._url = null; |
michael@0 | 73 | }, |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Creates an empty, hidden iframe and sets it to the _frame |
michael@0 | 77 | * property of this object. |
michael@0 | 78 | */ |
michael@0 | 79 | _createFrame: function Sandbox__createFrame() { |
michael@0 | 80 | let hiddenWindow = Services.appShell.hiddenDOMWindow; |
michael@0 | 81 | let doc = hiddenWindow.document; |
michael@0 | 82 | |
michael@0 | 83 | // Insert iframe in to create docshell. |
michael@0 | 84 | let frame = doc.createElementNS(XHTML_NS, "iframe"); |
michael@0 | 85 | frame.setAttribute("mozframetype", "content"); |
michael@0 | 86 | frame.sandbox = "allow-forms allow-scripts allow-same-origin"; |
michael@0 | 87 | frame.style.visibility = "collapse"; |
michael@0 | 88 | doc.documentElement.appendChild(frame); |
michael@0 | 89 | |
michael@0 | 90 | let docShell = frame.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 91 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 92 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 93 | .getInterface(Ci.nsIDocShell); |
michael@0 | 94 | |
michael@0 | 95 | // Stop about:blank from being loaded. |
michael@0 | 96 | docShell.stop(Ci.nsIWebNavigation.STOP_NETWORK); |
michael@0 | 97 | |
michael@0 | 98 | // Disable some types of content |
michael@0 | 99 | docShell.allowAuth = false; |
michael@0 | 100 | docShell.allowPlugins = false; |
michael@0 | 101 | docShell.allowImages = false; |
michael@0 | 102 | docShell.allowMedia = false; |
michael@0 | 103 | docShell.allowWindowControl = false; |
michael@0 | 104 | |
michael@0 | 105 | // Disable stylesheet loading since the document is not visible. |
michael@0 | 106 | let markupDocViewer = docShell.contentViewer |
michael@0 | 107 | .QueryInterface(Ci.nsIMarkupDocumentViewer); |
michael@0 | 108 | markupDocViewer.authorStyleDisabled = true; |
michael@0 | 109 | |
michael@0 | 110 | // Set instance properties. |
michael@0 | 111 | this._frame = frame; |
michael@0 | 112 | this._container = doc.documentElement; |
michael@0 | 113 | }, |
michael@0 | 114 | |
michael@0 | 115 | _createSandbox: function Sandbox__createSandbox(aCallback) { |
michael@0 | 116 | let self = this; |
michael@0 | 117 | function _makeSandboxContentLoaded(event) { |
michael@0 | 118 | self._log("_makeSandboxContentLoaded:", self.id, |
michael@0 | 119 | event.target.location.toString()); |
michael@0 | 120 | if (event.target != self._frame.contentDocument) { |
michael@0 | 121 | return; |
michael@0 | 122 | } |
michael@0 | 123 | self._frame.removeEventListener( |
michael@0 | 124 | "DOMWindowCreated", _makeSandboxContentLoaded, true |
michael@0 | 125 | ); |
michael@0 | 126 | |
michael@0 | 127 | aCallback(self); |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | this._frame.addEventListener("DOMWindowCreated", |
michael@0 | 131 | _makeSandboxContentLoaded, |
michael@0 | 132 | true); |
michael@0 | 133 | |
michael@0 | 134 | // Load the iframe. |
michael@0 | 135 | let webNav = this._frame.contentWindow |
michael@0 | 136 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 137 | .getInterface(Ci.nsIWebNavigation); |
michael@0 | 138 | |
michael@0 | 139 | webNav.loadURI( |
michael@0 | 140 | this._url, |
michael@0 | 141 | Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE, |
michael@0 | 142 | null, // referrer |
michael@0 | 143 | null, // postData |
michael@0 | 144 | null // headers |
michael@0 | 145 | ); |
michael@0 | 146 | |
michael@0 | 147 | }, |
michael@0 | 148 | |
michael@0 | 149 | _log: function Sandbox__log(...aMessageArgs) { |
michael@0 | 150 | Logger.log.apply(Logger, ["sandbox"].concat(aMessageArgs)); |
michael@0 | 151 | }, |
michael@0 | 152 | |
michael@0 | 153 | }; |