X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=bbef023eb510738b64b4e05688ed11429038b833;hb=cd2323e565785ec0867462f50de58406adaffe3d;hp=0c80f526d32c53e9aeefc51249479bdbd408a2cd;hpb=ed0a4234b452924acf1602bee6578a7a84445a85;p=PrivacyBrowserAndroid.git 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 0c80f526..bbef023e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -205,7 +205,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation private boolean adBlockerEnabled; // `privacyBrowserRuntime` is used in `onCreate()` and `applyAppSettings()`. - Runtime privacyBrowserRuntime; + private Runtime privacyBrowserRuntime; // `incognitoModeEnabled` is used in `onCreate()` and `applyAppSettings()`. private boolean incognitoModeEnabled; @@ -237,6 +237,9 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // `onTheFlyDisplayImagesSet` is used in `applyDomainSettings()` and `setDisplayWebpageImages()`. private boolean onTheFlyDisplayImagesSet; + // `loadingNewIntentBoolean` is used in `onNewIntent()` and `onRestart()`. + private boolean loadingNewIntentBoolean; + // `waitingForOrbotData` is used in `onCreate()` and `applyAppSettings()`. private String waitingForOrbotHTMLString; @@ -906,6 +909,32 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } } + @Override + protected void onNewIntent(Intent intent) { + // Set `loadingNewIntentBoolean`. + loadingNewIntentBoolean = true; + + // Sets the new intent as the activity intent, so that any future `getIntent()`s pick up this one instead of creating a new activity. + setIntent(intent); + + if (intent.getData() != null) { + // Get the intent data and convert it to a string. + final Uri intentUriData = intent.getData(); + formattedUrlString = intentUriData.toString(); + } + + // Close the navigation drawer if it is open. + if (drawerLayout.isDrawerVisible(GravityCompat.START)) { + drawerLayout.closeDrawer(GravityCompat.START); + } + + // Load the website. + loadUrl(formattedUrlString); + + // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it. + mainWebView.requestFocus(); + } + @Override public void onRestart() { super.onRestart(); @@ -919,8 +948,13 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Set the display webpage images mode. setDisplayWebpageImages(); - // Reload the webpage to remove images if `setDisplayWebpageImages` has turned them off. - mainWebView.reload(); + // Only reload `mainWebView` if not loading a new intent and not waiting for Orbot. + if (!loadingNewIntentBoolean && !waitingForOrbot) { + // Reload the webpage to remove images if `setDisplayWebpageImages` has turned them off. + mainWebView.reload(); + } else if (loadingNewIntentBoolean) { // Reset `loadingNewIntentBoolean` if this run comes from a new intent. + loadingNewIntentBoolean = false; + } } // `onResume()` runs after `onStart()`, which runs after `onCreate()` and `onRestart()`. @@ -956,29 +990,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation super.onPause(); } - @Override - protected void onNewIntent(Intent intent) { - // Sets the new intent as the activity intent, so that any future `getIntent()`s pick up this one instead of creating a new activity. - setIntent(intent); - - if (intent.getData() != null) { - // Get the intent data and convert it to a string. - final Uri intentUriData = intent.getData(); - formattedUrlString = intentUriData.toString(); - } - - // Close the navigation drawer if it is open. - if (drawerLayout.isDrawerVisible(GravityCompat.START)) { - drawerLayout.closeDrawer(GravityCompat.START); - } - - // Load the website. - loadUrl(formattedUrlString); - - // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it. - mainWebView.requestFocus(); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -1774,6 +1785,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(imageUrl)); // Pass cookies to download manager if cookies are enabled. This is required to download images from websites that require a login. + // Code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . if (firstPartyCookiesEnabled) { // Get the cookies for `imageUrl`. String cookies = cookieManager.getCookie(imageUrl); @@ -1821,6 +1833,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(downloadUrl)); // Pass cookies to download manager if cookies are enabled. This is required to download files from websites that require a login. + // Code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . if (firstPartyCookiesEnabled) { // Get the cookies for `downloadUrl`. String cookies = cookieManager.getCookie(downloadUrl);