Home | History | Annotate | Download | only in screen_security
      1 // Copyright 2013 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 ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_
      6 #define ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_
      7 
      8 #include "ash/system/tray/system_tray.h"
      9 #include "ash/system/tray/system_tray_item.h"
     10 #include "ash/system/tray/system_tray_notifier.h"
     11 #include "ash/system/tray/tray_item_view.h"
     12 #include "ash/system/tray/tray_notification_view.h"
     13 #include "ash/system/tray/tray_popup_label_button.h"
     14 #include "ui/message_center/notification_delegate.h"
     15 #include "ui/views/controls/button/button.h"
     16 #include "ui/views/controls/image_view.h"
     17 
     18 namespace views {
     19 class View;
     20 }
     21 
     22 namespace ash {
     23 namespace internal {
     24 
     25 class ScreenTrayItem;
     26 
     27 namespace tray {
     28 
     29 class ScreenTrayView : public TrayItemView {
     30  public:
     31   ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id);
     32   virtual ~ScreenTrayView();
     33 
     34   void Update();
     35 
     36  private:
     37   ScreenTrayItem* screen_tray_item_;
     38 
     39   DISALLOW_COPY_AND_ASSIGN(ScreenTrayView);
     40 };
     41 
     42 class ScreenStatusView : public views::View,
     43                          public views::ButtonListener {
     44  public:
     45   ScreenStatusView(ScreenTrayItem* screen_tray_item,
     46                    int icon_id,
     47                    const base::string16& label_text,
     48                    const base::string16& stop_button_text);
     49   virtual ~ScreenStatusView();
     50 
     51   // Overridden from views::View.
     52   virtual void Layout() OVERRIDE;
     53 
     54   // Overridden from views::ButtonListener.
     55   virtual void ButtonPressed(views::Button* sender,
     56                              const ui::Event& event) OVERRIDE;
     57 
     58   void CreateItems();
     59   void Update();
     60 
     61  private:
     62   ScreenTrayItem* screen_tray_item_;
     63   views::ImageView* icon_;
     64   views::Label* label_;
     65   TrayPopupLabelButton* stop_button_;
     66   int icon_id_;
     67   base::string16 label_text_;
     68   base::string16 stop_button_text_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(ScreenStatusView);
     71 };
     72 
     73 class ScreenNotificationDelegate : public message_center::NotificationDelegate {
     74  public:
     75   explicit ScreenNotificationDelegate(ScreenTrayItem* screen_tray);
     76 
     77   // message_center::NotificationDelegate overrides:
     78   virtual void Display() OVERRIDE;
     79   virtual void Error() OVERRIDE;
     80   virtual void Close(bool by_user) OVERRIDE;
     81   virtual void Click() OVERRIDE;
     82   virtual void ButtonClick(int button_index) OVERRIDE;
     83 
     84  protected:
     85   virtual ~ScreenNotificationDelegate();
     86 
     87  private:
     88   ScreenTrayItem* screen_tray_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(ScreenNotificationDelegate);
     91 };
     92 
     93 }  // namespace tray
     94 
     95 
     96 // The base tray item for screen capture and screen sharing. The
     97 // Start method brings up a notification and a tray item, and the user
     98 // can stop the screen capture/sharing by pressing the stop button.
     99 class ASH_EXPORT ScreenTrayItem : public SystemTrayItem {
    100  public:
    101   explicit ScreenTrayItem(SystemTray* system_tray);
    102   virtual ~ScreenTrayItem();
    103 
    104   tray::ScreenTrayView* tray_view() { return tray_view_; }
    105   void set_tray_view(tray::ScreenTrayView* tray_view) {
    106     tray_view_ = tray_view;
    107   }
    108 
    109   tray::ScreenStatusView* default_view() { return default_view_; }
    110   void set_default_view(tray::ScreenStatusView* default_view) {
    111     default_view_ = default_view;
    112   }
    113 
    114   bool is_started() const { return is_started_; }
    115   void set_is_started(bool is_started) { is_started_ = is_started; }
    116 
    117   void Update();
    118   void Start(const base::Closure& stop_callback);
    119   void Stop();
    120 
    121   // Creates or updates the notification for the tray item.
    122   virtual void CreateOrUpdateNotification() = 0;
    123 
    124   // Returns the id of the notification for the tray item.
    125   virtual std::string GetNotificationId() = 0;
    126 
    127   // Overridden from SystemTrayItem.
    128   virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE = 0;
    129   virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE = 0;
    130   virtual void DestroyTrayView() OVERRIDE;
    131   virtual void DestroyDefaultView() OVERRIDE;
    132 
    133  private:
    134   tray::ScreenTrayView* tray_view_;
    135   tray::ScreenStatusView* default_view_;
    136   bool is_started_;
    137   base::Closure stop_callback_;
    138 
    139   DISALLOW_COPY_AND_ASSIGN(ScreenTrayItem);
    140 };
    141 
    142 }  // namespace internal
    143 }  // namespace ash
    144 
    145 #endif  // ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_
    146