]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Only load domain settings when the domain changes. Fixes https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Tue, 21 Mar 2017 04:17:38 +0000 (21:17 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 21 Mar 2017 04:17:38 +0000 (21:17 -0700)
app/src/main/assets/de/about_contributors.html
app/src/main/assets/en/about_contributors.html
app/src/main/assets/es/about_contributors.html
app/src/main/assets/it/about_contributors.html
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java

index de04b7f4d9713fca3839b0a8ecdf89e606bd9e00..5c9a5e4e4e7af25ede55fc6208e33a618b79277f 100644 (file)
         Hendrik Knackstedt
 
         <h3>Mitwirkende</h3>
-        <a href="mailto:aaron@gerlach.com">Aaron Gerlach</a>: Deutsche<br/>
-        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spanisch<br/>
-        Francesco Buratti: Italienisch
+        Francesco Buratti: Italienisch<br/>
+        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spanisch
 
+        <h3>Past Translators</h3>
+        <a href="mailto:aaron@gerlach.com">Aaron Gerlach</a>: German<br/>
         <br/>
         <p>Mitwirkung ist willkommen in Form von <a href="https://www.stoutner.com/privacy-browser/contributors/">Code und &Uuml;bersetzung</a>.</p>
     </body>
index fef5cab6e8537c9b4798cb39d8f81c55658a7855..a65de0f410105da2b345bf769ab57879b6fd31b2 100644 (file)
@@ -33,8 +33,8 @@
         Hendrik Knackstedt
 
         <h3>Translators</h3>
-        Francesco Buratti: Italian
-        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spanish<br/>
+        Francesco Buratti: Italian<br/>
+        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spanish
 
         <h3>Past Translators</h3>
         <a href="mailto:aaron@gerlach.com">Aaron Gerlach</a>: German<br/>
index adcfecef84b13ac2765f0bc1cb8eabc072fc116f..adcf596e27f6464c60728d7186b02963e1a0d5ad 100644 (file)
         Hendrik Knackstedt
 
         <h3>Traductores</h3>
+        Francesco Buratti: Italiano<br/>
+        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Espa&ntilde;ol
+
+        <h3>Traductores anteriores</h3>
         <a href="mailto:aaron@gerlach.com">Aaron Gerlach</a>: Alem&aacute;n<br/>
-        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Espa&ntilde;ol<br/>
-        Francesco Buratti: Italiano
 
         <br/>
         <p>Los colaboradores son bienvenidos para enviar tanto <a href="https://www.stoutner.com/privacy-browser/contributors/">c&oacute;digo como traducciones</a>.</p>
index 5c86f3ba73250c2b8966a0bf0fadc9e279eaa712..3baf6ed6bf1d3850c6e907da93033b42131960d3 100644 (file)
         Hendrik Knackstedt
 
         <h3>Traduttori</h3>
+        Francesco Buratti: Italiano<br/>
+        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spagnolo
+
+        <h3>Traduttori precedenti</h3>
         <a href="mailto:aaron@gerlach.com">Aaron Gerlach</a>: Tedesco<br/>
-        <a href="mailto:emails@joseleon.me">Jose A. Le&oacute;n Becerra</a>: Spagnolo<br/>
-        Francesco Buratti: Italiano
 
         <br/>
         <p>Si accettano contributi per lo sviluppo di <a href="https://www.stoutner.com/privacy-browser/contributors/">codice e traduzioni</a>.</p>
index 89fb9e0ae0b2b9e241ee413b72a2aa200302111e..08aa9eb21f074639b376f62f7e9e00694e0273f1 100644 (file)
@@ -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 = "<html><body><br/><center><h1>" + getString(R.string.waiting_for_orbot) + "</h1></center></body></html>";
 
-        // 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<String> 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<String> domainSettingsSet = new HashSet<>();
 
-        // Populate `domainSettingsSet`.
-        for (int i=0; i<domainNameCursor.getCount(); i++) {
-            // Move `domainsCursor` to the current row.
-            domainNameCursor.moveToPosition(i);
+            // Get the domain name column index.
+            int domainNameColumnIndex = domainNameCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME);
 
-            // Store the domain name in `domainSettingsSet`.
-            domainSettingsSet.add(domainNameCursor.getString(domainNameColumnIndex));
-        }
+            // Populate `domainSettingsSet`.
+            for (int i = 0; i < domainNameCursor.getCount(); i++) {
+                // Move `domainsCursor` to the current row.
+                domainNameCursor.moveToPosition(i);
+
+                // Store the domain name in `domainSettingsSet`.
+                domainSettingsSet.add(domainNameCursor.getString(domainNameColumnIndex));
+            }
 
-        // Close `domainNameCursor.
-        domainNameCursor.close();
+            // Close `domainNameCursor.
+            domainNameCursor.close();
 
-        // Initialize variables to track if this domain has stored domain settings, and if so, under which name.
-        boolean hostHasDomainSettings = false;
-        String domainNameInDatabase =  null;
+            // Initialize variables to track if this domain has stored domain settings, and if so, under which name.
+            boolean hostHasDomainSettings = false;
+            String domainNameInDatabase = null;
 
-        // Check all the subdomains of `domain` if it is not `null` against the list of domains in `domainCursor`.
-        if (hostname != null) {
+            // Check all the subdomains of `hostname` against the list of domains in `domainCursor`.
             while (hostname.contains(".") && !hostHasDomainSettings) {  // Stop checking if we run out of  `.` or if we already know that `hostHasDomainSettings` is `true`.
                 if (domainSettingsSet.contains(hostname)) {  // Check the host name.
                     hostHasDomainSettings = true;
                     domainNameInDatabase = hostname;
-                } else if (domainSettingsSet.contains("*." + hostname)){  // Check the host name prepended by `*.`.
+                } else if (domainSettingsSet.contains("*." + hostname)) {  // Check the host name prepended by `*.`.
                     hostHasDomainSettings = true;
                     domainNameInDatabase = "*." + hostname;
                 }
@@ -1881,104 +1887,104 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 // Strip out the lowest subdomain of `host`.
                 hostname = hostname.substring(hostname.indexOf(".") + 1);
             }
-        }
 
-        FrameLayout urlAppBarFrameLayout = (FrameLayout) findViewById(R.id.url_app_bar_framelayout);
-
-        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();
-
-            // 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)));
-
-            // 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);
-
-            // Set third-party cookies status if API >= 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);