| 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 "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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "grit/locale_settings.h" | 13 #include "grit/locale_settings.h" |
| 14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/layout.h" | 16 #include "ui/base/layout.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/favicon_size.h" |
| 18 | 19 |
| 19 FaviconSource::FaviconSource(Profile* profile, IconType type) | 20 FaviconSource::FaviconSource(Profile* profile, IconType type) |
| 20 : DataSource(type == FAVICON ? chrome::kChromeUIFaviconHost : | 21 : DataSource(type == FAVICON ? chrome::kChromeUIFaviconHost : |
| 21 chrome::kChromeUITouchIconHost, | 22 chrome::kChromeUITouchIconHost, |
| 22 MessageLoop::current()) { | 23 MessageLoop::current()) { |
| 23 Init(profile, type); | 24 Init(profile, type); |
| 24 } | 25 } |
| 25 | 26 |
| 26 FaviconSource::FaviconSource(Profile* profile, | 27 FaviconSource::FaviconSource(Profile* profile, |
| 27 IconType type, | 28 IconType type, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 FaviconService* favicon_service = | 47 FaviconService* favicon_service = |
| 47 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 48 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 48 if (!favicon_service || path.empty()) { | 49 if (!favicon_service || path.empty()) { |
| 49 SendDefaultResponse(request_id); | 50 SendDefaultResponse(request_id); |
| 50 return; | 51 return; |
| 51 } | 52 } |
| 52 | 53 |
| 53 FaviconService::Handle handle; | 54 FaviconService::Handle handle; |
| 54 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { | 55 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { |
| 55 // TODO : Change GetFavicon to support combination of IconType. | 56 // TODO : Change GetFavicon to support combination of IconType. |
| 56 handle = favicon_service->GetFavicon( | 57 handle = favicon_service->GetRawFavicon( |
| 57 GURL(path.substr(8)), | 58 GURL(path.substr(8)), |
| 58 history::FAVICON, | 59 history::FAVICON, |
| 60 gfx::kFaviconSize, |
| 61 ui::SCALE_FACTOR_100P, |
| 59 &cancelable_consumer_, | 62 &cancelable_consumer_, |
| 60 base::Bind(&FaviconSource::OnFaviconDataAvailable, | 63 base::Bind(&FaviconSource::OnFaviconDataAvailable, |
| 61 base::Unretained(this))); | 64 base::Unretained(this))); |
| 62 } else { | 65 } else { |
| 63 GURL url; | 66 GURL url; |
| 64 | 67 |
| 65 if (path.size() > 5 && path.substr(0, 5) == "size/") { | 68 if (path.size() > 5 && path.substr(0, 5) == "size/") { |
| 66 size_t slash = path.find("/", 5); | 69 size_t slash = path.find("/", 5); |
| 67 std::string size = path.substr(5, slash - 5); | 70 std::string size = path.substr(5, slash - 5); |
| 68 int pixel_size = atoi(size.c_str()); | 71 int pixel_size = atoi(size.c_str()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 98 request_size_map_.erase(request_id); | 101 request_size_map_.erase(request_id); |
| 99 SendResponse(request_id, | 102 SendResponse(request_id, |
| 100 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 103 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 101 history::kPrepopulatedPages[i].favicon_id, | 104 history::kPrepopulatedPages[i].favicon_id, |
| 102 ui::SCALE_FACTOR_100P)); | 105 ui::SCALE_FACTOR_100P)); |
| 103 return; | 106 return; |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 // TODO(estade): fetch the requested size. | 110 // TODO(estade): fetch the requested size. |
| 108 handle = favicon_service->GetFaviconForURL( | 111 handle = favicon_service->GetRawFaviconForURL( |
| 109 profile_, | 112 profile_, |
| 110 url, | 113 url, |
| 111 icon_types_, | 114 icon_types_, |
| 115 gfx::kFaviconSize, |
| 116 ui::SCALE_FACTOR_100P, |
| 112 &cancelable_consumer_, | 117 &cancelable_consumer_, |
| 113 base::Bind(&FaviconSource::OnFaviconDataAvailable, | 118 base::Bind(&FaviconSource::OnFaviconDataAvailable, |
| 114 base::Unretained(this))); | 119 base::Unretained(this))); |
| 115 } | 120 } |
| 116 | 121 |
| 117 // Attach the ChromeURLDataManager request ID to the history request. | 122 // Attach the ChromeURLDataManager request ID to the history request. |
| 118 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 123 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 119 } | 124 } |
| 120 | 125 |
| 121 std::string FaviconSource::GetMimeType(const std::string&) const { | 126 std::string FaviconSource::GetMimeType(const std::string&) const { |
| 122 // We need to explicitly return a mime type, otherwise if the user tries to | 127 // We need to explicitly return a mime type, otherwise if the user tries to |
| 123 // drag the image they get no extension. | 128 // drag the image they get no extension. |
| 124 return "image/png"; | 129 return "image/png"; |
| 125 } | 130 } |
| 126 | 131 |
| 127 bool FaviconSource::ShouldReplaceExistingSource() const { | 132 bool FaviconSource::ShouldReplaceExistingSource() const { |
| 128 // Leave the existing DataSource in place, otherwise we'll drop any pending | 133 // Leave the existing DataSource in place, otherwise we'll drop any pending |
| 129 // requests on the floor. | 134 // requests on the floor. |
| 130 return false; | 135 return false; |
| 131 } | 136 } |
| 132 | 137 |
| 133 void FaviconSource::OnFaviconDataAvailable( | 138 void FaviconSource::OnFaviconDataAvailable( |
| 134 FaviconService::Handle request_handle, | 139 FaviconService::Handle request_handle, |
| 135 history::FaviconData favicon) { | 140 const history::FaviconBitmapResult& bitmap_result) { |
| 136 FaviconService* favicon_service = | 141 FaviconService* favicon_service = |
| 137 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 142 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 138 int request_id = cancelable_consumer_.GetClientData(favicon_service, | 143 int request_id = cancelable_consumer_.GetClientData(favicon_service, |
| 139 request_handle); | 144 request_handle); |
| 140 | 145 |
| 141 if (favicon.is_valid()) { | 146 if (bitmap_result.is_valid()) { |
| 142 // Forward the data along to the networking system. | 147 // Forward the data along to the networking system. |
| 143 SendResponse(request_id, favicon.image_data); | 148 SendResponse(request_id, bitmap_result.bitmap_data); |
| 144 } else { | 149 } else { |
| 145 SendDefaultResponse(request_id); | 150 SendDefaultResponse(request_id); |
| 146 } | 151 } |
| 147 } | 152 } |
| 148 | 153 |
| 149 void FaviconSource::SendDefaultResponse(int request_id) { | 154 void FaviconSource::SendDefaultResponse(int request_id) { |
| 150 base::RefCountedMemory* bytes = NULL; | 155 base::RefCountedMemory* bytes = NULL; |
| 151 if (request_size_map_[request_id] == 32) { | 156 if (request_size_map_[request_id] == 32) { |
| 152 if (!default_favicon_large_.get()) { | 157 if (!default_favicon_large_.get()) { |
| 153 default_favicon_large_ = | 158 default_favicon_large_ = |
| 154 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 159 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 155 IDR_DEFAULT_LARGE_FAVICON, ui::SCALE_FACTOR_100P); | 160 IDR_DEFAULT_LARGE_FAVICON, ui::SCALE_FACTOR_100P); |
| 156 } | 161 } |
| 157 bytes = default_favicon_large_; | 162 bytes = default_favicon_large_; |
| 158 } else { | 163 } else { |
| 159 if (!default_favicon_.get()) { | 164 if (!default_favicon_.get()) { |
| 160 default_favicon_ = | 165 default_favicon_ = |
| 161 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 166 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 162 IDR_DEFAULT_FAVICON, ui::SCALE_FACTOR_100P); | 167 IDR_DEFAULT_FAVICON, ui::SCALE_FACTOR_100P); |
| 163 } | 168 } |
| 164 bytes = default_favicon_; | 169 bytes = default_favicon_; |
| 165 } | 170 } |
| 166 request_size_map_.erase(request_id); | 171 request_size_map_.erase(request_id); |
| 167 | 172 |
| 168 SendResponse(request_id, bytes); | 173 SendResponse(request_id, bytes); |
| 169 } | 174 } |
| OLD | NEW |