addon-sdk/source/lib/sdk/frame/utils.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
michael@0 5 'use strict';
michael@0 6
michael@0 7 module.metadata = {
michael@0 8 "stability": "experimental"
michael@0 9 };
michael@0 10
michael@0 11 const { Ci } = require("chrome");
michael@0 12 const XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
michael@0 13
michael@0 14 function eventTarget(frame) {
michael@0 15 return getDocShell(frame).chromeEventHandler;
michael@0 16 }
michael@0 17 exports.eventTarget = eventTarget;
michael@0 18
michael@0 19 function getDocShell(frame) {
michael@0 20 let { frameLoader } = frame.QueryInterface(Ci.nsIFrameLoaderOwner);
michael@0 21 return frameLoader && frameLoader.docShell;
michael@0 22 }
michael@0 23 exports.getDocShell = getDocShell;
michael@0 24
michael@0 25 /**
michael@0 26 * Creates a XUL `browser` element in a privileged document.
michael@0 27 * @params {nsIDOMDocument} document
michael@0 28 * @params {String} options.type
michael@0 29 * By default is 'content' for possible values see:
michael@0 30 * https://developer.mozilla.org/en/XUL/iframe#a-browser.type
michael@0 31 * @params {String} options.uri
michael@0 32 * URI of the document to be loaded into created frame.
michael@0 33 * @params {Boolean} options.remote
michael@0 34 * If `true` separate process will be used for this frame, also in such
michael@0 35 * case all the following options are ignored.
michael@0 36 * @params {Boolean} options.allowAuth
michael@0 37 * Whether to allow auth dialogs. Defaults to `false`.
michael@0 38 * @params {Boolean} options.allowJavascript
michael@0 39 * Whether to allow Javascript execution. Defaults to `false`.
michael@0 40 * @params {Boolean} options.allowPlugins
michael@0 41 * Whether to allow plugin execution. Defaults to `false`.
michael@0 42 */
michael@0 43 function create(target, options) {
michael@0 44 target = target instanceof Ci.nsIDOMDocument ? target.documentElement :
michael@0 45 target instanceof Ci.nsIDOMWindow ? target.document.documentElement :
michael@0 46 target;
michael@0 47 options = options || {};
michael@0 48 let remote = options.remote || false;
michael@0 49 let namespaceURI = options.namespaceURI || XUL;
michael@0 50 let isXUL = namespaceURI === XUL;
michael@0 51 let nodeName = isXUL && options.browser ? 'browser' : 'iframe';
michael@0 52 let document = target.ownerDocument;
michael@0 53
michael@0 54 let frame = document.createElementNS(namespaceURI, nodeName);
michael@0 55 // Type="content" is mandatory to enable stuff here:
michael@0 56 // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1776
michael@0 57 frame.setAttribute('type', options.type || 'content');
michael@0 58 frame.setAttribute('src', options.uri || 'about:blank');
michael@0 59
michael@0 60 target.appendChild(frame);
michael@0 61
michael@0 62 // Load in separate process if `options.remote` is `true`.
michael@0 63 // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1347
michael@0 64 if (remote) {
michael@0 65 if (isXUL) {
michael@0 66 // We remove XBL binding to avoid execution of code that is not going to
michael@0 67 // work because browser has no docShell attribute in remote mode
michael@0 68 // (for example)
michael@0 69 frame.setAttribute('style', '-moz-binding: none;');
michael@0 70 frame.setAttribute('remote', 'true');
michael@0 71 }
michael@0 72 else {
michael@0 73 frame.QueryInterface(Ci.nsIMozBrowserFrame);
michael@0 74 frame.createRemoteFrameLoader(null);
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78
michael@0 79
michael@0 80 // If browser is remote it won't have a `docShell`.
michael@0 81 if (!remote) {
michael@0 82 let docShell = getDocShell(frame);
michael@0 83 docShell.allowAuth = options.allowAuth || false;
michael@0 84 docShell.allowJavascript = options.allowJavascript || false;
michael@0 85 docShell.allowPlugins = options.allowPlugins || false;
michael@0 86
michael@0 87 // Control whether the document can move/resize the window. Requires
michael@0 88 // recently added platform capability, so we test to avoid exceptions
michael@0 89 // in cases where capability is not present yet.
michael@0 90 if ("allowWindowControl" in docShell && "allowWindowControl" in options)
michael@0 91 docShell.allowWindowControl = !!options.allowWindowControl;
michael@0 92 }
michael@0 93
michael@0 94 return frame;
michael@0 95 }
michael@0 96 exports.create = create;
michael@0 97
michael@0 98 function swapFrameLoaders(from, to)
michael@0 99 from.QueryInterface(Ci.nsIFrameLoaderOwner).swapFrameLoaders(to)
michael@0 100 exports.swapFrameLoaders = swapFrameLoaders;

mercurial