| 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..c1965305bbbd997227d0cbd29d122f9fb2d89d02 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
|
| @@ -2100,6 +2100,25 @@ public class ContentViewCore implements
|
| }
|
|
|
| @Override
|
| + public void translate() {
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
|
| + final String query = sanitizeQuery(getSelectedText(), MAX_SEARCH_QUERY_LENGTH);
|
| + if (TextUtils.isEmpty(query)) return;
|
| +
|
| + Intent i = new Intent(Intent.ACTION_PROCESS_TEXT);
|
| + i.setType("text/plain");
|
| + i.putExtra(Intent.EXTRA_PROCESS_TEXT, query);
|
| + i.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, !isSelectionEditable());
|
| + // add the ability to replace the text after it is translated.
|
| + // Does not work if FLAG_ACTIVITY_NEW_TASK is set.
|
| + try {
|
| + getContext().startActivity(i);
|
| + } 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;
|
| @@ -2166,6 +2185,18 @@ public class ContentViewCore implements
|
| }
|
|
|
| @Override
|
| + public boolean isTranslateAvailable() {
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
|
| + Intent intent = new Intent(Intent.ACTION_PROCESS_TEXT);
|
| + intent.setType("text/plain");
|
| + return getContext()
|
| + .getPackageManager()
|
| + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
|
| + .size()
|
| + > 0;
|
| + }
|
| +
|
| + @Override
|
| public boolean isWebSearchAvailable() {
|
| if (getContentViewClient().doesPerformWebSearch()) return true;
|
| Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
|
|
|