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 63e45013eb0e644f764c8f74a9f3367c34abd78f..8b1974e11dda6334583a6f9d65ca6432acacc8b3 100644 |
--- a/content/browser/web_contents/web_contents_android.cc |
+++ b/content/browser/web_contents/web_contents_android.cc |
@@ -435,6 +435,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, |