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) { | |
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 20 matching lines...) Expand all Loading... | |
66 return web_state()->GetBrowserState()->IsOffTheRecord(); | 71 return web_state()->GetBrowserState()->IsOffTheRecord(); |
67 } | 72 } |
68 | 73 |
69 GURL WebFaviconDriver::GetActiveURL() { | 74 GURL WebFaviconDriver::GetActiveURL() { |
70 web::NavigationItem* item = | 75 web::NavigationItem* item = |
71 web_state()->GetNavigationManager()->GetVisibleItem(); | 76 web_state()->GetNavigationManager()->GetVisibleItem(); |
72 return item ? item->GetURL() : GURL(); | 77 return item ? item->GetURL() : GURL(); |
73 } | 78 } |
74 | 79 |
75 bool WebFaviconDriver::GetActiveFaviconValidity() { | 80 bool WebFaviconDriver::GetActiveFaviconValidity() { |
76 return GetFaviconStatus().valid; | 81 return ActiveURLChangedSinceFetchFavicon() ? false : GetFaviconStatus().valid; |
sdefresne
2015/08/26 16:26:07
nit (optional): return !ActiveURLChangedSinceFetch
| |
77 } | 82 } |
78 | 83 |
79 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { | 84 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { |
80 GetFaviconStatus().valid = validity; | 85 GetFaviconStatus().valid = validity; |
81 } | 86 } |
82 | 87 |
83 GURL WebFaviconDriver::GetActiveFaviconURL() { | 88 GURL WebFaviconDriver::GetActiveFaviconURL() { |
84 return GetFaviconStatus().url; | 89 return ActiveURLChangedSinceFetchFavicon() ? GURL() : GetFaviconStatus().url; |
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() { | |
101 // FaviconHandler sends notifications with the assumption that the active URL | |
102 // has not changed. Suppress FaviconHandler notifications if the active URL | |
103 // has changed. | |
104 return !ActiveURLChangedSinceFetchFavicon(); | |
105 } | |
106 | |
107 bool WebFaviconDriver::ActiveURLChangedSinceFetchFavicon() { | |
108 // On iOS the active URL can change in between calls to FetchFavicon(). For | |
109 // instance, FetchFavicon() is not synchronously called when the active URL | |
110 // changes as a result of CRWSessionController::goToEntry(). | |
111 return GetActiveURL() != fetch_favicon_url_; | |
112 } | |
113 | |
95 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { | 114 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { |
96 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem()); | 115 DCHECK(!ActiveURLChangedSinceFetchFavicon()); |
97 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); | 116 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); |
98 } | 117 } |
99 | 118 |
100 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 119 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
101 FaviconService* favicon_service, | 120 FaviconService* favicon_service, |
102 history::HistoryService* history_service, | 121 history::HistoryService* history_service, |
103 bookmarks::BookmarkModel* bookmark_model) | 122 bookmarks::BookmarkModel* bookmark_model) |
104 : web::WebStateObserver(web_state), | 123 : web::WebStateObserver(web_state), |
105 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 124 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
106 } | 125 } |
107 | 126 |
108 WebFaviconDriver::~WebFaviconDriver() { | 127 WebFaviconDriver::~WebFaviconDriver() { |
109 } | 128 } |
110 | 129 |
111 void WebFaviconDriver::FaviconUrlUpdated( | 130 void WebFaviconDriver::FaviconUrlUpdated( |
112 const std::vector<web::FaviconURL>& candidates) { | 131 const std::vector<web::FaviconURL>& candidates) { |
132 if (fetch_favicon_url_.is_empty() || ActiveURLChangedSinceFetchFavicon()) | |
133 return; | |
134 | |
113 DCHECK(!candidates.empty()); | 135 DCHECK(!candidates.empty()); |
114 OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates)); | 136 OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates)); |
115 } | 137 } |
116 | 138 |
117 } // namespace favicon | 139 } // namespace favicon |
OLD | NEW |