From 6735400e31c7cd3769362b37920691669eebb103 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Fri, 12 Jan 2018 15:22:27 -0800 Subject: [PATCH] Closes #311: re-enable tracking protection. I think request.isForMainFrame() is unnecessary because of this line in UrlMatcher.matches: if (pageHost != null && pageHost.equals(resourceHost)) { return false; } Which whitelists first party requests: this is assuming the `pageHost`, which comes from `TrackingProtectionWebViewClient.currentPageUrl`, actually represents the current page loading (and thus the main frame). I noted that my Android TV emulator seems to block the same numbers of trackers as Focus. --- .../TrackingProtectionWebViewClient.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/webview/java/org/mozilla/focus/webview/TrackingProtectionWebViewClient.java b/app/src/webview/java/org/mozilla/focus/webview/TrackingProtectionWebViewClient.java index f675eb6a70..8854f1ff00 100644 --- a/app/src/webview/java/org/mozilla/focus/webview/TrackingProtectionWebViewClient.java +++ b/app/src/webview/java/org/mozilla/focus/webview/TrackingProtectionWebViewClient.java @@ -102,19 +102,20 @@ public AmazonWebResourceResponse shouldInterceptRequest(final AmazonWebView view return new AmazonWebResourceResponse(null, null, null); } - final UrlMatcher matcher = getMatcher(view.getContext()); + final UrlMatcher blockedSiteMatcher = getMatcher(view.getContext()); // Don't block the main frame from being loaded. This also protects against cases where we // open a link that redirects to another app (e.g. to the play store). - final Uri pageUri = Uri.parse(currentPageURL); - -// if ((!request.isForMainFrame()) && -// matcher.matches(resourceUri, pageUri)) { -// if (callback != null) { -// callback.countBlockedTracker(); -// } -// return new AmazonWebResourceResponse(null, null, null); -// } + final Uri currentPageUri = Uri.parse(currentPageURL); + + // Matches is true if the resourceUri is on the blocklist and is not a first party request. + // The matcher code could be better named to make this apparent. + if (blockedSiteMatcher.matches(resourceUri, currentPageUri)) { + if (callback != null) { + callback.countBlockedTracker(); + } + return new AmazonWebResourceResponse(null, null, null); + } return super.shouldInterceptRequest(view, request); }