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.
5 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.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"
16 using message_center::Notification
;
21 const char kScreenCaptureNotificationId
[] = "chrome://screen/capture";
25 ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray
* system_tray
)
26 : ScreenTrayItem(system_tray
) {
27 Shell::GetInstance()->AddShellObserver(this);
28 Shell::GetInstance()->system_tray_notifier()->
29 AddScreenCaptureObserver(this);
32 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
33 Shell::GetInstance()->RemoveShellObserver(this);
34 Shell::GetInstance()->system_tray_notifier()->
35 RemoveScreenCaptureObserver(this);
38 views::View
* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status
) {
40 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE
));
44 views::View
* ScreenCaptureTrayItem::CreateDefaultView(
45 user::LoginStatus status
) {
46 set_default_view(new tray::ScreenStatusView(
48 IDR_AURA_UBER_TRAY_SCREENSHARE_DARK
,
49 screen_capture_status_
,
50 l10n_util::GetStringUTF16(
51 IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP
)));
52 return default_view();
55 void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
56 message_center::RichNotificationData data
;
57 data
.buttons
.push_back(message_center::ButtonInfo(
58 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP
)));
59 ui::ResourceBundle
& resource_bundle
= ui::ResourceBundle::GetSharedInstance();
60 scoped_ptr
<Notification
> notification(new Notification(
61 message_center::NOTIFICATION_TYPE_SIMPLE
,
62 kScreenCaptureNotificationId
,
63 screen_capture_status_
,
64 base::string16() /* body is blank */,
65 resource_bundle
.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK
),
66 base::string16() /* display_source */,
67 message_center::NotifierId(
68 message_center::NotifierId::SYSTEM_COMPONENT
,
69 system_notifier::kNotifierScreenCapture
),
71 new tray::ScreenNotificationDelegate(this)));
72 notification
->SetSystemPriority();
73 message_center::MessageCenter::Get()->AddNotification(notification
.Pass());
76 std::string
ScreenCaptureTrayItem::GetNotificationId() {
77 return kScreenCaptureNotificationId
;
80 void ScreenCaptureTrayItem::OnScreenCaptureStart(
81 const base::Closure
& stop_callback
,
82 const base::string16
& screen_capture_status
) {
83 screen_capture_status_
= screen_capture_status
;
85 // We do not want to show the screen capture tray item and the chromecast
86 // casting tray item at the same time. We will hide this tray item.
88 // This suppression technique is currently dependent on the order
89 // that OnScreenCaptureStart and OnCastingSessionStartedOrStopped
90 // get invoked. OnCastingSessionStartedOrStopped currently gets
98 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
99 // We do not need to run the stop callback when
100 // screen capture is stopped externally.
101 set_is_started(false);
105 void ScreenCaptureTrayItem::OnCastingSessionStartedOrStopped(bool started
) {
106 is_casting_
= started
;