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

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

Issue 11788005: Switch Android code to use ExecuteJavascriptInWebFrameCallbackResult. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 7 years, 11 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 26d01f42162a2430ccfd6f79307dcaebf739be2b..a97a69c737b08efb2ecd4f218e56abd73200a0f2 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
@@ -1097,18 +1097,26 @@ public class ContentViewCore implements MotionEventDelegate, NavigationClient {
}
}
+ public interface JavaScriptCallback {
+ void handleJavaScriptResult(String jsonResult);
+ }
+
/**
- * Injects the passed JavaScript code in the current page and evaluates it.
- * Once evaluated, an asynchronous call to
- * ContentViewClient.onJavaScriptEvaluationResult is made. Used in automation
- * tests.
+ * Injects the passed Javascript code in the current page and evaluates it.
+ * If a result is required, pass in a callback.
+ * Used in automation tests.
*
- * @return an id that is passed along in the asynchronous onJavaScriptEvaluationResult callback
+ * @param script The Javascript to execute.
+ * @param message The callback to be fired off when a result is ready. The script's
+ * result will be json encoded and passed as the parameter, and the call
+ * will be made on the main thread.
+ * If no result is required, pass null.
* @throws IllegalStateException If the ContentView has been destroyed.
*/
- public int evaluateJavaScript(String script) throws IllegalStateException {
+ public void evaluateJavaScript(
+ String script, JavaScriptCallback callback) throws IllegalStateException {
checkIsAlive();
- return nativeEvaluateJavaScript(script);
+ nativeEvaluateJavaScript(mNativeContentViewCore, script, callback);
}
/**
@@ -2043,8 +2051,9 @@ public class ContentViewCore implements MotionEventDelegate, NavigationClient {
@SuppressWarnings("unused")
@CalledByNative
- private void onEvaluateJavaScriptResult(int id, String jsonResult) {
- getContentViewClient().onEvaluateJavaScriptResult(id, jsonResult);
+ private static void onEvaluateJavaScriptResult(
+ String jsonResult, JavaScriptCallback callback) {
+ callback.handleJavaScriptResult(jsonResult);
}
@SuppressWarnings("unused")
@@ -2555,7 +2564,8 @@ public class ContentViewCore implements MotionEventDelegate, NavigationClient {
private native void nativeClearHistory(int nativeContentViewCoreImpl);
- private native int nativeEvaluateJavaScript(String script);
+ private native void nativeEvaluateJavaScript(int nativeContentViewCoreImpl,
+ String script, JavaScriptCallback callback);
private native int nativeGetNativeImeAdapter(int nativeContentViewCoreImpl);

Powered by Google App Engine
This is Rietveld 408576698