summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/cocoa/tab_contents/favicon_util.mm')
-rw-r--r--chrome/browser/ui/cocoa/tab_contents/favicon_util.mm35
1 files changed, 35 insertions, 0 deletions
diff --git a/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm b/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm
new file mode 100644
index 0000000..3fcba52
--- /dev/null
+++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm
@@ -0,0 +1,35 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/cocoa/tab_contents/favicon_util.h"
+
+#import <AppKit/AppKit.h>
+
+#include "app/mac/nsimage_cache.h"
+#include "base/mac/mac_util.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "skia/ext/skia_utils_mac.h"
+
+namespace mac {
+
+NSImage* FaviconForTabContents(TabContents* contents) {
+ // TabContents returns IDR_DEFAULT_FAVICON, which is a rasterized version of
+ // the Mac PDF. Use the PDF so the icon in the Omnibox matches the default
+ // favicon.
+ if (contents && contents->FaviconIsValid()) {
+ CGColorSpaceRef color_space = base::mac::GetSystemColorSpace();
+ NSImage* image =
+ gfx::SkBitmapToNSImageWithColorSpace(contents->GetFavicon(),
+ color_space);
+ // The |image| could be nil if the bitmap is null. In that case, fallback
+ // to the default image.
+ if (image) {
+ return image;
+ }
+ }
+
+ return app::mac::GetCachedImageWithName(@"nav.pdf");
+}
+
+} // namespace mac