addon-sdk/source/lib/sdk/tab/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 // This module provides temporary shim until Bug 843901 is shipped.
michael@0 8 // It basically registers tab event listeners on all windows that get
michael@0 9 // opened and forwards them through observer notifications.
michael@0 10
michael@0 11 module.metadata = {
michael@0 12 "stability": "experimental"
michael@0 13 };
michael@0 14
michael@0 15 const { Ci } = require("chrome");
michael@0 16 const { windows, isInteractive } = require("../window/utils");
michael@0 17 const { events } = require("../browser/events");
michael@0 18 const { open } = require("../event/dom");
michael@0 19 const { filter, map, merge, expand } = require("../event/utils");
michael@0 20 const isFennec = require("sdk/system/xul-app").is("Fennec");
michael@0 21
michael@0 22 // Module provides event stream (in nodejs style) that emits data events
michael@0 23 // for all the tab events that happen in running firefox. At the moment
michael@0 24 // it does it by registering listeners on all browser windows and then
michael@0 25 // forwarding events when they occur to a stream. This will become obsolete
michael@0 26 // once Bug 843901 is fixed, and we'll just leverage observer notifications.
michael@0 27
michael@0 28 // Set of tab events that this module going to aggregate and expose.
michael@0 29 const TYPES = ["TabOpen","TabClose","TabSelect","TabMove","TabPinned",
michael@0 30 "TabUnpinned"];
michael@0 31
michael@0 32 // Utility function that given a browser `window` returns stream of above
michael@0 33 // defined tab events for all tabs on the given window.
michael@0 34 function tabEventsFor(window) {
michael@0 35 // Map supported event types to a streams of those events on the given
michael@0 36 // `window` and than merge these streams into single form stream off
michael@0 37 // all events.
michael@0 38 let channels = TYPES.map(function(type) open(window, type));
michael@0 39 return merge(channels);
michael@0 40 }
michael@0 41
michael@0 42 // Filter DOMContentLoaded events from all the browser events.
michael@0 43 let readyEvents = filter(events, function(e) e.type === "DOMContentLoaded");
michael@0 44 // Map DOMContentLoaded events to it's target browser windows.
michael@0 45 let futureWindows = map(readyEvents, function(e) e.target);
michael@0 46 // Expand all browsers that will become interactive to supported tab events
michael@0 47 // on these windows. Result will be a tab events from all tabs of all windows
michael@0 48 // that will become interactive.
michael@0 49 let eventsFromFuture = expand(futureWindows, tabEventsFor);
michael@0 50
michael@0 51 // Above covers only windows that will become interactive in a future, but some
michael@0 52 // windows may already be interactive so we pick those and expand to supported
michael@0 53 // tab events for them too.
michael@0 54 let interactiveWindows = windows("navigator:browser", { includePrivate: true }).
michael@0 55 filter(isInteractive);
michael@0 56 let eventsFromInteractive = merge(interactiveWindows.map(tabEventsFor));
michael@0 57
michael@0 58
michael@0 59 // Finally merge stream of tab events from future windows and current windows
michael@0 60 // to cover all tab events on all windows that will open.
michael@0 61 let allEvents = merge([eventsFromInteractive, eventsFromFuture]);
michael@0 62
michael@0 63 // Map events to Fennec format if necessary
michael@0 64 exports.events = map(allEvents, function (event) {
michael@0 65 return !isFennec ? event : {
michael@0 66 type: event.type,
michael@0 67 target: event.target.ownerDocument.defaultView.BrowserApp
michael@0 68 .getTabForBrowser(event.target)
michael@0 69 };
michael@0 70 });

mercurial