1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright 2017 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.
/**
* This behavior bundles functionality required to show a password to the user.
* It is used by both <password-list-item> and <password-edit-dialog>.
*
* @polymerBehavior
*/
const ShowPasswordBehavior = {
properties: {
/**
* The password that is being displayed.
* @type {!ShowPasswordBehavior.UiEntryWithPassword}
*/
item: Object,
},
/**
* Gets the password input's type. Should be 'text' when password is visible
* or when there's federated text otherwise 'password'.
* @private
*/
getPasswordInputType_: function() {
return this.item.password || this.item.entry.federationText ? 'text' :
'password';
},
/**
* Gets the title text for the show/hide icon.
* @param {string} password
* @param {string} hide The i18n text to use for 'Hide'
* @param {string} show The i18n text to use for 'Show'
* @private
*/
showPasswordTitle_: function(password, hide, show) {
return password ? hide : show;
},
/**
* Get the right icon to display when hiding/showing a password.
* @return {string}
* @private
*/
getIconClass_: function() {
return this.item.password ? 'icon-visibility-off' : 'icon-visibility';
},
/**
* Gets the text of the password. Will use the value of |password| unless it
* cannot be shown, in which case it will be spaces. It can also be the
* federated text.
* @private
*/
getPassword_: function() {
if (!this.item) {
return '';
}
return this.item.entry.federationText || this.item.password ||
' '.repeat(this.item.entry.numCharactersInPassword);
},
/**
* Handler for tapping the show/hide button.
* @private
*/
onShowPasswordButtonTap_: function() {
if (this.item.password) {
this.set('item.password', '');
} else {
PasswordManagerImpl.getInstance()
.getPlaintextPassword(this.item.entry.id)
.then(password => {
this.set('item.password', password);
});
}
},
};
/**
* @typedef {{
* entry: !chrome.passwordsPrivate.PasswordUiEntry,
* password: string
* }}
*/
ShowPasswordBehavior.UiEntryWithPassword;
|