Index: chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image.h |
diff --git a/chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image.h b/chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea3200e47dccc27464c402fbee2e75b09745217e |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image.h |
@@ -0,0 +1,83 @@ |
+// Copyright 2015 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. |
+ |
+#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_LAUNCHER_SEARCH_EXTENSION_BADGED_ICON_IMAGE_H_ |
+#define CHROME_BROWSER_UI_APP_LIST_SEARCH_LAUNCHER_SEARCH_EXTENSION_BADGED_ICON_IMAGE_H_ |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "extensions/browser/extension_icon_image.h" |
+#include "extensions/common/extension.h" |
+#include "ui/gfx/image/image_skia.h" |
+#include "url/gurl.h" |
+ |
+namespace app_list { |
+ |
+// Provides an icon image which is badged with extension icon. If custom icon |
+// image is not specified, extension icon will be used. |
+class ExtensionBadgedIconImage : extensions::IconImage::Observer { |
+ public: |
+ class Observer { |
+ public: |
+ // Called when icon image is changed. To obtain the new image, call |
+ // GetIconImage method. |
+ virtual void OnIconImageChanged(ExtensionBadgedIconImage* image) = 0; |
+ }; |
+ |
+ // If |custom_icon_url| is empty, uses the extension icon. |
+ ExtensionBadgedIconImage( |
+ const GURL& custom_icon_url, |
+ Profile* profile, |
+ const extensions::Extension* extension, |
+ const int icon_dimension, |
+ const chromeos::launcher_search_provider::ErrorReporter& error_reporter); |
+ ~ExtensionBadgedIconImage() override; |
+ |
+ // Adds |observer| to listen icon image changed event. To get fresh icon |
+ // image, you need to add observer before you call GetIconImage. |
+ void AddObserver(Observer* observer); |
+ |
+ // Removes |observer|. |
+ void RemoveObserver(Observer* observer); |
+ |
+ // extensions::IconImage::Observer overrides. |
+ void OnExtensionIconImageChanged(extensions::IconImage* image) override; |
+ |
+ // Returns badged icon image |
+ const gfx::ImageSkia& GetIconImage() const; |
+ |
+ private: |
+ // Called when custom icon image is loaded. |
+ void OnCustomIconLoaded(const gfx::Image& image); |
+ |
+ // Updates icon image. |
+ void Update(); |
+ |
+ // Sets new icon image, and notify to observers. |
+ void SetIconImage(const gfx::ImageSkia& image); |
+ |
+ // Returns truncated icon url. Since max_size includes trailing ..., it should |
+ // be larger than 3. |
+ std::string GetTruncatedIconUrl(const uint32 max_size); |
+ |
+ const extensions::IconImage extension_icon_image_; |
+ gfx::ImageSkia custom_icon_image_; |
+ gfx::ImageSkia badged_icon_image_; |
+ |
+ const GURL icon_url_; |
+ const gfx::Size icon_size_; |
+ |
+ Profile* profile_; |
+ chromeos::launcher_search_provider::ErrorReporter error_reporter_; |
+ std::set<Observer*> observers_; |
+ |
+ base::WeakPtrFactory<ExtensionBadgedIconImage> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionBadgedIconImage); |
+}; |
+ |
+} // namespace app_list |
+ |
+#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_LAUNCHER_SEARCH_EXTENSION_BADGED_ICON_IMAGE_H_ |