Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #311: re-enable tracking protection.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcomella committed Jan 16, 2018
1 parent 82a8db5 commit 6735400
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6735400

Please sign in to comment.