@@ -0,0 +1,2123 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-%0A * This Source Code Form is subject to the terms of the Mozilla Public%0A * License, v. 2.0. If a copy of the MPL was not distributed with this%0A * file, You can obtain one at http://mozilla.org/MPL/2.0/. */%0Apackage org.mozilla.focus.webkit;%0A%0Aimport android.content.Context;%0Aimport android.graphics.Bitmap;%0Aimport android.webkit.WebResourceResponse;%0Aimport android.webkit.WebView;%0Aimport android.webkit.WebViewClient;%0A%0Aimport org.mozilla.focus.R;%0Aimport org.mozilla.focus.webkit.matcher.UrlMatcher;%0A%0Apublic class TrackingProtectionWebViewClient extends WebViewClient %7B%0A%0A    private String currentPageURL;%0A    private final UrlMatcher matcher;%0A%0A    public TrackingProtectionWebViewClient(final Context context) %7B%0A        matcher = new UrlMatcher(context, R.raw.blocklist, R.raw.entitylist);%0A    %7D%0A%0A    /*%0A     * The new undeprecated version of this methods is API 21+.%0A     */%0A    @Override%0A    public WebResourceResponse shouldInterceptRequest(WebView view, String url) %7B%0A        if (matcher.matches(url, currentPageURL)) %7B%0A            return new WebResourceResponse(null, null, null);%0A        %7D%0A%0A        return super.shouldInterceptRequest(view, url);%0A    %7D%0A%0A%0A    /**%0A     * Notify that the user has requested a new URL. This MUST be called before loading a new URL%0A     * into the webview: sometimes content requests might begin before the WebView itself notifies%0A     * the WebViewClient via onpageStarted/shouldOverrideUrlLoading. If we don't know the current page%0A     * URL then the entitylist whitelists might not work if we're trying to load an explicitly whitelisted%0A     * page.%0A     */%0A    public void notifyCurrentURL(final String url) %7B%0A        currentPageURL = url;%0A    %7D%0A%0A    @Override%0A    public void onPageStarted(WebView view, String url, Bitmap favicon) %7B%0A        currentPageURL = url;%0A%0A        super.onPageStarted(view, url, favicon);%0A    %7D%0A%0A    @Override%0A    public boolean shouldOverrideUrlLoading(WebView view, String url) %7B%0A        currentPageURL = url;%0A%0A        return super.shouldOverrideUrlLoading(view, url);%0A    %7D%0A%0A%7D%0A

Add WebViewClient to wrap URL matching.