| Index: components/favicon/core/favicon_handler.cc
|
| diff --git a/components/favicon/core/favicon_handler.cc b/components/favicon/core/favicon_handler.cc
|
| index aff16261e47917a0680e7ec581d1644f29875f1f..1d5eac7ccdf34289398f1c2aa256434a160ccb5a 100644
|
| --- a/components/favicon/core/favicon_handler.cc
|
| +++ b/components/favicon/core/favicon_handler.cc
|
| @@ -235,7 +235,10 @@ void FaviconHandler::FetchFavicon(const GURL& url) {
|
| url_ = url;
|
|
|
| favicon_expired_or_incomplete_ = got_favicon_from_history_ = false;
|
| + download_requests_.clear();
|
| image_urls_.clear();
|
| + history_results_.clear();
|
| + best_favicon_candidate_ = FaviconCandidate();
|
|
|
| // Request the favicon from the history service. In parallel to this the
|
| // renderer is going to notify us (well WebContents) when the favicon url is
|
| @@ -298,19 +301,12 @@ void FaviconHandler::SetFavicon(const GURL& url,
|
| if (ShouldSaveFavicon(url))
|
| SetHistoryFavicons(url, icon_url, icon_type, image);
|
|
|
| - if (!UrlMatches(url, url_) || PageChangedSinceFaviconWasRequested())
|
| - return;
|
| -
|
| - NotifyFaviconAvailable(
|
| - icon_url,
|
| - image,
|
| - icon_type == favicon_base::FAVICON && !download_largest_icon_);
|
| + NotifyFaviconAvailable(icon_url, image);
|
| }
|
|
|
| void FaviconHandler::NotifyFaviconAvailable(
|
| const std::vector<favicon_base::FaviconRawBitmapResult>&
|
| - favicon_bitmap_results,
|
| - bool is_active_favicon) {
|
| + favicon_bitmap_results) {
|
| gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs(
|
| favicon_bitmap_results,
|
| favicon_base::GetFaviconScales(),
|
| @@ -319,23 +315,27 @@ void FaviconHandler::NotifyFaviconAvailable(
|
| // not matter which result we get the |icon_url| from.
|
| const GURL icon_url = favicon_bitmap_results.empty() ?
|
| GURL() : favicon_bitmap_results[0].icon_url;
|
| - NotifyFaviconAvailable(icon_url, resized_image, is_active_favicon);
|
| + NotifyFaviconAvailable(icon_url, resized_image);
|
| }
|
|
|
| void FaviconHandler::NotifyFaviconAvailable(const GURL& icon_url,
|
| - const gfx::Image& image,
|
| - bool is_active_favicon) {
|
| + const gfx::Image& image) {
|
| gfx::Image image_with_adjusted_colorspace = image;
|
| favicon_base::SetFaviconColorSpace(&image_with_adjusted_colorspace);
|
|
|
| + bool is_active_favicon =
|
| + (handler_type_ == FAVICON && !download_largest_icon_);
|
| +
|
| driver_->OnFaviconAvailable(
|
| image_with_adjusted_colorspace, icon_url, is_active_favicon);
|
| }
|
|
|
| void FaviconHandler::OnUpdateFaviconURL(
|
| const std::vector<FaviconURL>& candidates) {
|
| + download_requests_.clear();
|
| image_urls_.clear();
|
| best_favicon_candidate_ = FaviconCandidate();
|
| +
|
| for (const FaviconURL& candidate : candidates) {
|
| if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_))
|
| image_urls_.push_back(candidate);
|
| @@ -393,14 +393,19 @@ void FaviconHandler::OnDidDownloadFavicon(
|
| DownloadRequest download_request = i->second;
|
| download_requests_.erase(i);
|
|
|
| - if (current_candidate() &&
|
| - DoUrlAndIconMatch(*current_candidate(),
|
| - image_url,
|
| - download_request.icon_type)) {
|
| - bool request_next_icon = true;
|
| + if (PageChangedSinceFaviconWasRequested() ||
|
| + !current_candidate() ||
|
| + !DoUrlAndIconMatch(*current_candidate(),
|
| + image_url,
|
| + download_request.icon_type)) {
|
| + return;
|
| + }
|
| +
|
| + bool request_next_icon = true;
|
| + if (!bitmaps.empty()) {
|
| float score = 0.0f;
|
| gfx::ImageSkia image_skia;
|
| - if (download_largest_icon_ && !bitmaps.empty()) {
|
| + if (download_largest_icon_) {
|
| int index = -1;
|
| // Use the largest bitmap if FaviconURL doesn't have sizes attribute.
|
| if (current_candidate()->icon_sizes.empty()) {
|
| @@ -424,30 +429,27 @@ void FaviconHandler::OnDidDownloadFavicon(
|
| gfx::Image image(image_skia);
|
| // The downloaded icon is still valid when there is no FaviconURL update
|
| // during the downloading.
|
| - if (!bitmaps.empty()) {
|
| - request_next_icon = !UpdateFaviconCandidate(
|
| - download_request.url, image_url, image, score,
|
| - download_request.icon_type);
|
| - }
|
| - }
|
| - if (request_next_icon && !PageChangedSinceFaviconWasRequested() &&
|
| - image_urls_.size() > 1) {
|
| - // Remove the first member of image_urls_ and process the remaining.
|
| - image_urls_.erase(image_urls_.begin());
|
| - ProcessCurrentUrl();
|
| - } else if (best_favicon_candidate_.icon_type !=
|
| - favicon_base::INVALID_ICON) {
|
| - // No more icons to request, set the favicon from the candidate.
|
| - SetFavicon(best_favicon_candidate_.url,
|
| - best_favicon_candidate_.image_url,
|
| - best_favicon_candidate_.image,
|
| - best_favicon_candidate_.icon_type);
|
| - // Reset candidate.
|
| - image_urls_.clear();
|
| - download_requests_.clear();
|
| - best_favicon_candidate_ = FaviconCandidate();
|
| + request_next_icon = !UpdateFaviconCandidate(
|
| + download_request.url, image_url, image, score,
|
| + download_request.icon_type);
|
| }
|
| }
|
| +
|
| + if (request_next_icon && image_urls_.size() > 1) {
|
| + // Remove the first member of image_urls_ and process the remaining.
|
| + image_urls_.erase(image_urls_.begin());
|
| + ProcessCurrentUrl();
|
| + } else if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) {
|
| + // No more icons to request, set the favicon from the candidate.
|
| + SetFavicon(best_favicon_candidate_.url,
|
| + best_favicon_candidate_.image_url,
|
| + best_favicon_candidate_.image,
|
| + best_favicon_candidate_.icon_type);
|
| + // Reset candidate.
|
| + image_urls_.clear();
|
| + download_requests_.clear();
|
| + best_favicon_candidate_ = FaviconCandidate();
|
| + }
|
| }
|
|
|
| bool FaviconHandler::HasPendingTasksForTest() {
|
| @@ -569,7 +571,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
|
| // doesn't have an icon. Set the favicon now, and if the favicon turns out
|
| // to be expired (or the wrong url) we'll fetch later on. This way the
|
| // user doesn't see a flash of the default favicon.
|
| - NotifyFaviconAvailable(favicon_bitmap_results, true);
|
| + NotifyFaviconAvailable(favicon_bitmap_results);
|
| } else {
|
| // If |favicon_bitmap_results| does not have any valid results, treat the
|
| // favicon as if it's expired.
|
| @@ -599,7 +601,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
|
| // renderer to download the icon.
|
|
|
| if (has_valid_result && (handler_type_ != FAVICON || download_largest_icon_))
|
| - NotifyFaviconAvailable(favicon_bitmap_results, false);
|
| + NotifyFaviconAvailable(favicon_bitmap_results);
|
| }
|
|
|
| void FaviconHandler::DownloadFaviconOrAskFaviconService(
|
| @@ -647,7 +649,7 @@ void FaviconHandler::OnFaviconData(const std::vector<
|
| // There is a favicon, set it now. If expired we'll download the current
|
| // one again, but at least the user will get some icon instead of the
|
| // default and most likely the current one is fine anyway.
|
| - NotifyFaviconAvailable(favicon_bitmap_results, true);
|
| + NotifyFaviconAvailable(favicon_bitmap_results);
|
| }
|
| if (has_expired_or_incomplete_result) {
|
| // The favicon is out of date. Request the current one.
|
| @@ -668,11 +670,11 @@ void FaviconHandler::OnFaviconData(const std::vector<
|
|
|
| if (has_valid_result &&
|
| (handler_type_ != FAVICON || download_largest_icon_)) {
|
| - NotifyFaviconAvailable(favicon_bitmap_results, false);
|
| + NotifyFaviconAvailable(favicon_bitmap_results);
|
| }
|
| }
|
|
|
| -int FaviconHandler::ScheduleDownload(const GURL& url,
|
| +void FaviconHandler::ScheduleDownload(const GURL& url,
|
| const GURL& image_url,
|
| favicon_base::IconType icon_type) {
|
| // A max bitmap size is specified to avoid receiving huge bitmaps in
|
| @@ -686,8 +688,6 @@ int FaviconHandler::ScheduleDownload(const GURL& url,
|
| download_requests_[download_id] =
|
| DownloadRequest(url, image_url, icon_type);
|
| }
|
| -
|
| - return download_id;
|
| }
|
|
|
| void FaviconHandler::SortAndPruneImageUrls() {
|
|
|