blob: 18dd317883c98685f84b7419e180b81ba5859f17 [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_share_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 kScreenShareNotificationId[] = "chrome://screen/share";
22
23}
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010024
25ScreenShareTrayItem::ScreenShareTrayItem(SystemTray* system_tray)
26 : ScreenTrayItem(system_tray) {
27 Shell::GetInstance()->system_tray_notifier()->
28 AddScreenShareObserver(this);
29}
30
31ScreenShareTrayItem::~ScreenShareTrayItem() {
32 Shell::GetInstance()->system_tray_notifier()->
33 RemoveScreenShareObserver(this);
34}
35
36views::View* ScreenShareTrayItem::CreateTrayView(user::LoginStatus status) {
37 set_tray_view(
Ben Murdocheb525c52013-07-10 11:40:50 +010038 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_DISPLAY_LIGHT));
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010039 return tray_view();
40}
41
42views::View* ScreenShareTrayItem::CreateDefaultView(user::LoginStatus status) {
43 set_default_view(new tray::ScreenStatusView(
44 this,
Ben Murdocheb525c52013-07-10 11:40:50 +010045 IDR_AURA_UBER_TRAY_DISPLAY,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010046 l10n_util::GetStringUTF16(
47 IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED),
48 l10n_util::GetStringUTF16(
49 IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP)));
50 return default_view();
51}
52
Ben Murdochbb1529c2013-08-08 10:24:53 +010053void ScreenShareTrayItem::CreateOrUpdateNotification() {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010054 base::string16 help_label_text;
55 if (!helper_name_.empty()) {
56 help_label_text = l10n_util::GetStringFUTF16(
57 IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED_NAME,
58 helper_name_);
59 } else {
60 help_label_text = l10n_util::GetStringUTF16(
61 IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED);
62 }
63
Ben Murdochbb1529c2013-08-08 10:24:53 +010064 message_center::RichNotificationData data;
65 data.buttons.push_back(message_center::ButtonInfo(
66 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP)));
67 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
68 scoped_ptr<Notification> notification(new Notification(
69 message_center::NOTIFICATION_TYPE_SIMPLE,
70 kScreenShareNotificationId,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010071 help_label_text,
Ben Murdochbb1529c2013-08-08 10:24:53 +010072 base::string16() /* body is blank */,
73 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
74 base::string16() /* display_source */,
75 std::string() /* extension_id */,
76 data,
77 new tray::ScreenNotificationDelegate(this)));
78 notification->SetSystemPriority();
79 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
80}
81
82std::string ScreenShareTrayItem::GetNotificationId() {
83 return kScreenShareNotificationId;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010084}
85
86void ScreenShareTrayItem::OnScreenShareStart(
87 const base::Closure& stop_callback,
88 const base::string16& helper_name) {
89 helper_name_ = helper_name;
90 Start(stop_callback);
91}
92
93void ScreenShareTrayItem::OnScreenShareStop() {
94 // We do not need to run the stop callback
95 // when screening is stopped externally.
96 set_is_started(false);
97 Update();
98}
99
100} // namespace internal
101} // namespace ash