authPrompt: Stop accepting preemptive answer if user stops typing

We only want to allow the user to type the preemptive password in
one smooth motion.  If they start to type, and then stop typing,
we should discard their preemptive password as expired.

Typing ahead the password is just a convenience for users who don't
want to manually lift the shift before typing their passwords, after
all.
This commit is contained in:
Ray Strode 2015-10-05 15:26:18 -04:00
parent 0d571e9191
commit 4aa823f7c4

View file

@ -21,6 +21,7 @@ const DEFAULT_BUTTON_WELL_ANIMATION_DELAY = 1000;
const DEFAULT_BUTTON_WELL_ANIMATION_TIME = 300;
const MESSAGE_FADE_OUT_ANIMATION_TIME = 500;
const PREEMPTIVE_ANSWER_TIMEOUT = 500;
/** @enum {number} */
export const AuthPromptMode = {
@ -70,6 +71,8 @@ export const AuthPrompt = GObject.registerClass({
this._defaultButtonWellActor = null;
this._cancelledRetries = 0;
this._idleMonitor = global.backend.get_core_idle_monitor();
let reauthenticationOnly;
if (this._mode === AuthPromptMode.UNLOCK_ONLY)
reauthenticationOnly = true;
@ -127,8 +130,14 @@ export const AuthPrompt = GObject.registerClass({
}
_onDestroy() {
if (this._preemptiveAnswerWatchId) {
this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
this._preemptiveAnswerWatchId = 0;
}
this._inactiveEntry.destroy();
this._inactiveEntry = null;
this._userVerifier.destroy();
this._userVerifier = null;
}
@ -281,6 +290,11 @@ export const AuthPrompt = GObject.registerClass({
else
this._preemptiveAnswer = this._entry.text;
if (this._preemptiveAnswerWatchId) {
this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
this._preemptiveAnswerWatchId = 0;
}
this.emit('next');
}
@ -490,6 +504,11 @@ export const AuthPrompt = GObject.registerClass({
}
setQuestion(question) {
if (this._preemptiveAnswerWatchId) {
this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
this._preemptiveAnswerWatchId = 0;
}
this._entry.hint_text = question;
this._authList.hide();
@ -611,6 +630,19 @@ export const AuthPrompt = GObject.registerClass({
this._updateEntry(false);
}
_onUserStoppedTypePreemptiveAnswer() {
if (!this._preemptiveAnswerWatchId ||
this._preemptiveAnswer ||
this._queryingService)
return;
this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
this._preemptiveAnswerWatchId = 0;
this._entry.text = '';
this.updateSensitivity(false);
}
reset() {
let oldStatus = this.verificationStatus;
this.verificationStatus = AuthPromptStatus.NOT_VERIFYING;
@ -618,6 +650,11 @@ export const AuthPrompt = GObject.registerClass({
this.cancelButton.can_focus = this._hasCancelButton;
this._preemptiveAnswer = null;
if (this._preemptiveAnswerWatchId)
this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
this._preemptiveAnswerWatchId = this._idleMonitor.add_idle_watch(PREEMPTIVE_ANSWER_TIMEOUT,
this._onUserStoppedTypePreemptiveAnswer.bind(this));
if (this._userVerifier)
this._userVerifier.cancel();