addon-sdk/source/lib/sdk/window/events.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": "unstable"
michael@0 8 };
michael@0 9
michael@0 10 const { Ci } = require("chrome");
michael@0 11 const { observe } = require("../event/chrome");
michael@0 12 const { open } = require("../event/dom");
michael@0 13 const { windows } = require("../window/utils");
michael@0 14 const { filter, merge, map, expand } = require("../event/utils");
michael@0 15
michael@0 16 // Function registers single shot event listeners for relevant window events
michael@0 17 // that forward events to exported event stream.
michael@0 18 function eventsFor(window) {
michael@0 19 let interactive = open(window, "DOMContentLoaded", { capture: true });
michael@0 20 let complete = open(window, "load", { capture: true });
michael@0 21 let states = merge([interactive, complete]);
michael@0 22 let changes = filter(states, function({target}) target === window.document);
michael@0 23 return map(changes, function({type, target}) {
michael@0 24 return { type: type, target: target.defaultView }
michael@0 25 });
michael@0 26 }
michael@0 27
michael@0 28 // In addition to observing windows that are open we also observe windows
michael@0 29 // that are already already opened in case they're in process of loading.
michael@0 30 let opened = windows(null, { includePrivate: true });
michael@0 31 let currentEvents = merge(opened.map(eventsFor));
michael@0 32
michael@0 33 // Register system event listeners for top level window open / close.
michael@0 34 function rename({type, target, data}) {
michael@0 35 return { type: rename[type], target: target, data: data }
michael@0 36 }
michael@0 37 rename.domwindowopened = "open";
michael@0 38 rename.domwindowclosed = "close";
michael@0 39
michael@0 40 let openEvents = map(observe("domwindowopened"), rename);
michael@0 41 let closeEvents = map(observe("domwindowclosed"), rename);
michael@0 42 let futureEvents = expand(openEvents, function({target}) eventsFor(target));
michael@0 43
michael@0 44 let channel = merge([currentEvents, futureEvents,
michael@0 45 openEvents, closeEvents]);
michael@0 46 exports.events = channel;

mercurial