Add a "Web Search" option to the WebView select text ActionBar

This change allows selected text in a web view to be used as a search
query.

Bug: 3132422
Change-Id: I9ed2a5913641b37732586f8d8aa8a80c3486b606
diff --git a/core/java/android/webkit/SelectActionModeCallback.java b/core/java/android/webkit/SelectActionModeCallback.java
index 2f3dc7c..54c9d9a 100644
--- a/core/java/android/webkit/SelectActionModeCallback.java
+++ b/core/java/android/webkit/SelectActionModeCallback.java
@@ -16,6 +16,8 @@
 
 package android.webkit;
 
+import android.app.SearchManager;
+import android.content.Intent;
 import android.provider.Browser;
 import android.webkit.WebView;
 import android.view.ActionMode;
@@ -74,6 +76,12 @@
                 mode.finish();
                 mWebView.showFindDialog(sel);
                 break;
+            case com.android.internal.R.id.websearch:
+                mode.finish();
+                Intent i = new Intent(Intent.ACTION_WEB_SEARCH);
+                i.putExtra(SearchManager.QUERY, mWebView.getSelection());
+                mWebView.getContext().startActivity(i);
+                break;
 
             default:
                 return false;
diff --git a/core/res/res/menu/webview_copy.xml b/core/res/res/menu/webview_copy.xml
index b28c1c1..41ad06a 100644
--- a/core/res/res/menu/webview_copy.xml
+++ b/core/res/res/menu/webview_copy.xml
@@ -34,5 +34,10 @@
         android:title="@string/find"
         android:showAsAction="always|withText"
         />
+    <item android:id="@+id/websearch"
+        android:icon="@drawable/ic_menu_search"
+        android:title="@string/websearch"
+        android:showAsAction="always|withText"
+        />
 </menu>
 
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 2e235f0..d780335 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2622,6 +2622,8 @@
     <string name="share">Share</string>
     <!-- ActionBar action to use the current selection to open the Find on page functionality [CHAR LIMIT=10]-->
     <string name="find">Find</string>
+    <!-- ActionBar action to use the current selection to perform a web search [CHAR-LIMIT=16] -->
+    <string name="websearch">Web Search</string>
 
     <!-- Network positioning notification ticker. The name of the user (e.g. John Doe) who sent
          the request is shown as a dynamic string. -->