1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/tabs/tabs-firefox.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +'use strict'; 1.8 + 1.9 +// TODO: BUG 792670 - remove dependency below 1.10 +const { browserWindows: windows } = require('../windows'); 1.11 +const { tabs } = require('../windows/tabs-firefox'); 1.12 +const { isPrivate } = require('../private-browsing'); 1.13 +const { isWindowPBSupported } = require('../private-browsing/utils') 1.14 +const { isPrivateBrowsingSupported } = require('sdk/self'); 1.15 + 1.16 +const supportPrivateTabs = isPrivateBrowsingSupported && isWindowPBSupported; 1.17 + 1.18 +function newTabWindow(options) { 1.19 + // `tabs` option is under review and may be removed. 1.20 + return windows.open({ 1.21 + tabs: [ options ], 1.22 + isPrivate: options.isPrivate 1.23 + }); 1.24 +} 1.25 + 1.26 +Object.defineProperties(tabs, { 1.27 + open: { value: function open(options) { 1.28 + if (options.inNewWindow) { 1.29 + newTabWindow(options); 1.30 + return undefined; 1.31 + } 1.32 + 1.33 + let activeWindow = windows.activeWindow; 1.34 + let privateState = (supportPrivateTabs && (options.isPrivate || isPrivate(activeWindow))) || false; 1.35 + 1.36 + // if the active window is in the state that we need then use it 1.37 + if (activeWindow && (!supportPrivateTabs || privateState === isPrivate(activeWindow))) { 1.38 + activeWindow.tabs.open(options); 1.39 + } 1.40 + else { 1.41 + // find a window in the state that we need 1.42 + let window = getWindow(privateState); 1.43 + if (window) { 1.44 + window.tabs.open(options); 1.45 + } 1.46 + // open a window in the state that we need 1.47 + else { 1.48 + newTabWindow(options); 1.49 + } 1.50 + } 1.51 + 1.52 + return undefined; 1.53 + }} 1.54 +}); 1.55 + 1.56 +function getWindow(privateState) { 1.57 + for each (let window in windows) { 1.58 + if (privateState === isPrivate(window)) { 1.59 + return window; 1.60 + } 1.61 + } 1.62 + return null; 1.63 +} 1.64 + 1.65 +// Workaround for bug 674195. Freezing objects from other compartments fail, 1.66 +// so we use `Object.freeze` from the same component as objects 1.67 +// `hasOwnProperty`. Since `hasOwnProperty` here will be from other component 1.68 +// we override it to support our workaround. 1.69 +module.exports = Object.create(tabs, { 1.70 + isPrototypeOf: { value: Object.prototype.isPrototypeOf } 1.71 +});