| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 if (result.is_valid()) { | 57 if (result.is_valid()) { |
| 58 SkBitmap favicon_bitmap; | 58 SkBitmap favicon_bitmap; |
| 59 gfx::PNGCodec::Decode(result.bitmap_data->front(), | 59 gfx::PNGCodec::Decode(result.bitmap_data->front(), |
| 60 result.bitmap_data->size(), | 60 result.bitmap_data->size(), |
| 61 &favicon_bitmap); | 61 &favicon_bitmap); |
| 62 if (!favicon_bitmap.isNull()) | 62 if (!favicon_bitmap.isNull()) |
| 63 j_favicon_bitmap = gfx::ConvertToJavaBitmap(&favicon_bitmap); | 63 j_favicon_bitmap = gfx::ConvertToJavaBitmap(&favicon_bitmap); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Call java side OnLocalFaviconAvailable method. | 66 // Call java side OnLocalFaviconAvailable method. |
| 67 Java_FaviconImageCallback_onFaviconAvailable(env, | 67 Java_FaviconImageCallback_onFaviconAvailable( |
| 68 j_favicon_image_callback->obj(), | 68 env, j_favicon_image_callback->obj(), j_favicon_bitmap, j_icon_url); |
| 69 j_favicon_bitmap.obj(), | |
| 70 j_icon_url.obj()); | |
| 71 } | 69 } |
| 72 | 70 |
| 73 size_t GetLargestSizeIndex(const std::vector<gfx::Size>& sizes) { | 71 size_t GetLargestSizeIndex(const std::vector<gfx::Size>& sizes) { |
| 74 DCHECK(!sizes.empty()); | 72 DCHECK(!sizes.empty()); |
| 75 size_t ret = 0; | 73 size_t ret = 0; |
| 76 for (size_t i = 1; i < sizes.size(); ++i) { | 74 for (size_t i = 1; i < sizes.size(); ++i) { |
| 77 if (sizes[ret].GetArea() < sizes[i].GetArea()) | 75 if (sizes[ret].GetArea() < sizes[i].GetArea()) |
| 78 ret = i; | 76 ret = i; |
| 79 } | 77 } |
| 80 return ret; | 78 return ret; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 favicon::FaviconService* service = FaviconServiceFactory::GetForProfile( | 98 favicon::FaviconService* service = FaviconServiceFactory::GetForProfile( |
| 101 profile, ServiceAccessType::IMPLICIT_ACCESS); | 99 profile, ServiceAccessType::IMPLICIT_ACCESS); |
| 102 service->SetFavicons(page_url, image_url, icon_type, image); | 100 service->SetFavicons(page_url, image_url, icon_type, image); |
| 103 | 101 |
| 104 if (is_temporary) | 102 if (is_temporary) |
| 105 service->SetFaviconOutOfDateForPage(page_url); | 103 service->SetFaviconOutOfDateForPage(page_url); |
| 106 } | 104 } |
| 107 | 105 |
| 108 JNIEnv* env = AttachCurrentThread(); | 106 JNIEnv* env = AttachCurrentThread(); |
| 109 Java_IconAvailabilityCallback_onIconAvailabilityChecked( | 107 Java_IconAvailabilityCallback_onIconAvailabilityChecked( |
| 110 env, j_availability_callback.obj(), success); | 108 env, j_availability_callback, success); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void OnFaviconImageResultAvailable( | 111 void OnFaviconImageResultAvailable( |
| 114 const ScopedJavaGlobalRef<jobject>& j_availability_callback, | 112 const ScopedJavaGlobalRef<jobject>& j_availability_callback, |
| 115 Profile* profile, | 113 Profile* profile, |
| 116 content::WebContents* web_contents, | 114 content::WebContents* web_contents, |
| 117 const GURL& page_url, | 115 const GURL& page_url, |
| 118 const GURL& icon_url, | 116 const GURL& icon_url, |
| 119 favicon_base::IconType icon_type, | 117 favicon_base::IconType icon_type, |
| 120 bool is_temporary, | 118 bool is_temporary, |
| 121 const favicon_base::FaviconImageResult& result) { | 119 const favicon_base::FaviconImageResult& result) { |
| 122 // If there already is a favicon, return immediately. | 120 // If there already is a favicon, return immediately. |
| 123 if (!result.image.IsEmpty()) { | 121 if (!result.image.IsEmpty()) { |
| 124 JNIEnv* env = AttachCurrentThread(); | 122 JNIEnv* env = AttachCurrentThread(); |
| 125 Java_IconAvailabilityCallback_onIconAvailabilityChecked( | 123 Java_IconAvailabilityCallback_onIconAvailabilityChecked( |
| 126 env, j_availability_callback.obj(), false); | 124 env, j_availability_callback, false); |
| 127 return; | 125 return; |
| 128 } | 126 } |
| 129 | 127 |
| 130 web_contents->DownloadImage( | 128 web_contents->DownloadImage( |
| 131 icon_url, true, 0, false, | 129 icon_url, true, 0, false, |
| 132 base::Bind(OnFaviconDownloaded, j_availability_callback, profile, | 130 base::Bind(OnFaviconDownloaded, j_availability_callback, profile, |
| 133 page_url, icon_type, is_temporary)); | 131 page_url, icon_type, is_temporary)); |
| 134 } | 132 } |
| 135 | 133 |
| 136 } // namespace | 134 } // namespace |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 258 |
| 261 gfx::JavaBitmap bitmap_lock(bitmap); | 259 gfx::JavaBitmap bitmap_lock(bitmap); |
| 262 SkBitmap skbitmap = gfx::CreateSkBitmapFromJavaBitmap(bitmap_lock); | 260 SkBitmap skbitmap = gfx::CreateSkBitmapFromJavaBitmap(bitmap_lock); |
| 263 return color_utils::CalculateKMeanColorOfBitmap(skbitmap); | 261 return color_utils::CalculateKMeanColorOfBitmap(skbitmap); |
| 264 } | 262 } |
| 265 | 263 |
| 266 // static | 264 // static |
| 267 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { | 265 bool FaviconHelper::RegisterFaviconHelper(JNIEnv* env) { |
| 268 return RegisterNativesImpl(env); | 266 return RegisterNativesImpl(env); |
| 269 } | 267 } |
| OLD | NEW |