| 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/java_bound_object.h" | 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" |
| 23 #include "content/browser/android/java/java_bridge_dispatcher_host_manager.h" | |
| 24 #include "content/browser/android/load_url_params.h" | 23 #include "content/browser/android/load_url_params.h" |
| 25 #include "content/browser/frame_host/interstitial_page_impl.h" | 24 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 26 #include "content/browser/frame_host/navigation_controller_impl.h" | 25 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 27 #include "content/browser/frame_host/navigation_entry_impl.h" | 26 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 28 #include "content/browser/geolocation/geolocation_dispatcher_host.h" | 27 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
| 29 #include "content/browser/media/media_web_contents_observer.h" | 28 #include "content/browser/media/media_web_contents_observer.h" |
| 30 #include "content/browser/renderer_host/compositor_impl_android.h" | 29 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 31 #include "content/browser/renderer_host/input/motion_event_android.h" | 30 #include "content/browser/renderer_host/input/motion_event_android.h" |
| 32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 31 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
| 33 #include "content/browser/renderer_host/input/web_input_event_util.h" | 32 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1190 |
| 1193 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | 1191 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( |
| 1194 web_contents_->GetMainFrame()->GetRoutingID(), | 1192 web_contents_->GetMainFrame()->GetRoutingID(), |
| 1195 ConvertJavaStringToUTF8(env, url))); | 1193 ConvertJavaStringToUTF8(env, url))); |
| 1196 } | 1194 } |
| 1197 | 1195 |
| 1198 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1196 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
| 1199 JNIEnv* env, | 1197 JNIEnv* env, |
| 1200 jobject obj, | 1198 jobject obj, |
| 1201 jboolean allow) { | 1199 jboolean allow) { |
| 1202 java_bridge_dispatcher_host_manager_->SetAllowObjectContentsInspection(allow); | 1200 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); |
| 1203 } | 1201 } |
| 1204 | 1202 |
| 1205 void ContentViewCoreImpl::AddJavascriptInterface( | 1203 void ContentViewCoreImpl::AddJavascriptInterface( |
| 1206 JNIEnv* env, | 1204 JNIEnv* env, |
| 1207 jobject /* obj */, | 1205 jobject /* obj */, |
| 1208 jobject object, | 1206 jobject object, |
| 1209 jstring name, | 1207 jstring name, |
| 1210 jclass safe_annotation_clazz) { | 1208 jclass safe_annotation_clazz) { |
| 1211 ScopedJavaLocalRef<jobject> scoped_object(env, object); | 1209 ScopedJavaLocalRef<jobject> scoped_object(env, object); |
| 1212 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); | 1210 ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); |
| 1213 | 1211 java_bridge_dispatcher_host_->AddNamedObject( |
| 1214 // JavaBoundObject creates the NPObject with a ref count of 1, and | 1212 ConvertJavaStringToUTF8(env, name), scoped_object, scoped_clazz); |
| 1215 // JavaBridgeDispatcherHostManager takes its own ref. | |
| 1216 NPObject* bound_object = JavaBoundObject::Create( | |
| 1217 scoped_object, | |
| 1218 scoped_clazz, | |
| 1219 java_bridge_dispatcher_host_manager_->AsWeakPtr(), | |
| 1220 java_bridge_dispatcher_host_manager_->GetAllowObjectContentsInspection()); | |
| 1221 java_bridge_dispatcher_host_manager_->AddNamedObject( | |
| 1222 ConvertJavaStringToUTF16(env, name), bound_object); | |
| 1223 blink::WebBindings::releaseObject(bound_object); | |
| 1224 } | 1213 } |
| 1225 | 1214 |
| 1226 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1215 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
| 1227 jobject /* obj */, | 1216 jobject /* obj */, |
| 1228 jstring name) { | 1217 jstring name) { |
| 1229 java_bridge_dispatcher_host_manager_->RemoveNamedObject( | 1218 java_bridge_dispatcher_host_->RemoveNamedObject( |
| 1230 ConvertJavaStringToUTF16(env, name)); | 1219 ConvertJavaStringToUTF8(env, name)); |
| 1231 } | 1220 } |
| 1232 | 1221 |
| 1233 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1222 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
| 1234 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1223 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1235 gfx::Size physical_size( | 1224 gfx::Size physical_size( |
| 1236 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1225 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1237 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1226 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1238 root_layer_->SetBounds(physical_size); | 1227 root_layer_->SetBounds(physical_size); |
| 1239 | 1228 |
| 1240 if (view) { | 1229 if (view) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1657 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1669 retained_objects_set); | 1658 retained_objects_set); |
| 1670 return reinterpret_cast<intptr_t>(view); | 1659 return reinterpret_cast<intptr_t>(view); |
| 1671 } | 1660 } |
| 1672 | 1661 |
| 1673 bool RegisterContentViewCore(JNIEnv* env) { | 1662 bool RegisterContentViewCore(JNIEnv* env) { |
| 1674 return RegisterNativesImpl(env); | 1663 return RegisterNativesImpl(env); |
| 1675 } | 1664 } |
| 1676 | 1665 |
| 1677 } // namespace content | 1666 } // namespace content |
| OLD | NEW |