From e181e7bccc149dc4a839697a6e0417d7b9c54948 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 8 May 2019 15:33:05 -0700 Subject: [PATCH] Add option to remove Facebook Click IDs from URLs. https://redmine.stoutner.com/issues/436 --- .idea/dictionaries/soren.xml | 1 + .../activities/MainWebViewActivity.java | 15 ++++++++ .../fragments/SettingsFragment.java | 35 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences.xml | 6 ++++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index b99112e2..d708ca01 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -65,6 +65,7 @@ fanboy fanboys favoriteicon + fbclid fbee fdfilter fdid 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 7900b066..aa091453 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -281,6 +281,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The URL sanitizers are set in `applyAppSettings()` and used in `sanitizeUrl()`. private boolean sanitizeGoogleAnalytics; + private boolean sanitizeFacebookClickIds; // The download strings are used in `onCreate()`, `onRequestPermissionResult()` and `initializeWebView()`. private String downloadUrl; @@ -3060,6 +3061,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false); sanitizeGoogleAnalytics = sharedPreferences.getBoolean("google_analytics", true); + sanitizeFacebookClickIds = sharedPreferences.getBoolean("facebook_click_ids", true); proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("full_screen_browsing_mode", false); hideAppBar = sharedPreferences.getBoolean("hide_app_bar", true); @@ -3980,6 +3982,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } + // Sanitize Facebook Click IDs. + if (sanitizeFacebookClickIds) { + // Remove `?fbclid=`. + if (url.contains("?fbclid=")) { + url = url.substring(0, url.indexOf("?fbclid=")); + } + + // Remove &fbclid=`. + if (url.contains("&fbclid=")) { + url = url.substring(0, url.indexOf("&fbclid=")); + } + } + // Return the sanitized URL. return url; } diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index 37225fb6..51962b6b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -73,6 +73,7 @@ public class SettingsFragment extends PreferenceFragment { Preference ultraPrivacyPreference = findPreference("ultraprivacy"); Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests"); Preference googleAnalyticsPreference = findPreference("google_analytics"); + Preference facebookClickIdsPreference = findPreference("facebook_click_ids"); Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot"); Preference torHomepagePreference = findPreference("tor_homepage"); Preference torSearchPreference = findPreference("tor_search"); @@ -458,7 +459,7 @@ public class SettingsFragment extends PreferenceFragment { } } - // Set the Google Analytics icons according to the theme. + // Set the Google Analytics icon according to the theme. if (savedPreferences.getBoolean("google_analytics", true)) { if (darkTheme) { googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_dark); @@ -473,6 +474,21 @@ public class SettingsFragment extends PreferenceFragment { } } + // Set the Facebook Click IDs icon according to the theme. + if (savedPreferences.getBoolean("facebook_click_ids", true)) { + if (darkTheme) { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_dark); + } else { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_light); + } + } else { + if (darkTheme) { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_dark); + } else { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_light); + } + } + // Set the Tor icons according to the theme. if (proxyThroughOrbot) { // Proxying is enabled. if (darkTheme) { @@ -1143,6 +1159,23 @@ public class SettingsFragment extends PreferenceFragment { } break; + case "facebook_click_ids": + // Update the icon. + if (sharedPreferences.getBoolean("facebook_click_ids", true)) { + if (darkTheme) { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_dark); + } else { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_light); + } + } else { + if (darkTheme) { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_dark); + } else { + facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_light); + } + } + break; + case "proxy_through_orbot": // Get current settings. boolean currentProxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 099857f3..6f041478 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -517,6 +517,8 @@ URL Modification Google Analytics Remove “?utm_” or “&utm_” and anything after it from URLs. + Facebook Click IDs + Remove “?fbclid=” or “&fbclid=” and anything after it from URLs. Tor Proxy through Orbot Proxy all web traffic through Orbot on localhost:8118. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index dc8ffcba..fe3a1440 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -138,6 +138,12 @@ android:title="@string/google_analytics" android:summary="@string/google_analytics_summary" android:defaultValue="true" /> + +