Add option to remove Facebook Click IDs from URLs. https://redmine.stoutner.com...
authorSoren Stoutner <soren@stoutner.com>
Wed, 8 May 2019 22:33:05 +0000 (15:33 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 8 May 2019 22:33:05 +0000 (15:33 -0700)
.idea/dictionaries/soren.xml
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index b99112e..d708ca0 100644 (file)
@@ -65,6 +65,7 @@
       <w>fanboy</w>
       <w>fanboys</w>
       <w>favoriteicon</w>
+      <w>fbclid</w>
       <w>fbee</w>
       <w>fdfilter</w>
       <w>fdid</w>
index 7900b06..aa09145 100644 (file)
@@ -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;
     }
index 37225fb..51962b6 100644 (file)
@@ -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);
index 099857f..6f04147 100644 (file)
     <string name="url_modification">URL Modification</string>
         <string name="google_analytics">Google Analytics</string>
         <string name="google_analytics_summary">Remove “?utm_” or “&amp;utm_” and anything after it from URLs.</string>
+        <string name="facebook_click_ids">Facebook Click IDs</string>
+        <string name="facebook_click_ids_summary">Remove “?fbclid=” or “&amp;fbclid=” and anything after it from URLs.</string>
     <string name="tor">Tor</string>
         <string name="proxy_through_orbot">Proxy through Orbot</string>
         <string name="proxy_through_orbot_summary">Proxy all web traffic through Orbot on localhost:8118.</string>
index dc8ffcb..fe3a144 100644 (file)
             android:title="@string/google_analytics"
             android:summary="@string/google_analytics_summary"
             android:defaultValue="true" />
+
+        <SwitchPreference
+            android:key="facebook_click_ids"
+            android:title="@string/facebook_click_ids"
+            android:summary="@string/facebook_click_ids_summary"
+            android:defaultValue="true" />
     </PreferenceCategory>
 
     <PreferenceCategory