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/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" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 15 #include "chrome/browser/android/tab_android.h" | 15 #include "chrome/browser/android/tab_android.h" |
| 16 #include "chrome/browser/favicon/favicon_service.h" | 16 #include "chrome/browser/favicon/favicon_service.h" |
| 17 #include "chrome/browser/favicon/favicon_service_factory.h" | 17 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 18 #include "chrome/common/cancelable_task_tracker.h" | 18 #include "chrome/common/cancelable_task_tracker.h" |
| 19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
| 20 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/common/frame_navigate_params.h" | 23 #include "content/public/common/frame_navigate_params.h" |
| 24 #include "jni/ShortcutHelper_jni.h" | 24 #include "jni/ShortcutHelper_jni.h" |
| 25 #include "ui/gfx/android/java_bitmap.h" | 25 #include "ui/gfx/android/java_bitmap.h" |
| 26 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
| 27 #include "ui/gfx/color_analysis.h" | 27 #include "ui/gfx/color_analysis.h" |
| 28 #include "ui/gfx/favicon_size.h" | |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 ShortcutBuilder::ShortcutBuilder(content::WebContents* web_contents, | 31 ShortcutBuilder::ShortcutBuilder(content::WebContents* web_contents, |
| 31 const string16& title) | 32 const string16& title) |
| 32 : shortcut_type_(BOOKMARK) { | 33 : shortcut_type_(BOOKMARK) { |
| 33 Observe(web_contents); | 34 Observe(web_contents); |
| 34 url_ = web_contents->GetURL(); | 35 url_ = web_contents->GetURL(); |
| 35 if (title.length() > 0) | 36 if (title.length() > 0) |
| 36 title_ = title; | 37 title_ = title; |
| 37 else | 38 else |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 64 shortcut_type_ = APP_SHORTCUT_APPLE; | 65 shortcut_type_ = APP_SHORTCUT_APPLE; |
| 65 } else if (is_apple_mobile_webapp_capable || is_mobile_webapp_capable) { | 66 } else if (is_apple_mobile_webapp_capable || is_mobile_webapp_capable) { |
| 66 shortcut_type_ = APP_SHORTCUT; | 67 shortcut_type_ = APP_SHORTCUT; |
| 67 } else { | 68 } else { |
| 68 shortcut_type_ = BOOKMARK; | 69 shortcut_type_ = BOOKMARK; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Grab the best, largest icon we can find to represent this bookmark. | 72 // Grab the best, largest icon we can find to represent this bookmark. |
| 72 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its | 73 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its |
| 73 // rewrite is further along. | 74 // rewrite is further along. |
| 74 FaviconService::FaviconForURLParams favicon_params( | 75 std::vector<int> icon_types; |
| 75 profile, | 76 icon_types.push_back(chrome::FAVICON); |
| 76 url_, | 77 icon_types.push_back(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON); |
| 77 chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON | chrome::FAVICON, | |
| 78 0); | |
| 79 | |
| 80 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 78 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 81 profile, Profile::EXPLICIT_ACCESS); | 79 profile, Profile::EXPLICIT_ACCESS); |
| 82 | 80 |
| 83 favicon_service->GetRawFaviconForURL( | 81 // Using favicon if its size is not smaller than platform required size, |
| 84 favicon_params, | 82 // otherwise using the largest icon among all avaliable icons. |
| 85 ui::SCALE_FACTOR_100P, | 83 int minimum_size = Java_ShortcutHelper_getLauncherLargeIconSize( |
| 84 base::android::AttachCurrentThread(), | |
| 85 base::android::GetApplicationContext()); | |
| 86 favicon_service->GetLargestRawFaviconForURL(profile, url_, icon_types, | |
| 87 minimum_size - 1, | |
|
gone
2013/10/24 22:07:32
Why are you subtracting off 1 pixel btw?
michaelbai
2013/10/25 03:36:43
The GetLargestRawFaviconForURL finds the icon larg
| |
| 86 base::Bind(&ShortcutBuilder::FinishAddingShortcut, | 88 base::Bind(&ShortcutBuilder::FinishAddingShortcut, |
| 87 base::Unretained(this)), | 89 base::Unretained(this)), |
| 88 &cancelable_task_tracker_); | 90 &cancelable_task_tracker_); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void ShortcutBuilder::FinishAddingShortcut( | 93 void ShortcutBuilder::FinishAddingShortcut( |
| 92 const chrome::FaviconBitmapResult& bitmap_result) { | 94 const chrome::FaviconBitmapResult& bitmap_result) { |
| 93 base::WorkerPool::PostTask( | 95 base::WorkerPool::PostTask( |
| 94 FROM_HERE, | 96 FROM_HERE, |
| 95 base::Bind(&ShortcutHelper::AddShortcutInBackground, | 97 base::Bind(&ShortcutHelper::AddShortcutInBackground, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // its otherwise inaccessible WebContents. | 204 // its otherwise inaccessible WebContents. |
| 203 static void AddShortcut(JNIEnv* env, | 205 static void AddShortcut(JNIEnv* env, |
| 204 jclass clazz, | 206 jclass clazz, |
| 205 jint tab_android_ptr, | 207 jint tab_android_ptr, |
| 206 jstring title) { | 208 jstring title) { |
| 207 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); | 209 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); |
| 208 ShortcutHelper::AddShortcut( | 210 ShortcutHelper::AddShortcut( |
| 209 tab->web_contents(), | 211 tab->web_contents(), |
| 210 base::android::ConvertJavaStringToUTF16(env, title)); | 212 base::android::ConvertJavaStringToUTF16(env, title)); |
| 211 } | 213 } |
| OLD | NEW |