Bug 263433 - 'text-link' XUL widget should open tabs rather than windows. r=enn

--HG--
extra : rebase_source : aab45840ef599a15d491d5548fdfd3fd19a738c4
This commit is contained in:
Dão Gottwald 2012-12-14 01:09:03 +01:00
parent d275dd6ea0
commit 2e26c0c69e
2 changed files with 27 additions and 7 deletions

View File

@ -281,6 +281,16 @@ BrowserGlue.prototype = {
case "initial-migration-did-import-default-bookmarks":
this._initPlaces(true);
break;
case "handle-xul-text-link":
let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
if (!linkHandled.data) {
let win = this.getMostRecentBrowserWindow();
if (win) {
win.openUILinkIn(data, "tab");
linkHandled.data = true;
}
}
break;
}
},
@ -312,6 +322,7 @@ BrowserGlue.prototype = {
os.addObserver(this, "places-shutdown", false);
this._isPlacesShutdownObserver = true;
os.addObserver(this, "defaultURIFixup-using-keyword-pref", false);
os.addObserver(this, "handle-xul-text-link", false);
},
// cleanup (called on application shutdown)
@ -342,6 +353,7 @@ BrowserGlue.prototype = {
if (this._isPlacesShutdownObserver)
os.removeObserver(this, "places-shutdown");
os.removeObserver(this, "defaultURIFixup-using-keyword-pref");
os.removeObserver(this, "handle-xul-text-link");
UserAgentOverrides.uninit();
webappsUI.uninit();
SignInToWebsiteUX.uninit();

View File

@ -350,19 +350,27 @@
Components.utils.reportError(ex);
}
aEvent.preventDefault();
href = uri ? uri.spec : href;
// Try handing off the link to the host application, e.g. for
// opening it in a tabbed browser.
var linkHandled = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
linkHandled.data = false;
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService)
.notifyObservers(linkHandled, "handle-xul-text-link", href);
if (linkHandled.data)
return;
// otherwise, fall back to opening the anchor directly
var win = window;
if (window instanceof Components.interfaces.nsIDOMChromeWindow) {
while (win.opener && !win.opener.closed)
win = win.opener;
}
if (uri)
win.open(uri.spec);
else
win.open(href);
aEvent.preventDefault();
win.open(href);
]]>
</body>
</method>