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

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: pass in launcher_large_icon_size 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
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 int launcher_large_icon_size)
34 : launcher_large_icon_size_(launcher_large_icon_size),
35 shortcut_type_(BOOKMARK) {
33 Observe(web_contents); 36 Observe(web_contents);
34 url_ = web_contents->GetURL(); 37 url_ = web_contents->GetURL();
35 if (title.length() > 0) 38 if (title.length() > 0)
36 title_ = title; 39 title_ = title;
37 else 40 else
38 title_ = web_contents->GetTitle(); 41 title_ = web_contents->GetTitle();
39 42
40 // Send a message to the renderer to retrieve information about the page. 43 // Send a message to the renderer to retrieve information about the page.
41 Send(new ChromeViewMsg_RetrieveWebappInformation(routing_id(), url_)); 44 Send(new ChromeViewMsg_RetrieveWebappInformation(routing_id(), url_));
42 } 45 }
(...skipping 21 matching lines...) Expand all
64 shortcut_type_ = APP_SHORTCUT_APPLE; 67 shortcut_type_ = APP_SHORTCUT_APPLE;
65 } else if (is_apple_mobile_webapp_capable || is_mobile_webapp_capable) { 68 } else if (is_apple_mobile_webapp_capable || is_mobile_webapp_capable) {
66 shortcut_type_ = APP_SHORTCUT; 69 shortcut_type_ = APP_SHORTCUT;
67 } else { 70 } else {
68 shortcut_type_ = BOOKMARK; 71 shortcut_type_ = BOOKMARK;
69 } 72 }
70 73
71 // Grab the best, largest icon we can find to represent this bookmark. 74 // Grab the best, largest icon we can find to represent this bookmark.
72 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its 75 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its
73 // rewrite is further along. 76 // rewrite is further along.
74 FaviconService::FaviconForURLParams favicon_params( 77 std::vector<int> icon_types;
75 profile, 78 icon_types.push_back(chrome::FAVICON);
76 url_, 79 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( 80 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
81 profile, Profile::EXPLICIT_ACCESS); 81 profile, Profile::EXPLICIT_ACCESS);
82 82
83 favicon_service->GetRawFaviconForURL( 83 // Using favicon if its size is not smaller than platform required size,
84 favicon_params, 84 // otherwise using the largest icon among all avaliable icons.
85 ui::SCALE_FACTOR_100P, 85 int threshold_to_get_any_largest_icon = launcher_large_icon_size_ - 1;
86 favicon_service->GetLargestRawFaviconForURL(profile, url_, icon_types,
Yaron 2013/10/25 18:50:17 Can you add a test that triggers this?
michaelbai 2013/10/25 19:01:00 There already unit test for HistoryBackend::GetLar
87 threshold_to_get_any_largest_icon,
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 20 matching lines...) Expand all
116 } 118 }
117 119
118 void ShortcutBuilder::Destroy() { 120 void ShortcutBuilder::Destroy() {
119 if (cancelable_task_tracker_.HasTrackedTasks()) { 121 if (cancelable_task_tracker_.HasTrackedTasks()) {
120 cancelable_task_tracker_.TryCancelAll(); 122 cancelable_task_tracker_.TryCancelAll();
121 } 123 }
122 delete this; 124 delete this;
123 } 125 }
124 126
125 void ShortcutHelper::AddShortcut(content::WebContents* web_contents, 127 void ShortcutHelper::AddShortcut(content::WebContents* web_contents,
126 const string16& title) { 128 const string16& title,
129 int launcher_large_icon_size) {
127 // The ShortcutBuilder deletes itself when it's done. 130 // The ShortcutBuilder deletes itself when it's done.
128 new ShortcutBuilder(web_contents, title); 131 new ShortcutBuilder(web_contents, title, launcher_large_icon_size);
129 } 132 }
130 133
131 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 134 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
132 return RegisterNativesImpl(env); 135 return RegisterNativesImpl(env);
133 } 136 }
134 137
135 void ShortcutHelper::AddShortcutInBackground( 138 void ShortcutHelper::AddShortcutInBackground(
136 const GURL& url, 139 const GURL& url,
137 const string16& title, 140 const string16& title,
138 ShortcutBuilder::ShortcutType shortcut_type, 141 ShortcutBuilder::ShortcutType shortcut_type,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 199 }
197 } 200 }
198 201
199 // Adds a shortcut to the current URL to the Android home screen, firing 202 // Adds a shortcut to the current URL to the Android home screen, firing
200 // background tasks to pull all the data required. 203 // background tasks to pull all the data required.
201 // Note that we don't actually care about the tab here -- we just want 204 // Note that we don't actually care about the tab here -- we just want
202 // its otherwise inaccessible WebContents. 205 // its otherwise inaccessible WebContents.
203 static void AddShortcut(JNIEnv* env, 206 static void AddShortcut(JNIEnv* env,
204 jclass clazz, 207 jclass clazz,
205 jint tab_android_ptr, 208 jint tab_android_ptr,
206 jstring title) { 209 jstring title,
210 jint launcher_large_icon_size) {
207 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); 211 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr);
208 ShortcutHelper::AddShortcut( 212 ShortcutHelper::AddShortcut(
209 tab->web_contents(), 213 tab->web_contents(),
210 base::android::ConvertJavaStringToUTF16(env, title)); 214 base::android::ConvertJavaStringToUTF16(env, title),
215 launcher_large_icon_size);
211 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698