OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/dom_ui_favicon_source.h" | 5 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "grit/app_resources.h" | 12 #include "grit/app_resources.h" |
13 | 13 |
14 DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) | 14 DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) |
15 : DataSource(chrome::kChromeUIFavIconHost, MessageLoop::current()), | 15 : DataSource(chrome::kChromeUIFavIconHost, MessageLoop::current()), |
16 profile_(profile) { | 16 profile_(profile) { |
17 } | 17 } |
18 | 18 |
19 DOMUIFavIconSource::~DOMUIFavIconSource() { | 19 DOMUIFavIconSource::~DOMUIFavIconSource() { |
20 } | 20 } |
21 | 21 |
22 void DOMUIFavIconSource::StartDataRequest(const std::string& path, | 22 void DOMUIFavIconSource::StartDataRequest(const std::string& path, |
23 bool is_off_the_record, | 23 bool is_off_the_record, |
24 int request_id) { | 24 int request_id) { |
25 FaviconService* favicon_service = | 25 FaviconService* favicon_service = |
26 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 26 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
27 if (favicon_service) { | 27 if (favicon_service) { |
28 FaviconService::Handle handle; | 28 FaviconService::Handle handle; |
| 29 if (path.empty()) { |
| 30 SendDefaultResponse(request_id); |
| 31 return; |
| 32 } |
| 33 |
29 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { | 34 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { |
30 handle = favicon_service->GetFavicon( | 35 handle = favicon_service->GetFavicon( |
31 GURL(path.substr(8)), | 36 GURL(path.substr(8)), |
32 &cancelable_consumer_, | 37 &cancelable_consumer_, |
33 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); | 38 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); |
34 } else { | 39 } else { |
35 handle = favicon_service->GetFaviconForURL( | 40 handle = favicon_service->GetFaviconForURL( |
36 GURL(path), | 41 GURL(path), |
37 &cancelable_consumer_, | 42 &cancelable_consumer_, |
38 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); | 43 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); |
(...skipping 19 matching lines...) Expand all Loading... |
58 GURL icon_url) { | 63 GURL icon_url) { |
59 FaviconService* favicon_service = | 64 FaviconService* favicon_service = |
60 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 65 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
61 int request_id = cancelable_consumer_.GetClientData(favicon_service, | 66 int request_id = cancelable_consumer_.GetClientData(favicon_service, |
62 request_handle); | 67 request_handle); |
63 | 68 |
64 if (know_favicon && data.get() && data->size()) { | 69 if (know_favicon && data.get() && data->size()) { |
65 // Forward the data along to the networking system. | 70 // Forward the data along to the networking system. |
66 SendResponse(request_id, data); | 71 SendResponse(request_id, data); |
67 } else { | 72 } else { |
68 if (!default_favicon_.get()) { | 73 SendDefaultResponse(request_id); |
69 default_favicon_ = | |
70 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | |
71 IDR_DEFAULT_FAVICON); | |
72 } | |
73 | |
74 SendResponse(request_id, default_favicon_); | |
75 } | 74 } |
76 } | 75 } |
| 76 |
| 77 void DOMUIFavIconSource::SendDefaultResponse(int request_id) { |
| 78 if (!default_favicon_.get()) { |
| 79 default_favicon_ = |
| 80 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 81 IDR_DEFAULT_FAVICON); |
| 82 } |
| 83 |
| 84 SendResponse(request_id, default_favicon_); |
| 85 } |
OLD | NEW |