| 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_utils.h" | 5 #include "chrome/browser/favicon/favicon_utils.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/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "components/favicon/content/content_favicon_driver.h" |
| 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/common/favicon_url.h" | 16 #include "content/public/common/favicon_url.h" |
| 17 #include "ui/gfx/image/image.h" |
| 18 #include "ui/gfx/image/image_skia.h" |
| 19 #include "ui/gfx/image/image_skia_operations.h" |
| 14 | 20 |
| 15 namespace favicon { | 21 namespace favicon { |
| 16 | 22 |
| 23 namespace { |
| 24 |
| 25 // Desaturate favicon HSL shift values. |
| 26 const double kDesaturateHue = -1.0; |
| 27 const double kDesaturateSaturation = 0.0; |
| 28 const double kDesaturateLightness = 0.6; |
| 29 } |
| 30 |
| 17 void CreateContentFaviconDriverForWebContents( | 31 void CreateContentFaviconDriverForWebContents( |
| 18 content::WebContents* web_contents) { | 32 content::WebContents* web_contents) { |
| 19 DCHECK(web_contents); | 33 DCHECK(web_contents); |
| 20 if (ContentFaviconDriver::FromWebContents(web_contents)) | 34 if (ContentFaviconDriver::FromWebContents(web_contents)) |
| 21 return; | 35 return; |
| 22 | 36 |
| 23 Profile* original_profile = | 37 Profile* original_profile = |
| 24 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 38 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 25 ->GetOriginalProfile(); | 39 ->GetOriginalProfile(); |
| 26 return ContentFaviconDriver::CreateForWebContents( | 40 return ContentFaviconDriver::CreateForWebContents( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 return false; | 58 return false; |
| 45 } | 59 } |
| 46 | 60 |
| 47 // No favicon on Instant New Tab Pages. | 61 // No favicon on Instant New Tab Pages. |
| 48 if (search::IsInstantNTP(web_contents)) | 62 if (search::IsInstantNTP(web_contents)) |
| 49 return false; | 63 return false; |
| 50 | 64 |
| 51 return true; | 65 return true; |
| 52 } | 66 } |
| 53 | 67 |
| 68 gfx::Image TabFaviconFromWebContents(content::WebContents* contents) { |
| 69 DCHECK(contents); |
| 70 |
| 71 favicon::FaviconDriver* favicon_driver = |
| 72 favicon::ContentFaviconDriver::FromWebContents(contents); |
| 73 gfx::Image favicon = favicon_driver->GetFavicon(); |
| 74 |
| 75 // Desaturate the favicon if the navigation entry contains a network error. |
| 76 if (!contents->IsLoadingToDifferentDocument()) { |
| 77 const content::NavigationController& controller = contents->GetController(); |
| 78 |
| 79 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 80 if (entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR)) { |
| 81 color_utils::HSL shift = {kDesaturateHue, kDesaturateSaturation, |
| 82 kDesaturateLightness}; |
| 83 return gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage( |
| 84 *favicon.ToImageSkia(), shift)); |
| 85 } |
| 86 } |
| 87 |
| 88 return favicon; |
| 89 } |
| 90 |
| 54 } // namespace favicon | 91 } // namespace favicon |
| OLD | NEW |