- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / screen_security / screen_capture_tray_item.cc
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 "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"
15
16 using message_center::Notification;
17
18 namespace ash {
19 namespace internal {
20 namespace {
21
22 const char kScreenCaptureNotificationId[] = "chrome://screen/capture";
23
24 }  // namespace
25
26 ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray)
27     : ScreenTrayItem(system_tray) {
28   Shell::GetInstance()->system_tray_notifier()->
29       AddScreenCaptureObserver(this);
30 }
31
32 ScreenCaptureTrayItem::~ScreenCaptureTrayItem() {
33   Shell::GetInstance()->system_tray_notifier()->
34       RemoveScreenCaptureObserver(this);
35 }
36
37 views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) {
38   set_tray_view(
39       new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_DISPLAY_LIGHT));
40   return tray_view();
41 }
42
43 views::View* ScreenCaptureTrayItem::CreateDefaultView(
44     user::LoginStatus status) {
45   set_default_view(new tray::ScreenStatusView(
46       this,
47       IDR_AURA_UBER_TRAY_DISPLAY,
48       screen_capture_status_,
49       l10n_util::GetStringUTF16(
50           IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
51   return default_view();
52 }
53
54 void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
55   message_center::RichNotificationData data;
56   data.buttons.push_back(message_center::ButtonInfo(
57       l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP)));
58   ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
59   scoped_ptr<Notification> notification(new Notification(
60       message_center::NOTIFICATION_TYPE_SIMPLE,
61       kScreenCaptureNotificationId,
62       screen_capture_status_,
63       base::string16() /* body is blank */,
64       resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
65       base::string16() /* display_source */,
66       message_center::NotifierId(system_notifier::NOTIFIER_SCREEN_CAPTURE),
67       data,
68       new tray::ScreenNotificationDelegate(this)));
69   notification->SetSystemPriority();
70   message_center::MessageCenter::Get()->AddNotification(notification.Pass());
71 }
72
73 std::string ScreenCaptureTrayItem::GetNotificationId() {
74   return kScreenCaptureNotificationId;
75 }
76
77 void ScreenCaptureTrayItem::OnScreenCaptureStart(
78     const base::Closure& stop_callback,
79     const base::string16& screen_capture_status) {
80   screen_capture_status_ = screen_capture_status;
81   Start(stop_callback);
82 }
83
84 void ScreenCaptureTrayItem::OnScreenCaptureStop() {
85   // We do not need to run the stop callback when
86   // screen capture is stopped externally.
87   set_is_started(false);
88   Update();
89 }
90
91 }  // namespace internal
92 }  // namespace ash