1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/tabs/helpers.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,41 @@ 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 +module.metadata = { 1.10 + 'stability': 'unstable' 1.11 +}; 1.12 + 1.13 + 1.14 +// NOTE: This file should only export Tab instances 1.15 + 1.16 + 1.17 +const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils'); 1.18 +const { Tab } = require('./tab'); 1.19 +const { rawTabNS } = require('./namespace'); 1.20 + 1.21 +function getTabForWindow(win) { 1.22 + let tab = getTabForContentWindow(win); 1.23 + // We were unable to find the related tab! 1.24 + if (!tab) 1.25 + return null; 1.26 + 1.27 + return getTabForRawTab(tab) || Tab({ tab: tab }); 1.28 +} 1.29 +exports.getTabForWindow = getTabForWindow; 1.30 + 1.31 +// only works on fennec atm 1.32 +function getTabForRawTab(rawTab) { 1.33 + let tab = rawTabNS(rawTab).tab; 1.34 + if (tab) { 1.35 + return tab; 1.36 + } 1.37 + return null; 1.38 +} 1.39 +exports.getTabForRawTab = getTabForRawTab; 1.40 + 1.41 +function getTabForBrowser(browser) { 1.42 + return getTabForRawTab(getRawTabForBrowser(browser)); 1.43 +} 1.44 +exports.getTabForBrowser = getTabForBrowser;