From 93aa3ac5acb2e3f7c238b1052e39a305f3c9986e Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 11 Jul 2017 11:39:06 -0700 Subject: [PATCH] Add `System default` entries in domain settings. https://redmine.stoutner.com/issues/153 --- .idea/dictionaries/soren.xml | 1 + app/src/main/assets/it/about_licenses.html | 5 +- .../activities/DomainSettingsActivity.java | 4 +- .../activities/MainWebViewActivity.java | 57 +++++++--- .../fragments/DomainSettingsFragment.java | 101 +++++++++++++----- .../helpers/DomainsDatabaseHelper.java | 4 +- app/src/main/res/values-es/strings.xml | 30 +++++- app/src/main/res/values-it/strings.xml | 30 +++++- app/src/main/res/values/strings.xml | 56 ++++++++++ 9 files changed, 242 insertions(+), 46 deletions(-) diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index ad8158d5..4ee70c2d 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -29,6 +29,7 @@ customuseragent deeplinks didn + displayimages displayorder dname doesn diff --git a/app/src/main/assets/it/about_licenses.html b/app/src/main/assets/it/about_licenses.html index 899cd65e..efe8d205 100644 --- a/app/src/main/assets/it/about_licenses.html +++ b/app/src/main/assets/it/about_licenses.html @@ -63,8 +63,9 @@ Il testo completo della Licenza è riportato di seguito. Copyright delle modifiche © 2016 Soren Stoutner. Le immagini risultanti sono rilasciate sotto Licenza GPLv3+.

- is derived from ic_exit_to_app, which is part of the Android Material icon set and is released under the Apache License 2.0. - The full text of the license is below. Modifications copyright © 2017 Soren Stoutner. The resulting image is released under the GPLv3+ license.

+ è stata derivata da ic_exit_to_app, che fa parte dell'Android Material icon set ed è stata rilasciata sotto Licenza Apache 2.0. + Il testo completo della licenza è riportato di seguito. Copyright delle modifiche © 2017 Soren Stoutner. + L'immagine risultante è rilasciata sotto Licenza GPLv3+.

orbot è una versione modificata della icona di stato del progetto Orbot, il cui copyright è 2009-2010 Nathan Freitas, The Guardian Project. E' rilasciata sotto 3-clause BSD license. Il testo completo della Licenza è riportato di seguito. Copyright delle modifiche © 2017Soren Stoutner. L'immagine risultante è rilasciata sotto Licenza GPLv3+.

diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java index 17529eba..c4b6581c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainSettingsActivity.java @@ -134,8 +134,8 @@ public class DomainSettingsActivity extends AppCompatActivity { int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition(); // Get the data for the `Spinners` from the entry values string arrays. - String userAgentString = getResources().getStringArray(R.array.user_agent_entry_values)[userAgentPositionInt]; - int fontSizeInt = Integer.parseInt(getResources().getStringArray(R.array.default_font_size_entry_values)[fontSizePositionInt]); + String userAgentString = getResources().getStringArray(R.array.domain_settings_user_agent_entry_values)[userAgentPositionInt]; + int fontSizeInt = Integer.parseInt(getResources().getStringArray(R.array.domain_settings_font_size_entry_values)[fontSizePositionInt]); // Check to see if we are using a custom user agent. if (userAgentString.equals("Custom user agent")) { 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 36650cd7..f1110c57 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -2445,6 +2445,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Get a handle for the shared preference. `this` references the current context. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + // Store the default font size and user agent information. + String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100"); + String defaultUserAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0"); + String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"); + if (domainSettingsApplied) { // The url we are loading has custom domain settings. // Get a cursor for the current host and move it to the first position. Cursor currentHostDomainSettingsCursor = domainsDatabaseHelper.getCursorForDomainName(domainNameInDatabase); @@ -2468,7 +2473,13 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation cookieManager.setAcceptCookie(firstPartyCookiesEnabled); mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); - mainWebView.getSettings().setTextZoom(fontSize); + + // Apply the font size. + if (fontSize == 0) { // Apply the default font size. + mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString)); + } else { // Apply the specified font size. + mainWebView.getSettings().setTextZoom(fontSize); + } // Set third-party cookies status if API >= 21. if (Build.VERSION.SDK_INT >= 21) { @@ -2477,12 +2488,34 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Only set the user agent if the webpage is not currently loading. Otherwise, changing the user agent on redirects can cause the original website to reload. if (!urlIsLoading) { - if (userAgentString.equals("WebView default user agent")) { - // Set the user agent to `""`, which uses the default value. - mainWebView.getSettings().setUserAgentString(""); - } else { - // Use the selected user agent. - mainWebView.getSettings().setUserAgentString(userAgentString); + switch (userAgentString) { + case "System default user agent": + // Set the user agent according to the system default. + switch (defaultUserAgentString) { + case "WebView default user agent": + // Set the user agent to `""`, which uses the default value. + mainWebView.getSettings().setUserAgentString(""); + break; + + case "Custom user agent": + // Set the custom user agent. + mainWebView.getSettings().setUserAgentString(defaultCustomUserAgentString); + break; + + default: + // Use the selected user agent. + mainWebView.getSettings().setUserAgentString(defaultUserAgentString); + } + break; + + case "WebView default user agent": + // Set the user agent to `""`, which uses the default value. + mainWebView.getSettings().setUserAgentString(""); + break; + + default: + // Use the selected user agent. + mainWebView.getSettings().setUserAgentString(userAgentString); } } @@ -2499,9 +2532,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false); domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false); saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); - String userAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0"); - String customUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"); - String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100"); // Apply the default settings. mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled); @@ -2517,7 +2547,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Only set the user agent if the webpage is not currently loading. Otherwise, changing the user agent on redirects can cause the original website to reload. if (!urlIsLoading) { - switch (userAgentString) { + switch (defaultUserAgentString) { case "WebView default user agent": // Set the user agent to `""`, which uses the default value. mainWebView.getSettings().setUserAgentString(""); @@ -2525,13 +2555,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation case "Custom user agent": // Set the custom user agent. - mainWebView.getSettings().setUserAgentString(customUserAgentString); + mainWebView.getSettings().setUserAgentString(defaultCustomUserAgentString); break; default: // Use the selected user agent. - mainWebView.getSettings().setUserAgentString(userAgentString); - break; + mainWebView.getSettings().setUserAgentString(defaultUserAgentString); } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java index 8581f400..dbd8bb9b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -21,10 +21,12 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.database.Cursor; import android.os.Build; import android.os.Bundle; // We have to use `android.support.v4.app.Fragment` until minimum API >= 23. Otherwise we cannot call `getContext()`. +import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -109,10 +111,10 @@ public class DomainSettingsFragment extends Fragment { int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)); // Create `ArrayAdapters` for the `Spinners`and their `entry values`. - ArrayAdapter userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entries, R.layout.spinner_item); - final ArrayAdapter userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entry_values, R.layout.spinner_item); - ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entries, R.layout.spinner_item); - ArrayAdapter fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entry_values, R.layout.spinner_item); + ArrayAdapter userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entries, R.layout.spinner_item); + final ArrayAdapter userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entry_values, R.layout.spinner_item); + ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entries, R.layout.spinner_item); + ArrayAdapter fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entry_values, R.layout.spinner_item); final ArrayAdapter displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_website_images_array, R.layout.spinner_item); // Set the `DropDownViewResource` on the `Spinners`. @@ -251,6 +253,13 @@ public class DomainSettingsFragment extends Fragment { WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview); final String webViewDefaultUserAgentString = bareWebView.getSettings().getUserAgentString(); + // Get a handle for the shared preference. `this` references the current context. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + // Store the default user agent string values. + final String defaultUserAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0"); + final String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"); + // Get the position of the user agent in `userAgentEntryValuesArrayAdapter`. int userAgentArrayPosition = userAgentEntryValuesArrayAdapter.getPosition(currentUserAgentString); @@ -265,26 +274,46 @@ public class DomainSettingsFragment extends Fragment { // Show `customUserAgentEditText` and set `userAgentString` as the text. customUserAgentEditText.setVisibility(View.VISIBLE); customUserAgentEditText.setText(currentUserAgentString); - } else if (currentUserAgentString.equals("WebView default user agent")) { // We are using the `WebView` default user agent. + } else{ // We are using one of the preset user agents. // Set the `userAgentSpinner` selection. userAgentSpinner.setSelection(userAgentArrayPosition); - // Show `userAgentTextView` and set the text. + // Show `userAgentTextView`. userAgentTextView.setVisibility(View.VISIBLE); - userAgentTextView.setText(webViewDefaultUserAgentString); // Hide `customUserAgentEditText`. customUserAgentEditText.setVisibility(View.GONE); - } else { // We are using a standard user agent. - // Set the `userAgentSpinner` selection. - userAgentSpinner.setSelection(userAgentArrayPosition); - // Show `userAgentTextView` and set the text. - userAgentTextView.setVisibility(View.VISIBLE); - userAgentTextView.setText(currentUserAgentString); + // Set the user agent text. + switch (currentUserAgentString) { + case "System default user agent": + // Display the user agent text string. + switch (defaultUserAgentString) { + case "WebView default user agent": + // Display the `WebView` default user agent. + userAgentTextView.setText(webViewDefaultUserAgentString); + break; + + case "Custom user agent": + // Display the custom user agent. + userAgentTextView.setText(defaultCustomUserAgentString); + break; + + default: + // Display the text from `defaultUserAgentString`. + userAgentTextView.setText(defaultUserAgentString); + } + break; - // Hide `customUserAgentEditText`. - customUserAgentEditText.setVisibility(View.GONE); + case "WebView default user agent": + // Display the `WebView` default user agent. + userAgentTextView.setText(webViewDefaultUserAgentString); + break; + + default: + // Display the text from `currentUserAgentString`. + userAgentTextView.setText(currentUserAgentString); + } } // Set the selected font size. @@ -475,17 +504,33 @@ public class DomainSettingsFragment extends Fragment { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { // Store the new user agent string. - String newUserAgentString = getResources().getStringArray(R.array.user_agent_entry_values)[position]; + String newUserAgentString = getResources().getStringArray(R.array.domain_settings_user_agent_entry_values)[position]; // Set the new user agent. switch (newUserAgentString) { - case "Custom user agent": - // Hide `userAgentTextView`. - userAgentTextView.setVisibility(View.GONE); + case "System default user agent": + // Show `userAgentTextView`. + userAgentTextView.setVisibility(View.VISIBLE); - // Show `customUserAgentEditText` and set `userAgentString` as the text. - customUserAgentEditText.setVisibility(View.VISIBLE); - customUserAgentEditText.setText(currentUserAgentString); + // Hide `customUserAgentEditText`. + customUserAgentEditText.setVisibility(View.GONE); + + // Set the user text. + switch (defaultUserAgentString) { + case "WebView default user agent": + // Display the `WebView` default user agent. + userAgentTextView.setText(webViewDefaultUserAgentString); + break; + + case "Custom user agent": + // Display the custom user agent. + userAgentTextView.setText(defaultCustomUserAgentString); + break; + + default: + // Display the text from `defaultUserAgentString`. + userAgentTextView.setText(defaultUserAgentString); + } break; case "WebView default user agent": @@ -497,14 +542,22 @@ public class DomainSettingsFragment extends Fragment { customUserAgentEditText.setVisibility(View.GONE); break; + case "Custom user agent": + // Hide `userAgentTextView`. + userAgentTextView.setVisibility(View.GONE); + + // Show `customUserAgentEditText` and set `userAgentString` as the text. + customUserAgentEditText.setVisibility(View.VISIBLE); + customUserAgentEditText.setText(currentUserAgentString); + break; + default: // Show `userAgentTextView` and set the text. userAgentTextView.setVisibility(View.VISIBLE); - userAgentTextView.setText(getResources().getStringArray(R.array.user_agent_entry_values)[position]); + userAgentTextView.setText(newUserAgentString); // Hide `customUserAgentEditText`. customUserAgentEditText.setVisibility(View.GONE); - break; } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java index f6bd47ad..86a1ed12 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java @@ -142,8 +142,8 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, false); domainContentValues.put(ENABLE_DOM_STORAGE, false); domainContentValues.put(ENABLE_FORM_DATA, false); - domainContentValues.put(USER_AGENT, "PrivacyBrowser/1.0"); - domainContentValues.put(FONT_SIZE, "100"); + domainContentValues.put(USER_AGENT, "System default user agent"); + domainContentValues.put(FONT_SIZE, 0); domainContentValues.put(DISPLAY_IMAGES, 0); // Get a writable database handle. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ed5790dc..9a3e922d 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -60,7 +60,7 @@ Ver certificado SSL Web sin cifrar - La comunicación con esta web no está cifrada por un certificado SSL. + La comunicación con esta página web no está cifrada. Esto permite a terceras partes interceptar información, rastrear su navegación e inyectar contenido malicioso. Certificado SSL Cerrar Emitido a @@ -232,6 +232,23 @@ Safari 10.0.2 en macOS 10.12.2 Personalizado + + Por defecto del sistema + Navegador Privado 1.0 + WebView por defecto + Firefox 50 en Android 7.1.1 + Chrome 55 en Android 7.1.1 + Safari 10 en iOS 10.2.1 + Firefox 45 en Linux + Chromium 55 en Linux + Konqueror 4.14.26 en Linux + Firefox 50 en Windows 10 + Chrome 55 en Windows 10 + Edge 14 en Windows 10 + Internet Explorer 11 en Windows 10 + Safari 10.0.2 en macOS 10.12.2 + Personalizado + Agente de usuario personalizado Bloquear anuncios Usar la lista de servidores de anuncios de pgl.yoyo.org para bloquear anuncios. @@ -296,6 +313,17 @@ 175% 200% + + Por defecto del sistema + 25% + 50% + 75% + 100% + 125% + 150% + 175% + 200% + Deslizar para actualizar Algunas webs no funcionan bien si la opción deslizar para actualizar está habilitada. Mostrar iconos adicionales en la barra de aplicación diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 6ae6b91c..a2a56174 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -62,7 +62,7 @@ Visualizza il certificato SSL Sito non criptato - La comunicazione con il sito non è criptata attraverso un certificato SSL. + La comunicazione con questo sito web non è criptata. Questo consente a terze parti la possibilità di intercettare le informazioni scambiate, di tracciare la navigazione e di inviare contenuto maligno. Certificato SSL Chiudi Emesso a @@ -234,6 +234,23 @@ Safari 10.0.2 su macOS 10.12.2 Personalizzato + + Impostazioni di default + Privacy Browser 1.0 + WebView Default + Firefox 50 su Android 7.1.1 + Chrome 55 su Android 7.1.1 + Safari 10 su iOS 10.2.1 + Firefox 45 su Linux + Chromium 55 su Linux + Konqueror 4.14.26 su Linux + Firefox 50 su Windows 10 + Chrome 55 su Windows 10 + Edge 14 su Windows 10 + Internet Explorer 11 su Windows 10 + Safari 10.0.2 su macOS 10.12.2 + Personalizzato + User agent personalizzato Blocca annunci Per bloccare gli annunci utilizza la lista dei server di pgl.yoyo.org. @@ -298,6 +315,17 @@ 175% 200% + + Impostazioni di default + 25% + 50% + 75% + 100% + 125% + 150% + 175% + 200% + Swipe per aggiornare Alcuni siti non funzionano correttamente se questa opzione è abilitata. Mostra icone addizionali nella barra dell\'applicazione diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 386e9c9d..359cc97e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -252,6 +252,40 @@ Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12 Custom user agent + + + System default + Privacy Browser 1.0 + WebView Default + Firefox 50 on Android 7.1.1 + Chrome 55 on Android 7.1.1 + Safari 10 on iOS 10.2.1 + Firefox 45 on Linux + Chromium 55 on Linux + Konqueror 4.14.26 on Linux + Firefox 50 on Windows 10 + Chrome 55 on Windows 10 + Edge 14 on Windows 10 + Internet Explorer 11 on Windows 10 + Safari 10.0.2 on macOS 10.12.2 + Custom + + + System default user agent + PrivacyBrowser/1.0 + WebView default user agent + Mozilla/5.0 (Android 7.1.1; Mobile; rv:50.0) Gecko/50.0 Firefox/50.0 + Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6P Build/N4F26I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36 + Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1 + Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 + Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36 + Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) konqueror/4.14.26 Safari/534.34 + Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0 + Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 + Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393 + Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko + Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12 + Custom user agent Custom user agent Block ads @@ -345,6 +379,28 @@ 175 200 + + System default + 25% + 50% + 75% + 100% + 125% + 150% + 175% + 200% + + + 0 + 25 + 50 + 75 + 100 + 125 + 150 + 175 + 200 + Swipe to refresh Some websites don’t work well if swipe to refresh is enabled. Display additional app bar icons -- 2.45.2