Bug 1580854 - Allow blocking level 1 ETP lists in GV. r=geckoview-reviewers,snorp,agi

Differential Revision: https://phabricator.services.mozilla.com/D45709

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dylan Roeh 2019-09-20 19:10:18 +00:00
Родитель 92562d539f
Коммит 6053c05dba
4 изменённых файлов: 86 добавлений и 1 удалений

Просмотреть файл

@ -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<ContentBlocking.Settings> 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);
}

Просмотреть файл

@ -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<String> mAt = new Pref<String>(
@ -117,6 +130,11 @@ public class ContentBlocking {
/* package */ final Pref<Integer> mCookieLifetime = new Pref<Integer>(
"network.cookie.lifetimePolicy", CookieLifetime.NORMAL);
/* package */ final Pref<Boolean> mEtpEnabled = new Pref<Boolean>(
"privacy.trackingprotection.annotate_channels", false);
/* package */ final Pref<Boolean> mEtpStrict = new Pref<Boolean>(
"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.
*/

Просмотреть файл

@ -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

Просмотреть файл

@ -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())