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: // The panel module currently supports only Firefox. michael@0: // See: https://bugzilla.mozilla.org/show_bug.cgi?id=jetpack-panel-apps michael@0: module.metadata = { michael@0: 'stability': 'unstable', michael@0: 'engines': { michael@0: 'Firefox': '*' michael@0: } michael@0: }; michael@0: michael@0: const { getMostRecentBrowserWindow, windows: getWindows } = require('../window/utils'); michael@0: const { ignoreWindow } = require('../private-browsing/utils'); michael@0: const { isPrivateBrowsingSupported } = require('../self'); michael@0: const { isGlobalPBSupported } = require('../private-browsing/utils'); michael@0: michael@0: function getWindow(anchor) { michael@0: let window; michael@0: let windows = getWindows("navigator:browser", { michael@0: includePrivate: isPrivateBrowsingSupported || isGlobalPBSupported michael@0: }); michael@0: michael@0: if (anchor) { michael@0: let anchorWindow = anchor.ownerDocument.defaultView.top; michael@0: let anchorDocument = anchorWindow.document; michael@0: michael@0: // loop thru supported windows michael@0: for each(let enumWindow in windows) { michael@0: // Check if the anchor is in this browser window. michael@0: if (enumWindow == anchorWindow) { michael@0: window = anchorWindow; michael@0: break; michael@0: } michael@0: michael@0: // Check if the anchor is in a browser tab in this browser window. michael@0: let browser = enumWindow.gBrowser.getBrowserForDocument(anchorDocument); michael@0: if (browser) { michael@0: window = enumWindow; michael@0: break; michael@0: } michael@0: michael@0: // Look in other subdocuments (sidebar, etc.)? michael@0: } michael@0: } michael@0: michael@0: // If we didn't find the anchor's window (or we have no anchor), michael@0: // return the most recent browser window. michael@0: if (!window) michael@0: window = getMostRecentBrowserWindow(); michael@0: michael@0: // if the window is not supported, then it should be ignored michael@0: if (ignoreWindow(window)) { michael@0: return null; michael@0: } michael@0: michael@0: return window; michael@0: } michael@0: exports.getWindow = getWindow;