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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { | 150 int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { |
151 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 151 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
152 profile_->GetOriginalProfile(), ServiceAccessType::IMPLICIT_ACCESS); | 152 profile_->GetOriginalProfile(), ServiceAccessType::IMPLICIT_ACCESS); |
153 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { | 153 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { |
154 DVLOG(1) << "Skip Failed FavIcon: " << url; | 154 DVLOG(1) << "Skip Failed FavIcon: " << url; |
155 return 0; | 155 return 0; |
156 } | 156 } |
157 | 157 |
| 158 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); |
| 159 bypass_cache_page_url_ = GURL(); |
| 160 |
158 return web_contents()->DownloadImage( | 161 return web_contents()->DownloadImage( |
159 url, | 162 url, true, max_image_size, bypass_cache, |
160 true, | 163 base::Bind(&FaviconTabHelper::DidDownloadFavicon, |
161 max_image_size, | 164 base::Unretained(this))); |
162 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); | |
163 } | 165 } |
164 | 166 |
165 bool FaviconTabHelper::IsOffTheRecord() { | 167 bool FaviconTabHelper::IsOffTheRecord() { |
166 DCHECK(web_contents()); | 168 DCHECK(web_contents()); |
167 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 169 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
168 } | 170 } |
169 | 171 |
170 const gfx::Image FaviconTabHelper::GetActiveFaviconImage() { | 172 const gfx::Image FaviconTabHelper::GetActiveFaviconImage() { |
171 return GetFaviconStatus().image; | 173 return GetFaviconStatus().image; |
172 } | 174 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() { | 227 content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() { |
226 DCHECK(web_contents()->GetController().GetActiveEntry()); | 228 DCHECK(web_contents()->GetController().GetActiveEntry()); |
227 return web_contents()->GetController().GetActiveEntry()->GetFavicon(); | 229 return web_contents()->GetController().GetActiveEntry()->GetFavicon(); |
228 } | 230 } |
229 | 231 |
230 void FaviconTabHelper::DidStartNavigationToPendingEntry( | 232 void FaviconTabHelper::DidStartNavigationToPendingEntry( |
231 const GURL& url, | 233 const GURL& url, |
232 NavigationController::ReloadType reload_type) { | 234 NavigationController::ReloadType reload_type) { |
233 if (reload_type != NavigationController::NO_RELOAD && | 235 if (reload_type != NavigationController::NO_RELOAD && |
234 !profile_->IsOffTheRecord()) { | 236 !profile_->IsOffTheRecord()) { |
| 237 bypass_cache_page_url_ = url; |
| 238 |
235 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 239 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
236 profile_, ServiceAccessType::IMPLICIT_ACCESS); | 240 profile_, ServiceAccessType::IMPLICIT_ACCESS); |
237 if (favicon_service) { | 241 if (favicon_service) { |
238 favicon_service->SetFaviconOutOfDateForPage(url); | 242 favicon_service->SetFaviconOutOfDateForPage(url); |
239 if (reload_type == NavigationController::RELOAD_IGNORING_CACHE) | 243 if (reload_type == NavigationController::RELOAD_IGNORING_CACHE) |
240 favicon_service->ClearUnableToDownloadFavicons(); | 244 favicon_service->ClearUnableToDownloadFavicons(); |
241 } | 245 } |
242 } | 246 } |
243 } | 247 } |
244 | 248 |
245 void FaviconTabHelper::DidNavigateMainFrame( | 249 void FaviconTabHelper::DidNavigateMainFrame( |
246 const content::LoadCommittedDetails& details, | 250 const content::LoadCommittedDetails& details, |
247 const content::FrameNavigateParams& params) { | 251 const content::FrameNavigateParams& params) { |
248 favicon_urls_.clear(); | 252 favicon_urls_.clear(); |
| 253 |
| 254 // Wait till the user navigates to a new URL to start checking the cache |
| 255 // again. The cache may be ignored for non-reload navigations (e.g. |
| 256 // history.replace() in-page navigation). This is allowed to increase the |
| 257 // likelihood that "reloading a page ignoring the cache" redownloads the |
| 258 // favicon. In particular, a page may do an in-page navigation before |
| 259 // FaviconHandler has the time to determine that the favicon needs to be |
| 260 // redownloaded. |
| 261 GURL url = details.entry->GetURL(); |
| 262 if (url != bypass_cache_page_url_) |
| 263 bypass_cache_page_url_ = GURL(); |
| 264 |
249 // Get the favicon, either from history or request it from the net. | 265 // Get the favicon, either from history or request it from the net. |
250 FetchFavicon(details.entry->GetURL()); | 266 FetchFavicon(url); |
251 } | 267 } |
252 | 268 |
253 // Returns favicon_base::IconType the given icon_type corresponds to. | 269 // Returns favicon_base::IconType the given icon_type corresponds to. |
254 // TODO(jif): Move function to /components/favicon_base/content/ | 270 // TODO(jif): Move function to /components/favicon_base/content/ |
255 // crbug.com/374281. | 271 // crbug.com/374281. |
256 favicon_base::IconType ToChromeIconType( | 272 favicon_base::IconType ToChromeIconType( |
257 content::FaviconURL::IconType icon_type) { | 273 content::FaviconURL::IconType icon_type) { |
258 switch (icon_type) { | 274 switch (icon_type) { |
259 case content::FaviconURL::FAVICON: | 275 case content::FaviconURL::FAVICON: |
260 return favicon_base::FAVICON; | 276 return favicon_base::FAVICON; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 favicon_service->UnableToDownloadFavicon(image_url); | 317 favicon_service->UnableToDownloadFavicon(image_url); |
302 } | 318 } |
303 | 319 |
304 favicon_handler_->OnDidDownloadFavicon( | 320 favicon_handler_->OnDidDownloadFavicon( |
305 id, image_url, bitmaps, original_bitmap_sizes); | 321 id, image_url, bitmaps, original_bitmap_sizes); |
306 if (touch_icon_handler_.get()) { | 322 if (touch_icon_handler_.get()) { |
307 touch_icon_handler_->OnDidDownloadFavicon( | 323 touch_icon_handler_->OnDidDownloadFavicon( |
308 id, image_url, bitmaps, original_bitmap_sizes); | 324 id, image_url, bitmaps, original_bitmap_sizes); |
309 } | 325 } |
310 } | 326 } |
OLD | NEW |