Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 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 "ash/shell.h" |
| 8 | #include "grit/ash_resources.h" |
| 9 | #include "grit/ash_strings.h" |
| 10 | #include "ui/base/l10n/l10n_util.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 11 | #include "ui/base/resource/resource_bundle.h" |
| 12 | #include "ui/message_center/message_center.h" |
| 13 | #include "ui/message_center/notification.h" |
| 14 | |
| 15 | using message_center::Notification; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 16 | |
| 17 | namespace ash { |
| 18 | namespace internal { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 19 | namespace { |
| 20 | |
| 21 | const char kScreenCaptureNotificationId[] = "chrome://screen/capture"; |
| 22 | |
| 23 | } // namespace |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 24 | |
| 25 | ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray) |
| 26 | : ScreenTrayItem(system_tray) { |
| 27 | Shell::GetInstance()->system_tray_notifier()-> |
| 28 | AddScreenCaptureObserver(this); |
| 29 | } |
| 30 | |
| 31 | ScreenCaptureTrayItem::~ScreenCaptureTrayItem() { |
| 32 | Shell::GetInstance()->system_tray_notifier()-> |
| 33 | RemoveScreenCaptureObserver(this); |
| 34 | } |
| 35 | |
| 36 | views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) { |
| 37 | set_tray_view( |
| 38 | new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_DISPLAY_LIGHT)); |
| 39 | return tray_view(); |
| 40 | } |
| 41 | |
| 42 | views::View* ScreenCaptureTrayItem::CreateDefaultView( |
| 43 | user::LoginStatus status) { |
| 44 | set_default_view(new tray::ScreenStatusView( |
| 45 | this, |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 46 | IDR_AURA_UBER_TRAY_DISPLAY, |
| 47 | screen_capture_status_, |
| 48 | l10n_util::GetStringUTF16( |
| 49 | IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); |
| 50 | return default_view(); |
| 51 | } |
| 52 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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, |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 61 | screen_capture_status_, |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 62 | base::string16() /* body is blank */, |
| 63 | resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY), |
| 64 | base::string16() /* display_source */, |
| 65 | std::string() /* extension_id */, |
| 66 | data, |
| 67 | new tray::ScreenNotificationDelegate(this))); |
| 68 | notification->SetSystemPriority(); |
| 69 | message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 70 | } |
| 71 | |
| 72 | std::string ScreenCaptureTrayItem::GetNotificationId() { |
| 73 | return kScreenCaptureNotificationId; |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void ScreenCaptureTrayItem::OnScreenCaptureStart( |
| 77 | const base::Closure& stop_callback, |
| 78 | const base::string16& screen_capture_status) { |
| 79 | screen_capture_status_ = screen_capture_status; |
| 80 | Start(stop_callback); |
| 81 | } |
| 82 | |
| 83 | void ScreenCaptureTrayItem::OnScreenCaptureStop() { |
| 84 | // We do not need to run the stop callback when |
| 85 | // screen capture is stopped externally. |
| 86 | set_is_started(false); |
| 87 | Update(); |
| 88 | } |
| 89 | |
| 90 | } // namespace internal |
| 91 | } // namespace ash |