| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 WebContentsViewAndroid* view = | 649 WebContentsViewAndroid* view = |
| 650 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 650 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
| 651 view->SetOverscrollRefreshHandler( | 651 view->SetOverscrollRefreshHandler( |
| 652 base::MakeUnique<ui::OverscrollRefreshHandler>( | 652 base::MakeUnique<ui::OverscrollRefreshHandler>( |
| 653 overscroll_refresh_handler)); | 653 overscroll_refresh_handler)); |
| 654 } | 654 } |
| 655 | 655 |
| 656 void WebContentsAndroid::GetContentBitmap( | 656 void WebContentsAndroid::GetContentBitmap( |
| 657 JNIEnv* env, | 657 JNIEnv* env, |
| 658 const JavaParamRef<jobject>& obj, | 658 const JavaParamRef<jobject>& obj, |
| 659 const JavaParamRef<jobject>& jcallback, | 659 jint width, |
| 660 const JavaParamRef<jobject>& color_type, | 660 jint height, |
| 661 jfloat scale, | 661 const JavaParamRef<jobject>& jcallback) { |
| 662 jfloat x, | |
| 663 jfloat y, | |
| 664 jfloat width, | |
| 665 jfloat height) { | |
| 666 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 662 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 667 const ReadbackRequestCallback result_callback = base::Bind( | 663 const ReadbackRequestCallback result_callback = base::Bind( |
| 668 &WebContentsAndroid::OnFinishGetContentBitmap, weak_factory_.GetWeakPtr(), | 664 &WebContentsAndroid::OnFinishGetContentBitmap, weak_factory_.GetWeakPtr(), |
| 669 ScopedJavaGlobalRef<jobject>(env, obj), | 665 ScopedJavaGlobalRef<jobject>(env, obj), |
| 670 ScopedJavaGlobalRef<jobject>(env, jcallback)); | 666 ScopedJavaGlobalRef<jobject>(env, jcallback)); |
| 671 SkColorType pref_color_type = gfx::ConvertToSkiaColorType(color_type); | 667 if (!view) { |
| 672 if (!view || pref_color_type == kUnknown_SkColorType) { | |
| 673 result_callback.Run(SkBitmap(), READBACK_FAILED); | 668 result_callback.Run(SkBitmap(), READBACK_FAILED); |
| 674 return; | 669 return; |
| 675 } | 670 } |
| 676 if (!view->IsSurfaceAvailableForCopy()) { | 671 view->CopyFromSurface(gfx::Rect(), gfx::Size(width, height), result_callback, |
| 677 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 672 kN32_SkColorType); |
| 678 return; | |
| 679 } | |
| 680 view->GetScaledContentBitmap(scale, | |
| 681 pref_color_type, | |
| 682 gfx::Rect(x, y, width, height), | |
| 683 result_callback); | |
| 684 } | 673 } |
| 685 | 674 |
| 686 void WebContentsAndroid::ReloadLoFiImages(JNIEnv* env, | 675 void WebContentsAndroid::ReloadLoFiImages(JNIEnv* env, |
| 687 const JavaParamRef<jobject>& obj) { | 676 const JavaParamRef<jobject>& obj) { |
| 688 static_cast<WebContentsImpl*>(web_contents_)->ReloadLoFiImages(); | 677 static_cast<WebContentsImpl*>(web_contents_)->ReloadLoFiImages(); |
| 689 } | 678 } |
| 690 | 679 |
| 691 int WebContentsAndroid::DownloadImage( | 680 int WebContentsAndroid::DownloadImage( |
| 692 JNIEnv* env, | 681 JNIEnv* env, |
| 693 const base::android::JavaParamRef<jobject>& obj, | 682 const base::android::JavaParamRef<jobject>& obj, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); | 759 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); |
| 771 } | 760 } |
| 772 | 761 |
| 773 void WebContentsAndroid::SetMediaSession( | 762 void WebContentsAndroid::SetMediaSession( |
| 774 const ScopedJavaLocalRef<jobject>& j_media_session) { | 763 const ScopedJavaLocalRef<jobject>& j_media_session) { |
| 775 JNIEnv* env = base::android::AttachCurrentThread(); | 764 JNIEnv* env = base::android::AttachCurrentThread(); |
| 776 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); | 765 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); |
| 777 } | 766 } |
| 778 | 767 |
| 779 } // namespace content | 768 } // namespace content |
| OLD | NEW |