Bug 1440592 - [4.3] Allow load delegation when opening windows before requesting a new session. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Tue, 27 Mar 2018 22:35:17 +0200
changeset 773607 15eed3a9a8e31a536dfbdb1af5ffbcab2be5c5b8
parent 773606 dc273da372bd8dcb4792000f724a7a523c2c071f
child 773608 af66807a5c4b8366dc98d3aae7d55124003a1039
push id104266
push userbmo:hsivonen@hsivonen.fi
push dateWed, 28 Mar 2018 07:33:03 +0000
reviewerssnorp
bugs1440592
milestone61.0a1
Bug 1440592 - [4.3] Allow load delegation when opening windows before requesting a new session. r=snorp
mobile/android/modules/geckoview/GeckoViewModule.jsm
mobile/android/modules/geckoview/GeckoViewNavigation.jsm
--- a/mobile/android/modules/geckoview/GeckoViewModule.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewModule.jsm
@@ -124,49 +124,49 @@ class EventProxy {
     this.listener = aListener;
     this.eventDispatcher = aEventDispatcher;
     this._eventQueue = [];
     this._registeredEvents = [];
     this._enableQueuing = false;
   }
 
   registerListener(aEventList) {
-    debug("rabbit register " + aEventList);
+    debug("register " + aEventList);
     this.eventDispatcher.registerListener(this, aEventList);
     this._registeredEvents = this._registeredEvents.concat(aEventList);
   }
 
   unregisterListener() {
-    debug("rabbit unregister");
+    debug("unregister");
     if (this._registeredEvents.length === 0) {
       return;
     }
     this.eventDispatcher.unregisterListener(this, this._registeredEvents);
     this._registeredEvents = [];
   }
 
   onEvent(aEvent, aData, aCallback) {
     if (this._enableQueuing) {
-      debug("rabbit queue " + aEvent + ", aData=" + JSON.stringify(aData));
+      debug("queue " + aEvent + ", aData=" + JSON.stringify(aData));
       this._eventQueue.unshift(arguments);
     } else {
       this._dispatch.apply(this, arguments);
     }
   }
 
   enableQueuing(aEnable) {
     debug("enableQueuing " + aEnable);
     this._enableQueuing = aEnable;
   }
 
   _dispatch(aEvent, aData, aCallback) {
-    debug("rabbit dispatch " + aEvent + ", aData=" + JSON.stringify(aData));
+    debug("dispatch " + aEvent + ", aData=" + JSON.stringify(aData));
     this.listener.onEvent.apply(this.listener, arguments);
   }
 
   dispatchQueuedEvents() {
-    debug("rabbit dispatchQueued");
+    debug("dispatchQueued");
     while (this._eventQueue.length) {
       const e = this._eventQueue.pop();
       this._dispatch.apply(this, e);
     }
   }
 }
--- a/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
@@ -147,53 +147,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;
   }