Index: chrome/browser/favicon_delegate.cc |
diff --git a/chrome/browser/favicon_delegate.cc b/chrome/browser/favicon_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4ef2580f6e82fa87749db5c4f36b9e6b71985cb2 |
--- /dev/null |
+++ b/chrome/browser/favicon_delegate.cc |
@@ -0,0 +1,61 @@ |
+// 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/favicon_delegate.h" |
+ |
+#include "content/browser/tab_contents/navigation_entry.h" |
+#include "content/browser/tab_contents/tab_contents.h" |
+#include "ui/gfx/favicon_size.h" |
+ |
+FaviconDelegate::FaviconDelegate(TabContents* tab_contents) |
+ : IconDelegate(), |
+ tab_contents_(tab_contents) { |
+} |
+ |
+FaviconDelegate::~FaviconDelegate() { |
+} |
+ |
+void FaviconDelegate::UpdateFaviconImageData( |
+ NavigationEntry* entry, |
+ const GURL& icon_url, |
+ scoped_refptr<RefCountedMemory> data) { |
+ if (entry->favicon().is_valid() && icon_url != entry->favicon().url()) |
+ return; |
+ UpdateFaviconImageData(entry, data); |
+} |
+ |
+void FaviconDelegate::UpdateFaviconImageData(NavigationEntry* entry, |
+ const SkBitmap& image) { |
+ // No matter what happens, we need to mark the favicon as being set. |
+ entry->favicon().set_is_valid(true); |
+ |
+ if (image.empty()) |
+ return; |
+ |
+ entry->favicon().set_bitmap(image); |
+ tab_contents_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); |
+} |
+ |
+void FaviconDelegate::UpdateFaviconURL(NavigationEntry* entry, |
+ const GURL& url) { |
+ entry->favicon().set_url(url); |
+} |
+ |
+SkBitmap FaviconDelegate::ConvertToFaviconSize(const SkBitmap& image) { |
+ int width = image.width(); |
+ int height = image.height(); |
+ |
+ if (width > 0 && width != kFaviconSize && height > 0 |
+ && height != kFaviconSize) { |
+ calc_favicon_target_size(&width, &height); |
+ return skia::ImageOperations::Resize( |
+ image, skia::ImageOperations::RESIZE_LANCZOS3, |
+ width, height); |
+ } |
+ return image; |
+} |
+ |
+int FaviconDelegate::GetIconSize() { |
+ return kFaviconSize; |
+} |