Commit 0b3eda72 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Smart Lock: Display the enterprise controlled state of sign-in pref.

R=khorimoto@chromium.org

Bug: 894598
Test: none
Change-Id: I85bfe11dda29295d45c609851222bd40fff98ef7
Reviewed-on: https://chromium-review.googlesource.com/c/1283486
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600800}
parent 24e8a9cc
...@@ -67,6 +67,14 @@ js_library("multidevice_page") { ...@@ -67,6 +67,14 @@ js_library("multidevice_page") {
] ]
} }
js_library("multidevice_radio_button") {
deps = [
"//third_party/polymer/v1_0/components-chromium/iron-a11y-keys-behavior:iron-a11y-keys-behavior-extracted",
"//ui/webui/resources/cr_elements/cr_radio_button:cr_radio_button_behavior",
"//ui/webui/resources/cr_elements/policy:cr_policy_indicator",
]
}
js_library("multidevice_smartlock_subpage") { js_library("multidevice_smartlock_subpage") {
deps = [ deps = [
":multidevice_constants", ":multidevice_constants",
......
...@@ -58,6 +58,13 @@ cr.define('settings', function() { ...@@ -58,6 +58,13 @@ cr.define('settings', function() {
*/ */
setSmartLockSignInEnabled(enabled, opt_authToken) {} setSmartLockSignInEnabled(enabled, opt_authToken) {}
/**
* Returns the value of the preference controlling whether Smart Lock
* sign-in is allowed.
* @return {!Promise<boolean>}
*/
getSmartLockSignInAllowed() {}
/** /**
* Returns android messages info with messages feature state * Returns android messages info with messages feature state
* and messages for web permissions origin. * and messages for web permissions origin.
...@@ -111,6 +118,11 @@ cr.define('settings', function() { ...@@ -111,6 +118,11 @@ cr.define('settings', function() {
chrome.send('setSmartLockSignInEnabled', [enabled, opt_authToken]); chrome.send('setSmartLockSignInEnabled', [enabled, opt_authToken]);
} }
/** @override */
getSmartLockSignInAllowed() {
return cr.sendWithPromise('getSmartLockSignInAllowed');
}
/** @override */ /** @override */
getAndroidSmsInfo() { getAndroidSmsInfo() {
return cr.sendWithPromise('getAndroidSmsInfo'); return cr.sendWithPromise('getAndroidSmsInfo');
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_button/cr_radio_button_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_button/cr_radio_button_style_css.html">
<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_indicator.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<link rel="import" href="../settings_shared_css.html">
<!-- TODO(jhawkins): This is copy/pasted from controlled_radio_button. Figure
out how to refactor such that a common UI/behavior may be shared. The only
difference is how the controlling preference is read. -->
<dom-module id="multidevice-radio-button">
<template>
<style include="settings-shared cr-radio-button-style">
:host([disabled]) {
opacity: 1;
}
/* Disc and label should be transluscent, but not the policy indicator. */
:host([disabled]) .disc-wrapper,
:host([disabled]) #labelWrapper {
opacity: var(--cr-disabled-opacity);
}
cr-policy-pref-indicator {
margin-inline-start: var(--settings-controlled-by-spacing);
/* Enable pointer events for the indicator so :hover works. Disable
* clicks/taps via onIndicatorTap_ so outer on-tap doesn't trigger. */
pointer-events: all;
}
</style>
<div class="disc-wrapper">
<div class="disc-border"></div>
<div class="disc"></div>
</div>
<div id="labelWrapper">
<span>[[label]]</span>
</div>
<template is="dom-if" if="[[disabled]]" restamp>
<cr-policy-indicator
indicator-type="userPolicy"
icon-aria-label="[[label]]"
on-click="onIndicatorTap_">
</cr-policy-indicator>
</template>
</template>
<script src="multidevice_radio_button.js"></script>
</dom-module>
// Copyright 2018 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.
Polymer({
is: 'multidevice-radio-button',
behaviors: [
CrRadioButtonBehavior,
],
properties: {
disabled: {
type: Boolean,
reflectToAttribute: true,
observer: 'disabledChanged_',
},
name: {
type: String,
notify: true,
},
},
/**
* Updates attributes of the control to reflect its disabled state.
* @private
*/
disabledChanged_: function() {
this.setAttribute('tabindex', this.disabled ? -1 : 0);
this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false');
},
/**
* Prevents on-click handles on the control from being activated when the
* indicator is clicked.
* @param {!Event} e The click event.
* @private
*/
onIndicatorTap_: function(e) {
e.preventDefault();
e.stopPropagation();
},
});
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<link rel="import" href="multidevice_browser_proxy.html"> <link rel="import" href="multidevice_browser_proxy.html">
<link rel="import" href="multidevice_feature_behavior.html"> <link rel="import" href="multidevice_feature_behavior.html">
<link rel="import" href="multidevice_feature_toggle.html"> <link rel="import" href="multidevice_feature_toggle.html">
<link rel="import" href="multidevice_radio_button.html">
<link rel="import" href="../i18n_setup.html"> <link rel="import" href="../i18n_setup.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
...@@ -37,19 +38,21 @@ ...@@ -37,19 +38,21 @@
<div class="list-frame"> <div class="list-frame">
<paper-radio-group <paper-radio-group
selected="[[smartLockSignInEnabled_]]" selected="[[smartLockSignInEnabled_]]"
selectable="cr-radio-button" selectable="multidevice-radio-button"
on-paper-radio-group-changed= on-paper-radio-group-changed=
"onSmartLockSignInEnabledChanged_"> "onSmartLockSignInEnabledChanged_">
<cr-radio-button <multidevice-radio-button
disabled$="[[!smartLockSignInAllowed_]]"
name="disabled" name="disabled"
class="list-item underbar" class="list-item underbar"
label="$i18n{easyUnlockUnlockDeviceOnly}"> label="$i18n{easyUnlockUnlockDeviceOnly}">
</cr-radio-button> </multidevice-radio-button>
<cr-radio-button <multidevice-radio-button
disabled$="[[!smartLockSignInAllowed_]]"
name="enabled" name="enabled"
class="list-item" class="list-item"
label="$i18n{easyUnlockUnlockDeviceAndAllowSignin}"> label="$i18n{easyUnlockUnlockDeviceAndAllowSignin}">
</cr-radio-button> </multidevice-radio-button>
</paper-radio-group> </paper-radio-group>
</div> </div>
</iron-collapse> </iron-collapse>
......
...@@ -62,6 +62,15 @@ Polymer({ ...@@ -62,6 +62,15 @@ Polymer({
value: settings.SignInEnabledState.DISABLED, value: settings.SignInEnabledState.DISABLED,
}, },
/**
* True if the user is allowed to enable Smart Lock sign-in.
* @private
*/
smartLockSignInAllowed_: {
type: Boolean,
value: true,
},
/** @private */ /** @private */
showPasswordPromptDialog_: { showPasswordPromptDialog_: {
type: Boolean, type: Boolean,
...@@ -85,9 +94,17 @@ Polymer({ ...@@ -85,9 +94,17 @@ Polymer({
'smart-lock-signin-enabled-changed', 'smart-lock-signin-enabled-changed',
this.updateSmartLockSignInEnabled_.bind(this)); this.updateSmartLockSignInEnabled_.bind(this));
this.addWebUIListener(
'smart-lock-signin-allowed-changed',
this.updateSmartLockSignInAllowed_.bind(this));
this.browserProxy_.getSmartLockSignInEnabled().then(enabled => { this.browserProxy_.getSmartLockSignInEnabled().then(enabled => {
this.updateSmartLockSignInEnabled_(enabled); this.updateSmartLockSignInEnabled_(enabled);
}); });
this.browserProxy_.getSmartLockSignInAllowed().then(allowed => {
this.updateSmartLockSignInAllowed_(allowed);
});
}, },
/** /**
...@@ -111,6 +128,15 @@ Polymer({ ...@@ -111,6 +128,15 @@ Polymer({
settings.SignInEnabledState.DISABLED; settings.SignInEnabledState.DISABLED;
}, },
/**
* Updates the Smart Lock 'sign-in enabled' toggle such that disallowing
* sign-in disables the toggle.
* @private
*/
updateSmartLockSignInAllowed_: function(allowed) {
this.smartLockSignInAllowed_ = allowed;
},
/** @private */ /** @private */
openPasswordPromptDialog_: function() { openPasswordPromptDialog_: function() {
this.showPasswordPromptDialog_ = true; this.showPasswordPromptDialog_ = true;
......
...@@ -1367,6 +1367,12 @@ ...@@ -1367,6 +1367,12 @@
<structure name="IDR_SETTINGS_MULTIDEVICE_PAGE_JS" <structure name="IDR_SETTINGS_MULTIDEVICE_PAGE_JS"
file="multidevice_page/multidevice_page.js" file="multidevice_page/multidevice_page.js"
type="chrome_html" /> type="chrome_html" />
<structure name="IDR_SETTINGS_MULTIDEVICE_RADIO_BUTTON_HTML"
file="multidevice_page/multidevice_radio_button.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_MULTIDEVICE_RADIO_BUTTON_JS"
file="multidevice_page/multidevice_radio_button.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_MULTIDEVICE_SMARTLOCK_SUBPAGE_HTML" <structure name="IDR_SETTINGS_MULTIDEVICE_SMARTLOCK_SUBPAGE_HTML"
file="multidevice_page/multidevice_smartlock_subpage.html" file="multidevice_page/multidevice_smartlock_subpage.html"
type="chrome_html" /> type="chrome_html" />
......
...@@ -1721,6 +1721,7 @@ jumbo_split_static_library("ui") { ...@@ -1721,6 +1721,7 @@ jumbo_split_static_library("ui") {
"//chromeos/services/assistant/public/mojom", "//chromeos/services/assistant/public/mojom",
"//chromeos/services/assistant/public/proto:proto", "//chromeos/services/assistant/public/proto:proto",
"//chromeos/services/multidevice_setup/public/cpp:cpp", "//chromeos/services/multidevice_setup/public/cpp:cpp",
"//chromeos/services/multidevice_setup/public/cpp:prefs",
"//chromeos/services/multidevice_setup/public/cpp:url_provider", "//chromeos/services/multidevice_setup/public/cpp:url_provider",
"//chromeos/services/multidevice_setup/public/mojom", "//chromeos/services/multidevice_setup/public/mojom",
"//chromeos/strings", "//chromeos/strings",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h" #include "chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h" #include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/content_settings/core/common/content_settings_pattern.h" #include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
...@@ -95,6 +96,10 @@ void MultideviceHandler::RegisterMessages() { ...@@ -95,6 +96,10 @@ void MultideviceHandler::RegisterMessages() {
"setSmartLockSignInEnabled", "setSmartLockSignInEnabled",
base::BindRepeating(&MultideviceHandler::HandleSetSmartLockSignInEnabled, base::BindRepeating(&MultideviceHandler::HandleSetSmartLockSignInEnabled,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getSmartLockSignInAllowed",
base::BindRepeating(&MultideviceHandler::HandleGetSmartLockSignInAllowed,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getAndroidSmsInfo", "getAndroidSmsInfo",
base::BindRepeating(&MultideviceHandler::HandleGetAndroidSmsInfo, base::BindRepeating(&MultideviceHandler::HandleGetAndroidSmsInfo,
...@@ -244,6 +249,17 @@ void MultideviceHandler::HandleSetSmartLockSignInEnabled( ...@@ -244,6 +249,17 @@ void MultideviceHandler::HandleSetSmartLockSignInEnabled(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, enabled); proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, enabled);
} }
void MultideviceHandler::HandleGetSmartLockSignInAllowed(
const base::ListValue* args) {
std::string callback_id;
CHECK(args->GetString(0, &callback_id));
bool sign_in_allowed =
prefs_->GetBoolean(multidevice_setup::kSmartLockSigninAllowedPrefName);
ResolveJavascriptCallback(base::Value(callback_id),
base::Value(sign_in_allowed));
}
std::unique_ptr<base::DictionaryValue> std::unique_ptr<base::DictionaryValue>
MultideviceHandler::GenerateAndroidSmsInfo() { MultideviceHandler::GenerateAndroidSmsInfo() {
auto android_sms_info = std::make_unique<base::DictionaryValue>(); auto android_sms_info = std::make_unique<base::DictionaryValue>();
...@@ -327,6 +343,11 @@ void MultideviceHandler::RegisterPrefChangeListeners() { ...@@ -327,6 +343,11 @@ void MultideviceHandler::RegisterPrefChangeListeners() {
base::BindRepeating( base::BindRepeating(
&MultideviceHandler::NotifySmartLockSignInEnabledChanged, &MultideviceHandler::NotifySmartLockSignInEnabledChanged,
base::Unretained(this))); base::Unretained(this)));
pref_change_registrar_.Add(
multidevice_setup::kSmartLockSigninAllowedPrefName,
base::BindRepeating(
&MultideviceHandler::NotifySmartLockSignInAllowedChanged,
base::Unretained(this)));
} }
void MultideviceHandler::NotifySmartLockSignInEnabledChanged() { void MultideviceHandler::NotifySmartLockSignInEnabledChanged() {
...@@ -336,6 +357,13 @@ void MultideviceHandler::NotifySmartLockSignInEnabledChanged() { ...@@ -336,6 +357,13 @@ void MultideviceHandler::NotifySmartLockSignInEnabledChanged() {
base::Value(sign_in_enabled)); base::Value(sign_in_enabled));
} }
void MultideviceHandler::NotifySmartLockSignInAllowedChanged() {
bool sign_in_allowed =
prefs_->GetBoolean(multidevice_setup::kSmartLockSigninAllowedPrefName);
FireWebUIListener("smart-lock-signin-allowed-changed",
base::Value(sign_in_allowed));
}
bool MultideviceHandler::IsAuthTokenValid(const std::string& auth_token) { bool MultideviceHandler::IsAuthTokenValid(const std::string& auth_token) {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
quick_unlock::QuickUnlockStorage* quick_unlock_storage = quick_unlock::QuickUnlockStorage* quick_unlock_storage =
......
...@@ -69,6 +69,7 @@ class MultideviceHandler ...@@ -69,6 +69,7 @@ class MultideviceHandler
void HandleSetUpAndroidSms(const base::ListValue* args); void HandleSetUpAndroidSms(const base::ListValue* args);
void HandleGetSmartLockSignInEnabled(const base::ListValue* args); void HandleGetSmartLockSignInEnabled(const base::ListValue* args);
void HandleSetSmartLockSignInEnabled(const base::ListValue* args); void HandleSetSmartLockSignInEnabled(const base::ListValue* args);
void HandleGetSmartLockSignInAllowed(const base::ListValue* args);
void HandleGetAndroidSmsInfo(const base::ListValue* args); void HandleGetAndroidSmsInfo(const base::ListValue* args);
void OnSetFeatureStateEnabledResult(const std::string& js_callback_id, void OnSetFeatureStateEnabledResult(const std::string& js_callback_id,
...@@ -76,6 +77,7 @@ class MultideviceHandler ...@@ -76,6 +77,7 @@ class MultideviceHandler
void RegisterPrefChangeListeners(); void RegisterPrefChangeListeners();
void NotifySmartLockSignInEnabledChanged(); void NotifySmartLockSignInEnabledChanged();
void NotifySmartLockSignInAllowedChanged();
// Generate android sms info dictionary containing the messages for web // Generate android sms info dictionary containing the messages for web
// content settings origin url and messages feature state. // content settings origin url and messages feature state.
std::unique_ptr<base::DictionaryValue> GenerateAndroidSmsInfo(); std::unique_ptr<base::DictionaryValue> GenerateAndroidSmsInfo();
......
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