extension_app_item.h revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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/chrome_app_list_item.h" 13#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 14#include "sync/api/string_ordinal.h" 15#include "ui/base/models/simple_menu_model.h" 16#include "ui/gfx/image/image_skia.h" 17 18class AppListControllerDelegate; 19class ExtensionEnableFlow; 20class Profile; 21 22namespace extensions { 23class ContextMenuMatcher; 24class Extension; 25} 26 27// ExtensionAppItem represents an extension app in app list. 28class ExtensionAppItem : public ChromeAppListItem, 29 public extensions::IconImage::Observer, 30 public ExtensionEnableFlowDelegate, 31 public ui::SimpleMenuModel::Delegate { 32 public: 33 ExtensionAppItem(Profile* profile, 34 const std::string& extension_id, 35 AppListControllerDelegate* controller, 36 const std::string& extension_name, 37 const gfx::ImageSkia& installing_icon, 38 bool is_platform_app); 39 virtual ~ExtensionAppItem(); 40 41 // Reload the title and icon from the underlying extension. 42 void Reload(); 43 44 syncer::StringOrdinal GetPageOrdinal() const; 45 syncer::StringOrdinal GetAppLaunchOrdinal() const; 46 47 // Update page and app launcher ordinals to put the app in between |prev| and 48 // |next|. Note that |prev| and |next| could be NULL when the app is put at 49 // the beginning or at the end. 50 void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next); 51 52 // Updates the app item's icon, if necessary adding an overlay and/or making 53 // it gray. 54 void UpdateIcon(); 55 56 const std::string& extension_id() const { return extension_id_; } 57 58 // Overridden from ChromeAppListItem: 59 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE; 60 61 private: 62 // Gets extension associated with this model. Returns NULL if extension 63 // no longer exists. 64 const extensions::Extension* GetExtension() const; 65 66 // Loads extension icon. 67 void LoadImage(const extensions::Extension* extension); 68 69 void ShowExtensionOptions(); 70 void ShowExtensionDetails(); 71 void StartExtensionUninstall(); 72 73 // Checks if extension is disabled and if enable flow should be started. 74 // Returns true if extension enable flow is started or there is already one 75 // running. 76 bool RunExtensionEnableFlow(); 77 78 // Private equivalent to Activate(), without refocus for already-running apps. 79 void Launch(int event_flags); 80 81 // Whether or not the app item has an overlay. 82 bool HasOverlay() const; 83 84 // Overridden from extensions::IconImage::Observer: 85 virtual void OnExtensionIconImageChanged( 86 extensions::IconImage* image) OVERRIDE; 87 88 // Overridden from ExtensionEnableFlowDelegate: 89 virtual void ExtensionEnableFlowFinished() OVERRIDE; 90 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; 91 92 // Overridden from ui::SimpleMenuModel::Delegate: 93 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; 94 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; 95 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 96 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 97 virtual bool GetAcceleratorForCommandId( 98 int command_id, 99 ui::Accelerator* acclelrator) OVERRIDE; 100 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 101 102 // Overridden from ChromeAppListItem: 103 virtual void Activate(int event_flags) OVERRIDE; 104 105 Profile* profile_; 106 const std::string extension_id_; 107 AppListControllerDelegate* controller_; 108 109 scoped_ptr<extensions::IconImage> icon_; 110 scoped_ptr<ui::SimpleMenuModel> context_menu_model_; 111 scoped_ptr<extensions::ContextMenuMatcher> extension_menu_items_; 112 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 113 114 // Name to use for the extension if we can't access it. 115 std::string extension_name_; 116 117 // Icon for the extension if we can't access the installed extension. 118 gfx::ImageSkia installing_icon_; 119 120 // Whether or not this app is a platform app. 121 bool is_platform_app_; 122 123 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); 124}; 125 126#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ 127