| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "ash/common/system/system_notifier.h" | |
| 10 #include "ash/common/system/tray/system_tray_notifier.h" | |
| 11 #include "ash/common/wm_shell.h" | |
| 12 #include "grit/ash_resources.h" | |
| 13 #include "grit/ash_strings.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/message_center/message_center.h" | |
| 17 #include "ui/message_center/notification.h" | |
| 18 | |
| 19 using message_center::Notification; | |
| 20 | |
| 21 namespace ash { | |
| 22 namespace { | |
| 23 | |
| 24 const char kScreenCaptureNotificationId[] = "chrome://screen/capture"; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray) | |
| 29 : ScreenTrayItem(system_tray) { | |
| 30 WmShell::Get()->AddShellObserver(this); | |
| 31 WmShell::Get()->system_tray_notifier()->AddScreenCaptureObserver(this); | |
| 32 } | |
| 33 | |
| 34 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() { | |
| 35 WmShell::Get()->RemoveShellObserver(this); | |
| 36 WmShell::Get()->system_tray_notifier()->RemoveScreenCaptureObserver(this); | |
| 37 } | |
| 38 | |
| 39 views::View* ScreenCaptureTrayItem::CreateTrayView(LoginStatus status) { | |
| 40 set_tray_view(new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE)); | |
| 41 return tray_view(); | |
| 42 } | |
| 43 | |
| 44 views::View* ScreenCaptureTrayItem::CreateDefaultView(LoginStatus status) { | |
| 45 set_default_view(new tray::ScreenStatusView( | |
| 46 this, IDR_AURA_UBER_TRAY_SCREENSHARE_DARK, screen_capture_status_, | |
| 47 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); | |
| 48 return default_view(); | |
| 49 } | |
| 50 | |
| 51 void ScreenCaptureTrayItem::CreateOrUpdateNotification() { | |
| 52 message_center::RichNotificationData data; | |
| 53 data.buttons.push_back(message_center::ButtonInfo( | |
| 54 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); | |
| 55 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 56 std::unique_ptr<Notification> notification(new Notification( | |
| 57 message_center::NOTIFICATION_TYPE_SIMPLE, kScreenCaptureNotificationId, | |
| 58 screen_capture_status_, base::string16() /* body is blank */, | |
| 59 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK), | |
| 60 base::string16() /* display_source */, GURL(), | |
| 61 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | |
| 62 system_notifier::kNotifierScreenCapture), | |
| 63 data, new tray::ScreenNotificationDelegate(this))); | |
| 64 notification->SetSystemPriority(); | |
| 65 message_center::MessageCenter::Get()->AddNotification( | |
| 66 std::move(notification)); | |
| 67 } | |
| 68 | |
| 69 std::string ScreenCaptureTrayItem::GetNotificationId() { | |
| 70 return kScreenCaptureNotificationId; | |
| 71 } | |
| 72 | |
| 73 void ScreenCaptureTrayItem::OnScreenCaptureStart( | |
| 74 const base::Closure& stop_callback, | |
| 75 const base::string16& screen_capture_status) { | |
| 76 screen_capture_status_ = screen_capture_status; | |
| 77 | |
| 78 // We do not want to show the screen capture tray item and the chromecast | |
| 79 // casting tray item at the same time. We will hide this tray item. | |
| 80 // | |
| 81 // This suppression technique is currently dependent on the order | |
| 82 // that OnScreenCaptureStart and OnCastingSessionStartedOrStopped | |
| 83 // get invoked. OnCastingSessionStartedOrStopped currently gets | |
| 84 // called first. | |
| 85 if (is_casting_) | |
| 86 return; | |
| 87 | |
| 88 Start(stop_callback); | |
| 89 } | |
| 90 | |
| 91 void ScreenCaptureTrayItem::OnScreenCaptureStop() { | |
| 92 // We do not need to run the stop callback when | |
| 93 // screen capture is stopped externally. | |
| 94 set_is_started(false); | |
| 95 Update(); | |
| 96 } | |
| 97 | |
| 98 void ScreenCaptureTrayItem::OnCastingSessionStartedOrStopped(bool started) { | |
| 99 is_casting_ = started; | |
| 100 } | |
| 101 | |
| 102 } // namespace ash | |
| OLD | NEW |