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

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

Issue 11762004: Make favicons for about:history and about:bookmarks switch from lodpi to hidpi when dragging browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 "chrome/browser/favicon/favicon_service_factory.h" 9 #include "chrome/browser/favicon/favicon_service_factory.h"
10 #include "chrome/browser/history/top_sites.h" 10 #include "chrome/browser/history/top_sites.h"
(...skipping 29 matching lines...) Expand all
40 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON | 40 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON |
41 history::FAVICON; 41 history::FAVICON;
42 } 42 }
43 43
44 void FaviconSource::StartDataRequest(const std::string& path, 44 void FaviconSource::StartDataRequest(const std::string& path,
45 bool is_incognito, 45 bool is_incognito,
46 int request_id) { 46 int request_id) {
47 FaviconService* favicon_service = 47 FaviconService* favicon_service =
48 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 48 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
49 if (!favicon_service || path.empty()) { 49 if (!favicon_service || path.empty()) {
50 SendDefaultResponse(IconRequest(request_id, 16, ui::SCALE_FACTOR_100P)); 50 SendDefaultResponse(IconRequest(request_id,
51 "",
52 16,
53 ui::SCALE_FACTOR_100P));
51 return; 54 return;
52 } 55 }
53 56
54 int size_in_dip = gfx::kFaviconSize; 57 int size_in_dip = gfx::kFaviconSize;
55 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; 58 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P;
56 59
57 if (path.size() > 8 && 60 if (path.size() > 8 &&
58 (path.substr(0, 8) == "iconurl/" || path.substr(0, 8) == "iconurl@")) { 61 (path.substr(0, 8) == "iconurl/" || path.substr(0, 8) == "iconurl@")) {
59 size_t prefix_length = 8; 62 size_t prefix_length = 8;
60 // Optional scale factor appended to iconurl, which may be @1x or @2x. 63 // Optional scale factor appended to iconurl, which may be @1x or @2x.
61 if (path.at(7) == '@') { 64 if (path.at(7) == '@') {
62 size_t slash = path.find("/"); 65 size_t slash = path.find("/");
63 std::string scale_str = path.substr(8, slash - 8); 66 std::string scale_str = path.substr(8, slash - 8);
64 web_ui_util::ParseScaleFactor(scale_str, &scale_factor); 67 web_ui_util::ParseScaleFactor(scale_str, &scale_factor);
65 prefix_length = slash + 1; 68 prefix_length = slash + 1;
66 } 69 }
67 // TODO(michaelbai): Change GetRawFavicon to support combination of 70 // TODO(michaelbai): Change GetRawFavicon to support combination of
68 // IconType. 71 // IconType.
69 favicon_service->GetRawFavicon( 72 favicon_service->GetRawFavicon(
70 GURL(path.substr(prefix_length)), 73 GURL(path.substr(prefix_length)),
71 history::FAVICON, 74 history::FAVICON,
72 size_in_dip, 75 size_in_dip,
73 scale_factor, 76 scale_factor,
74 base::Bind(&FaviconSource::OnFaviconDataAvailable, 77 base::Bind(&FaviconSource::OnFaviconDataAvailable,
75 base::Unretained(this), 78 base::Unretained(this),
76 IconRequest(request_id, size_in_dip, scale_factor)), 79 IconRequest(request_id,
80 path.substr(prefix_length),
81 size_in_dip,
82 scale_factor)),
77 &cancelable_task_tracker_); 83 &cancelable_task_tracker_);
78 } else { 84 } else {
79 GURL url; 85 GURL url;
80 if (path.size() > 5 && path.substr(0, 5) == "size/") { 86 if (path.size() > 5 && path.substr(0, 5) == "size/") {
81 size_t slash = path.find("/", 5); 87 size_t slash = path.find("/", 5);
82 size_t scale_delimiter = path.find("@", 5); 88 size_t scale_delimiter = path.find("@", 5);
83 std::string size = path.substr(5, slash - 5); 89 std::string size = path.substr(5, slash - 5);
84 size_in_dip = atoi(size.c_str()); 90 size_in_dip = atoi(size.c_str());
85 if (size_in_dip != 64 && size_in_dip != 32 && size_in_dip != 16) { 91 if (size_in_dip != 64 && size_in_dip != 32 && size_in_dip != 16) {
86 // Only 64x64, 32x32 and 16x16 icons are supported. 92 // Only 64x64, 32x32 and 16x16 icons are supported.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return; 130 return;
125 } 131 }
126 } 132 }
127 133
128 favicon_service->GetRawFaviconForURL( 134 favicon_service->GetRawFaviconForURL(
129 FaviconService::FaviconForURLParams( 135 FaviconService::FaviconForURLParams(
130 profile_, url, icon_types_, size_in_dip), 136 profile_, url, icon_types_, size_in_dip),
131 scale_factor, 137 scale_factor,
132 base::Bind(&FaviconSource::OnFaviconDataAvailable, 138 base::Bind(&FaviconSource::OnFaviconDataAvailable,
133 base::Unretained(this), 139 base::Unretained(this),
134 IconRequest(request_id, size_in_dip, scale_factor)), 140 IconRequest(request_id,
141 url.spec(),
142 size_in_dip,
143 scale_factor)),
135 &cancelable_task_tracker_); 144 &cancelable_task_tracker_);
136 } 145 }
137 } 146 }
138 147
139 std::string FaviconSource::GetMimeType(const std::string&) const { 148 std::string FaviconSource::GetMimeType(const std::string&) const {
140 // We need to explicitly return a mime type, otherwise if the user tries to 149 // We need to explicitly return a mime type, otherwise if the user tries to
141 // drag the image they get no extension. 150 // drag the image they get no extension.
142 return "image/png"; 151 return "image/png";
143 } 152 }
144 153
145 bool FaviconSource::ShouldReplaceExistingSource() const { 154 bool FaviconSource::ShouldReplaceExistingSource() const {
146 // Leave the existing DataSource in place, otherwise we'll drop any pending 155 // Leave the existing DataSource in place, otherwise we'll drop any pending
147 // requests on the floor. 156 // requests on the floor.
148 return false; 157 return false;
149 } 158 }
150 159
160 bool FaviconSource::HandleMissingResource(const IconRequest& request) {
161 // No additional checks to locate the favicon resource in the base
162 // implementation.
163 return false;
164 }
165
151 void FaviconSource::OnFaviconDataAvailable( 166 void FaviconSource::OnFaviconDataAvailable(
152 const IconRequest& request, 167 const IconRequest& request,
153 const history::FaviconBitmapResult& bitmap_result) { 168 const history::FaviconBitmapResult& bitmap_result) {
154 if (bitmap_result.is_valid()) { 169 if (bitmap_result.is_valid()) {
155 // Forward the data along to the networking system. 170 // Forward the data along to the networking system.
156 SendResponse(request.request_id, bitmap_result.bitmap_data); 171 SendResponse(request.request_id, bitmap_result.bitmap_data);
157 } else { 172 } else if (!HandleMissingResource(request)) {
158 SendDefaultResponse(request); 173 SendDefaultResponse(request);
159 } 174 }
160 } 175 }
161 176
162 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { 177 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) {
163 int favicon_index; 178 int favicon_index;
164 int resource_id; 179 int resource_id;
165 switch (icon_request.size_in_dip) { 180 switch (icon_request.size_in_dip) {
166 case 64: 181 case 64:
167 favicon_index = SIZE_64; 182 favicon_index = SIZE_64;
(...skipping 12 matching lines...) Expand all
180 195
181 if (!default_favicon) { 196 if (!default_favicon) {
182 ui::ScaleFactor scale_factor = icon_request.scale_factor; 197 ui::ScaleFactor scale_factor = icon_request.scale_factor;
183 default_favicon = ResourceBundle::GetSharedInstance() 198 default_favicon = ResourceBundle::GetSharedInstance()
184 .LoadDataResourceBytesForScale(resource_id, scale_factor); 199 .LoadDataResourceBytesForScale(resource_id, scale_factor);
185 default_favicons_[favicon_index] = default_favicon; 200 default_favicons_[favicon_index] = default_favicon;
186 } 201 }
187 202
188 SendResponse(icon_request.request_id, default_favicon); 203 SendResponse(icon_request.request_id, default_favicon);
189 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698