OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "grit/app_resources.h" | 10 #include "grit/app_resources.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (favicon_service) { | 26 if (favicon_service) { |
27 FaviconService::Handle handle; | 27 FaviconService::Handle handle; |
28 if (path.empty()) { | 28 if (path.empty()) { |
29 SendDefaultResponse(request_id); | 29 SendDefaultResponse(request_id); |
30 return; | 30 return; |
31 } | 31 } |
32 | 32 |
33 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { | 33 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { |
34 handle = favicon_service->GetFavicon( | 34 handle = favicon_service->GetFavicon( |
35 GURL(path.substr(8)), | 35 GURL(path.substr(8)), |
| 36 history::FAVICON, |
36 &cancelable_consumer_, | 37 &cancelable_consumer_, |
37 NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); | 38 NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); |
38 } else { | 39 } else { |
39 handle = favicon_service->GetFaviconForURL( | 40 handle = favicon_service->GetFaviconForURL( |
40 GURL(path), | 41 GURL(path), |
| 42 history::FAVICON, |
41 &cancelable_consumer_, | 43 &cancelable_consumer_, |
42 NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); | 44 NewCallback(this, &FaviconSource::OnFaviconDataAvailable)); |
43 } | 45 } |
44 // Attach the ChromeURLDataManager request ID to the history request. | 46 // Attach the ChromeURLDataManager request ID to the history request. |
45 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 47 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
46 } else { | 48 } else { |
47 SendResponse(request_id, NULL); | 49 SendResponse(request_id, NULL); |
48 } | 50 } |
49 } | 51 } |
50 | 52 |
51 std::string FaviconSource::GetMimeType(const std::string&) const { | 53 std::string FaviconSource::GetMimeType(const std::string&) const { |
52 // We need to explicitly return a mime type, otherwise if the user tries to | 54 // We need to explicitly return a mime type, otherwise if the user tries to |
53 // drag the image they get no extension. | 55 // drag the image they get no extension. |
54 return "image/png"; | 56 return "image/png"; |
55 } | 57 } |
56 | 58 |
57 bool FaviconSource::ShouldReplaceExistingSource() const { | 59 bool FaviconSource::ShouldReplaceExistingSource() const { |
58 // Leave the existing DataSource in place, otherwise we'll drop any pending | 60 // Leave the existing DataSource in place, otherwise we'll drop any pending |
59 // requests on the floor. | 61 // requests on the floor. |
60 return false; | 62 return false; |
61 } | 63 } |
62 | 64 |
63 void FaviconSource::OnFaviconDataAvailable( | 65 void FaviconSource::OnFaviconDataAvailable( |
64 FaviconService::Handle request_handle, | 66 FaviconService::Handle request_handle, |
65 bool know_favicon, | 67 history::FaviconData favicon) { |
66 scoped_refptr<RefCountedMemory> data, | |
67 bool expired, | |
68 GURL icon_url) { | |
69 FaviconService* favicon_service = | 68 FaviconService* favicon_service = |
70 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 69 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
71 int request_id = cancelable_consumer_.GetClientData(favicon_service, | 70 int request_id = cancelable_consumer_.GetClientData(favicon_service, |
72 request_handle); | 71 request_handle); |
73 | 72 |
74 if (know_favicon && data.get() && data->size()) { | 73 if (favicon.is_valid()) { |
75 // Forward the data along to the networking system. | 74 // Forward the data along to the networking system. |
76 SendResponse(request_id, data); | 75 SendResponse(request_id, favicon.image_data); |
77 } else { | 76 } else { |
78 SendDefaultResponse(request_id); | 77 SendDefaultResponse(request_id); |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
82 void FaviconSource::SendDefaultResponse(int request_id) { | 81 void FaviconSource::SendDefaultResponse(int request_id) { |
83 if (!default_favicon_.get()) { | 82 if (!default_favicon_.get()) { |
84 default_favicon_ = | 83 default_favicon_ = |
85 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 84 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
86 IDR_DEFAULT_FAVICON); | 85 IDR_DEFAULT_FAVICON); |
87 } | 86 } |
88 | 87 |
89 SendResponse(request_id, default_favicon_); | 88 SendResponse(request_id, default_favicon_); |
90 } | 89 } |
OLD | NEW |