OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/extensions/chrome_app_icon_delegate.h" |
12 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h" | 13 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h" |
13 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 14 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
14 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
15 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 16 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
16 #include "extensions/browser/extension_icon_image.h" | 17 #include "extensions/browser/extension_icon_image.h" |
17 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
18 | 19 |
19 class AppListControllerDelegate; | 20 class AppListControllerDelegate; |
20 class ExtensionEnableFlow; | 21 class ExtensionEnableFlow; |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace app_list { | 24 namespace app_list { |
24 class ExtensionAppContextMenu; | 25 class ExtensionAppContextMenu; |
25 } | 26 } |
26 | 27 |
27 namespace extensions { | 28 namespace extensions { |
28 class Extension; | 29 class Extension; |
29 } | 30 } |
30 | 31 |
31 // ExtensionAppItem represents an extension app in app list. | 32 // ExtensionAppItem represents an extension app in app list. |
32 class ExtensionAppItem : public ChromeAppListItem, | 33 class ExtensionAppItem : public ChromeAppListItem, |
33 public extensions::IconImage::Observer, | 34 public extensions::ChromeAppIconDelegate, |
34 public ExtensionEnableFlowDelegate, | 35 public ExtensionEnableFlowDelegate, |
35 public app_list::AppContextMenuDelegate { | 36 public app_list::AppContextMenuDelegate { |
36 public: | 37 public: |
37 static const char kItemType[]; | 38 static const char kItemType[]; |
38 | 39 |
39 ExtensionAppItem(Profile* profile, | 40 ExtensionAppItem(Profile* profile, |
40 const app_list::AppListSyncableService::SyncItem* sync_item, | 41 const app_list::AppListSyncableService::SyncItem* sync_item, |
41 const std::string& extension_id, | 42 const std::string& extension_id, |
42 const std::string& extension_name, | 43 const std::string& extension_name, |
43 const gfx::ImageSkia& installing_icon, | 44 const gfx::ImageSkia& installing_icon, |
44 bool is_platform_app); | 45 bool is_platform_app); |
45 ~ExtensionAppItem() override; | 46 ~ExtensionAppItem() override; |
46 | 47 |
47 // Reload the title and icon from the underlying extension. | 48 // Reload the title and icon from the underlying extension. |
48 void Reload(); | 49 void Reload(); |
49 | 50 |
50 // Updates the app item's icon, if necessary making it gray. | |
51 void UpdateIcon(); | |
52 | |
53 // Update page and app launcher ordinals to put the app in between |prev| and | 51 // Update page and app launcher ordinals to put the app in between |prev| and |
54 // |next|. Note that |prev| and |next| could be NULL when the app is put at | 52 // |next|. Note that |prev| and |next| could be NULL when the app is put at |
55 // the beginning or at the end. | 53 // the beginning or at the end. |
56 void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next); | 54 void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next); |
57 | 55 |
58 const std::string& extension_id() const { return id(); } | 56 const std::string& extension_id() const { return id(); } |
59 const std::string& extension_name() const { return extension_name_; } | 57 const std::string& extension_name() const { return extension_name_; } |
60 | 58 |
61 private: | 59 private: |
62 // Gets extension associated with this model. Returns NULL if extension | 60 // Gets extension associated with this model. Returns NULL if extension |
63 // no longer exists. | 61 // no longer exists. |
64 const extensions::Extension* GetExtension() const; | 62 const extensions::Extension* GetExtension() const; |
65 | 63 |
66 // Loads extension icon. | |
67 void LoadImage(const extensions::Extension* extension); | |
68 | |
69 // Checks if extension is disabled and if enable flow should be started. | 64 // Checks if extension is disabled and if enable flow should be started. |
70 // Returns true if extension enable flow is started or there is already one | 65 // Returns true if extension enable flow is started or there is already one |
71 // running. | 66 // running. |
72 bool RunExtensionEnableFlow(); | 67 bool RunExtensionEnableFlow(); |
73 | 68 |
74 // Private equivalent to Activate(), without refocus for already-running apps. | 69 // Private equivalent to Activate(), without refocus for already-running apps. |
75 void Launch(int event_flags); | 70 void Launch(int event_flags); |
76 | 71 |
77 // Overridden from extensions::IconImage::Observer: | |
78 void OnExtensionIconImageChanged(extensions::IconImage* image) override; | |
79 void OnExtensionIconImageDestroyed(extensions::IconImage* image) override; | |
80 | |
81 // Overridden from ExtensionEnableFlowDelegate: | 72 // Overridden from ExtensionEnableFlowDelegate: |
82 void ExtensionEnableFlowFinished() override; | 73 void ExtensionEnableFlowFinished() override; |
83 void ExtensionEnableFlowAborted(bool user_initiated) override; | 74 void ExtensionEnableFlowAborted(bool user_initiated) override; |
84 | 75 |
85 // Overridden from AppListItem: | 76 // Overridden from AppListItem: |
86 void Activate(int event_flags) override; | 77 void Activate(int event_flags) override; |
87 ui::MenuModel* GetContextMenuModel() override; | 78 ui::MenuModel* GetContextMenuModel() override; |
88 const char* GetItemType() const override; | 79 const char* GetItemType() const override; |
89 | 80 |
90 // Overridden from app_list::AppContextMenuDelegate: | 81 // Overridden from app_list::AppContextMenuDelegate: |
91 void ExecuteLaunchCommand(int event_flags) override; | 82 void ExecuteLaunchCommand(int event_flags) override; |
92 | 83 |
93 std::unique_ptr<extensions::IconImage> icon_; | 84 // extensions::ChromeAppIconDelegate: |
| 85 void OnIconUpdated(extensions::ChromeAppIcon* icon) override; |
| 86 |
| 87 std::unique_ptr<extensions::ChromeAppIcon> icon_; |
94 std::unique_ptr<app_list::ExtensionAppContextMenu> context_menu_; | 88 std::unique_ptr<app_list::ExtensionAppContextMenu> context_menu_; |
95 std::unique_ptr<ExtensionEnableFlow> extension_enable_flow_; | 89 std::unique_ptr<ExtensionEnableFlow> extension_enable_flow_; |
96 AppListControllerDelegate* extension_enable_flow_controller_; | 90 AppListControllerDelegate* extension_enable_flow_controller_; |
97 | 91 |
98 // Name to use for the extension if we can't access it. | 92 // Name to use for the extension if we can't access it. |
99 std::string extension_name_; | 93 std::string extension_name_; |
100 | 94 |
101 // Icon for the extension if we can't access the installed extension. | 95 // Icon for the extension if we can't access the installed extension. |
102 gfx::ImageSkia installing_icon_; | 96 const gfx::ImageSkia installing_icon_; |
103 | 97 |
104 // Whether or not this app is a platform app. | 98 // Whether or not this app is a platform app. |
105 bool is_platform_app_; | 99 bool is_platform_app_; |
106 | 100 |
107 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); | 101 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); |
108 }; | 102 }; |
109 | 103 |
110 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ | 104 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ |
OLD | NEW |