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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "experimental" michael@0: }; michael@0: michael@0: const { Ci, Cc } = require("chrome"); michael@0: const { make: makeWindow, getHiddenWindow } = require("../window/utils"); michael@0: const { create: makeFrame, getDocShell } = require("../frame/utils"); michael@0: const { defer } = require("../core/promise"); michael@0: const { when: unload } = require("../system/unload"); michael@0: const cfxArgs = require("@test/options"); michael@0: michael@0: let addonPrincipal = Cc["@mozilla.org/systemprincipal;1"]. michael@0: createInstance(Ci.nsIPrincipal); michael@0: michael@0: let hiddenWindow = getHiddenWindow(); michael@0: michael@0: if (cfxArgs.parseable) { michael@0: console.info("hiddenWindow document.documentURI:" + michael@0: hiddenWindow.document.documentURI); michael@0: console.info("hiddenWindow document.readyState:" + michael@0: hiddenWindow.document.readyState); michael@0: } michael@0: michael@0: // Once Bug 565388 is fixed and shipped we'll be able to make invisible, michael@0: // permanent docShells. Meanwhile we create hidden top level window and michael@0: // use it's docShell. michael@0: let frame = makeFrame(hiddenWindow.document, { michael@0: nodeName: "iframe", michael@0: namespaceURI: "http://www.w3.org/1999/xhtml", michael@0: allowJavascript: true, michael@0: allowPlugins: true michael@0: }) michael@0: let docShell = getDocShell(frame); michael@0: let eventTarget = docShell.chromeEventHandler; michael@0: michael@0: // We need to grant docShell system principals in order to load XUL document michael@0: // from data URI into it. michael@0: docShell.createAboutBlankContentViewer(addonPrincipal); michael@0: michael@0: // Get a reference to the DOM window of the given docShell and load michael@0: // such document into that would allow us to create XUL iframes, that michael@0: // are necessary for hidden frames etc.. michael@0: let window = docShell.contentViewer.DOMDocument.defaultView; michael@0: window.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8,"; michael@0: michael@0: // Create a promise that is delivered once add-on window is interactive, michael@0: // used by add-on runner to defer add-on loading until window is ready. michael@0: let { promise, resolve } = defer(); michael@0: eventTarget.addEventListener("DOMContentLoaded", function handler(event) { michael@0: eventTarget.removeEventListener("DOMContentLoaded", handler, false); michael@0: resolve(); michael@0: }, false); michael@0: michael@0: michael@0: michael@0: exports.ready = promise; michael@0: exports.window = window; michael@0: michael@0: // Still close window on unload to claim memory back early. michael@0: unload(function() { michael@0: window.close() michael@0: frame.parentNode.removeChild(frame); michael@0: });