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;
22 const char kScreenCaptureNotificationId[] = "chrome://screen/capture";
26 ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray)
27 : ScreenTrayItem(system_tray) {
28 Shell::GetInstance()->system_tray_notifier()->
29 AddScreenCaptureObserver(this);
32 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
33 Shell::GetInstance()->system_tray_notifier()->
34 RemoveScreenCaptureObserver(this);
37 views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) {
39 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_DISPLAY_LIGHT));
43 views::View* ScreenCaptureTrayItem::CreateDefaultView(
44 user::LoginStatus status) {
45 set_default_view(new tray::ScreenStatusView(
47 IDR_AURA_UBER_TRAY_DISPLAY,
48 screen_capture_status_,
49 l10n_util::GetStringUTF16(
50 IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
51 return default_view();
54 void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
55 message_center::RichNotificationData data;
56 data.buttons.push_back(message_center::ButtonInfo(
57 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
58 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
59 scoped_ptr<Notification> notification(new Notification(
60 message_center::NOTIFICATION_TYPE_SIMPLE,
61 kScreenCaptureNotificationId,
62 screen_capture_status_,
63 base::string16() /* body is blank */,
64 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
65 base::string16() /* display_source */,
66 message_center::NotifierId(system_notifier::NOTIFIER_SCREEN_CAPTURE),
68 new tray::ScreenNotificationDelegate(this)));
69 notification->SetSystemPriority();
70 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
73 std::string ScreenCaptureTrayItem::GetNotificationId() {
74 return kScreenCaptureNotificationId;
77 void ScreenCaptureTrayItem::OnScreenCaptureStart(
78 const base::Closure& stop_callback,
79 const base::string16& screen_capture_status) {
80 screen_capture_status_ = screen_capture_status;
84 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
85 // We do not need to run the stop callback when
86 // screen capture is stopped externally.
87 set_is_started(false);
91 } // namespace internal