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/ui/cocoa/tab_contents/favicon_util_mac.h" | 5 #include "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "components/favicon/content/content_favicon_driver.h" | 10 #include "components/favicon/content/content_favicon_driver.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 namespace mac { | 91 namespace mac { |
92 | 92 |
93 NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) { | 93 NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) { |
94 favicon::FaviconDriver* favicon_driver = | 94 favicon::FaviconDriver* favicon_driver = |
95 contents ? favicon::ContentFaviconDriver::FromWebContents(contents) | 95 contents ? favicon::ContentFaviconDriver::FromWebContents(contents) |
96 : nullptr; | 96 : nullptr; |
97 if (favicon_driver && favicon_driver->FaviconIsValid()) { | 97 if (favicon_driver && favicon_driver->FaviconIsValid()) { |
98 NSImage* image = favicon_driver->GetFavicon().AsNSImage(); | 98 NSImage* image = favicon_driver->GetFavicon().AsNSImage(); |
99 // The |image| could be nil if the bitmap is null. In that case, fallback | 99 // The |image| could be nil if the bitmap is null. In that case, fallback |
100 // to the default image. | 100 // to the default image. |
101 if (image) { | 101 if (image) |
102 return image; | 102 return image; |
103 } | |
104 } | 103 } |
105 | 104 |
| 105 return DefaultFavicon(color); |
| 106 } |
| 107 |
| 108 NSImage* DefaultFavicon(SkColor color) { |
106 if (ui::MaterialDesignController::IsModeMaterial()) | 109 if (ui::MaterialDesignController::IsModeMaterial()) |
107 return [DefaultFaviconImageRep imageForColor:color]; | 110 return [DefaultFaviconImageRep imageForColor:color]; |
108 | 111 |
109 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
110 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); | 113 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); |
111 } | 114 } |
112 | 115 |
| 116 bool ShouldUseDefaultFavicon(content::WebContents* contents) { |
| 117 favicon::FaviconDriver* favicon_driver = |
| 118 contents ? favicon::ContentFaviconDriver::FromWebContents(contents) |
| 119 : nullptr; |
| 120 if (favicon_driver && favicon_driver->FaviconIsValid()) |
| 121 return favicon_driver->GetFavicon().IsEmpty(); |
| 122 |
| 123 return YES; |
| 124 } |
| 125 |
113 } // namespace mac | 126 } // namespace mac |
OLD | NEW |