Chromium Code Reviews| 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 "base/metrics/field_trial.h" | |
| 8 #include "base/strings/string_util.h" | |
| 7 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/favicon/chrome_favicon_client.h" | 10 #include "chrome/browser/favicon/chrome_favicon_client.h" |
| 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 11 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
| 10 #include "chrome/browser/favicon/favicon_service_factory.h" | 12 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 16 #include "components/favicon/core/browser/favicon_handler.h" | 18 #include "components/favicon/core/browser/favicon_handler.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 33 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
| 34 #include "ui/gfx/image/image_skia_rep.h" | 36 #include "ui/gfx/image/image_skia_rep.h" |
| 35 | 37 |
| 36 using content::FaviconStatus; | 38 using content::FaviconStatus; |
| 37 using content::NavigationController; | 39 using content::NavigationController; |
| 38 using content::NavigationEntry; | 40 using content::NavigationEntry; |
| 39 using content::WebContents; | 41 using content::WebContents; |
| 40 | 42 |
| 41 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper); | 43 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper); |
| 42 | 44 |
| 45 namespace { | |
| 46 | |
| 47 // Returns whether icon NTP is enabled. | |
| 48 bool IsIconNTPEnabled() { | |
|
sky
2015/05/06 19:29:05
Will this ever be used on android?
huangs
2015/05/06 19:59:14
Currently it isn't, and likely Android will do thi
| |
| 49 return StartsWithASCII(base::FieldTrialList::FindFullName("IconNTP"), | |
| 50 "Enabled", true); | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 43 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 55 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
| 44 : content::WebContentsObserver(web_contents), | 56 : content::WebContentsObserver(web_contents), |
| 45 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 57 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 46 client_ = ChromeFaviconClientFactory::GetForProfile(profile_); | 58 client_ = ChromeFaviconClientFactory::GetForProfile(profile_); |
| 47 #if defined(OS_ANDROID) || defined(OS_IOS) | 59 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 48 bool download_largest_icon = true; | 60 bool download_largest_icon = true; |
| 49 #else | 61 #else |
| 50 bool download_largest_icon = false; | 62 bool download_largest_icon = false; |
| 51 #endif | 63 #endif |
| 52 FaviconService* service = FaviconServiceFactory::GetForProfile( | 64 FaviconService* service = FaviconServiceFactory::GetForProfile( |
| 53 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 65 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 54 favicon_handler_.reset(new FaviconHandler( | 66 favicon_handler_.reset(new FaviconHandler( |
| 55 service, client_, this, FaviconHandler::FAVICON, download_largest_icon)); | 67 service, client_, this, FaviconHandler::FAVICON, download_largest_icon)); |
| 56 if (chrome::kEnableTouchIcon) | 68 if (chrome::kEnableTouchIcon) |
| 57 touch_icon_handler_.reset(new FaviconHandler( | 69 touch_icon_handler_.reset(new FaviconHandler( |
| 58 service, client_, this, FaviconHandler::TOUCH, download_largest_icon)); | 70 service, client_, this, FaviconHandler::TOUCH, download_largest_icon)); |
| 71 if (IsIconNTPEnabled()) | |
|
sky
2015/05/06 20:13:53
My concern is more of here. If IsIconNTPEnabled is
huangs
2015/05/06 20:33:55
rogerm@ has considered this, and has a CL to make
| |
| 72 large_icon_handler_.reset(new FaviconHandler( | |
| 73 service, client_, this, FaviconHandler::LARGE, true)); | |
| 59 } | 74 } |
| 60 | 75 |
| 61 FaviconTabHelper::~FaviconTabHelper() { | 76 FaviconTabHelper::~FaviconTabHelper() { |
| 62 } | 77 } |
| 63 | 78 |
| 64 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 79 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
| 65 favicon_handler_->FetchFavicon(url); | 80 favicon_handler_->FetchFavicon(url); |
| 66 if (touch_icon_handler_.get()) | 81 if (touch_icon_handler_.get()) |
| 67 touch_icon_handler_->FetchFavicon(url); | 82 touch_icon_handler_->FetchFavicon(url); |
| 83 if (large_icon_handler_.get()) | |
| 84 large_icon_handler_->FetchFavicon(url); | |
| 68 } | 85 } |
| 69 | 86 |
| 70 gfx::Image FaviconTabHelper::GetFavicon() const { | 87 gfx::Image FaviconTabHelper::GetFavicon() const { |
| 71 // Like GetTitle(), we also want to use the favicon for the last committed | 88 // Like GetTitle(), we also want to use the favicon for the last committed |
| 72 // entry rather than a pending navigation entry. | 89 // entry rather than a pending navigation entry. |
| 73 const NavigationController& controller = web_contents()->GetController(); | 90 const NavigationController& controller = web_contents()->GetController(); |
| 74 NavigationEntry* entry = controller.GetTransientEntry(); | 91 NavigationEntry* entry = controller.GetTransientEntry(); |
| 75 if (entry) | 92 if (entry) |
| 76 return entry->GetFavicon().image; | 93 return entry->GetFavicon().image; |
| 77 | 94 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 for (size_t i = 0; i < candidates.size(); i++) { | 310 for (size_t i = 0; i < candidates.size(); i++) { |
| 294 const content::FaviconURL& candidate = candidates[i]; | 311 const content::FaviconURL& candidate = candidates[i]; |
| 295 favicon_urls.push_back( | 312 favicon_urls.push_back( |
| 296 favicon::FaviconURL(candidate.icon_url, | 313 favicon::FaviconURL(candidate.icon_url, |
| 297 ToChromeIconType(candidate.icon_type), | 314 ToChromeIconType(candidate.icon_type), |
| 298 candidate.icon_sizes)); | 315 candidate.icon_sizes)); |
| 299 } | 316 } |
| 300 favicon_handler_->OnUpdateFaviconURL(favicon_urls); | 317 favicon_handler_->OnUpdateFaviconURL(favicon_urls); |
| 301 if (touch_icon_handler_.get()) | 318 if (touch_icon_handler_.get()) |
| 302 touch_icon_handler_->OnUpdateFaviconURL(favicon_urls); | 319 touch_icon_handler_->OnUpdateFaviconURL(favicon_urls); |
| 320 if (large_icon_handler_.get()) | |
| 321 large_icon_handler_->OnUpdateFaviconURL(favicon_urls); | |
| 303 } | 322 } |
| 304 | 323 |
| 305 void FaviconTabHelper::DidDownloadFavicon( | 324 void FaviconTabHelper::DidDownloadFavicon( |
| 306 int id, | 325 int id, |
| 307 int http_status_code, | 326 int http_status_code, |
| 308 const GURL& image_url, | 327 const GURL& image_url, |
| 309 const std::vector<SkBitmap>& bitmaps, | 328 const std::vector<SkBitmap>& bitmaps, |
| 310 const std::vector<gfx::Size>& original_bitmap_sizes) { | 329 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 311 | 330 |
| 312 if (bitmaps.empty() && http_status_code == 404) { | 331 if (bitmaps.empty() && http_status_code == 404) { |
| 313 DVLOG(1) << "Failed to Download Favicon:" << image_url; | 332 DVLOG(1) << "Failed to Download Favicon:" << image_url; |
| 314 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 333 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 315 profile_->GetOriginalProfile(), ServiceAccessType::IMPLICIT_ACCESS); | 334 profile_->GetOriginalProfile(), ServiceAccessType::IMPLICIT_ACCESS); |
| 316 if (favicon_service) | 335 if (favicon_service) |
| 317 favicon_service->UnableToDownloadFavicon(image_url); | 336 favicon_service->UnableToDownloadFavicon(image_url); |
| 318 } | 337 } |
| 319 | 338 |
| 320 favicon_handler_->OnDidDownloadFavicon( | 339 favicon_handler_->OnDidDownloadFavicon( |
| 321 id, image_url, bitmaps, original_bitmap_sizes); | 340 id, image_url, bitmaps, original_bitmap_sizes); |
| 322 if (touch_icon_handler_.get()) { | 341 if (touch_icon_handler_.get()) { |
| 323 touch_icon_handler_->OnDidDownloadFavicon( | 342 touch_icon_handler_->OnDidDownloadFavicon( |
| 324 id, image_url, bitmaps, original_bitmap_sizes); | 343 id, image_url, bitmaps, original_bitmap_sizes); |
| 325 } | 344 } |
| 345 if (large_icon_handler_.get()) { | |
| 346 large_icon_handler_->OnDidDownloadFavicon( | |
| 347 id, image_url, bitmaps, original_bitmap_sizes); | |
| 348 } | |
| 326 } | 349 } |
| OLD | NEW |