addon-sdk/source/lib/sdk/panel/window.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:09f974eab87d
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 // The panel module currently supports only Firefox.
7 // See: https://bugzilla.mozilla.org/show_bug.cgi?id=jetpack-panel-apps
8 module.metadata = {
9 'stability': 'unstable',
10 'engines': {
11 'Firefox': '*'
12 }
13 };
14
15 const { getMostRecentBrowserWindow, windows: getWindows } = require('../window/utils');
16 const { ignoreWindow } = require('../private-browsing/utils');
17 const { isPrivateBrowsingSupported } = require('../self');
18 const { isGlobalPBSupported } = require('../private-browsing/utils');
19
20 function getWindow(anchor) {
21 let window;
22 let windows = getWindows("navigator:browser", {
23 includePrivate: isPrivateBrowsingSupported || isGlobalPBSupported
24 });
25
26 if (anchor) {
27 let anchorWindow = anchor.ownerDocument.defaultView.top;
28 let anchorDocument = anchorWindow.document;
29
30 // loop thru supported windows
31 for each(let enumWindow in windows) {
32 // Check if the anchor is in this browser window.
33 if (enumWindow == anchorWindow) {
34 window = anchorWindow;
35 break;
36 }
37
38 // Check if the anchor is in a browser tab in this browser window.
39 let browser = enumWindow.gBrowser.getBrowserForDocument(anchorDocument);
40 if (browser) {
41 window = enumWindow;
42 break;
43 }
44
45 // Look in other subdocuments (sidebar, etc.)?
46 }
47 }
48
49 // If we didn't find the anchor's window (or we have no anchor),
50 // return the most recent browser window.
51 if (!window)
52 window = getMostRecentBrowserWindow();
53
54 // if the window is not supported, then it should be ignored
55 if (ignoreWindow(window)) {
56 return null;
57 }
58
59 return window;
60 }
61 exports.getWindow = getWindow;

mercurial