summaryrefslogtreecommitdiffstats
path: root/android_webview/java
diff options
context:
space:
mode:
authorhush <hush@chromium.org>2015-10-23 12:30:22 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-23 19:31:25 +0000
commitbc5bc8853ce851bc323a2d4fbddb25abacd0aafe (patch)
tree18962eff96b26b66d41a44832d0bc7b0cca1d719 /android_webview/java
parent20f614c8452f52ce85da0caec79f476d02e86a9b (diff)
downloadchromium_src-bc5bc8853ce851bc323a2d4fbddb25abacd0aafe.zip
chromium_src-bc5bc8853ce851bc323a2d4fbddb25abacd0aafe.tar.gz
chromium_src-bc5bc8853ce851bc323a2d4fbddb25abacd0aafe.tar.bz2
Make Chrome and WebView replace the selected text with the processed text.
This CL uses WindowAndroid to send intents and receive results for Chrome. It is not possible to do the same for WebView because WebView is not by itself an application. WebView needs to use View#startActivityForResult to send intents and use View#onActivityResult to receive the process text. Both of these View APIs are in M. BUG=521027 Review URL: https://codereview.chromium.org/1409443002 Cr-Commit-Position: refs/heads/master@{#355858}
Diffstat (limited to 'android_webview/java')
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java11
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java26
2 files changed, 34 insertions, 3 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
index 5b452c5..cf39c5b 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java
@@ -5,6 +5,7 @@
package org.chromium.android_webview;
import android.content.Context;
+import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.URLUtil;
@@ -103,6 +104,16 @@ public class AwContentViewClient extends ContentViewClient implements ContentVid
public void setSystemUiVisibility(boolean enterFullscreen) {
}
+ @Override
+ public boolean doesPerformProcessText() {
+ return true;
+ }
+
+ @Override
+ public void startProcessTextIntent(Intent intent) {
+ mAwContents.startProcessTextIntent(intent);
+ }
+
/**
* Called to show the web contents in fullscreen mode.
*
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index ab356ff..6f3b8d0 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -100,6 +100,8 @@ public class AwContents implements SmartClipProvider,
private static final int WARN = 1;
private static final String WEB_ARCHIVE_EXTENSION = ".mht";
+ // The request code should be unique per WebView/AwContents object.
+ private static final int PROCESS_TEXT_REQUEST_CODE = 100;
// Used to avoid enabling zooming in / out if resulting zooming will
// produce little visible difference.
@@ -2210,7 +2212,7 @@ public class AwContents implements SmartClipProvider,
* be thrown by Android framework if startActivityForResult is called with
* a non-Activity context.
*/
- public void startActivityForResult(Intent intent, int requestCode) {
+ void startActivityForResult(Intent intent, int requestCode) {
// Even in fullscreen mode, startActivityForResult will still use the
// initial internal access delegate because it has access to
// the hidden API View#startActivityForResult.
@@ -2218,9 +2220,27 @@ public class AwContents implements SmartClipProvider,
.super_startActivityForResult(intent, requestCode);
}
+ void startProcessTextIntent(Intent intent) {
+ // on Android M, WebView is not able to replace the text with the processed text.
+ // So set the readonly flag for M.
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
+ intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true);
+ }
+
+ if (ContentViewCore.activityFromContext(mContext) == null) {
+ mContext.startActivity(intent);
+ return;
+ }
+
+ startActivityForResult(intent, PROCESS_TEXT_REQUEST_CODE);
+ }
+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- // TODO(hush): Forward the activity result to content view core and
- // replace the text with translated text.
+ if (requestCode == PROCESS_TEXT_REQUEST_CODE) {
+ mContentViewCore.onReceivedProcessTextResult(resultCode, data);
+ } else {
+ Log.e(TAG, "Received activity result for an unknown request code " + requestCode);
+ }
}
/**