addon-sdk/source/lib/sdk/input/window.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 const { windows, isInteractive, isDocumentLoaded,
michael@0 7 getOuterId, isTopLevel } = require("../window/utils");
michael@0 8 const { InputPort } = require("./system");
michael@0 9 const { lift, merges, foldp, keepIf, start, Input } = require("../event/utils");
michael@0 10 const { patch } = require("diffpatcher/index");
michael@0 11 const { on } = require("../event/core");
michael@0 12 const { Sequence, seq, filter, object, pairs } = require("../util/sequence");
michael@0 13
michael@0 14
michael@0 15 // Create lazy iterators from the regular arrays, although
michael@0 16 // once https://github.com/mozilla/addon-sdk/pull/1314 lands
michael@0 17 // `windows` will be transforme to lazy iterators.
michael@0 18 // When iterated over belowe sequences items will represent
michael@0 19 // state of windows at the time of iteration.
michael@0 20 const opened = seq(function*() {
michael@0 21 const items = windows(null, {includePrivates: true});
michael@0 22 for (let item of items)
michael@0 23 yield [getOuterId(item), item];
michael@0 24 });
michael@0 25 const interactive = filter(([_, window]) => isInteractive(window), opened);
michael@0 26 const loaded = filter(([_, window]) => isDocumentLoaded(window), opened);
michael@0 27
michael@0 28 // Helper function that converts given argument to a delta.
michael@0 29 const Update = window => window && object([getOuterId(window), window]);
michael@0 30 const Delete = window => window && object([getOuterId(window), null]);
michael@0 31
michael@0 32 // Signal represents delta for last opened top level window.
michael@0 33 const LastOpened = lift(Update, new InputPort({topic: "domwindowopened"}));
michael@0 34 exports.LastOpened = LastOpened;
michael@0 35
michael@0 36 // Signal represents delta for last top level window close.
michael@0 37 const LastClosed = lift(Delete, new InputPort({topic: "domwindowclosed"}));
michael@0 38 exports.LastClosed = LastClosed;
michael@0 39
michael@0 40 const windowFor = document => document && document.defaultView;
michael@0 41
michael@0 42 // Signal represent delta for last top level window document becoming interactive.
michael@0 43 const InteractiveDoc = new InputPort({topic: "chrome-document-interactive"});
michael@0 44 const InteractiveWin = lift(windowFor, InteractiveDoc);
michael@0 45 const LastInteractive = lift(Update, keepIf(isTopLevel, null, InteractiveWin));
michael@0 46 exports.LastInteractive = LastInteractive;
michael@0 47
michael@0 48 // Signal represent delta for last top level window loaded.
michael@0 49 const LoadedDoc = new InputPort({topic: "chrome-document-loaded"});
michael@0 50 const LoadedWin = lift(windowFor, LoadedDoc);
michael@0 51 const LastLoaded = lift(Update, keepIf(isTopLevel, null, LoadedWin));
michael@0 52 exports.LastLoaded = LastLoaded;
michael@0 53
michael@0 54
michael@0 55 const initialize = input => {
michael@0 56 if (!input.initialized) {
michael@0 57 input.value = object(...input.value);
michael@0 58 Input.start(input);
michael@0 59 input.initialized = true;
michael@0 60 }
michael@0 61 };
michael@0 62
michael@0 63 // Signal represents set of currently opened top level windows, updated
michael@0 64 // to new set any time window is opened or closed.
michael@0 65 const Opened = foldp(patch, opened, merges([LastOpened, LastClosed]));
michael@0 66 Opened[start] = initialize;
michael@0 67 exports.Opened = Opened;
michael@0 68
michael@0 69 // Signal represents set of top level interactive windows, updated any
michael@0 70 // time new window becomes interactive or one get's closed.
michael@0 71 const Interactive = foldp(patch, interactive, merges([LastInteractive,
michael@0 72 LastClosed]));
michael@0 73 Interactive[start] = initialize;
michael@0 74 exports.Interactive = Interactive;
michael@0 75
michael@0 76 // Signal represents set of top level loaded window, updated any time
michael@0 77 // new window becomes interactive or one get's closed.
michael@0 78 const Loaded = foldp(patch, loaded, merges([LastLoaded, LastClosed]));
michael@0 79 Loaded[start] = initialize;
michael@0 80 exports.Loaded = Loaded;

mercurial