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

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 38523002: Using largest favicon for shortcut when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 // The favicon was resized by ScaleFactor and stored in HistoryBackend.
83 favicon_service->GetRawFaviconForURL( 81 // We need to get largest possible size of the resized normal favicon and
84 favicon_params, 82 // pass it into GetLargestFawFaviconForURL(), otherwise, the normal favicon is
85 ui::SCALE_FACTOR_100P, 83 // returned even there is larger touch icon avaliable.
84 // In theory, the side effect is that the touch icon or precomposed touch
85 // icon whose size is smaller than kFaviconSize*ScaleFactor and larger than
86 // kFaviconSize can't be returned, but it actually not a issue as the normal
87 // favicon is 16x16, the maximum scale factor we used is 2.0f, so the maximum
88 // resized favicon is 32x32 and much smaller than touch icon whose size is
89 // from 57x57 to 144x144.
michaelbai 2013/10/23 23:20:47 I have a CL to fix this issue, the icon will not b
90 std::vector<ui::ScaleFactor> favicon_scale_factors =
91 ui::GetSupportedScaleFactors();
92 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P;
93 for (std::vector<ui::ScaleFactor>::const_iterator i =
94 favicon_scale_factors.begin(); i != favicon_scale_factors.end();
95 ++i) {
96 if (scale_factor < *i)
97 scale_factor = *i;
98 }
99 favicon_service->GetLargestRawFaviconForURL(profile, url_, icon_types,
100 gfx::kFaviconSize * ui::GetImageScale(scale_factor),
86 base::Bind(&ShortcutBuilder::FinishAddingShortcut, 101 base::Bind(&ShortcutBuilder::FinishAddingShortcut,
87 base::Unretained(this)), 102 base::Unretained(this)),
88 &cancelable_task_tracker_); 103 &cancelable_task_tracker_);
89 } 104 }
90 105
91 void ShortcutBuilder::FinishAddingShortcut( 106 void ShortcutBuilder::FinishAddingShortcut(
92 const chrome::FaviconBitmapResult& bitmap_result) { 107 const chrome::FaviconBitmapResult& bitmap_result) {
93 base::WorkerPool::PostTask( 108 base::WorkerPool::PostTask(
94 FROM_HERE, 109 FROM_HERE,
95 base::Bind(&ShortcutHelper::AddShortcutInBackground, 110 base::Bind(&ShortcutHelper::AddShortcutInBackground,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // its otherwise inaccessible WebContents. 217 // its otherwise inaccessible WebContents.
203 static void AddShortcut(JNIEnv* env, 218 static void AddShortcut(JNIEnv* env,
204 jclass clazz, 219 jclass clazz,
205 jint tab_android_ptr, 220 jint tab_android_ptr,
206 jstring title) { 221 jstring title) {
207 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); 222 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr);
208 ShortcutHelper::AddShortcut( 223 ShortcutHelper::AddShortcut(
209 tab->web_contents(), 224 tab->web_contents(),
210 base::android::ConvertJavaStringToUTF16(env, title)); 225 base::android::ConvertJavaStringToUTF16(env, title));
211 } 226 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698