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_share_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 kScreenShareNotificationId[] = "chrome://screen/share";
     23 
     24 }
     25 
     26 ScreenShareTrayItem::ScreenShareTrayItem(SystemTray* system_tray)
     27     : ScreenTrayItem(system_tray) {
     28   Shell::GetInstance()->system_tray_notifier()->
     29       AddScreenShareObserver(this);
     30 }
     31 
     32 ScreenShareTrayItem::~ScreenShareTrayItem() {
     33   Shell::GetInstance()->system_tray_notifier()->
     34       RemoveScreenShareObserver(this);
     35 }
     36 
     37 views::View* ScreenShareTrayItem::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* ScreenShareTrayItem::CreateDefaultView(user::LoginStatus status) {
     44   set_default_view(new tray::ScreenStatusView(
     45       this,
     46       IDR_AURA_UBER_TRAY_SCREENSHARE_DARK,
     47       l10n_util::GetStringUTF16(
     48           IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED),
     49       l10n_util::GetStringUTF16(
     50           IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP)));
     51   return default_view();
     52 }
     53 
     54 void ScreenShareTrayItem::CreateOrUpdateNotification() {
     55   base::string16 help_label_text;
     56   if (!helper_name_.empty()) {
     57     help_label_text = l10n_util::GetStringFUTF16(
     58         IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED_NAME,
     59         helper_name_);
     60   } else {
     61     help_label_text = l10n_util::GetStringUTF16(
     62         IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED);
     63   }
     64 
     65   message_center::RichNotificationData data;
     66   data.buttons.push_back(message_center::ButtonInfo(
     67       l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP)));
     68   ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
     69   scoped_ptr<Notification> notification(new Notification(
     70       message_center::NOTIFICATION_TYPE_SIMPLE,
     71       kScreenShareNotificationId,
     72       help_label_text,
     73       base::string16() /* body is blank */,
     74       resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK),
     75       base::string16() /* display_source */,
     76       message_center::NotifierId(
     77           message_center::NotifierId::SYSTEM_COMPONENT,
     78           system_notifier::kNotifierScreenShare),
     79       data,
     80       new tray::ScreenNotificationDelegate(this)));
     81   notification->SetSystemPriority();
     82   message_center::MessageCenter::Get()->AddNotification(notification.Pass());
     83 }
     84 
     85 std::string ScreenShareTrayItem::GetNotificationId() {
     86   return kScreenShareNotificationId;
     87 }
     88 
     89 void ScreenShareTrayItem::OnScreenShareStart(
     90     const base::Closure& stop_callback,
     91     const base::string16& helper_name) {
     92   helper_name_ = helper_name;
     93   Start(stop_callback);
     94 }
     95 
     96 void ScreenShareTrayItem::OnScreenShareStop() {
     97   // We do not need to run the stop callback
     98   // when screening is stopped externally.
     99   set_is_started(false);
    100   Update();
    101 }
    102 
    103 }  // namespace internal
    104 }  // namespace ash
    105