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/content/content_favicon_driver.h" | 5 #include "components/favicon/content/content_favicon_driver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/favicon/content/favicon_url_util.h" | 8 #include "components/favicon/content/favicon_url_util.h" |
9 #include "components/favicon/core/favicon_service.h" | 9 #include "components/favicon/core/favicon_service.h" |
10 #include "components/favicon/core/favicon_url.h" | 10 #include "components/favicon/core/favicon_url.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 DCHECK(web_contents()); | 106 DCHECK(web_contents()); |
107 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 107 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
108 } | 108 } |
109 | 109 |
110 GURL ContentFaviconDriver::GetActiveURL() { | 110 GURL ContentFaviconDriver::GetActiveURL() { |
111 content::NavigationEntry* entry = | 111 content::NavigationEntry* entry = |
112 web_contents()->GetController().GetLastCommittedEntry(); | 112 web_contents()->GetController().GetLastCommittedEntry(); |
113 return entry ? entry->GetURL() : GURL(); | 113 return entry ? entry->GetURL() : GURL(); |
114 } | 114 } |
115 | 115 |
116 void ContentFaviconDriver::SetActiveFaviconValidity(bool valid) { | |
117 GetFaviconStatus().valid = valid; | |
118 } | |
119 | |
120 GURL ContentFaviconDriver::GetActiveFaviconURL() { | |
121 return GetFaviconStatus().url; | |
122 } | |
123 | |
124 void ContentFaviconDriver::SetActiveFaviconURL(const GURL& url) { | |
125 GetFaviconStatus().url = url; | |
126 } | |
127 | |
128 void ContentFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | |
129 GetFaviconStatus().image = image; | |
130 } | |
131 | |
132 content::FaviconStatus& ContentFaviconDriver::GetFaviconStatus() { | |
133 DCHECK(web_contents()->GetController().GetLastCommittedEntry()); | |
134 return web_contents()->GetController().GetLastCommittedEntry()->GetFavicon(); | |
135 } | |
136 | |
137 ContentFaviconDriver::ContentFaviconDriver( | 116 ContentFaviconDriver::ContentFaviconDriver( |
138 content::WebContents* web_contents, | 117 content::WebContents* web_contents, |
139 FaviconService* favicon_service, | 118 FaviconService* favicon_service, |
140 history::HistoryService* history_service, | 119 history::HistoryService* history_service, |
141 bookmarks::BookmarkModel* bookmark_model) | 120 bookmarks::BookmarkModel* bookmark_model) |
142 : content::WebContentsObserver(web_contents), | 121 : content::WebContentsObserver(web_contents), |
143 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 122 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
144 } | 123 } |
145 | 124 |
146 ContentFaviconDriver::~ContentFaviconDriver() { | 125 ContentFaviconDriver::~ContentFaviconDriver() { |
147 } | 126 } |
148 | 127 |
149 void ContentFaviconDriver::NotifyFaviconUpdated(bool icon_url_changed) { | 128 void ContentFaviconDriver::OnFaviconUpdated( |
150 FaviconDriverImpl::NotifyFaviconUpdated(icon_url_changed); | 129 const GURL& page_url, |
151 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 130 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 131 const GURL& icon_url, |
| 132 bool icon_url_changed, |
| 133 const gfx::Image& image) { |
| 134 content::NavigationEntry* entry = |
| 135 web_contents()->GetController().GetLastCommittedEntry(); |
| 136 DCHECK(entry && entry->GetURL() == page_url); |
| 137 |
| 138 if (notification_icon_type == FaviconDriverObserver::NON_TOUCH_16_DIP) { |
| 139 entry->GetFavicon().valid = true; |
| 140 entry->GetFavicon().url = icon_url; |
| 141 entry->GetFavicon().image = image; |
| 142 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 143 } |
| 144 |
| 145 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, |
| 146 icon_url_changed, image); |
152 } | 147 } |
153 | 148 |
154 void ContentFaviconDriver::DidUpdateFaviconURL( | 149 void ContentFaviconDriver::DidUpdateFaviconURL( |
155 const std::vector<content::FaviconURL>& candidates) { | 150 const std::vector<content::FaviconURL>& candidates) { |
156 DCHECK(!candidates.empty()); | 151 DCHECK(!candidates.empty()); |
157 | 152 |
158 // Ignore the update if there is no last committed navigation entry. This can | 153 // Ignore the update if there is no last committed navigation entry. This can |
159 // occur when loading an initially blank page. | 154 // occur when loading an initially blank page. |
160 content::NavigationEntry* entry = | 155 content::NavigationEntry* entry = |
161 web_contents()->GetController().GetLastCommittedEntry(); | 156 web_contents()->GetController().GetLastCommittedEntry(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // redownloaded. | 188 // redownloaded. |
194 GURL url = details.entry->GetURL(); | 189 GURL url = details.entry->GetURL(); |
195 if (url != bypass_cache_page_url_) | 190 if (url != bypass_cache_page_url_) |
196 bypass_cache_page_url_ = GURL(); | 191 bypass_cache_page_url_ = GURL(); |
197 | 192 |
198 // Get the favicon, either from history or request it from the net. | 193 // Get the favicon, either from history or request it from the net. |
199 FetchFavicon(url); | 194 FetchFavicon(url); |
200 } | 195 } |
201 | 196 |
202 } // namespace favicon | 197 } // namespace favicon |
OLD | NEW |