| 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 11 matching lines...) Expand all Loading... |
| 22 #include "content/browser/android/load_url_params.h" | 22 #include "content/browser/android/load_url_params.h" |
| 23 #include "content/browser/frame_host/interstitial_page_impl.h" | 23 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 24 #include "content/browser/frame_host/navigation_controller_impl.h" | 24 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 25 #include "content/browser/frame_host/navigation_entry_impl.h" | 25 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 26 #include "content/browser/geolocation/geolocation_dispatcher_host.h" | 26 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
| 27 #include "content/browser/media/media_web_contents_observer.h" | 27 #include "content/browser/media/media_web_contents_observer.h" |
| 28 #include "content/browser/renderer_host/compositor_impl_android.h" | 28 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 29 #include "content/browser/renderer_host/input/motion_event_android.h" | 29 #include "content/browser/renderer_host/input/motion_event_android.h" |
| 30 #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
" |
| 31 #include "content/browser/renderer_host/input/web_input_event_util.h" | 31 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 32 #include "content/browser/renderer_host/java/java_bound_object.h" | 32 #include "content/browser/renderer_host/java/gin_java_bridge_dispatcher_host.h" |
| 33 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" | |
| 34 #include "content/browser/renderer_host/render_view_host_impl.h" | 33 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 35 #include "content/browser/renderer_host/render_widget_host_impl.h" | 34 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 36 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 35 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 36 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" |
| 38 #include "content/browser/ssl/ssl_host_state.h" | 37 #include "content/browser/ssl/ssl_host_state.h" |
| 39 #include "content/browser/transition_request_manager.h" | 38 #include "content/browser/transition_request_manager.h" |
| 40 #include "content/browser/web_contents/web_contents_view_android.h" | 39 #include "content/browser/web_contents/web_contents_view_android.h" |
| 41 #include "content/common/frame_messages.h" | 40 #include "content/common/frame_messages.h" |
| 42 #include "content/common/input/web_input_event_traits.h" | 41 #include "content/common/input/web_input_event_traits.h" |
| 43 #include "content/common/input_messages.h" | 42 #include "content/common/input_messages.h" |
| 44 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
| 45 #include "content/public/browser/browser_accessibility_state.h" | 44 #include "content/public/browser/browser_accessibility_state.h" |
| 46 #include "content/public/browser/browser_context.h" | 45 #include "content/public/browser/browser_context.h" |
| 47 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/favicon_status.h" | 47 #include "content/public/browser/favicon_status.h" |
| 49 #include "content/public/browser/render_frame_host.h" | 48 #include "content/public/browser/render_frame_host.h" |
| 50 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 51 #include "content/public/common/content_client.h" | 50 #include "content/public/common/content_client.h" |
| 52 #include "content/public/common/content_switches.h" | 51 #include "content/public/common/content_switches.h" |
| 53 #include "content/public/common/menu_item.h" | 52 #include "content/public/common/menu_item.h" |
| 54 #include "content/public/common/page_transition_types.h" | 53 #include "content/public/common/page_transition_types.h" |
| 55 #include "content/public/common/user_agent.h" | 54 #include "content/public/common/user_agent.h" |
| 56 #include "jni/ContentViewCore_jni.h" | 55 #include "jni/ContentViewCore_jni.h" |
| 57 #include "third_party/WebKit/public/web/WebBindings.h" | |
| 58 #include "third_party/WebKit/public/web/WebInputEvent.h" | 56 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 59 #include "ui/base/android/view_android.h" | 57 #include "ui/base/android/view_android.h" |
| 60 #include "ui/base/android/window_android.h" | 58 #include "ui/base/android/window_android.h" |
| 61 #include "ui/gfx/android/java_bitmap.h" | 59 #include "ui/gfx/android/java_bitmap.h" |
| 62 #include "ui/gfx/screen.h" | 60 #include "ui/gfx/screen.h" |
| 63 #include "ui/gfx/size_conversions.h" | 61 #include "ui/gfx/size_conversions.h" |
| 64 #include "ui/gfx/size_f.h" | 62 #include "ui/gfx/size_f.h" |
| 65 | 63 |
| 66 using base::android::AttachCurrentThread; | 64 using base::android::AttachCurrentThread; |
| 67 using base::android::ConvertJavaStringToUTF16; | 65 using base::android::ConvertJavaStringToUTF16; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Currently, the only use case we have for overriding a user agent involves | 237 // Currently, the only use case we have for overriding a user agent involves |
| 240 // spoofing a desktop Linux user agent for "Request desktop site". | 238 // spoofing a desktop Linux user agent for "Request desktop site". |
| 241 // Automatically set it for all WebContents so that it is available when a | 239 // Automatically set it for all WebContents so that it is available when a |
| 242 // NavigationEntry requires the user agent to be overridden. | 240 // NavigationEntry requires the user agent to be overridden. |
| 243 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 241 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 244 std::string product = content::GetContentClient()->GetProduct(); | 242 std::string product = content::GetContentClient()->GetProduct(); |
| 245 std::string spoofed_ua = | 243 std::string spoofed_ua = |
| 246 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 244 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 247 web_contents->SetUserAgentOverride(spoofed_ua); | 245 web_contents->SetUserAgentOverride(spoofed_ua); |
| 248 | 246 |
| 249 java_bridge_dispatcher_host_manager_.reset( | 247 java_bridge_dispatcher_host_.reset( |
| 250 new JavaBridgeDispatcherHostManager(web_contents, | 248 new GinJavaBridgeDispatcherHost(web_contents, |
| 251 java_bridge_retained_object_set)); | 249 java_bridge_retained_object_set)); |
| 252 | 250 |
| 253 InitWebContents(); | 251 InitWebContents(); |
| 254 } | 252 } |
| 255 | 253 |
| 256 ContentViewCoreImpl::~ContentViewCoreImpl() { | 254 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 257 JNIEnv* env = base::android::AttachCurrentThread(); | 255 JNIEnv* env = base::android::AttachCurrentThread(); |
| 258 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 256 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 259 java_ref_.reset(); | 257 java_ref_.reset(); |
| 260 if (!j_obj.is_null()) { | 258 if (!j_obj.is_null()) { |
| 261 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 259 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 | 1221 |
| 1224 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | 1222 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( |
| 1225 web_contents_->GetMainFrame()->GetRoutingID(), | 1223 web_contents_->GetMainFrame()->GetRoutingID(), |
| 1226 ConvertJavaStringToUTF8(env, url))); | 1224 ConvertJavaStringToUTF8(env, url))); |
| 1227 } | 1225 } |
| 1228 | 1226 |
| 1229 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1227 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
| 1230 JNIEnv* env, | 1228 JNIEnv* env, |
| 1231 jobject obj, | 1229 jobject obj, |
| 1232 jboolean allow) { | 1230 jboolean allow) { |
| 1233 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow); | 1231 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); |
| 1234 } | 1232 } |
| 1235 | 1233 |
| 1236 void ContentViewCoreImpl::AddJavascriptInterface( | 1234 void ContentViewCoreImpl::AddJavascriptInterface( |
| 1237 JNIEnv* env, | 1235 JNIEnv* env, |
| 1238 jobject /* obj */, | 1236 jobject /* obj */, |
| 1239 jobject object, | 1237 jobject object, |
| 1240 jstring name, | 1238 jstring name, |
| 1241 jclass safe_annotation_clazz) { | 1239 jclass safe_annotation_clazz) { |
| 1242 ScopedJavaLocalRef<jobject> scoped_object(env, object); | 1240 ScopedJavaLocalRef<jobject> scoped_object(env, object); |
| 1243 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); | 1241 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); |
| 1244 | 1242 java_bridge_dispatcher_host_->AddNamedObject( |
| 1245 // JavaBoundObject creates the NPObject with a ref count of 1, and | 1243 ConvertJavaStringToUTF8(env, name), scoped_object, scoped_clazz); |
| 1246 // JavaBridgeDispatcherHostManager takes its own ref. | |
| 1247 NPObject* bound_object = JavaBoundObject::Create( | |
| 1248 scoped_object, | |
| 1249 scoped_clazz, | |
| 1250 java_bridge_dispatcher_host_manager_->AsWeakPtr(), | |
| 1251 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection()); | |
| 1252 java_bridge_dispatcher_host_manager_->AddNamedObject( | |
| 1253 ConvertJavaStringToUTF16(env, name), bound_object); | |
| 1254 blink::WebBindings::releaseObject(bound_object); | |
| 1255 } | 1244 } |
| 1256 | 1245 |
| 1257 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1246 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
| 1258 jobject /* obj */, | 1247 jobject /* obj */, |
| 1259 jstring name) { | 1248 jstring name) { |
| 1260 java_bridge_dispatcher_host_manager_->RemoveNamedObject( | 1249 java_bridge_dispatcher_host_->RemoveNamedObject( |
| 1261 ConvertJavaStringToUTF16(env, name)); | 1250 ConvertJavaStringToUTF8(env, name)); |
| 1262 } | 1251 } |
| 1263 | 1252 |
| 1264 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1253 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
| 1265 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1254 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1266 gfx::Size physical_size( | 1255 gfx::Size physical_size( |
| 1267 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1256 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1268 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1257 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1269 root_layer_->SetBounds(physical_size); | 1258 root_layer_->SetBounds(physical_size); |
| 1270 | 1259 |
| 1271 if (view) { | 1260 if (view) { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1679 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1691 retained_objects_set); | 1680 retained_objects_set); |
| 1692 return reinterpret_cast<intptr_t>(view); | 1681 return reinterpret_cast<intptr_t>(view); |
| 1693 } | 1682 } |
| 1694 | 1683 |
| 1695 bool RegisterContentViewCore(JNIEnv* env) { | 1684 bool RegisterContentViewCore(JNIEnv* env) { |
| 1696 return RegisterNativesImpl(env); | 1685 return RegisterNativesImpl(env); |
| 1697 } | 1686 } |
| 1698 | 1687 |
| 1699 } // namespace content | 1688 } // namespace content |
| OLD | NEW |