Bug 1392210 - Extension content needs nsIWebBrowserChrome3 for link traversal. r=kmag, a=gchang
authorShane Caraveo <scaraveo@mozilla.com>
Tue, 05 Sep 2017 13:36:08 -0700
changeset 423975 7a6699a52aec8acfd69754f439b6fd0605d827c3
parent 423974 7f6aade38935c08c783c23d51160427011f92ef2
child 423976 a805179e01649318edd4fb9fe029203241ee25a6
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, gchang
bugs1392210
milestone56.0
Bug 1392210 - Extension content needs nsIWebBrowserChrome3 for link traversal. r=kmag, a=gchang MozReview-Commit-ID: ITJhNL8FemG
toolkit/components/extensions/ext-browser-content.js
--- a/toolkit/components/extensions/ext-browser-content.js
+++ b/toolkit/components/extensions/ext-browser-content.js
@@ -2,18 +2,22 @@
  * 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";
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
+                                  "resource://gre/modules/BrowserUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "clearTimeout",
                                   "resource://gre/modules/Timer.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
+                                  "resource:///modules/E10SUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionCommon",
                                   "resource://gre/modules/ExtensionCommon.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "require",
                                   "resource://devtools/shared/Loader.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
                                   "resource://gre/modules/Timer.jsm");
@@ -287,8 +291,43 @@ const BrowserListener = {
     }
 
     sendAsyncMessage("Extension:BrowserResized", result);
   },
 };
 
 addMessageListener("Extension:InitBrowser", BrowserListener);
 addMessageListener("Extension:UnblockParser", BrowserListener);
+
+var WebBrowserChrome = {
+  onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab) {
+    // isAppTab is the value for the docShell that received the click.  We're
+    // handling this in the top-level frame and want traversal behavior to
+    // match the value for this frame rather than any subframe, so we pass
+    // through the docShell.isAppTab value rather than what we were handed.
+    return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, docShell.isAppTab);
+  },
+
+  shouldLoadURI(docShell, URI, referrer, hasPostData, triggeringPrincipal) {
+    return true;
+  },
+
+  shouldLoadURIInThisProcess(URI) {
+    return E10SUtils.shouldLoadURIInThisProcess(URI);
+  },
+
+  reloadInFreshProcess(docShell, URI, referrer, triggeringPrincipal, loadFlags) {
+    return false;
+  },
+
+  startPrerenderingDocument(href, referrer, triggeringPrincipal) {
+  },
+
+  shouldSwitchToPrerenderedDocument(href, referrer, success, failure) {
+    return false;
+  },
+};
+
+if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
+  let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsITabChild);
+  tabchild.webBrowserChrome = WebBrowserChrome;
+}