addon-sdk/source/lib/sdk/addon/window.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 module.metadata = {
michael@0 7 "stability": "experimental"
michael@0 8 };
michael@0 9
michael@0 10 const { Ci, Cc } = require("chrome");
michael@0 11 const { make: makeWindow, getHiddenWindow } = require("../window/utils");
michael@0 12 const { create: makeFrame, getDocShell } = require("../frame/utils");
michael@0 13 const { defer } = require("../core/promise");
michael@0 14 const { when: unload } = require("../system/unload");
michael@0 15 const cfxArgs = require("@test/options");
michael@0 16
michael@0 17 let addonPrincipal = Cc["@mozilla.org/systemprincipal;1"].
michael@0 18 createInstance(Ci.nsIPrincipal);
michael@0 19
michael@0 20 let hiddenWindow = getHiddenWindow();
michael@0 21
michael@0 22 if (cfxArgs.parseable) {
michael@0 23 console.info("hiddenWindow document.documentURI:" +
michael@0 24 hiddenWindow.document.documentURI);
michael@0 25 console.info("hiddenWindow document.readyState:" +
michael@0 26 hiddenWindow.document.readyState);
michael@0 27 }
michael@0 28
michael@0 29 // Once Bug 565388 is fixed and shipped we'll be able to make invisible,
michael@0 30 // permanent docShells. Meanwhile we create hidden top level window and
michael@0 31 // use it's docShell.
michael@0 32 let frame = makeFrame(hiddenWindow.document, {
michael@0 33 nodeName: "iframe",
michael@0 34 namespaceURI: "http://www.w3.org/1999/xhtml",
michael@0 35 allowJavascript: true,
michael@0 36 allowPlugins: true
michael@0 37 })
michael@0 38 let docShell = getDocShell(frame);
michael@0 39 let eventTarget = docShell.chromeEventHandler;
michael@0 40
michael@0 41 // We need to grant docShell system principals in order to load XUL document
michael@0 42 // from data URI into it.
michael@0 43 docShell.createAboutBlankContentViewer(addonPrincipal);
michael@0 44
michael@0 45 // Get a reference to the DOM window of the given docShell and load
michael@0 46 // such document into that would allow us to create XUL iframes, that
michael@0 47 // are necessary for hidden frames etc..
michael@0 48 let window = docShell.contentViewer.DOMDocument.defaultView;
michael@0 49 window.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8,<window/>";
michael@0 50
michael@0 51 // Create a promise that is delivered once add-on window is interactive,
michael@0 52 // used by add-on runner to defer add-on loading until window is ready.
michael@0 53 let { promise, resolve } = defer();
michael@0 54 eventTarget.addEventListener("DOMContentLoaded", function handler(event) {
michael@0 55 eventTarget.removeEventListener("DOMContentLoaded", handler, false);
michael@0 56 resolve();
michael@0 57 }, false);
michael@0 58
michael@0 59
michael@0 60
michael@0 61 exports.ready = promise;
michael@0 62 exports.window = window;
michael@0 63
michael@0 64 // Still close window on unload to claim memory back early.
michael@0 65 unload(function() {
michael@0 66 window.close()
michael@0 67 frame.parentNode.removeChild(frame);
michael@0 68 });

mercurial