Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "chrome/browser/extensions/extension_icon_image.h" | |
| 9 #include "chrome/common/extensions/extension.h" | |
| 10 #include "chrome/common/extensions/extension_icon_set.h" | |
| 11 #include "grit/theme_resources.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | |
| 14 | |
| 15 using extensions::Extension; | |
| 16 using extensions::IconImage; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 gfx::ImageSkia GetDefaultIcon() { | |
| 21 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 22 IDR_EXTENSIONS_FAVICON).ToImageSkia(); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 // extension::IconImage wrapper for extension action icons. We need this | |
| 28 // because ExtensionAction class cannot use extensions::IconImage directly. | |
| 29 ExtensionActionIconFactory::ExtensionActionIconFactory( | |
| 30 const Extension* extension, Observer* observer) | |
| 31 : extension_(extension), | |
| 32 observer_(observer), | |
| 33 last_icon_set_(NULL), | |
| 34 last_size_(0) { | |
| 35 } | |
| 36 | |
| 37 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} | |
| 38 | |
| 39 // extensions::IconImage::Observer overrides. | |
| 40 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { | |
| 41 observer_->OnIconUpdated(); | |
| 42 } | |
| 43 | |
| 44 gfx::ImageSkia ExtensionActionIconFactory::GetIcon( | |
| 45 const ExtensionIconSet* icon_set, | |
| 46 int desired_size) { | |
| 47 // If icon set hasn't changed, return the present icon. | |
| 48 if (icon_.get() && last_icon_set_ == icon_set) { | |
| 49 DCHECK_EQ(last_size_, desired_size); | |
|
Jeffrey Yasskin
2012/09/13 00:23:36
I don't see a reason to DCHECK that the sizes matc
tbarzic
2012/09/13 02:01:01
Done.
| |
| 50 return icon_->image_skia(); | |
| 51 } | |
| 52 | |
| 53 // TODO(tbarzic): Cache old icon, so we don't have to reload it if gets | |
| 54 // requested again. | |
| 55 icon_.reset( | |
| 56 new IconImage(extension_, *icon_set, desired_size, GetDefaultIcon(), | |
| 57 this)); | |
| 58 last_icon_set_ = icon_set; | |
| 59 last_size_ = desired_size; | |
| 60 | |
| 61 return icon_->image_skia(); | |
| 62 } | |
| OLD | NEW |