Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| index d3bc650c1ad0ea29b25920fc136c83af82790be2..852a8c22cd7f3f8c4efab535a784db1d2abcf1a3 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| @@ -13,6 +13,7 @@ import android.content.Context; |
| import android.content.ContextWrapper; |
| import android.content.Intent; |
| import android.content.pm.PackageManager; |
| +import android.content.pm.ResolveInfo; |
| import android.content.res.Configuration; |
| import android.database.ContentObserver; |
| import android.graphics.Bitmap; |
| @@ -33,6 +34,8 @@ import android.view.ActionMode; |
| import android.view.HapticFeedbackConstants; |
| import android.view.InputDevice; |
| import android.view.KeyEvent; |
| +import android.view.Menu; |
| +import android.view.MenuItem; |
| import android.view.MotionEvent; |
| import android.view.View; |
| import android.view.ViewGroup; |
| @@ -90,6 +93,7 @@ import org.chromium.ui.touch_selection.SelectionEventType; |
| import java.lang.annotation.Annotation; |
| import java.lang.ref.WeakReference; |
| import java.util.ArrayList; |
| +import java.util.Collections; |
| import java.util.HashMap; |
| import java.util.HashSet; |
| import java.util.LinkedHashMap; |
| @@ -2100,6 +2104,32 @@ public class ContentViewCore implements |
| } |
| @Override |
| + public void initializeTextProcessingMenu(Menu menu) { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
| + int i = 0; |
| + for (ResolveInfo resolveInfo : getSupportedTextProcessingActivities()) { |
|
Ted C
2015/09/17 20:34:57
I would iterate over the list using the for (int i
hush (inactive)
2015/09/17 21:30:52
Done.
|
| + menu.add(R.id.select_action_menu_text_processing_menus, Menu.NONE, i++, |
| + getLabel(resolveInfo)) |
|
Ted C
2015/09/17 20:34:57
this line needs to be indented 4 more
hush (inactive)
2015/09/17 21:30:52
Done.
|
| + .setIntent(createProcessTextIntentForResolveInfo(resolveInfo)) |
| + .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| + } |
| + } |
| + |
| + @Override |
| + public void processText(Intent intent) { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
|
Ted C
2015/09/17 20:34:57
we should probably assert false here since it woul
hush (inactive)
2015/09/17 21:30:52
Done.
|
| + final String query = sanitizeQuery(getSelectedText(), MAX_SEARCH_QUERY_LENGTH); |
| + if (TextUtils.isEmpty(query)) return; |
| + |
| + intent.putExtra(Intent.EXTRA_PROCESS_TEXT, query); |
| + try { |
| + getContext().startActivity(intent); |
| + } catch (android.content.ActivityNotFoundException ex) { |
| + // If no app handles it, do nothing. |
| + } |
| + } |
| + |
| + @Override |
| public void search() { |
| final String query = sanitizeQuery(getSelectedText(), MAX_SEARCH_QUERY_LENGTH); |
| if (TextUtils.isEmpty(query)) return; |
| @@ -2122,6 +2152,32 @@ public class ContentViewCore implements |
| } |
| } |
| + private List<ResolveInfo> getSupportedTextProcessingActivities() { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
|
Ted C
2015/09/17 20:34:57
I would just inline this function above to above t
hush (inactive)
2015/09/17 21:30:52
Done.
|
| + return Collections.<ResolveInfo>emptyList(); |
| + } |
| + PackageManager packageManager = getContext().getPackageManager(); |
| + return packageManager.queryIntentActivities(createProcessTextIntent(), 0); |
| + } |
| + |
| + @TargetApi(Build.VERSION_CODES.M) |
| + private Intent createProcessTextIntent() { |
| + return new Intent().setAction(Intent.ACTION_PROCESS_TEXT).setType("text/plain"); |
| + } |
| + |
| + @TargetApi(Build.VERSION_CODES.M) |
| + private Intent createProcessTextIntentForResolveInfo(ResolveInfo info) { |
| + return createProcessTextIntent() |
| + // TODO(hush): should be !isSelectionEditable(), if WebView supports |
| + // replacing the text. |
| + .putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true) |
| + .setClassName(info.activityInfo.packageName, info.activityInfo.name); |
| + } |
| + |
| + private CharSequence getLabel(ResolveInfo resolveInfo) { |
|
Ted C
2015/09/17 20:34:57
seems unnecessary, I would just inline above.
Doe
hush (inactive)
2015/09/17 21:30:52
Done. And it does not cause any strict mode violat
|
| + return resolveInfo.loadLabel(getContext().getPackageManager()); |
| + } |
| + |
| @Override |
| public boolean isSelectionPassword() { |
| return mFocusedNodeIsPassword; |