X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=50f6a2cca239d85c35f75f280371f151ca58c8be;hp=b6ba809717074ee392dee17ad0fc4dcdafe4ce9c;hb=8b69108b214333167fc16cb897143005a7dfbad7;hpb=a35a6e396b61579e00f1954801720613dd6685f7 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 b6ba8097..50f6a2cc 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -810,11 +810,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook String intentAction = intent.getAction(); Uri intentUriData = intent.getData(); - // Only process the URI if it contains data. If the user pressed the desktop icon after the app was already running the URI will be null. - if (intentUriData != null) { - // Sets the new intent as the activity intent, which replaces the one that originally started the app. - setIntent(intent); + // Determine if this is a web search. + boolean isWebSearch = ((intentAction != null) && intentAction.equals(Intent.ACTION_WEB_SEARCH)); + // Only process the URI if it contains data or it is a web search. If the user pressed the desktop icon after the app was already running the URI will be null. + if (intentUriData != null || isWebSearch) { // Get the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -831,7 +831,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook String url; // If the intent action is a web search, perform the search. - if ((intentAction != null) && intentAction.equals(Intent.ACTION_WEB_SEARCH)) { + if (isWebSearch) { // Create an encoded URL string. String encodedUrlString; @@ -3160,6 +3160,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } else { // There isn't anything to do in Privacy Browser. // Run the default commands. super.onBackPressed(); + + // Manually kill Privacy Browser. Otherwise, it is glitchy when restarted. + System.exit(0); } } @@ -5374,10 +5377,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook CheckPinnedMismatchHelper.checkPinnedMismatch(getSupportFragmentManager(), nestedScrollWebView); } + // Get the current URL from the nested scroll WebView. This is more accurate than using the URL passed into the method, which is sometimes not the final one. + String currentUrl = nestedScrollWebView.getUrl(); + // Update the URL text bar if the page is currently selected and the user is not currently typing in the URL edit text. - if ((tabLayout.getSelectedTabPosition() == currentPagePosition) && !urlEditText.hasFocus()) { + // Crash records show that, in some crazy way, it is possible for the current URL to be blank at this point. + // Probably some sort of race condition when Privacy Browser is being resumed. + if ((tabLayout.getSelectedTabPosition() == currentPagePosition) && !urlEditText.hasFocus() && (currentUrl != null)) { // Check to see if the URL is `about:blank`. - if (nestedScrollWebView.getUrl().equals("about:blank")) { // The WebView is blank. + if (currentUrl.equals("about:blank")) { // The WebView is blank. // Display the hint in the URL edit text. urlEditText.setText(""); @@ -5394,7 +5402,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook applyDomainSettings(nestedScrollWebView, "", true, false); } else { // The WebView has loaded a webpage. // Display the final URL. Getting the URL from the WebView instead of using the one provided by `onPageFinished()` makes websites like YouTube function correctly. - urlEditText.setText(nestedScrollWebView.getUrl()); + urlEditText.setText(currentUrl); // Apply text highlighting to the URL. highlightUrlText();