screen_share_tray_item.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/system/chromeos/screen_security/screen_share_tray_item.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/shell.h" 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/system/system_notifier.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "grit/ash_resources.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "grit/ash_strings.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 12bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/base/resource/resource_bundle.h" 13bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/message_center/message_center.h" 14bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/message_center/notification.h" 15bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 16bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochusing message_center::Notification; 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace ash { 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace internal { 20bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace { 21bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 22bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochconst char kScreenShareNotificationId[] = "chrome://screen/share"; 23bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 24bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScreenShareTrayItem::ScreenShareTrayItem(SystemTray* system_tray) 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) : ScreenTrayItem(system_tray) { 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()-> 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AddScreenShareObserver(this); 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScreenShareTrayItem::~ScreenShareTrayItem() { 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()-> 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) RemoveScreenShareObserver(this); 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)views::View* ScreenShareTrayItem::CreateTrayView(user::LoginStatus status) { 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) set_tray_view( 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE)); 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return tray_view(); 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)views::View* ScreenShareTrayItem::CreateDefaultView(user::LoginStatus status) { 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) set_default_view(new tray::ScreenStatusView( 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) this, 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IDR_AURA_UBER_TRAY_SCREENSHARE_DARK, 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) l10n_util::GetStringUTF16( 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED), 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) l10n_util::GetStringUTF16( 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP))); 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return default_view(); 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 54bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochvoid ScreenShareTrayItem::CreateOrUpdateNotification() { 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::string16 help_label_text; 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!helper_name_.empty()) { 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) help_label_text = l10n_util::GetStringFUTF16( 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED_NAME, 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) helper_name_); 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } else { 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) help_label_text = l10n_util::GetStringUTF16( 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED); 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 65bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::RichNotificationData data; 66bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch data.buttons.push_back(message_center::ButtonInfo( 67bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP))); 68bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); 69bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch scoped_ptr<Notification> notification(new Notification( 70bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::NOTIFICATION_TYPE_SIMPLE, 71bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch kScreenShareNotificationId, 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) help_label_text, 73bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch base::string16() /* body is blank */, 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK), 75bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch base::string16() /* display_source */, 76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId( 77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId::SYSTEM_COMPONENT, 78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) system_notifier::kNotifierScreenShare), 79bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch data, 80bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch new tray::ScreenNotificationDelegate(this))); 81bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch notification->SetSystemPriority(); 82bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 83bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 84bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 85bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochstd::string ScreenShareTrayItem::GetNotificationId() { 86bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return kScreenShareNotificationId; 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ScreenShareTrayItem::OnScreenShareStart( 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::Closure& stop_callback, 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::string16& helper_name) { 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) helper_name_ = helper_name; 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Start(stop_callback); 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ScreenShareTrayItem::OnScreenShareStop() { 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // We do not need to run the stop callback 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // when screening is stopped externally. 99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) set_is_started(false); 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Update(); 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace internal 104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace ash 105