]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Updates about_licenses, adding the full text of the Apache License 2.0 and the 3...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index 0701a162a0fa9aecf83d7c719f0f3ad51ba1e712..353a8d16407ddb6f182921d15dc22916b250e951 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2015-2017 Soren Stoutner <soren@stoutner.com>.
  *
  * Download cookie code contributed 2017 Hendrik Knackstedt.  Copyright assigned to Soren Stoutner <soren@stoutner.com>.
  *
@@ -568,8 +568,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
             @SuppressWarnings("deprecation")
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                // Use an external email program if the link begins with `mailto:`.
-                if (url.startsWith("mailto:")) {
+                if (url.startsWith("mailto:")) {  // Load the URL in an external email program because it begins with `mailto:`.
                     // We use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
                     Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
 
@@ -581,10 +580,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
                     // Make it so.
                     startActivity(emailIntent);
+
+                    // Returning `true` indicates the application is handling the URL.
                     return true;
                 } else {  // Load the URL in Privacy Browser.
-                    loadUrl(url);
-                    return true;
+                    // Apply the domain settings for the new URL.
+                    applyDomainSettings(url);
+
+                    // Returning `false` causes the current `WebView` to handle the URL and prevents it from adding redirects to the history list.
+                    return false;
                 }
             }
 
@@ -1232,10 +1236,21 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 return true;
 
             case R.id.share:
+                // Setup the share string.
+                String shareString;
+                if (webViewTitle != null) {
+                    shareString = webViewTitle + " – " + urlTextBox.getText().toString();
+                } else {
+                    shareString = urlTextBox.getText().toString();
+                }
+
+                // Create the share intent.
                 Intent shareIntent = new Intent();
                 shareIntent.setAction(Intent.ACTION_SEND);
-                shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
+                shareIntent.putExtra(Intent.EXTRA_TEXT, shareString);
                 shareIntent.setType("text/plain");
+
+                // Make it so.
                 startActivity(Intent.createChooser(shareIntent, "Share URL"));
                 return true;
 
@@ -1866,7 +1881,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         String unformattedUrlString = urlTextBox.getText().toString().trim();
 
         // Check to see if `unformattedUrlString` is a valid URL.  Otherwise, convert it into a search.
-        if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.contains("localhost"))) {
+        if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.startsWith("http://")) || (unformattedUrlString.startsWith("https://"))) {
             // Add `http://` at the beginning if it is missing.  Otherwise the app will segfault.
             if (!unformattedUrlString.startsWith("http")) {
                 unformattedUrlString = "http://" + unformattedUrlString;