Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: components/favicon/content/content_favicon_driver.cc

Issue 2321833002: [Mac] Desaturate the Favicon for Network Errors (Closed)
Patch Set: move desaturation code Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/favicon/content/content_favicon_driver.h" 5 #include "components/favicon/content/content_favicon_driver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/favicon/content/favicon_url_util.h" 8 #include "components/favicon/content/favicon_url_util.h"
9 #include "components/favicon/core/favicon_service.h" 9 #include "components/favicon/core/favicon_service.h"
10 #include "components/favicon/core/favicon_url.h" 10 #include "components/favicon/core/favicon_url.h"
11 #include "components/history/core/browser/history_service.h" 11 #include "components/history/core/browser/history_service.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/favicon_status.h" 13 #include "content/public/browser/favicon_status.h"
14 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_details.h"
16 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/common/favicon_url.h" 17 #include "content/public/common/favicon_url.h"
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/image/image_skia_operations.h"
19 21
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver);
21 23
24 #if defined(OS_MACOSX) || defined(TOOLKIT_VIEWS)
25
26 namespace {
27
28 // Desaturate favicon HSL shift values.
29 const double kDesaturateHue = -1.0;
30 const double kDesaturateSaturation = 0.0;
31 const double kDesaturateLightness = 0.6;
32
33 gfx::Image GetDesaturatedFavicon(gfx::Image favicon) {
34 color_utils::HSL shift = {kDesaturateHue, kDesaturateSaturation,
35 kDesaturateLightness};
36 const gfx::ImageSkia* image = favicon.ToImageSkia();
37 if (image) {
Nico 2016/09/15 16:58:37 Can this ever be not true? I thought ToImageSkia()
spqchan 2016/09/15 22:07:04 Sure thing, I was just cautious
38 return gfx::Image(
39 gfx::ImageSkiaOperations::CreateHSLShiftedImage(*image, shift));
40 }
41
42 return favicon;
43 }
44
45 } // namespace
46
47 #endif
48
22 namespace favicon { 49 namespace favicon {
23 50
24 // static 51 // static
25 void ContentFaviconDriver::CreateForWebContents( 52 void ContentFaviconDriver::CreateForWebContents(
26 content::WebContents* web_contents, 53 content::WebContents* web_contents,
27 FaviconService* favicon_service, 54 FaviconService* favicon_service,
28 history::HistoryService* history_service, 55 history::HistoryService* history_service,
29 bookmarks::BookmarkModel* bookmark_model) { 56 bookmarks::BookmarkModel* bookmark_model) {
30 if (FromWebContents(web_contents)) 57 if (FromWebContents(web_contents))
31 return; 58 return;
(...skipping 29 matching lines...) Expand all
61 gfx::Image ContentFaviconDriver::GetFavicon() const { 88 gfx::Image ContentFaviconDriver::GetFavicon() const {
62 // Like GetTitle(), we also want to use the favicon for the last committed 89 // Like GetTitle(), we also want to use the favicon for the last committed
63 // entry rather than a pending navigation entry. 90 // entry rather than a pending navigation entry.
64 const content::NavigationController& controller = 91 const content::NavigationController& controller =
65 web_contents()->GetController(); 92 web_contents()->GetController();
66 content::NavigationEntry* entry = controller.GetTransientEntry(); 93 content::NavigationEntry* entry = controller.GetTransientEntry();
67 if (entry) 94 if (entry)
68 return entry->GetFavicon().image; 95 return entry->GetFavicon().image;
69 96
70 entry = controller.GetLastCommittedEntry(); 97 entry = controller.GetLastCommittedEntry();
71 if (entry) 98 if (entry) {
72 return entry->GetFavicon().image; 99 gfx::Image image = entry->GetFavicon().image;
100
101 #if defined(OS_MACOSX) || defined(TOOLKIT_VIEWS)
102 bool network_error = !web_contents()->IsLoadingToDifferentDocument() &&
103 entry->GetPageType() == content::PAGE_TYPE_ERROR;
104 if (network_error)
105 return GetDesaturatedFavicon(image);
106 #endif
107
108 return image;
109 }
73 return gfx::Image(); 110 return gfx::Image();
74 } 111 }
75 112
76 bool ContentFaviconDriver::FaviconIsValid() const { 113 bool ContentFaviconDriver::FaviconIsValid() const {
77 const content::NavigationController& controller = 114 const content::NavigationController& controller =
78 web_contents()->GetController(); 115 web_contents()->GetController();
79 content::NavigationEntry* entry = controller.GetTransientEntry(); 116 content::NavigationEntry* entry = controller.GetTransientEntry();
80 if (entry) 117 if (entry)
81 return entry->GetFavicon().valid; 118 return entry->GetFavicon().valid;
82 119
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // redownloaded. 226 // redownloaded.
190 GURL url = details.entry->GetURL(); 227 GURL url = details.entry->GetURL();
191 if (url != bypass_cache_page_url_) 228 if (url != bypass_cache_page_url_)
192 bypass_cache_page_url_ = GURL(); 229 bypass_cache_page_url_ = GURL();
193 230
194 // Get the favicon, either from history or request it from the net. 231 // Get the favicon, either from history or request it from the net.
195 FetchFavicon(url); 232 FetchFavicon(url);
196 } 233 }
197 234
198 } // namespace favicon 235 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698