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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 1349563003: Implement Android M text process action in ActionMode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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
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);

Powered by Google App Engine
This is Rietveld 408576698