Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / chromeos / screen_security / screen_share_tray_item.cc
blob1a23b7f641f6748509af0e9c606ed187d8fcdee3
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, kScreenShareNotificationId,
70 help_label_text, base::string16() /* body is blank */,
71 resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK),
72 base::string16() /* display_source */, GURL(),
73 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
74 system_notifier::kNotifierScreenShare),
75 data, new tray::ScreenNotificationDelegate(this)));
76 notification->SetSystemPriority();
77 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
80 std::string ScreenShareTrayItem::GetNotificationId() {
81 return kScreenShareNotificationId;
84 void ScreenShareTrayItem::OnScreenShareStart(
85 const base::Closure& stop_callback,
86 const base::string16& helper_name) {
87 helper_name_ = helper_name;
88 Start(stop_callback);
91 void ScreenShareTrayItem::OnScreenShareStop() {
92 // We do not need to run the stop callback
93 // when screening is stopped externally.
94 set_is_started(false);
95 Update();
98 } // namespace ash