addon-sdk/source/lib/sdk/windows/fennec.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 { Class } = require('../core/heritage');
michael@0 7 const { BrowserWindow } = require('../window/browser');
michael@0 8 const { WindowTracker } = require('../deprecated/window-utils');
michael@0 9 const { isBrowser, getMostRecentBrowserWindow } = require('../window/utils');
michael@0 10 const { windowNS } = require('../window/namespace');
michael@0 11 const { on, off, once, emit } = require('../event/core');
michael@0 12 const { method } = require('../lang/functional');
michael@0 13 const { EventTarget } = require('../event/target');
michael@0 14 const { List, addListItem } = require('../util/list');
michael@0 15
michael@0 16 const ERR_FENNEC_MSG = 'This method is not yet supported by Fennec, consider using require("sdk/tabs") instead';
michael@0 17
michael@0 18 // NOTE: On Fennec there is only one window.
michael@0 19
michael@0 20 let BrowserWindows = Class({
michael@0 21 implements: [ List ],
michael@0 22 extends: EventTarget,
michael@0 23 initialize: function() {
michael@0 24 List.prototype.initialize.apply(this);
michael@0 25 },
michael@0 26 get activeWindow() {
michael@0 27 let window = getMostRecentBrowserWindow();
michael@0 28 return window ? getBrowserWindow({window: window}) : null;
michael@0 29 },
michael@0 30 open: function open(options) {
michael@0 31 throw new Error(ERR_FENNEC_MSG);
michael@0 32 return null;
michael@0 33 }
michael@0 34 });
michael@0 35 const browserWindows = exports.browserWindows = BrowserWindows();
michael@0 36
michael@0 37
michael@0 38 /**
michael@0 39 * Gets a `BrowserWindow` for the given `chromeWindow` if previously
michael@0 40 * registered, `null` otherwise.
michael@0 41 */
michael@0 42 function getRegisteredWindow(chromeWindow) {
michael@0 43 for each (let window in browserWindows) {
michael@0 44 if (chromeWindow === windowNS(window).window)
michael@0 45 return window;
michael@0 46 }
michael@0 47
michael@0 48 return null;
michael@0 49 }
michael@0 50
michael@0 51 /**
michael@0 52 * Gets a `BrowserWindow` for the provided window options obj
michael@0 53 * @params {Object} options
michael@0 54 * Options that are passed to the the `BrowserWindowTrait`
michael@0 55 * @returns {BrowserWindow}
michael@0 56 */
michael@0 57 function getBrowserWindow(options) {
michael@0 58 let window = null;
michael@0 59
michael@0 60 // if we have a BrowserWindow already then use it
michael@0 61 if ('window' in options)
michael@0 62 window = getRegisteredWindow(options.window);
michael@0 63 if (window)
michael@0 64 return window;
michael@0 65
michael@0 66 // we don't have a BrowserWindow yet, so create one
michael@0 67 var window = BrowserWindow(options);
michael@0 68 addListItem(browserWindows, window);
michael@0 69 return window;
michael@0 70 }
michael@0 71
michael@0 72 WindowTracker({
michael@0 73 onTrack: function onTrack(chromeWindow) {
michael@0 74 if (!isBrowser(chromeWindow)) return;
michael@0 75 let window = getBrowserWindow({ window: chromeWindow });
michael@0 76 emit(browserWindows, 'open', window);
michael@0 77 },
michael@0 78 onUntrack: function onUntrack(chromeWindow) {
michael@0 79 if (!isBrowser(chromeWindow)) return;
michael@0 80 let window = getBrowserWindow({ window: chromeWindow });
michael@0 81 emit(browserWindows, 'close', window);
michael@0 82 }
michael@0 83 });

mercurial