diff --git a/docshell/base/nsIWebNavigation.idl b/docshell/base/nsIWebNavigation.idl index 82a0bb8efa57f..fcddcd85de62e 100644 --- a/docshell/base/nsIWebNavigation.idl +++ b/docshell/base/nsIWebNavigation.idl @@ -214,6 +214,11 @@ interface nsIWebNavigation : nsISupports */ const unsigned long LOAD_FLAGS_FORCE_ALLOW_DATA_URI = 0x400000; + /** + * This load is the result of an HTTP redirect. + */ + const unsigned long LOAD_FLAGS_IS_REDIRECT = 0x800000; + /** * Loads a given URI. This will give priority to loading the requested URI * in the object implementing this interface. If it can't be loaded here diff --git 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 index 0ddaec78bacd7..8b04686a06a9f 100644 --- 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 @@ -234,6 +234,8 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Target should not be null", request.target, notNullValue()) assertThat("Target should match", request.target, equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + assertThat("Redirect flag is set", request.isRedirect, + equalTo(forEachCall(false, true))) return null } }) @@ -503,6 +505,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Target should not be null", request.target, notNullValue()) assertThat("Target should match", request.target, equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + assertThat("Redirect flag is not set", request.isRedirect, equalTo(false)) return null } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java index af63e8ea6970c..d1812603add15 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java @@ -411,11 +411,6 @@ private int convertGeckoTarget(int geckoTarget) { } } - // The flags are already matched with nsIDocShell.idl. - private int filterFlags(int flags) { - return flags & NavigationDelegate.LOAD_REQUEST_IS_USER_TRIGGERED; - } - @Override public void handleMessage(final NavigationDelegate delegate, final String event, @@ -2812,15 +2807,11 @@ public interface NavigationDelegate { public static final int TARGET_WINDOW_CURRENT = 1; public static final int TARGET_WINDOW_NEW = 2; - @IntDef(flag = true, - value = {LOAD_REQUEST_IS_USER_TRIGGERED}) - /* package */ @interface LoadRequestFlags {} - - // Match with nsIDocShell.idl. + // Match with nsIWebNavigation.idl. /** - * The load request was triggered by user input. + * The load request was triggered by an HTTP redirect. */ - public static final int LOAD_REQUEST_IS_USER_TRIGGERED = 0x1000; + static final int LOAD_REQUEST_IS_REDIRECT = 0x800000; /** * Load request details. @@ -2833,9 +2824,7 @@ public static class LoadRequest { this.uri = uri; this.triggerUri = triggerUri; this.target = convertGeckoTarget(geckoTarget); - - // Match with nsIDocShell.idl. - this.isUserTriggered = (flags & 0x1000) != 0; + this.isRedirect = (flags & LOAD_REQUEST_IS_REDIRECT) != 0; } // This needs to match nsIBrowserDOMWindow.idl @@ -2869,7 +2858,7 @@ public static class LoadRequest { /** * True if and only if the request was triggered by user interaction. */ - public final boolean isUserTriggered; + public final boolean isRedirect; } /** diff --git a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java index 74b3c4cb163fe..278557341d749 100644 --- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java +++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java @@ -675,7 +675,7 @@ public GeckoResult onLoadRequest(final GeckoSession session, Log.d(LOGTAG, "onLoadRequest=" + request.uri + " triggerUri=" + request.triggerUri + " where=" + request.target + - " isUserTriggered=" + request.isUserTriggered); + " isRedirect=" + request.isRedirect); return GeckoResult.fromValue(AllowOrDeny.ALLOW); } diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index 87e08d997e55b..a193d8dff458a 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -11,6 +11,7 @@ #include "nsCURILoader.h" #include "nsNetUtil.h" #include "nsIHttpChannel.h" +#include "nsIWebNavigation.h" #include "nsIWebProgressListener2.h" #include "nsIServiceManager.h" @@ -1446,7 +1447,8 @@ NS_IMETHODIMP nsDocLoader::AsyncOnChannelRedirect(nsIChannel *aOldChannel, if (newURI) { const int where = nsIBrowserDOMWindow::OPEN_CURRENTWINDOW; bool loadURIHandled = false; - nsresult rv = delegate->LoadURI(newURI, where, /* flags */ 0, + nsresult rv = delegate->LoadURI(newURI, where, + nsIWebNavigation::LOAD_FLAGS_IS_REDIRECT, /* triggering principal */ nullptr, &loadURIHandled); if (NS_SUCCEEDED(rv) && loadURIHandled) {