2012-12-06 05:59:26 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["RecentWindow"];
|
|
|
|
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2015-03-12 18:25:32 +03:00
|
|
|
Cu.import("resource://gre/modules/AppConstants.jsm");
|
2012-12-06 05:59:26 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
|
|
|
this.RecentWindow = {
|
|
|
|
/*
|
|
|
|
* Get the most recent browser window.
|
|
|
|
*
|
|
|
|
* @param aOptions an object accepting the arguments for the search.
|
2013-03-17 19:12:54 +04:00
|
|
|
* * private: true to restrict the search to private windows
|
|
|
|
* only, false to restrict the search to non-private only.
|
|
|
|
* Omit the property to search in both groups.
|
|
|
|
* * allowPopups: true if popup windows are permissable.
|
2012-12-06 05:59:26 +04:00
|
|
|
*/
|
|
|
|
getMostRecentBrowserWindow: function RW_getMostRecentBrowserWindow(aOptions) {
|
|
|
|
let checkPrivacy = typeof aOptions == "object" &&
|
|
|
|
"private" in aOptions;
|
|
|
|
|
2013-03-17 19:12:54 +04:00
|
|
|
let allowPopups = typeof aOptions == "object" && !!aOptions.allowPopups;
|
|
|
|
|
2012-12-06 05:59:26 +04:00
|
|
|
function isSuitableBrowserWindow(win) {
|
|
|
|
return (!win.closed &&
|
2013-03-17 19:12:54 +04:00
|
|
|
(allowPopups || win.toolbar.visible) &&
|
2012-12-06 05:59:26 +04:00
|
|
|
(!checkPrivacy ||
|
2013-03-07 19:30:47 +04:00
|
|
|
PrivateBrowsingUtils.permanentPrivateBrowsing ||
|
2012-12-06 05:59:26 +04:00
|
|
|
PrivateBrowsingUtils.isWindowPrivate(win) == aOptions.private));
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:25:32 +03:00
|
|
|
let broken_wm_z_order =
|
|
|
|
AppConstants.platform != "macosx" && AppConstants.platform != "win";
|
|
|
|
|
|
|
|
if (broken_wm_z_order) {
|
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
2012-12-06 05:59:26 +04:00
|
|
|
|
2015-03-12 18:25:32 +03:00
|
|
|
// if we're lucky, this isn't a popup, and we can just return this
|
|
|
|
if (win && !isSuitableBrowserWindow(win)) {
|
|
|
|
win = null;
|
|
|
|
let windowList = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
// this is oldest to newest, so this gets a bit ugly
|
|
|
|
while (windowList.hasMoreElements()) {
|
|
|
|
let nextWin = windowList.getNext();
|
|
|
|
if (isSuitableBrowserWindow(nextWin))
|
|
|
|
win = nextWin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return win;
|
|
|
|
} else {
|
|
|
|
let windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
|
2012-12-06 05:59:26 +04:00
|
|
|
while (windowList.hasMoreElements()) {
|
2015-03-12 18:25:32 +03:00
|
|
|
let win = windowList.getNext();
|
|
|
|
if (isSuitableBrowserWindow(win))
|
|
|
|
return win;
|
2012-12-06 05:59:26 +04:00
|
|
|
}
|
2015-03-12 18:25:32 +03:00
|
|
|
return null;
|
2012-12-06 05:59:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|