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()->system_tray_notifier()->
28 AddScreenCaptureObserver(this);
31 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
32 Shell::GetInstance()->system_tray_notifier()->
33 RemoveScreenCaptureObserver(this);
36 views::View
* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status
) {
38 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE
));
42 views::View
* ScreenCaptureTrayItem::CreateDefaultView(
43 user::LoginStatus status
) {
44 set_default_view(new tray::ScreenStatusView(
46 IDR_AURA_UBER_TRAY_SCREENSHARE_DARK
,
47 screen_capture_status_
,
48 l10n_util::GetStringUTF16(
49 IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP
)));
50 return default_view();
53 void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
54 message_center::RichNotificationData data
;
55 data
.buttons
.push_back(message_center::ButtonInfo(
56 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP
)));
57 ui::ResourceBundle
& resource_bundle
= ui::ResourceBundle::GetSharedInstance();
58 scoped_ptr
<Notification
> notification(new Notification(
59 message_center::NOTIFICATION_TYPE_SIMPLE
,
60 kScreenCaptureNotificationId
,
61 screen_capture_status_
,
62 base::string16() /* body is blank */,
63 resource_bundle
.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK
),
64 base::string16() /* display_source */,
65 message_center::NotifierId(
66 message_center::NotifierId::SYSTEM_COMPONENT
,
67 system_notifier::kNotifierScreenCapture
),
69 new tray::ScreenNotificationDelegate(this)));
70 notification
->SetSystemPriority();
71 message_center::MessageCenter::Get()->AddNotification(notification
.Pass());
74 std::string
ScreenCaptureTrayItem::GetNotificationId() {
75 return kScreenCaptureNotificationId
;
78 void ScreenCaptureTrayItem::OnScreenCaptureStart(
79 const base::Closure
& stop_callback
,
80 const base::string16
& screen_capture_status
) {
81 screen_capture_status_
= screen_capture_status
;
85 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
86 // We do not need to run the stop callback when
87 // screen capture is stopped externally.
88 set_is_started(false);