extension_app_item.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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 // Update page and app launcher ordinals to put the app in between |prev| and 52 // |next|. Note that |prev| and |next| could be NULL when the app is put at 53 // the beginning or at the end. 54 void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next); 55 56 const std::string& extension_id() const { return extension_id_; } 57 58 static const char kAppType[]; 59 60 private: 61 // Gets extension associated with this model. Returns NULL if extension 62 // no longer exists. 63 const extensions::Extension* GetExtension() const; 64 65 // Loads extension icon. 66 void LoadImage(const extensions::Extension* extension); 67 68 // Checks if extension is disabled and if enable flow should be started. 69 // Returns true if extension enable flow is started or there is already one 70 // running. 71 bool RunExtensionEnableFlow(); 72 73 // Private equivalent to Activate(), without refocus for already-running apps. 74 void Launch(int event_flags); 75 76 // Whether or not the app item has an overlay. 77 bool HasOverlay() const; 78 79 // Overridden from extensions::IconImage::Observer: 80 virtual void OnExtensionIconImageChanged( 81 extensions::IconImage* image) OVERRIDE; 82 83 // Overridden from ExtensionEnableFlowDelegate: 84 virtual void ExtensionEnableFlowFinished() OVERRIDE; 85 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; 86 87 // Overridden from AppListItemModel: 88 virtual void Activate(int event_flags) OVERRIDE; 89 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE; 90 virtual const char* GetAppType() const OVERRIDE; 91 92 // Overridden from app_list::AppContextMenuDelegate: 93 virtual void ExecuteLaunchCommand(int event_flags) OVERRIDE; 94 95 // Set the position from the extension ordering. 96 void UpdatePositionFromExtensionOrdering(); 97 98 Profile* profile_; 99 const std::string extension_id_; 100 AppListControllerDelegate* controller_; 101 102 scoped_ptr<extensions::IconImage> icon_; 103 scoped_ptr<app_list::AppContextMenu> context_menu_; 104 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 105 106 // Name to use for the extension if we can't access it. 107 std::string extension_name_; 108 109 // Icon for the extension if we can't access the installed extension. 110 gfx::ImageSkia installing_icon_; 111 112 // Whether or not this app is a platform app. 113 bool is_platform_app_; 114 115 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); 116}; 117 118#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ 119