| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 | 336 |
| 337 void WebContentsAndroid::DidStartNavigationTransitionForFrame(int64 frame_id) { | 337 void WebContentsAndroid::DidStartNavigationTransitionForFrame(int64 frame_id) { |
| 338 JNIEnv* env = AttachCurrentThread(); | 338 JNIEnv* env = AttachCurrentThread(); |
| 339 Java_WebContentsImpl_didStartNavigationTransitionForFrame( | 339 Java_WebContentsImpl_didStartNavigationTransitionForFrame( |
| 340 env, obj_.obj(), frame_id); | 340 env, obj_.obj(), frame_id); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, | 343 void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, |
| 344 jobject obj, | 344 jobject obj, |
| 345 jstring script, | 345 jstring script, |
| 346 jobject callback, | 346 jobject callback) { |
| 347 jboolean start_renderer) { | |
| 348 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 347 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 349 DCHECK(rvh); | 348 DCHECK(rvh); |
| 350 | 349 |
| 351 if (start_renderer && !rvh->IsRenderViewLive()) { | 350 if (!rvh->IsRenderViewLive()) { |
| 352 if (!static_cast<WebContentsImpl*>(web_contents_)-> | 351 if (!static_cast<WebContentsImpl*>(web_contents_)-> |
| 353 CreateRenderViewForInitialEmptyDocument()) { | 352 CreateRenderViewForInitialEmptyDocument()) { |
| 354 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript"; | 353 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript"; |
| 355 return; | 354 return; |
| 356 } | 355 } |
| 357 } | 356 } |
| 358 | 357 |
| 359 if (!callback) { | 358 if (!callback) { |
| 360 // No callback requested. | 359 // No callback requested. |
| 361 web_contents_->GetMainFrame()->ExecuteJavaScript( | 360 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 362 ConvertJavaStringToUTF16(env, script)); | 361 ConvertJavaStringToUTF16(env, script)); |
| 363 return; | 362 return; |
| 364 } | 363 } |
| 365 | 364 |
| 366 // Secure the Java callback in a scoped object and give ownership of it to the | 365 // Secure the Java callback in a scoped object and give ownership of it to the |
| 367 // base::Callback. | 366 // base::Callback. |
| 368 ScopedJavaGlobalRef<jobject> j_callback; | 367 ScopedJavaGlobalRef<jobject> j_callback; |
| 369 j_callback.Reset(env, callback); | 368 j_callback.Reset(env, callback); |
| 370 content::RenderFrameHost::JavaScriptResultCallback js_callback = | 369 content::RenderFrameHost::JavaScriptResultCallback js_callback = |
| 371 base::Bind(&JavaScriptResultCallback, j_callback); | 370 base::Bind(&JavaScriptResultCallback, j_callback); |
| 372 | 371 |
| 373 web_contents_->GetMainFrame()->ExecuteJavaScript( | 372 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 374 ConvertJavaStringToUTF16(env, script), js_callback); | 373 ConvertJavaStringToUTF16(env, script), js_callback); |
| 375 } | 374 } |
| 376 | 375 |
| 377 } // namespace content | 376 } // namespace content |
| OLD | NEW |