| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 | 6 const OptionsPage = options.OptionsPage; |
| 7 var OptionsPage = options.OptionsPage; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 8 | 9 |
| 9 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
| 10 // PasswordManager class: | 11 // PasswordManager class: |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * Encapsulated handling of password and exceptions page. | 14 * Encapsulated handling of password and exceptions page. |
| 14 * @constructor | 15 * @constructor |
| 15 */ | 16 */ |
| 16 function PasswordManager() { | 17 function PasswordManager() { |
| 17 this.activeNavTab = null; | 18 this.activeNavTab = null; |
| 18 OptionsPage.call(this, | 19 OptionsPage.call(this, |
| 19 'passwordManager', | 20 'passwordManager', |
| 20 templateData.savedPasswordsTitle, | 21 templateData.passwordsTitle, |
| 21 'passwordManager'); | 22 'password-manager'); |
| 22 } | 23 } |
| 23 | 24 |
| 24 cr.addSingletonGetter(PasswordManager); | 25 cr.addSingletonGetter(PasswordManager); |
| 25 | 26 |
| 26 PasswordManager.prototype = { | 27 PasswordManager.prototype = { |
| 27 __proto__: OptionsPage.prototype, | 28 __proto__: OptionsPage.prototype, |
| 28 | 29 |
| 30 /** |
| 31 * The saved passwords list. |
| 32 * @type {DeletableItemList} |
| 33 * @private |
| 34 */ |
| 35 savedPasswordsList_: null, |
| 36 |
| 37 /** |
| 38 * The password exceptions list. |
| 39 * @type {DeletableItemList} |
| 40 * @private |
| 41 */ |
| 42 passwordExceptionsList_: null, |
| 43 |
| 29 initializePage: function() { | 44 initializePage: function() { |
| 30 OptionsPage.prototype.initializePage.call(this); | 45 OptionsPage.prototype.initializePage.call(this); |
| 31 | 46 |
| 32 options.passwordManager.PasswordsListArea.decorate($('passwordsArea')); | 47 this.createSavedPasswordsList_(); |
| 33 options.passwordManager.PasswordExceptionsListArea.decorate( | 48 this.createPasswordExceptionsList_(); |
| 34 $('passwordExceptionsArea')); | |
| 35 | 49 |
| 36 $('password-exceptions-nav-tab').onclick = function() { | 50 chrome.send('updatePasswordLists'); |
| 37 OptionsPage.showTab($('password-exceptions-nav-tab')); | |
| 38 passwordExceptionsList.redraw(); | |
| 39 } | |
| 40 }, | 51 }, |
| 41 | 52 |
| 42 setSavedPasswordsList_: function(entries) { | 53 /** |
| 43 savedPasswordsList.clear(); | 54 * Creates, decorates and initializes the saved passwords list. |
| 44 for (var i = 0; i < entries.length; i++) { | 55 * @private |
| 45 savedPasswordsList.addEntry(entries[i]); | 56 */ |
| 46 } | 57 createSavedPasswordsList_: function() { |
| 58 this.savedPasswordsList_ = $('saved-passwords-list'); |
| 59 options.passwordManager.PasswordsList.decorate(this.savedPasswordsList_); |
| 60 this.savedPasswordsList_.selectionModel = new ListSingleSelectionModel; |
| 61 this.savedPasswordsList_.autoExpands = true; |
| 47 }, | 62 }, |
| 48 | 63 |
| 49 setPasswordExceptionsList_: function(entries) { | 64 /** |
| 50 passwordExceptionsList.clear(); | 65 * Creates, decorates and initializes the password exceptions list. |
| 51 for (var i = 0; i < entries.length; i++) { | 66 * @private |
| 52 passwordExceptionsList.addEntry(entries[i]); | 67 */ |
| 53 } | 68 createPasswordExceptionsList_: function() { |
| 69 this.passwordExceptionsList_ = $('password-exceptions-list'); |
| 70 options.passwordManager.PasswordExceptionsList.decorate( |
| 71 this.passwordExceptionsList_); |
| 72 this.passwordExceptionsList_.selectionModel = |
| 73 new ListSingleSelectionModel; |
| 74 this.passwordExceptionsList_.autoExpands = true; |
| 54 }, | 75 }, |
| 55 | 76 |
| 56 }; | 77 /** |
| 78 * Updates the data model for the saved passwords list with the values from |
| 79 * |entries|. |
| 80 * @param {Array} entries The list of saved password data. |
| 81 */ |
| 82 setSavedPasswordsList_: function(entries) { |
| 83 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
| 84 }, |
| 57 | 85 |
| 58 PasswordManager.load = function() { | 86 /** |
| 59 chrome.send('loadLists'); | 87 * Updates the data model for the password exceptions list with the values |
| 88 * from |entries|. |
| 89 * @param {Array} entries The list of password exception data. |
| 90 */ |
| 91 setPasswordExceptionsList_: function(entries) { |
| 92 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
| 93 }, |
| 60 }; | 94 }; |
| 61 | 95 |
| 62 /** | 96 /** |
| 63 * Call to remove a saved password. | 97 * Call to remove a saved password. |
| 64 * @param rowIndex indicating the row to remove. | 98 * @param rowIndex indicating the row to remove. |
| 65 */ | 99 */ |
| 66 PasswordManager.removeSavedPassword = function(rowIndex) { | 100 PasswordManager.removeSavedPassword = function(rowIndex) { |
| 67 chrome.send('removeSavedPassword', [String(rowIndex)]); | 101 chrome.send('removeSavedPassword', [String(rowIndex)]); |
| 68 }; | 102 }; |
| 69 | 103 |
| 70 /** | 104 /** |
| 71 * Call to remove a password exception. | 105 * Call to remove a password exception. |
| 72 * @param rowIndex indicating the row to remove. | 106 * @param rowIndex indicating the row to remove. |
| 73 */ | 107 */ |
| 74 PasswordManager.removePasswordException = function(rowIndex) { | 108 PasswordManager.removePasswordException = function(rowIndex) { |
| 75 chrome.send('removePasswordException', [String(rowIndex)]); | 109 chrome.send('removePasswordException', [String(rowIndex)]); |
| 76 }; | 110 }; |
| 77 | 111 |
| 78 | |
| 79 /** | 112 /** |
| 80 * Call to remove all saved passwords. | 113 * Call to remove all saved passwords. |
| 81 * @param tab contentType of the tab currently on. | 114 * @param tab contentType of the tab currently on. |
| 82 */ | 115 */ |
| 83 PasswordManager.removeAllPasswords = function() { | 116 PasswordManager.removeAllPasswords = function() { |
| 84 chrome.send('removeAllSavedPasswords'); | 117 chrome.send('removeAllSavedPasswords'); |
| 85 }; | 118 }; |
| 86 | 119 |
| 87 /** | 120 /** |
| 88 * Call to remove all saved passwords. | 121 * Call to remove all saved passwords. |
| 89 * @param tab contentType of the tab currently on. | 122 * @param tab contentType of the tab currently on. |
| 90 */ | 123 */ |
| 91 PasswordManager.removeAllPasswordExceptions = function() { | 124 PasswordManager.removeAllPasswordExceptions = function() { |
| 92 chrome.send('removeAllPasswordExceptions'); | 125 chrome.send('removeAllPasswordExceptions'); |
| 93 }; | 126 }; |
| 94 | 127 |
| 95 PasswordManager.showSelectedPassword = function(index) { | |
| 96 chrome.send('showSelectedPassword', [String(index)]); | |
| 97 }; | |
| 98 | |
| 99 PasswordManager.setSavedPasswordsList = function(entries) { | 128 PasswordManager.setSavedPasswordsList = function(entries) { |
| 100 PasswordManager.getInstance().setSavedPasswordsList_(entries); | 129 PasswordManager.getInstance().setSavedPasswordsList_(entries); |
| 101 }; | 130 }; |
| 102 | 131 |
| 103 PasswordManager.setPasswordExceptionsList = function(entries) { | 132 PasswordManager.setPasswordExceptionsList = function(entries) { |
| 104 PasswordManager.getInstance().setPasswordExceptionsList_(entries); | 133 PasswordManager.getInstance().setPasswordExceptionsList_(entries); |
| 105 }; | 134 }; |
| 106 | 135 |
| 107 PasswordManager.selectedPasswordCallback = function(password) { | |
| 108 passwordsArea.displayReturnedPassword(password); | |
| 109 }; | |
| 110 | |
| 111 // Export | 136 // Export |
| 112 return { | 137 return { |
| 113 PasswordManager: PasswordManager | 138 PasswordManager: PasswordManager |
| 114 }; | 139 }; |
| 115 | 140 |
| 116 }); | 141 }); |
| 117 | 142 |
| OLD | NEW |