blob: 6563e4bad86a5eb82efaa17eb2b8fe397fdfd43b [file] [log] [blame]
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001// 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 Murdochbb1529c2013-08-08 10:24:53 +010011#include "ui/base/resource/resource_bundle.h"
12#include "ui/message_center/message_center.h"
13#include "ui/message_center/notification.h"
14
15using message_center::Notification;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010016
17namespace ash {
18namespace internal {
Ben Murdochbb1529c2013-08-08 10:24:53 +010019namespace {
20
21const char kScreenCaptureNotificationId[] = "chrome://screen/capture";
22
23} // namespace
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010024
25ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray)
26 : ScreenTrayItem(system_tray) {
27 Shell::GetInstance()->system_tray_notifier()->
28 AddScreenCaptureObserver(this);
29}
30
31ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
32 Shell::GetInstance()->system_tray_notifier()->
33 RemoveScreenCaptureObserver(this);
34}
35
36views::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
42views::View* ScreenCaptureTrayItem::CreateDefaultView(
43 user::LoginStatus status) {
44 set_default_view(new tray::ScreenStatusView(
45 this,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010046 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 Murdochbb1529c2013-08-08 10:24:53 +010053void 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)868fa2f2013-06-11 10:57:03 +010061 screen_capture_status_,
Ben Murdochbb1529c2013-08-08 10:24:53 +010062 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
72std::string ScreenCaptureTrayItem::GetNotificationId() {
73 return kScreenCaptureNotificationId;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010074}
75
76void 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
83void 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