X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=7900b066e500ef7217f19ed7b73762a2bbbd3925;hp=df7cef48fd39a8052e9685b050fe1ac12f267d91;hb=0d5f4763ba83016e32a91379ceb66baac63cc0c9;hpb=34f4c1390fdb56aab87786cfe022b12a75bf0bbe diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index df7cef48..7900b066 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -279,6 +279,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The swipe refresh layout top padding is used when exiting full screen browsing mode. It is used in an inner class in `initializeWebView()`. private int swipeRefreshLayoutPaddingTop; + // The URL sanitizers are set in `applyAppSettings()` and used in `sanitizeUrl()`. + private boolean sanitizeGoogleAnalytics; + // The download strings are used in `onCreate()`, `onRequestPermissionResult()` and `initializeWebView()`. private String downloadUrl; private String downloadContentDisposition; @@ -2999,6 +3002,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } private void loadUrl(String url) { + // Sanitize the URL. + url = sanitizeUrl(url); + // Apply the domain settings. applyDomainSettings(currentWebView, url, true, false); @@ -3053,6 +3059,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Store the values from the shared preferences in variables. incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false); + sanitizeGoogleAnalytics = sharedPreferences.getBoolean("google_analytics", true); proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("full_screen_browsing_mode", false); hideAppBar = sharedPreferences.getBoolean("hide_app_bar", true); @@ -3959,12 +3966,33 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook startActivity(openWithBrowserIntent); } + private String sanitizeUrl(String url) { + // Sanitize Google Analytics. + if (sanitizeGoogleAnalytics) { + // Remove `?utm_`. + if (url.contains("?utm_")) { + url = url.substring(0, url.indexOf("?utm_")); + } + + // Remove `&utm_`. + if (url.contains("&utm_")) { + url = url.substring(0, url.indexOf("&utm_")); + } + } + + // Return the sanitized URL. + return url; + } + public void addTab(View view) { // Add a new tab with a blank URL. addNewTab(""); } private void addNewTab(String url) { + // Sanitize the URL. + url = sanitizeUrl(url); + // Get a handle for the tab layout and the view pager. TabLayout tabLayout = findViewById(R.id.tablayout); ViewPager webViewPager = findViewById(R.id.webviewpager); @@ -4770,6 +4798,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The deprecated `shouldOverrideUrlLoading` must be used until API >= 24. @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + // Sanitize the url. + url = sanitizeUrl(url); + if (url.startsWith("http")) { // Load the URL in Privacy Browser. // Apply the domain settings for the new URL. This doesn't do anything if the domain has not changed. boolean userAgentChanged = applyDomainSettings(nestedScrollWebView, url, true, false);