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