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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_
6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/extensions/extension_icon_image.h"
12 #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/extensions/extension_enable_flow_delegate.h"
15 #include "ui/app_list/app_list_item.h"
16 #include "ui/gfx/image/image_skia.h"
18 class AppListControllerDelegate
;
19 class ExtensionEnableFlow
;
26 namespace extensions
{
27 class ContextMenuMatcher
;
31 // ExtensionAppItem represents an extension app in app list.
32 class ExtensionAppItem
: public app_list::AppListItem
,
33 public extensions::IconImage::Observer
,
34 public ExtensionEnableFlowDelegate
,
35 public app_list::AppContextMenuDelegate
{
37 ExtensionAppItem(Profile
* profile
,
38 const app_list::AppListSyncableService::SyncItem
* sync_item
,
39 const std::string
& extension_id
,
40 const std::string
& extension_name
,
41 const gfx::ImageSkia
& installing_icon
,
42 bool is_platform_app
);
43 virtual ~ExtensionAppItem();
45 // Reload the title and icon from the underlying extension.
48 // Updates the app item's icon, if necessary adding an overlay and/or making
52 // Update page and app launcher ordinals to put the app in between |prev| and
53 // |next|. Note that |prev| and |next| could be NULL when the app is put at
54 // the beginning or at the end.
55 void Move(const ExtensionAppItem
* prev
, const ExtensionAppItem
* next
);
57 const std::string
& extension_id() const { return extension_id_
; }
58 const std::string
& extension_name() const { return extension_name_
; }
60 static const char kAppType
[];
63 // Gets extension associated with this model. Returns NULL if extension
65 const extensions::Extension
* GetExtension() const;
67 // Loads extension icon.
68 void LoadImage(const extensions::Extension
* extension
);
70 // Checks if extension is disabled and if enable flow should be started.
71 // Returns true if extension enable flow is started or there is already one
73 bool RunExtensionEnableFlow();
75 // Private equivalent to Activate(), without refocus for already-running apps.
76 void Launch(int event_flags
);
78 // Whether or not the app item has an overlay.
79 bool HasOverlay() const;
81 // Overridden from extensions::IconImage::Observer:
82 virtual void OnExtensionIconImageChanged(
83 extensions::IconImage
* image
) OVERRIDE
;
85 // Overridden from ExtensionEnableFlowDelegate:
86 virtual void ExtensionEnableFlowFinished() OVERRIDE
;
87 virtual void ExtensionEnableFlowAborted(bool user_initiated
) OVERRIDE
;
89 // Overridden from AppListItem:
90 virtual void Activate(int event_flags
) OVERRIDE
;
91 virtual ui::MenuModel
* GetContextMenuModel() OVERRIDE
;
92 virtual const char* GetAppType() const OVERRIDE
;
94 // Overridden from app_list::AppContextMenuDelegate:
95 virtual void ExecuteLaunchCommand(int event_flags
) OVERRIDE
;
97 // Set the position from the extension ordering.
98 void UpdatePositionFromExtensionOrdering();
100 // Return the controller for the active desktop type.
101 AppListControllerDelegate
* GetController();
104 const std::string extension_id_
;
106 scoped_ptr
<extensions::IconImage
> icon_
;
107 scoped_ptr
<app_list::AppContextMenu
> context_menu_
;
108 scoped_ptr
<ExtensionEnableFlow
> extension_enable_flow_
;
109 AppListControllerDelegate
* extension_enable_flow_controller_
;
111 // Name to use for the extension if we can't access it.
112 std::string extension_name_
;
114 // Icon for the extension if we can't access the installed extension.
115 gfx::ImageSkia installing_icon_
;
117 // Whether or not this app is a platform app.
118 bool is_platform_app_
;
120 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem
);
123 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_