addon-sdk/source/lib/sdk/content/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
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 { open } = require("../event/dom");
michael@0 13 const { observe } = require("../event/chrome");
michael@0 14 const { filter, merge, map, expand } = require("../event/utils");
michael@0 15 const { windows } = require("../window/utils");
michael@0 16 const { events: windowEvents } = require("sdk/window/events");
michael@0 17
michael@0 18 // Note: Please note that even though pagehide event is included
michael@0 19 // it's not observable reliably since it's not always triggered
michael@0 20 // when closing tabs. Implementation can be imrpoved once that
michael@0 21 // event will be necessary.
michael@0 22 let TYPES = ["DOMContentLoaded", "load", "pageshow", "pagehide"];
michael@0 23
michael@0 24 let insert = observe("document-element-inserted");
michael@0 25 let windowCreate = merge([
michael@0 26 observe("content-document-global-created"),
michael@0 27 observe("chrome-document-global-created")
michael@0 28 ]);
michael@0 29 let create = map(windowCreate, function({target, data, type}) {
michael@0 30 return { target: target.document, type: type, data: data }
michael@0 31 });
michael@0 32
michael@0 33 function streamEventsFrom({document}) {
michael@0 34 // Map supported event types to a streams of those events on the given
michael@0 35 // `window` for the inserted document and than merge these streams into
michael@0 36 // single form stream off all window state change events.
michael@0 37 let stateChanges = TYPES.map(function(type) {
michael@0 38 return open(document, type, { capture: true });
michael@0 39 });
michael@0 40
michael@0 41 // Since load events on document occur for every loded resource
michael@0 42 return filter(merge(stateChanges), function({target}) {
michael@0 43 return target instanceof Ci.nsIDOMDocument
michael@0 44 })
michael@0 45 }
michael@0 46 exports.streamEventsFrom = streamEventsFrom;
michael@0 47
michael@0 48 let opened = windows(null, { includePrivate: true });
michael@0 49 let state = merge(opened.map(streamEventsFrom));
michael@0 50
michael@0 51
michael@0 52 let futureReady = filter(windowEvents, function({type})
michael@0 53 type === "DOMContentLoaded");
michael@0 54 let futureWindows = map(futureReady, function({target}) target);
michael@0 55 let futureState = expand(futureWindows, streamEventsFrom);
michael@0 56
michael@0 57 exports.events = merge([insert, create, state, futureState]);

mercurial