Commit 8c5d422b authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer shell: turn non-URL URL bar inputs into searches.

For example, typing "cats" searches for cats. Works from URL bar or
command line.

Bug: none
Change-Id: Icd609ca4183398254d886d392570216eeca82d7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353059
Auto-Submit: Evan Stade <estade@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797458}
parent 37570b61
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.weblayer.shell; package org.chromium.weblayer.shell;
import static android.util.Patterns.WEB_URL;
import android.app.Activity; import android.app.Activity;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
...@@ -19,7 +21,6 @@ import android.view.Menu; ...@@ -19,7 +21,6 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.webkit.URLUtil;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.PopupMenu; import android.widget.PopupMenu;
...@@ -356,11 +357,7 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -356,11 +357,7 @@ public class WebLayerShellActivity extends FragmentActivity {
if (getCurrentDisplayUrl() != null) { if (getCurrentDisplayUrl() != null) {
return; return;
} }
String startupUrl = getUrlFromIntent(getIntent()); loadUrl(getUrlFromIntent(getIntent()));
if (TextUtils.isEmpty(startupUrl) || !URLUtil.isValidUrl(startupUrl)) {
startupUrl = "https://google.com";
}
loadUrl(startupUrl);
} }
/* Returns the Url for the current tab as a String, or null if there is no /* Returns the Url for the current tab as a String, or null if there is no
...@@ -515,8 +512,21 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -515,8 +512,21 @@ public class WebLayerShellActivity extends FragmentActivity {
return fragment; return fragment;
} }
public void loadUrl(String url) { public void loadUrl(String input) {
mBrowser.getActiveTab().getNavigationController().navigate(Uri.parse(sanitizeUrl(url))); String sanitized = sanitizeUrl(input);
Uri uri;
if (WEB_URL.matcher(sanitized).matches()) {
uri = Uri.parse(sanitized);
} else if (TextUtils.isEmpty(input)) {
uri = Uri.parse("https://google.com");
} else {
uri = Uri.parse("https://google.com/search")
.buildUpon()
.appendQueryParameter("q", input)
.build();
}
mBrowser.getActiveTab().getNavigationController().navigate(uri);
} }
private static String getUrlFromIntent(Intent intent) { private static String getUrlFromIntent(Intent intent) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment