Bug 1478171 - [1.0] Forward channel redirect to nsILoadURIDelegate to allow external handling. r=snorp,smaug
authorEugen Sawin <esawin@mozilla.com>
Wed, 31 Oct 2018 16:16:28 -0500
changeset 444028 be2ca9d4fb4c4e5a79b3ddf3be8cdad4e2df1ed3
parent 444002 ef53052535067df8a9eee34d65e25d6fadac8911
child 444029 da432adc1cd593a84f5f95e0c362cca424760dfb
push id34979
push userccoroiu@mozilla.com
push dateFri, 02 Nov 2018 05:11:39 +0000
treeherdermozilla-central@b8222faf7d06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, smaug
bugs1478171
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1478171 - [1.0] Forward channel redirect to nsILoadURIDelegate to allow external handling. r=snorp,smaug
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
uriloader/base/nsDocLoader.cpp
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
@@ -200,17 +200,16 @@ class NavigationDelegateTest : BaseSessi
                 object : Callbacks.TrackingProtectionDelegate {
             @AssertCalled(false)
             override fun onTrackerBlocked(session: GeckoSession, uri: String,
                                           categories: Int) {
             }
         })
     }
 
-    @Ignore
     @Test fun redirectLoad() {
         val redirectUri = if (sessionRule.env.isAutomation) {
             "http://example.org/tests/robocop/robocop_blank_02.html"
         } else {
             "http://jigsaw.w3.org/HTTP/300/Overview.html"
         }
         val uri = if (sessionRule.env.isAutomation) {
             "http://example.org/tests/robocop/simple_redirect.sjs?$redirectUri"
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -29,16 +29,18 @@
 #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::dom::ContentBlockingLog;
 using mozilla::DebugOnly;
 using mozilla::LogLevel;
 
 //
 // Log module for nsIDocumentLoader logging...
 //
@@ -1419,16 +1421,46 @@ int64_t nsDocLoader::CalculateMaxProgres
   return max;
 }
 
 NS_IMETHODIMP nsDocLoader::AsyncOnChannelRedirect(nsIChannel *aOldChannel,
                                                   nsIChannel *aNewChannel,
                                                   uint32_t aFlags,
                                                   nsIAsyncVerifyRedirectCallback *cb)
 {
+  if (aFlags &
+      (nsIChannelEventSink::REDIRECT_TEMPORARY |
+       nsIChannelEventSink::REDIRECT_PERMANENT)) {
+    nsCOMPtr<nsIDocShell> docShell =
+      do_QueryInterface(static_cast<nsIRequestObserver*>(this));
+
+    nsCOMPtr<nsILoadURIDelegate> delegate;
+    if (docShell) {
+      docShell->GetLoadURIDelegate(getter_AddRefs(delegate));
+    }
+
+    nsCOMPtr<nsIURI> newURI;
+    if (delegate) {
+      // No point in getting the URI if we don't have a LoadURIDelegate.
+      aNewChannel->GetURI(getter_AddRefs(newURI));
+    }
+
+    if (newURI) {
+      const int where = nsIBrowserDOMWindow::OPEN_CURRENTWINDOW;
+      bool loadURIHandled = false;
+      nsresult rv = delegate->LoadURI(newURI, where, /* flags */ 0,
+                                      /* triggering principal */ nullptr,
+                                      &loadURIHandled);
+      if (NS_SUCCEEDED(rv) && loadURIHandled) {
+        cb->OnRedirectVerifyCallback(NS_OK);
+        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