Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1818)

Unified Diff: chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js

Issue 2627123002: Load Passwords and Autofill in the corresponding sub page. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js
diff --git a/chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js b/chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js
index 42fe312f06222977b1e0f6357f1b4d19daa2ba2f..a70b96c77bc1387c2298b0b78c0adb73a9d43d6d 100644
--- a/chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js
+++ b/chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js
@@ -8,6 +8,154 @@
* save any passwords.
*/
+/**
+ * Interface for all callbacks to the password API.
+ * @interface
+ */
+function PasswordManager() {}
+
+/** @typedef {chrome.passwordsPrivate.PasswordUiEntry} */
+PasswordManager.PasswordUiEntry;
+
+/** @typedef {chrome.passwordsPrivate.LoginPair} */
+PasswordManager.LoginPair;
+
+/** @typedef {chrome.passwordsPrivate.ExceptionPair} */
+PasswordManager.ExceptionPair;
+
+/** @typedef {chrome.passwordsPrivate.PlaintextPasswordEventParameters} */
+PasswordManager.PlaintextPasswordEvent;
+
+PasswordManager.prototype = {
+ /**
+ * Add an observer to the list of saved passwords.
+ * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener
+ */
+ addSavedPasswordListChangedListener: assertNotReached,
+
+ /**
+ * Remove an observer from the list of saved passwords.
+ * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} listener
+ */
+ removeSavedPasswordListChangedListener: assertNotReached,
+
+ /**
+ * Request the list of saved passwords.
+ * @param {function(!Array<!PasswordManager.PasswordUiEntry>):void} callback
+ */
+ getSavedPasswordList: assertNotReached,
+
+ /**
+ * Should remove the saved password and notify that the list has changed.
+ * @param {!PasswordManager.LoginPair} loginPair The saved password that
+ * should be removed from the list. No-op if |loginPair| is not found.
+ */
+ removeSavedPassword: assertNotReached,
+
+ /**
+ * Add an observer to the list of password exceptions.
+ * @param {function(!Array<!PasswordManager.ExceptionPair>):void} listener
+ */
+ addExceptionListChangedListener: assertNotReached,
+
+ /**
+ * Remove an observer from the list of password exceptions.
+ * @param {function(!Array<!PasswordManager.ExceptionPair>):void} listener
+ */
+ removeExceptionListChangedListener: assertNotReached,
+
+ /**
+ * Request the list of password exceptions.
+ * @param {function(!Array<!PasswordManager.ExceptionPair>):void} callback
+ */
+ getExceptionList: assertNotReached,
+
+ /**
+ * Should remove the password exception and notify that the list has changed.
+ * @param {string} exception The exception that should be removed from the
+ * list. No-op if |exception| is not in the list.
+ */
+ removeException: assertNotReached,
+
+ /**
+ * Gets the saved password for a given login pair.
+ * @param {!PasswordManager.LoginPair} loginPair The saved password that
+ * should be retrieved.
+ * @param {function(!PasswordManager.PlaintextPasswordEvent):void} callback
+ */
+ getPlaintextPassword: assertNotReached,
+};
+
+/**
+ * Implementation that accesses the private API.
+ * @implements {PasswordManager}
+ * @constructor
+ */
+function PasswordManagerImpl() {}
+cr.addSingletonGetter(PasswordManagerImpl);
+
+PasswordManagerImpl.prototype = {
+ __proto__: PasswordManager,
+
+ /** @override */
+ addSavedPasswordListChangedListener: function(listener) {
+ chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener);
+ },
+
+ /** @override */
+ removeSavedPasswordListChangedListener: function(listener) {
+ chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener(
+ listener);
+ },
+
+ /** @override */
+ getSavedPasswordList: function(callback) {
+ chrome.passwordsPrivate.getSavedPasswordList(callback);
+ },
+
+ /** @override */
+ removeSavedPassword: function(loginPair) {
+ chrome.passwordsPrivate.removeSavedPassword(loginPair);
+ },
+
+ /** @override */
+ addExceptionListChangedListener: function(listener) {
+ chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener(
+ listener);
+ },
+
+ /** @override */
+ removeExceptionListChangedListener: function(listener) {
+ chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener(
+ listener);
+ },
+
+ /** @override */
+ getExceptionList: function(callback) {
+ chrome.passwordsPrivate.getPasswordExceptionList(callback);
+ },
+
+ /** @override */
+ removeException: function(exception) {
+ chrome.passwordsPrivate.removePasswordException(exception);
+ },
+
+ /** @override */
+ getPlaintextPassword: function(loginPair, callback) {
+ var listener = function(reply) {
+ // Only handle the reply for our loginPair request.
+ if (reply.loginPair.originUrl == loginPair.originUrl &&
+ reply.loginPair.username == loginPair.username) {
+ chrome.passwordsPrivate.onPlaintextPasswordRetrieved.removeListener(
+ listener);
+ callback(reply);
+ }
+ };
+ chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(listener);
+ chrome.passwordsPrivate.requestPlaintextPassword(loginPair);
+ },
+};
+
/** @typedef {!{model: !{item: !chrome.passwordsPrivate.PasswordUiEntry}}} */
var PasswordUiEntryEvent;
@@ -31,21 +179,15 @@ Polymer({
/**
* An array of passwords to display.
- * @type {!Array<!chrome.passwordsPrivate.PasswordUiEntry>}
+ * @type {!Array<!PasswordManager.PasswordUiEntry>}
*/
- savedPasswords: {
- type: Array,
- value: function() { return []; },
- },
+ savedPasswords: Array,
/**
* An array of sites to display.
- * @type {!Array<!chrome.passwordsPrivate.ExceptionPair>}
+ * @type {!Array<!PasswordManager.ExceptionPair>}
*/
- passwordExceptions: {
- type: Array,
- value: function() { return []; },
- },
+ passwordExceptions: Array,
/** @override */
subpageRoute: {
@@ -69,6 +211,66 @@ Polymer({
},
},
+ listeners: {
+ 'show-password': 'showPassword_',
+ },
+
+ /**
+ * @type {PasswordManager}
+ * @private
+ */
+ passwordManager_: null,
+
+ /**
+ * @type {?function(!Array<PasswordManager.PasswordUiEntry>):void}
+ * @private
+ */
+ setSavedPasswordsListener_: null,
+
+ /**
+ * @type {?function(!Array<PasswordManager.ExceptionPair>):void}
+ * @private
+ */
+ setPasswordExceptionsListener_: null,
+
+ /** @override */
+ ready: function() {
+ // Create listener functions.
+ var setSavedPasswordsListener = function(list) {
+ this.savedPasswords = list;
+ }.bind(this);
+
+ var setPasswordExceptionsListener = function(list) {
+ this.passwordExceptions = list;
+ }.bind(this);
+
+ this.setSavedPasswordsListener_ = setSavedPasswordsListener;
+ this.setPasswordExceptionsListener_ = setPasswordExceptionsListener;
+
+ // Set the manager. These can be overridden by tests.
+ this.passwordManager_ = PasswordManagerImpl.getInstance();
+
+ // Request initial data.
+ this.passwordManager_.getSavedPasswordList(setSavedPasswordsListener);
+ this.passwordManager_.getExceptionList(setPasswordExceptionsListener);
+
+ // Listen for changes.
+ this.passwordManager_.addSavedPasswordListChangedListener(
+ setSavedPasswordsListener);
+ this.passwordManager_.addExceptionListChangedListener(
+ setPasswordExceptionsListener);
+ },
+
+ /** @override */
+ detached: function() {
+ this.passwordManager_.removeSavedPasswordListChangedListener(
+ /** @type {function(!Array<PasswordManager.PasswordUiEntry>):void} */(
+ this.setSavedPasswordsListener_));
+ this.passwordManager_.removeExceptionListChangedListener(
+ /** @type {function(!Array<PasswordManager.ExceptionPair>):void} */(
+ this.setPasswordExceptionsListener_));
+ },
+
/**
* Sets the password in the current password dialog if the loginPair matches.
* @param {!chrome.passwordsPrivate.LoginPair} loginPair
@@ -130,7 +332,7 @@ Polymer({
* @private
*/
onMenuRemovePasswordTap_: function() {
- this.fire('remove-saved-password', this.activePassword.loginPair);
+ this.passwordManager_.removeSavedPassword(this.activePassword.loginPair);
/** @type {CrActionMenuElement} */(this.$.menu).close();
},
@@ -140,7 +342,7 @@ Polymer({
* @private
*/
onRemoveExceptionButtonTap_: function(e) {
- this.fire('remove-password-exception', e.model.item.exceptionUrl);
+ this.passwordManager_.removeException(e.model.item.exceptionUrl);
},
/**
@@ -175,5 +377,18 @@ Polymer({
hasSome_: function(list) {
return !!(list && list.length);
},
+
+ /**
+ * Listens for the show-password event, and calls the private API.
+ * @param {!Event} event
+ * @private
+ */
+ showPassword_: function(event) {
+ this.passwordManager_.getPlaintextPassword(
+ /** @type {!PasswordManager.LoginPair} */(event.detail),
+ function(item) {
+ this.setPassword(item.loginPair, item.plaintextPassword);
+ }.bind(this));
+ },
});
})();

Powered by Google App Engine
This is Rietveld 408576698