diff options
author | Ben Murdoch <benm@google.com> | 2014-11-13 21:55:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-11-13 21:55:58 +0000 |
commit | 66b65590bbb54dab9b24d1973ea44deaee01a95d (patch) | |
tree | 93db304fb242fc6252e032b88d7acb01d4bb0ab9 | |
parent | 757e6d30528497c763bce864b552885d3c119fc7 (diff) | |
parent | ed88037384b3793eacfd970667911ea07873a584 (diff) | |
download | chromium_org-66b65590bbb54dab9b24d1973ea44deaee01a95d.tar.gz |
Merge "Implement support for SmartClip in AwContents." into m39
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwContents.java | 30 |
1 files changed, 27 insertions, 3 deletions
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 e47e0cc207..3b45089e0a 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -20,6 +20,7 @@ import android.net.http.SslCertificate; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.Log; @@ -48,6 +49,7 @@ import org.chromium.content.browser.ContentSettings; import org.chromium.content.browser.ContentViewClient; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewStatics; +import org.chromium.content.browser.SmartClipProvider; import org.chromium.content.browser.WebContentsObserverAndroid; import org.chromium.content.common.CleanupReference; import org.chromium.content_public.browser.GestureStateListener; @@ -80,7 +82,7 @@ import java.util.concurrent.Callable; * continuous build & test in the open source SDK-based tree). */ @JNINamespace("android_webview") -public class AwContents { +public class AwContents implements SmartClipProvider { private static final String TAG = "AwContents"; private static final String WEB_ARCHIVE_EXTENSION = ".mht"; @@ -2227,12 +2229,34 @@ public class AwContents { return null; } + @Override public void extractSmartClipData(int x, int y, int width, int height) { if (!isDestroyed()) mContentViewCore.extractSmartClipData(x, y, width, height); } - public void setSmartClipDataListener(ContentViewCore.SmartClipDataListener listener) { - if (!isDestroyed()) mContentViewCore.setSmartClipDataListener(listener); + @Override + public void setSmartClipResultHandler(final Handler resultHandler) { + if (resultHandler == null) { + mContentViewCore.setSmartClipDataListener(null); + return; + } + mContentViewCore.setSmartClipDataListener(new ContentViewCore.SmartClipDataListener() { + public void onSmartClipDataExtracted(String text, String html, Rect clipRect) { + Bundle bundle = new Bundle(); + bundle.putString("url", mContentViewCore.getWebContents().getVisibleUrl()); + bundle.putString("title", mContentViewCore.getWebContents().getTitle()); + bundle.putParcelable("rect", clipRect); + bundle.putString("text", text); + bundle.putString("html", html); + try { + Message msg = Message.obtain(resultHandler, 0); + msg.setData(bundle); + msg.sendToTarget(); + } catch (Exception e) { + Log.e(TAG, "Error calling handler for smart clip data: ", e); + } + } + }); } // -------------------------------------------------------------------------------------------- |