summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authormsarda <msarda@chromium.org>2015-04-27 08:30:23 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-27 15:30:25 +0000
commitf80a09109fae223241b5462e20a3556edfbd6740 (patch)
treee389138ceecdaa066a260cf0385c11373781985b /components
parent89cdcdeb58101b663c32ba25e07cccd919222dac (diff)
downloadchromium_src-f80a09109fae223241b5462e20a3556edfbd6740.zip
chromium_src-f80a09109fae223241b5462e20a3556edfbd6740.tar.gz
chromium_src-f80a09109fae223241b5462e20a3556edfbd6740.tar.bz2
Move ScreenlockBridge to components/proximity_auth.
This CL moves ScreenlockBridge to components/proximity_auth. It also moves the usage of profile out of ScreenLockBridge as this dependency is forbidden in //components. TBR=rogerta,antrim,rdevlin.cronin,tengs BUG=479670 Review URL: https://codereview.chromium.org/1096293003 Cr-Commit-Position: refs/heads/master@{#327049}
Diffstat (limited to 'components')
-rw-r--r--components/proximity_auth.gypi3
-rw-r--r--components/proximity_auth/BUILD.gn3
-rw-r--r--components/proximity_auth/DEPS6
-rw-r--r--components/proximity_auth/proximity_auth_client.h39
-rw-r--r--components/proximity_auth/screenlock_bridge.cc176
-rw-r--r--components/proximity_auth/screenlock_bridge.h190
6 files changed, 417 insertions, 0 deletions
diff --git a/components/proximity_auth.gypi b/components/proximity_auth.gypi
index c5fcc84..e10cc9c 100644
--- a/components/proximity_auth.gypi
+++ b/components/proximity_auth.gypi
@@ -37,11 +37,14 @@
"proximity_auth/connection.h",
"proximity_auth/connection_finder.h",
"proximity_auth/connection_observer.h",
+ "proximity_auth/proximity_auth_client.h",
"proximity_auth/proximity_auth_system.cc",
"proximity_auth/proximity_auth_system.h",
"proximity_auth/remote_device.h",
"proximity_auth/remote_status_update.cc",
"proximity_auth/remote_status_update.h",
+ "proximity_auth/screenlock_bridge.cc",
+ "proximity_auth/screenlock_bridge.h",
"proximity_auth/secure_context.h",
"proximity_auth/switches.cc",
"proximity_auth/switches.h",
diff --git a/components/proximity_auth/BUILD.gn b/components/proximity_auth/BUILD.gn
index 7d31f67..e2faf96 100644
--- a/components/proximity_auth/BUILD.gn
+++ b/components/proximity_auth/BUILD.gn
@@ -23,11 +23,14 @@ source_set("proximity_auth") {
"connection.h",
"connection_finder.h",
"connection_observer.h",
+ "proximity_auth_client.h",
"proximity_auth_system.cc",
"proximity_auth_system.h",
"remote_device.h",
"remote_status_update.cc",
"remote_status_update.h",
+ "screenlock_bridge.cc",
+ "screenlock_bridge.h",
"secure_context.h",
"switches.cc",
"switches.h",
diff --git a/components/proximity_auth/DEPS b/components/proximity_auth/DEPS
index 6d746ad..161da31 100644
--- a/components/proximity_auth/DEPS
+++ b/components/proximity_auth/DEPS
@@ -2,3 +2,9 @@ include_rules = [
"+device/bluetooth",
"+net",
]
+
+specific_include_rules = {
+ "screenlock_bridge\.*": [
+ "+chromeos",
+ ],
+}
diff --git a/components/proximity_auth/proximity_auth_client.h b/components/proximity_auth/proximity_auth_client.h
new file mode 100644
index 0000000..b9ad752
--- /dev/null
+++ b/components/proximity_auth/proximity_auth_client.h
@@ -0,0 +1,39 @@
+// Copyright 2015 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 COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
+#define COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
+
+#include <string>
+
+#include "base/macros.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace proximity_auth {
+
+// An interface that needs to be supplied to the Proximity Auth component by its
+// embedder.
+class ProximityAuthClient {
+ public:
+ // Returns the authenticated username for |browser_context|.
+ virtual std::string GetAuthenticatedUsername(
+ content::BrowserContext* browser_context) const = 0;
+
+ // Locks the screen for |browser_context|.
+ virtual void Lock(content::BrowserContext* browser_context) = 0;
+
+ protected:
+ ProximityAuthClient() {}
+ virtual ~ProximityAuthClient() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProximityAuthClient);
+};
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
diff --git a/components/proximity_auth/screenlock_bridge.cc b/components/proximity_auth/screenlock_bridge.cc
new file mode 100644
index 0000000..2af8378
--- /dev/null
+++ b/components/proximity_auth/screenlock_bridge.cc
@@ -0,0 +1,176 @@
+// 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/logging.h"
+#include "base/strings/string16.h"
+#include "components/proximity_auth/proximity_auth_client.h"
+
+#if defined(OS_CHROMEOS)
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/session_manager_client.h"
+#endif
+
+namespace proximity_auth {
+namespace {
+
+// 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::ScreenlockBridge(ProximityAuthClient* client)
+ : client_(client), lock_handler_(nullptr) {
+ DCHECK(client_);
+}
+
+ScreenlockBridge::~ScreenlockBridge() {
+}
+
+ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions()
+ : autoshow_tooltip_(false),
+ hardlock_on_click_(false),
+ is_trial_run_(false) {
+}
+
+ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {
+}
+
+scoped_ptr<base::DictionaryValue>
+ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
+ scoped_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.Pass();
+}
+
+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;
+}
+
+void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) {
+ DCHECK(lock_handler_ == nullptr || lock_handler == nullptr);
+
+ // 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;
+
+ // 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_EACH_OBSERVER(Observer, observers_, OnScreenDidLock(screen_type));
+ else
+ FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidUnlock(screen_type));
+}
+
+void ScreenlockBridge::SetFocusedUser(const std::string& user_id) {
+ if (user_id == focused_user_id_)
+ return;
+ focused_user_id_ = user_id;
+ FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id));
+}
+
+bool ScreenlockBridge::IsLocked() const {
+ return lock_handler_ != nullptr;
+}
+
+void ScreenlockBridge::Lock(content::BrowserContext* browser_context) {
+#if defined(OS_CHROMEOS)
+ chromeos::SessionManagerClient* session_manager =
+ chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
+ session_manager->RequestLockScreen();
+#else
+ client_->Lock(browser_context);
+#endif
+}
+
+void ScreenlockBridge::Unlock(content::BrowserContext* browser_context) {
+ if (lock_handler_)
+ lock_handler_->Unlock(client_->GetAuthenticatedUsername(browser_context));
+}
+
+void ScreenlockBridge::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void ScreenlockBridge::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+} // namespace proximity_auth
diff --git a/components/proximity_auth/screenlock_bridge.h b/components/proximity_auth/screenlock_bridge.h
new file mode 100644
index 0000000..8386370
--- /dev/null
+++ b/components/proximity_auth/screenlock_bridge.h
@@ -0,0 +1,190 @@
+// 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.
+
+#ifndef COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
+#define COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "base/strings/string16.h"
+#include "base/values.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace proximity_auth {
+
+class ProximityAuthClient;
+
+// ScreenlockBridge brings together the screenLockPrivate API and underlying
+// support. On ChromeOS, it delegates calls to the ScreenLocker. On other
+// platforms, it delegates calls to UserManagerUI (and friends).
+// TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
+// used solely for the lock screen anymore.
+class ScreenlockBridge {
+ public:
+ // |client| is not owned and must outlive this object.
+ explicit ScreenlockBridge(ProximityAuthClient* client);
+ ~ScreenlockBridge();
+
+ // User pod icons supported by lock screen / signin screen UI.
+ enum UserPodCustomIcon {
+ USER_POD_CUSTOM_ICON_NONE,
+ USER_POD_CUSTOM_ICON_HARDLOCKED,
+ USER_POD_CUSTOM_ICON_LOCKED,
+ USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED,
+ // TODO(isherman): The "locked with proximity hint" icon is currently the
+ // same as the "locked" icon. It's treated as a separate case to allow an
+ // easy asset swap without changing the code, in case we decide to use a
+ // different icon for this case. If we definitely decide against that, then
+ // this enum entry should be removed.
+ USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT,
+ USER_POD_CUSTOM_ICON_UNLOCKED,
+ USER_POD_CUSTOM_ICON_SPINNER
+ };
+
+ // Class containing parameters describing the custom icon that should be
+ // shown on a user's screen lock pod next to the input field.
+ class UserPodCustomIconOptions {
+ public:
+ UserPodCustomIconOptions();
+ ~UserPodCustomIconOptions();
+
+ // Converts parameters to a dictionary values that can be sent to the
+ // screenlock web UI.
+ scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
+
+ // Sets the icon that should be shown in the UI.
+ void SetIcon(UserPodCustomIcon icon);
+
+ // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
+ // shown with the icon.
+ void SetTooltip(const base::string16& tooltip, bool autoshow);
+
+ // Sets the accessibility label of the icon. If this attribute is not
+ // provided, then the tooltip will be used.
+ void SetAriaLabel(const base::string16& aria_label);
+
+ // If hardlock on click is set, clicking the icon in the screenlock will
+ // go to state where password is required for unlock.
+ void SetHardlockOnClick();
+
+ // If the current lock screen is a trial run to introduce users to Easy
+ // Unlock, the icon will record metrics upon click.
+ void SetTrialRun();
+
+ private:
+ UserPodCustomIcon icon_;
+
+ base::string16 tooltip_;
+ bool autoshow_tooltip_;
+
+ base::string16 aria_label_;
+
+ bool hardlock_on_click_;
+
+ bool is_trial_run_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
+ };
+
+ class LockHandler {
+ public:
+ // Supported authentication types. Keep in sync with the enum in
+ // user_pod_row.js.
+ enum AuthType {
+ OFFLINE_PASSWORD = 0,
+ ONLINE_SIGN_IN = 1,
+ NUMERIC_PIN = 2,
+ USER_CLICK = 3,
+ EXPAND_THEN_USER_CLICK = 4,
+ FORCE_OFFLINE_PASSWORD = 5
+ };
+
+ enum ScreenType { SIGNIN_SCREEN = 0, LOCK_SCREEN = 1, OTHER_SCREEN = 2 };
+
+ // Displays |message| in a banner on the lock screen.
+ virtual void ShowBannerMessage(const base::string16& message) = 0;
+
+ // Shows a custom icon in the user pod on the lock screen.
+ virtual void ShowUserPodCustomIcon(
+ const std::string& user_email,
+ const UserPodCustomIconOptions& icon) = 0;
+
+ // Hides the custom icon in user pod for a user.
+ virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
+
+ // (Re)enable lock screen UI.
+ virtual void EnableInput() = 0;
+
+ // Set the authentication type to be used on the lock screen.
+ virtual void SetAuthType(const std::string& user_email,
+ AuthType auth_type,
+ const base::string16& auth_value) = 0;
+
+ // Returns the authentication type used for a user.
+ virtual AuthType GetAuthType(const std::string& user_email) const = 0;
+
+ // Returns the type of the screen -- a signin or a lock screen.
+ virtual ScreenType GetScreenType() const = 0;
+
+ // Unlocks from easy unlock app for a user.
+ virtual void Unlock(const std::string& user_email) = 0;
+
+ // Attempts to login the user using an easy unlock key.
+ virtual void AttemptEasySignin(const std::string& user_email,
+ const std::string& secret,
+ const std::string& key_label) = 0;
+
+ protected:
+ virtual ~LockHandler() {}
+ };
+
+ class Observer {
+ public:
+ // Invoked after the screen is locked.
+ virtual void OnScreenDidLock(LockHandler::ScreenType screen_type) = 0;
+
+ // Invoked after the screen lock is dismissed.
+ virtual void OnScreenDidUnlock(LockHandler::ScreenType screen_type) = 0;
+
+ // Invoked when the user focused on the lock screen changes.
+ virtual void OnFocusedUserChanged(const std::string& user_id) = 0;
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ void SetLockHandler(LockHandler* lock_handler);
+ void SetFocusedUser(const std::string& user_id);
+
+ bool IsLocked() const;
+ void Lock(content::BrowserContext* browser_context);
+ void Unlock(content::BrowserContext* browser_context);
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ LockHandler* lock_handler() { return lock_handler_; }
+
+ std::string focused_user_id() const { return focused_user_id_; }
+
+ private:
+ ProximityAuthClient* client_; // Not owned. Must outlive this object.
+ LockHandler* lock_handler_; // Not owned
+ // The last focused user's id.
+ std::string focused_user_id_;
+ ObserverList<Observer, true> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
+};
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_