Chromium Code Reviews| 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" | |
| 11 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 12 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
| 18 #include "cc/output/begin_frame_args.h" | 17 #include "cc/output/begin_frame_args.h" |
| 19 #include "content/browser/android/gesture_event_type.h" | 18 #include "content/browser/android/gesture_event_type.h" |
| 20 #include "content/browser/android/interstitial_page_delegate_android.h" | 19 #include "content/browser/android/interstitial_page_delegate_android.h" |
| 21 #include "content/browser/android/load_url_params.h" | 20 #include "content/browser/android/load_url_params.h" |
| 22 #include "content/browser/frame_host/interstitial_page_impl.h" | 21 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 23 #include "content/browser/frame_host/navigation_controller_impl.h" | 22 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 24 #include "content/browser/frame_host/navigation_entry_impl.h" | 23 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 25 #include "content/browser/media/android/browser_media_player_manager.h" | 24 #include "content/browser/media/android/browser_media_player_manager.h" |
| 26 #include "content/browser/renderer_host/compositor_impl_android.h" | 25 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 26 #include "content/browser/renderer_host/dip_util.h" | |
| 27 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " | 27 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " |
| 28 #include "content/browser/renderer_host/java/java_bound_object.h" | 28 #include "content/browser/renderer_host/java/java_bound_object.h" |
| 29 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" | 29 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" |
| 30 #include "content/browser/renderer_host/render_view_host_impl.h" | 30 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_impl.h" | 31 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 32 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 32 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 33 #include "content/browser/ssl/ssl_host_state.h" | 33 #include "content/browser/ssl/ssl_host_state.h" |
| 34 #include "content/browser/web_contents/web_contents_view_android.h" | 34 #include "content/browser/web_contents/web_contents_view_android.h" |
| 35 #include "content/common/input/web_input_event_traits.h" | 35 #include "content/common/input/web_input_event_traits.h" |
| 36 #include "content/common/input_messages.h" | 36 #include "content/common/input_messages.h" |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 } | 450 } |
| 451 | 451 |
| 452 void ContentViewCoreImpl::OnTabCrashed() { | 452 void ContentViewCoreImpl::OnTabCrashed() { |
| 453 JNIEnv* env = AttachCurrentThread(); | 453 JNIEnv* env = AttachCurrentThread(); |
| 454 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 454 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 455 if (obj.is_null()) | 455 if (obj.is_null()) |
| 456 return; | 456 return; |
| 457 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | 457 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void ContentViewCoreImpl::OnBitmapReady(bool result, const SkBitmap& bitmap) { | |
| 461 JNIEnv* env = AttachCurrentThread(); | |
| 462 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 463 if (obj.is_null()) | |
| 464 return; | |
| 465 java_bitmap_.reset(NULL); | |
| 466 Java_ContentViewCore_onBitmapReady(env, obj.obj(), | |
| 467 result, | |
| 468 jbitmap_.Release()); | |
| 469 } | |
| 470 | |
| 460 // All positions and sizes are in CSS pixels. | 471 // All positions and sizes are in CSS pixels. |
| 461 // Note that viewport_width/height is a best effort based. | 472 // Note that viewport_width/height is a best effort based. |
| 462 // ContentViewCore has the actual information about the physical viewport size. | 473 // ContentViewCore has the actual information about the physical viewport size. |
| 463 void ContentViewCoreImpl::UpdateFrameInfo( | 474 void ContentViewCoreImpl::UpdateFrameInfo( |
| 464 const gfx::Vector2dF& scroll_offset, | 475 const gfx::Vector2dF& scroll_offset, |
| 465 float page_scale_factor, | 476 float page_scale_factor, |
| 466 const gfx::Vector2dF& page_scale_factor_limits, | 477 const gfx::Vector2dF& page_scale_factor_limits, |
| 467 const gfx::SizeF& content_size, | 478 const gfx::SizeF& content_size, |
| 468 const gfx::SizeF& viewport_size, | 479 const gfx::SizeF& viewport_size, |
| 469 const gfx::Vector2dF& controls_offset, | 480 const gfx::Vector2dF& controls_offset, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 POPUP_ITEM_TYPE_DISABLED)); | 574 POPUP_ITEM_TYPE_DISABLED)); |
| 564 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 575 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
| 565 } | 576 } |
| 566 ScopedJavaLocalRef<jobjectArray> items_array( | 577 ScopedJavaLocalRef<jobjectArray> items_array( |
| 567 base::android::ToJavaArrayOfStrings(env, labels)); | 578 base::android::ToJavaArrayOfStrings(env, labels)); |
| 568 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 579 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
| 569 items_array.obj(), enabled_array.obj(), | 580 items_array.obj(), enabled_array.obj(), |
| 570 multiple, selected_array.obj()); | 581 multiple, selected_array.obj()); |
| 571 } | 582 } |
| 572 | 583 |
| 584 void ContentViewCoreImpl::ProxyBitmapAllocator(SkBitmap*& bitmap, | |
| 585 const gfx::Size& computed_size, | |
| 586 SkBitmap::Config bitmap_config) | |
| 587 { | |
| 588 const gfx::Display& display = | |
| 589 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 590 float device_scale_factor = display.device_scale_factor(); | |
| 591 gfx::Size dst_size_in_pixel = | |
| 592 ConvertRectToPixel(device_scale_factor, gfx::Rect(computed_size)).size(); | |
| 593 | |
| 594 base::android::ScopedJavaLocalRef<jobject> new_bitmap = | |
| 595 gfx::CreateJavaBitmap(dst_size_in_pixel.width(), | |
| 596 dst_size_in_pixel.height(), | |
| 597 (bitmap_config == SkBitmap::kRGB_565_Config)); | |
| 598 jbitmap_.Reset(AttachCurrentThread(), new_bitmap.obj()); | |
| 599 java_bitmap_.reset(new gfx::JavaBitmap(jbitmap_.obj())); | |
| 600 | |
| 601 bitmap = new SkBitmap(); | |
| 602 bitmap->setConfig(bitmap_config, dst_size_in_pixel.width() , | |
| 603 dst_size_in_pixel.height()); | |
| 604 bitmap->setPixels(java_bitmap_->pixels()); | |
| 605 } | |
| 606 | |
| 573 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 607 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 574 touch_disposition_gesture_filter_.OnTouchEventAck(ack_result); | 608 touch_disposition_gesture_filter_.OnTouchEventAck(ack_result); |
| 575 } | 609 } |
| 576 | 610 |
| 577 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 611 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
| 578 InputEventAckState ack_result) { | 612 InputEventAckState ack_result) { |
| 579 JNIEnv* env = AttachCurrentThread(); | 613 JNIEnv* env = AttachCurrentThread(); |
| 580 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 614 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 581 if (j_obj.is_null()) | 615 if (j_obj.is_null()) |
| 582 return; | 616 return; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 725 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 692 if (obj.is_null()) | 726 if (obj.is_null()) |
| 693 return; | 727 return; |
| 694 Java_ContentViewCore_showPastePopup(env, obj.obj(), | 728 Java_ContentViewCore_showPastePopup(env, obj.obj(), |
| 695 static_cast<jint>(x_dip), | 729 static_cast<jint>(x_dip), |
| 696 static_cast<jint>(y_dip)); | 730 static_cast<jint>(y_dip)); |
| 697 } | 731 } |
| 698 | 732 |
| 699 void ContentViewCoreImpl::GetScaledContentBitmap( | 733 void ContentViewCoreImpl::GetScaledContentBitmap( |
| 700 float scale, | 734 float scale, |
| 701 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { | 735 const base::Callback<void(bool, const SkBitmap&)>& result_callback, |
| 736 SkBitmap::Config bitmap_config, | |
| 737 const gfx::Rect& bounding_rect, | |
| 738 const BitmapAllocator bitmap_allocator) { | |
| 702 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 739 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 703 if (!view) { | 740 if (!view) { |
| 704 result_callback.Run(false, SkBitmap()); | 741 result_callback.Run(false, SkBitmap()); |
| 705 return; | 742 return; |
| 706 } | 743 } |
| 707 | 744 |
| 708 view->GetScaledContentBitmap(scale, result_callback); | 745 view->GetScaledContentBitmap(scale, result_callback, |
| 746 bitmap_config, bounding_rect, bitmap_allocator); | |
| 709 } | 747 } |
| 710 | 748 |
| 711 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 749 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
| 712 JNIEnv* env = AttachCurrentThread(); | 750 JNIEnv* env = AttachCurrentThread(); |
| 713 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 751 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 714 if (j_obj.is_null()) | 752 if (j_obj.is_null()) |
| 715 return; | 753 return; |
| 716 ScopedJavaLocalRef<jstring> jcontent_url = | 754 ScopedJavaLocalRef<jstring> jcontent_url = |
| 717 ConvertUTF8ToJavaString(env, content_url.spec()); | 755 ConvertUTF8ToJavaString(env, content_url.spec()); |
| 718 Java_ContentViewCore_startContentIntent(env, | 756 Java_ContentViewCore_startContentIntent(env, |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env, | 1500 jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env, |
| 1463 jobject obj, | 1501 jobject obj, |
| 1464 jobject jbitmap) { | 1502 jobject jbitmap) { |
| 1465 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1503 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1466 if (!view) | 1504 if (!view) |
| 1467 return false; | 1505 return false; |
| 1468 | 1506 |
| 1469 return view->PopulateBitmapWithContents(jbitmap); | 1507 return view->PopulateBitmapWithContents(jbitmap); |
| 1470 } | 1508 } |
| 1471 | 1509 |
| 1510 void ContentViewCoreImpl::PopulateBitmapFromCompositorAsync( | |
| 1511 JNIEnv* env, | |
| 1512 jobject obj, | |
| 1513 jint x, | |
| 1514 jint y, | |
| 1515 jint width, | |
| 1516 jint height, | |
| 1517 jfloat scale, | |
| 1518 jobject jbitmap_config) { | |
| 1519 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 1520 if (!view) | |
| 1521 return; | |
| 1522 | |
| 1523 base::Callback<void(bool, const SkBitmap&)> callback = | |
| 1524 base::Bind(&ContentViewCoreImpl::OnBitmapReady, | |
| 1525 base::Unretained(this)); | |
| 1526 | |
| 1527 BitmapAllocator bitmap_allocator = | |
| 1528 base::Bind(&ContentViewCoreImpl::ProxyBitmapAllocator, | |
| 1529 base::Unretained(this)); | |
| 1530 | |
| 1531 //SkBitmap::Config bitmap_config = gfx::ConvertToSkiaConfig(jbitmap_config); | |
|
vivekg
2014/02/26 01:44:46
This would be enabled once https://codereview.chro
| |
| 1532 SkBitmap::Config bitmap_config = SkBitmap::kARGB_8888_Config; | |
| 1533 | |
| 1534 GetScaledContentBitmap(scale, callback, bitmap_config, | |
| 1535 gfx::Rect(x, y, width, height), | |
| 1536 bitmap_allocator); | |
| 1537 } | |
| 1538 | |
| 1472 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1539 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
| 1473 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1540 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1474 if (view) | 1541 if (view) |
| 1475 view->WasResized(); | 1542 view->WasResized(); |
| 1476 } | 1543 } |
| 1477 | 1544 |
| 1478 void ContentViewCoreImpl::ShowInterstitialPage( | 1545 void ContentViewCoreImpl::ShowInterstitialPage( |
| 1479 JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) { | 1546 JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) { |
| 1480 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 1547 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
| 1481 InterstitialPageDelegateAndroid* delegate = | 1548 InterstitialPageDelegateAndroid* delegate = |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1832 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1899 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1833 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1900 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1834 return reinterpret_cast<intptr_t>(view); | 1901 return reinterpret_cast<intptr_t>(view); |
| 1835 } | 1902 } |
| 1836 | 1903 |
| 1837 bool RegisterContentViewCore(JNIEnv* env) { | 1904 bool RegisterContentViewCore(JNIEnv* env) { |
| 1838 return RegisterNativesImpl(env); | 1905 return RegisterNativesImpl(env); |
| 1839 } | 1906 } |
| 1840 | 1907 |
| 1841 } // namespace content | 1908 } // namespace content |
| OLD | NEW |