123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // Copyright 2014 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/components/proximity_auth/screenlock_bridge.h"
- #include <string>
- #include <utility>
- #include <memory>
- #include "ash/components/multidevice/logging/logging.h"
- #include "build/build_config.h"
- #include "chromeos/ash/components/dbus/session_manager/session_manager_client.h"
- namespace proximity_auth {
- namespace {
- base::LazyInstance<ScreenlockBridge>::DestructorAtExit
- g_screenlock_bridge_instance = LAZY_INSTANCE_INITIALIZER;
- // Ids for the icons that are supported by lock screen and signin screen
- // account picker as user pod custom icons.
- // The id's should be kept in sync with values used by user_pod_row.js.
- const char kLockedUserPodCustomIconId[] = "locked";
- const char kLockedToBeActivatedUserPodCustomIconId[] = "locked-to-be-activated";
- const char kLockedWithProximityHintUserPodCustomIconId[] =
- "locked-with-proximity-hint";
- const char kUnlockedUserPodCustomIconId[] = "unlocked";
- const char kHardlockedUserPodCustomIconId[] = "hardlocked";
- const char kSpinnerUserPodCustomIconId[] = "spinner";
- // Given the user pod icon, returns its id as used by the user pod UI code.
- std::string GetIdForIcon(ScreenlockBridge::UserPodCustomIcon icon) {
- switch (icon) {
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED:
- return kLockedUserPodCustomIconId;
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED:
- return kLockedToBeActivatedUserPodCustomIconId;
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT:
- return kLockedWithProximityHintUserPodCustomIconId;
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_UNLOCKED:
- return kUnlockedUserPodCustomIconId;
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_HARDLOCKED:
- return kHardlockedUserPodCustomIconId;
- case ScreenlockBridge::USER_POD_CUSTOM_ICON_SPINNER:
- return kSpinnerUserPodCustomIconId;
- default:
- return "";
- }
- }
- } // namespace
- ScreenlockBridge::UserPodCustomIconInfo::UserPodCustomIconInfo()
- : autoshow_tooltip_(false), hardlock_on_click_(false) {}
- ScreenlockBridge::UserPodCustomIconInfo::~UserPodCustomIconInfo() {}
- std::unique_ptr<base::DictionaryValue>
- ScreenlockBridge::UserPodCustomIconInfo::ToDictionaryValue() const {
- auto result = std::make_unique<base::DictionaryValue>();
- result->SetStringKey("id", GetIDString());
- if (!tooltip_.empty()) {
- base::DictionaryValue tooltip_options;
- tooltip_options.SetStringKey("text", tooltip_);
- tooltip_options.SetBoolKey("autoshow", autoshow_tooltip_);
- result->SetKey("tooltip", std::move(tooltip_options));
- }
- if (!aria_label_.empty())
- result->SetStringKey("ariaLabel", aria_label_);
- if (hardlock_on_click_)
- result->SetBoolKey("hardlockOnClick", true);
- return result;
- }
- void ScreenlockBridge::UserPodCustomIconInfo::SetIcon(
- ScreenlockBridge::UserPodCustomIcon icon) {
- icon_ = icon;
- }
- void ScreenlockBridge::UserPodCustomIconInfo::SetTooltip(
- const std::u16string& tooltip,
- bool autoshow) {
- tooltip_ = tooltip;
- autoshow_tooltip_ = autoshow;
- }
- void ScreenlockBridge::UserPodCustomIconInfo::SetAriaLabel(
- const std::u16string& aria_label) {
- aria_label_ = aria_label;
- }
- void ScreenlockBridge::UserPodCustomIconInfo::SetHardlockOnClick() {
- hardlock_on_click_ = true;
- }
- std::string ScreenlockBridge::UserPodCustomIconInfo::GetIDString() const {
- return GetIdForIcon(icon_);
- }
- // static
- ScreenlockBridge* ScreenlockBridge::Get() {
- return g_screenlock_bridge_instance.Pointer();
- }
- void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) {
- // Don't notify observers if there is no change -- i.e. if the screen was
- // already unlocked, and is remaining unlocked.
- if (lock_handler == lock_handler_)
- return;
- DCHECK(lock_handler_ == nullptr || lock_handler == nullptr);
- // TODO(isherman): If |lock_handler| is null, then |lock_handler_| might have
- // been freed. Cache the screen type rather than querying it below.
- LockHandler::ScreenType screen_type;
- if (lock_handler_)
- screen_type = lock_handler_->GetScreenType();
- else
- screen_type = lock_handler->GetScreenType();
- lock_handler_ = lock_handler;
- if (lock_handler_) {
- for (auto& observer : observers_)
- observer.OnScreenDidLock(screen_type);
- } else {
- focused_account_id_ = EmptyAccountId();
- for (auto& observer : observers_)
- observer.OnScreenDidUnlock(screen_type);
- }
- }
- void ScreenlockBridge::SetFocusedUser(const AccountId& account_id) {
- if (account_id == focused_account_id_)
- return;
- focused_account_id_ = account_id;
- for (auto& observer : observers_)
- observer.OnFocusedUserChanged(account_id);
- }
- bool ScreenlockBridge::IsLocked() const {
- return lock_handler_ != nullptr;
- }
- void ScreenlockBridge::Lock() {
- ash::SessionManagerClient::Get()->RequestLockScreen();
- }
- void ScreenlockBridge::Unlock(const AccountId& account_id) {
- if (lock_handler_)
- lock_handler_->Unlock(account_id);
- }
- void ScreenlockBridge::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
- }
- void ScreenlockBridge::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
- }
- ScreenlockBridge::ScreenlockBridge()
- : lock_handler_(nullptr), focused_account_id_(EmptyAccountId()) {}
- ScreenlockBridge::~ScreenlockBridge() {}
- } // namespace proximity_auth
|