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 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ash/system/system_notifier.h"
      9 #include "grit/ash_resources.h"
     10 #include "grit/ash_strings.h"
     11 #include "ui/base/l10n/l10n_util.h"
     12 #include "ui/base/resource/resource_bundle.h"
     13 #include "ui/message_center/message_center.h"
     14 #include "ui/message_center/notification.h"
     15 
     16 using message_center::Notification;
     17 
     18 namespace ash {
     19 namespace {
     20 
     21 const char kScreenCaptureNotificationId[] = "chrome://screen/capture";
     22 
     23 }  // namespace
     24 
     25 ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray)
     26     : ScreenTrayItem(system_tray) {
     27   Shell::GetInstance()->system_tray_notifier()->
     28       AddScreenCaptureObserver(this);
     29 }
     30 
     31 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
     32   Shell::GetInstance()->system_tray_notifier()->
     33       RemoveScreenCaptureObserver(this);
     34 }
     35 
     36 views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) {
     37   set_tray_view(
     38       new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE));
     39   return tray_view();
     40 }
     41 
     42 views::View* ScreenCaptureTrayItem::CreateDefaultView(
     43     user::LoginStatus status) {
     44   set_default_view(new tray::ScreenStatusView(
     45       this,
     46       IDR_AURA_UBER_TRAY_SCREENSHARE_DARK,
     47       screen_capture_status_,
     48       l10n_util::GetStringUTF16(
     49           IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
     50   return default_view();
     51 }
     52 
     53 void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
     54   message_center::RichNotificationData data;
     55   data.buttons.push_back(message_center::ButtonInfo(
     56       l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
     57   ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
     58   scoped_ptr<Notification> notification(new Notification(
     59       message_center::NOTIFICATION_TYPE_SIMPLE,
     60       kScreenCaptureNotificationId,
     61       screen_capture_status_,
     62       base::string16() /* body is blank */,
     63       resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK),
     64       base::string16() /* display_source */,
     65       message_center::NotifierId(
     66           message_center::NotifierId::SYSTEM_COMPONENT,
     67           system_notifier::kNotifierScreenCapture),
     68       data,
     69       new tray::ScreenNotificationDelegate(this)));
     70   notification->SetSystemPriority();
     71   message_center::MessageCenter::Get()->AddNotification(notification.Pass());
     72 }
     73 
     74 std::string ScreenCaptureTrayItem::GetNotificationId() {
     75   return kScreenCaptureNotificationId;
     76 }
     77 
     78 void ScreenCaptureTrayItem::OnScreenCaptureStart(
     79     const base::Closure& stop_callback,
     80     const base::string16& screen_capture_status) {
     81   screen_capture_status_ = screen_capture_status;
     82   Start(stop_callback);
     83 }
     84 
     85 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
     86   // We do not need to run the stop callback when
     87   // screen capture is stopped externally.
     88   set_is_started(false);
     89   Update();
     90 }
     91 
     92 }  // namespace ash
     93