| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/core/favicon_driver_impl.h" | 5 #include "components/favicon/core/favicon_driver_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, | 44 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, |
| 45 history::HistoryService* history_service, | 45 history::HistoryService* history_service, |
| 46 bookmarks::BookmarkModel* bookmark_model) | 46 bookmarks::BookmarkModel* bookmark_model) |
| 47 : favicon_service_(favicon_service), | 47 : favicon_service_(favicon_service), |
| 48 history_service_(history_service), | 48 history_service_(history_service), |
| 49 bookmark_model_(bookmark_model) { | 49 bookmark_model_(bookmark_model) { |
| 50 favicon_handler_.reset(new FaviconHandler( | 50 favicon_handler_.reset(new FaviconHandler( |
| 51 favicon_service_, this, kEnableTouchIcon ? FaviconHandler::LARGEST_FAVICON | 51 favicon_service_, this, kEnableTouchIcon |
| 52 : FaviconHandler::FAVICON)); | 52 ? FaviconDriverObserver::NON_TOUCH_LARGEST |
| 53 : FaviconDriverObserver::NON_TOUCH_16_DIP)); |
| 53 if (kEnableTouchIcon || IsIconNTPEnabled()) { | 54 if (kEnableTouchIcon || IsIconNTPEnabled()) { |
| 54 touch_icon_handler_.reset(new FaviconHandler( | 55 touch_icon_handler_.reset(new FaviconHandler( |
| 55 favicon_service_, this, FaviconHandler::LARGEST_TOUCH)); | 56 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 FaviconDriverImpl::~FaviconDriverImpl() { | 60 FaviconDriverImpl::~FaviconDriverImpl() { |
| 60 } | 61 } |
| 61 | 62 |
| 62 void FaviconDriverImpl::FetchFavicon(const GURL& url) { | 63 void FaviconDriverImpl::FetchFavicon(const GURL& url) { |
| 63 favicon_handler_->FetchFavicon(url); | 64 favicon_handler_->FetchFavicon(url); |
| 64 if (touch_icon_handler_.get()) | 65 if (touch_icon_handler_.get()) |
| 65 touch_icon_handler_->FetchFavicon(url); | 66 touch_icon_handler_->FetchFavicon(url); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 if (touch_icon_handler_.get()) { | 83 if (touch_icon_handler_.get()) { |
| 83 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, | 84 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, |
| 84 original_bitmap_sizes); | 85 original_bitmap_sizes); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { | 89 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { |
| 89 return bookmark_model_ && bookmark_model_->IsBookmarked(url); | 90 return bookmark_model_ && bookmark_model_->IsBookmarked(url); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void FaviconDriverImpl::OnFaviconAvailable(const GURL& page_url, | |
| 93 const GURL& icon_url, | |
| 94 const gfx::Image& image, | |
| 95 bool is_active_favicon) { | |
| 96 // Check whether the active URL has changed since FetchFavicon() was called. | |
| 97 // On iOS only, the active URL can change between calls to FetchFavicon(). | |
| 98 // For instance, FetchFavicon() is not synchronously called when the active | |
| 99 // URL changes as a result of CRWSessionController::goToEntry(). | |
| 100 if (page_url != GetActiveURL()) | |
| 101 return; | |
| 102 | |
| 103 if (is_active_favicon) { | |
| 104 bool icon_url_changed = GetActiveFaviconURL() != icon_url; | |
| 105 // No matter what happens, we need to mark the favicon as being set. | |
| 106 SetActiveFaviconValidity(true); | |
| 107 SetActiveFaviconURL(icon_url); | |
| 108 | |
| 109 if (image.IsEmpty()) | |
| 110 return; | |
| 111 | |
| 112 SetActiveFaviconImage(image); | |
| 113 NotifyFaviconUpdated(icon_url_changed); | |
| 114 } | |
| 115 if (!image.IsEmpty()) | |
| 116 NotifyFaviconAvailable(image); | |
| 117 } | |
| 118 | |
| 119 bool FaviconDriverImpl::HasPendingTasksForTest() { | 93 bool FaviconDriverImpl::HasPendingTasksForTest() { |
| 120 if (favicon_handler_->HasPendingTasksForTest()) | 94 if (favicon_handler_->HasPendingTasksForTest()) |
| 121 return true; | 95 return true; |
| 122 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) | 96 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) |
| 123 return true; | 97 return true; |
| 124 return false; | 98 return false; |
| 125 } | 99 } |
| 126 | 100 |
| 127 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) { | 101 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) { |
| 128 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url); | 102 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 void FaviconDriverImpl::OnUpdateFaviconURL( | 114 void FaviconDriverImpl::OnUpdateFaviconURL( |
| 141 const GURL& page_url, | 115 const GURL& page_url, |
| 142 const std::vector<FaviconURL>& candidates) { | 116 const std::vector<FaviconURL>& candidates) { |
| 143 DCHECK(!candidates.empty()); | 117 DCHECK(!candidates.empty()); |
| 144 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); | 118 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); |
| 145 if (touch_icon_handler_.get()) | 119 if (touch_icon_handler_.get()) |
| 146 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); | 120 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); |
| 147 } | 121 } |
| 148 | 122 |
| 149 } // namespace favicon | 123 } // namespace favicon |
| OLD | NEW |