extension_app_item.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 AppListControllerDelegate* controller, 39 const std::string& extension_name, 40 const gfx::ImageSkia& installing_icon, 41 bool is_platform_app); 42 virtual ~ExtensionAppItem(); 43 44 // Reload the title and icon from the underlying extension. 45 void Reload(); 46 47 // Updates the app item's icon, if necessary adding an overlay and/or making 48 // it gray. 49 void UpdateIcon(); 50 51 const std::string& extension_id() const { return extension_id_; } 52 53 static const char kAppType[]; 54 55 private: 56 // Gets extension associated with this model. Returns NULL if extension 57 // no longer exists. 58 const extensions::Extension* GetExtension() const; 59 60 // Loads extension icon. 61 void LoadImage(const extensions::Extension* extension); 62 63 // Checks if extension is disabled and if enable flow should be started. 64 // Returns true if extension enable flow is started or there is already one 65 // running. 66 bool RunExtensionEnableFlow(); 67 68 // Private equivalent to Activate(), without refocus for already-running apps. 69 void Launch(int event_flags); 70 71 // Whether or not the app item has an overlay. 72 bool HasOverlay() const; 73 74 // Overridden from extensions::IconImage::Observer: 75 virtual void OnExtensionIconImageChanged( 76 extensions::IconImage* image) OVERRIDE; 77 78 // Overridden from ExtensionEnableFlowDelegate: 79 virtual void ExtensionEnableFlowFinished() OVERRIDE; 80 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; 81 82 // Overridden from AppListItemModel: 83 virtual std::string GetSortOrder() const OVERRIDE; 84 virtual void Activate(int event_flags) OVERRIDE; 85 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE; 86 virtual const char* GetAppType() const OVERRIDE; 87 88 // Overridden from app_list::AppContextMenuDelegate: 89 virtual void ExecuteLaunchCommand(int event_flags) OVERRIDE; 90 91 Profile* profile_; 92 const std::string extension_id_; 93 AppListControllerDelegate* controller_; 94 95 scoped_ptr<extensions::IconImage> icon_; 96 scoped_ptr<app_list::AppContextMenu> context_menu_; 97 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 98 99 // Name to use for the extension if we can't access it. 100 std::string extension_name_; 101 102 // Icon for the extension if we can't access the installed extension. 103 gfx::ImageSkia installing_icon_; 104 105 // Whether or not this app is a platform app. 106 bool is_platform_app_; 107 108 // Cache initial sort order. Sort order is not synced with the extensions 109 // app ordering once apps are loaded. This will be ignored (or overridden) 110 // once the app list is synced. 111 std::string sort_order_; 112 113 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); 114}; 115 116#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ 117