OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #ifndef CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/macros.h" |
| 13 #include "extensions/browser/extension_icon_image.h" |
| 14 #include "ui/gfx/image/image_skia.h" |
| 15 |
| 16 namespace content { |
| 17 class BrowserContext; |
| 18 } |
| 19 |
| 20 namespace extensions { |
| 21 |
| 22 class Extension; |
| 23 class ChromeAppIconDelegate; |
| 24 |
| 25 // This represents how an extension app icon should finally look. As a base, |
| 26 // extension icon is used and effects that depend on extension type, state and |
| 27 // some external conditions are applied. Resulting image is sent via |
| 28 // ChromeAppIconDelegate. Several updates are expected in case extension |
| 29 // state or some external conditions are changed. |
| 30 class ChromeAppIcon : public IconImage::Observer { |
| 31 public: |
| 32 using DestroyedCallback = base::OnceCallback<void(ChromeAppIcon*)>; |
| 33 |
| 34 ChromeAppIcon(ChromeAppIconDelegate* delegate, |
| 35 content::BrowserContext* browser_context, |
| 36 DestroyedCallback destroyed_callback, |
| 37 const std::string& app_id, |
| 38 int resource_size_in_dip); |
| 39 ~ChromeAppIcon() override; |
| 40 |
| 41 // Reloads icon. |
| 42 void Reload(); |
| 43 |
| 44 // Returns true if the icon still refers to existing extension. Once extension |
| 45 // is disabled it is discarded from the icon. |
| 46 bool IsValid() const; |
| 47 |
| 48 // Re-applies app effects over the current extension icon and dispatches the |
| 49 // result via |delegate_|. |
| 50 void UpdateIcon(); |
| 51 |
| 52 const gfx::ImageSkia& image_skia() const { return image_skia_; } |
| 53 const std::string& app_id() const { return app_id_; } |
| 54 |
| 55 private: |
| 56 const Extension* GetExtension(); |
| 57 |
| 58 // IconImage::Observer: |
| 59 void OnExtensionIconImageChanged(IconImage* image) override; |
| 60 |
| 61 // Unowned pointers. |
| 62 ChromeAppIconDelegate* const delegate_; |
| 63 content::BrowserContext* const browser_context_; |
| 64 |
| 65 // Called when this instance of ChromeAppIcon is destroyed. |
| 66 DestroyedCallback destroyed_callback_; |
| 67 |
| 68 const std::string app_id_; |
| 69 |
| 70 // Contains current icon image. This is static image with applied effects and |
| 71 // it is updated each time when |icon_| is updated. |
| 72 gfx::ImageSkia image_skia_; |
| 73 |
| 74 const int resource_size_in_dip_; |
| 75 |
| 76 std::unique_ptr<IconImage> icon_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ChromeAppIcon); |
| 79 }; |
| 80 |
| 81 } // namespace extensions |
| 82 |
| 83 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_H_ |
OLD | NEW |