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/bookmarks/bookmark_model_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/favicon/favicon_handler.h" | 9 #include "chrome/browser/favicon/favicon_handler.h" |
10 #include "chrome/browser/favicon/favicon_service_factory.h" | 10 #include "chrome/browser/favicon/favicon_service_factory.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return; | 128 return; |
129 const FaviconStatus& favicon(entry->GetFavicon()); | 129 const FaviconStatus& favicon(entry->GetFavicon()); |
130 if (!favicon.valid || favicon.url.is_empty() || | 130 if (!favicon.valid || favicon.url.is_empty() || |
131 favicon.image.IsEmpty()) { | 131 favicon.image.IsEmpty()) { |
132 return; | 132 return; |
133 } | 133 } |
134 service->SetFavicons( | 134 service->SetFavicons( |
135 entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image); | 135 entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image); |
136 } | 136 } |
137 | 137 |
138 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | |
139 return web_contents()->GetController().GetActiveEntry(); | |
140 } | |
141 | |
142 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { | 138 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { |
143 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 139 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
144 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); | 140 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
145 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { | 141 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { |
146 DVLOG(1) << "Skip Failed FavIcon: " << url; | 142 DVLOG(1) << "Skip Failed FavIcon: " << url; |
147 return 0; | 143 return 0; |
148 } | 144 } |
149 | 145 |
150 return web_contents()->DownloadImage( | 146 return web_contents()->DownloadImage( |
151 url, | 147 url, |
152 true, | 148 true, |
153 max_image_size, | 149 max_image_size, |
154 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); | 150 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); |
155 } | 151 } |
156 | 152 |
157 void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) { | 153 void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) { |
158 content::NotificationService::current()->Notify( | 154 content::NotificationService::current()->Notify( |
159 chrome::NOTIFICATION_FAVICON_UPDATED, | 155 chrome::NOTIFICATION_FAVICON_UPDATED, |
160 content::Source<WebContents>(web_contents()), | 156 content::Source<WebContents>(web_contents()), |
161 content::Details<bool>(&icon_url_changed)); | 157 content::Details<bool>(&icon_url_changed)); |
162 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
163 } | 159 } |
164 | 160 |
165 bool FaviconTabHelper::IsOffTheRecord() { | 161 bool FaviconTabHelper::IsOffTheRecord() { |
166 DCHECK(web_contents()); | 162 DCHECK(web_contents()); |
167 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 163 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
168 } | 164 } |
169 | 165 |
| 166 const gfx::Image FaviconTabHelper::GetActiveFaviconImage() { |
| 167 return GetFaviconStatus().image; |
| 168 } |
| 169 |
| 170 const GURL FaviconTabHelper::GetActiveFaviconURL() { |
| 171 return GetFaviconStatus().url; |
| 172 } |
| 173 |
| 174 bool FaviconTabHelper::GetActiveFaviconValidity() { |
| 175 return GetFaviconStatus().valid; |
| 176 } |
| 177 |
| 178 const GURL FaviconTabHelper::GetActiveURL() { |
| 179 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
| 180 if (!entry || entry->GetURL().is_empty()) |
| 181 return GURL(); |
| 182 return entry->GetURL(); |
| 183 } |
| 184 |
| 185 void FaviconTabHelper::SetActiveFaviconImage(gfx::Image image) { |
| 186 GetFaviconStatus().image = image; |
| 187 } |
| 188 |
| 189 void FaviconTabHelper::SetActiveFaviconURL(GURL url) { |
| 190 GetFaviconStatus().url = url; |
| 191 } |
| 192 |
| 193 void FaviconTabHelper::SetActiveFaviconValidity(bool validity) { |
| 194 GetFaviconStatus().valid = validity; |
| 195 } |
| 196 |
| 197 content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() { |
| 198 DCHECK(web_contents()->GetController().GetActiveEntry()); |
| 199 return web_contents()->GetController().GetActiveEntry()->GetFavicon(); |
| 200 } |
| 201 |
170 void FaviconTabHelper::DidStartNavigationToPendingEntry( | 202 void FaviconTabHelper::DidStartNavigationToPendingEntry( |
171 const GURL& url, | 203 const GURL& url, |
172 NavigationController::ReloadType reload_type) { | 204 NavigationController::ReloadType reload_type) { |
173 if (reload_type != NavigationController::NO_RELOAD && | 205 if (reload_type != NavigationController::NO_RELOAD && |
174 !profile_->IsOffTheRecord()) { | 206 !profile_->IsOffTheRecord()) { |
175 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 207 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
176 profile_, Profile::IMPLICIT_ACCESS); | 208 profile_, Profile::IMPLICIT_ACCESS); |
177 if (favicon_service) { | 209 if (favicon_service) { |
178 favicon_service->SetFaviconOutOfDateForPage(url); | 210 favicon_service->SetFaviconOutOfDateForPage(url); |
179 if (reload_type == NavigationController::RELOAD_IGNORING_CACHE) | 211 if (reload_type == NavigationController::RELOAD_IGNORING_CACHE) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 favicon_service->UnableToDownloadFavicon(image_url); | 257 favicon_service->UnableToDownloadFavicon(image_url); |
226 } | 258 } |
227 | 259 |
228 favicon_handler_->OnDidDownloadFavicon( | 260 favicon_handler_->OnDidDownloadFavicon( |
229 id, image_url, bitmaps, original_bitmap_sizes); | 261 id, image_url, bitmaps, original_bitmap_sizes); |
230 if (touch_icon_handler_.get()) { | 262 if (touch_icon_handler_.get()) { |
231 touch_icon_handler_->OnDidDownloadFavicon( | 263 touch_icon_handler_->OnDidDownloadFavicon( |
232 id, image_url, bitmaps, original_bitmap_sizes); | 264 id, image_url, bitmaps, original_bitmap_sizes); |
233 } | 265 } |
234 } | 266 } |
OLD | NEW |