extension_app_item.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/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" 17 18class AppListControllerDelegate; 19class ExtensionEnableFlow; 20class Profile; 21 22namespace app_list { 23class AppContextMenu; 24} 25 26namespace extensions { 27class ContextMenuMatcher; 28class Extension; 29} 30 31// ExtensionAppItem represents an extension app in app list. 32class ExtensionAppItem : public app_list::AppListItem, 33 public extensions::IconImage::Observer, 34 public ExtensionEnableFlowDelegate, 35 public app_list::AppContextMenuDelegate { 36 public: 37 static const char kItemType[]; 38 39 ExtensionAppItem(Profile* profile, 40 const app_list::AppListSyncableService::SyncItem* sync_item, 41 const std::string& extension_id, 42 const std::string& extension_name, 43 const gfx::ImageSkia& installing_icon, 44 bool is_platform_app); 45 virtual ~ExtensionAppItem(); 46 47 // Reload the title and icon from the underlying extension. 48 void Reload(); 49 50 // Updates the app item's icon, if necessary adding an overlay and/or making 51 // it gray. 52 void UpdateIcon(); 53 54 // Only updates the icon if the overlay needs to be added/removed. 55 void UpdateIconOverlay(); 56 57 // Update page and app launcher ordinals to put the app in between |prev| and 58 // |next|. Note that |prev| and |next| could be NULL when the app is put at 59 // the beginning or at the end. 60 void Move(const ExtensionAppItem* prev, const ExtensionAppItem* next); 61 62 const std::string& extension_id() const { return extension_id_; } 63 const std::string& extension_name() const { return extension_name_; } 64 65 private: 66 // Gets extension associated with this model. Returns NULL if extension 67 // no longer exists. 68 const extensions::Extension* GetExtension() const; 69 70 // Loads extension icon. 71 void LoadImage(const extensions::Extension* extension); 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 needs an overlay. 82 bool NeedsOverlay() 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 AppListItem: 93 virtual void Activate(int event_flags) OVERRIDE; 94 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE; 95 virtual const char* GetItemType() const OVERRIDE; 96 97 // Overridden from app_list::AppContextMenuDelegate: 98 virtual void ExecuteLaunchCommand(int event_flags) OVERRIDE; 99 100 // Set the position from the extension ordering. 101 void UpdatePositionFromExtensionOrdering(); 102 103 // Return the controller for the active desktop type. 104 AppListControllerDelegate* GetController(); 105 106 Profile* profile_; 107 const std::string extension_id_; 108 109 scoped_ptr<extensions::IconImage> icon_; 110 scoped_ptr<app_list::AppContextMenu> context_menu_; 111 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 112 AppListControllerDelegate* extension_enable_flow_controller_; 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 // Whether this app item has an overlay. 124 bool has_overlay_; 125 126 DISALLOW_COPY_AND_ASSIGN(ExtensionAppItem); 127}; 128 129#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_ITEM_H_ 130