Bug 1530789 - [1.0] Extend Content Blocking API: cryptomining protection. r=geckoview-reviewers,dimi,snorp,Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eugen Sawin 2019-03-22 20:44:55 +00:00
parent 041f01f61f
commit d94b0ddbac
2 changed files with 49 additions and 5 deletions

View File

@ -42,3 +42,6 @@ pref("browser.safebrowsing.features.malware.update", true);
// Enable Tracking Protection blocklist updates
pref("browser.safebrowsing.features.trackingAnnotation.update", true);
pref("browser.safebrowsing.features.trackingProtection.update", true);
// Enable cryptomining protection blocklist updates
pref("browser.safebrowsing.features.cryptomining.update", true);

View File

@ -75,6 +75,12 @@ public class ContentBlocking {
"urlclassifier.trackingTable",
ContentBlocking.catToAtPref(
AT_TEST | AT_ANALYTIC | AT_SOCIAL | AT_AD));
/* package */ final Pref<Boolean> mCm = new Pref<Boolean>(
"privacy.trackingprotection.cryptomining.enabled", false);
/* package */ final Pref<String> mCmList = new Pref<String>(
"urlclassifier.features.cryptomining.blacklistTables",
ContentBlocking.catToCmListPref(NONE));
/* package */ final Pref<Boolean> mSbMalware = new Pref<Boolean>(
"browser.safebrowsing.malware.enabled", true);
/* package */ final Pref<Boolean> mSbPhishing = new Pref<Boolean>(
@ -130,6 +136,10 @@ public class ContentBlocking {
*/
public @NonNull Settings setCategories(final @Category int cat) {
mAt.commit(ContentBlocking.catToAtPref(cat));
mCm.commit(ContentBlocking.catToCmPref(cat));
mCmList.commit(ContentBlocking.catToCmListPref(cat));
mSbMalware.commit(ContentBlocking.catToSbMalware(cat));
mSbPhishing.commit(ContentBlocking.catToSbPhishing(cat));
return this;
@ -141,7 +151,8 @@ public class ContentBlocking {
* @return The categories of resources to be blocked.
*/
public @Category int getCategories() {
return ContentBlocking.listToCat(mAt.get())
return ContentBlocking.atListToCat(mAt.get())
| ContentBlocking.cmListToCat(mCmList.get())
| ContentBlocking.sbMalwareToCat(mSbMalware.get())
| ContentBlocking.sbPhishingToCat(mSbPhishing.get());
}
@ -195,7 +206,7 @@ public class ContentBlocking {
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true,
value = { NONE, AT_AD, AT_ANALYTIC, AT_SOCIAL, AT_CONTENT,
AT_ALL, AT_TEST,
AT_ALL, AT_TEST, AT_CRYPTOMINING,
SB_MALWARE, SB_UNWANTED,
SB_HARMFUL, SB_PHISHING })
/* package */ @interface Category {}
@ -228,11 +239,17 @@ public class ContentBlocking {
*/
public static final int AT_TEST = 1 << 5;
/**
* Block cryptocurrency miners.
*/
public static final int AT_CRYPTOMINING = 1 << 6;
/**
* Block all known trackers.
* Blocks all {@link #AT_AD AT_*} types.
*/
public static final int AT_ALL =
AT_AD | AT_ANALYTIC | AT_SOCIAL | AT_CONTENT | AT_TEST;
AT_AD | AT_ANALYTIC | AT_SOCIAL | AT_CONTENT | AT_TEST | AT_CRYPTOMINING;
// Safe browsing
/**
@ -350,7 +367,8 @@ public class ContentBlocking {
@Category int cats = NONE;
if (matchedList != null) {
cats = ContentBlocking.listToCat(matchedList);
cats = ContentBlocking.atListToCat(matchedList) |
ContentBlocking.cmListToCat(matchedList);
} else if (error != 0L) {
cats = ContentBlocking.errorToCat(error);
}
@ -383,6 +401,8 @@ public class ContentBlocking {
private static final String ANALYTIC = "analytics-track-digest256";
private static final String SOCIAL = "social-track-digest256";
private static final String CONTENT = "content-track-digest256";
private static final String CRYPTOMINING =
"base-cryptomining-track-digest256";
/* package */ static @Category int sbMalwareToCat(final boolean enabled) {
return enabled ? (SB_MALWARE | SB_UNWANTED | SB_HARMFUL)
@ -427,7 +447,20 @@ public class ContentBlocking {
return builder.substring(0, builder.length() - 1);
}
/* package */ static @Category int listToCat(final String list) {
/* package */ static boolean catToCmPref(@Category int cat) {
return (cat & AT_CRYPTOMINING) != 0;
}
/* package */ static String catToCmListPref(@Category int cat) {
StringBuilder builder = new StringBuilder();
if ((cat & AT_CRYPTOMINING) != 0) {
builder.append(CRYPTOMINING);
}
return builder.toString();
}
/* package */ static @Category int atListToCat(final String list) {
int cat = 0;
if (list.indexOf(TEST) != -1) {
cat |= AT_TEST;
@ -447,6 +480,14 @@ public class ContentBlocking {
return cat;
}
/* package */ static @Category int cmListToCat(final String list) {
int cat = 0;
if (list.indexOf(CRYPTOMINING) != -1) {
cat |= AT_CRYPTOMINING;
}
return cat;
}
/* package */ static @Category int errorToCat(final long error) {
// Match flags with XPCOM ErrorList.h.
if (error == 0x805D001FL) {