Bug 1487542 - Change LoadRequest.isUserTriggered to isRedirect. r=snorp,smaug
authorMatt Brubeck <mbrubeck@mozilla.com>
Wed, 21 Nov 2018 22:35:42 +0000
changeset 504060 6893246437a24a624ba3876c518ec82ba09e995d
parent 504059 2ec7bd511b7f5ab1b6f11beca250dd094a79943b
child 504061 c54f764614f707076e93256e7e241eddcc087283
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, smaug
bugs1487542
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 1487542 - Change LoadRequest.isUserTriggered to isRedirect. r=snorp,smaug Differential Revision: https://phabricator.services.mozilla.com/D12370
docshell/base/nsIWebNavigation.idl
mobile/android/geckoview/api.txt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
uriloader/base/nsDocLoader.cpp
--- a/docshell/base/nsIWebNavigation.idl
+++ b/docshell/base/nsIWebNavigation.idl
@@ -210,16 +210,21 @@ interface nsIWebNavigation : nsISupports
 
   /**
    * Allows a top-level data: navigation to occur. E.g. view-image
    * is an explicit user action which should be allowed.
    */
   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
    * however, the URI dispatcher will go through its normal process of content
    * loading.
    *
    * @param aURI
    *        The URI string to load.  For HTTP and FTP URLs and possibly others,
    *        characters above U+007F will be converted to UTF-8 and then URL-
--- a/mobile/android/geckoview/api.txt
+++ b/mobile/android/geckoview/api.txt
@@ -369,32 +369,29 @@ package org.mozilla.geckoview {
 
   public static interface GeckoSession.NavigationDelegate {
     method public void onCanGoBack(org.mozilla.geckoview.GeckoSession, boolean);
     method public void onCanGoForward(org.mozilla.geckoview.GeckoSession, boolean);
     method public org.mozilla.geckoview.GeckoResult<java.lang.String> onLoadError(org.mozilla.geckoview.GeckoSession, java.lang.String, org.mozilla.geckoview.WebRequestError);
     method public org.mozilla.geckoview.GeckoResult<org.mozilla.geckoview.AllowOrDeny> onLoadRequest(org.mozilla.geckoview.GeckoSession, org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest);
     method public void onLocationChange(org.mozilla.geckoview.GeckoSession, java.lang.String);
     method public org.mozilla.geckoview.GeckoResult<org.mozilla.geckoview.GeckoSession> onNewSession(org.mozilla.geckoview.GeckoSession, java.lang.String);
-    field public static final int LOAD_REQUEST_IS_USER_TRIGGERED = 4096;
+    field public static final int LOAD_REQUEST_IS_REDIRECT = 8388608;
     field public static final int TARGET_WINDOW_CURRENT = 1;
     field public static final int TARGET_WINDOW_NEW = 2;
     field public static final int TARGET_WINDOW_NONE = 0;
   }
 
   public static class GeckoSession.NavigationDelegate.LoadRequest {
-    field public final boolean isUserTriggered;
+    field public final boolean isRedirect;
     field public final int target;
     field public final java.lang.String triggerUri;
     field public final java.lang.String uri;
   }
 
-  public static interface GeckoSession.NavigationDelegate.LoadRequestFlags implements java.lang.annotation.Annotation {
-  }
-
   public static interface GeckoSession.NavigationDelegate.TargetWindow implements java.lang.annotation.Annotation {
   }
 
   public static interface GeckoSession.PermissionDelegate {
     method public void onAndroidPermissionsRequest(org.mozilla.geckoview.GeckoSession, java.lang.String[], org.mozilla.geckoview.GeckoSession.PermissionDelegate.Callback);
     method public void onContentPermissionRequest(org.mozilla.geckoview.GeckoSession, java.lang.String, int, org.mozilla.geckoview.GeckoSession.PermissionDelegate.Callback);
     method public void onMediaPermissionRequest(org.mozilla.geckoview.GeckoSession, java.lang.String, org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource[], org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource[], org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaCallback);
     field public static final int PERMISSION_AUTOPLAY_MEDIA = 2;
--- 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
@@ -229,16 +229,18 @@ class NavigationDelegateTest : BaseSessi
                 assertThat("URI should not be null", request.uri, notNullValue())
                 assertThat("URL should match", request.uri,
                         equalTo(forEachCall(request.uri, redirectUri)))
                 assertThat("Trigger URL should be null", request.triggerUri,
                            nullValue())
                 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
             }
         })
     }
 
     @Test fun safebrowsingPhishing() {
         val phishingUri = "https://www.itisatrap.org/firefox/its-a-trap.html"
 
@@ -498,16 +500,17 @@ class NavigationDelegateTest : BaseSessi
                 assertThat("Session should not be null", session, notNullValue())
                 assertThat("URI should not be null", request.uri, notNullValue())
                 assertThat("URI should match", request.uri, endsWith(HELLO_HTML_PATH))
                 assertThat("Trigger URL should be null", request.triggerUri,
                            nullValue())
                 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
             }
 
             @AssertCalled(count = 1, order = [2])
             override fun onLocationChange(session: GeckoSession, url: String) {
                 assertThat("Session should not be null", session, notNullValue())
                 assertThat("URL should not be null", url, notNullValue())
                 assertThat("URL should match", url, endsWith(HELLO_HTML_PATH))
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -406,21 +406,16 @@ public class GeckoSession implements Par
                     case 0: // OPEN_DEFAULTWINDOW
                     case 1: // OPEN_CURRENTWINDOW
                         return NavigationDelegate.TARGET_WINDOW_CURRENT;
                     default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_SWITCHTAB
                         return NavigationDelegate.TARGET_WINDOW_NEW;
                 }
             }
 
-            // 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,
                                       final GeckoBundle message,
                                       final EventCallback callback) {
                 if ("GeckoView:LocationChange".equals(event)) {
                     if (message.getBoolean("isTopLevel")) {
                         delegate.onLocationChange(GeckoSession.this,
@@ -2807,40 +2802,34 @@ public class GeckoSession implements Par
         void onCanGoForward(GeckoSession session, boolean canGoForward);
 
         @IntDef({TARGET_WINDOW_NONE, TARGET_WINDOW_CURRENT, TARGET_WINDOW_NEW})
         /* package */ @interface TargetWindow {}
         public static final int TARGET_WINDOW_NONE = 0;
         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.
          */
         public static class LoadRequest {
             /* package */ LoadRequest(@NonNull final String uri,
                                       @Nullable final String triggerUri,
                                       int geckoTarget,
                                       int flags) {
                 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
             private @TargetWindow int convertGeckoTarget(int geckoTarget) {
                 switch (geckoTarget) {
                     case 0: // OPEN_DEFAULTWINDOW
                     case 1: // OPEN_CURRENTWINDOW
                         return TARGET_WINDOW_CURRENT;
@@ -2864,17 +2853,17 @@ public class GeckoSession implements Par
              * The target where the window has requested to open.
              * One of {@link #TARGET_WINDOW_NONE TARGET_WINDOW_*}.
              */
             public final @TargetWindow int target;
 
             /**
              * True if and only if the request was triggered by user interaction.
              */
-            public final boolean isUserTriggered;
+            public final boolean isRedirect;
         }
 
         /**
          * A request to open an URI. This is called before each page load to
          * allow custom behavior implementation.
          * For example, this can be used to override the behavior of
          * TAGET_WINDOW_NEW requests, which defaults to requesting a new
          * GeckoSession via onNewSession.
--- 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
@@ -670,17 +670,17 @@ public class GeckoViewActivity extends A
         }
 
         @Override
         public GeckoResult<AllowOrDeny> onLoadRequest(final GeckoSession session,
                                                       final LoadRequest request) {
             Log.d(LOGTAG, "onLoadRequest=" + request.uri +
                   " triggerUri=" + request.triggerUri +
                   " where=" + request.target +
-                  " isUserTriggered=" + request.isUserTriggered);
+                  " isRedirect=" + request.isRedirect);
 
             return GeckoResult.fromValue(AllowOrDeny.ALLOW);
         }
 
         @Override
         public GeckoResult<GeckoSession> onNewSession(final GeckoSession session, final String uri) {
             GeckoSession newSession = new GeckoSession(session.getSettings());
 
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -6,16 +6,17 @@
 #include "nspr.h"
 #include "mozilla/Logging.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
 #include "nsDocLoader.h"
 #include "nsCURILoader.h"
 #include "nsNetUtil.h"
 #include "nsIHttpChannel.h"
+#include "nsIWebNavigation.h"
 #include "nsIWebProgressListener2.h"
 
 #include "nsIServiceManager.h"
 #include "nsString.h"
 
 #include "nsIURL.h"
 #include "nsCOMPtr.h"
 #include "nscore.h"
@@ -1441,17 +1442,18 @@ NS_IMETHODIMP nsDocLoader::AsyncOnChanne
     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,
+      nsresult rv = delegate->LoadURI(newURI, where,
+                                      nsIWebNavigation::LOAD_FLAGS_IS_REDIRECT,
                                       /* triggering principal */ nullptr,
                                       &loadURIHandled);
       if (NS_SUCCEEDED(rv) && loadURIHandled) {
         cb->OnRedirectVerifyCallback(NS_OK);
         return NS_OK;
       }
     }
   }