OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/favicon/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/favicon/chrome_favicon_client.h" | 8 #include "chrome/browser/favicon/chrome_favicon_client.h" |
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
10 #include "chrome/browser/favicon/favicon_handler.h" | 10 #include "chrome/browser/favicon/favicon_handler.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return; | 129 return; |
130 const FaviconStatus& favicon(entry->GetFavicon()); | 130 const FaviconStatus& favicon(entry->GetFavicon()); |
131 if (!favicon.valid || favicon.url.is_empty() || | 131 if (!favicon.valid || favicon.url.is_empty() || |
132 favicon.image.IsEmpty()) { | 132 favicon.image.IsEmpty()) { |
133 return; | 133 return; |
134 } | 134 } |
135 service->SetFavicons( | 135 service->SetFavicons( |
136 entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image); | 136 entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image); |
137 } | 137 } |
138 | 138 |
| 139 void FaviconTabHelper::AddObserver(Observer* observer) { |
| 140 observer_list_.AddObserver(observer); |
| 141 } |
| 142 |
| 143 void FaviconTabHelper::RemoveObserver(Observer* observer) { |
| 144 observer_list_.RemoveObserver(observer); |
| 145 } |
| 146 |
139 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { | 147 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { |
140 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 148 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
141 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); | 149 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
142 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { | 150 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { |
143 DVLOG(1) << "Skip Failed FavIcon: " << url; | 151 DVLOG(1) << "Skip Failed FavIcon: " << url; |
144 return 0; | 152 return 0; |
145 } | 153 } |
146 | 154 |
147 return web_contents()->DownloadImage( | 155 return web_contents()->DownloadImage( |
148 url, | 156 url, |
149 true, | 157 true, |
150 max_image_size, | 158 max_image_size, |
151 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); | 159 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); |
152 } | 160 } |
153 | 161 |
154 void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) { | |
155 content::NotificationService::current()->Notify( | |
156 chrome::NOTIFICATION_FAVICON_UPDATED, | |
157 content::Source<WebContents>(web_contents()), | |
158 content::Details<bool>(&icon_url_changed)); | |
159 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | |
160 } | |
161 | |
162 bool FaviconTabHelper::IsOffTheRecord() { | 162 bool FaviconTabHelper::IsOffTheRecord() { |
163 DCHECK(web_contents()); | 163 DCHECK(web_contents()); |
164 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 164 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
165 } | 165 } |
166 | 166 |
167 const gfx::Image FaviconTabHelper::GetActiveFaviconImage() { | 167 const gfx::Image FaviconTabHelper::GetActiveFaviconImage() { |
168 return GetFaviconStatus().image; | 168 return GetFaviconStatus().image; |
169 } | 169 } |
170 | 170 |
171 const GURL FaviconTabHelper::GetActiveFaviconURL() { | 171 const GURL FaviconTabHelper::GetActiveFaviconURL() { |
(...skipping 16 matching lines...) Expand all Loading... |
188 } | 188 } |
189 | 189 |
190 void FaviconTabHelper::SetActiveFaviconURL(GURL url) { | 190 void FaviconTabHelper::SetActiveFaviconURL(GURL url) { |
191 GetFaviconStatus().url = url; | 191 GetFaviconStatus().url = url; |
192 } | 192 } |
193 | 193 |
194 void FaviconTabHelper::SetActiveFaviconValidity(bool validity) { | 194 void FaviconTabHelper::SetActiveFaviconValidity(bool validity) { |
195 GetFaviconStatus().valid = validity; | 195 GetFaviconStatus().valid = validity; |
196 } | 196 } |
197 | 197 |
| 198 void FaviconTabHelper::OnFaviconAvailable(const gfx::Image& image, |
| 199 const GURL& icon_url, |
| 200 bool update_active_favicon) { |
| 201 if (update_active_favicon) { |
| 202 // No matter what happens, we need to mark the favicon as being set. |
| 203 SetActiveFaviconValidity(true); |
| 204 bool icon_url_changed = GetActiveFaviconURL() != icon_url; |
| 205 SetActiveFaviconURL(icon_url); |
| 206 |
| 207 if (image.IsEmpty()) |
| 208 return; |
| 209 |
| 210 SetActiveFaviconImage(image); |
| 211 content::NotificationService::current()->Notify( |
| 212 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 213 content::Source<WebContents>(web_contents()), |
| 214 content::Details<bool>(&icon_url_changed)); |
| 215 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 216 } |
| 217 if (!image.IsEmpty()) |
| 218 FOR_EACH_OBSERVER(Observer, observer_list_, OnFaviconAvailable(image)); |
| 219 } |
| 220 |
198 content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() { | 221 content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() { |
199 DCHECK(web_contents()->GetController().GetActiveEntry()); | 222 DCHECK(web_contents()->GetController().GetActiveEntry()); |
200 return web_contents()->GetController().GetActiveEntry()->GetFavicon(); | 223 return web_contents()->GetController().GetActiveEntry()->GetFavicon(); |
201 } | 224 } |
202 | 225 |
203 void FaviconTabHelper::DidStartNavigationToPendingEntry( | 226 void FaviconTabHelper::DidStartNavigationToPendingEntry( |
204 const GURL& url, | 227 const GURL& url, |
205 NavigationController::ReloadType reload_type) { | 228 NavigationController::ReloadType reload_type) { |
206 if (reload_type != NavigationController::NO_RELOAD && | 229 if (reload_type != NavigationController::NO_RELOAD && |
207 !profile_->IsOffTheRecord()) { | 230 !profile_->IsOffTheRecord()) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 favicon_service->UnableToDownloadFavicon(image_url); | 297 favicon_service->UnableToDownloadFavicon(image_url); |
275 } | 298 } |
276 | 299 |
277 favicon_handler_->OnDidDownloadFavicon( | 300 favicon_handler_->OnDidDownloadFavicon( |
278 id, image_url, bitmaps, original_bitmap_sizes); | 301 id, image_url, bitmaps, original_bitmap_sizes); |
279 if (touch_icon_handler_.get()) { | 302 if (touch_icon_handler_.get()) { |
280 touch_icon_handler_->OnDidDownloadFavicon( | 303 touch_icon_handler_->OnDidDownloadFavicon( |
281 id, image_url, bitmaps, original_bitmap_sizes); | 304 id, image_url, bitmaps, original_bitmap_sizes); |
282 } | 305 } |
283 } | 306 } |
OLD | NEW |