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

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 23018005: Start renderer in ContentViewCoreImpl::EvaluateJavaScript. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 7 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/android/content_view_core_impl.h" 5 #include "content/browser/android/content_view_core_impl.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/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); 1465 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json);
1466 Java_ContentViewCore_onEvaluateJavaScriptResult(env, 1466 Java_ContentViewCore_onEvaluateJavaScriptResult(env,
1467 j_json.obj(), 1467 j_json.obj(),
1468 callback.obj()); 1468 callback.obj());
1469 } 1469 }
1470 } // namespace 1470 } // namespace
1471 1471
1472 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, 1472 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
1473 jobject obj, 1473 jobject obj,
1474 jstring script, 1474 jstring script,
1475 jobject callback) { 1475 jobject callback,
1476 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1476 jboolean start_renderer) {
1477 DCHECK(host); 1477 RenderViewHost* rvh = web_contents_->GetRenderViewHost();
1478 DCHECK(rvh);
1479
1480 if (start_renderer && !rvh->IsRenderViewLive()) {
1481 if (!web_contents_->CreateRenderViewForInitialEmptyDocument()) {
1482 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript";
1483 return;
1484 }
1485 }
1478 1486
1479 if (!callback) { 1487 if (!callback) {
1480 // No callback requested. 1488 // No callback requested.
1481 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath 1489 rvh->ExecuteJavascriptInWebFrame(string16(), // frame_xpath
1482 ConvertJavaStringToUTF16(env, script)); 1490 ConvertJavaStringToUTF16(env, script));
1483 return; 1491 return;
1484 } 1492 }
1485 1493
1486 // Secure the Java callback in a scoped object and give ownership of it to the 1494 // Secure the Java callback in a scoped object and give ownership of it to the
1487 // base::Callback. 1495 // base::Callback.
1488 ScopedJavaGlobalRef<jobject> j_callback; 1496 ScopedJavaGlobalRef<jobject> j_callback;
1489 j_callback.Reset(env, callback); 1497 j_callback.Reset(env, callback);
1490 content::RenderViewHost::JavascriptResultCallback c_callback = 1498 content::RenderViewHost::JavascriptResultCallback c_callback =
1491 base::Bind(&JavaScriptResultCallback, j_callback); 1499 base::Bind(&JavaScriptResultCallback, j_callback);
1492 1500
1493 host->ExecuteJavascriptInWebFrameCallbackResult( 1501 rvh->ExecuteJavascriptInWebFrameCallbackResult(
1494 string16(), // frame_xpath 1502 string16(), // frame_xpath
1495 ConvertJavaStringToUTF16(env, script), 1503 ConvertJavaStringToUTF16(env, script),
1496 c_callback); 1504 c_callback);
1497 } 1505 }
1498 1506
1499 bool ContentViewCoreImpl::GetUseDesktopUserAgent( 1507 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1500 JNIEnv* env, jobject obj) { 1508 JNIEnv* env, jobject obj) {
1501 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 1509 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
1502 return entry && entry->GetIsOverridingUserAgent(); 1510 return entry && entry->GetIsOverridingUserAgent();
1503 } 1511 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 reinterpret_cast<ui::ViewAndroid*>(view_android), 1602 reinterpret_cast<ui::ViewAndroid*>(view_android),
1595 reinterpret_cast<ui::WindowAndroid*>(window_android)); 1603 reinterpret_cast<ui::WindowAndroid*>(window_android));
1596 return reinterpret_cast<jint>(view); 1604 return reinterpret_cast<jint>(view);
1597 } 1605 }
1598 1606
1599 bool RegisterContentViewCore(JNIEnv* env) { 1607 bool RegisterContentViewCore(JNIEnv* env) {
1600 return RegisterNativesImpl(env); 1608 return RegisterNativesImpl(env);
1601 } 1609 }
1602 1610
1603 } // namespace content 1611 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698