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_capture_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 { 19bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace { 20bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 21bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochconst char kScreenCaptureNotificationId[] = "chrome://screen/capture"; 22bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 23bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} // namespace 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) : ScreenTrayItem(system_tray) { 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()-> 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AddScreenCaptureObserver(this); 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScreenCaptureTrayItem::~ScreenCaptureTrayItem() { 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()-> 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) RemoveScreenCaptureObserver(this); 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) { 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) set_tray_view( 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE)); 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return tray_view(); 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)views::View* ScreenCaptureTrayItem::CreateDefaultView( 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 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) screen_capture_status_, 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) l10n_util::GetStringUTF16( 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return default_view(); 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 53bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochvoid ScreenCaptureTrayItem::CreateOrUpdateNotification() { 54bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::RichNotificationData data; 55bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch data.buttons.push_back(message_center::ButtonInfo( 56bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); 57bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); 58bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch scoped_ptr<Notification> notification(new Notification( 59bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::NOTIFICATION_TYPE_SIMPLE, 60bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch kScreenCaptureNotificationId, 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) screen_capture_status_, 62bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch base::string16() /* body is blank */, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK), 64bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch base::string16() /* display_source */, 65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId( 66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId::SYSTEM_COMPONENT, 67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) system_notifier::kNotifierScreenCapture), 68bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch data, 69bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch new tray::ScreenNotificationDelegate(this))); 70bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch notification->SetSystemPriority(); 71bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 72bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 73bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 74bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochstd::string ScreenCaptureTrayItem::GetNotificationId() { 75bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return kScreenCaptureNotificationId; 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ScreenCaptureTrayItem::OnScreenCaptureStart( 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::Closure& stop_callback, 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::string16& screen_capture_status) { 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) screen_capture_status_ = screen_capture_status; 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Start(stop_callback); 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ScreenCaptureTrayItem::OnScreenCaptureStop() { 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // We do not need to run the stop callback when 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // screen capture is stopped externally. 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) set_is_started(false); 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Update(); 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace ash 93