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_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 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 if (!favicon_expired_ && entry->GetFavicon().valid && | 275 if (!favicon_expired_ && entry->GetFavicon().valid && |
276 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url, | 276 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url, |
277 history::FAVICON)) | 277 history::FAVICON)) |
278 return; | 278 return; |
279 | 279 |
280 entry->GetFavicon().url = current_candidate()->icon_url; | 280 entry->GetFavicon().url = current_candidate()->icon_url; |
281 } else if (!favicon_expired_ && got_favicon_from_history_ && | 281 } else if (!favicon_expired_ && got_favicon_from_history_ && |
282 history_icon_.is_valid() && | 282 history_icon_.is_valid() && |
283 DoUrlAndIconMatch( | 283 DoUrlAndIconMatch( |
284 *current_candidate(), | 284 *current_candidate(), |
285 history_icon_.icon_url, history_icon_.icon_type)) { | 285 history_icon_.elements[0].icon_url, |
286 history_icon_.icon_type)) { | |
286 return; | 287 return; |
287 } | 288 } |
288 | 289 |
289 if (got_favicon_from_history_) | 290 if (got_favicon_from_history_) |
290 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url, | 291 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url, |
291 ToHistoryIconType(current_candidate()->icon_type)); | 292 ToHistoryIconType(current_candidate()->icon_type)); |
292 } | 293 } |
293 | 294 |
294 void FaviconHandler::OnDidDownloadFavicon(int id, | 295 void FaviconHandler::OnDidDownloadFavicon(int id, |
295 const GURL& image_url, | 296 const GURL& image_url, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 return true; | 392 return true; |
392 | 393 |
393 // Otherwise store the favicon if the page is bookmarked. | 394 // Otherwise store the favicon if the page is bookmarked. |
394 BookmarkModel* bookmark_model = | 395 BookmarkModel* bookmark_model = |
395 BookmarkModelFactory::GetForProfile(profile_); | 396 BookmarkModelFactory::GetForProfile(profile_); |
396 return bookmark_model && bookmark_model->IsBookmarked(url); | 397 return bookmark_model && bookmark_model->IsBookmarked(url); |
397 } | 398 } |
398 | 399 |
399 void FaviconHandler::OnFaviconDataForInitialURL( | 400 void FaviconHandler::OnFaviconDataForInitialURL( |
400 FaviconService::Handle handle, | 401 FaviconService::Handle handle, |
401 history::FaviconData favicon) { | 402 history::FaviconData favicon_data) { |
402 NavigationEntry* entry = GetEntry(); | 403 NavigationEntry* entry = GetEntry(); |
403 if (!entry) | 404 if (!entry) |
404 return; | 405 return; |
405 | 406 |
406 got_favicon_from_history_ = true; | 407 got_favicon_from_history_ = true; |
407 history_icon_ = favicon; | 408 history_icon_ = favicon_data; |
408 | 409 |
409 favicon_expired_ = (favicon.known_icon && favicon.expired); | 410 favicon_expired_ = (favicon_data.known_icon && favicon_data.expired); |
410 | 411 |
411 if (favicon.known_icon && favicon.icon_type == history::FAVICON && | 412 history::FaviconDataElement element; |
413 if (!favicon_data.elements.empty()) | |
414 element = favicon_data.elements[0]; | |
415 if (favicon_data.known_icon && favicon_data.icon_type == history::FAVICON && | |
412 !entry->GetFavicon().valid && | 416 !entry->GetFavicon().valid && |
413 (!current_candidate() || | 417 (!current_candidate() || |
414 DoUrlAndIconMatch( | 418 DoUrlAndIconMatch( |
415 *current_candidate(), favicon.icon_url, favicon.icon_type))) { | 419 *current_candidate(), element.icon_url, favicon_data.icon_type))) { |
416 // The db knows the favicon (although it may be out of date) and the entry | 420 // The db knows the favicon (although it may be out of date) and the entry |
417 // doesn't have an icon. Set the favicon now, and if the favicon turns out | 421 // doesn't have an icon. Set the favicon now, and if the favicon turns out |
418 // to be expired (or the wrong url) we'll fetch later on. This way the | 422 // to be expired (or the wrong url) we'll fetch later on. This way the |
419 // user doesn't see a flash of the default favicon. | 423 // user doesn't see a flash of the default favicon. |
420 entry->GetFavicon().url = favicon.icon_url; | 424 entry->GetFavicon().url = element.icon_url; |
421 if (favicon.is_valid()) | 425 if (favicon_data.is_valid()) |
422 UpdateFavicon(entry, favicon.image_data); | 426 UpdateFavicon(entry, element.bitmap_data); |
423 entry->GetFavicon().valid = true; | 427 entry->GetFavicon().valid = true; |
424 } | 428 } |
425 | 429 |
426 if (favicon.known_icon && !favicon.expired) { | 430 if (favicon_data.known_icon && !favicon_data.expired) { |
431 history::FaviconDataElement element = favicon_data.elements[0]; | |
427 if (current_candidate() && | 432 if (current_candidate() && |
428 !DoUrlAndIconMatch( | 433 !DoUrlAndIconMatch( |
429 *current_candidate(), favicon.icon_url, favicon.icon_type)) { | 434 *current_candidate(), element.icon_url, favicon_data.icon_type)) { |
430 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will | 435 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will |
431 // update the mapping for this url and download the favicon if we don't | 436 // update the mapping for this url and download the favicon if we don't |
432 // already have it. | 437 // already have it. |
433 DownloadFaviconOrAskHistory(entry->GetURL(), | 438 DownloadFaviconOrAskHistory(entry->GetURL(), |
434 current_candidate()->icon_url, | 439 current_candidate()->icon_url, |
435 static_cast<history::IconType>(current_candidate()->icon_type)); | 440 static_cast<history::IconType>(current_candidate()->icon_type)); |
436 } | 441 } |
437 } else if (current_candidate()) { | 442 } else if (current_candidate()) { |
438 // We know the official url for the favicon, by either don't have the | 443 // We know the official url for the favicon, by either don't have the |
439 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to | 444 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to |
(...skipping 28 matching lines...) Expand all Loading... | |
468 // This is asynchronous. The history service will call back when done. | 473 // This is asynchronous. The history service will call back when done. |
469 // Issue the request and associate the current page ID with it. | 474 // Issue the request and associate the current page ID with it. |
470 UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type, | 475 UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type, |
471 &cancelable_consumer_, | 476 &cancelable_consumer_, |
472 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this))); | 477 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this))); |
473 } | 478 } |
474 } | 479 } |
475 } | 480 } |
476 | 481 |
477 void FaviconHandler::OnFaviconData(FaviconService::Handle handle, | 482 void FaviconHandler::OnFaviconData(FaviconService::Handle handle, |
478 history::FaviconData favicon) { | 483 history::FaviconData favicon_data) { |
479 NavigationEntry* entry = GetEntry(); | 484 NavigationEntry* entry = GetEntry(); |
480 if (!entry) | 485 if (!entry) |
481 return; | 486 return; |
482 | 487 |
483 // No need to update the favicon url. By the time we get here | 488 // No need to update the favicon url. By the time we get here |
484 // UpdateFaviconURL will have set the favicon url. | 489 // UpdateFaviconURL will have set the favicon url. |
485 if (favicon.icon_type == history::FAVICON) { | 490 if (favicon_data.icon_type == history::FAVICON) { |
486 if (favicon.is_valid()) { | 491 if (favicon_data.is_valid()) { |
487 // There is a favicon, set it now. If expired we'll download the current | 492 // There is a favicon, set it now. If expired we'll download the current |
488 // one again, but at least the user will get some icon instead of the | 493 // one again, but at least the user will get some icon instead of the |
489 // default and most likely the current one is fine anyway. | 494 // default and most likely the current one is fine anyway. |
490 UpdateFavicon(entry, favicon.image_data); | 495 history::FaviconDataElement element = favicon_data.elements[0]; |
stevenjb
2012/08/15 22:59:18
Why do a copy here?
| |
496 UpdateFavicon(entry, element.bitmap_data); | |
491 } | 497 } |
492 if (!favicon.known_icon || favicon.expired) { | 498 if (!favicon_data.known_icon || favicon_data.expired) { |
493 // We don't know the favicon, or it is out of date. Request the current | 499 // We don't know the favicon, or it is out of date. Request the current |
494 // one. | 500 // one. |
495 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url, | 501 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url, |
496 preferred_icon_size(), | 502 preferred_icon_size(), |
497 history::FAVICON, | 503 history::FAVICON, |
498 FaviconTabHelper::ImageDownloadCallback()); | 504 FaviconTabHelper::ImageDownloadCallback()); |
499 } | 505 } |
500 } else if (current_candidate() && (!favicon.known_icon || favicon.expired || | 506 } else if (current_candidate() && |
501 !(DoUrlAndIconMatch( | 507 (!favicon_data.known_icon || favicon_data.expired || |
502 *current_candidate(), favicon.icon_url, favicon.icon_type)))) { | 508 favicon_data.elements.empty() || !(DoUrlAndIconMatch( |
stevenjb
2012/08/15 22:59:18
nit: put !(DoUrlAndIconMatch( on a new line
| |
509 *current_candidate(), favicon_data.elements[0].icon_url, | |
510 favicon_data.icon_type)))) { | |
503 // We don't know the favicon, it is out of date or its type is not same as | 511 // We don't know the favicon, it is out of date or its type is not same as |
504 // one got from page. Request the current one. | 512 // one got from page. Request the current one. |
505 ScheduleDownload(entry->GetURL(), current_candidate()->icon_url, | 513 ScheduleDownload(entry->GetURL(), current_candidate()->icon_url, |
506 preferred_icon_size(), | 514 preferred_icon_size(), |
507 ToHistoryIconType(current_candidate()->icon_type), | 515 ToHistoryIconType(current_candidate()->icon_type), |
508 FaviconTabHelper::ImageDownloadCallback()); | 516 FaviconTabHelper::ImageDownloadCallback()); |
509 } | 517 } |
510 history_icon_ = favicon; | 518 history_icon_ = favicon_data; |
511 } | 519 } |
512 | 520 |
513 int FaviconHandler::ScheduleDownload( | 521 int FaviconHandler::ScheduleDownload( |
514 const GURL& url, | 522 const GURL& url, |
515 const GURL& image_url, | 523 const GURL& image_url, |
516 int image_size, | 524 int image_size, |
517 history::IconType icon_type, | 525 history::IconType icon_type, |
518 const FaviconTabHelper::ImageDownloadCallback& callback) { | 526 const FaviconTabHelper::ImageDownloadCallback& callback) { |
519 const int download_id = DownloadFavicon(image_url, image_size); | 527 const int download_id = DownloadFavicon(image_url, image_size); |
520 if (download_id) { | 528 if (download_id) { |
(...skipping 13 matching lines...) Expand all Loading... | |
534 int height = bitmap.height(); | 542 int height = bitmap.height(); |
535 if (width > 0 && height > 0) { | 543 if (width > 0 && height > 0) { |
536 gfx::CalculateFaviconTargetSize(&width, &height); | 544 gfx::CalculateFaviconTargetSize(&width, &height); |
537 return gfx::Image(skia::ImageOperations::Resize( | 545 return gfx::Image(skia::ImageOperations::Resize( |
538 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, | 546 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |
539 width, height)); | 547 width, height)); |
540 } | 548 } |
541 | 549 |
542 return image; | 550 return image; |
543 } | 551 } |
OLD | NEW |