Commit e3f32003 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

Smart Lock: Remove authToken listeners.

This is a necessary change now that Polymer 2 is enabled.

Previously, Multidevice and Smart Lock pages were being informed
of an authToken change by their child element passwordPrompt, but that
is no longer bubbling up to the parent. Now, explicitly bind to the
authToken of passwordPrompt as a property, and use it when the dialog
close event is fired. As a consequence of this, the authTokenChanged()
callbacks in both parents is unnecessary and has been removed.

Bug: 934987
Change-Id: Ie0d624dde09f895a7076122aaed9eb224a629a1a
Reviewed-on: https://chromium-review.googlesource.com/c/1484495Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635795}
parent 57a6aba9
...@@ -70,7 +70,6 @@ Polymer({ ...@@ -70,7 +70,6 @@ Polymer({
}, },
listeners: { listeners: {
'auth-token-changed': 'onAuthTokenChanged_',
'close': 'onDialogClose_', 'close': 'onDialogClose_',
'feature-toggle-clicked': 'onFeatureToggleClicked_', 'feature-toggle-clicked': 'onFeatureToggleClicked_',
'forget-device-requested': 'onForgetDeviceRequested_', 'forget-device-requested': 'onForgetDeviceRequested_',
...@@ -272,14 +271,6 @@ Polymer({ ...@@ -272,14 +271,6 @@ Polymer({
this.showPasswordPromptDialog_ = false; this.showPasswordPromptDialog_ = false;
}, },
/**
* @param {!CustomEvent<!{value: string}>} event
* @private
*/
onAuthTokenChanged_: function(event) {
this.authToken_ = event.detail.value;
},
/** /**
* Attempt to enable the provided feature. If not authenticated (i.e., * Attempt to enable the provided feature. If not authenticated (i.e.,
* |authToken_| is invalid), display the password prompt to begin the * |authToken_| is invalid), display the password prompt to begin the
......
...@@ -56,9 +56,10 @@ ...@@ -56,9 +56,10 @@
</div> </div>
</iron-collapse> </iron-collapse>
<template is="dom-if" if="[[showPasswordPromptDialog_]]" restamp> <template is="dom-if" if="[[showPasswordPromptDialog_]]" restamp>
<settings-password-prompt-dialog on-close="onDialogClose_"> <settings-password-prompt-dialog id="smartLockSignInPasswordPrompt"
on-close="onEnableSignInDialogClose_" auth-token="{{authToken_}}">
</settings-password-prompt-dialog> </settings-password-prompt-dialog>
</template> </template>
</template> </template>
<script src="multidevice_smartlock_subpage.js"></script> <script src="multidevice_smartlock_subpage.js"></script>
</dom-module> </dom-module>
\ No newline at end of file
...@@ -76,10 +76,15 @@ Polymer({ ...@@ -76,10 +76,15 @@ Polymer({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
},
listeners: { /**
'auth-token-changed': 'onAuthTokenChanged_', * Authentication token provided by password-prompt-dialog.
* @private {string}
*/
authToken_: {
type: String,
value: '',
},
}, },
/** @private {?settings.MultiDeviceBrowserProxy} */ /** @private {?settings.MultiDeviceBrowserProxy} */
...@@ -163,30 +168,22 @@ Polymer({ ...@@ -163,30 +168,22 @@ Polymer({
}, },
/** /**
* Completes the transaction of setting the Smart Lock 'sign-in enabled' pref * Updates the state of the password dialog controller flag when the UI
* after the user authenticates. * element closes.
* @param {!CustomEvent<!{value: string}>} event The event containing the auth
* token.
* @private * @private
*/ */
onAuthTokenChanged_: function(event) { onEnableSignInDialogClose_: function() {
const authToken = event.detail.value; this.showPasswordPromptDialog_ = false;
// The auth-token-changed event fires after the expiration period ( // If |this.authToken_| is set when the dialog has been closed, this means
// represented by the empty string), so only move forward when the auth // that the user entered the correct password into the dialog when
// token is non-empty. // attempting to enable SignIn with Smart Lock.
if (authToken !== '') { if (this.authToken_ !== '') {
this.browserProxy_.setSmartLockSignInEnabled( this.browserProxy_.setSmartLockSignInEnabled(
true /* enabled */, authToken); true /* enabled */, this.authToken_);
} }
},
/** // Always require password entry if re-enabling SignIn with Smart Lock.
* Updates the state of the password dialog controller flag when the UI this.authToken_ = '';
* element closes.
* @private
*/
onDialogClose_: function() {
this.showPasswordPromptDialog_ = false;
}, },
}); });
...@@ -237,8 +237,10 @@ suite('Multidevice', function() { ...@@ -237,8 +237,10 @@ suite('Multidevice', function() {
assertEquals(settings.SignInEnabledState.DISABLED, assertEquals(settings.SignInEnabledState.DISABLED,
smartLockSignInRadio.selected); smartLockSignInRadio.selected);
// Simulate the user entering a valid password. // Simulate the user entering a valid password into the dialog.
smartLockSubPage.fire('auth-token-changed', {value: 'validAuthToken'}); smartLockSubPage.$$('#smartLockSignInPasswordPrompt').authToken =
'validAuthToken';
smartLockSubPage.$$('#smartLockSignInPasswordPrompt').fire('close');
assertEquals(settings.SignInEnabledState.ENABLED, assertEquals(settings.SignInEnabledState.ENABLED,
smartLockSignInRadio.selected); smartLockSignInRadio.selected);
......
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