Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2036)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java

Issue 2577963002: Always show 'WEB SEARCH' item in action mode on Chrome (Closed)
Patch Set: android_webview Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | android_webview/java/src/org/chromium/android_webview/AwContents.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java b/android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java
index 16f9a4889c10e0f7a322cdf9136b90b9887d2405..82b4595a9a708d2dd08d9356db206dac9b057a1c 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwActionModeCallback.java
@@ -4,7 +4,10 @@
package org.chromium.android_webview;
+import android.app.SearchManager;
+import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.view.ActionMode;
@@ -19,11 +22,14 @@ import org.chromium.content_public.browser.ActionModeCallbackHelper;
* A class that handles selection action mode for Android WebView.
*/
public class AwActionModeCallback implements ActionMode.Callback {
+ private final Context mContext;
private final AwContents mAwContents;
private final ActionModeCallbackHelper mHelper;
private int mAllowedMenuItems;
- public AwActionModeCallback(AwContents awContents, ActionModeCallbackHelper helper) {
+ public AwActionModeCallback(Context context, AwContents awContents,
+ ActionModeCallbackHelper helper) {
+ mContext = context;
mAwContents = awContents;
mHelper = helper;
mHelper.setAllowedMenuItems(0); // No item is allowed by default for WebView.
@@ -43,7 +49,18 @@ public class AwActionModeCallback implements ActionMode.Callback {
}
private int getAllowedMenu(int menuItem) {
- return mAwContents.isSelectActionModeAllowed(menuItem) ? menuItem : 0;
+ boolean showItem = true;
+ if (menuItem == ActionModeCallbackHelper.MENU_ITEM_WEB_SEARCH) {
+ showItem = isWebSearchAvailable();
+ }
+ return showItem && mAwContents.isSelectActionModeAllowed(menuItem) ? menuItem : 0;
+ }
+
+ private boolean isWebSearchAvailable() {
+ Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
+ intent.putExtra(SearchManager.EXTRA_NEW_SEARCH, true);
+ return mContext.getPackageManager().queryIntentActivities(intent,
+ PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
@Override
« no previous file with comments | « no previous file | android_webview/java/src/org/chromium/android_webview/AwContents.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698