Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / chromeos / screen_security / screen_capture_tray_item.cc
blob6dc83601c19758a457663fc059981c040e4e4a62
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"
7 #include "ash/shell.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;
18 namespace ash {
19 namespace {
21 const char kScreenCaptureNotificationId[] = "chrome://screen/capture";
23 } // namespace
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) {
39 set_tray_view(
40 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE));
41 return tray_view();
44 views::View* ScreenCaptureTrayItem::CreateDefaultView(
45 user::LoginStatus status) {
46 set_default_view(new tray::ScreenStatusView(
47 this,
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, kScreenCaptureNotificationId,
62 screen_capture_status_, base::string16() /* body is blank */,
63 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK),
64 base::string16() /* display_source */, GURL(),
65 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
66 system_notifier::kNotifierScreenCapture),
67 data, new tray::ScreenNotificationDelegate(this)));
68 notification->SetSystemPriority();
69 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
72 std::string ScreenCaptureTrayItem::GetNotificationId() {
73 return kScreenCaptureNotificationId;
76 void ScreenCaptureTrayItem::OnScreenCaptureStart(
77 const base::Closure& stop_callback,
78 const base::string16& screen_capture_status) {
79 screen_capture_status_ = screen_capture_status;
81 // We do not want to show the screen capture tray item and the chromecast
82 // casting tray item at the same time. We will hide this tray item.
84 // This suppression technique is currently dependent on the order
85 // that OnScreenCaptureStart and OnCastingSessionStartedOrStopped
86 // get invoked. OnCastingSessionStartedOrStopped currently gets
87 // called first.
88 if (is_casting_)
89 return;
91 Start(stop_callback);
94 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
95 // We do not need to run the stop callback when
96 // screen capture is stopped externally.
97 set_is_started(false);
98 Update();
101 void ScreenCaptureTrayItem::OnCastingSessionStartedOrStopped(bool started) {
102 is_casting_ = started;
105 } // namespace ash