From 61b26f607db0f7d2c16dd00662b8266903ed95eb Mon Sep 17 00:00:00 2001 From: "antrim@chromium.org" Date: Tue, 30 Apr 2013 15:20:30 +0000 Subject: Add tray warning for Locally managed users. BUG=229762 Review URL: https://chromiumcodereview.appspot.com/14507003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197372 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/ash.gyp | 4 ++ ash/ash_chromeos_strings.grdp | 2 +- ash/ash_strings.grd | 4 ++ ash/system/chromeos/enterprise/tray_enterprise.cc | 76 +++------------------- ash/system/chromeos/enterprise/tray_enterprise.h | 4 +- ash/system/chromeos/label_tray_view.cc | 60 +++++++++++++++++ ash/system/chromeos/label_tray_view.h | 37 +++++++++++ .../chromeos/managed/tray_locally_managed_user.cc | 53 +++++++++++++++ .../chromeos/managed/tray_locally_managed_user.h | 47 +++++++++++++ ash/system/tray/system_tray.cc | 2 + ash/system/tray/system_tray_delegate.h | 9 +++ ash/system/tray/test_system_tray_delegate.cc | 12 ++++ ash/system/tray/test_system_tray_delegate.h | 3 + ash/system/user/tray_user.cc | 16 +++-- 14 files changed, 253 insertions(+), 76 deletions(-) create mode 100644 ash/system/chromeos/label_tray_view.cc create mode 100644 ash/system/chromeos/label_tray_view.h create mode 100644 ash/system/chromeos/managed/tray_locally_managed_user.cc create mode 100644 ash/system/chromeos/managed/tray_locally_managed_user.h (limited to 'ash') diff --git a/ash/ash.gyp b/ash/ash.gyp index feace3b..392da15 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -194,6 +194,10 @@ 'system/chromeos/enterprise/tray_enterprise.cc', 'system/chromeos/keyboard_brightness_controller.cc', 'system/chromeos/keyboard_brightness_controller.h', + 'system/chromeos/label_tray_view.h', + 'system/chromeos/label_tray_view.cc', + 'system/chromeos/managed/tray_locally_managed_user.h', + 'system/chromeos/managed/tray_locally_managed_user.cc', 'system/chromeos/network/network_detailed_view.h', 'system/chromeos/network/network_icon.cc', 'system/chromeos/network/network_icon.h', diff --git a/ash/ash_chromeos_strings.grdp b/ash/ash_chromeos_strings.grdp index 70dee20..7ecee26 100644 --- a/ash/ash_chromeos_strings.grdp +++ b/ash/ash_chromeos_strings.grdp @@ -234,5 +234,5 @@ Stop - + diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index 96d80af..20a863e 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -435,6 +435,10 @@ Press Shift + Alt to switch. This session will end in $115 minutes. You will be automatically signed out. + + Locally managed user + + Previous menu diff --git a/ash/system/chromeos/enterprise/tray_enterprise.cc b/ash/system/chromeos/enterprise/tray_enterprise.cc index b316738..05ff799 100644 --- a/ash/system/chromeos/enterprise/tray_enterprise.cc +++ b/ash/system/chromeos/enterprise/tray_enterprise.cc @@ -4,78 +4,18 @@ #include "ash/system/chromeos/enterprise/tray_enterprise.h" -#include "ash/system/tray/hover_highlight_view.h" +#include "ash/system/chromeos/label_tray_view.h" #include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_views.h" #include "ash/system/user/login_status.h" #include "base/logging.h" #include "grit/ash_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/font.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/fill_layout.h" namespace ash { namespace internal { -class EnterpriseDefaultView : public views::View { - public: - explicit EnterpriseDefaultView(ViewClickListener* click_listener); - virtual ~EnterpriseDefaultView(); - void SetMessage(const base::string16& message); - private: - views::View* CreateChildView(const base::string16& message) const; - - ViewClickListener* click_listener_; - base::string16 message_; - - DISALLOW_COPY_AND_ASSIGN(EnterpriseDefaultView); -}; - -EnterpriseDefaultView::EnterpriseDefaultView( - ViewClickListener* click_listener) - : click_listener_(click_listener) { - SetLayoutManager(new views::FillLayout()); - SetVisible(false); -} - -EnterpriseDefaultView::~EnterpriseDefaultView() { -} - -void EnterpriseDefaultView::SetMessage(const base::string16& message) { - if (message_ == message) - return; - - message_ = message; - RemoveAllChildViews(true); - if (!message_.empty()) { - AddChildView(CreateChildView(message_)); - SetVisible(true); - } else { - SetVisible(false); - } -} - -views::View* EnterpriseDefaultView::CreateChildView( - const base::string16& message) const { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - const gfx::ImageSkia* icon = - rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); - HoverHighlightView* child = new HoverHighlightView(click_listener_); - child->AddIconAndLabel(*icon, message, gfx::Font::NORMAL); - child->text_label()->SetMultiLine(true); - child->text_label()->SetAllowCharacterBreak(true); - child->set_border(views::Border::CreateEmptyBorder(0, - kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); - child->SetExpandable(true); - child->SetVisible(true); - return child; -} - TrayEnterprise::TrayEnterprise(SystemTray* system_tray) : SystemTrayItem(system_tray), - default_view_(NULL) { + tray_view_(NULL) { Shell::GetInstance()->system_tray_notifier()-> AddEnterpriseDomainObserver(this); } @@ -88,23 +28,23 @@ TrayEnterprise::~TrayEnterprise() { void TrayEnterprise::UpdateEnterpriseMessage() { base::string16 message = Shell::GetInstance()->system_tray_delegate()-> GetEnterpriseMessage(); - if (default_view_) - default_view_->SetMessage(message); + if (tray_view_) + tray_view_->SetMessage(message); } views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) { - CHECK(default_view_ == NULL); + CHECK(tray_view_ == NULL); // For public accounts, enterprise ownership is indicated in the user details // instead. if (status == ash::user::LOGGED_IN_PUBLIC) return NULL; - default_view_ = new EnterpriseDefaultView(this); + tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); UpdateEnterpriseMessage(); - return default_view_; + return tray_view_; } void TrayEnterprise::DestroyDefaultView() { - default_view_ = NULL; + tray_view_ = NULL; } void TrayEnterprise::OnEnterpriseDomainChanged() { diff --git a/ash/system/chromeos/enterprise/tray_enterprise.h b/ash/system/chromeos/enterprise/tray_enterprise.h index 050c0f0..697dfcd 100644 --- a/ash/system/chromeos/enterprise/tray_enterprise.h +++ b/ash/system/chromeos/enterprise/tray_enterprise.h @@ -16,7 +16,7 @@ class SystemTray; namespace ash { namespace internal { -class EnterpriseDefaultView; +class LabelTrayView; class TrayEnterprise : public SystemTrayItem, public ViewClickListener, @@ -40,7 +40,7 @@ class TrayEnterprise : public SystemTrayItem, virtual void OnViewClicked(views::View* sender) OVERRIDE; private: - EnterpriseDefaultView* default_view_; + LabelTrayView* tray_view_; DISALLOW_COPY_AND_ASSIGN(TrayEnterprise); }; diff --git a/ash/system/chromeos/label_tray_view.cc b/ash/system/chromeos/label_tray_view.cc new file mode 100644 index 0000000..12a3ba5 --- /dev/null +++ b/ash/system/chromeos/label_tray_view.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/chromeos/label_tray_view.h" + +#include "ash/system/tray/hover_highlight_view.h" +#include "ash/system/tray/tray_constants.h" +#include "ash/system/tray/tray_views.h" +#include "ash/system/tray/view_click_listener.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/font.h" +#include "ui/views/controls/label.h" +#include "ui/views/layout/fill_layout.h" + +namespace ash { +namespace internal { + +LabelTrayView::LabelTrayView(ViewClickListener* click_listener, + int icon_resource_id) + : click_listener_(click_listener), + icon_resource_id_(icon_resource_id) { + SetLayoutManager(new views::FillLayout()); + SetVisible(false); +} + +LabelTrayView::~LabelTrayView() { +} + +void LabelTrayView::SetMessage(const base::string16& message) { + if (message_ == message) + return; + + message_ = message; + RemoveAllChildViews(true); + if (!message_.empty()) { + AddChildView(CreateChildView(message_)); + SetVisible(true); + } else { + SetVisible(false); + } +} + +views::View* LabelTrayView::CreateChildView( + const base::string16& message) const { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + const gfx::ImageSkia* icon = rb.GetImageSkiaNamed(icon_resource_id_); + HoverHighlightView* child = new HoverHighlightView(click_listener_); + child->AddIconAndLabel(*icon, message, gfx::Font::NORMAL); + child->text_label()->SetMultiLine(true); + child->text_label()->SetAllowCharacterBreak(true); + child->set_border(views::Border::CreateEmptyBorder(0, + kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); + child->SetExpandable(true); + child->SetVisible(true); + return child; +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/chromeos/label_tray_view.h b/ash/system/chromeos/label_tray_view.h new file mode 100644 index 0000000..402f5c3 --- /dev/null +++ b/ash/system/chromeos/label_tray_view.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ +#define ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ + +#include "base/string16.h" +#include "ui/views/view.h" + +namespace ash { +namespace internal { + +class ViewClickListener; + +// View for simple information in tray. Automatically hides when message is +// empty. Supports multiline messages. + +class LabelTrayView : public views::View { + public: + LabelTrayView(ViewClickListener* click_listener, int icon_resource_id); + virtual ~LabelTrayView(); + void SetMessage(const base::string16& message); + private: + views::View* CreateChildView(const base::string16& message) const; + + ViewClickListener* click_listener_; + int icon_resource_id_; + base::string16 message_; + + DISALLOW_COPY_AND_ASSIGN(LabelTrayView); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ diff --git a/ash/system/chromeos/managed/tray_locally_managed_user.cc b/ash/system/chromeos/managed/tray_locally_managed_user.cc new file mode 100644 index 0000000..b610f5b --- /dev/null +++ b/ash/system/chromeos/managed/tray_locally_managed_user.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/chromeos/managed/tray_locally_managed_user.h" + +#include "ash/system/chromeos/label_tray_view.h" +#include "ash/system/tray/system_tray_notifier.h" +#include "ash/system/user/login_status.h" +#include "base/logging.h" +#include "grit/ash_resources.h" + +namespace ash { +namespace internal { + +TrayLocallyManagedUser::TrayLocallyManagedUser(SystemTray* system_tray) + : SystemTrayItem(system_tray), + tray_view_(NULL) { +} + +TrayLocallyManagedUser::~TrayLocallyManagedUser() { +} + +void TrayLocallyManagedUser::UpdateMessage() { + base::string16 message = Shell::GetInstance()->system_tray_delegate()-> + GetLocallyManagedUserMessage(); + if (tray_view_) + tray_view_->SetMessage(message); +} + +views::View* TrayLocallyManagedUser::CreateDefaultView( + user::LoginStatus status) { + CHECK(tray_view_ == NULL); + if (status != ash::user::LOGGED_IN_LOCALLY_MANAGED) + return NULL; + + // TODO(antrim): replace to appropriate icon when there is one. + tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); + UpdateMessage(); + return tray_view_; +} + +void TrayLocallyManagedUser::DestroyDefaultView() { + tray_view_ = NULL; +} + +void TrayLocallyManagedUser::OnViewClicked(views::View* sender) { + Shell::GetInstance()->system_tray_delegate()->ShowLocallyManagedUserInfo(); +} + +} // namespace internal +} // namespace ash + diff --git a/ash/system/chromeos/managed/tray_locally_managed_user.h b/ash/system/chromeos/managed/tray_locally_managed_user.h new file mode 100644 index 0000000..17f24ba --- /dev/null +++ b/ash/system/chromeos/managed/tray_locally_managed_user.h @@ -0,0 +1,47 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H +#define ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H + +#include "ash/system/tray/system_tray_item.h" +#include "ash/system/tray/view_click_listener.h" + +namespace ash { +class SystemTray; +} + +namespace ash { +namespace internal { + +class LabelTrayView; + +class TrayLocallyManagedUser : public SystemTrayItem, + public ViewClickListener { + public: + explicit TrayLocallyManagedUser(SystemTray* system_tray); + virtual ~TrayLocallyManagedUser(); + + // If message is not empty updates content of default view, otherwise hides + // tray items. + void UpdateMessage(); + + // Overridden from SystemTrayItem. + virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; + virtual void DestroyDefaultView() OVERRIDE; + + // Overridden from ViewClickListener. + virtual void OnViewClicked(views::View* sender) OVERRIDE; + + private: + LabelTrayView* tray_view_; + + DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUser); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H + diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index 198d847..ce3a81a 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -52,6 +52,7 @@ #if defined(OS_CHROMEOS) #include "ash/system/chromeos/audio/tray_audio.h" #include "ash/system/chromeos/enterprise/tray_enterprise.h" +#include "ash/system/chromeos/managed/tray_locally_managed_user.h" #include "ash/system/chromeos/network/tray_network.h" #include "ash/system/chromeos/network/tray_sms.h" #include "ash/system/chromeos/network/tray_vpn.h" @@ -142,6 +143,7 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) { #endif #if defined(OS_CHROMEOS) AddTrayItem(new internal::TrayEnterprise(this)); + AddTrayItem(new internal::TrayLocallyManagedUser(this)); #endif AddTrayItem(new internal::TrayIME(this)); tray_accessibility_ = new internal::TrayAccessibility(this); diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h index 2cfd27d..e5f25ec 100644 --- a/ash/system/tray/system_tray_delegate.h +++ b/ash/system/tray/system_tray_delegate.h @@ -148,6 +148,12 @@ class SystemTrayDelegate { // Returns notification for enterprise enrolled devices. virtual const base::string16 GetEnterpriseMessage() const = 0; + // Returns the email of user that manages current locally managed user. + virtual const std::string GetLocallyManagedUserManager() const = 0; + + // Returns notification for locally managed users. + virtual const base::string16 GetLocallyManagedUserMessage() const = 0; + // Returns whether a system upgrade is available. virtual bool SystemShouldUpgrade() const = 0; @@ -193,6 +199,9 @@ class SystemTrayDelegate { // Shows information about enterprise enrolled devices. virtual void ShowEnterpriseInfo() = 0; + // Shows information about locally managed users. + virtual void ShowLocallyManagedUserInfo() = 0; + // Shows login UI to add other users to this session. virtual void ShowUserLogin() = 0; diff --git a/ash/system/tray/test_system_tray_delegate.cc b/ash/system/tray/test_system_tray_delegate.cc index c51784b..89d1bd4 100644 --- a/ash/system/tray/test_system_tray_delegate.cc +++ b/ash/system/tray/test_system_tray_delegate.cc @@ -122,6 +122,15 @@ const base::string16 TestSystemTrayDelegate::GetEnterpriseMessage() const { return string16(); } +const std::string TestSystemTrayDelegate::GetLocallyManagedUserManager() const { + return std::string(); +} + +const base::string16 TestSystemTrayDelegate::GetLocallyManagedUserMessage() + const { + return string16(); +} + bool TestSystemTrayDelegate::SystemShouldUpgrade() const { return true; } @@ -170,6 +179,9 @@ void TestSystemTrayDelegate::ShowPublicAccountInfo() { void TestSystemTrayDelegate::ShowEnterpriseInfo() { } +void TestSystemTrayDelegate::ShowLocallyManagedUserInfo() { +} + void TestSystemTrayDelegate::ShowUserLogin() { } diff --git a/ash/system/tray/test_system_tray_delegate.h b/ash/system/tray/test_system_tray_delegate.h index 19d207f..58c9825 100644 --- a/ash/system/tray/test_system_tray_delegate.h +++ b/ash/system/tray/test_system_tray_delegate.h @@ -36,6 +36,8 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { virtual void ChangeProfilePicture() OVERRIDE; virtual const std::string GetEnterpriseDomain() const OVERRIDE; virtual const base::string16 GetEnterpriseMessage() const OVERRIDE; + virtual const std::string GetLocallyManagedUserManager() const OVERRIDE; + virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE; virtual bool SystemShouldUpgrade() const OVERRIDE; virtual base::HourClockType GetHourClockType() const OVERRIDE; virtual PowerSupplyStatus GetPowerSupplyStatus() const OVERRIDE; @@ -51,6 +53,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { virtual void ShowAccessibilityHelp() OVERRIDE; virtual void ShowPublicAccountInfo() OVERRIDE; virtual void ShowEnterpriseInfo() OVERRIDE; + virtual void ShowLocallyManagedUserInfo() OVERRIDE; virtual void ShowUserLogin() OVERRIDE; virtual void ShutDown() OVERRIDE; virtual void SignOut() OVERRIDE; diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index 60b0d8d..1532c52 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -553,12 +553,18 @@ void UserView::AddUserCard(SystemTrayItem* owner, username->SetHorizontalAlignment(gfx::ALIGN_LEFT); details->AddChildView(username); - views::Label* email = new views::Label(UTF8ToUTF16(delegate->GetUserEmail())); ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - email->SetFont(bundle.GetFont(ui::ResourceBundle::SmallFont)); - email->SetHorizontalAlignment(gfx::ALIGN_LEFT); - email->SetEnabled(false); - details->AddChildView(email); + + views::Label* additional = new views::Label(); + + additional->SetText(login == ash::user::LOGGED_IN_LOCALLY_MANAGED ? + bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) : + UTF8ToUTF16(delegate->GetUserEmail())); + + additional->SetFont(bundle.GetFont(ui::ResourceBundle::SmallFont)); + additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); + additional->SetEnabled(false); + details->AddChildView(additional); user_card_->AddChildView(details); } -- cgit v1.1