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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/json/json_writer.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
18 #include "cc/layers/solid_color_layer.h" | 17 #include "cc/layers/solid_color_layer.h" |
19 #include "cc/output/begin_frame_args.h" | 18 #include "cc/output/begin_frame_args.h" |
20 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 19 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
21 #include "content/browser/android/gesture_event_type.h" | 20 #include "content/browser/android/gesture_event_type.h" |
22 #include "content/browser/android/interstitial_page_delegate_android.h" | 21 #include "content/browser/android/interstitial_page_delegate_android.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "ui/gfx/android/java_bitmap.h" | 59 #include "ui/gfx/android/java_bitmap.h" |
61 #include "ui/gfx/screen.h" | 60 #include "ui/gfx/screen.h" |
62 #include "ui/gfx/size_conversions.h" | 61 #include "ui/gfx/size_conversions.h" |
63 #include "ui/gfx/size_f.h" | 62 #include "ui/gfx/size_f.h" |
64 | 63 |
65 using base::android::AttachCurrentThread; | 64 using base::android::AttachCurrentThread; |
66 using base::android::ConvertJavaStringToUTF16; | 65 using base::android::ConvertJavaStringToUTF16; |
67 using base::android::ConvertJavaStringToUTF8; | 66 using base::android::ConvertJavaStringToUTF8; |
68 using base::android::ConvertUTF16ToJavaString; | 67 using base::android::ConvertUTF16ToJavaString; |
69 using base::android::ConvertUTF8ToJavaString; | 68 using base::android::ConvertUTF8ToJavaString; |
70 using base::android::ScopedJavaGlobalRef; | |
71 using base::android::ScopedJavaLocalRef; | 69 using base::android::ScopedJavaLocalRef; |
72 using blink::WebGestureEvent; | 70 using blink::WebGestureEvent; |
73 using blink::WebInputEvent; | 71 using blink::WebInputEvent; |
74 | 72 |
75 // Describes the type and enabled state of a select popup item. | 73 // Describes the type and enabled state of a select popup item. |
76 namespace { | 74 namespace { |
77 | 75 |
78 enum { | 76 enum { |
79 #define DEFINE_POPUP_ITEM_TYPE(name, value) POPUP_ITEM_TYPE_##name = value, | 77 #define DEFINE_POPUP_ITEM_TYPE(name, value) POPUP_ITEM_TYPE_##name = value, |
80 #include "content/browser/android/popup_item_type_list.h" | 78 #include "content/browser/android/popup_item_type_list.h" |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); | 1300 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); |
1303 } | 1301 } |
1304 | 1302 |
1305 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { | 1303 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { |
1306 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1304 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1307 if (!rwhva) | 1305 if (!rwhva) |
1308 return 0; | 1306 return 0; |
1309 return rwhva->GetNativeImeAdapter(); | 1307 return rwhva->GetNativeImeAdapter(); |
1310 } | 1308 } |
1311 | 1309 |
1312 namespace { | |
1313 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, | |
1314 const base::Value* result) { | |
1315 JNIEnv* env = base::android::AttachCurrentThread(); | |
1316 std::string json; | |
1317 base::JSONWriter::Write(result, &json); | |
1318 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); | |
1319 Java_ContentViewCore_onEvaluateJavaScriptResult(env, | |
1320 j_json.obj(), | |
1321 callback.obj()); | |
1322 } | |
1323 } // namespace | |
1324 | |
1325 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, | |
1326 jobject obj, | |
1327 jstring script, | |
1328 jobject callback, | |
1329 jboolean start_renderer) { | |
1330 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
1331 DCHECK(rvh); | |
1332 | |
1333 if (start_renderer && !rvh->IsRenderViewLive()) { | |
1334 if (!web_contents_->CreateRenderViewForInitialEmptyDocument()) { | |
1335 LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript"; | |
1336 return; | |
1337 } | |
1338 } | |
1339 | |
1340 if (!callback) { | |
1341 // No callback requested. | |
1342 web_contents_->GetMainFrame()->ExecuteJavaScript( | |
1343 ConvertJavaStringToUTF16(env, script)); | |
1344 return; | |
1345 } | |
1346 | |
1347 // Secure the Java callback in a scoped object and give ownership of it to the | |
1348 // base::Callback. | |
1349 ScopedJavaGlobalRef<jobject> j_callback; | |
1350 j_callback.Reset(env, callback); | |
1351 content::RenderFrameHost::JavaScriptResultCallback c_callback = | |
1352 base::Bind(&JavaScriptResultCallback, j_callback); | |
1353 | |
1354 web_contents_->GetMainFrame()->ExecuteJavaScript( | |
1355 ConvertJavaStringToUTF16(env, script), | |
1356 c_callback); | |
1357 } | |
1358 | |
1359 // TODO(sgurun) add support for posting a frame whose name is known (only | 1310 // TODO(sgurun) add support for posting a frame whose name is known (only |
1360 // main frame is supported at this time, see crbug.com/389721) | 1311 // main frame is supported at this time, see crbug.com/389721) |
1361 // TODO(sgurun) add support for passing message ports | 1312 // TODO(sgurun) add support for passing message ports |
1362 void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj, | 1313 void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj, |
1363 jstring frame_name, jstring message, jstring source_origin, | 1314 jstring frame_name, jstring message, jstring source_origin, |
1364 jstring target_origin) { | 1315 jstring target_origin) { |
1365 | 1316 |
1366 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 1317 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
1367 if (!host) | 1318 if (!host) |
1368 return; | 1319 return; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1519 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1569 retained_objects_set); | 1520 retained_objects_set); |
1570 return reinterpret_cast<intptr_t>(view); | 1521 return reinterpret_cast<intptr_t>(view); |
1571 } | 1522 } |
1572 | 1523 |
1573 bool RegisterContentViewCore(JNIEnv* env) { | 1524 bool RegisterContentViewCore(JNIEnv* env) { |
1574 return RegisterNativesImpl(env); | 1525 return RegisterNativesImpl(env); |
1575 } | 1526 } |
1576 | 1527 |
1577 } // namespace content | 1528 } // namespace content |
OLD | NEW |