Home | History | Annotate | Download | only in launcher
      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/launcher/launcher_types.h"
      9 #include "ash/shelf/shelf_item_delegate.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 
     46   Type type() const { return type_; }
     47   ash::LauncherID launcher_id() const { return launcher_id_; }
     48   void set_launcher_id(ash::LauncherID id) { launcher_id_ = id; }
     49   virtual const std::string& app_id() const;
     50   ChromeLauncherController* launcher_controller() const {
     51     return launcher_controller_;
     52   }
     53 
     54   // Lock this item to the launcher without being pinned (windowed v1 apps).
     55   void lock() { locked_++; }
     56   void unlock() {
     57     DCHECK(locked_);
     58     locked_--;
     59   }
     60   bool locked() { return locked_ > 0; }
     61 
     62   bool image_set_by_controller() const { return 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   // Closes all windows associated with this item.
     82   virtual void Close() = 0;
     83 
     84   // Called to retrieve the list of running applications.
     85   virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0;
     86 
     87   // Helper function to get the ash::LauncherItemType for the item type.
     88   ash::LauncherItemType GetLauncherItemType() const;
     89 
     90  protected:
     91   // Helper function to return the title associated with |app_id_|.
     92   // Returns an empty title if no matching extension can be found.
     93   base::string16 GetAppTitle() const;
     94 
     95  private:
     96   const Type type_;
     97   // App id will be empty if there is no app associated with the window.
     98   const std::string app_id_;
     99   ash::LauncherID launcher_id_;
    100   ChromeLauncherController* launcher_controller_;
    101 
    102   // The lock counter which tells the launcher if the item can be removed from
    103   // the launcher (0) or not (>0). It is being used for windowed V1
    104   // applications.
    105   int locked_;
    106 
    107   // Set to true if the launcher item image has been set by the controller.
    108   bool image_set_by_controller_;
    109 
    110   DISALLOW_COPY_AND_ASSIGN(LauncherItemController);
    111 };
    112 
    113 #endif  // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
    114