OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview 'passwords-section' is the collapsible section containing | 6 * @fileoverview 'passwords-section' is the collapsible section containing |
7 * the list of saved passwords as well as the list of sites that will never | 7 * the list of saved passwords as well as the list of sites that will never |
8 * save any passwords. | 8 * save any passwords. |
9 */ | 9 */ |
10 | 10 |
11 /** | 11 /** |
12 * Interface for all callbacks to the password API. | 12 * Interface for all callbacks to the password API. |
13 * @interface | 13 * @interface |
14 */ | 14 */ |
15 function PasswordManager() {} | 15 class PasswordManager { |
16 | |
17 /** @typedef {chrome.passwordsPrivate.PasswordUiEntry} */ | |
18 PasswordManager.PasswordUiEntry; | |
19 | |
20 /** @typedef {chrome.passwordsPrivate.LoginPair} */ | |
21 PasswordManager.LoginPair; | |
22 | |
23 /** @typedef {chrome.passwordsPrivate.ExceptionEntry} */ | |
24 PasswordManager.ExceptionEntry; | |
25 | |
26 /** @typedef {chrome.passwordsPrivate.PlaintextPasswordEventParameters} */ | |
27 PasswordManager.PlaintextPasswordEvent; | |
28 | |
29 PasswordManager.prototype = { | |
30 /** | 16 /** |
31 * Add an observer to the list of saved passwords. | 17 * Add an observer to the list of saved passwords. |
32 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener | 18 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener |
33 */ | 19 */ |
34 addSavedPasswordListChangedListener: assertNotReached, | 20 addSavedPasswordListChangedListener(listener) {} |
35 | 21 |
36 /** | 22 /** |
37 * Remove an observer from the list of saved passwords. | 23 * Remove an observer from the list of saved passwords. |
38 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener | 24 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener |
39 */ | 25 */ |
40 removeSavedPasswordListChangedListener: assertNotReached, | 26 removeSavedPasswordListChangedListener(listener) {} |
41 | 27 |
42 /** | 28 /** |
43 * Request the list of saved passwords. | 29 * Request the list of saved passwords. |
44 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} callback | 30 * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} callback |
45 */ | 31 */ |
46 getSavedPasswordList: assertNotReached, | 32 getSavedPasswordList(callback) {} |
47 | 33 |
48 /** | 34 /** |
49 * Should remove the saved password and notify that the list has changed. | 35 * Should remove the saved password and notify that the list has changed. |
50 * @param {!PasswordManager.LoginPair} loginPair The saved password that | 36 * @param {!PasswordManager.LoginPair} loginPair The saved password that |
51 * should be removed from the list. No-op if |loginPair| is not found. | 37 * should be removed from the list. No-op if |loginPair| is not found. |
52 */ | 38 */ |
53 removeSavedPassword: assertNotReached, | 39 removeSavedPassword(loginPair) {} |
54 | 40 |
55 /** | 41 /** |
56 * Add an observer to the list of password exceptions. | 42 * Add an observer to the list of password exceptions. |
57 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener | 43 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener |
58 */ | 44 */ |
59 addExceptionListChangedListener: assertNotReached, | 45 addExceptionListChangedListener(listener) {} |
60 | 46 |
61 /** | 47 /** |
62 * Remove an observer from the list of password exceptions. | 48 * Remove an observer from the list of password exceptions. |
63 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener | 49 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} listener |
64 */ | 50 */ |
65 removeExceptionListChangedListener: assertNotReached, | 51 removeExceptionListChangedListener(listener) {} |
66 | 52 |
67 /** | 53 /** |
68 * Request the list of password exceptions. | 54 * Request the list of password exceptions. |
69 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} callback | 55 * @param {function(!Array<!PasswordManager.ExceptionEntry>):void} callback |
70 */ | 56 */ |
71 getExceptionList: assertNotReached, | 57 getExceptionList(callback) {} |
72 | 58 |
73 /** | 59 /** |
74 * Should remove the password exception and notify that the list has changed. | 60 * Should remove the password exception and notify that the list has changed. |
75 * @param {string} exception The exception that should be removed from the | 61 * @param {string} exception The exception that should be removed from the |
76 * list. No-op if |exception| is not in the list. | 62 * list. No-op if |exception| is not in the list. |
77 */ | 63 */ |
78 removeException: assertNotReached, | 64 removeException(exception) {} |
79 | 65 |
80 /** | 66 /** |
81 * Gets the saved password for a given login pair. | 67 * Gets the saved password for a given login pair. |
82 * @param {!PasswordManager.LoginPair} loginPair The saved password that | 68 * @param {!PasswordManager.LoginPair} loginPair The saved password that |
83 * should be retrieved. | 69 * should be retrieved. |
84 * @param {function(!PasswordManager.PlaintextPasswordEvent):void} callback | 70 * @param {function(!PasswordManager.PlaintextPasswordEvent):void} callback |
85 */ | 71 */ |
86 getPlaintextPassword: assertNotReached, | 72 getPlaintextPassword(loginPair, callback) {} |
87 }; | 73 } |
| 74 |
| 75 /** @typedef {chrome.passwordsPrivate.PasswordUiEntry} */ |
| 76 PasswordManager.PasswordUiEntry; |
| 77 |
| 78 /** @typedef {chrome.passwordsPrivate.LoginPair} */ |
| 79 PasswordManager.LoginPair; |
| 80 |
| 81 /** @typedef {chrome.passwordsPrivate.ExceptionEntry} */ |
| 82 PasswordManager.ExceptionEntry; |
| 83 |
| 84 /** @typedef {chrome.passwordsPrivate.PlaintextPasswordEventParameters} */ |
| 85 PasswordManager.PlaintextPasswordEvent; |
88 | 86 |
89 /** | 87 /** |
90 * Implementation that accesses the private API. | 88 * Implementation that accesses the private API. |
91 * @implements {PasswordManager} | 89 * @implements {PasswordManager} |
92 * @constructor | |
93 */ | 90 */ |
94 function PasswordManagerImpl() {} | 91 class PasswordManagerImpl { |
95 cr.addSingletonGetter(PasswordManagerImpl); | 92 /** @override */ |
96 | 93 addSavedPasswordListChangedListener(listener) { |
97 PasswordManagerImpl.prototype = { | 94 chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener); |
98 __proto__: PasswordManager, | 95 } |
99 | 96 |
100 /** @override */ | 97 /** @override */ |
101 addSavedPasswordListChangedListener: function(listener) { | 98 removeSavedPasswordListChangedListener(listener) { |
102 chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener); | 99 chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener( |
103 }, | 100 listener); |
| 101 } |
104 | 102 |
105 /** @override */ | 103 /** @override */ |
106 removeSavedPasswordListChangedListener: function(listener) { | 104 getSavedPasswordList(callback) { |
107 chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener( | 105 chrome.passwordsPrivate.getSavedPasswordList(callback); |
108 listener); | 106 } |
109 }, | |
110 | 107 |
111 /** @override */ | 108 /** @override */ |
112 getSavedPasswordList: function(callback) { | 109 removeSavedPassword(loginPair) { |
113 chrome.passwordsPrivate.getSavedPasswordList(callback); | 110 chrome.passwordsPrivate.removeSavedPassword(loginPair); |
114 }, | 111 } |
115 | 112 |
116 /** @override */ | 113 /** @override */ |
117 removeSavedPassword: function(loginPair) { | 114 addExceptionListChangedListener(listener) { |
118 chrome.passwordsPrivate.removeSavedPassword(loginPair); | 115 chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener( |
119 }, | 116 listener); |
| 117 } |
120 | 118 |
121 /** @override */ | 119 /** @override */ |
122 addExceptionListChangedListener: function(listener) { | 120 removeExceptionListChangedListener(listener) { |
123 chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener( | 121 chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener( |
124 listener); | 122 listener); |
125 }, | 123 } |
126 | 124 |
127 /** @override */ | 125 /** @override */ |
128 removeExceptionListChangedListener: function(listener) { | 126 getExceptionList(callback) { |
129 chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener( | 127 chrome.passwordsPrivate.getPasswordExceptionList(callback); |
130 listener); | 128 } |
131 }, | |
132 | 129 |
133 /** @override */ | 130 /** @override */ |
134 getExceptionList: function(callback) { | 131 removeException(exception) { |
135 chrome.passwordsPrivate.getPasswordExceptionList(callback); | 132 chrome.passwordsPrivate.removePasswordException(exception); |
136 }, | 133 } |
137 | 134 |
138 /** @override */ | 135 /** @override */ |
139 removeException: function(exception) { | 136 getPlaintextPassword(loginPair, callback) { |
140 chrome.passwordsPrivate.removePasswordException(exception); | |
141 }, | |
142 | |
143 /** @override */ | |
144 getPlaintextPassword: function(loginPair, callback) { | |
145 var listener = function(reply) { | 137 var listener = function(reply) { |
146 // Only handle the reply for our loginPair request. | 138 // Only handle the reply for our loginPair request. |
147 if (reply.loginPair.urls.origin == loginPair.urls.origin && | 139 if (reply.loginPair.urls.origin == loginPair.urls.origin && |
148 reply.loginPair.username == loginPair.username) { | 140 reply.loginPair.username == loginPair.username) { |
149 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.removeListener( | 141 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.removeListener( |
150 listener); | 142 listener); |
151 callback(reply); | 143 callback(reply); |
152 } | 144 } |
153 }; | 145 }; |
154 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(listener); | 146 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(listener); |
155 chrome.passwordsPrivate.requestPlaintextPassword(loginPair); | 147 chrome.passwordsPrivate.requestPlaintextPassword(loginPair); |
156 }, | 148 } |
157 }; | 149 } |
| 150 |
| 151 cr.addSingletonGetter(PasswordManagerImpl); |
158 | 152 |
159 /** @typedef {!{model: !{item: !chrome.passwordsPrivate.PasswordUiEntry}}} */ | 153 /** @typedef {!{model: !{item: !chrome.passwordsPrivate.PasswordUiEntry}}} */ |
160 var PasswordUiEntryEvent; | 154 var PasswordUiEntryEvent; |
161 | 155 |
162 /** @typedef {!{model: !{item: !chrome.passwordsPrivate.ExceptionEntry}}} */ | 156 /** @typedef {!{model: !{item: !chrome.passwordsPrivate.ExceptionEntry}}} */ |
163 var ExceptionEntryEntryEvent; | 157 var ExceptionEntryEntryEvent; |
164 | 158 |
165 (function() { | 159 (function() { |
166 'use strict'; | 160 'use strict'; |
167 | 161 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 /** | 394 /** |
401 * @private | 395 * @private |
402 * @param {boolean} toggleValue | 396 * @param {boolean} toggleValue |
403 * @return {string} | 397 * @return {string} |
404 */ | 398 */ |
405 getOnOffLabel_: function(toggleValue) { | 399 getOnOffLabel_: function(toggleValue) { |
406 return toggleValue ? this.i18n('toggleOn') : this.i18n('toggleOff'); | 400 return toggleValue ? this.i18n('toggleOn') : this.i18n('toggleOff'); |
407 } | 401 } |
408 }); | 402 }); |
409 })(); | 403 })(); |
OLD | NEW |