Bug 1322579 - Add flags to GeckoSession.loadUri() r=esawin,droeh draft
authorJames Willcox <snorp@snorp.net>
Fri, 09 Mar 2018 13:21:16 -0600
changeset 769465 8fdd82bcf883651fca5b47251124734c95943ebc
parent 769460 8aba2e75d3e1d7763ce06b7a44b81494dd8f8aa9
child 769466 86b2019e27ec235a0f1dfe6733b6ca41b643682f
push id103134
push userbmo:snorp@snorp.net
push dateMon, 19 Mar 2018 16:59:33 +0000
reviewersesawin, droeh
bugs1322579
milestone61.0a1
Bug 1322579 - Add flags to GeckoSession.loadUri() r=esawin,droeh MozReview-Commit-ID: 9meMsIOIZRX
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/modules/geckoview/GeckoViewNavigation.jsm
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -782,32 +782,112 @@ public class GeckoSession extends LayerS
      *
      * @return TextInputController instance.
      */
     public @NonNull TextInputController getTextInputController() {
         // May be called on any thread.
         return mTextInput;
     }
 
+    @IntDef(flag=true,
+            value = { LOAD_FLAGS_NONE, LOAD_FLAGS_BYPASS_CACHE, LOAD_FLAGS_BYPASS_PROXY,
+                      LOAD_FLAGS_EXTERNAL, LOAD_FLAGS_ALLOW_POPUPS })
+    public @interface LoadFlags {}
+
+    // These flags follow similarly named ones in Gecko's nsIWebNavigation.idl
+    // https://searchfox.org/mozilla-central/source/docshell/base/nsIWebNavigation.idl
+    //
+    // We do not use the same values directly in order to insulate ourselves from
+    // changes in Gecko. Instead, the flags are converted in GeckoViewNavigation.jsm.
+
     /**
-    * Load the given URI.
-    * @param uri The URI of the resource to load.
-    */
-    public void loadUri(String uri) {
-        final GeckoBundle msg = new GeckoBundle();
-        msg.putString("uri", uri);
-        mEventDispatcher.dispatch("GeckoView:LoadUri", msg);
-    }
+     * Default load flag, no special considerations.
+     */
+    public static final int LOAD_FLAGS_NONE = 0;
+
+    /**
+     * Bypass the cache.
+     */
+    public static final int LOAD_FLAGS_BYPASS_CACHE = 1 << 0;
+
+    /**
+     * Bypass the proxy, if one has been configured.
+     */
+    public static final int LOAD_FLAGS_BYPASS_PROXY = 1 << 1;
+
+    /**
+     * The load is coming from an external app. Perform additional checks.
+     */
+    public static final int LOAD_FLAGS_EXTERNAL = 1 << 2;
+
+    /**
+     * Popup blocking will be disabled for this load
+     */
+    public static final int LOAD_FLAGS_ALLOW_POPUPS = 1 << 3;
 
     /**
     * Load the given URI.
     * @param uri The URI of the resource to load.
     */
-    public void loadUri(Uri uri) {
-        loadUri(uri.toString());
+    public void loadUri(@NonNull String uri) {
+        loadUri(uri, null, LOAD_FLAGS_NONE);
+    }
+
+    /**
+     * Load the given URI with the specified referrer and load type.
+     *
+     * @param uri the URI to load
+     * @param flags the load flags to use, an ORed value of {@link #LOAD_FLAGS_NONE LOAD_FLAGS_*}
+     */
+    public void loadUri(@NonNull String uri, @LoadFlags int flags) {
+        loadUri(uri, null, flags);
+    }
+
+    /**
+     * Load the given URI with the specified referrer and load type.
+     *
+     * @param uri the URI to load
+     * @param referrer the referrer, may be null
+     * @param flags the load flags to use, an ORed value of {@link #LOAD_FLAGS_NONE LOAD_FLAGS_*}
+     */
+    public void loadUri(@NonNull String uri, @Nullable String referrer, @LoadFlags int flags) {
+        final GeckoBundle msg = new GeckoBundle();
+        msg.putString("uri", uri);
+        msg.putInt("flags", flags);
+        if (referrer != null) {
+            msg.putString("referrer", referrer);
+        }
+        mEventDispatcher.dispatch("GeckoView:LoadUri", msg);
+    }
+
+    /**
+     * Load the given Uri.
+     * @param uri The Uri of the resource to load.
+     */
+    public void loadUri(@NonNull Uri uri) {
+        loadUri(uri, null, LOAD_FLAGS_NONE);
+    }
+
+    /**
+     * Load the given Uri with the specified referrer and load type.
+     * @param uri the Uri to load
+     * @param flags the load flags to use, an ORed value of {@link #LOAD_FLAGS_NONE LOAD_FLAGS_*}
+     */
+    public void loadUri(@NonNull Uri uri, @LoadFlags int flags) {
+        loadUri(uri.toString(), null, flags);
+    }
+
+    /**
+     * Load the given Uri with the specified referrer and load type.
+     * @param uri the Uri to load
+     * @param referrer the Uri to use as the referrer
+     * @param flags the load flags to use, an ORed value of {@link #LOAD_FLAGS_NONE LOAD_FLAGS_*}
+     */
+    public void loadUri(@NonNull Uri uri, @Nullable Uri referrer, @LoadFlags int flags) {
+        loadUri(uri.toString(), referrer.toString(), flags);
     }
 
     /**
     * Reload the current URI.
     */
     public void reload() {
         mEventDispatcher.dispatch("GeckoView:Reload", null);
     }
--- a/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewNavigation.jsm
@@ -51,17 +51,38 @@ class GeckoViewNavigation extends GeckoV
     switch (aEvent) {
       case "GeckoView:GoBack":
         this.browser.goBack();
         break;
       case "GeckoView:GoForward":
         this.browser.goForward();
         break;
       case "GeckoView:LoadUri":
-        this.browser.loadURI(aData.uri, null, null, null);
+        const { uri, referrer, flags } = aData;
+
+        let navFlags = 0;
+
+        // These need to match the values in GeckoSession.LOAD_TYPE_*
+        if (flags & (1 << 0)) {
+          navFlags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
+        }
+
+        if (flags & (1 << 1)) {
+          navFlags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY;
+        }
+
+        if (flags & (1 << 2)) {
+          navFlags |= Ci.nsIWebNavigation.LOAD_FLAGS_EXTERNAL;
+        }
+
+        if (flags & (1 << 3)) {
+          navFlags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_POPUPS;
+        }
+
+        this.browser.loadURIWithFlags(uri, navFlags, referrer || null, null, null);
         break;
       case "GeckoView:Reload":
         this.browser.reload();
         break;
       case "GeckoView:Stop":
         this.browser.stop();
         break;
     }