From 81e513a94e5ab4e1108aae7b06f754115f219051 Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Mon, 6 Aug 2012 15:16:50 +0000 Subject: Fall back to the default favicon on invalid favicon files. I regressed this in r149891. BUG=140689 Review URL: https://chromiumcodereview.appspot.com/10853018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150092 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm | 2 +- ui/gfx/image/image.cc | 8 +++++++- ui/gfx/image/image.h | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm index 8ab22c2..9cc016e 100644 --- a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm +++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm @@ -13,7 +13,7 @@ namespace mac { NSImage* FaviconForTabContents(TabContents* contents) { if (contents && contents->favicon_tab_helper()->FaviconIsValid()) { - NSImage* image = contents->favicon_tab_helper()->GetFavicon().ToNSImage(); + NSImage* image = contents->favicon_tab_helper()->GetFavicon().AsNSImage(); // The |image| could be nil if the bitmap is null. In that case, fallback // to the default image. if (image) { diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc index 9854787..9c709dc 100644 --- a/ui/gfx/image/image.cc +++ b/ui/gfx/image/image.cc @@ -342,9 +342,15 @@ SkBitmap Image::AsBitmap() const { } ImageSkia Image::AsImageSkia() const { - return IsEmpty() ? ImageSkia(SkBitmap()) : *ToImageSkia(); + return IsEmpty() ? ImageSkia() : *ToImageSkia(); } +#if defined(OS_MACOSX) +NSImage* Image::AsNSImage() const { + return IsEmpty() ? nil : ToNSImage(); +} +#endif + ImageSkia* Image::CopyImageSkia() const { return new ImageSkia(*ToImageSkia()); } diff --git a/ui/gfx/image/image.h b/ui/gfx/image/image.h index 04a79da..b643362 100644 --- a/ui/gfx/image/image.h +++ b/ui/gfx/image/image.h @@ -97,7 +97,7 @@ class UI_EXPORT Image { // Converts the Image to the desired representation and stores it internally. // The returned result is a weak pointer owned by and scoped to the life of - // the Image. + // the Image. Must only be called if IsEmpty() is false. const SkBitmap* ToSkBitmap() const; const ImageSkia* ToImageSkia() const; #if defined(TOOLKIT_GTK) @@ -110,10 +110,15 @@ class UI_EXPORT Image { // Same as ToSkBitmap(), but returns a null SkBitmap if this image is empty. SkBitmap AsBitmap() const; - // Same as ToSkBitmap(), but returns a ImageSkia with a null SkBitmap if this + // Same as ToImageSkia(), but returns an empty ImageSkia if this // image is empty. ImageSkia AsImageSkia() const; +#if defined(OS_MACOSX) + // Same as ToSkBitmap(), but returns nil if this image is empty. + NSImage* AsNSImage() const; +#endif + // Performs a conversion, like above, but returns a copy of the result rather // than a weak pointer. The caller is responsible for deleting the result. // Note that the result is only a copy in terms of memory management; the -- cgit v1.1