| 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/fav_icon_helper.h" | 5 #include "chrome/browser/fav_icon_helper.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 FaviconService* FavIconHelper::GetFaviconService() { | 71 FaviconService* FavIconHelper::GetFaviconService() { |
| 72 return profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 72 return profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void FavIconHelper::SetFavIcon( | 75 void FavIconHelper::SetFavIcon( |
| 76 const GURL& url, | 76 const GURL& url, |
| 77 const GURL& image_url, | 77 const GURL& image_url, |
| 78 const SkBitmap& image) { | 78 const SkBitmap& image) { |
| 79 const SkBitmap& sized_image = | 79 const SkBitmap& sized_image = |
| 80 (image.width() == kFavIconSize && image.height() == kFavIconSize) | 80 (image.width() == kFaviconSize && image.height() == kFaviconSize) |
| 81 ? image : ConvertToFavIconSize(image); | 81 ? image : ConvertToFavIconSize(image); |
| 82 | 82 |
| 83 if (GetFaviconService() && ShouldSaveFavicon(url)) { | 83 if (GetFaviconService() && ShouldSaveFavicon(url)) { |
| 84 std::vector<unsigned char> image_data; | 84 std::vector<unsigned char> image_data; |
| 85 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); | 85 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); |
| 86 GetFaviconService()->SetFavicon(url, image_url, image_data); | 86 GetFaviconService()->SetFavicon(url, image_url, image_data); |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (url == url_) { | 89 if (url == url_) { |
| 90 NavigationEntry* entry = GetEntry(); | 90 NavigationEntry* entry = GetEntry(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DownloadFavIconOrAskHistory(entry); | 220 DownloadFavIconOrAskHistory(entry); |
| 221 } | 221 } |
| 222 // else we haven't got the icon url. When we get it we'll ask the | 222 // else we haven't got the icon url. When we get it we'll ask the |
| 223 // renderer to download the icon. | 223 // renderer to download the icon. |
| 224 } | 224 } |
| 225 | 225 |
| 226 void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { | 226 void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { |
| 227 DCHECK(entry); // We should only get here if entry is valid. | 227 DCHECK(entry); // We should only get here if entry is valid. |
| 228 if (fav_icon_expired_) { | 228 if (fav_icon_expired_) { |
| 229 // We have the mapping, but the favicon is out of date. Download it now. | 229 // We have the mapping, but the favicon is out of date. Download it now. |
| 230 ScheduleDownload(entry->url(), entry->favicon().url(), kFavIconSize, NULL); | 230 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); |
| 231 } else if (GetFaviconService()) { | 231 } else if (GetFaviconService()) { |
| 232 // We don't know the favicon, but we may have previously downloaded the | 232 // We don't know the favicon, but we may have previously downloaded the |
| 233 // favicon for another page that shares the same favicon. Ask for the | 233 // favicon for another page that shares the same favicon. Ask for the |
| 234 // favicon given the favicon URL. | 234 // favicon given the favicon URL. |
| 235 if (profile()->IsOffTheRecord()) { | 235 if (profile()->IsOffTheRecord()) { |
| 236 GetFaviconService()->GetFavicon( | 236 GetFaviconService()->GetFavicon( |
| 237 entry->favicon().url(), | 237 entry->favicon().url(), |
| 238 &cancelable_consumer_, | 238 &cancelable_consumer_, |
| 239 NewCallback(this, &FavIconHelper::OnFavIconData)); | 239 NewCallback(this, &FavIconHelper::OnFavIconData)); |
| 240 } else { | 240 } else { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 267 | 267 |
| 268 if (know_favicon && data.get() && data->size()) { | 268 if (know_favicon && data.get() && data->size()) { |
| 269 // There is a favicon, set it now. If expired we'll download the current | 269 // There is a favicon, set it now. If expired we'll download the current |
| 270 // one again, but at least the user will get some icon instead of the | 270 // one again, but at least the user will get some icon instead of the |
| 271 // default and most likely the current one is fine anyway. | 271 // default and most likely the current one is fine anyway. |
| 272 UpdateFavIcon(entry, data); | 272 UpdateFavIcon(entry, data); |
| 273 } | 273 } |
| 274 | 274 |
| 275 if (!know_favicon || expired) { | 275 if (!know_favicon || expired) { |
| 276 // We don't know the favicon, or it is out of date. Request the current one. | 276 // We don't know the favicon, or it is out of date. Request the current one. |
| 277 ScheduleDownload(entry->url(), entry->favicon().url(), kFavIconSize, NULL); | 277 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 int FavIconHelper::ScheduleDownload(const GURL& url, | 281 int FavIconHelper::ScheduleDownload(const GURL& url, |
| 282 const GURL& image_url, | 282 const GURL& image_url, |
| 283 int image_size, | 283 int image_size, |
| 284 ImageDownloadCallback* callback) { | 284 ImageDownloadCallback* callback) { |
| 285 const int download_id = tab_contents()->render_view_host()->DownloadFavIcon( | 285 const int download_id = tab_contents()->render_view_host()->DownloadFavIcon( |
| 286 image_url, image_size); | 286 image_url, image_size); |
| 287 | 287 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 307 } | 307 } |
| 308 | 308 |
| 309 bool FavIconHelper::ShouldSaveFavicon(const GURL& url) { | 309 bool FavIconHelper::ShouldSaveFavicon(const GURL& url) { |
| 310 if (!profile()->IsOffTheRecord()) | 310 if (!profile()->IsOffTheRecord()) |
| 311 return true; | 311 return true; |
| 312 | 312 |
| 313 // Otherwise store the favicon if the page is bookmarked. | 313 // Otherwise store the favicon if the page is bookmarked. |
| 314 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); | 314 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); |
| 315 return bookmark_model && bookmark_model->IsBookmarked(url); | 315 return bookmark_model && bookmark_model->IsBookmarked(url); |
| 316 } | 316 } |
| OLD | NEW |