Chromium Code Reviews| 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 "chrome/browser/android/favicon_helper.h" | 5 #include "chrome/browser/android/favicon_helper.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.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 21 matching lines...) Expand all Loading... | |
| 32 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
| 33 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
| 34 using base::android::ConvertJavaStringToUTF16; | 34 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertJavaStringToUTF8; | 35 using base::android::ConvertJavaStringToUTF8; |
| 36 using base::android::ConvertUTF8ToJavaString; | 36 using base::android::ConvertUTF8ToJavaString; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 void OnLocalFaviconAvailable( | 40 void OnLocalFaviconAvailable( |
| 41 ScopedJavaGlobalRef<jobject>* j_favicon_image_callback, | 41 ScopedJavaGlobalRef<jobject>* j_favicon_image_callback, |
| 42 const favicon_base::FaviconImageResult& favicon_image_result) { | 42 const favicon_base::FaviconRawBitmapResult& result) { |
| 43 JNIEnv* env = AttachCurrentThread(); | 43 JNIEnv* env = AttachCurrentThread(); |
| 44 | 44 |
| 45 // Convert favicon_image_result to java objects. | 45 // Convert favicon_image_result to java objects. |
| 46 ScopedJavaLocalRef<jstring> j_icon_url = | 46 ScopedJavaLocalRef<jstring> j_icon_url = |
| 47 ConvertUTF8ToJavaString(env, favicon_image_result.icon_url.spec()); | 47 ConvertUTF8ToJavaString(env, result.icon_url.spec()); |
| 48 SkBitmap favicon_bitmap = favicon_image_result.image.AsBitmap(); | |
| 49 ScopedJavaLocalRef<jobject> j_favicon_bitmap; | 48 ScopedJavaLocalRef<jobject> j_favicon_bitmap; |
| 50 if (!favicon_bitmap.isNull()) | 49 if (result.is_valid()) { |
| 51 j_favicon_bitmap = gfx::ConvertToJavaBitmap(&favicon_bitmap); | 50 SkBitmap favicon_bitmap; |
| 51 gfx::PNGCodec::Decode(result.bitmap_data->front(), | |
| 52 result.bitmap_data->size(), | |
| 53 &favicon_bitmap); | |
| 54 if (!favicon_bitmap.isNull()) | |
| 55 j_favicon_bitmap = gfx::ConvertToJavaBitmap(&favicon_bitmap); | |
| 56 } | |
| 52 | 57 |
| 53 // Call java side OnLocalFaviconAvailable method. | 58 // Call java side OnLocalFaviconAvailable method. |
| 54 Java_FaviconImageCallback_onFaviconAvailable(env, | 59 Java_FaviconImageCallback_onFaviconAvailable(env, |
| 55 j_favicon_image_callback->obj(), | 60 j_favicon_image_callback->obj(), |
| 56 j_favicon_bitmap.obj(), | 61 j_favicon_bitmap.obj(), |
| 57 j_icon_url.obj()); | 62 j_icon_url.obj()); |
| 58 } | 63 } |
| 59 | 64 |
| 60 void OnFaviconRawBitmapResultAvailable( | 65 void OnFaviconRawBitmapResultAvailable( |
| 61 ScopedJavaGlobalRef<jobject>* j_favicon_image_callback, | 66 ScopedJavaGlobalRef<jobject>* j_favicon_image_callback, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 void FaviconHelper::Destroy(JNIEnv* env, jobject obj) { | 101 void FaviconHelper::Destroy(JNIEnv* env, jobject obj) { |
| 97 delete this; | 102 delete this; |
| 98 } | 103 } |
| 99 | 104 |
| 100 jboolean FaviconHelper::GetLocalFaviconImageForURL( | 105 jboolean FaviconHelper::GetLocalFaviconImageForURL( |
| 101 JNIEnv* env, | 106 JNIEnv* env, |
| 102 jobject obj, | 107 jobject obj, |
| 103 jobject j_profile, | 108 jobject j_profile, |
| 104 jstring j_page_url, | 109 jstring j_page_url, |
| 105 jint j_icon_types, | 110 jint j_icon_types, |
| 106 jint j_desired_size_in_dip, | 111 jint j_desired_size_in_pixel, |
|
sky
2014/07/10 00:03:39
Were all call sites already passing in pixels?
pkotwicz
2014/07/11 01:23:08
In the implementation of OnLocalFaviconAvailable()
| |
| 107 jobject j_favicon_image_callback) { | 112 jobject j_favicon_image_callback) { |
| 108 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 113 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 109 DCHECK(profile); | 114 DCHECK(profile); |
| 110 if (!profile) | 115 if (!profile) |
| 111 return false; | 116 return false; |
| 112 | 117 |
| 113 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 118 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 114 profile, Profile::EXPLICIT_ACCESS); | 119 profile, Profile::EXPLICIT_ACCESS); |
| 115 DCHECK(favicon_service); | 120 DCHECK(favicon_service); |
| 116 if (!favicon_service) | 121 if (!favicon_service) |
| 117 return false; | 122 return false; |
| 118 | 123 |
| 119 FaviconService::FaviconForPageURLParams params( | |
| 120 GURL(ConvertJavaStringToUTF16(env, j_page_url)), | |
| 121 static_cast<int>(j_icon_types), | |
| 122 static_cast<int>(j_desired_size_in_dip)); | |
| 123 | |
| 124 ScopedJavaGlobalRef<jobject>* j_scoped_favicon_callback = | 124 ScopedJavaGlobalRef<jobject>* j_scoped_favicon_callback = |
| 125 new ScopedJavaGlobalRef<jobject>(); | 125 new ScopedJavaGlobalRef<jobject>(); |
| 126 j_scoped_favicon_callback->Reset(env, j_favicon_image_callback); | 126 j_scoped_favicon_callback->Reset(env, j_favicon_image_callback); |
| 127 | 127 |
| 128 favicon_base::FaviconImageCallback callback_runner = base::Bind( | 128 favicon_base::FaviconImageCallback callback_runner = base::Bind( |
| 129 &OnLocalFaviconAvailable, base::Owned(j_scoped_favicon_callback)); | 129 &OnLocalFaviconAvailable, base::Owned(j_scoped_favicon_callback)); |
| 130 | 130 |
| 131 favicon_service->GetFaviconImageForPageURL( | 131 favicon_service->GetRawFaviconForPageURL( |
| 132 params, callback_runner, | 132 GURL(ConvertJavaStringToUTF16(env, j_page_url), |
| 133 static_cast<int>(j_icon_types), | |
| 134 static_cast<int>(j_desired_size_in_pixel), | |
| 135 callback_runner, | |
| 133 cancelable_task_tracker_.get()); | 136 cancelable_task_tracker_.get()); |
| 134 | 137 |
| 135 return true; | 138 return true; |
| 136 } | 139 } |
| 137 | 140 |
| 138 void FaviconHelper::GetLargestRawFaviconForUrl( | 141 void FaviconHelper::GetLargestRawFaviconForUrl( |
| 139 JNIEnv* env, | 142 JNIEnv* env, |
| 140 jobject obj, | 143 jobject obj, |
| 141 jobject j_profile, | 144 jobject j_profile, |
| 142 jstring j_page_url, | 145 jstring j_page_url, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 218 |
| 216 gfx::JavaBitmap bitmap_lock(bitmap); | 219 gfx::JavaBitmap bitmap_lock(bitmap); |
| 217 SkBitmap skbitmap = gfx::CreateSkBitmapFromJavaBitmap(bitmap_lock); | 220 SkBitmap skbitmap = gfx::CreateSkBitmapFromJavaBitmap(bitmap_lock); |
| 218 return color_utils::CalculateKMeanColorOfBitmap(skbitmap); | 221 return color_utils::CalculateKMeanColorOfBitmap(skbitmap); |
| 219 } | 222 } |
| 220 | 223 |
| 221 // static | 224 // static |
| 222 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { | 225 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { |
| 223 return RegisterNativesImpl(env); | 226 return RegisterNativesImpl(env); |
| 224 } | 227 } |
| OLD | NEW |