Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Enhanced Tracking Protection
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Mar 25, 2020
1 parent d4af5a0 commit 929a87e
Show file tree
Hide file tree
Showing 39 changed files with 1,045 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ protected void onDestroy() {

SessionStore.get().onDestroy();


super.onDestroy();
mLifeCycle.setCurrentState(Lifecycle.State.DESTROYED);
mViewModelStore.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void onCreate() {
mAppExecutors = new AppExecutors();
mBitmapCache = new BitmapCache(this, mAppExecutors.diskIO(), mAppExecutors.mainThread());


TelemetryWrapper.init(this);
GleanMetricsService.init(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void setPermissionAllowed(String uri, @SitePermission.Category int catego
mSitePermissionModel.deleteSite(site);
} else {
if (site == null) {
site = new SitePermission(uri, false, category);
site = new SitePermission(uri, uri, false, category);
mSitePermissions.add(site);
}
site.allowed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private void showPopUp(int sessionId, @NonNull Pair<String, LinkedList<PopUpRequ
boolean allowed = index != PopUpBlockDialogWidget.NEGATIVE;
boolean askAgain = mPopUpPrompt.askAgain();
if (allowed && !askAgain) {
SitePermission permission = new SitePermission(uri, allowed, SitePermission.SITE_PERMISSION_POPUP);
SitePermission permission = new SitePermission(uri, uri, allowed, SitePermission.SITE_PERMISSION_POPUP);
mAllowedPopUpSites.add(permission);
mViewModel.insertSite(permission);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.R;
Expand Down Expand Up @@ -53,7 +54,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean UI_HARDWARE_ACCELERATION_DEFAULT_WAVEVR = false;
public final static boolean PERFORMANCE_MONITOR_DEFAULT = true;
public final static boolean DRM_PLAYBACK_DEFAULT = false;
public final static boolean TRACKING_DEFAULT = true;
public final static int TRACKING_DEFAULT = ContentBlocking.EtpLevel.DEFAULT;
public final static boolean NOTIFICATIONS_DEFAULT = true;
public final static boolean SPEECH_DATA_COLLECTION_DEFAULT = false;
public final static boolean SPEECH_DATA_COLLECTION_REVIEWED_DEFAULT = false;
Expand Down Expand Up @@ -206,14 +207,14 @@ public void setDrmContentPlaybackEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isTrackingProtectionEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_tracking_protection), TRACKING_DEFAULT);
public int getTrackingProtectionLevel() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_tracking_protection_level), TRACKING_DEFAULT);
}

public void setTrackingProtectionEnabled(boolean isEnabled) {
public void setTrackingProtectionLevel(int level) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_tracking_protection), isEnabled);
editor.putInt(mContext.getString(R.string.settings_key_tracking_protection_level), level);
editor.commit();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.mozilla.vrbrowser.browser.content;

import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.ContentBlocking.AntiTracking;

public class TrackingProtectionPolicy {

private static final int RECOMMENDED =
AntiTracking.AD |
AntiTracking.ANALYTIC |
AntiTracking.SOCIAL |
AntiTracking.TEST |
AntiTracking.STP |
AntiTracking.CRYPTOMINING;
private static final int STRICT =
RECOMMENDED | AntiTracking.FINGERPRINTING;

private int trackingPolicy;
private int cookiePolicy;

private TrackingProtectionPolicy() {
trackingPolicy = AntiTracking.NONE;
}

/**
* 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.
*/
static TrackingProtectionPolicy strict() {
TrackingProtectionPolicy policy = new TrackingProtectionPolicy();
policy.trackingPolicy = STRICT;
policy.cookiePolicy = ContentBlocking.CookieBehavior.ACCEPT_NON_TRACKERS;
return policy;
}

/**
* Recommended policy.
* Combining the [TrackingCategory.RECOMMENDED] plus a [CookiePolicy] of [ACCEPT_NON_TRACKERS].
* This is the recommended setting.
*/
static TrackingProtectionPolicy recommended() {
TrackingProtectionPolicy policy = new TrackingProtectionPolicy();
policy.trackingPolicy = RECOMMENDED;
policy.cookiePolicy = ContentBlocking.CookieBehavior.ACCEPT_NON_TRACKERS;
return policy;
}

static TrackingProtectionPolicy none() {
TrackingProtectionPolicy policy = new TrackingProtectionPolicy();
policy.trackingPolicy = AntiTracking.NONE;
policy.cookiePolicy = ContentBlocking.CookieBehavior.ACCEPT_ALL;
return policy;
}

public boolean shouldBlockContent() {
return trackingPolicy == STRICT;
}

int getCookiePolicy() {
return cookiePolicy;
}

int getAntiTrackingPolicy() {
return trackingPolicy;
}

}
Loading

0 comments on commit 929a87e

Please sign in to comment.