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

Unified Diff: chrome/browser/cocoa/tab_strip_controller.mm

Issue 131018: Add favicons to tabs on the Mac (Closed)
Patch Set: Rebase Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/tab_strip_controller.mm
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index 90fced55f4a53d5e914281f71e293434d7d0f6a8..1acff657d5a6b66bf3a8c8239202953dc3ee330b 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -5,6 +5,7 @@
#import "chrome/browser/cocoa/tab_strip_controller.h"
#include "app/l10n_util.h"
+#include "base/mac_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
@@ -17,10 +18,13 @@
#import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
#import "chrome/browser/cocoa/tab_view.h"
#import "chrome/browser/cocoa/throbber_view.h"
+#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "grit/generated_resources.h"
+#include "skia/ext/skia_utils_mac.h"
NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
@@ -420,13 +424,31 @@ NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
// A helper routine for creating an NSImageView to hold the fav icon for
// |contents|.
-// TODO(pinkerton): fill in with code to use the real favicon, not the default
-// for all cases.
- (NSImageView*)favIconImageViewForContents:(TabContents*)contents {
NSRect iconFrame = NSMakeRect(0, 0, 16, 16);
NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame]
autorelease];
- [view setImage:[NSImage imageNamed:@"nav"]];
+
+ NSImage* image = nil;
+
+ NavigationEntry* navEntry = contents->controller().GetLastCommittedEntry();
+ if (navEntry != NULL) {
+ NavigationEntry::FaviconStatus favIcon = navEntry->favicon();
+ const SkBitmap& bitmap = favIcon.bitmap();
+ if (favIcon.is_valid() && !bitmap.isNull())
+ image = gfx::SkBitmapToNSImage(bitmap);
+ }
+
+ // Either we don't have a valid favicon or there was some issue converting it
+ // from an SkBitmap. Either way, just show the default.
+ if (!image) {
+ NSBundle* bundle = mac_util::MainAppBundle();
+ image = [[NSImage alloc] initByReferencingFile:
+ [bundle pathForResource:@"nav" ofType:@"pdf"]];
+ [image autorelease];
+ }
+
+ [view setImage:image];
return view;
}
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698