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