]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Remove Torch from the list of recommended Tor search engines. Fixes https://redmine...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index 6e1189bb8736697e351d6616b6f81ac136823ca2..60ff281448bded819d6ae54f51c92b23b3843b02 100644 (file)
@@ -221,14 +221,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
     // `translucentNavigationBarOnFullscreen` is used in `onCreate()` and `applyAppSettings()`.
     private boolean translucentNavigationBarOnFullscreen;
 
-    // `proxyThroughOrbot` is used in `onCreate()` and `applyAppSettings()`.
-    private boolean proxyThroughOrbot;
-
     // `currentDomainName` is used in `onCreate(), `onNavigationItemSelected()`, and `applyDomainSettings()`.
     private String currentDomainName;
 
-    // `pendingUrl` is used in `onCreate()` and `applyAppSettings()`.
-    private static String pendingUrl;
+    // `waitingForOrbot` is used in `onCreate()` and `applyAppSettings()`.
+    private boolean waitingForOrbot;
 
     // `waitingForOrbotData` is used in `onCreate()` and `applyAppSettings()`.
     private String waitingForOrbotHTMLString;
@@ -313,10 +310,10 @@ 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 `currentDomainName`, `pendingUrl`, and `orbotStatus`.
+        // Initialize `currentDomainName`, `orbotStatus`, and `waitingForOrbot`.
         currentDomainName = "";
-        pendingUrl = "";
         orbotStatus = "unknown";
+        waitingForOrbot = false;
 
         // Create an Orbot status `BroadcastReceiver`.
         BroadcastReceiver orbotStatusBroadcastReceiver = new BroadcastReceiver() {
@@ -325,19 +322,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 // Store the content of the status message in `orbotStatus`.
                 orbotStatus = intent.getStringExtra("org.torproject.android.intent.extra.STATUS");
 
-                // If we are waiting on `pendingUrl`, load it now that Orbot is connected.
-                if (orbotStatus.equals("ON") && !pendingUrl.isEmpty()) {
-
-                    // Wait 500 milliseconds, because Orbot isn't really ready yet.
-                    try {
-                        Thread.sleep(500);
-                    } catch (InterruptedException exception) {
-                        // Do nothing.
-                    }
-
-                    // Copy `pendingUrl` to `formattedUrlString` and reset `pendingUrl` to be empty.
-                    formattedUrlString = pendingUrl;
-                    pendingUrl = "";
+                // If we are waiting on Orbot, load the website now that Orbot is connected.
+                if (orbotStatus.equals("ON") && waitingForOrbot) {
+                    // Reset `waitingForOrbot`.
+                    waitingForOrbot = false;
 
                     // Load `formattedUrlString
                     loadUrl(formattedUrlString);
@@ -647,7 +635,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 webViewTitle = getString(R.string.no_title);
 
                 // Check to see if we are waiting on Orbot.
-                if (pendingUrl.isEmpty()) {  // We are not waiting on Orbot, so we need to process the URL.
+                if (!waitingForOrbot) {  // We are not waiting on Orbot, so we need to process the URL.
                     // We need to update `formattedUrlString` at the beginning of the load, so that if the user toggles JavaScript during the load the new website is reloaded.
                     formattedUrlString = url;
 
@@ -685,7 +673,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 }
 
                 // Update `urlTextBox` and apply domain settings if not waiting on Orbot.
-                if (pendingUrl.isEmpty()) {  // We are not waiting on Orbot, so we need to process the URL.
+                if (!waitingForOrbot) {
                     // Check to see if `WebView` has set `url` to be `about:blank`.
                     if (url.equals("about:blank")) {  // `WebView` is blank, so `formattedUrlString` should be `""` and `urlTextBox` should display a hint.
                         // Set `formattedUrlString` to `""`.
@@ -879,9 +867,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Initialize `webViewTitle`.
         webViewTitle = getString(R.string.no_title);
 
-        // Apply the app settings from the shared preferences.
-        applyAppSettings();
-
         // Initialize `favoriteIconBitmap`.  We have to use `ContextCompat` until API >= 21.
         Drawable favoriteIconDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.world);
         BitmapDrawable favoriteIconBitmapDrawable = (BitmapDrawable) favoriteIconDrawable;
@@ -890,12 +875,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // If the favorite icon is null, load the default.
         if (favoriteIconBitmap == null) {
             favoriteIconBitmap = favoriteIconDefaultBitmap;
+        }
 
-        // Load `formattedUrlString` if we are not proxying through Orbot and waiting for Orbot to connect.
-        if (!(proxyThroughOrbot && !orbotStatus.equals("ON"))) {
+        // Apply the app settings from the shared preferences.
+        applyAppSettings();
+
+        // Load `formattedUrlString` if we are not waiting for Orbot to connect.
+        if (!waitingForOrbot) {
             loadUrl(formattedUrlString);
         }
-        }
     }
 
 
@@ -1834,7 +1822,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
     }
 
     @Override
-    public void onResume() {
+    public void onResume() {  // `onResume()` also runs every time the app starts after `onCreate()` and `onStart()`.
         super.onResume();
 
         // Resume JavaScript (if enabled).
@@ -2146,7 +2134,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         adBlockerEnabled = sharedPreferences.getBoolean("block_ads", true);
         incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false);
         boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false);
-        proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);
+        boolean proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);
         fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("enable_full_screen_browsing_mode", false);
         hideSystemBarsOnFullscreen = sharedPreferences.getBoolean("hide_system_bars", false);
         translucentNavigationBarOnFullscreen = sharedPreferences.getBoolean("translucent_navigation_bar", true);
@@ -2181,8 +2169,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
             // Display a message to the user if we are waiting on Orbot.
             if (!orbotStatus.equals("ON")) {
-                // Save `formattedUrlString` in `pendingUrl`.
-                pendingUrl = formattedUrlString;
+                // Set `waitingForOrbot`.
+                waitingForOrbot = true;
 
                 // Load a waiting page.  `null` specifies no encoding, which defaults to ASCII.
                 mainWebView.loadData(waitingForOrbotHTMLString, "text/html", null);
@@ -2213,11 +2201,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
             // Reset the proxy to default.  The host is `""` and the port is `"0"`.
             OrbotProxyHelper.setProxy(getApplicationContext(), this, "", "0");
 
-            // Reset `pendingUrl` if we are currently waiting for Orbot to connect.
-            if (!pendingUrl.isEmpty()) {
-                formattedUrlString = pendingUrl;
-                pendingUrl = "";
-            }
+            // Reset `waitingForOrbot.
+            waitingForOrbot = false;
         }
 
         // Set swipe to refresh.