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 bool WebFaviconDriver::GetActiveFaviconValidity() { | |
76 return !ActiveURLChangedSinceFetchFavicon() && GetFaviconStatus().valid; | |
77 } | |
78 | |
79 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { | 75 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { |
80 GetFaviconStatus().valid = validity; | 76 GetFaviconStatus().valid = validity; |
81 } | 77 } |
82 | 78 |
83 GURL WebFaviconDriver::GetActiveFaviconURL() { | 79 GURL WebFaviconDriver::GetActiveFaviconURL() { |
84 return ActiveURLChangedSinceFetchFavicon() ? GURL() : GetFaviconStatus().url; | 80 return GetFaviconStatus().url; |
85 } | 81 } |
86 | 82 |
87 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { | 83 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { |
88 GetFaviconStatus().url = url; | 84 GetFaviconStatus().url = url; |
89 } | 85 } |
90 | 86 |
91 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | 87 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { |
92 GetFaviconStatus().image = image; | 88 GetFaviconStatus().image = image; |
93 } | 89 } |
94 | 90 |
95 bool WebFaviconDriver::ActiveURLChangedSinceFetchFavicon() { | |
96 // On iOS the active URL can change in between calls to FetchFavicon(). For | |
97 // instance, FetchFavicon() is not synchronously called when the active URL | |
98 // changes as a result of CRWSessionController::goToEntry(). | |
99 // TODO(stuartmorgan): Remove this once iOS always triggers favicon fetches | |
100 // synchronously after active URL changes. | |
101 return GetActiveURL() != fetch_favicon_url_; | |
102 } | |
103 | |
104 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { | 91 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { |
105 DCHECK(!ActiveURLChangedSinceFetchFavicon()); | 92 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem()); |
106 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); | 93 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); |
107 } | 94 } |
108 | 95 |
109 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 96 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
110 FaviconService* favicon_service, | 97 FaviconService* favicon_service, |
111 history::HistoryService* history_service, | 98 history::HistoryService* history_service, |
112 bookmarks::BookmarkModel* bookmark_model) | 99 bookmarks::BookmarkModel* bookmark_model) |
113 : web::WebStateObserver(web_state), | 100 : web::WebStateObserver(web_state), |
114 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 101 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
115 } | 102 } |
116 | 103 |
117 WebFaviconDriver::~WebFaviconDriver() { | 104 WebFaviconDriver::~WebFaviconDriver() { |
118 } | 105 } |
119 | 106 |
120 void WebFaviconDriver::FaviconUrlUpdated( | 107 void WebFaviconDriver::FaviconUrlUpdated( |
121 const std::vector<web::FaviconURL>& candidates) { | 108 const std::vector<web::FaviconURL>& candidates) { |
122 DCHECK(!candidates.empty()); | 109 DCHECK(!candidates.empty()); |
123 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 110 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); |
124 } | 111 } |
125 | 112 |
126 } // namespace favicon | 113 } // namespace favicon |
OLD | NEW |