Commit 1f1083f8 authored by jinsukkim's avatar jinsukkim Committed by Commit bot

Always show 'WEB SEARCH' item in action mode on Chrome

There was a regression not showing web search menu item in
select action mode on Chrome if an activity for ACTION_WEB_SEARCH
cannot be found in the system. Chrome should always show it
since it can show the search result on a new tab. This CL fixes it
by showing the item by default, and having other embedder (webview)
configure it.

BUG=674104

Review-Url: https://codereview.chromium.org/2577963002
Cr-Commit-Position: refs/heads/master@{#439000}
parent 0e643e7b
......@@ -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
......
......@@ -812,7 +812,8 @@ public class AwContents implements SmartClipProvider, PostMessageSender.PostMess
WindowAndroid windowAndroid) {
contentViewCore.initialize(viewDelegate, internalDispatcher, webContents, windowAndroid);
contentViewCore.setActionModeCallback(
new AwActionModeCallback(this, contentViewCore.getActionModeCallbackHelper()));
new AwActionModeCallback(mContext, this,
contentViewCore.getActionModeCallbackHelper()));
contentViewCore.addGestureStateListener(gestureStateListener);
contentViewCore.setContentViewClient(contentViewClient);
}
......
......@@ -739,9 +739,6 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
if (actionModeItem == MENU_ITEM_SHARE) {
return isAllowedByClient && isShareAvailable();
}
if (actionModeItem == MENU_ITEM_WEB_SEARCH) {
return isAllowedByClient && isWebSearchAvailable();
}
return isAllowedByClient;
}
......@@ -945,11 +942,4 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
return mContext.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).size() > 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;
}
}
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