blob: e5f93aa26bc61211b55b85b8e17c704faaf459c1 [file] [log] [blame]
khmel8c1f6622017-05-11 19:14:501// 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
16namespace content {
17class BrowserContext;
18}
19
20namespace extensions {
21
22class Extension;
23class 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.
30class 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_; }
Vadim Trysheva5d129fa2018-01-18 04:18:3854#if defined(OS_CHROMEOS)
55 // Returns whether the icon is badged because it's an extension app that has
56 // its Android analog installed.
57 bool icon_is_badged() const { return icon_is_badged_; }
58#endif
khmel8c1f6622017-05-11 19:14:5059
60 private:
61 const Extension* GetExtension();
62
63 // IconImage::Observer:
64 void OnExtensionIconImageChanged(IconImage* image) override;
65
66 // Unowned pointers.
67 ChromeAppIconDelegate* const delegate_;
68 content::BrowserContext* const browser_context_;
69
70 // Called when this instance of ChromeAppIcon is destroyed.
71 DestroyedCallback destroyed_callback_;
72
73 const std::string app_id_;
74
75 // Contains current icon image. This is static image with applied effects and
76 // it is updated each time when |icon_| is updated.
77 gfx::ImageSkia image_skia_;
78
Vadim Trysheva5d129fa2018-01-18 04:18:3879#if defined(OS_CHROMEOS)
80 // Whether the icon got badged because it's an extension app that has its
81 // Android analog installed.
82 bool icon_is_badged_ = false;
83#endif
84
khmel8c1f6622017-05-11 19:14:5085 const int resource_size_in_dip_;
86
87 std::unique_ptr<IconImage> icon_;
88
89 DISALLOW_COPY_AND_ASSIGN(ChromeAppIcon);
90};
91
92} // namespace extensions
93
94#endif // CHROME_BROWSER_EXTENSIONS_CHROME_APP_ICON_H_