Commit df378cb5 authored by jdufault's avatar jdufault Committed by Commit bot

Add a settings screen that lets the user choose how they unlock their device.

Currently, the user can unlock their device using one of three methods:
  - their password,
  - a PIN or password,
  - no authentication.

The setup pin screen is in a dependent CL.

The choose-method screen is available from the /quickUnlock/chooseMethod
endpoint.

BUG=603217
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2097673002
Cr-Commit-Position: refs/heads/master@{#405249}
parent 6c8e8a9e
......@@ -85,6 +85,35 @@
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_authenticate',
'dependencies': [
'quick_unlock_routing_behavior',
'<(EXTERNS_GYP):quick_unlock_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_choose_method',
'dependencies': [
'quick_unlock_password_detect_behavior',
'../prefs/compiled_resources2.gyp:prefs_types',
'../prefs/compiled_resources2.gyp:prefs_behavior',
'<(EXTERNS_GYP):quick_unlock_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_routing_behavior',
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_password_detect_behavior',
'dependencies': [
'quick_unlock_routing_behavior',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'sync_page',
'dependencies': [
......@@ -130,17 +159,5 @@
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_routing_behavior',
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'quick_unlock_authenticate',
'dependencies': [
'quick_unlock_routing_behavior',
'<(EXTERNS_GYP):quick_unlock_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
],
}
......@@ -18,6 +18,7 @@
<link rel="import" href="/people_page/easy_unlock_browser_proxy.html">
<link rel="import" href="/people_page/easy_unlock_turn_off_dialog.html">
<link rel="import" href="/people_page/quick_unlock_authenticate.html">
<link rel="import" href="/people_page/quick_unlock_choose_method.html">
<link rel="import" href="/people_page/users_page.html">
</if>
<if expr="not chromeos">
......@@ -242,12 +243,21 @@
<template is="dom-if" name="quick-unlock-authenticate">
<settings-subpage page-title="$i18n{quickUnlockTitle}">
<settings-quick-unlock-authenticate
account-password="{{quickUnlockAccountPassword}}"
set-modes="{{quickUnlockSetModes}}"
current-route="{{currentRoute}}"
profile-name="[[profileName_]]">
</settings-quick-unlock-authenticate>
</settings-subpage>
</template>
<template is="dom-if" name="quick-unlock-choose-method">
<settings-subpage page-title="$i18n{quickUnlockTitle}">
<settings-quick-unlock-choose-method
set-modes="[[quickUnlockSetModes]]"
current-route="{{currentRoute}}"
prefs="{{prefs}}">
</settings-quick-unlock-choose-method>
</settings-subpage>
</template>
<template is="dom-if" name="users">
<settings-subpage page-title="$i18n{usersPageTitle}">
<settings-users-page prefs="{{prefs}}"></settings-users-page>
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-input/paper-input.html">
<link rel="import" href="/people_page/pin_keyboard.html">
<link rel="import" href="/people_page/quick_unlock_routing_behavior.html">
<link rel="import" href="/people_page/quick_unlock_password_detect_behavior.html">
<link rel="import" href="/prefs/prefs_behavior.html">
<link rel="import" href="/settings_page/settings_section.html">
<link rel="import" href="/settings_shared_css.html">
<dom-module id="settings-quick-unlock-choose-method">
<template>
<style include="settings-shared"></style>
<style>
#warning-message {
color: var(--paper-grey-500);
font-style: italic;
}
.align-end {
justify-content: flex-end;
}
</style>
<div>
<div class="settings-box">
$i18n{quickUnlockChooseUnlockMethod}
</div>
<div class="list-frame">
<paper-radio-group selected="{{selectedUnlockType_}}">
<paper-radio-button name="password">
$i18n{quickUnlockUnlockMethodPassword}
</paper-radio-button>
<paper-radio-button name="pin+password">
$i18n{quickUnlockUnlockMethodPinAndPassword}
</paper-radio-button>
<paper-radio-button name="none">
$i18n{quickUnlockUnlockMethodNone}
</paper-radio-button>
</paper-radio-group>
</div>
<div class="step" hidden$="[[!showSetupPin_(selectedUnlockType_)]]">
<div class="settings-box continuation">
<!-- TODO(jdufault): i18n once this string is finalized. -->
<span id="warning-message">
Warning about how PIN is weaker than a password.
</span>
</div>
<div class="align-end settings-box">
<paper-button class="action-button" on-tap="onConfigurePin_">
$i18n{quickUnlockConfigurePinButton}
</paper-button>
</div>
</div>
</div>
</template>
<script src="quick_unlock_choose_method.js"></script>
</dom-module>
// Copyright 2016 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.
/**
* @fileoverview
* 'settings-quick-unlock-choose-method' allows the user to change how they
* unlock their device. Note that setting up the unlock method is delegated
* to other elements.
*
* Example:
*
* <settings-quick-unlock-choose-method
* set-modes="[[quickUnlockSetModes]]"
* current-route="{{currentRoute}}"
* prefs="{{prefs}}">
* </settings-quick-unlock-choose-method>
*/
(function() {
'use strict';
/** @const */ var ENABLE_LOCK_SCREEN_PREF = 'settings.enable_screen_lock';
/** @enum {string} */
var QuickUnlockUnlockType = {
VALUE_PENDING: 'value_pending',
NONE: 'none',
PASSWORD: 'password',
PIN_PASSWORD: 'pin+password'
};
Polymer({
is: 'settings-quick-unlock-choose-method',
behaviors: [
PrefsBehavior, QuickUnlockPasswordDetectBehavior
],
properties: {
/** Preferences state. */
prefs: {
type: Object,
notify: true,
},
/**
* The currently selected unlock type.
* @type {!QuickUnlockUnlockType}
* @private
*/
selectedUnlockType_: {
type: String,
notify: true,
value: QuickUnlockUnlockType.VALUE_PENDING,
observer: 'selectedUnlockTypeChanged_'
}
},
observers: [
'onRouteChanged_(currentRoute)',
'onSetModesChanged_(setModes)'
],
/** @override */
attached: function() {
CrSettingsPrefs.initialized.then(this.updateUnlockType_.bind(this));
this.boundOnPrefsChanged_ = function(prefs) {
for (var i = 0; i < prefs.length; ++i) {
if (prefs[i].key == ENABLE_LOCK_SCREEN_PREF)
this.updateUnlockType_();
}
}.bind(this);
this.boundOnActiveModesChanged_ = this.updateUnlockType_.bind(this);
chrome.settingsPrivate.onPrefsChanged.addListener(
this.boundOnPrefsChanged_);
chrome.quickUnlockPrivate.onActiveModesChanged.addListener(
this.boundOnActiveModesChanged_);
this.askForPasswordIfUnset();
},
/** @override */
detached: function() {
chrome.settingsPrivate.onPrefsChanged.removeListener(
this.boundOnPrefsChanged_);
chrome.quickUnlockPrivate.onActiveModesChanged.removeListener(
this.boundOnActiveModesChanged_);
},
/** @private */
onRouteChanged_: function() {
if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
this.askForPasswordIfUnset();
},
/** @private */
onSetModesChanged_: function() {
if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
this.askForPasswordIfUnset();
},
/**
* Updates the selected unlock type radio group. This function will get called
* after preferences are initialized, after the quick unlock mode has been
* changed, and after the lockscreen preference has changed.
*
* @private
*/
updateUnlockType_: function() {
// The quickUnlockPrivate.onActiveModesChanged event could trigger this
// function before CrSettingsPrefs is initialized if another settings page
// changes the quick unlock state.
if (!CrSettingsPrefs.isInitialized)
return;
if (!this.getPref(ENABLE_LOCK_SCREEN_PREF).value) {
this.selectedUnlockType_ = QuickUnlockUnlockType.NONE;
return;
}
chrome.quickUnlockPrivate.getActiveModes(function(modes) {
if (modes.includes(chrome.quickUnlockPrivate.QuickUnlockMode.PIN)) {
this.selectedUnlockType_ = QuickUnlockUnlockType.PIN_PASSWORD;
} else if (this.selectedUnlockType_ !=
QuickUnlockUnlockType.PIN_PASSWORD) {
// We don't want to clobber an existing PIN+PASSWORD state because the
// user needs to configure that option before actually using it.
//
// Specifically, this check is needed because this function gets called
// by the pref system after changing the unlock type from NONE to
// PIN+PASSWORD. Without the conditional assignment, this function would
// change the PIN+PASSWORD lock type to PASSWORD because the PIN hasn't
// been configured yet.
this.selectedUnlockType_ = QuickUnlockUnlockType.PASSWORD;
}
}.bind(this));
},
/**
* Called when the unlock type has changed.
* @param {!string} selected The current unlock type.
* @param {?string} previous The old unlock type. undefined if not present.
* @private
*/
selectedUnlockTypeChanged_: function(selected, previous) {
// This method gets invoked when setting the initial value from the existing
// state. In that case, we don't need to bother updating the prefs.
if (!previous)
return;
this.setPrefValue(ENABLE_LOCK_SCREEN_PREF,
selected != QuickUnlockUnlockType.NONE);
if (selected != QuickUnlockUnlockType.PIN_PASSWORD && this.setModes) {
this.setModes.call(null, [], [], function(didSet) {
assert(didSet, 'Failed to clear quick unlock modes');
});
}
},
/**
* Retruns true if the setup pin section should be shown.
* @param {!string} selectedUnlockType The current unlock type. Used to let
* polymer know about the dependency.
* @private
*/
showSetupPin_: function(selectedUnlockType) {
return selectedUnlockType === QuickUnlockUnlockType.PIN_PASSWORD;
},
/** @private */
onConfigurePin_: function() {
this.currentRoute = {
page: 'basic',
section: 'people',
subpage: [QuickUnlockScreen.CHOOSE_METHOD, QuickUnlockScreen.SETUP_PIN]
};
},
});
})();
<link rel="import" href="chrome://resources/html/polymer.html">
<script src="/people_page/quick_unlock_password_detect_behavior.js"></script>
// Copyright 2016 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.
/**
* @fileoverview
* Contains utilities for verifying the user has entered an account password.
*/
/** @polymerBehavior */
var QuickUnlockPasswordDetectBehavior = [QuickUnlockRoutingBehavior, {
properties: {
setModes: Object
},
/**
* Verifies that there is an account password available for the
* chrome.quickUnlockPrivate.setModes call. If there is no password, this will
* redirect to the authenticate screen.
*/
askForPasswordIfUnset: function() {
if (!this.setModes) {
this.currentRoute = {
page: 'basic',
section: 'people',
subpage: [QuickUnlockScreen.AUTHENTICATE]
};
}
}
}];
......@@ -214,6 +214,12 @@ Polymer({
section: 'people',
subpage: ['quick-unlock-authenticate'],
},
{
url: '/quickUnlock/chooseMethod',
page: 'basic',
section: 'people',
subpage: ['quick-unlock-choose-method'],
},
{
url: '/accounts',
page: 'basic',
......
......@@ -971,6 +971,14 @@
type="chrome_html"
flattenhtml="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_QUICK_UNLOCK_CHOOSE_METHOD_JS"
file="people_page/quick_unlock_choose_method.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_QUICK_UNLOCK_CHOOSE_METHOD_HTML"
file="people_page/quick_unlock_choose_method.html"
type="chrome_html"
flattenhtml="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_QUICK_UNLOCK_ROUTING_BEHAVIOR_JS"
file="people_page/quick_unlock_routing_behavior.js"
type="chrome_html" />
......@@ -979,6 +987,14 @@
type="chrome_html"
flattenhtml="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_QUICK_UNLOCK_PASSWORD_DETECT_BEHAVIOR_JS"
file="people_page/quick_unlock_password_detect_behavior.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_QUICK_UNLOCK_PASSWORD_DETECT_BEHAVIOR_HTML"
file="people_page/quick_unlock_password_detect_behavior.html"
type="chrome_html"
flattenhtml="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_KEYBOARD_PIN_JS"
file="people_page/pin_keyboard.js"
type="chrome_html"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment