| 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 "components/favicon/core/favicon_url.h" | 8 #include "components/favicon/core/favicon_url.h" |
| 9 #include "components/favicon/ios/favicon_url_util.h" | 9 #include "components/favicon/ios/favicon_url_util.h" |
| 10 #include "ios/web/public/browser_state.h" | 10 #include "ios/web/public/browser_state.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DCHECK(web_state()); | 65 DCHECK(web_state()); |
| 66 return web_state()->GetBrowserState()->IsOffTheRecord(); | 66 return web_state()->GetBrowserState()->IsOffTheRecord(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 GURL WebFaviconDriver::GetActiveURL() { | 69 GURL WebFaviconDriver::GetActiveURL() { |
| 70 web::NavigationItem* item = | 70 web::NavigationItem* item = |
| 71 web_state()->GetNavigationManager()->GetVisibleItem(); | 71 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 72 return item ? item->GetURL() : GURL(); | 72 return item ? item->GetURL() : GURL(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { | 75 void WebFaviconDriver::OnFaviconUpdated( |
| 76 GetFaviconStatus().valid = validity; | 76 const GURL& page_url, |
| 77 } | 77 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 78 const GURL& icon_url, |
| 79 bool icon_url_changed, |
| 80 const gfx::Image& image) { |
| 81 // Check whether the active URL has changed since FetchFavicon() was called. |
| 82 // On iOS, the active URL can change between calls to FetchFavicon(). For |
| 83 // instance, FetchFavicon() is not synchronously called when the active URL |
| 84 // changes as a result of CRWSessionController::goToEntry(). |
| 85 web::NavigationItem* item = |
| 86 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 87 if (!item || item->GetURL() != page_url) |
| 88 return; |
| 78 | 89 |
| 79 GURL WebFaviconDriver::GetActiveFaviconURL() { | 90 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, |
| 80 return GetFaviconStatus().url; | 91 icon_url_changed, image); |
| 81 } | |
| 82 | |
| 83 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { | |
| 84 GetFaviconStatus().url = url; | |
| 85 } | |
| 86 | |
| 87 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | |
| 88 GetFaviconStatus().image = image; | |
| 89 } | |
| 90 | |
| 91 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { | |
| 92 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem()); | |
| 93 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); | |
| 94 } | 92 } |
| 95 | 93 |
| 96 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 94 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
| 97 FaviconService* favicon_service, | 95 FaviconService* favicon_service, |
| 98 history::HistoryService* history_service, | 96 history::HistoryService* history_service, |
| 99 bookmarks::BookmarkModel* bookmark_model) | 97 bookmarks::BookmarkModel* bookmark_model) |
| 100 : web::WebStateObserver(web_state), | 98 : web::WebStateObserver(web_state), |
| 101 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 99 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
| 102 } | 100 } |
| 103 | 101 |
| 104 WebFaviconDriver::~WebFaviconDriver() { | 102 WebFaviconDriver::~WebFaviconDriver() { |
| 105 } | 103 } |
| 106 | 104 |
| 107 void WebFaviconDriver::FaviconUrlUpdated( | 105 void WebFaviconDriver::FaviconUrlUpdated( |
| 108 const std::vector<web::FaviconURL>& candidates) { | 106 const std::vector<web::FaviconURL>& candidates) { |
| 109 DCHECK(!candidates.empty()); | 107 DCHECK(!candidates.empty()); |
| 110 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 108 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); |
| 111 } | 109 } |
| 112 | 110 |
| 113 } // namespace favicon | 111 } // namespace favicon |
| OLD | NEW |