From 9b436bde67babae105a4ce5bec71eca8b665f97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Fri, 14 Dec 2012 01:09:03 +0100 Subject: [PATCH] Bug 263433 - 'text-link' XUL widget should open tabs rather than windows. r=enn --HG-- extra : rebase_source : aab45840ef599a15d491d5548fdfd3fd19a738c4 --- browser/components/nsBrowserGlue.js | 12 ++++++++++++ toolkit/content/widgets/text.xml | 22 +++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 5c2d91d42154..23f0bd1c84a9 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -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(); diff --git a/toolkit/content/widgets/text.xml b/toolkit/content/widgets/text.xml index 81f6cff9721b..aefaf3bb6d86 100644 --- a/toolkit/content/widgets/text.xml +++ b/toolkit/content/widgets/text.xml @@ -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); ]]>