snooping_protection_view.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2021 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. #include "ash/system/human_presence/snooping_protection_view.h"
  5. #include "ash/public/cpp/session/session_observer.h"
  6. #include "ash/resources/vector_icons/vector_icons.h"
  7. #include "ash/session/session_controller_impl.h"
  8. #include "ash/shell.h"
  9. #include "ash/strings/grit/ash_strings.h"
  10. #include "ash/style/ash_color_provider.h"
  11. #include "ash/system/tray/tray_constants.h"
  12. #include "ash/system/tray/tray_utils.h"
  13. #include "base/logging.h"
  14. #include "components/session_manager/session_manager_types.h"
  15. #include "third_party/skia/include/core/SkColor.h"
  16. #include "ui/base/l10n/l10n_util.h"
  17. #include "ui/gfx/image/image_skia.h"
  18. #include "ui/gfx/paint_vector_icon.h"
  19. #include "ui/gfx/vector_icon_types.h"
  20. #include "ui/views/controls/image_view.h"
  21. namespace ash {
  22. SnoopingProtectionView::SnoopingProtectionView(Shelf* shelf)
  23. : TrayItemView(shelf) {
  24. CreateImageView();
  25. SessionControllerImpl* session_controller =
  26. Shell::Get()->session_controller();
  27. session_observation_.Observe(session_controller);
  28. SnoopingProtectionController* controller =
  29. Shell::Get()->snooping_protection_controller();
  30. controller_observation_.Observe(controller);
  31. SetVisible(controller->SnooperPresent());
  32. UpdateIconColor(session_controller->GetSessionState());
  33. image_view()->SetTooltipText(l10n_util::GetStringUTF16(
  34. IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_SYSTEM_TRAY_TOOLTIP_TEXT));
  35. }
  36. SnoopingProtectionView::~SnoopingProtectionView() = default;
  37. void SnoopingProtectionView::HandleLocaleChange() {}
  38. void SnoopingProtectionView::OnSessionStateChanged(
  39. session_manager::SessionState session_state) {
  40. UpdateIconColor(session_state);
  41. }
  42. void SnoopingProtectionView::OnThemeChanged() {
  43. TrayItemView::OnThemeChanged();
  44. UpdateIconColor(Shell::Get()->session_controller()->GetSessionState());
  45. }
  46. const char* SnoopingProtectionView::GetClassName() const {
  47. return "SnoopingProtectionView";
  48. }
  49. void SnoopingProtectionView::OnSnoopingStatusChanged(bool snooper) {
  50. SetVisible(snooper);
  51. }
  52. void SnoopingProtectionView::OnSnoopingProtectionControllerDestroyed() {
  53. controller_observation_.Reset();
  54. }
  55. void SnoopingProtectionView::UpdateIconColor(
  56. session_manager::SessionState session_state) {
  57. const SkColor new_color = TrayIconColor(session_state);
  58. const gfx::ImageSkia new_icon = gfx::CreateVectorIcon(gfx::IconDescription(
  59. kSystemTraySnoopingProtectionIcon, kUnifiedTrayIconSize, new_color));
  60. image_view()->SetImage(new_icon);
  61. }
  62. } // namespace ash