| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 48 #include "content/public/common/content_client.h" | 48 #include "content/public/common/content_client.h" |
| 49 #include "content/public/common/content_switches.h" | 49 #include "content/public/common/content_switches.h" |
| 50 #include "content/public/common/menu_item.h" | 50 #include "content/public/common/menu_item.h" |
| 51 #include "content/public/common/user_agent.h" | 51 #include "content/public/common/user_agent.h" |
| 52 #include "device/geolocation/geolocation_service_context.h" | 52 #include "device/geolocation/geolocation_service_context.h" |
| 53 #include "jni/ContentViewCore_jni.h" | 53 #include "jni/ContentViewCore_jni.h" |
| 54 #include "jni/DragEvent_jni.h" | 54 #include "jni/DragEvent_jni.h" |
| 55 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 55 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 56 #include "ui/android/view_android.h" | 56 #include "ui/android/view_android.h" |
| 57 #include "ui/android/view_root.h" |
| 57 #include "ui/android/window_android.h" | 58 #include "ui/android/window_android.h" |
| 58 #include "ui/base/clipboard/clipboard.h" | 59 #include "ui/base/clipboard/clipboard.h" |
| 59 #include "ui/base/ui_base_switches_util.h" | 60 #include "ui/base/ui_base_switches_util.h" |
| 60 #include "ui/events/android/motion_event_android.h" | 61 #include "ui/events/android/motion_event_android.h" |
| 61 #include "ui/events/blink/blink_event_util.h" | 62 #include "ui/events/blink/blink_event_util.h" |
| 62 #include "ui/events/blink/web_input_event_traits.h" | 63 #include "ui/events/blink/web_input_event_traits.h" |
| 63 #include "ui/events/event_utils.h" | 64 #include "ui/events/event_utils.h" |
| 64 #include "ui/events/gesture_detection/motion_event.h" | 65 #include "ui/events/gesture_detection/motion_event.h" |
| 65 #include "ui/gfx/android/java_bitmap.h" | 66 #include "ui/gfx/android/java_bitmap.h" |
| 66 #include "ui/gfx/geometry/point_conversions.h" | 67 #include "ui/gfx/geometry/point_conversions.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 WebContents* web_contents, | 223 WebContents* web_contents, |
| 223 float dpi_scale, | 224 float dpi_scale, |
| 224 const JavaRef<jobject>& java_bridge_retained_object_set) | 225 const JavaRef<jobject>& java_bridge_retained_object_set) |
| 225 : WebContentsObserver(web_contents), | 226 : WebContentsObserver(web_contents), |
| 226 java_ref_(env, obj), | 227 java_ref_(env, obj), |
| 227 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 228 page_scale_(1), | 229 page_scale_(1), |
| 229 dpi_scale_(dpi_scale), | 230 dpi_scale_(dpi_scale), |
| 230 device_orientation_(0), | 231 device_orientation_(0), |
| 231 accessibility_enabled_(false) { | 232 accessibility_enabled_(false) { |
| 232 GetViewAndroid()->SetLayer(cc::Layer::Create()); | |
| 233 gfx::Size physical_size( | |
| 234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
| 235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
| 236 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
| 237 | |
| 238 // Currently, the only use case we have for overriding a user agent involves | 233 // Currently, the only use case we have for overriding a user agent involves |
| 239 // spoofing a desktop Linux user agent for "Request desktop site". | 234 // spoofing a desktop Linux user agent for "Request desktop site". |
| 240 // Automatically set it for all WebContents so that it is available when a | 235 // Automatically set it for all WebContents so that it is available when a |
| 241 // NavigationEntry requires the user agent to be overridden. | 236 // NavigationEntry requires the user agent to be overridden. |
| 242 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 237 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 243 std::string product = content::GetContentClient()->GetProduct(); | 238 std::string product = content::GetContentClient()->GetProduct(); |
| 244 std::string spoofed_ua = | 239 std::string spoofed_ua = |
| 245 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 240 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 246 web_contents->SetUserAgentOverride(spoofed_ua); | 241 web_contents->SetUserAgentOverride(spoofed_ua); |
| 247 | 242 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 269 | 264 |
| 270 JNIEnv* env = base::android::AttachCurrentThread(); | 265 JNIEnv* env = base::android::AttachCurrentThread(); |
| 271 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 266 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 272 java_ref_.reset(); | 267 java_ref_.reset(); |
| 273 if (!j_obj.is_null()) { | 268 if (!j_obj.is_null()) { |
| 274 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 269 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 275 env, j_obj, reinterpret_cast<intptr_t>(this)); | 270 env, j_obj, reinterpret_cast<intptr_t>(this)); |
| 276 } | 271 } |
| 277 } | 272 } |
| 278 | 273 |
| 279 void ContentViewCoreImpl::UpdateWindowAndroid( | 274 void ContentViewCoreImpl::UpdateViewRoot( |
| 280 JNIEnv* env, | 275 JNIEnv* env, |
| 281 const base::android::JavaParamRef<jobject>& obj, | 276 const base::android::JavaParamRef<jobject>& obj, |
| 282 jlong window_android) { | 277 jlong view_root_ptr) { |
| 278 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(view_root_ptr); |
| 283 ui::ViewAndroid* view = GetViewAndroid(); | 279 ui::ViewAndroid* view = GetViewAndroid(); |
| 284 ui::WindowAndroid* window = | 280 if (view_root == view->GetViewRoot()) |
| 285 reinterpret_cast<ui::WindowAndroid*>(window_android); | |
| 286 if (window == GetWindowAndroid()) | |
| 287 return; | 281 return; |
| 288 if (GetWindowAndroid()) { | 282 if (view->GetViewRoot()) { |
| 289 for (auto& observer : observer_list_) | 283 for (auto& observer : observer_list_) |
| 290 observer.OnDetachedFromWindow(); | 284 observer.OnDetachedFromWindow(); |
| 291 view->RemoveFromParent(); | 285 view->RemoveFromParent(); |
| 292 } | 286 } |
| 293 if (window) { | 287 if (view_root) { |
| 294 window->AddChild(view); | 288 view_root->AddChild(view); |
| 295 for (auto& observer : observer_list_) | 289 for (auto& observer : observer_list_) |
| 296 observer.OnAttachedToWindow(); | 290 observer.OnAttachedToWindow(); |
| 297 } | 291 } |
| 298 } | 292 } |
| 299 | 293 |
| 300 base::android::ScopedJavaLocalRef<jobject> | 294 base::android::ScopedJavaLocalRef<jobject> |
| 301 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, | 295 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, |
| 302 const JavaParamRef<jobject>& obj) { | 296 const JavaParamRef<jobject>& obj) { |
| 303 return web_contents_->GetJavaWebContents(); | 297 return web_contents_->GetJavaWebContents(); |
| 304 } | 298 } |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 ConvertJavaStringToUTF8(env, name)); | 1236 ConvertJavaStringToUTF8(env, name)); |
| 1243 } | 1237 } |
| 1244 | 1238 |
| 1245 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1239 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1246 const JavaParamRef<jobject>& obj) { | 1240 const JavaParamRef<jobject>& obj) { |
| 1247 gfx::Size physical_size( | 1241 gfx::Size physical_size( |
| 1248 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1242 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1249 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1243 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1250 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1244 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
| 1251 | 1245 |
| 1246 gfx::Size view_size(GetViewSize()); |
| 1247 GetViewAndroid()->SetLayout(0, 0, view_size.width(), view_size.height(), |
| 1248 false); |
| 1249 |
| 1252 SendScreenRectsAndResizeWidget(); | 1250 SendScreenRectsAndResizeWidget(); |
| 1253 } | 1251 } |
| 1254 | 1252 |
| 1255 long ContentViewCoreImpl::GetNativeImeAdapter( | 1253 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1256 JNIEnv* env, | 1254 JNIEnv* env, |
| 1257 const JavaParamRef<jobject>& obj) { | 1255 const JavaParamRef<jobject>& obj) { |
| 1258 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1256 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1259 if (!rwhva) | 1257 if (!rwhva) |
| 1260 return 0; | 1258 return 0; |
| 1261 return rwhva->GetNativeImeAdapter(); | 1259 return rwhva->GetNativeImeAdapter(); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1487 static_cast<WebContentsImpl*>(web_contents())->GetView()); | 1485 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1488 DCHECK(wcva); | 1486 DCHECK(wcva); |
| 1489 wcva->SetContentViewCore(NULL); | 1487 wcva->SetContentViewCore(NULL); |
| 1490 } | 1488 } |
| 1491 | 1489 |
| 1492 // This is called for each ContentView. | 1490 // This is called for each ContentView. |
| 1493 jlong Init(JNIEnv* env, | 1491 jlong Init(JNIEnv* env, |
| 1494 const JavaParamRef<jobject>& obj, | 1492 const JavaParamRef<jobject>& obj, |
| 1495 const JavaParamRef<jobject>& jweb_contents, | 1493 const JavaParamRef<jobject>& jweb_contents, |
| 1496 const JavaParamRef<jobject>& jview_android_delegate, | 1494 const JavaParamRef<jobject>& jview_android_delegate, |
| 1497 jlong jwindow_android, | 1495 jlong jview_root_ptr, |
| 1498 jfloat dipScale, | 1496 jfloat dipScale, |
| 1499 const JavaParamRef<jobject>& retained_objects_set) { | 1497 const JavaParamRef<jobject>& retained_objects_set) { |
| 1500 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1498 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1501 WebContents::FromJavaWebContents(jweb_contents)); | 1499 WebContents::FromJavaWebContents(jweb_contents)); |
| 1502 CHECK(web_contents) << | 1500 CHECK(web_contents) << |
| 1503 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1501 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1504 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1502 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1505 view_android->SetDelegate(jview_android_delegate); | 1503 view_android->SetDelegate(jview_android_delegate); |
| 1504 view_android->SetLayer(cc::Layer::Create()); |
| 1505 gfx::Size physical_size( |
| 1506 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1507 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1508 view_android->GetLayer()->SetBounds(physical_size); |
| 1506 | 1509 |
| 1507 ui::WindowAndroid* window_android = | 1510 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(jview_root_ptr); |
| 1508 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1511 DCHECK(view_root->GetWindowAndroid()); |
| 1509 DCHECK(window_android); | 1512 view_root->AddChild(view_android); |
| 1510 window_android->AddChild(view_android); | |
| 1511 | 1513 |
| 1512 // TODO: pass dipScale. | 1514 // TODO: pass dipScale. |
| 1513 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1515 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1514 env, obj, web_contents, dipScale, retained_objects_set); | 1516 env, obj, web_contents, dipScale, retained_objects_set); |
| 1515 return reinterpret_cast<intptr_t>(view); | 1517 return reinterpret_cast<intptr_t>(view); |
| 1516 } | 1518 } |
| 1517 | 1519 |
| 1518 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1520 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1519 JNIEnv* env, | 1521 JNIEnv* env, |
| 1520 const JavaParamRef<jclass>& clazz, | 1522 const JavaParamRef<jclass>& clazz, |
| 1521 const JavaParamRef<jobject>& jweb_contents) { | 1523 const JavaParamRef<jobject>& jweb_contents) { |
| 1522 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1524 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1523 if (!web_contents) | 1525 if (!web_contents) |
| 1524 return ScopedJavaLocalRef<jobject>(); | 1526 return ScopedJavaLocalRef<jobject>(); |
| 1525 | 1527 |
| 1526 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1528 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1527 if (!view) | 1529 if (!view) |
| 1528 return ScopedJavaLocalRef<jobject>(); | 1530 return ScopedJavaLocalRef<jobject>(); |
| 1529 | 1531 |
| 1530 return view->GetJavaObject(); | 1532 return view->GetJavaObject(); |
| 1531 } | 1533 } |
| 1532 | 1534 |
| 1533 bool RegisterContentViewCore(JNIEnv* env) { | 1535 bool RegisterContentViewCore(JNIEnv* env) { |
| 1534 return RegisterNativesImpl(env); | 1536 return RegisterNativesImpl(env); |
| 1535 } | 1537 } |
| 1536 | 1538 |
| 1537 } // namespace content | 1539 } // namespace content |
| OLD | NEW |