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