Don't add URL redirects to the history list. Implements https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Wed, 17 May 2017 08:03:18 +0000 (01:03 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 17 May 2017 08:03:18 +0000 (01:03 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java
app/src/main/res/drawable/font_size.xml
app/src/main/res/drawable/user_agent.xml
app/src/main/res/layout/domain_settings.xml
app/src/main/res/xml/preferences.xml

index 3c832ae3ed2ec5806ac596f6dfa6f9a0f467d80e..a7dfad7e6831f198d03bded1742a29a58c1e51d6 100644 (file)
@@ -568,8 +568,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
             @SuppressWarnings("deprecation")
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                // Use an external email program if the link begins with `mailto:`.
-                if (url.startsWith("mailto:")) {
+                if (url.startsWith("mailto:")) {  // Load the URL in an external email program because it begins with `mailto:`.
                     // We use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
                     Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
 
@@ -581,10 +580,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
                     // Make it so.
                     startActivity(emailIntent);
+
+                    // Returning `true` indicates the application is handling the URL.
                     return true;
                 } else {  // Load the URL in Privacy Browser.
-                    loadUrl(url);
-                    return true;
+                    // Apply the domain settings for the new URL.
+                    applyDomainSettings(url);
+
+                    // Returning `false` causes the current `WebView` to handle the URL and prevents it from adding redirects to the history list.
+                    return false;
                 }
             }
 
index b783703e9350a519fcae82dd71adde77dd195810..75e008ad12cceaf6a9c61d6e7e0f7f20fe2ee563 100644 (file)
@@ -44,8 +44,10 @@ public class SettingsFragment extends PreferenceFragment {
         savedPreferences = getPreferenceScreen().getSharedPreferences();
 
         // Get handles for the preferences we need to modify.
-        final Preference domStorageEnabled = findPreference("dom_storage_enabled");
+        final Preference javaScriptEnabled = findPreference("javascript_enabled");
+        final Preference firstPartyCookiesEnabled = findPreference("first_party_cookies_enabled");
         final Preference thirdPartyCookiesEnabled = findPreference("third_party_cookies_enabled");
+        final Preference domStorageEnabled = findPreference("dom_storage_enabled");
         final Preference userAgentPreference = findPreference("user_agent");
         final Preference customUserAgent = findPreference("custom_user_agent");
         final Preference torHomepagePreference = findPreference("tor_homepage");
@@ -68,8 +70,13 @@ public class SettingsFragment extends PreferenceFragment {
         String torSearchString = savedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q=");
         String searchString = savedPreferences.getString("search", "https://duckduckgo.com/html/?q=");
 
+        // Get booleans from the preferences.
+        boolean javaScriptEnabledBoolean = savedPreferences.getBoolean("javascript_enabled", false);
+        boolean firstPartyCookiesEnabledBoolean = savedPreferences.getBoolean("first_party_cookies_enabled", false);
+        boolean thirdPartyCookiesEnabledBoolean = savedPreferences.getBoolean("third_party_cookies_enabled", false);
+
         // Only enable `third_party_cookies_enabled` if `first_party_cookies_enabled` is `true` and API >= 21.
-        thirdPartyCookiesEnabled.setEnabled(savedPreferences.getBoolean("first_party_cookies_enabled", false) && (Build.VERSION.SDK_INT >= 21));
+        thirdPartyCookiesEnabled.setEnabled(firstPartyCookiesEnabledBoolean && (Build.VERSION.SDK_INT >= 21));
 
         // We need to inflated a `WebView` to get the default user agent.
         LayoutInflater inflater = getActivity().getLayoutInflater();
@@ -145,6 +152,42 @@ public class SettingsFragment extends PreferenceFragment {
         defaultFontSizePreference.setSummary(savedPreferences.getString("default_font_size", "100") + "%%");
 
 
+        // Set the `javascript_enabled` icon.
+        if (javaScriptEnabledBoolean) {
+            javaScriptEnabled.setIcon(R.drawable.javascript_enabled);
+        } else {
+            javaScriptEnabled.setIcon(R.drawable.privacy_mode);
+        }
+
+        // Set the `first_party_cookies_enabled` icon.
+        if (firstPartyCookiesEnabledBoolean) {
+            firstPartyCookiesEnabled.setIcon(R.drawable.cookies_enabled);
+        } else {
+            firstPartyCookiesEnabled.setIcon(R.drawable.cookies_disabled);
+        }
+
+        // Set the `third_party_cookies_enabled` icon.
+        if (firstPartyCookiesEnabledBoolean && Build.VERSION.SDK_INT >= 21) {
+            if (thirdPartyCookiesEnabledBoolean) {
+                thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_warning);
+            } else {
+                thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_disabled);
+            }
+        } else {
+            thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_ghosted);
+        }
+
+        // Set the `dom_storage_enabled` icon.
+        if (javaScriptEnabledBoolean) {
+            if (savedPreferences.getBoolean("dom_storage_enabled", false)) {
+                domStorageEnabled.setIcon(R.drawable.dom_storage_enabled);
+            } else {
+                domStorageEnabled.setIcon(R.drawable.dom_storage_disabled);
+            }
+        } else {
+            domStorageEnabled.setIcon(R.drawable.dom_storage_ghosted);
+        }
+
         // Listen for preference changes.
         preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
             @Override
@@ -153,11 +196,73 @@ public class SettingsFragment extends PreferenceFragment {
             public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
 
                 switch (key) {
+                    case "javascript_enabled":
+                        // Update the icons.
+                        if (sharedPreferences.getBoolean("javascript_enabled", false)) {
+                            // Update the icon for `javascript_enabled`.
+                            javaScriptEnabled.setIcon(R.drawable.javascript_enabled);
+
+                            // Update the icon for `dom_storage_enabled`.
+                            if (sharedPreferences.getBoolean("dom_storage_enabled", false)) {
+                                domStorageEnabled.setIcon(R.drawable.dom_storage_enabled);
+                            } else {
+                                domStorageEnabled.setIcon(R.drawable.dom_storage_disabled);
+                            }
+                        } else {  // `javascript_enabled` is `false`.
+                            // Update the icon for `javascript_enabled`.
+                            javaScriptEnabled.setIcon(R.drawable.privacy_mode);
+
+                            // Set the icon for `dom_storage_disabled` to be ghosted.
+                            domStorageEnabled.setIcon(R.drawable.dom_storage_ghosted);
+                        }
+                        break;
+
                     case "first_party_cookies_enabled":
+                        // Update the icons for `first_party_cookies_enabled` and `third_party_cookies_enabled`.
+                        if (sharedPreferences.getBoolean("first_party_cookies_enabled", false)) {
+                            // Set the icon for `first_party_cookies_enabled`.
+                            firstPartyCookiesEnabled.setIcon(R.drawable.cookies_enabled);
+
+                            // Update the icon for `third_party_cookies_enabled`.
+                            if (Build.VERSION.SDK_INT >= 21) {
+                                if (sharedPreferences.getBoolean("third_party_cookies_enabled", false)) {
+                                    thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_warning);
+                                } else {
+                                    thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_disabled);
+                                }
+                            } else {
+                                thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_ghosted);
+                            }
+                        } else {  // `first_party_cookies_enabled` is `false`.
+                            // Update the icon for `first_party_cookies_enabled`.
+                            firstPartyCookiesEnabled.setIcon(R.drawable.cookies_disabled);
+
+                            // Set the icon for `third_party_cookies_enabled` to be ghosted.
+                            thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_ghosted);
+                        }
+
                         // Enable `third_party_cookies_enabled` if `first_party_cookies_enabled` is `true` and API >= 21.
                         thirdPartyCookiesEnabled.setEnabled(sharedPreferences.getBoolean("first_party_cookies_enabled", false) && (Build.VERSION.SDK_INT >= 21));
                         break;
 
+                    case "third_party_cookies_enabled":
+                        // Update the icon.
+                        if (sharedPreferences.getBoolean("third_party_cookies_enabled", false)) {
+                            thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_warning);
+                        } else {
+                            thirdPartyCookiesEnabled.setIcon(R.drawable.cookies_disabled);
+                        }
+                        break;
+
+                    case "dom_storage_enabled":
+                        // Update the icon.
+                        if (sharedPreferences.getBoolean("dom_storage_enabled", false)) {
+                            domStorageEnabled.setIcon(R.drawable.dom_storage_enabled);
+                        } else {
+                            domStorageEnabled.setIcon(R.drawable.dom_storage_disabled);
+                        }
+                        break;
+
                     case "user_agent":
                         String userAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0");
 
index 906a0dbc7966795ea8708692d50823426c3b933a..5b6bf6359d4a5ef6628a5ff3500c9f5864c8fd1e 100644 (file)
@@ -13,6 +13,6 @@
 
     <!-- We have to use a hard coded color code until API >= 21.  Then we can use `@color`. -->
     <path
-        android:fillColor="#FF000000"
+        android:fillColor="#FF1565C0"
         android:pathData="M2.5,4v3h5v12h3L10.5,7h5L15.5,4h-13zM21.5,9h-9v3h3v7h3v-7h3L21.5,9z" />
 </vector>
\ No newline at end of file
index 08b897e8e5fef8b40aa5ae2a8470adabf9d3ed9c..a346c5978bd9ab44d9b4fc5d5b5e5900eced7914 100644 (file)
@@ -13,6 +13,6 @@
 
     <!-- We have to use a hard coded color code until API >= 21.  Then we can use `@color`. -->
     <path
-        android:fillColor="#FF000000"
+        android:fillColor="#FF1565C0"
         android:pathData="M3,6h18L21,4L3,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h4v-2L3,18L3,6zM13,12L9,12v1.78c-0.61,0.55 -1,1.33 -1,2.22s0.39,1.67 1,2.22L9,20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22L13,12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1L23,9c0,-0.5 -0.5,-1 -1,-1zM21,18h-4v-8h4v8z"/>
 </vector>
index 37c8490d262ea20370c05bfabbdb8182cf39fc17..00479b52e0052094794c5b3b5ba757b7670bd16b 100644 (file)
                     android:layout_marginEnd="10dp"
                     android:layout_gravity="center_vertical"
                     android:src="@drawable/user_agent"
-                    android:tint="@color/blue_800"
                     android:contentDescription="@string/user_agent" />
 
                 <Spinner
                 android:layout_marginEnd="10dp"
                 android:layout_gravity="center_vertical"
                 android:src="@drawable/font_size"
-                android:tint="@color/blue_800"
                 android:contentDescription="@string/font_size" />
 
             <Spinner
index 91717abfe60734689ff5147bf87342530bbbfe90..aa5db948b77de1ea6fbdfc8edfe9bf7e9725c2ac 100644 (file)
@@ -58,7 +58,8 @@
             android:title="@string/user_agent"
             android:entries="@array/user_agent_entries"
             android:entryValues="@array/user_agent_entry_values"
-            android:defaultValue="PrivacyBrowser/1.0" />
+            android:defaultValue="PrivacyBrowser/1.0"
+            android:icon="@drawable/user_agent" />
 
         <!-- android:inputType="textVisiblePassword" sets the keyboard to have a dedicated number row.-->
         <EditTextPreference
             android:title="@string/default_font_size"
             android:entries="@array/default_font_size_entries"
             android:entryValues="@array/default_font_size_entry_values"
-            android:defaultValue="100" />
+            android:defaultValue="100"
+            android:icon="@drawable/font_size" />
 
         <SwitchPreference
             android:key="swipe_to_refresh"