| 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/ios/web_favicon_driver.h" | 5 #include "components/favicon/ios/web_favicon_driver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "components/favicon/core/favicon_url.h" | 9 #include "components/favicon/core/favicon_url.h" |
| 10 #include "components/favicon/ios/favicon_url_util.h" | 10 #include "components/favicon/ios/favicon_url_util.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 fetch_favicon_url_ = url; | 48 fetch_favicon_url_ = url; |
| 49 FaviconDriverImpl::FetchFavicon(url); | 49 FaviconDriverImpl::FetchFavicon(url); |
| 50 } | 50 } |
| 51 | 51 |
| 52 gfx::Image WebFaviconDriver::GetFavicon() const { | 52 gfx::Image WebFaviconDriver::GetFavicon() const { |
| 53 web::NavigationItem* item = | 53 web::NavigationItem* item = |
| 54 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 54 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 55 return item ? item->GetFavicon().image : gfx::Image(); | 55 return item ? item->GetFavicon().image : gfx::Image(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool WebFaviconDriver::FaviconIsValid() const { | |
| 59 web::NavigationItem* item = | |
| 60 web_state()->GetNavigationManager()->GetLastCommittedItem(); | |
| 61 return item ? item->GetFavicon().valid : false; | |
| 62 } | |
| 63 | |
| 64 GURL WebFaviconDriver::GetActiveURL() { | |
| 65 web::NavigationItem* item = | |
| 66 web_state()->GetNavigationManager()->GetVisibleItem(); | |
| 67 return item ? item->GetURL() : GURL(); | |
| 68 } | |
| 69 | |
| 70 int WebFaviconDriver::DownloadImage(const GURL& url, | 58 int WebFaviconDriver::DownloadImage(const GURL& url, |
| 71 int max_image_size, | 59 int max_image_size, |
| 72 ImageDownloadCallback callback) { | 60 ImageDownloadCallback callback) { |
| 73 if (WasUnableToDownloadFavicon(url)) { | 61 if (WasUnableToDownloadFavicon(url)) { |
| 74 DVLOG(1) << "Skip Failed FavIcon: " << url; | 62 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 75 return 0; | 63 return 0; |
| 76 } | 64 } |
| 77 | 65 |
| 78 static int downloaded_image_count = 0; | 66 static int downloaded_image_count = 0; |
| 79 int local_download_id = ++downloaded_image_count; | 67 int local_download_id = ++downloaded_image_count; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 112 |
| 125 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, | 113 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, |
| 126 icon_url_changed, image); | 114 icon_url_changed, image); |
| 127 } | 115 } |
| 128 | 116 |
| 129 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 117 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
| 130 FaviconService* favicon_service, | 118 FaviconService* favicon_service, |
| 131 history::HistoryService* history_service, | 119 history::HistoryService* history_service, |
| 132 bookmarks::BookmarkModel* bookmark_model) | 120 bookmarks::BookmarkModel* bookmark_model) |
| 133 : web::WebStateObserver(web_state), | 121 : web::WebStateObserver(web_state), |
| 134 FaviconDriverImpl(favicon_service, history_service, bookmark_model), | 122 FaviconDriverImpl(/*enable_touch_icons=*/true, |
| 123 favicon_service, |
| 124 history_service, |
| 125 bookmark_model), |
| 135 image_fetcher_(web_state->GetBrowserState()->GetRequestContext(), | 126 image_fetcher_(web_state->GetBrowserState()->GetRequestContext(), |
| 136 web::WebThread::GetBlockingPool()) {} | 127 web::WebThread::GetBlockingPool()) {} |
| 137 | 128 |
| 138 WebFaviconDriver::~WebFaviconDriver() { | 129 WebFaviconDriver::~WebFaviconDriver() { |
| 139 } | 130 } |
| 140 | 131 |
| 141 void WebFaviconDriver::FaviconUrlUpdated( | 132 void WebFaviconDriver::FaviconUrlUpdated( |
| 142 const std::vector<web::FaviconURL>& candidates) { | 133 const std::vector<web::FaviconURL>& candidates) { |
| 143 DCHECK(!candidates.empty()); | 134 DCHECK(!candidates.empty()); |
| 144 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 135 |
| 136 web::NavigationItem* item = |
| 137 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 138 |
| 139 OnUpdateFaviconURL(item ? item->GetURL() : GURL(), |
| 140 FaviconURLsFromWebFaviconURLs(candidates)); |
| 145 } | 141 } |
| 146 | 142 |
| 147 } // namespace favicon | 143 } // namespace favicon |
| OLD | NEW |