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