Backed out 4 changesets (bug 1441059, bug 1478171) for causing bug 1489257. GECKOVIEW_62_RELBRANCH
authorRyan VanderMeulen <ryanvm@gmail.com>
Mon, 10 Sep 2018 16:46:19 -0400
branchGECKOVIEW_62_RELBRANCH
changeset 481126 4cdeecd31350
parent 481124 ece2f6547002
child 481128 c019d0af0d64
push id1781
push userryanvm@gmail.com
push date2018-09-10 20:46 +0000
treeherdermozilla-release@4cdeecd31350 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1441059, 1478171, 1489257
milestone62.0.2
backs out99aa10a241f6
427eacc1a0bf
76f94cb522c7
f35ce4a93698
Backed out 4 changesets (bug 1441059, bug 1478171) for causing bug 1489257. Backed out changeset 99aa10a241f6 (bug 1478171) Backed out changeset 427eacc1a0bf (bug 1441059) Backed out changeset 76f94cb522c7 (bug 1441059) Backed out changeset f35ce4a93698 (bug 1441059)
docshell/base/nsDocShell.cpp
docshell/base/nsIDocShell.idl
mfbt/Maybe.h
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
mobile/android/modules/geckoview/GeckoViewNavigation.jsm
mobile/android/modules/geckoview/LoadURIDelegate.jsm
netwerk/base/nsIChannelEventSink.idl
uriloader/base/nsDocLoader.cpp
xpcom/base/nsILoadURIDelegate.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -9035,92 +9035,87 @@ nsDocShell::CopyFavicon(nsIURI* aOldURI,
   if (favSvc) {
     favSvc->CopyFavicons(aOldURI, aNewURI,
       aInPrivateBrowsing ? nsIFaviconService::FAVICON_LOAD_PRIVATE
                          : nsIFaviconService::FAVICON_LOAD_NON_PRIVATE, nullptr);
   }
 #endif
 }
 
-struct InternalLoadData 
+class InternalLoadEvent : public Runnable
 {
 public:
-  InternalLoadData(nsDocShell* aDocShell,
-                   nsIURI* aURI,
-                   nsIURI* aOriginalURI,
-                   Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
-                   bool aKeepResultPrincipalURIIfSet,
-                   bool aLoadReplace,
-                   nsIURI* aReferrer, uint32_t aReferrerPolicy,
-                   nsIPrincipal* aTriggeringPrincipal,
-                   nsIPrincipal* aPrincipalToInherit,
-                   uint32_t aFlags,
-                   const nsAString& aWindowTarget,
-                   const char* aTypeHint,
-                   const nsAString& aFileName,
-                   nsIInputStream* aPostData,
-                   nsIInputStream* aHeadersData,
-                   uint32_t aLoadType,
-                   nsISHEntry* aSHEntry,
-                   bool aFirstParty,
-                   const nsAString& aSrcdoc,
-                   nsIDocShell* aSourceDocShell,
-                   nsIURI* aBaseURI,
-                   nsIDocShell** aDocShell2,
-                   nsIRequest** aRequest)
-    : mSrcdoc(aSrcdoc)
+  InternalLoadEvent(nsDocShell* aDocShell,
+                    nsIURI* aURI,
+                    nsIURI* aOriginalURI,
+                    Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
+                    bool aKeepResultPrincipalURIIfSet,
+                    bool aLoadReplace,
+                    nsIURI* aReferrer, uint32_t aReferrerPolicy,
+                    nsIPrincipal* aTriggeringPrincipal,
+                    nsIPrincipal* aPrincipalToInherit,
+                    uint32_t aFlags,
+                    const char* aTypeHint,
+                    nsIInputStream* aPostData,
+                    nsIInputStream* aHeadersData,
+                    uint32_t aLoadType,
+                    nsISHEntry* aSHEntry,
+                    bool aFirstParty,
+                    const nsAString& aSrcdoc,
+                    nsIDocShell* aSourceDocShell,
+                    nsIURI* aBaseURI)
+    : mozilla::Runnable("InternalLoadEvent")
+    , mSrcdoc(aSrcdoc)
     , mDocShell(aDocShell)
     , mURI(aURI)
     , mOriginalURI(aOriginalURI)
     , mResultPrincipalURI(aResultPrincipalURI)
     , mKeepResultPrincipalURIIfSet(aKeepResultPrincipalURIIfSet)
     , mLoadReplace(aLoadReplace)
     , mReferrer(aReferrer)
     , mReferrerPolicy(aReferrerPolicy)
     , mTriggeringPrincipal(aTriggeringPrincipal)
     , mPrincipalToInherit(aPrincipalToInherit)
     , mPostData(aPostData)
     , mHeadersData(aHeadersData)
     , mSHEntry(aSHEntry)
     , mFlags(aFlags)
-    , mWindowTarget(aWindowTarget)
-    , mFileName(aFileName)
     , mLoadType(aLoadType)
     , mFirstParty(aFirstParty)
     , mSourceDocShell(aSourceDocShell)
     , mBaseURI(aBaseURI)
-    , mDocShell2(aDocShell2)
-    , mRequest(aRequest)
   {
     // Make sure to keep null things null as needed
     if (aTypeHint) {
       mTypeHint = aTypeHint;
     } else {
       mTypeHint.SetIsVoid(true);
     }
   }
 
-  nsresult Run()
+  NS_IMETHOD
+  Run() override
   {
     return mDocShell->InternalLoad(mURI, mOriginalURI, mResultPrincipalURI,
                                    mKeepResultPrincipalURIIfSet,
                                    mLoadReplace,
                                    mReferrer,
                                    mReferrerPolicy,
                                    mTriggeringPrincipal, mPrincipalToInherit,
-                                   mFlags, mWindowTarget,
+                                   mFlags, EmptyString(),
                                    mTypeHint.IsVoid() ? nullptr
                                                       : mTypeHint.get(),
-                                   mFileName, mPostData,
+                                   VoidString(), mPostData,
                                    mHeadersData, mLoadType, mSHEntry,
                                    mFirstParty, mSrcdoc, mSourceDocShell,
-                                   mBaseURI, mDocShell2,
-                                   mRequest);
-  }
-
+                                   mBaseURI, nullptr,
+                                   nullptr);
+  }
+
+private:
   nsCString mTypeHint;
   nsString mSrcdoc;
 
   RefPtr<nsDocShell> mDocShell;
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsIURI> mOriginalURI;
   Maybe<nsCOMPtr<nsIURI>> mResultPrincipalURI;
   bool mKeepResultPrincipalURIIfSet;
@@ -9128,184 +9123,22 @@ public:
   nsCOMPtr<nsIURI> mReferrer;
   uint32_t mReferrerPolicy;
   nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
   nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
   nsCOMPtr<nsIInputStream> mPostData;
   nsCOMPtr<nsIInputStream> mHeadersData;
   nsCOMPtr<nsISHEntry> mSHEntry;
   uint32_t mFlags;
-  nsString mWindowTarget;
-  nsString mFileName;
   uint32_t mLoadType;
   bool mFirstParty;
   nsCOMPtr<nsIDocShell> mSourceDocShell;
   nsCOMPtr<nsIURI> mBaseURI;
-  nsIDocShell** mDocShell2;
-  nsIRequest** mRequest;
 };
 
-class InternalLoadEvent : public Runnable
-{
-public:
-  InternalLoadEvent(nsDocShell* aDocShell,
-                    nsIURI* aURI,
-                    nsIURI* aOriginalURI,
-                    Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
-                    bool aKeepResultPrincipalURIIfSet,
-                    bool aLoadReplace,
-                    nsIURI* aReferrer,
-                    uint32_t aReferrerPolicy,
-                    nsIPrincipal* aTriggeringPrincipal,
-                    nsIPrincipal* aPrincipalToInherit,
-                    uint32_t aFlags,
-                    const char* aTypeHint,
-                    nsIInputStream* aPostData,
-                    nsIInputStream* aHeadersData,
-                    uint32_t aLoadType,
-                    nsISHEntry* aSHEntry,
-                    bool aFirstParty,
-                    const nsAString& aSrcdoc,
-                    nsIDocShell* aSourceDocShell,
-                    nsIURI* aBaseURI)
-    : mozilla::Runnable("InternalLoadEvent")
-    , mLoadData(aDocShell,
-                aURI,
-                aOriginalURI,
-                aResultPrincipalURI,
-                aKeepResultPrincipalURIIfSet,
-                aLoadReplace,
-                aReferrer,
-                aReferrerPolicy,
-                aTriggeringPrincipal,
-                aPrincipalToInherit,
-                aFlags,
-                EmptyString(),
-                aTypeHint,
-                VoidString(),
-                aPostData,
-                aHeadersData,
-                aLoadType,
-                aSHEntry,
-                aFirstParty,
-                aSrcdoc,
-                aSourceDocShell,
-                aBaseURI,
-                nullptr,
-                nullptr) 
-  {}
-
-  NS_IMETHOD
-  Run() override
-  {
-    return mLoadData.Run();
-  }
-
-private:
-  InternalLoadData mLoadData;
-};
-
-class LoadURIDelegateHandler final : public PromiseNativeHandler
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(LoadURIDelegateHandler)
-
-  LoadURIDelegateHandler(nsDocShell* aDocShell,
-                         nsIURI* aURI,
-                         nsIURI* aOriginalURI,
-                         Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
-                         bool aKeepResultPrincipalURIIfSet,
-                         bool aLoadReplace,
-                         nsIURI* aReferrer,
-                         uint32_t aReferrerPolicy,
-                         nsIPrincipal* aTriggeringPrincipal,
-                         nsIPrincipal* aPrincipalToInherit,
-                         uint32_t aFlags,
-                         const nsAString& aWindowTarget,
-                         const char* aTypeHint,
-                         const nsAString& aFileName,
-                         nsIInputStream* aPostData,
-                         nsIInputStream* aHeadersData,
-                         uint32_t aLoadType,
-                         nsISHEntry* aSHEntry,
-                         bool aFirstParty,
-                         const nsAString& aSrcdoc,
-                         nsIDocShell* aSourceDocShell,
-                         nsIURI* aBaseURI,
-                         nsIDocShell** aDocShell2,
-                         nsIRequest** aRequest)
-    : mLoadData(aDocShell,
-                aURI,
-                aOriginalURI,
-                aResultPrincipalURI,
-                aKeepResultPrincipalURIIfSet,
-                aLoadReplace,
-                aReferrer,
-                aReferrerPolicy,
-                aTriggeringPrincipal,
-                aPrincipalToInherit,
-                aFlags,
-                aWindowTarget,
-                aTypeHint,
-                aFileName,
-                aPostData,
-                aHeadersData,
-                aLoadType,
-                aSHEntry,
-                aFirstParty,
-                aSrcdoc,
-                aSourceDocShell,
-                aBaseURI,
-                aDocShell2,
-                aRequest)
-  {}
-
-  void
-  ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
-  {
-    if (aValue.isBoolean() && !aValue.toBoolean()) {
-      // Things went fine, not handled by app, let Gecko do its thing
-      mLoadData.Run();
-    } else if (!aValue.isBoolean()) {
-      // If the promise resolves to a non-boolean, let Gecko handle the load
-      mLoadData.Run();
-    }
-  }
-
-  void
-  RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
-  {
-    // In the event of a rejected callback, let Gecko handle the load
-    mLoadData.Run();
-  }
-
-private:
-  ~LoadURIDelegateHandler()
-  {}
-
-  InternalLoadData mLoadData;
-};
-
-NS_IMPL_CYCLE_COLLECTION(LoadURIDelegateHandler, mLoadData.mDocShell,
-                         mLoadData.mURI, mLoadData.mOriginalURI,
-                         mLoadData.mResultPrincipalURI, mLoadData.mReferrer,
-                         mLoadData.mTriggeringPrincipal,
-                         mLoadData.mPrincipalToInherit, 
-                         mLoadData.mPostData, mLoadData.mHeadersData,
-                         mLoadData.mSHEntry, mLoadData.mSourceDocShell,
-                         mLoadData.mBaseURI)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LoadURIDelegateHandler)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(LoadURIDelegateHandler)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(LoadURIDelegateHandler)
-
 /**
  * Returns true if we started an asynchronous load (i.e., from the network), but
  * the document we're loading there hasn't yet become this docshell's active
  * document.
  *
  * When JustStartedNetworkLoad is true, you should be careful about modifying
  * mLoadType and mLSHE.  These are both set when the asynchronous load first
  * starts, and the load expects that, when it eventually runs InternalLoad,
@@ -9543,50 +9376,34 @@ nsDocShell::InternalLoad(nsIURI* aURI,
   }
 
   nsIDocument* doc = mContentViewer ? mContentViewer->GetDocument()
                                     : nullptr;
 
   const bool isDocumentAuxSandboxed = doc &&
     (doc->GetSandboxFlags() & SANDBOXED_AUXILIARY_NAVIGATION);
 
-  const bool checkLoadDelegates = !(aFlags & INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED);
-  aFlags = aFlags & ~INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED;
-
-  if (aURI && mLoadURIDelegate && checkLoadDelegates &&
+  if (aURI && mLoadURIDelegate &&
       (!targetDocShell || targetDocShell == static_cast<nsIDocShell*>(this))) {
     // Dispatch only load requests for the current or a new window to the
     // delegate, e.g., to allow for GeckoView apps to handle the load event
     // outside of Gecko.
     const int where = (aWindowTarget.IsEmpty() || targetDocShell)
                       ? nsIBrowserDOMWindow::OPEN_CURRENTWINDOW
                       : nsIBrowserDOMWindow::OPEN_NEWWINDOW;
 
     if (where == nsIBrowserDOMWindow::OPEN_NEWWINDOW && isDocumentAuxSandboxed) {
       return NS_ERROR_DOM_INVALID_ACCESS_ERR;
     }
 
-    RefPtr<dom::Promise> promise;
+    bool loadURIHandled = false;
     rv = mLoadURIDelegate->LoadURI(aURI, where, aFlags, aTriggeringPrincipal,
-                                   getter_AddRefs(promise));
-    if (NS_SUCCEEDED(rv) && promise) {
-      const uint32_t flags = aFlags | INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED;
-
-      RefPtr<LoadURIDelegateHandler> handler = 
-        new LoadURIDelegateHandler(this, aURI, aOriginalURI, aResultPrincipalURI,
-                                   aKeepResultPrincipalURIIfSet,
-                                   aLoadReplace, aReferrer, aReferrerPolicy,
-                                   aTriggeringPrincipal, aPrincipalToInherit,
-                                   flags, aWindowTarget, aTypeHint, aFileName, aPostData,
-                                   aHeadersData, aLoadType, aSHEntry, aFirstParty,
-                                   aSrcdoc, aSourceDocShell, aBaseURI, nullptr, nullptr);
-
-      promise->AppendNativeHandler(handler);
-
-      // Checking for load delegates; InternalLoad will be re-called if needed.
+                                   &loadURIHandled);
+    if (NS_SUCCEEDED(rv) && loadURIHandled) {
+      // The request has been handled, nothing to do here.
       return NS_OK;
     }
   }
 
   //
   // Resolve the window target before going any further...
   // If the load has been targeted to another DocShell, then transfer the
   // load to it...
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -109,19 +109,16 @@ interface nsIDocShell : nsIDocShellTreeI
   // Whether this is the load of a frame's original src attribute
   const long INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC      = 0x80;
 
   const long INTERNAL_LOAD_FLAGS_NO_OPENER               = 0x100;
 
   // Whether a top-level data URI navigation is allowed for that load
   const long INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI    = 0x200;
 
-  // Whether load delegates have already been checked for this load
-  const long INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED       = 0x400;
-
   // Whether the load was triggered by user interaction.
   const long INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED       = 0x1000;
 
   /**
    * Loads the given URI.  This method is identical to loadURI(...) except
    * that its parameter list is broken out instead of being packaged inside
    * of an nsIDocShellLoadInfo object...
    *
--- a/mfbt/Maybe.h
+++ b/mfbt/Maybe.h
@@ -17,18 +17,16 @@
 #include "mozilla/OperatorNewExtensions.h"
 #include "mozilla/Poison.h"
 #include "mozilla/TypeTraits.h"
 
 #include <new>  // for placement new
 #include <ostream>
 #include <type_traits>
 
-class nsCycleCollectionTraversalCallback;
-
 namespace mozilla {
 
 struct Nothing { };
 
 namespace detail {
 
 // You would think that poisoning Maybe instances could just be a call
 // to mozWritePoison.  Unfortunately, using a simple call to
@@ -710,33 +708,11 @@ operator<=(const Maybe<T>& aLHS, const M
 }
 
 template<typename T> bool
 operator>=(const Maybe<T>& aLHS, const Maybe<T>& aRHS)
 {
   return !(aLHS < aRHS);
 }
 
-
-template<typename T>
-void
-ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
-                            Maybe<T>& aMaybe,
-                            const char* aName,
-                            uint32_t aFlags = 0)
-{
-  if (aMaybe.isSome()) {
-    ImplCycleCollectionTraverse(aCallback, aMaybe.ref(), aName, aFlags);
-  }
-}
-
-template<typename T>
-void
-ImplCycleCollectionUnlink(Maybe<T>& aMaybe)
-{
-  if (aMaybe.isSome()) {
-    ImplCycleCollectionUnlink(aMaybe.ref());
-  }
-}
-
 } // namespace mozilla
 
 #endif /* mozilla_Maybe_h */
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
@@ -81,16 +81,17 @@ class ProgressDelegateTest : BaseSession
     @Test fun loadUnknownHost() {
         loadExpectNetError(INVALID_URI)
     }
 
     @Test fun loadBadPort() {
         loadExpectNetError("http://localhost:1/")
     }
 
+    @Ignore
     @Test fun multipleLoads() {
         sessionRule.session.loadUri(INVALID_URI)
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStops(2)
 
         sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate {
             @AssertCalled(count = 2, order = [1, 3])
             override fun onPageStart(session: GeckoSession, url: String) {
--- a/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
@@ -145,34 +145,23 @@ class GeckoViewNavigation extends GeckoV
     });
 
     // Wait indefinitely for app to respond with a browser or null
     Services.tm.spinEventLoopUntil(() =>
         this.window.closed || browser !== undefined);
     return browser || null;
   }
 
-  isURIHandled(aUri, aWhere, aFlags) {
-    debug `isURIHandled: uri=${aUri} where=${aWhere} flags=${aFlags}`;
-
-    let handled = undefined;
-    LoadURIDelegate.load(this.window, this.eventDispatcher, aUri, aWhere, aFlags).then((response) => {
-      handled = response;
-    });
-
-    Services.tm.spinEventLoopUntil(() => this.window.closed || handled !== undefined);
-    return handled;
-  }
-
   // nsIBrowserDOMWindow.
   createContentWindow(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal) {
     debug `createContentWindow: uri=${aUri && aUri.spec}
                                 where=${aWhere} flags=${aFlags}`;
 
-    if (this.isURIHandled(aUri, aWhere, aFlags)) {
+    if (LoadURIDelegate.load(this.window, this.eventDispatcher,
+                             aUri, aWhere, aFlags)) {
       // 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, null);
     if (!browser) {
       Components.returnCode = Cr.NS_ERROR_ABORT;
@@ -185,17 +174,18 @@ class GeckoViewNavigation extends GeckoV
   // nsIBrowserDOMWindow.
   createContentWindowInFrame(aUri, aParams, aWhere, aFlags, aNextTabParentId,
                              aName) {
     debug `createContentWindowInFrame: uri=${aUri && aUri.spec}
                                        where=${aWhere} flags=${aFlags}
                                        nextTabParentId=${aNextTabParentId}
                                        name=${aName}`;
 
-    if (this.isURIHandled(aUri, aWhere, aFlags)) {
+    if (LoadURIDelegate.load(this.window, this.eventDispatcher,
+                             aUri, aWhere, aFlags)) {
       // 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, aNextTabParentId);
     if (!browser) {
       Components.returnCode = Cr.NS_ERROR_ABORT;
@@ -205,17 +195,18 @@ class GeckoViewNavigation extends GeckoV
     return browser;
   }
 
   handleOpenUri(aUri, aOpener, aWhere, aFlags, aTriggeringPrincipal,
                 aNextTabParentId) {
     debug `handleOpenUri: uri=${aUri && aUri.spec}
                           where=${aWhere} flags=${aFlags}`;
 
-    if (this.isURIHandled(aUri, aWhere, aFlags)) {
+    if (LoadURIDelegate.load(this.window, this.eventDispatcher,
+                             aUri, aWhere, aFlags)) {
       return null;
     }
 
     let browser = this.browser;
 
     if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW ||
         aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB ||
         aWhere === Ci.nsIBrowserDOMWindow.OPEN_SWITCHTAB) {
--- a/mobile/android/modules/geckoview/LoadURIDelegate.jsm
+++ b/mobile/android/modules/geckoview/LoadURIDelegate.jsm
@@ -3,26 +3,41 @@
  * 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";
 
 var EXPORTED_SYMBOLS = ["LoadURIDelegate"];
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+XPCOMUtils.defineLazyModuleGetters(this, {
+  Services: "resource://gre/modules/Services.jsm",
+});
+
 var LoadURIDelegate = {
   // Delegate URI loading to the app.
   // Return whether the loading has been handled.
   load: function(aWindow, aEventDispatcher, aUri, aWhere, aFlags) {
     if (!aWindow) {
-      return Promise.resolve(false);
+      return false;
     }
 
     const message = {
       type: "GeckoView:OnLoadRequest",
       uri: aUri ? aUri.displaySpec : "",
       where: aWhere,
       flags: aFlags
     };
 
-    return aEventDispatcher.sendRequestForResult(message).then((response) => response || false).catch(() => false);
+    let handled = undefined;
+    aEventDispatcher.sendRequestForResult(message).then(response => {
+      handled = response;
+    }, () => {
+      // There was an error or listener was not registered in GeckoSession,
+      // treat as unhandled.
+      handled = false;
+    });
+    Services.tm.spinEventLoopUntil(() =>
+        aWindow.closed || handled !== undefined);
+
+    return handled || false;
   }
 };
--- a/netwerk/base/nsIChannelEventSink.idl
+++ b/netwerk/base/nsIChannelEventSink.idl
@@ -48,23 +48,16 @@ interface nsIChannelEventSink : nsISuppo
     /**
      * This is a special-cased redirect coming from hitting HSTS upgrade
      * redirect from http to https only.  In some cases this type of redirect
      * may be considered as safe despite not being the-same-origin redirect.
      */
     const unsigned long REDIRECT_STS_UPGRADE = 1 << 3;
 
     /**
-     * This redirect has already been presented to the nsILoadURIDelegate
-     * for possible handling; if this flag is set we may safely skip checking
-     * if the nsILoadURIDelegate will handle the redirect.
-     */
-    const unsigned long REDIRECT_DELEGATES_CHECKED = 1 << 4;
-
-    /**
      * Called when a redirect occurs. This may happen due to an HTTP 3xx status
      * code. The purpose of this method is to notify the sink that a redirect
      * is about to happen, but also to give the sink the right to veto the
      * redirect by throwing or passing a failure-code in the callback.
      *
      * Note that vetoing the redirect simply means that |newChannel| will not
      * be opened. It is important to understand that |oldChannel| will continue
      * loading as if it received a HTTP 200, which includes notifying observers
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -1,18 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nspr.h"
 #include "mozilla/Logging.h"
 #include "mozilla/IntegerPrintfMacros.h"
-#include "mozilla/dom/Promise.h"
-#include "mozilla/dom/PromiseNativeHandler.h"
 
 #include "nsDocLoader.h"
 #include "nsCURILoader.h"
 #include "nsNetUtil.h"
 #include "nsIHttpChannel.h"
 #include "nsIWebProgressListener2.h"
 
 #include "nsIServiceManager.h"
@@ -31,18 +29,16 @@
 #include "nsIScriptSecurityManager.h"
 
 #include "nsITransport.h"
 #include "nsISocketTransport.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
-#include "nsILoadURIDelegate.h"
-#include "nsIBrowserDOMWindow.h"
 
 using mozilla::DebugOnly;
 using mozilla::LogLevel;
 
 //
 // Log module for nsIDocumentLoader logging...
 //
 // To enable logging (see mozilla/Logging.h for full details):
@@ -1419,116 +1415,21 @@ int64_t nsDocLoader::CalculateMaxProgres
     if (info->mMaxProgress < info->mCurrentProgress) {
       return int64_t(-1);
     }
     max += info->mMaxProgress;
   }
   return max;
 }
 
-class LoadURIDelegateRedirectHandler final : public mozilla::dom::PromiseNativeHandler
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(LoadURIDelegateRedirectHandler)
-
-  LoadURIDelegateRedirectHandler(nsDocLoader* aDocLoader,
-                                 nsIChannel* aOldChannel,
-                                 nsIChannel* aNewChannel,
-                                 uint32_t aFlags,
-                                 nsIAsyncVerifyRedirectCallback* aCallback)
-  : mDocLoader(aDocLoader)
-  , mOldChannel(aOldChannel)
-  , mNewChannel(aNewChannel)
-  , mFlags(aFlags)
-  , mCallback(aCallback)
-  {}
-
-  void
-  ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
-  {
-    if (aValue.isBoolean() && aValue.toBoolean()) {
-      // The app handled the redirect, notify the callback
-      mCallback->OnRedirectVerifyCallback(NS_ERROR_ABORT);
-    } else {
-      UnhandledCallback();
-    }
-  }
-
-  void
-  RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
-  {
-    UnhandledCallback();
-  }
-
-private:
-  ~LoadURIDelegateRedirectHandler()
-  {}
-
-  void UnhandledCallback()
-  {
-    // If the redirect wasn't handled by the nsILoadURIDelegate, let Gecko
-    // handle it.
-    mFlags |= nsIChannelEventSink::REDIRECT_DELEGATES_CHECKED;
-    mDocLoader->AsyncOnChannelRedirect(mOldChannel, mNewChannel, mFlags,
-                                       mCallback);
-  }
-
-  RefPtr<nsDocLoader> mDocLoader;
-  nsCOMPtr<nsIChannel> mOldChannel;
-  nsCOMPtr<nsIChannel> mNewChannel;
-  uint32_t mFlags;
-  nsCOMPtr<nsIAsyncVerifyRedirectCallback> mCallback;
-};
-
-NS_IMPL_CYCLE_COLLECTION(LoadURIDelegateRedirectHandler, mDocLoader, 
-                         mOldChannel, mNewChannel, mCallback)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LoadURIDelegateRedirectHandler)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(LoadURIDelegateRedirectHandler)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(LoadURIDelegateRedirectHandler)
-
 NS_IMETHODIMP nsDocLoader::AsyncOnChannelRedirect(nsIChannel *aOldChannel,
                                                   nsIChannel *aNewChannel,
                                                   uint32_t aFlags,
                                                   nsIAsyncVerifyRedirectCallback *cb)
 {
-  if ((aFlags &
-      (nsIChannelEventSink::REDIRECT_TEMPORARY |
-       nsIChannelEventSink::REDIRECT_PERMANENT)) &&
-      !(aFlags & nsIChannelEventSink::REDIRECT_DELEGATES_CHECKED)) {
-    nsCOMPtr<nsIDocShell> docShell =
-      do_QueryInterface(static_cast<nsIRequestObserver*>(this));
-
-    nsCOMPtr<nsILoadURIDelegate> delegate;
-    docShell->GetLoadURIDelegate(getter_AddRefs(delegate));
-
-    nsCOMPtr<nsIURI> newURI;
-    aNewChannel->GetURI(getter_AddRefs(newURI));
-
-    if (newURI && delegate) {
-      RefPtr<mozilla::dom::Promise> promise;
-      const int where = nsIBrowserDOMWindow::OPEN_CURRENTWINDOW;
-      nsresult rv = delegate->LoadURI(newURI, where, /* flags */ 0,
-                                      /* triggering principal */ nullptr,
-                                      getter_AddRefs(promise));
-      if (NS_SUCCEEDED(rv) && promise) {
-        RefPtr<LoadURIDelegateRedirectHandler> handler =
-          new LoadURIDelegateRedirectHandler(this, aOldChannel, aNewChannel,
-                                             aFlags, cb);
-
-        promise->AppendNativeHandler(handler);
-        return NS_OK;
-      }
-    }
-  }
-
   if (aOldChannel)
   {
     nsLoadFlags loadFlags = 0;
     int32_t stateFlags = nsIWebProgressListener::STATE_REDIRECTING |
                          nsIWebProgressListener::STATE_IS_REQUEST;
 
     aOldChannel->GetLoadFlags(&loadFlags);
     // If the document channel is being redirected, then indicate that the
--- a/xpcom/base/nsILoadURIDelegate.idl
+++ b/xpcom/base/nsILoadURIDelegate.idl
@@ -21,16 +21,13 @@ interface nsILoadURIDelegate : nsISuppor
 {
   /**
    * Delegates the URI load.
    *
    * @param aURI The URI to load.
    * @param aWhere See possible values described in nsIBrowserDOMWindow.
    * @param aFlags Flags which control the behavior of the load.
    * @param aTriggeringPrincipal The principal that triggered the load of aURI.
-   * @return A promise which can resolve to a boolean indicating whether or
-   *         not the app handled the load. Rejection should be treated the same
-   *         as a false resolution.
   */
-  Promise
+  boolean
   loadURI(in nsIURI aURI, in short aWhere, in long aFlags,
           in nsIPrincipal aTriggeringPrincipal);
 };