addon-sdk/source/lib/sdk/tabs/tabs-firefox.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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict';
     6 // TODO: BUG 792670 - remove dependency below
     7 const { browserWindows: windows } = require('../windows');
     8 const { tabs } = require('../windows/tabs-firefox');
     9 const { isPrivate } = require('../private-browsing');
    10 const { isWindowPBSupported } = require('../private-browsing/utils')
    11 const { isPrivateBrowsingSupported } = require('sdk/self');
    13 const supportPrivateTabs = isPrivateBrowsingSupported && isWindowPBSupported;
    15 function newTabWindow(options) {
    16   // `tabs` option is under review and may be removed.
    17   return windows.open({
    18     tabs: [ options ],
    19     isPrivate: options.isPrivate
    20   });
    21 }
    23 Object.defineProperties(tabs, {
    24   open: { value: function open(options) {
    25     if (options.inNewWindow) {
    26         newTabWindow(options);
    27         return undefined;
    28     }
    30     let activeWindow = windows.activeWindow;
    31     let privateState = (supportPrivateTabs && (options.isPrivate || isPrivate(activeWindow))) || false;
    33     // if the active window is in the state that we need then use it
    34     if (activeWindow && (!supportPrivateTabs || privateState === isPrivate(activeWindow))) {
    35       activeWindow.tabs.open(options);
    36     }
    37     else {
    38       // find a window in the state that we need
    39       let window = getWindow(privateState);
    40       if (window) {
    41         window.tabs.open(options);
    42       }
    43       // open a window in the state that we need
    44       else {
    45         newTabWindow(options);
    46       }
    47     }
    49     return undefined;
    50   }}
    51 });
    53 function getWindow(privateState) {
    54   for each (let window in windows) {
    55     if (privateState === isPrivate(window)) {
    56       return window;
    57     }
    58   }
    59   return null;
    60 }
    62 // Workaround for bug 674195. Freezing objects from other compartments fail,
    63 // so we use `Object.freeze` from the same component as objects
    64 // `hasOwnProperty`. Since `hasOwnProperty` here will be from other component
    65 // we override it to support our workaround.
    66 module.exports = Object.create(tabs, {
    67   isPrototypeOf: { value: Object.prototype.isPrototypeOf }
    68 });

mercurial