Bug 593687 - Don't let switchToTabHavingURI open tabs in popups. r=gavin

This commit is contained in:
Dão Gottwald 2011-02-12 10:02:48 +01:00
parent b95151bca0
commit be716f1278
3 changed files with 56 additions and 24 deletions

View File

@ -6437,10 +6437,45 @@ var MailIntegration = {
};
function BrowserOpenAddonsMgr(aView) {
switchToTabHavingURI("about:addons", true, function(browser) {
if (aView)
browser.contentWindow.wrappedJSObject.loadView(aView);
});
if (aView) {
let emWindow;
let browserWindow;
function receivePong(aSubject, aTopic, aData) {
let browserWin = aSubject.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
if (!emWindow || browserWin == window /* favor the current window */) {
emWindow = aSubject;
browserWindow = browserWin;
}
}
Services.obs.addObserver(receivePong, "EM-pong", false);
Services.obs.notifyObservers(null, "EM-ping", "");
Services.obs.removeObserver(receivePong, "EM-pong");
if (emWindow) {
emWindow.loadView(aView);
browserWindow.gBrowser.selectedTab =
browserWindow.gBrowser._getTabForContentWindow(emWindow);
emWindow.focus();
return;
}
}
var newLoad = !switchToTabHavingURI("about:addons", true);
if (aView) {
// This must be a new load, else the ping/pong would have
// found the window above.
Services.obs.addObserver(function (aSubject, aTopic, aData) {
Services.obs.removeObserver(arguments.callee, aTopic);
aSubject.loadView(aView);
}, "EM-loaded", false);
}
}
function AddKeywordForSearchField() {
@ -8360,11 +8395,9 @@ var LightWeightThemeWebInstaller = {
* URI to search for
* @param aOpenNew
* True to open a new tab and switch to it, if no existing tab is found
* @param A callback to call when the tab is open, the tab's browser will be
* passed as an argument
* @return True if a tab was switched to (or opened), false otherwise
* @return True if an existing tab was found, false otherwise
*/
function switchToTabHavingURI(aURI, aOpenNew, aCallback) {
function switchToTabHavingURI(aURI, aOpenNew) {
function switchIfURIInWindow(aWindow) {
if (!("gBrowser" in aWindow))
return false;
@ -8375,8 +8408,6 @@ function switchToTabHavingURI(aURI, aOpenNew, aCallback) {
// Focus the matching window & tab
aWindow.focus();
aWindow.gBrowser.tabContainer.selectedIndex = i;
if (aCallback)
aCallback(browser);
return true;
}
}
@ -8407,17 +8438,7 @@ function switchToTabHavingURI(aURI, aOpenNew, aCallback) {
if (isTabEmpty(gBrowser.selectedTab))
gBrowser.selectedBrowser.loadURI(aURI.spec);
else
gBrowser.selectedTab = gBrowser.addTab(aURI.spec);
if (aCallback) {
let browser = gBrowser.selectedBrowser;
browser.addEventListener("pageshow", function(event) {
if (event.target.location.href != aURI.spec)
return;
browser.removeEventListener("pageshow", arguments.callee, true);
aCallback(browser);
}, true);
}
return true;
openUILinkIn(aURI.spec, "tab");
}
return false;

View File

@ -109,6 +109,8 @@ function initialize() {
gHeader.initialize();
gViewController.initialize();
gEventManager.initialize();
Services.obs.addObserver(sendEMPong, "EM-ping", false);
Services.obs.notifyObservers(window, "EM-loaded", "");
}
function notifyInitialized() {
@ -128,6 +130,11 @@ function shutdown() {
gSearchView.shutdown();
gEventManager.shutdown();
gViewController.shutdown();
Services.obs.removeObserver(sendEMPong, "EM-ping");
}
function sendEMPong(aSubject, aTopic, aData) {
Services.obs.notifyObservers(window, "EM-pong", "");
}
// Used by external callers to load a specific view into the manager

View File

@ -242,9 +242,13 @@ function open_manager(aView, aCallback, aLoadCallback, aLongerTimeout) {
if (gUseInContentUI) {
gBrowser.selectedTab = gBrowser.addTab();
switchToTabHavingURI(MANAGER_URI, true, function(aBrowser) {
setup_manager(aBrowser.contentWindow.wrappedJSObject);
});
switchToTabHavingURI(MANAGER_URI, true);
gBrowser.selectedBrowser.addEventListener("pageshow", function (event) {
if (event.target.location.href != MANAGER_URI)
return;
gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
setup_manager(gBrowser.contentWindow.wrappedJSObject);
}, true);
return;
}