Chromium Code Reviews| 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/logging.h" | 8 #include "base/logging.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 15 matching lines...) Expand all Loading... | |
| 26 history::HistoryService* history_service, | 26 history::HistoryService* history_service, |
| 27 bookmarks::BookmarkModel* bookmark_model) { | 27 bookmarks::BookmarkModel* bookmark_model) { |
| 28 if (FromWebState(web_state)) | 28 if (FromWebState(web_state)) |
| 29 return; | 29 return; |
| 30 | 30 |
| 31 web_state->SetUserData(UserDataKey(), | 31 web_state->SetUserData(UserDataKey(), |
| 32 new WebFaviconDriver(web_state, favicon_service, | 32 new WebFaviconDriver(web_state, favicon_service, |
| 33 history_service, bookmark_model)); | 33 history_service, bookmark_model)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void WebFaviconDriver::FetchFavicon(const GURL& url) override { | |
| 37 fetch_favicon_url_ = url; | |
| 38 FaviconDriverImpl::FetchFavicon(url); | |
| 39 } | |
| 40 | |
| 36 void WebFaviconDriver::SaveFavicon() { | 41 void WebFaviconDriver::SaveFavicon() { |
| 37 NOTREACHED(); | 42 NOTREACHED(); |
| 38 } | 43 } |
| 39 | 44 |
| 40 gfx::Image WebFaviconDriver::GetFavicon() const { | 45 gfx::Image WebFaviconDriver::GetFavicon() const { |
| 41 web::NavigationItem* item = | 46 web::NavigationItem* item = |
| 42 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 47 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 43 return item ? item->GetFavicon().image : gfx::Image(); | 48 return item ? item->GetFavicon().image : gfx::Image(); |
| 44 } | 49 } |
| 45 | 50 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } | 90 } |
| 86 | 91 |
| 87 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { | 92 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { |
| 88 GetFaviconStatus().url = url; | 93 GetFaviconStatus().url = url; |
| 89 } | 94 } |
| 90 | 95 |
| 91 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | 96 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { |
| 92 GetFaviconStatus().image = image; | 97 GetFaviconStatus().image = image; |
| 93 } | 98 } |
| 94 | 99 |
| 100 bool WebFaviconDriver::ShouldSendFaviconAvailableNotifications() override { | |
| 101 // On iOS the active URL can change in between calls to FetchFavicon(). For | |
| 102 // instance, FetchFavicon() is not synchronously called when the active URL | |
| 103 // changes as a result of CRWSessionController::goToEntry(). FaviconHandler | |
|
pkotwicz
2015/08/23 19:59:47
FetchFavicon() is called by CRWUIWebViewWebControl
| |
| 104 // sends notifications with the assumption that the active URL has not | |
| 105 // changed. Suppress FaviconHandler notifications if the active URL has | |
| 106 // changed. | |
| 107 return GetActiveURL() == fetch_favicon_url_; | |
| 108 } | |
| 109 | |
| 95 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { | 110 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { |
| 96 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem()); | 111 web::NavigationItem* item = |
| 97 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); | 112 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 113 return item ? item->GetFavicon() : web::FaviconStatus(); | |
| 98 } | 114 } |
| 99 | 115 |
| 100 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 116 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
| 101 FaviconService* favicon_service, | 117 FaviconService* favicon_service, |
| 102 history::HistoryService* history_service, | 118 history::HistoryService* history_service, |
| 103 bookmarks::BookmarkModel* bookmark_model) | 119 bookmarks::BookmarkModel* bookmark_model) |
| 104 : web::WebStateObserver(web_state), | 120 : web::WebStateObserver(web_state), |
| 105 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 121 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
| 106 } | 122 } |
| 107 | 123 |
| 108 WebFaviconDriver::~WebFaviconDriver() { | 124 WebFaviconDriver::~WebFaviconDriver() { |
| 109 } | 125 } |
| 110 | 126 |
| 111 void WebFaviconDriver::FaviconUrlUpdated( | 127 void WebFaviconDriver::FaviconUrlUpdated( |
| 112 const std::vector<web::FaviconURL>& candidates) { | 128 const std::vector<web::FaviconURL>& candidates) { |
| 113 DCHECK(!candidates.empty()); | 129 DCHECK(!candidates.empty()); |
| 114 OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates)); | 130 OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates)); |
| 115 } | 131 } |
| 116 | 132 |
| 117 } // namespace favicon | 133 } // namespace favicon |
| OLD | NEW |