This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,021 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
app/src/common/shared/org/mozilla/vrbrowser/browser/tracking/TrackingProtectionPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.mozilla.vrbrowser.browser.tracking; | ||
|
||
import androidx.annotation.IntDef; | ||
|
||
import org.mozilla.geckoview.ContentBlocking; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TrackingProtectionPolicy { | ||
|
||
@IntDef(value = { ETP_NONE, ETP_DEFAULT, ETP_STRICT}) | ||
public @interface ETP_Level {} | ||
public static final int ETP_NONE = ContentBlocking.EtpLevel.NONE; | ||
public static final int ETP_DEFAULT = ContentBlocking.EtpLevel.DEFAULT; | ||
public static final int ETP_STRICT = ContentBlocking.EtpLevel.STRICT; | ||
|
||
private List<TrackingCategory> trackingCategory; | ||
private CookiePolicy cookiePolicy; | ||
private Boolean strictSocialTrackingProtection = null; | ||
|
||
private TrackingProtectionPolicy() { | ||
trackingCategory = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Strict policy. | ||
* Combining the [TrackingCategory.STRICT] plus a cookiePolicy of [ACCEPT_NON_TRACKERS] | ||
* This is the strictest setting and may cause issues on some web sites. | ||
*/ | ||
public static TrackingProtectionPolicy strict() { | ||
TrackingProtectionPolicy policy = new TrackingProtectionPolicy(); | ||
policy.trackingCategory = Collections.singletonList(TrackingCategory.STRICT); | ||
policy.cookiePolicy = CookiePolicy.ACCEPT_NON_TRACKERS; | ||
policy.strictSocialTrackingProtection = true; | ||
return policy; | ||
} | ||
|
||
/** | ||
* Recommended policy. | ||
* Combining the [TrackingCategory.RECOMMENDED] plus a [CookiePolicy] of [ACCEPT_NON_TRACKERS]. | ||
* This is the recommended setting. | ||
*/ | ||
public static TrackingProtectionPolicy recommended() { | ||
TrackingProtectionPolicy policy = new TrackingProtectionPolicy(); | ||
policy.trackingCategory = Collections.singletonList(TrackingCategory.RECOMMENDED); | ||
policy.cookiePolicy = CookiePolicy.ACCEPT_NON_TRACKERS; | ||
policy.strictSocialTrackingProtection = false; | ||
return policy; | ||
} | ||
|
||
public static TrackingProtectionPolicy none() { | ||
TrackingProtectionPolicy policy = new TrackingProtectionPolicy(); | ||
policy.trackingCategory = Collections.singletonList(TrackingCategory.NONE); | ||
policy.cookiePolicy = CookiePolicy.ACCEPT_ALL; | ||
return policy; | ||
} | ||
|
||
public enum TrackingCategory { | ||
NONE(0), | ||
AD(1 << 1), | ||
ANALYTICS(1 << 2), | ||
SOCIAL(1 << 3), | ||
CONTENT(1 << 4), | ||
TEST(1 << 5), | ||
CRYPTOMINING(1 << 6), | ||
FINGERPRINTING(1 << 7), | ||
MOZILLA_SOCIAL(1 << 8), | ||
SCRIPTS_AND_SUB_RESOURCES(1 << 9999), | ||
RECOMMENDED(AD.value + ANALYTICS.value + SOCIAL.value + | ||
TEST.value + MOZILLA_SOCIAL.value + CRYPTOMINING.value), | ||
STRICT(RECOMMENDED.value + SCRIPTS_AND_SUB_RESOURCES.value + | ||
FINGERPRINTING.value); | ||
|
||
private final int value; | ||
|
||
TrackingCategory(final int newValue) { | ||
value = newValue; | ||
} | ||
|
||
public int getValue() { return value; } | ||
} | ||
|
||
public enum CookiePolicy { | ||
ACCEPT_ALL(0), | ||
ACCEPT_ONLY_FIRST_PARTY(1), | ||
ACCEPT_NONE(2), | ||
ACCEPT_VISITED(3), | ||
ACCEPT_NON_TRACKERS(4); | ||
|
||
private final int value; | ||
|
||
CookiePolicy(final int newValue) { | ||
value = newValue; | ||
} | ||
|
||
public int getValue() { return value; } | ||
} | ||
|
||
public List<TrackingCategory> getTrackingCategory() { | ||
return trackingCategory; | ||
} | ||
|
||
public Boolean getStrictSocialTrackingProtection() { | ||
return strictSocialTrackingProtection; | ||
} | ||
|
||
public CookiePolicy getCookiePolicy() { | ||
return cookiePolicy; | ||
} | ||
|
||
public int getAntiTrackingPolicy() { | ||
/* | ||
* The [TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES] is an | ||
* artificial category, created with the sole purpose of going around this bug | ||
* https://bugzilla.mozilla.org/show_bug.cgi?id=1579264, for this reason we have to | ||
* remove its value from the valid anti tracking categories, when is present. | ||
*/ | ||
int total = trackingCategory.stream().mapToInt(TrackingCategory::getValue).sum(); | ||
if (contains(TrackingCategory.SCRIPTS_AND_SUB_RESOURCES)) { | ||
return total - TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES.getValue(); | ||
} else { | ||
return total; | ||
} | ||
} | ||
|
||
public boolean contains(TrackingCategory category) { | ||
int sum = trackingCategory.stream().mapToInt(TrackingCategory::getValue).sum(); | ||
return (sum & category.getValue()) != 0; | ||
} | ||
|
||
} |
Oops, something went wrong.