Index: content/browser/web_contents/web_contents_android.cc |
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc |
index 33296c100ab1fde8f60151aee7c38d474b1afd0a..8fd5c506a2dfb263920e9538108c22af5985d837 100644 |
--- a/content/browser/web_contents/web_contents_android.cc |
+++ b/content/browser/web_contents/web_contents_android.cc |
@@ -440,6 +440,39 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, |
ConvertJavaStringToUTF16(env, script), js_callback); |
} |
+void WebContentsAndroid::EvaluateJavaScriptForTests(JNIEnv* env, |
+ jobject obj, |
+ jstring script, |
+ jobject callback) { |
+ RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
+ DCHECK(rvh); |
+ |
+ if (!rvh->IsRenderViewLive()) { |
+ if (!static_cast<WebContentsImpl*>(web_contents_)-> |
+ CreateRenderViewForInitialEmptyDocument()) { |
+ LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests"; |
+ return; |
+ } |
+ } |
+ |
+ if (!callback) { |
+ // No callback requested. |
+ web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( |
+ ConvertJavaStringToUTF16(env, script)); |
+ return; |
+ } |
+ |
+ // Secure the Java callback in a scoped object and give ownership of it to the |
+ // base::Callback. |
+ ScopedJavaGlobalRef<jobject> j_callback; |
+ j_callback.Reset(env, callback); |
+ RenderFrameHost::JavaScriptResultCallback js_callback = |
+ base::Bind(&JavaScriptResultCallback, j_callback); |
+ |
+ web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( |
+ ConvertJavaStringToUTF16(env, script), js_callback); |
+} |
+ |
void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, |
jobject jobj, |
jint level, |