extension_app_item.h revision f2477e01787aa58f445919b809d89e252beef54f
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.
4
5#ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_
6#define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_
7
8#include <string>
9
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/extensions/extension_enable_flow_delegate.h"
14#include "ui/app_list/app_list_item_model.h"
15#include "ui/gfx/image/image_skia.h"
16
17class AppListControllerDelegate;
18class ExtensionEnableFlow;
19class Profile;
20
21namespace app_list {
22class AppContextMenu;
23}
24
25namespace extensions {
26class ContextMenuMatcher;
27class Extension;
28}
29
30// ExtensionAppItem represents an extension app in app list.
31class ExtensionAppItem : public app_list::AppListItemModel,
32                         public extensions::IconImage::Observer,
33                         public ExtensionEnableFlowDelegate,
34                         public app_list::AppContextMenuDelegate {
35 public:
36  ExtensionAppItem(Profile* profile,
37                   const std::string& extension_id,
38                   const std::string& extension_name,
39                   const gfx::ImageSkia& installing_icon,
40                   bool is_platform_app);
41  virtual ~ExtensionAppItem();
42
43  // Reload the title and icon from the underlying extension.
44  void Reload();
45
46  // Updates the app item's icon, if necessary adding an overlay and/or making
47  // it gray.
48  void UpdateIcon();
49
50  // Update page and app launcher ordinals to put the app in between |prev| and
51  // |next|. Note that |prev| and |next| could be NULL when the app is put at
52  // the beginning or at the end.
53  void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next);
54
55  const std::string& extension_id() const { return extension_id_; }
56
57  static const char kAppType[];
58
59 private:
60  // Gets extension associated with this model. Returns NULL if extension
61  // no longer exists.
62  const extensions::Extension* GetExtension() const;
63
64  // Loads extension icon.
65  void LoadImage(const extensions::Extension* extension);
66
67  // Checks if extension is disabled and if enable flow should be started.
68  // Returns true if extension enable flow is started or there is already one
69  // running.
70  bool RunExtensionEnableFlow();
71
72  // Private equivalent to Activate(), without refocus for already-running apps.
73  void Launch(int event_flags);
74
75  // Whether or not the app item has an overlay.
76  bool HasOverlay() const;
77
78  // Overridden from extensions::IconImage::Observer:
79  virtual void OnExtensionIconImageChanged(
80      extensions::IconImage* image) OVERRIDE;
81
82  // Overridden from ExtensionEnableFlowDelegate:
83  virtual void ExtensionEnableFlowFinished() OVERRIDE;
84  virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE;
85
86  // Overridden from AppListItemModel:
87  virtual void Activate(int event_flags) OVERRIDE;
88  virtual ui::MenuModel* GetContextMenuModel() OVERRIDE;
89  virtual const char* GetAppType() const OVERRIDE;
90
91  // Overridden from app_list::AppContextMenuDelegate:
92  virtual void ExecuteLaunchCommand(int event_flags) OVERRIDE;
93
94  // Set the position from the extension ordering.
95  void UpdatePositionFromExtensionOrdering();
96
97  // Return the controller for the active desktop type.
98  AppListControllerDelegate* GetController();
99
100  Profile* profile_;
101  const std::string extension_id_;
102
103  scoped_ptr<extensions::IconImage> icon_;
104  scoped_ptr<app_list::AppContextMenu> context_menu_;
105  scoped_ptr<ExtensionEnableFlow> extension_enable_flow_;
106  AppListControllerDelegate* extension_enable_flow_controller_;
107
108  // Name to use for the extension if we can't access it.
109  std::string extension_name_;
110
111  // Icon for the extension if we can't access the installed extension.
112  gfx::ImageSkia installing_icon_;
113
114  // Whether or not this app is a platform app.
115  bool is_platform_app_;
116
117  DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem);
118};
119
120#endif  // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_
121