addon-sdk/source/lib/sdk/content/mod.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 } = require("chrome");
michael@0 11 const method = require("../../method/core");
michael@0 12 const { add, remove, iterator } = require("../lang/weak-set");
michael@0 13
michael@0 14 let getTargetWindow = method("getTargetWindow");
michael@0 15
michael@0 16 getTargetWindow.define(function (target) {
michael@0 17 if (target instanceof Ci.nsIDOMWindow)
michael@0 18 return target;
michael@0 19 if (target instanceof Ci.nsIDOMDocument)
michael@0 20 return target.defaultView || null;
michael@0 21
michael@0 22 return null;
michael@0 23 });
michael@0 24
michael@0 25 exports.getTargetWindow = getTargetWindow;
michael@0 26
michael@0 27 let attachTo = method("attachTo");
michael@0 28 exports.attachTo = attachTo;
michael@0 29
michael@0 30 let detachFrom = method("detatchFrom");
michael@0 31 exports.detachFrom = detachFrom;
michael@0 32
michael@0 33 function attach(modification, target) {
michael@0 34 if (!modification)
michael@0 35 return;
michael@0 36
michael@0 37 let window = getTargetWindow(target);
michael@0 38
michael@0 39 attachTo(modification, window);
michael@0 40
michael@0 41 // modification are stored per content; `window` reference can still be the
michael@0 42 // same even if the content is changed, therefore `document` is used instead.
michael@0 43 add(modification, window.document);
michael@0 44 }
michael@0 45 exports.attach = attach;
michael@0 46
michael@0 47 function detach(modification, target) {
michael@0 48 if (!modification)
michael@0 49 return;
michael@0 50
michael@0 51 if (target) {
michael@0 52 let window = getTargetWindow(target);
michael@0 53 detachFrom(modification, window);
michael@0 54 remove(modification, window.document);
michael@0 55 }
michael@0 56 else {
michael@0 57 let documents = iterator(modification);
michael@0 58 for (let document of documents) {
michael@0 59 detachFrom(modification, document.defaultView);
michael@0 60 remove(modification, document);
michael@0 61 }
michael@0 62 }
michael@0 63 }
michael@0 64 exports.detach = detach;

mercurial