| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
| 50 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
| 51 #include "content/public/common/menu_item.h" | 51 #include "content/public/common/menu_item.h" |
| 52 #include "content/public/common/user_agent.h" | 52 #include "content/public/common/user_agent.h" |
| 53 #include "device/geolocation/geolocation_service_context.h" | 53 #include "device/geolocation/geolocation_service_context.h" |
| 54 #include "jni/ContentViewCore_jni.h" | 54 #include "jni/ContentViewCore_jni.h" |
| 55 #include "jni/DragEvent_jni.h" | 55 #include "jni/DragEvent_jni.h" |
| 56 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 56 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 57 #include "ui/android/view_android.h" | 57 #include "ui/android/view_android.h" |
| 58 #include "ui/android/view_root.h" |
| 58 #include "ui/android/window_android.h" | 59 #include "ui/android/window_android.h" |
| 59 #include "ui/base/clipboard/clipboard.h" | 60 #include "ui/base/clipboard/clipboard.h" |
| 60 #include "ui/base/ui_base_switches_util.h" | 61 #include "ui/base/ui_base_switches_util.h" |
| 61 #include "ui/events/android/motion_event_android.h" | 62 #include "ui/events/android/motion_event_android.h" |
| 62 #include "ui/events/blink/blink_event_util.h" | 63 #include "ui/events/blink/blink_event_util.h" |
| 63 #include "ui/events/blink/web_input_event_traits.h" | 64 #include "ui/events/blink/web_input_event_traits.h" |
| 64 #include "ui/events/event_utils.h" | 65 #include "ui/events/event_utils.h" |
| 65 #include "ui/events/gesture_detection/motion_event.h" | 66 #include "ui/events/gesture_detection/motion_event.h" |
| 66 #include "ui/gfx/android/java_bitmap.h" | 67 #include "ui/gfx/android/java_bitmap.h" |
| 67 #include "ui/gfx/geometry/point_conversions.h" | 68 #include "ui/gfx/geometry/point_conversions.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 WebContents* web_contents, | 224 WebContents* web_contents, |
| 224 float dpi_scale, | 225 float dpi_scale, |
| 225 const JavaRef<jobject>& java_bridge_retained_object_set) | 226 const JavaRef<jobject>& java_bridge_retained_object_set) |
| 226 : WebContentsObserver(web_contents), | 227 : WebContentsObserver(web_contents), |
| 227 java_ref_(env, obj), | 228 java_ref_(env, obj), |
| 228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 229 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 229 page_scale_(1), | 230 page_scale_(1), |
| 230 dpi_scale_(dpi_scale), | 231 dpi_scale_(dpi_scale), |
| 231 device_orientation_(0), | 232 device_orientation_(0), |
| 232 accessibility_enabled_(false) { | 233 accessibility_enabled_(false) { |
| 233 GetViewAndroid()->SetLayer(cc::Layer::Create()); | |
| 234 gfx::Size physical_size( | |
| 235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
| 236 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
| 237 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
| 238 | |
| 239 // Currently, the only use case we have for overriding a user agent involves | 234 // Currently, the only use case we have for overriding a user agent involves |
| 240 // spoofing a desktop Linux user agent for "Request desktop site". | 235 // spoofing a desktop Linux user agent for "Request desktop site". |
| 241 // Automatically set it for all WebContents so that it is available when a | 236 // Automatically set it for all WebContents so that it is available when a |
| 242 // NavigationEntry requires the user agent to be overridden. | 237 // NavigationEntry requires the user agent to be overridden. |
| 243 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 238 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 244 std::string product = content::GetContentClient()->GetProduct(); | 239 std::string product = content::GetContentClient()->GetProduct(); |
| 245 std::string spoofed_ua = | 240 std::string spoofed_ua = |
| 246 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 241 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 247 web_contents->SetUserAgentOverride(spoofed_ua); | 242 web_contents->SetUserAgentOverride(spoofed_ua); |
| 248 | 243 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 270 | 265 |
| 271 JNIEnv* env = base::android::AttachCurrentThread(); | 266 JNIEnv* env = base::android::AttachCurrentThread(); |
| 272 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 267 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 273 java_ref_.reset(); | 268 java_ref_.reset(); |
| 274 if (!j_obj.is_null()) { | 269 if (!j_obj.is_null()) { |
| 275 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 270 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 276 env, j_obj, reinterpret_cast<intptr_t>(this)); | 271 env, j_obj, reinterpret_cast<intptr_t>(this)); |
| 277 } | 272 } |
| 278 } | 273 } |
| 279 | 274 |
| 280 void ContentViewCoreImpl::UpdateWindowAndroid( | 275 void ContentViewCoreImpl::UpdateViewRoot( |
| 281 JNIEnv* env, | 276 JNIEnv* env, |
| 282 const base::android::JavaParamRef<jobject>& obj, | 277 const base::android::JavaParamRef<jobject>& obj, |
| 283 jlong window_android) { | 278 jlong view_root_ptr) { |
| 279 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(view_root_ptr); |
| 284 ui::ViewAndroid* view = GetViewAndroid(); | 280 ui::ViewAndroid* view = GetViewAndroid(); |
| 285 ui::WindowAndroid* window = | 281 if (view_root == view->GetViewRoot()) |
| 286 reinterpret_cast<ui::WindowAndroid*>(window_android); | |
| 287 if (window == GetWindowAndroid()) | |
| 288 return; | 282 return; |
| 289 if (GetWindowAndroid()) { | 283 |
| 284 if (view->GetViewRoot()) { |
| 290 for (auto& observer : observer_list_) | 285 for (auto& observer : observer_list_) |
| 291 observer.OnDetachedFromWindow(); | 286 observer.OnDetachedFromWindow(); |
| 292 view->RemoveFromParent(); | 287 view->RemoveFromParent(); |
| 293 } | 288 } |
| 294 if (window) { | 289 |
| 295 window->AddChild(view); | 290 if (view_root) { |
| 291 view_root->AddChild(view); |
| 296 for (auto& observer : observer_list_) | 292 for (auto& observer : observer_list_) |
| 297 observer.OnAttachedToWindow(); | 293 observer.OnAttachedToWindow(); |
| 298 } | 294 } |
| 299 } | 295 } |
| 300 | 296 |
| 301 base::android::ScopedJavaLocalRef<jobject> | 297 base::android::ScopedJavaLocalRef<jobject> |
| 302 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, | 298 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, |
| 303 const JavaParamRef<jobject>& obj) { | 299 const JavaParamRef<jobject>& obj) { |
| 304 return web_contents_->GetJavaWebContents(); | 300 return web_contents_->GetJavaWebContents(); |
| 305 } | 301 } |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 ConvertJavaStringToUTF8(env, name)); | 1262 ConvertJavaStringToUTF8(env, name)); |
| 1267 } | 1263 } |
| 1268 | 1264 |
| 1269 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1265 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1270 const JavaParamRef<jobject>& obj) { | 1266 const JavaParamRef<jobject>& obj) { |
| 1271 gfx::Size physical_size( | 1267 gfx::Size physical_size( |
| 1272 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1268 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1273 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1269 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1274 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1270 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
| 1275 | 1271 |
| 1272 gfx::Size view_size(GetViewSize()); |
| 1273 GetViewAndroid()->SetBounds(gfx::Point(), |
| 1274 view_size.width(), |
| 1275 view_size.height()); |
| 1276 SendScreenRectsAndResizeWidget(); | 1276 SendScreenRectsAndResizeWidget(); |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 long ContentViewCoreImpl::GetNativeImeAdapter( | 1279 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1280 JNIEnv* env, | 1280 JNIEnv* env, |
| 1281 const JavaParamRef<jobject>& obj) { | 1281 const JavaParamRef<jobject>& obj) { |
| 1282 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1282 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1283 if (!rwhva) | 1283 if (!rwhva) |
| 1284 return 0; | 1284 return 0; |
| 1285 return rwhva->GetNativeImeAdapter(); | 1285 return rwhva->GetNativeImeAdapter(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1437 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 1438 } | 1438 } |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 bool ContentViewCoreImpl::IsTouchDragDropEnabled( | 1441 bool ContentViewCoreImpl::IsTouchDragDropEnabled( |
| 1442 JNIEnv* env, | 1442 JNIEnv* env, |
| 1443 const base::android::JavaParamRef<jobject>& jobj) { | 1443 const base::android::JavaParamRef<jobject>& jobj) { |
| 1444 return switches::IsTouchDragDropEnabled(); | 1444 return switches::IsTouchDragDropEnabled(); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 void ContentViewCoreImpl::MoveToFrontInViewHierarchy( |
| 1448 JNIEnv* env, |
| 1449 const base::android::JavaParamRef<jobject>& jobj) { |
| 1450 ui::ViewAndroid* view_android = GetViewAndroid(); |
| 1451 ui::ViewRoot* view_root = |
| 1452 static_cast<ui::ViewRoot*>(view_android->GetViewRoot()); |
| 1453 view_root->MoveToFront(view_android); |
| 1454 } |
| 1455 |
| 1456 void ContentViewCoreImpl::UpdateViewBounds( |
| 1457 JNIEnv* env, |
| 1458 const base::android::JavaParamRef<jobject>& jobj, |
| 1459 int x, |
| 1460 int y, |
| 1461 int width, |
| 1462 int height) { |
| 1463 ui::ViewAndroid* view_android = GetViewAndroid(); |
| 1464 view_android->SetBounds(gfx::Point(x, y), width, height); |
| 1465 } |
| 1466 |
| 1447 void ContentViewCoreImpl::OnDragEvent( | 1467 void ContentViewCoreImpl::OnDragEvent( |
| 1448 JNIEnv* env, | 1468 JNIEnv* env, |
| 1449 const base::android::JavaParamRef<jobject>& jobj, | 1469 const base::android::JavaParamRef<jobject>& jobj, |
| 1450 jint action, | 1470 jint action, |
| 1451 jint x, | 1471 jint x, |
| 1452 jint y, | 1472 jint y, |
| 1453 jint screen_x, | 1473 jint screen_x, |
| 1454 jint screen_y, | 1474 jint screen_y, |
| 1455 const base::android::JavaParamRef<jobjectArray>& j_mimeTypes, | 1475 const base::android::JavaParamRef<jobjectArray>& j_mimeTypes, |
| 1456 const base::android::JavaParamRef<jstring>& j_content) { | 1476 const base::android::JavaParamRef<jstring>& j_content) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 static_cast<WebContentsImpl*>(web_contents())->GetView()); | 1565 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1546 DCHECK(wcva); | 1566 DCHECK(wcva); |
| 1547 wcva->SetContentViewCore(NULL); | 1567 wcva->SetContentViewCore(NULL); |
| 1548 } | 1568 } |
| 1549 | 1569 |
| 1550 // This is called for each ContentView. | 1570 // This is called for each ContentView. |
| 1551 jlong Init(JNIEnv* env, | 1571 jlong Init(JNIEnv* env, |
| 1552 const JavaParamRef<jobject>& obj, | 1572 const JavaParamRef<jobject>& obj, |
| 1553 const JavaParamRef<jobject>& jweb_contents, | 1573 const JavaParamRef<jobject>& jweb_contents, |
| 1554 const JavaParamRef<jobject>& jview_android_delegate, | 1574 const JavaParamRef<jobject>& jview_android_delegate, |
| 1555 jlong jwindow_android, | 1575 jlong view_root_ptr, |
| 1556 jfloat dipScale, | 1576 jfloat dipScale, |
| 1557 const JavaParamRef<jobject>& retained_objects_set) { | 1577 const JavaParamRef<jobject>& retained_objects_set) { |
| 1558 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1578 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1559 WebContents::FromJavaWebContents(jweb_contents)); | 1579 WebContents::FromJavaWebContents(jweb_contents)); |
| 1560 CHECK(web_contents) << | 1580 CHECK(web_contents) << |
| 1561 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1581 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1562 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1582 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1563 view_android->SetDelegate(jview_android_delegate); | 1583 view_android->SetDelegate(jview_android_delegate); |
| 1584 view_android->SetLayer(cc::Layer::Create()); |
| 1585 gfx::Size physical_size( |
| 1586 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1587 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1588 view_android->GetLayer()->SetBounds(physical_size); |
| 1564 | 1589 |
| 1565 ui::WindowAndroid* window_android = | 1590 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(view_root_ptr); |
| 1566 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1591 view_root->AddChild(view_android); |
| 1567 DCHECK(window_android); | |
| 1568 window_android->AddChild(view_android); | |
| 1569 | 1592 |
| 1570 // TODO: pass dipScale. | 1593 // TODO: pass dipScale. |
| 1571 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1594 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1572 env, obj, web_contents, dipScale, retained_objects_set); | 1595 env, obj, web_contents, dipScale, retained_objects_set); |
| 1573 return reinterpret_cast<intptr_t>(view); | 1596 return reinterpret_cast<intptr_t>(view); |
| 1574 } | 1597 } |
| 1575 | 1598 |
| 1576 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1599 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1577 JNIEnv* env, | 1600 JNIEnv* env, |
| 1578 const JavaParamRef<jclass>& clazz, | 1601 const JavaParamRef<jclass>& clazz, |
| 1579 const JavaParamRef<jobject>& jweb_contents) { | 1602 const JavaParamRef<jobject>& jweb_contents) { |
| 1580 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1603 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1581 if (!web_contents) | 1604 if (!web_contents) |
| 1582 return ScopedJavaLocalRef<jobject>(); | 1605 return ScopedJavaLocalRef<jobject>(); |
| 1583 | 1606 |
| 1584 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1607 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1585 if (!view) | 1608 if (!view) |
| 1586 return ScopedJavaLocalRef<jobject>(); | 1609 return ScopedJavaLocalRef<jobject>(); |
| 1587 | 1610 |
| 1588 return view->GetJavaObject(); | 1611 return view->GetJavaObject(); |
| 1589 } | 1612 } |
| 1590 | 1613 |
| 1591 bool RegisterContentViewCore(JNIEnv* env) { | 1614 bool RegisterContentViewCore(JNIEnv* env) { |
| 1592 return RegisterNativesImpl(env); | 1615 return RegisterNativesImpl(env); |
| 1593 } | 1616 } |
| 1594 | 1617 |
| 1595 } // namespace content | 1618 } // namespace content |
| OLD | NEW |