Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: content/browser/web_contents/web_contents_android.cc

Issue 2538463002: android: Don't pass ScopedJavaGlobalRef pointers. (Closed)
Patch Set: timeouts are very annoying Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 JNIEnv* env, 620 JNIEnv* env,
621 const JavaParamRef<jobject>& obj, 621 const JavaParamRef<jobject>& obj,
622 const JavaParamRef<jobject>& jcallback, 622 const JavaParamRef<jobject>& jcallback,
623 const JavaParamRef<jobject>& color_type, 623 const JavaParamRef<jobject>& color_type,
624 jfloat scale, 624 jfloat scale,
625 jfloat x, 625 jfloat x,
626 jfloat y, 626 jfloat y,
627 jfloat width, 627 jfloat width,
628 jfloat height) { 628 jfloat height) {
629 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 629 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
630 const ReadbackRequestCallback result_callback = 630 const ReadbackRequestCallback result_callback = base::Bind(
631 base::Bind(&WebContentsAndroid::OnFinishGetContentBitmap, 631 &WebContentsAndroid::OnFinishGetContentBitmap, weak_factory_.GetWeakPtr(),
632 weak_factory_.GetWeakPtr(), 632 ScopedJavaGlobalRef<jobject>(env, obj),
633 base::Owned(new ScopedJavaGlobalRef<jobject>(env, obj)), 633 ScopedJavaGlobalRef<jobject>(env, jcallback));
634 base::Owned(new ScopedJavaGlobalRef<jobject>(env, jcallback)));
635 SkColorType pref_color_type = gfx::ConvertToSkiaColorType(color_type); 634 SkColorType pref_color_type = gfx::ConvertToSkiaColorType(color_type);
636 if (!view || pref_color_type == kUnknown_SkColorType) { 635 if (!view || pref_color_type == kUnknown_SkColorType) {
637 result_callback.Run(SkBitmap(), READBACK_FAILED); 636 result_callback.Run(SkBitmap(), READBACK_FAILED);
638 return; 637 return;
639 } 638 }
640 if (!view->IsSurfaceAvailableForCopy()) { 639 if (!view->IsSurfaceAvailableForCopy()) {
641 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 640 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
642 return; 641 return;
643 } 642 }
644 view->GetScaledContentBitmap(scale, 643 view->GetScaledContentBitmap(scale,
(...skipping 13 matching lines...) Expand all
658 const base::android::JavaParamRef<jstring>& jurl, 657 const base::android::JavaParamRef<jstring>& jurl,
659 jboolean is_fav_icon, 658 jboolean is_fav_icon,
660 jint max_bitmap_size, 659 jint max_bitmap_size,
661 jboolean bypass_cache, 660 jboolean bypass_cache,
662 const base::android::JavaParamRef<jobject>& jcallback) { 661 const base::android::JavaParamRef<jobject>& jcallback) {
663 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); 662 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
664 return web_contents_->DownloadImage( 663 return web_contents_->DownloadImage(
665 url, is_fav_icon, max_bitmap_size, bypass_cache, 664 url, is_fav_icon, max_bitmap_size, bypass_cache,
666 base::Bind(&WebContentsAndroid::OnFinishDownloadImage, 665 base::Bind(&WebContentsAndroid::OnFinishDownloadImage,
667 weak_factory_.GetWeakPtr(), 666 weak_factory_.GetWeakPtr(),
668 base::Owned(new ScopedJavaGlobalRef<jobject>( 667 ScopedJavaGlobalRef<jobject>(env, obj),
669 env, obj)), 668 ScopedJavaGlobalRef<jobject>(env, jcallback)));
670 base::Owned(new ScopedJavaGlobalRef<jobject>(
671 env, jcallback))));
672 } 669 }
673 670
674 void WebContentsAndroid::DismissTextHandles( 671 void WebContentsAndroid::DismissTextHandles(
675 JNIEnv* env, 672 JNIEnv* env,
676 const base::android::JavaParamRef<jobject>& obj) { 673 const base::android::JavaParamRef<jobject>& obj) {
677 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 674 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
678 if (view) 675 if (view)
679 view->DismissTextHandles(); 676 view->DismissTextHandles();
680 } 677 }
681 678
682 void WebContentsAndroid::OnFinishGetContentBitmap( 679 void WebContentsAndroid::OnFinishGetContentBitmap(
683 ScopedJavaGlobalRef<jobject>* obj, 680 const JavaRef<jobject>& obj,
684 ScopedJavaGlobalRef<jobject>* callback, 681 const JavaRef<jobject>& callback,
685 const SkBitmap& bitmap, 682 const SkBitmap& bitmap,
686 ReadbackResponse response) { 683 ReadbackResponse response) {
687 JNIEnv* env = base::android::AttachCurrentThread(); 684 JNIEnv* env = base::android::AttachCurrentThread();
688 ScopedJavaLocalRef<jobject> java_bitmap; 685 ScopedJavaLocalRef<jobject> java_bitmap;
689 if (response == READBACK_SUCCESS) 686 if (response == READBACK_SUCCESS)
690 java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); 687 java_bitmap = gfx::ConvertToJavaBitmap(&bitmap);
691 Java_WebContentsImpl_onGetContentBitmapFinished(env, *obj, *callback, 688 Java_WebContentsImpl_onGetContentBitmapFinished(env, obj, callback,
692 java_bitmap, response); 689 java_bitmap, response);
693 } 690 }
694 691
695 void WebContentsAndroid::OnFinishDownloadImage( 692 void WebContentsAndroid::OnFinishDownloadImage(
696 base::android::ScopedJavaGlobalRef<jobject>* obj, 693 const JavaRef<jobject>& obj,
697 base::android::ScopedJavaGlobalRef<jobject>* callback, 694 const JavaRef<jobject>& callback,
698 int id, 695 int id,
699 int http_status_code, 696 int http_status_code,
700 const GURL& url, 697 const GURL& url,
701 const std::vector<SkBitmap>& bitmaps, 698 const std::vector<SkBitmap>& bitmaps,
702 const std::vector<gfx::Size>& sizes) { 699 const std::vector<gfx::Size>& sizes) {
703 JNIEnv* env = base::android::AttachCurrentThread(); 700 JNIEnv* env = base::android::AttachCurrentThread();
704 ScopedJavaLocalRef<jobject> jbitmaps = 701 ScopedJavaLocalRef<jobject> jbitmaps =
705 Java_WebContentsImpl_createBitmapList(env); 702 Java_WebContentsImpl_createBitmapList(env);
706 ScopedJavaLocalRef<jobject> jsizes = 703 ScopedJavaLocalRef<jobject> jsizes =
707 Java_WebContentsImpl_createSizeList(env); 704 Java_WebContentsImpl_createSizeList(env);
708 ScopedJavaLocalRef<jstring> jurl = 705 ScopedJavaLocalRef<jstring> jurl =
709 base::android::ConvertUTF8ToJavaString(env, url.spec()); 706 base::android::ConvertUTF8ToJavaString(env, url.spec());
710 707
711 for (const SkBitmap& bitmap : bitmaps) { 708 for (const SkBitmap& bitmap : bitmaps) {
712 // WARNING: convering to java bitmaps results in duplicate memory 709 // WARNING: convering to java bitmaps results in duplicate memory
713 // allocations, which increases the chance of OOMs if DownloadImage() is 710 // allocations, which increases the chance of OOMs if DownloadImage() is
714 // misused. 711 // misused.
715 ScopedJavaLocalRef<jobject> jbitmap = gfx::ConvertToJavaBitmap(&bitmap); 712 ScopedJavaLocalRef<jobject> jbitmap = gfx::ConvertToJavaBitmap(&bitmap);
716 Java_WebContentsImpl_addToBitmapList(env, jbitmaps, jbitmap); 713 Java_WebContentsImpl_addToBitmapList(env, jbitmaps, jbitmap);
717 } 714 }
718 for (const gfx::Size& size : sizes) { 715 for (const gfx::Size& size : sizes) {
719 Java_WebContentsImpl_createSizeAndAddToList(env, jsizes, size.width(), 716 Java_WebContentsImpl_createSizeAndAddToList(env, jsizes, size.width(),
720 size.height()); 717 size.height());
721 } 718 }
722 Java_WebContentsImpl_onDownloadImageFinished( 719 Java_WebContentsImpl_onDownloadImageFinished(
723 env, *obj, *callback, id, http_status_code, jurl, jbitmaps, jsizes); 720 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes);
724 } 721 }
725 722
726 void WebContentsAndroid::SetMediaSession( 723 void WebContentsAndroid::SetMediaSession(
727 const ScopedJavaLocalRef<jobject>& j_media_session) { 724 const ScopedJavaLocalRef<jobject>& j_media_session) {
728 JNIEnv* env = base::android::AttachCurrentThread(); 725 JNIEnv* env = base::android::AttachCurrentThread();
729 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); 726 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session);
730 } 727 }
731 728
732 } // namespace content 729 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_android.h ('k') | content/public/browser/android/app_web_message_port_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698