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" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 #include "ui/gfx/screen.h" | 54 #include "ui/gfx/screen.h" |
| 55 #include "ui/gfx/size_conversions.h" | 55 #include "ui/gfx/size_conversions.h" |
| 56 #include "ui/gfx/size_f.h" | 56 #include "ui/gfx/size_f.h" |
| 57 #include "webkit/common/user_agent/user_agent_util.h" | 57 #include "webkit/common/user_agent/user_agent_util.h" |
| 58 | 58 |
| 59 using base::android::AttachCurrentThread; | 59 using base::android::AttachCurrentThread; |
| 60 using base::android::ConvertJavaStringToUTF16; | 60 using base::android::ConvertJavaStringToUTF16; |
| 61 using base::android::ConvertJavaStringToUTF8; | 61 using base::android::ConvertJavaStringToUTF8; |
| 62 using base::android::ConvertUTF16ToJavaString; | 62 using base::android::ConvertUTF16ToJavaString; |
| 63 using base::android::ConvertUTF8ToJavaString; | 63 using base::android::ConvertUTF8ToJavaString; |
| 64 using base::android::HasException; | |
| 65 using base::android::JavaByteArrayToByteVector; | |
| 64 using base::android::ScopedJavaGlobalRef; | 66 using base::android::ScopedJavaGlobalRef; |
| 65 using base::android::ScopedJavaLocalRef; | 67 using base::android::ScopedJavaLocalRef; |
| 66 using WebKit::WebGestureEvent; | 68 using WebKit::WebGestureEvent; |
| 67 using WebKit::WebInputEvent; | 69 using WebKit::WebInputEvent; |
| 68 | 70 |
| 69 // Describes the type and enabled state of a select popup item. | 71 // Describes the type and enabled state of a select popup item. |
| 70 // Keep in sync with the value defined in SelectPopupDialog.java | 72 // Keep in sync with the value defined in SelectPopupDialog.java |
| 71 enum PopupItemType { | 73 enum PopupItemType { |
| 72 POPUP_ITEM_TYPE_GROUP = 0, | 74 POPUP_ITEM_TYPE_GROUP = 0, |
| 73 POPUP_ITEM_TYPE_DISABLED, | 75 POPUP_ITEM_TYPE_DISABLED, |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 } | 702 } |
| 701 | 703 |
| 702 void ContentViewCoreImpl::SetNeedsAnimate() { | 704 void ContentViewCoreImpl::SetNeedsAnimate() { |
| 703 JNIEnv* env = AttachCurrentThread(); | 705 JNIEnv* env = AttachCurrentThread(); |
| 704 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 706 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 705 if (obj.is_null()) | 707 if (obj.is_null()) |
| 706 return; | 708 return; |
| 707 Java_ContentViewCore_setNeedsAnimate(env, obj.obj()); | 709 Java_ContentViewCore_setNeedsAnimate(env, obj.obj()); |
| 708 } | 710 } |
| 709 | 711 |
| 712 bool ContentViewCoreImpl::GrabSnapshot(const std::string& format, | |
| 713 int quality, | |
| 714 double scale, | |
| 715 std::vector<uint8>* data) { | |
| 716 gfx::Size size = gfx::ToFlooredSize(gfx::ScaleSize(GetViewportSizePix(), | |
| 717 scale)); | |
|
Sami
2013/08/05 16:56:15
Check that no dimension of |size| is zero here.
| |
| 718 SkBitmap bitmap; | |
|
Sami
2013/08/05 16:56:15
To avoid the extra allocation and copy on line 735
| |
| 719 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | |
| 720 bitmap.allocPixels(); | |
| 721 SkAutoLockPixels lock(bitmap); | |
| 722 | |
| 723 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 724 if (!view->PopulateBitmapWithContents(size, &bitmap)) | |
|
no sievers
2013/08/05 21:46:44
We'd like to deprecate this API and make all readb
| |
| 725 return false; | |
| 726 | |
| 727 JNIEnv* env = AttachCurrentThread(); | |
| 728 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 729 if (obj.is_null()) | |
| 730 return false; | |
| 731 | |
| 732 ScopedJavaLocalRef<jstring> jstring_format = | |
| 733 ConvertUTF8ToJavaString(env, format); | |
| 734 ScopedJavaLocalRef<jobject> java_bitmap = | |
| 735 gfx::ConvertToJavaBitmap(&bitmap); | |
| 736 DCHECK(!java_bitmap.is_null()); | |
| 737 | |
| 738 ScopedJavaLocalRef<jbyteArray> data_ref = | |
| 739 Java_ContentViewCore_compressBitmap(env, obj.obj(), java_bitmap.obj(), | |
| 740 jstring_format.obj(), quality); | |
| 741 if (HasException(env) || data_ref.is_null()) | |
| 742 return false; | |
| 743 | |
| 744 JavaByteArrayToByteVector(env, data_ref.obj(), data); | |
| 745 return true; | |
| 746 } | |
| 747 | |
| 710 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 748 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
| 711 // view_android_ should never be null for Chrome. | 749 // view_android_ should never be null for Chrome. |
| 712 DCHECK(view_android_); | 750 DCHECK(view_android_); |
| 713 return view_android_; | 751 return view_android_; |
| 714 } | 752 } |
| 715 | 753 |
| 716 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 754 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
| 717 // This should never be NULL for Chrome, but will be NULL for WebView. | 755 // This should never be NULL for Chrome, but will be NULL for WebView. |
| 718 DCHECK(window_android_); | 756 DCHECK(window_android_); |
| 719 return window_android_; | 757 return window_android_; |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1632 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1595 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1633 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1596 return reinterpret_cast<jint>(view); | 1634 return reinterpret_cast<jint>(view); |
| 1597 } | 1635 } |
| 1598 | 1636 |
| 1599 bool RegisterContentViewCore(JNIEnv* env) { | 1637 bool RegisterContentViewCore(JNIEnv* env) { |
| 1600 return RegisterNativesImpl(env); | 1638 return RegisterNativesImpl(env); |
| 1601 } | 1639 } |
| 1602 | 1640 |
| 1603 } // namespace content | 1641 } // namespace content |
| OLD | NEW |