OLD | NEW |
---|---|
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 Loading... | |
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 = |
1478 static_cast<RenderViewHost*>(web_contents_->GetRenderViewHost()); | |
1479 DCHECK(rvh); | |
1480 | |
1481 if (start_renderer && !rvh->IsRenderViewLive()) { | |
1482 if (!web_contents_->CreateRenderViewWithoutNavigationEntry(rvh)) { | |
Charlie Reis
2013/08/20 22:03:49
Maybe navigate it to about:blank first instead?
michaelbai
2013/08/21 23:32:17
Already tried, the Java context can not be transfe
| |
1483 LOG(ERROR) << "Falied to create RenderView in EvaluateJavaScript"; | |
Charlie Reis
2013/08/20 22:03:49
nit: Failed
michaelbai
2013/08/21 23:32:17
Done.
| |
1484 return; | |
1485 } | |
1486 } | |
1478 | 1487 |
1479 if (!callback) { | 1488 if (!callback) { |
1480 // No callback requested. | 1489 // No callback requested. |
1481 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath | 1490 rvh->ExecuteJavascriptInWebFrame(string16(), // frame_xpath |
1482 ConvertJavaStringToUTF16(env, script)); | 1491 ConvertJavaStringToUTF16(env, script)); |
1483 return; | 1492 return; |
1484 } | 1493 } |
1485 | 1494 |
1486 // Secure the Java callback in a scoped object and give ownership of it to the | 1495 // Secure the Java callback in a scoped object and give ownership of it to the |
1487 // base::Callback. | 1496 // base::Callback. |
1488 ScopedJavaGlobalRef<jobject> j_callback; | 1497 ScopedJavaGlobalRef<jobject> j_callback; |
1489 j_callback.Reset(env, callback); | 1498 j_callback.Reset(env, callback); |
1490 content::RenderViewHost::JavascriptResultCallback c_callback = | 1499 content::RenderViewHost::JavascriptResultCallback c_callback = |
1491 base::Bind(&JavaScriptResultCallback, j_callback); | 1500 base::Bind(&JavaScriptResultCallback, j_callback); |
1492 | 1501 |
1493 host->ExecuteJavascriptInWebFrameCallbackResult( | 1502 rvh->ExecuteJavascriptInWebFrameCallbackResult( |
1494 string16(), // frame_xpath | 1503 string16(), // frame_xpath |
1495 ConvertJavaStringToUTF16(env, script), | 1504 ConvertJavaStringToUTF16(env, script), |
1496 c_callback); | 1505 c_callback); |
1497 } | 1506 } |
1498 | 1507 |
1499 bool ContentViewCoreImpl::GetUseDesktopUserAgent( | 1508 bool ContentViewCoreImpl::GetUseDesktopUserAgent( |
1500 JNIEnv* env, jobject obj) { | 1509 JNIEnv* env, jobject obj) { |
1501 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); | 1510 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); |
1502 return entry && entry->GetIsOverridingUserAgent(); | 1511 return entry && entry->GetIsOverridingUserAgent(); |
1503 } | 1512 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1594 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1603 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1595 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1604 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1596 return reinterpret_cast<jint>(view); | 1605 return reinterpret_cast<jint>(view); |
1597 } | 1606 } |
1598 | 1607 |
1599 bool RegisterContentViewCore(JNIEnv* env) { | 1608 bool RegisterContentViewCore(JNIEnv* env) { |
1600 return RegisterNativesImpl(env); | 1609 return RegisterNativesImpl(env); |
1601 } | 1610 } |
1602 | 1611 |
1603 } // namespace content | 1612 } // namespace content |
OLD | NEW |