diff --git a/mobile/android/geckoview/api.txt b/mobile/android/geckoview/api.txt index aa10f04f458f..610a914ff0fb 100644 --- a/mobile/android/geckoview/api.txt +++ b/mobile/android/geckoview/api.txt @@ -185,6 +185,13 @@ package org.mozilla.geckoview { method @UiThread default public void onContentLoaded(@NonNull GeckoSession, @NonNull ContentBlocking.BlockEvent); } + public static class ContentBlocking.EtpLevel { + ctor public EtpLevel(); + field public static final int DEFAULT = 1; + field public static final int NONE = 0; + field public static final int STRICT = 2; + } + public static class ContentBlocking.SafeBrowsing { ctor protected SafeBrowsing(); field public static final int DEFAULT = 15360; @@ -199,10 +206,12 @@ package org.mozilla.geckoview { method public int getAntiTrackingCategories(); method public int getCookieBehavior(); method public int getCookieLifetime(); + method public int getEnhancedTrackingProtectionLevel(); method public int getSafeBrowsingCategories(); method @NonNull public ContentBlocking.Settings setAntiTracking(int); method @NonNull public ContentBlocking.Settings setCookieBehavior(int); method @NonNull public ContentBlocking.Settings setCookieLifetime(int); + method @NonNull public ContentBlocking.Settings setEnhancedTrackingProtectionLevel(int); method @NonNull public ContentBlocking.Settings setSafeBrowsing(int); method @NonNull public ContentBlocking.Settings setStrictSocialTrackingProtection(boolean); field public static final Parcelable.Creator CREATOR; @@ -213,6 +222,7 @@ package org.mozilla.geckoview { method @NonNull public ContentBlocking.Settings.Builder antiTracking(int); method @NonNull public ContentBlocking.Settings.Builder cookieBehavior(int); method @NonNull public ContentBlocking.Settings.Builder cookieLifetime(int); + method @NonNull public ContentBlocking.Settings.Builder enhancedTrackingProtectionLevel(int); method @NonNull public ContentBlocking.Settings.Builder safeBrowsing(int); method @NonNull protected ContentBlocking.Settings newSettings(@Nullable ContentBlocking.Settings); } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java index 22b6fad2fd0e..dfa3ea1017ff 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java @@ -85,6 +85,19 @@ public class ContentBlocking { getSettings().setCookieLifetime(lifetime); return this; } + + /** + * Set the ETP behavior level. + * + * @param level The level of ETP blocking to use. Only takes effect if + * cookie behavior is set to {@link ContentBlocking.CookieBehavior#ACCEPT_NON_TRACKERS}. + * + * @return The Builder instance. + */ + public @NonNull Builder enhancedTrackingProtectionLevel(final @CBEtpLevel int level) { + getSettings().setEnhancedTrackingProtectionLevel(level); + return this; + } } /* package */ final Pref mAt = new Pref( @@ -117,6 +130,11 @@ public class ContentBlocking { /* package */ final Pref mCookieLifetime = new Pref( "network.cookie.lifetimePolicy", CookieLifetime.NORMAL); + /* package */ final Pref mEtpEnabled = new Pref( + "privacy.trackingprotection.annotate_channels", false); + /* package */ final Pref mEtpStrict = new Pref( + "privacy.annotate_channels.strict_list.enabled", false); + /** * Construct default settings. */ @@ -175,6 +193,21 @@ public class ContentBlocking { return this; } + /** + * Set the ETP behavior level. + * + * @param level The level of ETP blocking to use; must be one of {@link ContentBlocking.EtpLevel} + * flags. Only takes effect if the cookie behavior is + * {@link ContentBlocking.CookieBehavior#ACCEPT_NON_TRACKERS}. + * + * @return This Settings instance. + */ + public @NonNull Settings setEnhancedTrackingProtectionLevel(final @CBEtpLevel int level) { + mEtpEnabled.commit(level == ContentBlocking.EtpLevel.DEFAULT || level == ContentBlocking.EtpLevel.STRICT); + mEtpStrict.commit(level == ContentBlocking.EtpLevel.STRICT); + return this; + } + /** * Set whether or not strict social tracking protection is enabled * (ie, whether to block content or just cookies). Will only block @@ -216,6 +249,20 @@ public class ContentBlocking { ContentBlocking.stListToAtCat(mStList.get()); } + /** + * Get the set ETP behavior level. + * + * @return The current ETP level; one of {@link ContentBlocking.EtpLevel}. + */ + public @CBEtpLevel int getEnhancedTrackingProtectionLevel() { + if (mEtpStrict.get()) { + return ContentBlocking.EtpLevel.STRICT; + } else if (mEtpEnabled.get()) { + return ContentBlocking.EtpLevel.DEFAULT; + } + return ContentBlocking.EtpLevel.NONE; + } + /** * Get the set safe browsing categories. * @@ -461,6 +508,31 @@ public class ContentBlocking { CookieLifetime.DAYS }) /* package */ @interface CBCookieLifetime {} + @Retention(RetentionPolicy.SOURCE) + @IntDef({ EtpLevel.NONE, EtpLevel.DEFAULT, EtpLevel.STRICT }) + /* package */ @interface CBEtpLevel {} + + /** + * Possible settings for ETP. + */ + public static class EtpLevel { + /** + * Do not enable ETP at all. + */ + public static final int NONE = 0; + + /** + * Enable ETP for ads, analytic, and social tracking lists. + */ + public static final int DEFAULT = 1; + + /** + * Enable ETP for all of the default lists as well as the content list. + * May break many sites! + */ + public static final int STRICT = 2; + } + /** * Holds content block event details. */ diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md index fe0d5113ada4..aa721f4141c8 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md @@ -36,6 +36,8 @@ exclude: true ([bug 1540065]({{bugzilla}}1540065)) - Added [`GeckoSession.ContentDelegate.onFirstContentfulPaint`][71.13] ([bug 1578947]({{bugzilla}}1578947)) +- Added `setEnhancedTrackingProtectionLevel` to [`ContentBlocking.Settings`][71.14]. + ([bug 1580854]({{bugzilla}}1580854)) [71.1]: {{javadoc_uri}}/RuntimeTelemetry.Delegate.html#onBooleanScalar-org.mozilla.geckoview.RuntimeTelemetry.Metric- [71.2]: {{javadoc_uri}}/RuntimeTelemetry.Delegate.html#onLongScalar-org.mozilla.geckoview.RuntimeTelemetry.Metric- @@ -372,4 +374,4 @@ exclude: true [65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String- [65.25]: {{javadoc_uri}}/GeckoResult.html -[api-version]: 40441c6fcd77218d1d32b468894558141d8ccad9 +[api-version]: bc4c4b661a4dd390c2a10c1057a2ce2aa09e3483 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 e280ec522fe0..edc2a149c141 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 @@ -179,6 +179,7 @@ public class GeckoViewActivity extends AppCompatActivity { ContentBlocking.AntiTracking.STP) .safeBrowsing(ContentBlocking.SafeBrowsing.DEFAULT) .cookieBehavior(ContentBlocking.CookieBehavior.ACCEPT_NON_TRACKERS) + .etpLevel(ContentBlocking.EtpLevel.DEFAULT) .build()) .crashHandler(ExampleCrashHandler.class) .telemetryDelegate(new ExampleTelemetryDelegate())