Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ash / system / chromeos / screen_security / screen_capture_tray_item.cc
bloba5c40c01cdf756176e34a6dd2f22691f17966614
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,
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),
70 data,
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
91 // called first.
92 if (is_casting_)
93 return;
95 Start(stop_callback);
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);
102 Update();
105 void ScreenCaptureTrayItem::OnCastingSessionStartedOrStopped(bool started) {
106 is_casting_ = started;
109 } // namespace ash