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

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

Issue 1409443002: Make Chrome and WebView replace the selected text with the processed text. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved comments around Created 5 years, 2 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 69d11cf978e8029adf93e805b3e2ad632d3cddc1..98a547993ef0502681711acb5fdd371fd6b1a557 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
@@ -9,6 +9,7 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.app.SearchManager;
import android.content.ClipboardManager;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
@@ -102,10 +103,8 @@ import java.util.Map.Entry;
* being tied to the view system.
*/
@JNINamespace("content")
-public class ContentViewCore implements
- AccessibilityStateChangeListener, ScreenOrientationObserver,
- SystemCaptioningBridge.SystemCaptioningBridgeListener {
-
+public class ContentViewCore implements AccessibilityStateChangeListener, ScreenOrientationObserver,
+ SystemCaptioningBridge.SystemCaptioningBridgeListener {
private static final String TAG = "cr.ContentViewCore";
// Used to avoid enabling zooming in / out if resulting zooming will
@@ -2091,7 +2090,19 @@ public class ContentViewCore implements
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, query);
try {
- getContext().startActivity(intent);
+ if (getContentViewClient().doesPerformProcessText()) {
+ getContentViewClient().startProcessTextIntent(intent);
+ } else {
+ getWindowAndroid().showIntent(
+ intent, new WindowAndroid.IntentCallback() {
+ @Override
+ public void onIntentCompleted(WindowAndroid window,
+ int resultCode, ContentResolver contentResolver,
+ Intent data) {
+ onReceivedProcessTextResult(resultCode, data);
+ }
+ }, null);
+ }
} catch (android.content.ActivityNotFoundException ex) {
// If no app handles it, do nothing.
}
@@ -3045,6 +3056,26 @@ public class ContentViewCore implements
}
/**
+ * Called when the processed text is replied from an activity that supports
+ * Intent.ACTION_PROCESS_TEXT.
+ * @param resultCode the code that indicates if the activity successfully processed the text
+ * @param data the reply that contains the processed text.
+ */
+ public void onReceivedProcessTextResult(int resultCode, Intent data) {
+ if (mWebContents == null || !isSelectionEditable() || resultCode != Activity.RESULT_OK
+ || data == null) {
+ return;
+ }
+
+ CharSequence result = data.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
+ if (result != null) {
+ // TODO(hush): Use a variant of replace that re-selects the replaced text.
+ // crbug.com/546710
+ mWebContents.replace(result.toString());
+ }
+ }
+
+ /**
* Returns true if accessibility is on and touch exploration is enabled.
*/
public boolean isTouchExplorationEnabled() {

Powered by Google App Engine
This is Rietveld 408576698