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/favicon/favicon_service.h" | 5 #include "chrome/browser/favicon/favicon_service.h" |
6 | 6 |
7 #include "chrome/browser/favicon/favicon_util.h" | 7 #include "chrome/browser/favicon/favicon_util.h" |
8 #include "chrome/browser/history/history.h" | 8 #include "chrome/browser/history/history.h" |
9 #include "chrome/browser/history/history_backend.h" | 9 #include "chrome/browser/history/history_backend.h" |
10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 std::vector<GURL> icon_urls; | 83 std::vector<GURL> icon_urls; |
84 icon_urls.push_back(icon_url); | 84 icon_urls.push_back(icon_url); |
85 history_service_->GetFavicons(request, icon_urls, icon_type, | 85 history_service_->GetFavicons(request, icon_urls, icon_type, |
86 desired_size_in_dip, desired_scale_factors); | 86 desired_size_in_dip, desired_scale_factors); |
87 } else { | 87 } else { |
88 ForwardEmptyResultAsync(request); | 88 ForwardEmptyResultAsync(request); |
89 } | 89 } |
90 return request->handle(); | 90 return request->handle(); |
91 } | 91 } |
92 | 92 |
93 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( | 93 FaviconService::Handle FaviconService::UpdateFaviconMappingsAndFetch( |
94 const GURL& page_url, | 94 const GURL& page_url, |
95 const GURL& icon_url, | 95 const std::vector<GURL>& icon_urls, |
96 history::IconType icon_type, | 96 int icon_types, |
| 97 int desired_size_in_dip, |
| 98 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
97 CancelableRequestConsumerBase* consumer, | 99 CancelableRequestConsumerBase* consumer, |
98 const FaviconResultsCallback& callback) { | 100 const FaviconResultsCallback& callback) { |
99 GetFaviconRequest* request = new GetFaviconRequest(callback); | 101 GetFaviconRequest* request = new GetFaviconRequest(callback); |
100 AddRequest(request, consumer); | 102 AddRequest(request, consumer); |
101 if (history_service_) { | 103 if (history_service_) { |
102 std::vector<GURL> icon_urls; | |
103 icon_urls.push_back(icon_url); | |
104 // TODO(pkotwicz): Pass in |desired_size_in_dip| and |desired_scale_factors| | |
105 // from FaviconHandler. | |
106 history_service_->UpdateFaviconMappingsAndFetch(request, page_url, | 104 history_service_->UpdateFaviconMappingsAndFetch(request, page_url, |
107 icon_urls, icon_type, gfx::kFaviconSize, | 105 icon_urls, icon_types, desired_size_in_dip, desired_scale_factors); |
108 ui::GetSupportedScaleFactors()); | |
109 } else { | 106 } else { |
110 ForwardEmptyResultAsync(request); | 107 ForwardEmptyResultAsync(request); |
111 } | 108 } |
112 return request->handle(); | 109 return request->handle(); |
113 } | 110 } |
114 | 111 |
115 FaviconService::Handle FaviconService::GetFaviconImageForURL( | 112 FaviconService::Handle FaviconService::GetFaviconImageForURL( |
116 const FaviconForURLParams& params, | 113 const FaviconForURLParams& params, |
117 const FaviconImageCallback& callback) { | 114 const FaviconImageCallback& callback) { |
118 GetFaviconRequest* request = new GetFaviconRequest(base::Bind( | 115 GetFaviconRequest* request = new GetFaviconRequest(base::Bind( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (history_service_) | 183 if (history_service_) |
187 history_service_->CloneFavicons(old_page_url, new_page_url); | 184 history_service_->CloneFavicons(old_page_url, new_page_url); |
188 } | 185 } |
189 | 186 |
190 void FaviconService::SetImportedFavicons( | 187 void FaviconService::SetImportedFavicons( |
191 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { | 188 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { |
192 if (history_service_) | 189 if (history_service_) |
193 history_service_->SetImportedFavicons(favicon_usage); | 190 history_service_->SetImportedFavicons(favicon_usage); |
194 } | 191 } |
195 | 192 |
196 void FaviconService::SetFavicon(const GURL& page_url, | 193 void FaviconService::MergeFavicon( |
197 const GURL& icon_url, | 194 const GURL& page_url, |
198 const std::vector<unsigned char>& image_data, | 195 const GURL& icon_url, |
199 history::IconType icon_type) { | 196 history::IconType icon_type, |
| 197 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 198 const gfx::Size& pixel_size) { |
200 if (history_service_) { | 199 if (history_service_) { |
201 // TODO(pkotwicz): Pass in the real pixel size of |image_data|. | 200 history_service_->MergeFavicon(page_url, icon_url, icon_type, bitmap_data, |
202 history::FaviconBitmapData bitmap_data_element; | 201 pixel_size); |
203 bitmap_data_element.bitmap_data = new base::RefCountedBytes(image_data); | |
204 bitmap_data_element.pixel_size = gfx::Size(); | |
205 bitmap_data_element.icon_url = icon_url; | |
206 std::vector<history::FaviconBitmapData> favicon_bitmap_data; | |
207 favicon_bitmap_data.push_back(bitmap_data_element); | |
208 history::FaviconSizes favicon_sizes; | |
209 favicon_sizes.push_back(gfx::Size()); | |
210 history::IconURLSizesMap icon_url_sizes; | |
211 icon_url_sizes[icon_url] = favicon_sizes; | |
212 history_service_->SetFavicons(page_url, icon_type, | |
213 favicon_bitmap_data, icon_url_sizes); | |
214 } | 202 } |
215 } | 203 } |
216 | 204 |
| 205 void FaviconService::SetFavicons( |
| 206 const GURL& page_url, |
| 207 const GURL& icon_url, |
| 208 history::IconType icon_type, |
| 209 const gfx::Image& image) { |
| 210 if (!history_service_) |
| 211 return; |
| 212 |
| 213 gfx::ImageSkia image_skia = image.AsImageSkia(); |
| 214 image_skia.EnsureRepsForSupportedScaleFactors(); |
| 215 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); |
| 216 std::vector<history::FaviconBitmapData> favicon_bitmap_data; |
| 217 history::FaviconSizes favicon_sizes; |
| 218 for (size_t i = 0; i < image_reps.size(); ++i) { |
| 219 scoped_refptr<base::RefCountedBytes> bitmap_data( |
| 220 new base::RefCountedBytes()); |
| 221 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_reps[i].sk_bitmap(), |
| 222 false, |
| 223 &bitmap_data->data())) { |
| 224 gfx::Size pixel_size(image_reps[i].pixel_width(), |
| 225 image_reps[i].pixel_height()); |
| 226 history::FaviconBitmapData bitmap_data_element; |
| 227 bitmap_data_element.bitmap_data = bitmap_data; |
| 228 bitmap_data_element.pixel_size = pixel_size; |
| 229 bitmap_data_element.icon_url = icon_url; |
| 230 |
| 231 favicon_bitmap_data.push_back(bitmap_data_element); |
| 232 |
| 233 // Construct favicon sizes from a guess at what the HTML 5 'sizes' |
| 234 // attribute in the link tag is. |
| 235 // TODO(pkotwicz): Plumb the HTML 5 sizes attribute to FaviconHandler. |
| 236 favicon_sizes.push_back(pixel_size); |
| 237 } |
| 238 } |
| 239 |
| 240 // TODO(pkotwicz): Tell the database about all the icon URLs associated |
| 241 // with |page_url|. |
| 242 history::IconURLSizesMap icon_url_sizes; |
| 243 icon_url_sizes[icon_url] = favicon_sizes; |
| 244 |
| 245 history_service_->SetFavicons(page_url, icon_type, favicon_bitmap_data, |
| 246 icon_url_sizes); |
| 247 } |
| 248 |
217 FaviconService::~FaviconService() { | 249 FaviconService::~FaviconService() { |
218 } | 250 } |
219 | 251 |
220 FaviconService::Handle FaviconService::GetFaviconForURLImpl( | 252 FaviconService::Handle FaviconService::GetFaviconForURLImpl( |
221 const FaviconForURLParams& params, | 253 const FaviconForURLParams& params, |
222 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 254 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
223 GetFaviconRequest* request) { | 255 GetFaviconRequest* request) { |
224 AddRequest(request, params.consumer); | 256 AddRequest(request, params.consumer); |
225 FaviconService::Handle handle = request->handle(); | 257 FaviconService::Handle handle = request->handle(); |
226 if (params.page_url.SchemeIs(chrome::kChromeUIScheme) || | 258 if (params.page_url.SchemeIs(chrome::kChromeUIScheme) || |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( | 350 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( |
319 &resized_bitmap_data); | 351 &resized_bitmap_data); |
320 callback.Run(handle, bitmap_result); | 352 callback.Run(handle, bitmap_result); |
321 } | 353 } |
322 | 354 |
323 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { | 355 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { |
324 request->ForwardResultAsync(request->handle(), | 356 request->ForwardResultAsync(request->handle(), |
325 std::vector<history::FaviconBitmapResult>(), | 357 std::vector<history::FaviconBitmapResult>(), |
326 history::IconURLSizesMap()); | 358 history::IconURLSizesMap()); |
327 } | 359 } |
OLD | NEW |