Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/instant/instant_io_context.h" | 12 #include "chrome/browser/instant/instant_io_context.h" |
| 13 #include "chrome/browser/instant/instant_service.h" | |
| 14 #include "chrome/browser/instant/instant_service_factory.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "grit/locale_settings.h" | 17 #include "grit/locale_settings.h" |
| 16 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
| 17 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/layout.h" | 21 #include "ui/base/layout.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/webui/web_ui_util.h" | 23 #include "ui/webui/web_ui_util.h" |
| 22 | 24 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 75 |
| 74 FaviconSource::~FaviconSource() { | 76 FaviconSource::~FaviconSource() { |
| 75 } | 77 } |
| 76 | 78 |
| 77 std::string FaviconSource::GetSource() { | 79 std::string FaviconSource::GetSource() { |
| 78 return icon_types_ == history::FAVICON ? | 80 return icon_types_ == history::FAVICON ? |
| 79 chrome::kChromeUIFaviconHost : chrome::kChromeUITouchIconHost; | 81 chrome::kChromeUIFaviconHost : chrome::kChromeUITouchIconHost; |
| 80 } | 82 } |
| 81 | 83 |
| 82 void FaviconSource::StartDataRequest( | 84 void FaviconSource::StartDataRequest( |
| 83 const std::string& path, | 85 const std::string& raw_path, |
| 84 bool is_incognito, | 86 bool is_incognito, |
| 85 const content::URLDataSource::GotDataCallback& callback) { | 87 const content::URLDataSource::GotDataCallback& callback) { |
| 86 FaviconService* favicon_service = | 88 FaviconService* favicon_service = |
| 87 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 89 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 88 if (!favicon_service || path.empty()) { | 90 if (!favicon_service || raw_path.empty()) { |
| 89 SendDefaultResponse(callback); | 91 SendDefaultResponse(callback); |
| 90 return; | 92 return; |
| 91 } | 93 } |
| 92 | 94 |
| 95 // Translate to regular path if |raw_path| is of the form | |
| 96 // chrome-search://favicon/<rid>, where rid is a uint64. | |
|
Evan Stade
2013/03/12 01:30:23
nit: rid no longer makes sense here
dhollowa
2013/03/12 01:48:07
Done.
| |
| 97 std::string path = InstantService::MaybeTranslateInstantPathOnUI(profile_, | |
| 98 raw_path); | |
| 99 | |
| 93 DCHECK_EQ(16, gfx::kFaviconSize); | 100 DCHECK_EQ(16, gfx::kFaviconSize); |
| 94 int size_in_dip = 16; | 101 int size_in_dip = 16; |
| 95 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; | 102 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; |
| 96 | 103 |
| 97 size_t parsed_index = 0; | 104 size_t parsed_index = 0; |
| 98 if (HasSubstringAt(path, parsed_index, kLargestParameter)) { | 105 if (HasSubstringAt(path, parsed_index, kLargestParameter)) { |
| 99 parsed_index += strlen(kLargestParameter); | 106 parsed_index += strlen(kLargestParameter); |
| 100 size_in_dip = 0; | 107 size_in_dip = 0; |
| 101 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { | 108 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { |
| 102 parsed_index += strlen(kSizeParameter); | 109 parsed_index += strlen(kSizeParameter); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return "image/png"; | 219 return "image/png"; |
| 213 } | 220 } |
| 214 | 221 |
| 215 bool FaviconSource::ShouldReplaceExistingSource() const { | 222 bool FaviconSource::ShouldReplaceExistingSource() const { |
| 216 // Leave the existing DataSource in place, otherwise we'll drop any pending | 223 // Leave the existing DataSource in place, otherwise we'll drop any pending |
| 217 // requests on the floor. | 224 // requests on the floor. |
| 218 return false; | 225 return false; |
| 219 } | 226 } |
| 220 | 227 |
| 221 bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const { | 228 bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const { |
| 222 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | 229 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| 223 return InstantIOContext::ShouldServiceRequest(request); | 230 return InstantService::IsInstantPath(request->url()) && |
| 231 InstantIOContext::ShouldServiceRequest(request); | |
| 232 } | |
| 224 return URLDataSource::ShouldServiceRequest(request); | 233 return URLDataSource::ShouldServiceRequest(request); |
| 225 } | 234 } |
| 226 | 235 |
| 227 bool FaviconSource::HandleMissingResource(const IconRequest& request) { | 236 bool FaviconSource::HandleMissingResource(const IconRequest& request) { |
| 228 // No additional checks to locate the favicon resource in the base | 237 // No additional checks to locate the favicon resource in the base |
| 229 // implementation. | 238 // implementation. |
| 230 return false; | 239 return false; |
| 231 } | 240 } |
| 232 | 241 |
| 233 void FaviconSource::OnFaviconDataAvailable( | 242 void FaviconSource::OnFaviconDataAvailable( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 279 |
| 271 if (!default_favicon) { | 280 if (!default_favicon) { |
| 272 ui::ScaleFactor scale_factor = icon_request.scale_factor; | 281 ui::ScaleFactor scale_factor = icon_request.scale_factor; |
| 273 default_favicon = ResourceBundle::GetSharedInstance() | 282 default_favicon = ResourceBundle::GetSharedInstance() |
| 274 .LoadDataResourceBytesForScale(resource_id, scale_factor); | 283 .LoadDataResourceBytesForScale(resource_id, scale_factor); |
| 275 default_favicons_[favicon_index] = default_favicon; | 284 default_favicons_[favicon_index] = default_favicon; |
| 276 } | 285 } |
| 277 | 286 |
| 278 icon_request.callback.Run(default_favicon); | 287 icon_request.callback.Run(default_favicon); |
| 279 } | 288 } |
| OLD | NEW |