Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Side by Side Diff: chrome/browser/favicon/favicon_handler.cc

Issue 10912088: favicon handler: Consider all frames when receiving favicons from the history db (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_handler.h" 5 #include "chrome/browser/favicon/favicon_handler.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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "chrome/browser/bookmarks/bookmark_model.h" 14 #include "chrome/browser/bookmarks/bookmark_model.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/favicon/favicon_service_factory.h" 16 #include "chrome/browser/favicon/favicon_service_factory.h"
17 #include "chrome/browser/favicon/favicon_util.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/icon_messages.h" 19 #include "chrome/common/icon_messages.h"
19 #include "content/public/browser/favicon_status.h" 20 #include "content/public/browser/favicon_status.h"
20 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
21 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
22 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/image/image_util.h" 26 #include "ui/gfx/image/image_util.h"
25 27
26 using content::NavigationEntry; 28 using content::NavigationEntry;
27 29
28 namespace { 30 namespace {
29 31
30 // Returns history::IconType the given icon_type corresponds to. 32 // Returns history::IconType the given icon_type corresponds to.
31 history::IconType ToHistoryIconType(FaviconURL::IconType icon_type) { 33 history::IconType ToHistoryIconType(FaviconURL::IconType icon_type) {
32 switch (icon_type) { 34 switch (icon_type) {
33 case FaviconURL::FAVICON: 35 case FaviconURL::FAVICON:
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (UrlMatches(url, url_) && icon_type == history::FAVICON) { 227 if (UrlMatches(url, url_) && icon_type == history::FAVICON) {
226 NavigationEntry* entry = GetEntry(); 228 NavigationEntry* entry = GetEntry();
227 if (entry) { 229 if (entry) {
228 entry->GetFavicon().url = image_url; 230 entry->GetFavicon().url = image_url;
229 UpdateFavicon(entry, &sized_image); 231 UpdateFavicon(entry, &sized_image);
230 } 232 }
231 } 233 }
232 } 234 }
233 235
234 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, 236 void FaviconHandler::UpdateFavicon(NavigationEntry* entry,
235 scoped_refptr<base::RefCountedMemory> data) { 237 const std::vector<history::FaviconBitmapResult>& favicon_bitmap_results) {
236 scoped_ptr<gfx::Image> image(gfx::ImageFromPNGEncodedData(data->front(), 238 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs(
237 data->size())); 239 favicon_bitmap_results,
238 UpdateFavicon(entry, image.get()); 240 ui::GetSupportedScaleFactors(),
241 preferred_icon_size());
242 if (!resized_image.IsEmpty())
243 UpdateFavicon(entry, &resized_image);
239 } 244 }
240 245
241 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, 246 void FaviconHandler::UpdateFavicon(NavigationEntry* entry,
242 const gfx::Image* image) { 247 const gfx::Image* image) {
243 // No matter what happens, we need to mark the favicon as being set. 248 // No matter what happens, we need to mark the favicon as being set.
244 entry->GetFavicon().valid = true; 249 entry->GetFavicon().valid = true;
245 250
246 if (!image) 251 if (!image)
247 return; 252 return;
248 253
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 !entry->GetFavicon().valid && 439 !entry->GetFavicon().valid &&
435 (!current_candidate() || 440 (!current_candidate() ||
436 DoUrlAndIconMatch(*current_candidate(), 441 DoUrlAndIconMatch(*current_candidate(),
437 bitmap_result.icon_url, bitmap_result.icon_type))) { 442 bitmap_result.icon_url, bitmap_result.icon_type))) {
438 // The db knows the favicon (although it may be out of date) and the entry 443 // The db knows the favicon (although it may be out of date) and the entry
439 // doesn't have an icon. Set the favicon now, and if the favicon turns out 444 // doesn't have an icon. Set the favicon now, and if the favicon turns out
440 // to be expired (or the wrong url) we'll fetch later on. This way the 445 // to be expired (or the wrong url) we'll fetch later on. This way the
441 // user doesn't see a flash of the default favicon. 446 // user doesn't see a flash of the default favicon.
442 entry->GetFavicon().url = bitmap_result.icon_url; 447 entry->GetFavicon().url = bitmap_result.icon_url;
443 if (bitmap_result.is_valid()) 448 if (bitmap_result.is_valid())
444 UpdateFavicon(entry, bitmap_result.bitmap_data); 449 UpdateFavicon(entry, favicon_bitmap_results);
445 entry->GetFavicon().valid = true; 450 entry->GetFavicon().valid = true;
446 } 451 }
447 452
448 if (has_results && !bitmap_result.expired) { 453 if (has_results && !bitmap_result.expired) {
449 if (current_candidate() && 454 if (current_candidate() &&
450 !DoUrlAndIconMatch(*current_candidate(), 455 !DoUrlAndIconMatch(*current_candidate(),
451 bitmap_result.icon_url, bitmap_result.icon_type)) { 456 bitmap_result.icon_url, bitmap_result.icon_type)) {
452 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will 457 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will
453 // update the mapping for this url and download the favicon if we don't 458 // update the mapping for this url and download the favicon if we don't
454 // already have it. 459 // already have it.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 if (has_results) 514 if (has_results)
510 bitmap_result = favicon_bitmap_results[0]; 515 bitmap_result = favicon_bitmap_results[0];
511 516
512 // No need to update the favicon url. By the time we get here 517 // No need to update the favicon url. By the time we get here
513 // UpdateFaviconURL will have set the favicon url. 518 // UpdateFaviconURL will have set the favicon url.
514 if (has_results && bitmap_result.icon_type == history::FAVICON) { 519 if (has_results && bitmap_result.icon_type == history::FAVICON) {
515 if (bitmap_result.is_valid()) { 520 if (bitmap_result.is_valid()) {
516 // There is a favicon, set it now. If expired we'll download the current 521 // There is a favicon, set it now. If expired we'll download the current
517 // one again, but at least the user will get some icon instead of the 522 // one again, but at least the user will get some icon instead of the
518 // default and most likely the current one is fine anyway. 523 // default and most likely the current one is fine anyway.
519 UpdateFavicon(entry, bitmap_result.bitmap_data); 524 UpdateFavicon(entry, favicon_bitmap_results);
520 } 525 }
521 if (HasExpiredFaviconResult(favicon_bitmap_results)) { 526 if (HasExpiredFaviconResult(favicon_bitmap_results)) {
522 // The favicon is out of date. Request the current one. 527 // The favicon is out of date. Request the current one.
523 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url, 528 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url,
524 preferred_icon_size(), 529 preferred_icon_size(),
525 history::FAVICON, 530 history::FAVICON,
526 FaviconTabHelper::ImageDownloadCallback()); 531 FaviconTabHelper::ImageDownloadCallback());
527 } 532 }
528 } else if (current_candidate() && 533 } else if (current_candidate() &&
529 (!has_results || HasExpiredFaviconResult(favicon_bitmap_results) || 534 (!has_results || HasExpiredFaviconResult(favicon_bitmap_results) ||
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 int height = bitmap.height(); 568 int height = bitmap.height();
564 if (width > 0 && height > 0) { 569 if (width > 0 && height > 0) {
565 gfx::CalculateFaviconTargetSize(&width, &height); 570 gfx::CalculateFaviconTargetSize(&width, &height);
566 return gfx::Image(skia::ImageOperations::Resize( 571 return gfx::Image(skia::ImageOperations::Resize(
567 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, 572 bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
568 width, height)); 573 width, height));
569 } 574 }
570 575
571 return image; 576 return image;
572 } 577 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698