Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tab_contents / favicon_util_mac.mm
blobd713b62fd46191f2e3d0c7bc57e5c126564abfa9
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h"
7 #include "components/favicon/content/content_favicon_driver.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/resources/grit/ui_resources.h"
11 namespace mac {
13 NSImage* FaviconForWebContents(content::WebContents* contents) {
14   favicon::FaviconDriver* favicon_driver =
15       contents ? favicon::ContentFaviconDriver::FromWebContents(contents)
16                : nullptr;
17   if (favicon_driver && favicon_driver->FaviconIsValid()) {
18     NSImage* image = favicon_driver->GetFavicon().AsNSImage();
19     // The |image| could be nil if the bitmap is null. In that case, fallback
20     // to the default image.
21     if (image) {
22       return image;
23     }
24   }
26   ResourceBundle& rb = ResourceBundle::GetSharedInstance();
27   return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage();
30 }  // namespace mac