From: Soren Stoutner Date: Tue, 21 Mar 2017 04:17:38 +0000 (-0700) Subject: Only load domain settings when the domain changes. Fixes https://redmine.stoutner... X-Git-Tag: v2.0.1~2 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=086d810836a7d34f3e536b8b2622fa9ce07f1d88;p=PrivacyBrowserAndroid.git Only load domain settings when the domain changes. Fixes https://redmine.stoutner.com/issues/101. --- diff --git a/app/src/main/assets/de/about_contributors.html b/app/src/main/assets/de/about_contributors.html index de04b7f4..5c9a5e4e 100644 --- a/app/src/main/assets/de/about_contributors.html +++ b/app/src/main/assets/de/about_contributors.html @@ -38,10 +38,11 @@ Hendrik Knackstedt

Mitwirkende

- Aaron Gerlach: Deutsche
- Jose A. León Becerra: Spanisch
- Francesco Buratti: Italienisch + Francesco Buratti: Italienisch
+ Jose A. León Becerra: Spanisch +

Past Translators

+ Aaron Gerlach: German

Mitwirkung ist willkommen in Form von Code und Übersetzung.

diff --git a/app/src/main/assets/en/about_contributors.html b/app/src/main/assets/en/about_contributors.html index fef5cab6..a65de0f4 100644 --- a/app/src/main/assets/en/about_contributors.html +++ b/app/src/main/assets/en/about_contributors.html @@ -33,8 +33,8 @@ Hendrik Knackstedt

Translators

- Francesco Buratti: Italian - Jose A. León Becerra: Spanish
+ Francesco Buratti: Italian
+ Jose A. León Becerra: Spanish

Past Translators

Aaron Gerlach: German
diff --git a/app/src/main/assets/es/about_contributors.html b/app/src/main/assets/es/about_contributors.html index adcfecef..adcf596e 100644 --- a/app/src/main/assets/es/about_contributors.html +++ b/app/src/main/assets/es/about_contributors.html @@ -33,9 +33,11 @@ Hendrik Knackstedt

Traductores

+ Francesco Buratti: Italiano
+ Jose A. León Becerra: Español + +

Traductores anteriores

Aaron Gerlach: Alemán
- Jose A. León Becerra: Español
- Francesco Buratti: Italiano

Los colaboradores son bienvenidos para enviar tanto código como traducciones.

diff --git a/app/src/main/assets/it/about_contributors.html b/app/src/main/assets/it/about_contributors.html index 5c86f3ba..3baf6ed6 100644 --- a/app/src/main/assets/it/about_contributors.html +++ b/app/src/main/assets/it/about_contributors.html @@ -35,9 +35,11 @@ Hendrik Knackstedt

Traduttori

+ Francesco Buratti: Italiano
+ Jose A. León Becerra: Spagnolo + +

Traduttori precedenti

Aaron Gerlach: Tedesco
- Jose A. León Becerra: Spagnolo
- Francesco Buratti: Italiano

Si accettano contributi per lo sviluppo di codice e traduzioni.

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 89fb9e0a..08aa9eb2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -209,6 +209,9 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // `proxyThroughOrbot` is used in `onCreate()` and `applySettings()` private boolean proxyThroughOrbot; + // `currentDomain` is used in `onCreate() and `applyDomainSettings()`. + private String currentDomain; + // `pendingUrl` is used in `onCreate()` and `applySettings()` private static String pendingUrl; @@ -292,10 +295,9 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Set `waitingForOrbotHTMLString`. waitingForOrbotHTMLString = "

" + getString(R.string.waiting_for_orbot) + "

"; - // Initialize `pendingUrl`. + // Initialize `currentDomain`, `pendingUrl`, and `orbotStatus`. + currentDomain = ""; pendingUrl = ""; - - // Set the initial Orbot status. orbotStatus = "unknown"; // Create an Orbot status `BroadcastReceiver`. @@ -800,8 +802,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation domStorageEnabled = false; saveFormDataEnabled = false; - // Apply the settings from the shared preferences. - applySettings(); + // Apply the app settings from the shared preferences. + applyAppSettings(); // Load `formattedUrlString` if we are not proxying through Orbot and waiting for Orbot to connect. if (!(proxyThroughOrbot && !orbotStatus.equals("ON"))) { @@ -1765,7 +1767,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation super.onRestart(); // Apply the settings from shared preferences, which might have been changed in `SettingsActivity`. - applySettings(); + applyAppSettings(); // Update the privacy icon. `true` runs `invalidateOptionsMenu` as the last step. updatePrivacyIcons(true); @@ -1838,42 +1840,46 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Extract the domain from `uri`. String hostname = uri.getHost(); - // Initialize the database handler. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`. - // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`. - DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(this, null, null, 0); + // Only apply the domain settings if `hostname` is not the same as `currentDomain`. This allows the user to set temporary settings for JavaScript, Cookies, DOM Storage, etc. + if (!hostname.equals(currentDomain)) { + // Set the new `hostname` as the `currentDomain`. + currentDomain = hostname; - // Get a full cursor from `domainsDatabaseHelper`. - Cursor domainNameCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomain(); + // Initialize the database handler. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`. + // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`. + DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(this, null, null, 0); - // Initialize `domainSettingsSet`. - Set domainSettingsSet = new HashSet<>(); + // Get a full cursor from `domainsDatabaseHelper`. + Cursor domainNameCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomain(); - // Get the domain name column index. - int domainNameColumnIndex = domainNameCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME); + // Initialize `domainSettingsSet`. + Set domainSettingsSet = new HashSet<>(); - // Populate `domainSettingsSet`. - for (int i=0; i= 21. - if (Build.VERSION.SDK_INT >= 21) { - cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); - } + FrameLayout urlAppBarFrameLayout = (FrameLayout) findViewById(R.id.url_app_bar_framelayout); - // Set the user agent. - 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); - } + if (hostHasDomainSettings) { // 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); + currentHostDomainSettingsCursor.moveToFirst(); - // Set a green background on `urlTextBox` to indicate that custom domain settings are being used. We have to use the deprecated `.getColor()` until the minimum API >= 23. - urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.green_100)); - } else { // The URL we are loading does not have custom domain settings. Load the defaults. - // Get the shared preference values. `this` references the current context. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - - // Store the values from `sharedPreferences` in variables. - javaScriptEnabled = sharedPreferences.getBoolean("javascript_enabled", false); - firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false); - 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); - cookieManager.setAcceptCookie(firstPartyCookiesEnabled); - mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); - mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); - mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString)); - - // Set third-party cookies status if API >= 21. - if (Build.VERSION.SDK_INT >= 21) { - cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); - } + // Get the settings from the cursor. + javaScriptEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)) == 1); + firstPartyCookiesEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)) == 1); + thirdPartyCookiesEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)) == 1); + domStorageEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)) == 1); + saveFormDataEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)) == 1); + String userAgentString = (currentHostDomainSettingsCursor.getString(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT))); + int fontSize = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE))); - // Set the default user agent. - switch (userAgentString) { - case "WebView default user agent": - // Set the user agent to `""`, which uses the default value. - mainWebView.getSettings().setUserAgentString(""); - break; + // Close `currentHostDomainSettingsCursor`. + currentHostDomainSettingsCursor.close(); + + // Apply the domain settings. + mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled); + cookieManager.setAcceptCookie(firstPartyCookiesEnabled); + mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); + mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); + mainWebView.getSettings().setTextZoom(fontSize); - case "Custom user agent": - // Set the custom user agent. - mainWebView.getSettings().setUserAgentString(customUserAgentString); - break; + // Set third-party cookies status if API >= 21. + if (Build.VERSION.SDK_INT >= 21) { + cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); + } - default: + // Set the user agent. + 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); - break; - } + } - // Set a transparent background on `urlTextBox`. We have to use the deprecated `.getColor()` until the minimum API >= 23. - urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.transparent)); - } + // Set a green background on `urlTextBox` to indicate that custom domain settings are being used. We have to use the deprecated `.getColor()` until the minimum API >= 23. + urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.green_100)); + } else { // The URL we are loading does not have custom domain settings. Load the defaults. + // Get the shared preference values. `this` references the current context. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + + // Store the values from `sharedPreferences` in variables. + javaScriptEnabled = sharedPreferences.getBoolean("javascript_enabled", false); + firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false); + 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); + cookieManager.setAcceptCookie(firstPartyCookiesEnabled); + mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); + mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); + mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString)); - // Close `domainsDatabaseHelper`. - domainsDatabaseHelper.close(); + // Set third-party cookies status if API >= 21. + if (Build.VERSION.SDK_INT >= 21) { + cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); + } + + // Set the default user agent. + switch (userAgentString) { + 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(customUserAgentString); + break; + + default: + // Use the selected user agent. + mainWebView.getSettings().setUserAgentString(userAgentString); + break; + } - // Update the privacy icons, but only if `mainMenu` has already been populated. - if (mainMenu != null) { - updatePrivacyIcons(true); + // Set a transparent background on `urlTextBox`. We have to use the deprecated `.getColor()` until the minimum API >= 23. + urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.transparent)); + } + + // Close `domainsDatabaseHelper`. + domainsDatabaseHelper.close(); + + // Update the privacy icons, but only if `mainMenu` has already been populated. + if (mainMenu != null) { + updatePrivacyIcons(true); + } } } @@ -2009,7 +2015,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); } - private void applySettings() { + private void applyAppSettings() { // Get the shared preference values. `this` references the current context. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);