Chromium Code Reviews| Index: chrome/browser/resources/options/password_manager.js |
| diff --git a/chrome/browser/resources/options/password_manager.js b/chrome/browser/resources/options/password_manager.js |
| index 4758254538cf243d93e99601941836210b30514d..2f590af6730679351507b4c74408888c4ca85181 100644 |
| --- a/chrome/browser/resources/options/password_manager.js |
| +++ b/chrome/browser/resources/options/password_manager.js |
| @@ -54,6 +54,13 @@ cr.define('options', function() { |
| */ |
| lastQuery_: null, |
| + /** |
| + * Whether a search query filter is applied to the current data model. |
| + * @type {boolean} |
| + * @private |
| + */ |
| + filterIsActive_: false, |
| + |
| /** @override */ |
| initializePage: function() { |
| Page.prototype.initializePage.call(this); |
| @@ -153,6 +160,7 @@ cr.define('options', function() { |
| * @param {Array} entries The list of saved password data. |
| */ |
| setSavedPasswordsList_: function(entries) { |
| + this.filterIsActive_ = !!this.lastQuery_; |
| if (this.lastQuery_) { |
| // Implement password searching here in javascript, rather than in C++. |
| // The number of saved passwords shouldn't be too big for us to handle. |
| @@ -169,6 +177,9 @@ cr.define('options', function() { |
| return false; |
| }; |
| entries = entries.filter(filter); |
| + } else { |
| + // Adds the Add New Entry row. |
| + entries.push(null); |
| } |
| this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
| this.updateListVisibility_(this.savedPasswordsList_); |
| @@ -192,7 +203,7 @@ cr.define('options', function() { |
| */ |
| showPassword_: function(index, password) { |
| var model = this.savedPasswordsList_.dataModel; |
| - if (this.lastQuery_) { |
| + if (this.filterIsActive_) { |
| // When a filter is active, |index| does not represent the current |
| // index in the model, but each entry stores its original index, so |
| // we can find the item using a linear search. |
| @@ -208,6 +219,52 @@ cr.define('options', function() { |
| var item = this.savedPasswordsList_.getListItemByIndex(index); |
| item.showPassword(password); |
| }, |
| + |
| + /** |
| + * Forwards the validity of the origin to the Add New Entry row. |
| + * @param {string} url The origin. |
| + * @param {boolean} valid The validity of the origin for adding. |
| + * @private |
| + */ |
| + originValidityCheckComplete_: function(url, valid) { |
| + // There is no Add New Entry row when a filter is active. |
| + if (this.filterIsActive_) |
| + return; |
| + var model = this.savedPasswordsList_.dataModel; |
|
Dan Beam
2014/09/11 05:17:57
assert(model.length > 0);
jaekyeom
2014/09/12 10:35:57
Done.
|
| + // Since no filter is active, the Add New Entry row always exists and its |
| + // item is the last one. |
| + var addRowItem = this.savedPasswordsList_.getListItemByIndex( |
| + model.length - 1); |
| + addRowItem.originValidityCheckComplete(url, valid); |
| + }, |
| + }; |
| + |
| + /** |
| + * Requests the browser to check the validity of the origin being edited by |
| + * the user in the Add New Entry row. |
| + * @param {string} url The origin being edited. |
| + */ |
| + PasswordManager.checkOriginValidityForAdding = function(url) { |
| + chrome.send('checkOriginValidityForAdding', [url]); |
| + }; |
| + |
| + /** |
| + * Adds a new password entry. |
| + * @param {string} url The origin. |
| + * @param {string} username The username value. |
| + * @param {string} password The password value. |
| + */ |
| + PasswordManager.addPassword = function(url, username, password) { |
| + chrome.send('addPassword', [url, username, password]); |
| + }; |
| + |
| + /** |
| + * Updates the password value of an entry. |
| + * @param {number} rowIndex The row to update. |
| + * @param {string} newPassword The new password value. |
| + */ |
| + PasswordManager.updatePassword = function(rowIndex, newPassword) { |
| + chrome.send('updatePassword', [String(rowIndex), newPassword]); |
| }; |
| /** |
| @@ -234,7 +291,8 @@ cr.define('options', function() { |
| [ |
| 'setSavedPasswordsList', |
| 'setPasswordExceptionsList', |
| - 'showPassword' |
| + 'showPassword', |
| + 'originValidityCheckComplete' |
| ].forEach(function(name) { |
| PasswordManager[name] = function() { |
| var instance = PasswordManager.getInstance(); |