Bug 1440592 - [4.3] Allow load delegation when opening windows before requesting a new session. r=snorp, a=RyanVM
authorEugen Sawin <esawin@mozilla.com>
Tue, 27 Mar 2018 22:35:17 +0200
changeset 776136 d244d295cd2b3d8d8255716e37fd3107eaf6df66
parent 776135 32c8f13203b34e82f8dd515489080cdbab595ae5
child 776137 54d48c08e4c952384c7e31b391396f7f8784e247
push id104821
push userbmo:rrosario@mozilla.com
push dateMon, 02 Apr 2018 18:45:53 +0000
reviewerssnorp, RyanVM
bugs1440592
milestone60.0
Bug 1440592 - [4.3] Allow load delegation when opening windows before requesting a new session. r=snorp, a=RyanVM
mobile/android/modules/geckoview/GeckoViewNavigation.jsm
--- a/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
@@ -125,53 +125,79 @@ class GeckoViewNavigation extends GeckoV
   }
 
   // nsIBrowserDOMWindow.
   createContentWindow(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal) {
     debug("createContentWindow: aUri=" + (aUri && aUri.spec) +
           " aWhere=" + aWhere +
           " aFlags=" + aFlags);
 
+    if (LoadURIDelegate.load(this.eventDispatcher, aUri, aWhere, aFlags,
+                             aTriggeringPrincipal)) {
+      // The app has handled the load, abort open-window handling.
+      Components.returnCode = Cr.NS_ERROR_ABORT;
+      return null;
+    }
+
     const browser = this.handleNewSession(aUri, aOpener, aWhere, aFlags,
                                           aTriggeringPrincipal);
-    return browser && browser.contentWindow;
+    if (!browser) {
+      Components.returnCode = Cr.NS_ERROR_ABORT;
+      return null;
+    }
+
+    return browser.contentWindow;
   }
 
   // nsIBrowserDOMWindow.
   createContentWindowInFrame(aUri, aParams, aWhere, aFlags, aNextTabParentId,
                              aName) {
     debug("createContentWindowInFrame: aUri=" + (aUri && aUri.spec) +
           " aParams=" + aParams +
           " aWhere=" + aWhere +
           " aFlags=" + aFlags +
           " aNextTabParentId=" + aNextTabParentId +
           " aName=" + aName);
 
-    const browser = this.handleNewSession(aUri, null, aWhere, aFlags, null);
-    if (browser) {
-      browser.setAttribute("nextTabParentId", aNextTabParentId);
+    if (LoadURIDelegate.load(this.eventDispatcher, aUri, aWhere, aFlags, null)) {
+      // The app has handled the load, abort open-window handling.
+      Components.returnCode = Cr.NS_ERROR_ABORT;
+      return null;
     }
 
+    const browser = this.handleNewSession(aUri, null, aWhere, aFlags, null);
+    if (!browser) {
+      Components.returnCode = Cr.NS_ERROR_ABORT;
+      return null;
+    }
+
+    browser.setAttribute("nextTabParentId", aNextTabParentId);
     return browser;
   }
 
   handleOpenUri(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal,
                 aNextTabParentId) {
-    let browser = this.browser;
+    debug("handleOpenUri: aUri=" + (aUri && aUri.spec) +
+          " aWhere=" + aWhere +
+          " aFlags=" + aFlags);
+
     if (LoadURIDelegate.load(this.eventDispatcher, aUri, aWhere, aFlags,
                              aTriggeringPrincipal)) {
-      return browser;
+      return null;
     }
 
+    let browser = this.browser;
+
     if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW ||
         aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB ||
         aWhere === Ci.nsIBrowserDOMWindow.OPEN_SWITCHTAB) {
       browser = this.handleNewSession(aUri, aOpener, aWhere, aFlags,
                                       aTriggeringPrincipal);
     }
+
     if (!browser) {
       // Should we throw?
       return null;
     }
     browser.loadURI(aUri.spec, null, null, null, null, aTriggeringPrincipal);
     return browser;
   }