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

Side by Side Diff: chrome/browser/ui/webui/favicon_source.cc

Issue 335233003: Convert ui::ScaleFactor -> float in favicon/history code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix size_t Created 6 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/favicon_source.h" 5 #include "chrome/browser/ui/webui/favicon_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/favicon/favicon_service_factory.h" 10 #include "chrome/browser/favicon/favicon_service_factory.h"
11 #include "chrome/browser/history/top_sites.h" 11 #include "chrome/browser/history/top_sites.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/instant_io_context.h" 13 #include "chrome/browser/search/instant_io_context.h"
14 #include "chrome/browser/sync/open_tabs_ui_delegate.h" 14 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
15 #include "chrome/browser/sync/profile_sync_service.h" 15 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
17 #include "chrome/common/favicon/favicon_url_parser.h" 17 #include "chrome/common/favicon/favicon_url_parser.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "grit/locale_settings.h" 19 #include "grit/locale_settings.h"
20 #include "grit/ui_resources.h" 20 #include "grit/ui_resources.h"
21 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/layout.h" 23 #include "ui/base/layout.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/webui/web_ui_util.h" 25 #include "ui/base/webui/web_ui_util.h"
26 26
27 FaviconSource::IconRequest::IconRequest() 27 FaviconSource::IconRequest::IconRequest()
28 : size_in_dip(gfx::kFaviconSize), 28 : size_in_dip(gfx::kFaviconSize), device_scale_factor(1.0f) {
29 scale_factor(ui::SCALE_FACTOR_NONE) {
30 } 29 }
31 30
32 FaviconSource::IconRequest::IconRequest( 31 FaviconSource::IconRequest::IconRequest(
33 const content::URLDataSource::GotDataCallback& cb, 32 const content::URLDataSource::GotDataCallback& cb,
34 const GURL& path, 33 const GURL& path,
35 int size, 34 int size,
36 ui::ScaleFactor scale) 35 float scale)
37 : callback(cb), 36 : callback(cb),
38 request_path(path), 37 request_path(path),
39 size_in_dip(size), 38 size_in_dip(size),
40 scale_factor(scale) { 39 device_scale_factor(scale) {
41 } 40 }
42 41
43 FaviconSource::IconRequest::~IconRequest() { 42 FaviconSource::IconRequest::~IconRequest() {
44 } 43 }
45 44
46 FaviconSource::FaviconSource(Profile* profile, IconType type) 45 FaviconSource::FaviconSource(Profile* profile, IconType type)
47 : profile_(profile->GetOriginalProfile()), 46 : profile_(profile->GetOriginalProfile()),
48 icon_types_(type == FAVICON ? favicon_base::FAVICON 47 icon_types_(type == FAVICON ? favicon_base::FAVICON
49 : favicon_base::TOUCH_PRECOMPOSED_ICON | 48 : favicon_base::TOUCH_PRECOMPOSED_ICON |
50 favicon_base::TOUCH_ICON | 49 favicon_base::TOUCH_ICON |
(...skipping 21 matching lines...) Expand all
72 71
73 chrome::ParsedFaviconPath parsed; 72 chrome::ParsedFaviconPath parsed;
74 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); 73 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed);
75 if (!success) { 74 if (!success) {
76 SendDefaultResponse(callback); 75 SendDefaultResponse(callback);
77 return; 76 return;
78 } 77 }
79 78
80 GURL url(parsed.url); 79 GURL url(parsed.url);
81 80
82 ui::ScaleFactor scale_factor =
83 ui::GetSupportedScaleFactor(parsed.scale_factor);
84 if (parsed.is_icon_url) { 81 if (parsed.is_icon_url) {
85 // TODO(michaelbai): Change GetRawFavicon to support combination of 82 // TODO(michaelbai): Change GetRawFavicon to support combination of
86 // IconType. 83 // IconType.
87 favicon_service->GetRawFavicon( 84 favicon_service->GetRawFavicon(
88 url, 85 url,
89 favicon_base::FAVICON, 86 favicon_base::FAVICON,
90 parsed.size_in_dip, 87 parsed.size_in_dip,
91 scale_factor, 88 parsed.device_scale_factor,
92 base::Bind(&FaviconSource::OnFaviconDataAvailable, 89 base::Bind(
93 base::Unretained(this), 90 &FaviconSource::OnFaviconDataAvailable,
94 IconRequest( 91 base::Unretained(this),
95 callback, url, parsed.size_in_dip, scale_factor)), 92 IconRequest(
93 callback, url, parsed.size_in_dip, parsed.device_scale_factor)),
96 &cancelable_task_tracker_); 94 &cancelable_task_tracker_);
97 } else { 95 } else {
98 // Intercept requests for prepopulated pages. 96 // Intercept requests for prepopulated pages.
99 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { 97 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
100 if (url.spec() == 98 if (url.spec() ==
101 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { 99 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
100 ui::ScaleFactor resource_scale_factor =
101 ui::GetSupportedScaleFactor(parsed.device_scale_factor);
102 callback.Run( 102 callback.Run(
103 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 103 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
104 history::kPrepopulatedPages[i].favicon_id, 104 history::kPrepopulatedPages[i].favicon_id,
105 scale_factor)); 105 resource_scale_factor));
106 return; 106 return;
107 } 107 }
108 } 108 }
109 109
110 favicon_service->GetRawFaviconForPageURL( 110 favicon_service->GetRawFaviconForPageURL(
111 FaviconService::FaviconForPageURLParams( 111 FaviconService::FaviconForPageURLParams(
112 url, icon_types_, parsed.size_in_dip), 112 url, icon_types_, parsed.size_in_dip),
113 scale_factor, 113 parsed.device_scale_factor,
114 base::Bind( 114 base::Bind(
115 &FaviconSource::OnFaviconDataAvailable, 115 &FaviconSource::OnFaviconDataAvailable,
116 base::Unretained(this), 116 base::Unretained(this),
117 IconRequest(callback, url, parsed.size_in_dip, scale_factor)), 117 IconRequest(
118 callback, url, parsed.size_in_dip, parsed.device_scale_factor)),
118 &cancelable_task_tracker_); 119 &cancelable_task_tracker_);
119 } 120 }
120 } 121 }
121 122
122 std::string FaviconSource::GetMimeType(const std::string&) const { 123 std::string FaviconSource::GetMimeType(const std::string&) const {
123 // We need to explicitly return a mime type, otherwise if the user tries to 124 // We need to explicitly return a mime type, otherwise if the user tries to
124 // drag the image they get no extension. 125 // drag the image they get no extension.
125 return "image/png"; 126 return "image/png";
126 } 127 }
127 128
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (bitmap_result.is_valid()) { 161 if (bitmap_result.is_valid()) {
161 // Forward the data along to the networking system. 162 // Forward the data along to the networking system.
162 request.callback.Run(bitmap_result.bitmap_data.get()); 163 request.callback.Run(bitmap_result.bitmap_data.get());
163 } else if (!HandleMissingResource(request)) { 164 } else if (!HandleMissingResource(request)) {
164 SendDefaultResponse(request); 165 SendDefaultResponse(request);
165 } 166 }
166 } 167 }
167 168
168 void FaviconSource::SendDefaultResponse( 169 void FaviconSource::SendDefaultResponse(
169 const content::URLDataSource::GotDataCallback& callback) { 170 const content::URLDataSource::GotDataCallback& callback) {
170 SendDefaultResponse( 171 SendDefaultResponse(IconRequest(callback, GURL(), 16, 1.0f));
171 IconRequest(callback, GURL(), 16, ui::SCALE_FACTOR_100P));
172 } 172 }
173 173
174 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { 174 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) {
175 int favicon_index; 175 int favicon_index;
176 int resource_id; 176 int resource_id;
177 switch (icon_request.size_in_dip) { 177 switch (icon_request.size_in_dip) {
178 case 64: 178 case 64:
179 favicon_index = SIZE_64; 179 favicon_index = SIZE_64;
180 resource_id = IDR_DEFAULT_FAVICON_64; 180 resource_id = IDR_DEFAULT_FAVICON_64;
181 break; 181 break;
182 case 32: 182 case 32:
183 favicon_index = SIZE_32; 183 favicon_index = SIZE_32;
184 resource_id = IDR_DEFAULT_FAVICON_32; 184 resource_id = IDR_DEFAULT_FAVICON_32;
185 break; 185 break;
186 default: 186 default:
187 favicon_index = SIZE_16; 187 favicon_index = SIZE_16;
188 resource_id = IDR_DEFAULT_FAVICON; 188 resource_id = IDR_DEFAULT_FAVICON;
189 break; 189 break;
190 } 190 }
191 base::RefCountedMemory* default_favicon = 191 base::RefCountedMemory* default_favicon =
192 default_favicons_[favicon_index].get(); 192 default_favicons_[favicon_index].get();
193 193
194 if (!default_favicon) { 194 if (!default_favicon) {
195 default_favicon = ResourceBundle::GetSharedInstance() 195 ui::ScaleFactor resource_scale_factor =
196 .LoadDataResourceBytesForScale(resource_id, 196 ui::GetSupportedScaleFactor(icon_request.device_scale_factor);
197 icon_request.scale_factor); 197 default_favicon =
198 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
199 resource_id, resource_scale_factor);
198 default_favicons_[favicon_index] = default_favicon; 200 default_favicons_[favicon_index] = default_favicon;
199 } 201 }
200 202
201 icon_request.callback.Run(default_favicon); 203 icon_request.callback.Run(default_favicon);
202 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698