• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
7 
8 #include "ash/shelf/shelf_item_delegate.h"
9 #include "ash/shelf/shelf_item_types.h"
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
15 #include "ui/events/event.h"
16 
17 class ChromeLauncherController;
18 class ChromeLauncherAppMenuItem;
19 
20 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems;
21 
22 namespace aura {
23 class Window;
24 }
25 
26 namespace content {
27 class WebContents;
28 }
29 
30 // LauncherItemController is used by ChromeLauncherController to track one
31 // or more windows associated with a shelf item.
32 class LauncherItemController : public ash::ShelfItemDelegate {
33  public:
34   enum Type {
35     TYPE_APP,
36     TYPE_APP_PANEL,
37     TYPE_SHORTCUT,
38     TYPE_WINDOWED_APP
39   };
40 
41   LauncherItemController(Type type,
42                          const std::string& app_id,
43                          ChromeLauncherController* launcher_controller);
44   virtual ~LauncherItemController();
45 
type()46   Type type() const { return type_; }
shelf_id()47   ash::ShelfID shelf_id() const { return shelf_id_; }
set_shelf_id(ash::ShelfID id)48   void set_shelf_id(ash::ShelfID id) { shelf_id_ = id; }
49   virtual const std::string& app_id() const;
launcher_controller()50   ChromeLauncherController* launcher_controller() const {
51     return launcher_controller_;
52   }
53 
54   // Lock this item to the launcher without being pinned (windowed v1 apps).
lock()55   void lock() { locked_++; }
unlock()56   void unlock() {
57     DCHECK(locked_);
58     locked_--;
59   }
locked()60   bool locked() { return locked_ > 0; }
61 
image_set_by_controller()62   bool image_set_by_controller() const { return image_set_by_controller_; }
set_image_set_by_controller(bool image_set_by_controller)63   void set_image_set_by_controller(bool image_set_by_controller) {
64     image_set_by_controller_ = image_set_by_controller;
65   }
66 
67   // Returns true if this item is open.
68   virtual bool IsOpen() const = 0;
69 
70   // Returns true if this item is visible (e.g. not minimized).
71   virtual bool IsVisible() const = 0;
72 
73   // Launches a new instance of the app associated with this item.
74   virtual void Launch(ash::LaunchSource source, int event_flags) = 0;
75 
76   // Shows and activates the most-recently-active window associated with the
77   // item, or launches the item if it is not currently open.
78   // Returns true when a new item got created.
79   virtual bool Activate(ash::LaunchSource source) = 0;
80 
81   // Called to retrieve the list of running applications.
82   virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0;
83 
84   // Helper function to get the ash::ShelfItemType for the item type.
85   ash::ShelfItemType GetShelfItemType() const;
86 
87  protected:
88   // Helper function to return the title associated with |app_id_|.
89   // Returns an empty title if no matching extension can be found.
90   base::string16 GetAppTitle() const;
91 
92  private:
93   const Type type_;
94   // App id will be empty if there is no app associated with the window.
95   const std::string app_id_;
96   ash::ShelfID shelf_id_;
97   ChromeLauncherController* launcher_controller_;
98 
99   // The lock counter which tells the launcher if the item can be removed from
100   // the launcher (0) or not (>0). It is being used for windowed V1
101   // applications.
102   int locked_;
103 
104   // Set to true if the launcher item image has been set by the controller.
105   bool image_set_by_controller_;
106 
107   DISALLOW_COPY_AND_ASSIGN(LauncherItemController);
108 };
109 
110 #endif  // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
111