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_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 // base::Callback. | 433 // base::Callback. |
434 ScopedJavaGlobalRef<jobject> j_callback; | 434 ScopedJavaGlobalRef<jobject> j_callback; |
435 j_callback.Reset(env, callback); | 435 j_callback.Reset(env, callback); |
436 RenderFrameHost::JavaScriptResultCallback js_callback = | 436 RenderFrameHost::JavaScriptResultCallback js_callback = |
437 base::Bind(&JavaScriptResultCallback, j_callback); | 437 base::Bind(&JavaScriptResultCallback, j_callback); |
438 | 438 |
439 web_contents_->GetMainFrame()->ExecuteJavaScript( | 439 web_contents_->GetMainFrame()->ExecuteJavaScript( |
440 ConvertJavaStringToUTF16(env, script), js_callback); | 440 ConvertJavaStringToUTF16(env, script), js_callback); |
441 } | 441 } |
442 | 442 |
443 void WebContentsAndroid::EvaluateJavaScriptForTests(JNIEnv* env, | |
444 jobject obj, | |
445 jstring script, | |
446 jobject callback) { | |
447 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
448 DCHECK(rvh); | |
449 | |
450 if (!rvh->IsRenderViewLive()) { | |
451 if (!static_cast<WebContentsImpl*>(web_contents_)-> | |
452 CreateRenderViewForInitialEmptyDocument()) { | |
453 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests"; | |
454 return; | |
455 } | |
456 } | |
457 | |
458 if (!callback) { | |
459 // No callback requested. | |
460 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( | |
461 ConvertJavaStringToUTF16(env, script)); | |
462 return; | |
463 } | |
464 | |
465 // Secure the Java callback in a scoped object and give ownership of it to the | |
466 // base::Callback. | |
467 ScopedJavaGlobalRef<jobject> j_callback; | |
468 j_callback.Reset(env, callback); | |
469 RenderFrameHost::JavaScriptResultCallback js_callback = | |
470 base::Bind(&JavaScriptResultCallback, j_callback); | |
471 | |
472 web_contents_->GetMainFrame()->ExecuteJavaScriptForTests( | |
473 ConvertJavaStringToUTF16(env, script), js_callback); | |
474 } | |
475 | |
476 void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, | 443 void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, |
477 jobject jobj, | 444 jobject jobj, |
478 jint level, | 445 jint level, |
479 jstring message) { | 446 jstring message) { |
480 DCHECK_GE(level, 0); | 447 DCHECK_GE(level, 0); |
481 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST); | 448 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST); |
482 | 449 |
483 web_contents_->GetMainFrame()->AddMessageToConsole( | 450 web_contents_->GetMainFrame()->AddMessageToConsole( |
484 static_cast<ConsoleMessageLevel>(level), | 451 static_cast<ConsoleMessageLevel>(level), |
485 ConvertJavaStringToUTF8(env, message)); | 452 ConvertJavaStringToUTF8(env, message)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 484 |
518 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { | 485 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { |
519 web_contents_->ResumeMediaSession(); | 486 web_contents_->ResumeMediaSession(); |
520 } | 487 } |
521 | 488 |
522 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { | 489 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { |
523 web_contents_->SuspendMediaSession(); | 490 web_contents_->SuspendMediaSession(); |
524 } | 491 } |
525 | 492 |
526 } // namespace content | 493 } // namespace content |
OLD | NEW |