| 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/shortcut_helper.h" | 5 #include "chrome/browser/android/shortcut_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_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 std::vector<int> icon_types; | 77 std::vector<int> icon_types; |
| 78 icon_types.push_back(favicon_base::FAVICON); | 78 icon_types.push_back(favicon_base::FAVICON); |
| 79 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | | 79 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | |
| 80 favicon_base::TOUCH_ICON); | 80 favicon_base::TOUCH_ICON); |
| 81 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 81 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 82 profile, Profile::EXPLICIT_ACCESS); | 82 profile, Profile::EXPLICIT_ACCESS); |
| 83 | 83 |
| 84 // Using favicon if its size is not smaller than platform required size, | 84 // Using favicon if its size is not smaller than platform required size, |
| 85 // otherwise using the largest icon among all avaliable icons. | 85 // otherwise using the largest icon among all avaliable icons. |
| 86 int threshold_to_get_any_largest_icon = launcher_large_icon_size_ - 1; | 86 int threshold_to_get_any_largest_icon = launcher_large_icon_size_ - 1; |
| 87 favicon_service->GetLargestRawFaviconForURL(profile, url_, icon_types, | 87 favicon_service->GetLargestRawFaviconForPageURL(profile, url_, icon_types, |
| 88 threshold_to_get_any_largest_icon, | 88 threshold_to_get_any_largest_icon, |
| 89 base::Bind(&ShortcutBuilder::FinishAddingShortcut, | 89 base::Bind(&ShortcutBuilder::FinishAddingShortcut, |
| 90 base::Unretained(this)), | 90 base::Unretained(this)), |
| 91 &cancelable_task_tracker_); | 91 &cancelable_task_tracker_); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ShortcutBuilder::FinishAddingShortcut( | 94 void ShortcutBuilder::FinishAddingShortcut( |
| 95 const favicon_base::FaviconBitmapResult& bitmap_result) { | 95 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 96 base::WorkerPool::PostTask( | 96 base::WorkerPool::PostTask( |
| 97 FROM_HERE, | 97 FROM_HERE, |
| 98 base::Bind(&ShortcutHelper::AddShortcutInBackground, | 98 base::Bind(&ShortcutHelper::AddShortcutInBackground, |
| 99 url_, | 99 url_, |
| 100 title_, | 100 title_, |
| 101 shortcut_type_, | 101 shortcut_type_, |
| 102 bitmap_result), | 102 bitmap_result), |
| 103 true); | 103 true); |
| 104 Destroy(); | 104 Destroy(); |
| 105 } | 105 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 135 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 136 return RegisterNativesImpl(env); | 136 return RegisterNativesImpl(env); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ShortcutHelper::AddShortcutInBackground( | 139 void ShortcutHelper::AddShortcutInBackground( |
| 140 const GURL& url, | 140 const GURL& url, |
| 141 const base::string16& title, | 141 const base::string16& title, |
| 142 ShortcutBuilder::ShortcutType shortcut_type, | 142 ShortcutBuilder::ShortcutType shortcut_type, |
| 143 const favicon_base::FaviconBitmapResult& bitmap_result) { | 143 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 144 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); | 144 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); |
| 145 | 145 |
| 146 // Grab the average color from the bitmap. | 146 // Grab the average color from the bitmap. |
| 147 SkColor color = SK_ColorWHITE; | 147 SkColor color = SK_ColorWHITE; |
| 148 SkBitmap favicon_bitmap; | 148 SkBitmap favicon_bitmap; |
| 149 if (bitmap_result.is_valid()) { | 149 if (bitmap_result.is_valid()) { |
| 150 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), | 150 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), |
| 151 bitmap_result.bitmap_data->size(), | 151 bitmap_result.bitmap_data->size(), |
| 152 &favicon_bitmap)) | 152 &favicon_bitmap)) |
| 153 color = color_utils::CalculateKMeanColorOfBitmap(favicon_bitmap); | 153 color = color_utils::CalculateKMeanColorOfBitmap(favicon_bitmap); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 jclass clazz, | 204 jclass clazz, |
| 205 jlong tab_android_ptr, | 205 jlong tab_android_ptr, |
| 206 jstring title, | 206 jstring title, |
| 207 jint launcher_large_icon_size) { | 207 jint launcher_large_icon_size) { |
| 208 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); | 208 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); |
| 209 ShortcutHelper::AddShortcut( | 209 ShortcutHelper::AddShortcut( |
| 210 tab->web_contents(), | 210 tab->web_contents(), |
| 211 base::android::ConvertJavaStringToUTF16(env, title), | 211 base::android::ConvertJavaStringToUTF16(env, title), |
| 212 launcher_large_icon_size); | 212 launcher_large_icon_size); |
| 213 } | 213 } |
| OLD | NEW |