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" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
18 #include "cc/layers/solid_color_layer.h" | 18 #include "cc/layers/solid_color_layer.h" |
19 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
20 #include "content/browser/android/gesture_event_type.h" | 20 #include "content/browser/android/gesture_event_type.h" |
21 #include "content/browser/android/interstitial_page_delegate_android.h" | 21 #include "content/browser/android/interstitial_page_delegate_android.h" |
22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" | 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" |
23 #include "content/browser/android/load_url_params.h" | 23 #include "content/browser/android/load_url_params.h" |
24 #include "content/browser/android/popup_touch_handle_drawable.h" | 24 #include "content/browser/android/popup_touch_handle_drawable.h" |
25 #include "content/browser/frame_host/interstitial_page_impl.h" | 25 #include "content/browser/frame_host/interstitial_page_impl.h" |
26 #include "content/browser/frame_host/navigation_controller_impl.h" | |
27 #include "content/browser/frame_host/navigation_entry_impl.h" | |
28 #include "content/browser/geolocation/geolocation_dispatcher_host.h" | 26 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
29 #include "content/browser/media/media_web_contents_observer.h" | 27 #include "content/browser/media/media_web_contents_observer.h" |
30 #include "content/browser/renderer_host/compositor_impl_android.h" | 28 #include "content/browser/renderer_host/compositor_impl_android.h" |
31 #include "content/browser/renderer_host/input/motion_event_android.h" | 29 #include "content/browser/renderer_host/input/motion_event_android.h" |
32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 30 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
33 #include "content/browser/renderer_host/input/web_input_event_util.h" | 31 #include "content/browser/renderer_host/input/web_input_event_util.h" |
34 #include "content/browser/renderer_host/render_view_host_impl.h" | 32 #include "content/browser/renderer_host/render_view_host_impl.h" |
35 #include "content/browser/renderer_host/render_widget_host_impl.h" | 33 #include "content/browser/renderer_host/render_widget_host_impl.h" |
36 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 34 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 35 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 return; | 789 return; |
792 | 790 |
793 gfx::Point start_point = gfx::Point(start.x(), start.y()); | 791 gfx::Point start_point = gfx::Point(start.x(), start.y()); |
794 gfx::Point end_point = gfx::Point(end.x(), end.y()); | 792 gfx::Point end_point = gfx::Point(end.x(), end.y()); |
795 if (start_point == end_point) | 793 if (start_point == end_point) |
796 return; | 794 return; |
797 | 795 |
798 web_contents_->SelectRange(start_point, end_point); | 796 web_contents_->SelectRange(start_point, end_point); |
799 } | 797 } |
800 | 798 |
801 void ContentViewCoreImpl::LoadUrl( | |
802 NavigationController::LoadURLParams& params) { | |
803 GetWebContents()->GetController().LoadURLWithParams(params); | |
804 } | |
805 | |
806 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 799 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
807 return view_android_; | 800 return view_android_; |
808 } | 801 } |
809 | 802 |
810 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 803 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
811 return window_android_; | 804 return window_android_; |
812 } | 805 } |
813 | 806 |
814 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 807 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
815 return root_layer_.get(); | 808 return root_layer_.get(); |
(...skipping 15 matching lines...) Expand all Loading... |
831 | 824 |
832 int selected_count = env->GetArrayLength(indices); | 825 int selected_count = env->GetArrayLength(indices); |
833 std::vector<int> selected_indices; | 826 std::vector<int> selected_indices; |
834 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); | 827 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); |
835 for (int i = 0; i < selected_count; ++i) | 828 for (int i = 0; i < selected_count; ++i) |
836 selected_indices.push_back(indices_ptr[i]); | 829 selected_indices.push_back(indices_ptr[i]); |
837 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); | 830 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); |
838 rvhi->DidSelectPopupMenuItems(selected_indices); | 831 rvhi->DidSelectPopupMenuItems(selected_indices); |
839 } | 832 } |
840 | 833 |
841 void ContentViewCoreImpl::LoadUrl( | |
842 JNIEnv* env, jobject obj, | |
843 jstring url, | |
844 jint load_url_type, | |
845 jint transition_type, | |
846 jstring j_referrer_url, | |
847 jint referrer_policy, | |
848 jint ua_override_option, | |
849 jstring extra_headers, | |
850 jbyteArray post_data, | |
851 jstring base_url_for_data_url, | |
852 jstring virtual_url_for_data_url, | |
853 jboolean can_load_local_resources, | |
854 jboolean is_renderer_initiated) { | |
855 DCHECK(url); | |
856 NavigationController::LoadURLParams params( | |
857 GURL(ConvertJavaStringToUTF8(env, url))); | |
858 | |
859 params.load_type = static_cast<NavigationController::LoadURLType>( | |
860 load_url_type); | |
861 params.transition_type = PageTransitionFromInt(transition_type); | |
862 params.override_user_agent = | |
863 static_cast<NavigationController::UserAgentOverrideOption>( | |
864 ua_override_option); | |
865 | |
866 if (extra_headers) | |
867 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); | |
868 | |
869 if (post_data) { | |
870 std::vector<uint8> http_body_vector; | |
871 base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector); | |
872 params.browser_initiated_post_data = | |
873 base::RefCountedBytes::TakeVector(&http_body_vector); | |
874 } | |
875 | |
876 if (base_url_for_data_url) { | |
877 params.base_url_for_data_url = | |
878 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); | |
879 } | |
880 | |
881 if (virtual_url_for_data_url) { | |
882 params.virtual_url_for_data_url = | |
883 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); | |
884 } | |
885 | |
886 params.can_load_local_resources = can_load_local_resources; | |
887 if (j_referrer_url) { | |
888 params.referrer = content::Referrer( | |
889 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), | |
890 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | |
891 } | |
892 | |
893 params.is_renderer_initiated = is_renderer_initiated; | |
894 | |
895 LoadUrl(params); | |
896 } | |
897 | |
898 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( | 834 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( |
899 JNIEnv* env, jobject) const { | 835 JNIEnv* env, jobject) const { |
900 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec()); | 836 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec()); |
901 } | 837 } |
902 | 838 |
903 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | 839 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
904 return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); | 840 return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); |
905 } | 841 } |
906 | 842 |
907 WebContents* ContentViewCoreImpl::GetWebContents() const { | 843 WebContents* ContentViewCoreImpl::GetWebContents() const { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 } | 1113 } |
1178 | 1114 |
1179 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, | 1115 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, |
1180 jobject obj, | 1116 jobject obj, |
1181 jboolean enabled) { | 1117 jboolean enabled) { |
1182 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1118 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1183 if (rwhv) | 1119 if (rwhv) |
1184 rwhv->SetMultiTouchZoomSupportEnabled(enabled); | 1120 rwhv->SetMultiTouchZoomSupportEnabled(enabled); |
1185 } | 1121 } |
1186 | 1122 |
1187 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | |
1188 // TODO(creis): Do callers of this need to know if it fails? | |
1189 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | |
1190 web_contents_->GetController().PruneAllButLastCommitted(); | |
1191 } | |
1192 | |
1193 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1123 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
1194 JNIEnv* env, | 1124 JNIEnv* env, |
1195 jobject obj, | 1125 jobject obj, |
1196 jboolean allow) { | 1126 jboolean allow) { |
1197 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); | 1127 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); |
1198 } | 1128 } |
1199 | 1129 |
1200 void ContentViewCoreImpl::AddJavascriptInterface( | 1130 void ContentViewCoreImpl::AddJavascriptInterface( |
1201 JNIEnv* env, | 1131 JNIEnv* env, |
1202 jobject /* obj */, | 1132 jobject /* obj */, |
(...skipping 21 matching lines...) Expand all Loading... |
1224 root_layer_->SetBounds(physical_size); | 1154 root_layer_->SetBounds(physical_size); |
1225 | 1155 |
1226 if (view) { | 1156 if (view) { |
1227 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 1157 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
1228 view->GetRenderWidgetHost()); | 1158 view->GetRenderWidgetHost()); |
1229 host->SendScreenRects(); | 1159 host->SendScreenRects(); |
1230 view->WasResized(); | 1160 view->WasResized(); |
1231 } | 1161 } |
1232 } | 1162 } |
1233 | 1163 |
1234 namespace { | |
1235 | |
1236 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj, | |
1237 jobject history, | |
1238 NavigationEntry* entry, | |
1239 int index) { | |
1240 // Get the details of the current entry | |
1241 ScopedJavaLocalRef<jstring> j_url( | |
1242 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | |
1243 ScopedJavaLocalRef<jstring> j_virtual_url( | |
1244 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); | |
1245 ScopedJavaLocalRef<jstring> j_original_url( | |
1246 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); | |
1247 ScopedJavaLocalRef<jstring> j_title( | |
1248 ConvertUTF16ToJavaString(env, entry->GetTitle())); | |
1249 ScopedJavaLocalRef<jobject> j_bitmap; | |
1250 const FaviconStatus& status = entry->GetFavicon(); | |
1251 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) | |
1252 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | |
1253 | |
1254 // Add the item to the list | |
1255 Java_ContentViewCore_addToNavigationHistory( | |
1256 env, obj, history, index, j_url.obj(), j_virtual_url.obj(), | |
1257 j_original_url.obj(), j_title.obj(), j_bitmap.obj()); | |
1258 } | |
1259 | |
1260 } // namespace | |
1261 | |
1262 int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env, | |
1263 jobject obj, | |
1264 jobject history) { | |
1265 // Iterate through navigation entries to populate the list | |
1266 const NavigationController& controller = web_contents_->GetController(); | |
1267 int count = controller.GetEntryCount(); | |
1268 for (int i = 0; i < count; ++i) { | |
1269 AddNavigationEntryToHistory( | |
1270 env, obj, history, controller.GetEntryAtIndex(i), i); | |
1271 } | |
1272 | |
1273 return controller.GetCurrentEntryIndex(); | |
1274 } | |
1275 | |
1276 void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env, | |
1277 jobject obj, | |
1278 jobject history, | |
1279 jboolean is_forward, | |
1280 jint max_entries) { | |
1281 // Iterate through navigation entries to populate the list | |
1282 const NavigationController& controller = web_contents_->GetController(); | |
1283 int count = controller.GetEntryCount(); | |
1284 int num_added = 0; | |
1285 int increment_value = is_forward ? 1 : -1; | |
1286 for (int i = controller.GetCurrentEntryIndex() + increment_value; | |
1287 i >= 0 && i < count; | |
1288 i += increment_value) { | |
1289 if (num_added >= max_entries) | |
1290 break; | |
1291 | |
1292 AddNavigationEntryToHistory( | |
1293 env, obj, history, controller.GetEntryAtIndex(i), i); | |
1294 num_added++; | |
1295 } | |
1296 } | |
1297 | |
1298 ScopedJavaLocalRef<jstring> | |
1299 ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env, | |
1300 jobject obj) { | |
1301 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
1302 if (entry == NULL) | |
1303 return ScopedJavaLocalRef<jstring>(env, NULL); | |
1304 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); | |
1305 } | |
1306 | |
1307 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { | 1164 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { |
1308 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1165 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1309 if (!rwhva) | 1166 if (!rwhva) |
1310 return 0; | 1167 return 0; |
1311 return rwhva->GetNativeImeAdapter(); | 1168 return rwhva->GetNativeImeAdapter(); |
1312 } | 1169 } |
1313 | 1170 |
1314 namespace { | 1171 namespace { |
1315 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, | 1172 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, |
1316 const base::Value* result) { | 1173 const base::Value* result) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 return; | 1227 return; |
1371 ViewMsg_PostMessage_Params params; | 1228 ViewMsg_PostMessage_Params params; |
1372 params.source_origin = ConvertJavaStringToUTF16(env, source_origin); | 1229 params.source_origin = ConvertJavaStringToUTF16(env, source_origin); |
1373 params.target_origin = ConvertJavaStringToUTF16(env, target_origin); | 1230 params.target_origin = ConvertJavaStringToUTF16(env, target_origin); |
1374 params.data = ConvertJavaStringToUTF16(env, message); | 1231 params.data = ConvertJavaStringToUTF16(env, message); |
1375 params.is_data_raw_string = true; | 1232 params.is_data_raw_string = true; |
1376 params.source_routing_id = MSG_ROUTING_NONE; | 1233 params.source_routing_id = MSG_ROUTING_NONE; |
1377 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params)); | 1234 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params)); |
1378 } | 1235 } |
1379 | 1236 |
1380 | |
1381 bool ContentViewCoreImpl::GetUseDesktopUserAgent( | |
1382 JNIEnv* env, jobject obj) { | |
1383 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
1384 return entry && entry->GetIsOverridingUserAgent(); | |
1385 } | |
1386 | |
1387 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, | 1237 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, |
1388 int text_input_type, | 1238 int text_input_type, |
1389 const std::string& text, | 1239 const std::string& text, |
1390 int selection_start, | 1240 int selection_start, |
1391 int selection_end, | 1241 int selection_end, |
1392 int composition_start, | 1242 int composition_start, |
1393 int composition_end, | 1243 int composition_end, |
1394 bool show_ime_if_needed, | 1244 bool show_ime_if_needed, |
1395 bool is_non_ime_change) { | 1245 bool is_non_ime_change) { |
1396 JNIEnv* env = AttachCurrentThread(); | 1246 JNIEnv* env = AttachCurrentThread(); |
1397 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1247 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
1398 if (obj.is_null()) | 1248 if (obj.is_null()) |
1399 return; | 1249 return; |
1400 | 1250 |
1401 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); | 1251 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); |
1402 Java_ContentViewCore_updateImeAdapter(env, obj.obj(), | 1252 Java_ContentViewCore_updateImeAdapter(env, obj.obj(), |
1403 native_ime_adapter, text_input_type, | 1253 native_ime_adapter, text_input_type, |
1404 jstring_text.obj(), | 1254 jstring_text.obj(), |
1405 selection_start, selection_end, | 1255 selection_start, selection_end, |
1406 composition_start, composition_end, | 1256 composition_start, composition_end, |
1407 show_ime_if_needed, is_non_ime_change); | 1257 show_ime_if_needed, is_non_ime_change); |
1408 } | 1258 } |
1409 | 1259 |
1410 void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) { | |
1411 SSLHostState* state = SSLHostState::GetFor( | |
1412 web_contents_->GetController().GetBrowserContext()); | |
1413 state->Clear(); | |
1414 } | |
1415 | |
1416 void ContentViewCoreImpl::SetUseDesktopUserAgent( | |
1417 JNIEnv* env, | |
1418 jobject obj, | |
1419 jboolean enabled, | |
1420 jboolean reload_on_state_change) { | |
1421 if (GetUseDesktopUserAgent(env, obj) == enabled) | |
1422 return; | |
1423 | |
1424 // Make sure the navigation entry actually exists. | |
1425 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
1426 if (!entry) | |
1427 return; | |
1428 | |
1429 // Set the flag in the NavigationEntry. | |
1430 entry->SetIsOverridingUserAgent(enabled); | |
1431 | |
1432 // Send the override to the renderer. | |
1433 if (reload_on_state_change) { | |
1434 // Reloading the page will send the override down as part of the | |
1435 // navigation IPC message. | |
1436 NavigationControllerImpl& controller = | |
1437 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | |
1438 controller.ReloadOriginalRequestURL(false); | |
1439 } | |
1440 } | |
1441 | |
1442 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, | 1260 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, |
1443 bool enabled) { | 1261 bool enabled) { |
1444 SetAccessibilityEnabledInternal(enabled); | 1262 SetAccessibilityEnabledInternal(enabled); |
1445 } | 1263 } |
1446 | 1264 |
1447 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { | 1265 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { |
1448 JNIEnv* env = AttachCurrentThread(); | 1266 JNIEnv* env = AttachCurrentThread(); |
1449 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1267 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
1450 if (obj.is_null()) | 1268 if (obj.is_null()) |
1451 return true; | 1269 return true; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1424 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1607 retained_objects_set); | 1425 retained_objects_set); |
1608 return reinterpret_cast<intptr_t>(view); | 1426 return reinterpret_cast<intptr_t>(view); |
1609 } | 1427 } |
1610 | 1428 |
1611 bool RegisterContentViewCore(JNIEnv* env) { | 1429 bool RegisterContentViewCore(JNIEnv* env) { |
1612 return RegisterNativesImpl(env); | 1430 return RegisterNativesImpl(env); |
1613 } | 1431 } |
1614 | 1432 |
1615 } // namespace content | 1433 } // namespace content |
OLD | NEW |