michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: module.metadata = { michael@0: 'stability': 'unstable' michael@0: }; michael@0: michael@0: michael@0: // NOTE: This file should only export Tab instances michael@0: michael@0: michael@0: const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils'); michael@0: const { Tab } = require('./tab'); michael@0: const { rawTabNS } = require('./namespace'); michael@0: michael@0: function getTabForWindow(win) { michael@0: let tab = getTabForContentWindow(win); michael@0: // We were unable to find the related tab! michael@0: if (!tab) michael@0: return null; michael@0: michael@0: return getTabForRawTab(tab) || Tab({ tab: tab }); michael@0: } michael@0: exports.getTabForWindow = getTabForWindow; michael@0: michael@0: // only works on fennec atm michael@0: function getTabForRawTab(rawTab) { michael@0: let tab = rawTabNS(rawTab).tab; michael@0: if (tab) { michael@0: return tab; michael@0: } michael@0: return null; michael@0: } michael@0: exports.getTabForRawTab = getTabForRawTab; michael@0: michael@0: function getTabForBrowser(browser) { michael@0: return getTabForRawTab(getRawTabForBrowser(browser)); michael@0: } michael@0: exports.getTabForBrowser = getTabForBrowser;