1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
// 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 "components/proximity_auth/screenlock_bridge.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "components/proximity_auth/logging/logging.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#endif
namespace proximity_auth {
namespace {
base::LazyInstance<ScreenlockBridge> 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::UserPodCustomIconOptions::UserPodCustomIconOptions()
: autoshow_tooltip_(false),
hardlock_on_click_(false),
is_trial_run_(false) {
}
ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {
}
std::unique_ptr<base::DictionaryValue>
ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
std::string icon_id = GetIdForIcon(icon_);
result->SetString("id", icon_id);
if (!tooltip_.empty()) {
base::DictionaryValue* tooltip_options = new base::DictionaryValue();
tooltip_options->SetString("text", tooltip_);
tooltip_options->SetBoolean("autoshow", autoshow_tooltip_);
result->Set("tooltip", tooltip_options);
}
if (!aria_label_.empty())
result->SetString("ariaLabel", aria_label_);
if (hardlock_on_click_)
result->SetBoolean("hardlockOnClick", true);
if (is_trial_run_)
result->SetBoolean("isTrialRun", true);
return result;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetIcon(
ScreenlockBridge::UserPodCustomIcon icon) {
icon_ = icon;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetTooltip(
const base::string16& tooltip,
bool autoshow) {
tooltip_ = tooltip;
autoshow_tooltip_ = autoshow;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetAriaLabel(
const base::string16& aria_label) {
aria_label_ = aria_label;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() {
hardlock_on_click_ = true;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() {
is_trial_run_ = true;
}
// 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();
focused_account_id_ = EmptyAccountId();
lock_handler_ = lock_handler;
if (lock_handler_) {
for (auto& observer : observers_)
observer.OnScreenDidLock(screen_type);
} else {
for (auto& observer : observers_)
observer.OnScreenDidUnlock(screen_type);
}
}
void ScreenlockBridge::SetFocusedUser(const AccountId& account_id) {
if (account_id == focused_account_id_)
return;
PA_LOG(INFO) << "Focused user changed to " << account_id.Serialize();
focused_account_id_ = account_id;
for (auto& observer : observers_)
observer.OnFocusedUserChanged(account_id);
}
bool ScreenlockBridge::IsLocked() const {
return lock_handler_ != nullptr;
}
void ScreenlockBridge::Lock() {
#if defined(OS_CHROMEOS)
chromeos::SessionManagerClient* session_manager =
chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
session_manager->RequestLockScreen();
#else
NOTIMPLEMENTED();
#endif
}
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
|