Bug 1483342 - [1.1] Add GeckoRuntime Safe Browsing API. r=snorp,jchen,francois
authorEugen Sawin <esawin@mozilla.com>
Tue, 14 Aug 2018 21:40:50 +0200
changeset 487068 47e290808d8e401d70ef5fc4a8f523388de6dd96
parent 487067 744065f01f78c24de3f18276d0bb8d47e4709f4b
child 487069 fb971f169811504aaa15352ea46f0a2ba7bcc2a0
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jchen, francois
bugs1483342
milestone63.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 1483342 - [1.1] Add GeckoRuntime Safe Browsing API. r=snorp,jchen,francois
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -242,16 +242,47 @@ public final class GeckoRuntimeSettings 
          *
          * @param density The display density value to use for overriding the system default.
          * @return The builder instance.
          */
         public @NonNull Builder displayDensityOverride(float density) {
             mSettings.mDisplayDensityOverride = density;
             return this;
         }
+
+        /** Set whether or not known malware sites should be blocked.
+         *
+         * Note: For each blocked site, {@link NavigationDelegate#onLoadError}
+         * with error category {@link NavigationDelegate#ERROR_CATEGORY_SAFEBROWSING}
+         * is called.
+         *
+         * @param enabled A flag determining whether or not to block malware
+         *                sites.
+         * @return The builder instance.
+         */
+        public @NonNull Builder blockMalware(boolean enabled) {
+            mSettings.mSafebrowsingMalware.set(enabled);
+            return this;
+        }
+
+        /**
+         * Set whether or not known phishing sites should be blocked.
+         *
+         * Note: For each blocked site, {@link NavigationDelegate#onLoadError}
+         * with error category {@link NavigationDelegate#ERROR_CATEGORY_SAFEBROWSING}
+         * is called.
+         *
+         * @param enabled A flag determining whether or not to block phishing
+         *                sites.
+         * @return The builder instance.
+         */
+        public @NonNull Builder blockPhishing(boolean enabled) {
+            mSettings.mSafebrowsingPhishing.set(enabled);
+            return this;
+        }
     }
 
     /* package */ GeckoRuntime runtime;
     /* package */ boolean mUseContentProcess;
     /* package */ String[] mArgs;
     /* package */ Bundle mExtras;
     /* package */ int prefCount;
 
@@ -300,26 +331,31 @@ public final class GeckoRuntimeSettings 
         "urlclassifier.trackingTable",
         TrackingProtection.buildPrefValue(
             TrackingProtectionDelegate.CATEGORY_TEST |
             TrackingProtectionDelegate.CATEGORY_ANALYTIC |
             TrackingProtectionDelegate.CATEGORY_SOCIAL |
             TrackingProtectionDelegate.CATEGORY_AD));
     /* package */ Pref<Boolean> mConsoleOutput = new Pref<Boolean>(
         "geckoview.console.enabled", false);
+    /* package */ Pref<Boolean> mSafebrowsingMalware = new Pref<Boolean>(
+        "browser.safebrowsing.malware.enabled", true);
+    /* package */ Pref<Boolean> mSafebrowsingPhishing = new Pref<Boolean>(
+        "browser.safebrowsing.phishing.enabled", true);
 
     /* package */ boolean mNativeCrashReporting;
     /* package */ boolean mJavaCrashReporting;
     /* package */ int mCrashReportingJobId;
     /* package */ boolean mDebugPause;
     /* package */ float mDisplayDensityOverride = -1.0f;
 
     private final Pref<?>[] mPrefs = new Pref<?>[] {
         mCookieBehavior, mCookieLifetime, mConsoleOutput,
-        mJavaScript, mRemoteDebugging, mTrackingProtection, mWebFonts
+        mJavaScript, mRemoteDebugging, mSafebrowsingMalware,
+        mSafebrowsingPhishing, mTrackingProtection, mWebFonts,
     };
 
     /* package */ GeckoRuntimeSettings() {
         this(null);
     }
 
     /* package */ GeckoRuntimeSettings(final @Nullable GeckoRuntimeSettings settings) {
         if (BuildConfig.DEBUG && prefCount != mPrefs.length) {
@@ -618,22 +654,70 @@ public final class GeckoRuntimeSettings 
     public @NonNull GeckoRuntimeSettings setConsoleOutputEnabled(boolean enabled) {
         mConsoleOutput.set(enabled);
         return this;
     }
 
     /**
      * Get whether or not web console messages are sent to logcat.
      *
-     * @return This GeckoRuntimeSettings instance.
+     * @return True if console output is enabled.
      */
     public boolean getConsoleOutputEnabled() {
         return mConsoleOutput.get();
     }
 
+    /**
+     * Set whether or not known malware sites should be blocked.
+     *
+     * Note: For each blocked site, {@link NavigationDelegate#onLoadError}
+     * with error category {@link NavigationDelegate#ERROR_CATEGORY_SAFEBROWSING}
+     * is called.
+     *
+     * @param enabled A flag determining whether or not to block malware sites.
+     * @return The GeckoRuntimeSettings instance.
+     */
+    public @NonNull GeckoRuntimeSettings setBlockMalware(boolean enabled) {
+        mSafebrowsingMalware.set(enabled);
+        return this;
+    }
+
+    /**
+     * Get whether or not known malware sites are blocked.
+     *
+     * @return True if malware site blocking is enabled.
+     */
+    public boolean getBlockMalware() {
+        return mSafebrowsingMalware.get();
+    }
+
+    /**
+     * Set whether or not known phishing sites should be blocked.
+     *
+     * Note: For each blocked site, {@link NavigationDelegate#onLoadError}
+     * with error category {@link NavigationDelegate#ERROR_CATEGORY_SAFEBROWSING}
+     * is called.
+     *
+     * @param enabled A flag determining whether or not to block phishing sites.
+     * @return The GeckoRuntimeSettings instance.
+     */
+    public @NonNull GeckoRuntimeSettings setBlockPhishing(boolean enabled) {
+        mSafebrowsingPhishing.set(enabled);
+        return this;
+    }
+
+    /**
+     * Get whether or not known phishing sites are blocked.
+     *
+     * @return True if phishing site blocking is enabled.
+     */
+    public boolean getBlockPhishing() {
+        return mSafebrowsingPhishing.get();
+    }
+
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         ParcelableUtils.writeBoolean(out, mUseContentProcess);