From fb11286c1590367fa2bc75db4dc2dbdbf11b459b Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 18 Jul 2012 15:43:34 -0700 Subject: [PATCH] comparing with http://hg.mozilla.org/integration/mozilla-inbound/ searching for changes changeset: 99712:bbdfd47ad4d7 tag: tip user: Wes Johnston summary: Bug 766802 - Clicks on links with target=blank in webapps should open in the browser. r=mfinkle --- mobile/android/chrome/content/WebAppRT.js | 39 +++++++++++++++++++++++ mobile/android/chrome/content/browser.js | 4 +++ mobile/android/chrome/jar.mn | 1 + 3 files changed, 44 insertions(+) create mode 100644 mobile/android/chrome/content/WebAppRT.js diff --git a/mobile/android/chrome/content/WebAppRT.js b/mobile/android/chrome/content/WebAppRT.js new file mode 100644 index 00000000000..6e4417e8bc1 --- /dev/null +++ b/mobile/android/chrome/content/WebAppRT.js @@ -0,0 +1,39 @@ +/* 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/. */ +let Cc = Components.classes; +let Ci = Components.interfaces; +let Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); + +var WebAppRT = { + init: function() { + this.deck = document.getElementById("browsers"); + this.deck.addEventListener("click", onContentClick, false, true); + }, + + handleEvent: function(event) { + let target = event.target; + + if (!(target instanceof HTMLAnchorElement) || + target.getAttribute("target") != "_blank") { + return; + } + + let uri = Services.io.newURI(target.href, + target.ownerDocument.characterSet, + null); + + // Direct the URL to the browser. + Cc["@mozilla.org/uriloader/external-protocol-service;1"]. + getService(Ci.nsIExternalProtocolService). + getProtocolHandlerInfo(uri.scheme). + launchWithURI(uri); + + // Prevent the runtime from loading the URL. We do this after directing it + // to the browser to give the runtime a shot at handling the URL if we fail + // to direct it to the browser for some reason. + event.preventDefault(); + } +} diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 29a248cce06..cff50c593d6 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -32,6 +32,7 @@ XPCOMUtils.defineLazyGetter(this, "DebuggerServer", function() { ["HelperApps", "chrome://browser/content/HelperApps.js"], ["SelectHelper", "chrome://browser/content/SelectHelper.js"], ["Readability", "chrome://browser/content/Readability.js"], + ["WebAppRT", "chrome://browser/content/WebAppRT.js"], ].forEach(function (aScript) { let [name, script] = aScript; XPCOMUtils.defineLazyGetter(window, name, function() { @@ -309,6 +310,9 @@ var BrowserApp = { #endif } + if (pinned) + WebAppRT.init(); + if (this.isAppUpdated()) this.onAppUpdated(); diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index 39c7d2e03da..efc847482d7 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -36,6 +36,7 @@ chrome.jar: content/SelectHelper.js (content/SelectHelper.js) content/HelperApps.js (content/HelperApps.js) content/dbg-browser-actors.js (content/dbg-browser-actors.js) + content/WebAppRT.js (content/WebAppRT.js) % content branding %content/branding/