|
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'; |
|
5 |
|
6 module.metadata = { |
|
7 'stability': 'unstable' |
|
8 }; |
|
9 |
|
10 |
|
11 // NOTE: This file should only export Tab instances |
|
12 |
|
13 |
|
14 const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils'); |
|
15 const { Tab } = require('./tab'); |
|
16 const { rawTabNS } = require('./namespace'); |
|
17 |
|
18 function getTabForWindow(win) { |
|
19 let tab = getTabForContentWindow(win); |
|
20 // We were unable to find the related tab! |
|
21 if (!tab) |
|
22 return null; |
|
23 |
|
24 return getTabForRawTab(tab) || Tab({ tab: tab }); |
|
25 } |
|
26 exports.getTabForWindow = getTabForWindow; |
|
27 |
|
28 // only works on fennec atm |
|
29 function getTabForRawTab(rawTab) { |
|
30 let tab = rawTabNS(rawTab).tab; |
|
31 if (tab) { |
|
32 return tab; |
|
33 } |
|
34 return null; |
|
35 } |
|
36 exports.getTabForRawTab = getTabForRawTab; |
|
37 |
|
38 function getTabForBrowser(browser) { |
|
39 return getTabForRawTab(getRawTabForBrowser(browser)); |
|
40 } |
|
41 exports.getTabForBrowser = getTabForBrowser; |