Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / chromeos / screen_security / screen_share_tray_item.cc
blobe2bf334774df433e4fe380786e07a2d25200c821
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.
5 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h"
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"
16 using message_center::Notification;
18 namespace ash {
19 namespace {
21 const char kScreenShareNotificationId[] = "chrome://screen/share";
25 ScreenShareTrayItem::ScreenShareTrayItem(SystemTray* system_tray)
26 : ScreenTrayItem(system_tray) {
27 Shell::GetInstance()->system_tray_notifier()->
28 AddScreenShareObserver(this);
31 ScreenShareTrayItem::~ScreenShareTrayItem() {
32 Shell::GetInstance()->system_tray_notifier()->
33 RemoveScreenShareObserver(this);
36 views::View* ScreenShareTrayItem::CreateTrayView(user::LoginStatus status) {
37 set_tray_view(
38 new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE));
39 return tray_view();
42 views::View* ScreenShareTrayItem::CreateDefaultView(user::LoginStatus status) {
43 set_default_view(new tray::ScreenStatusView(
44 this,
45 IDR_AURA_UBER_TRAY_SCREENSHARE_DARK,
46 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();
53 void ScreenShareTrayItem::CreateOrUpdateNotification() {
54 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);
64 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,
71 help_label_text,
72 base::string16() /* body is blank */,
73 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK),
74 base::string16() /* display_source */,
75 message_center::NotifierId(
76 message_center::NotifierId::SYSTEM_COMPONENT,
77 system_notifier::kNotifierScreenShare),
78 data,
79 new tray::ScreenNotificationDelegate(this)));
80 notification->SetSystemPriority();
81 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
84 std::string ScreenShareTrayItem::GetNotificationId() {
85 return kScreenShareNotificationId;
88 void ScreenShareTrayItem::OnScreenShareStart(
89 const base::Closure& stop_callback,
90 const base::string16& helper_name) {
91 helper_name_ = helper_name;
92 Start(stop_callback);
95 void ScreenShareTrayItem::OnScreenShareStop() {
96 // We do not need to run the stop callback
97 // when screening is stopped externally.
98 set_is_started(false);
99 Update();
102 } // namespace ash