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

Side by Side Diff: content/browser/web_contents/web_contents_android.cc

Issue 1123783002: Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 4 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 unified diff | Download patch
OLDNEW
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
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
443 void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, 476 void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env,
444 jobject jobj, 477 jobject jobj,
445 jint level, 478 jint level,
446 jstring message) { 479 jstring message) {
447 DCHECK_GE(level, 0); 480 DCHECK_GE(level, 0);
448 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST); 481 DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST);
449 482
450 web_contents_->GetMainFrame()->AddMessageToConsole( 483 web_contents_->GetMainFrame()->AddMessageToConsole(
451 static_cast<ConsoleMessageLevel>(level), 484 static_cast<ConsoleMessageLevel>(level),
452 ConvertJavaStringToUTF8(env, message)); 485 ConvertJavaStringToUTF8(env, message));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 517
485 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { 518 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) {
486 web_contents_->ResumeMediaSession(); 519 web_contents_->ResumeMediaSession();
487 } 520 }
488 521
489 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { 522 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) {
490 web_contents_->SuspendMediaSession(); 523 web_contents_->SuspendMediaSession();
491 } 524 }
492 525
493 } // namespace content 526 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698