| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 | 9 |
| 10 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 */ | 47 */ |
| 48 queryDelayTimerId_: 0, | 48 queryDelayTimerId_: 0, |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * The most recent search query, or null if the query is empty. | 51 * The most recent search query, or null if the query is empty. |
| 52 * @type {?string} | 52 * @type {?string} |
| 53 * @private | 53 * @private |
| 54 */ | 54 */ |
| 55 lastQuery_: null, | 55 lastQuery_: null, |
| 56 | 56 |
| 57 /** |
| 58 * Whether a search query filter is applied to the current data model. |
| 59 * @type {boolean} |
| 60 * @private |
| 61 */ |
| 62 filterIsActive_: false, |
| 63 |
| 57 /** @override */ | 64 /** @override */ |
| 58 initializePage: function() { | 65 initializePage: function() { |
| 59 Page.prototype.initializePage.call(this); | 66 Page.prototype.initializePage.call(this); |
| 60 | 67 |
| 61 $('password-manager-confirm').onclick = function() { | 68 $('password-manager-confirm').onclick = function() { |
| 62 PageManager.closeOverlay(); | 69 PageManager.closeOverlay(); |
| 63 }; | 70 }; |
| 64 | 71 |
| 65 $('password-search-box').addEventListener('search', | 72 $('password-search-box').addEventListener('search', |
| 66 this.handleSearchQueryChange_.bind(this)); | 73 this.handleSearchQueryChange_.bind(this)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 list.hidden = empty; | 153 list.hidden = empty; |
| 147 $(listPlaceHolderID).hidden = !empty; | 154 $(listPlaceHolderID).hidden = !empty; |
| 148 }, | 155 }, |
| 149 | 156 |
| 150 /** | 157 /** |
| 151 * Updates the data model for the saved passwords list with the values from | 158 * Updates the data model for the saved passwords list with the values from |
| 152 * |entries|. | 159 * |entries|. |
| 153 * @param {Array} entries The list of saved password data. | 160 * @param {Array} entries The list of saved password data. |
| 154 */ | 161 */ |
| 155 setSavedPasswordsList_: function(entries) { | 162 setSavedPasswordsList_: function(entries) { |
| 163 this.filterIsActive_ = !!this.lastQuery_; |
| 156 if (this.lastQuery_) { | 164 if (this.lastQuery_) { |
| 157 // Implement password searching here in javascript, rather than in C++. | 165 // Implement password searching here in javascript, rather than in C++. |
| 158 // The number of saved passwords shouldn't be too big for us to handle. | 166 // The number of saved passwords shouldn't be too big for us to handle. |
| 159 var query = this.lastQuery_; | 167 var query = this.lastQuery_; |
| 160 var filter = function(entry, index, list) { | 168 var filter = function(entry, index, list) { |
| 161 // Search both URL and username. | 169 // Search both URL and username. |
| 162 if (entry[0].toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 170 if (entry[0].toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
| 163 entry[1].toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 171 entry[1].toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
| 164 // Keep the original index so we can delete correctly. See also | 172 // Keep the original index so we can delete correctly. See also |
| 165 // deleteItemAtIndex() in password_manager_list.js that uses this. | 173 // deleteItemAtIndex() in password_manager_list.js that uses this. |
| 166 entry[3] = index; | 174 entry[3] = index; |
| 167 return true; | 175 return true; |
| 168 } | 176 } |
| 169 return false; | 177 return false; |
| 170 }; | 178 }; |
| 171 entries = entries.filter(filter); | 179 entries = entries.filter(filter); |
| 180 } else { |
| 181 // Adds the Add New Entry row. |
| 182 entries.push(null); |
| 172 } | 183 } |
| 173 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 184 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
| 174 this.updateListVisibility_(this.savedPasswordsList_); | 185 this.updateListVisibility_(this.savedPasswordsList_); |
| 175 }, | 186 }, |
| 176 | 187 |
| 177 /** | 188 /** |
| 178 * Updates the data model for the password exceptions list with the values | 189 * Updates the data model for the password exceptions list with the values |
| 179 * from |entries|. | 190 * from |entries|. |
| 180 * @param {Array} entries The list of password exception data. | 191 * @param {Array} entries The list of password exception data. |
| 181 */ | 192 */ |
| 182 setPasswordExceptionsList_: function(entries) { | 193 setPasswordExceptionsList_: function(entries) { |
| 183 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 194 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
| 184 this.updateListVisibility_(this.passwordExceptionsList_); | 195 this.updateListVisibility_(this.passwordExceptionsList_); |
| 185 }, | 196 }, |
| 186 | 197 |
| 187 /** | 198 /** |
| 188 * Reveals the password for a saved password entry. This is called by the | 199 * Reveals the password for a saved password entry. This is called by the |
| 189 * backend after it has authenticated the user. | 200 * backend after it has authenticated the user. |
| 190 * @param {number} index The original index of the entry in the model. | 201 * @param {number} index The original index of the entry in the model. |
| 191 * @param {string} password The saved password. | 202 * @param {string} password The saved password. |
| 192 */ | 203 */ |
| 193 showPassword_: function(index, password) { | 204 showPassword_: function(index, password) { |
| 194 var model = this.savedPasswordsList_.dataModel; | 205 var model = this.savedPasswordsList_.dataModel; |
| 195 if (this.lastQuery_) { | 206 if (this.filterIsActive_) { |
| 196 // When a filter is active, |index| does not represent the current | 207 // When a filter is active, |index| does not represent the current |
| 197 // index in the model, but each entry stores its original index, so | 208 // index in the model, but each entry stores its original index, so |
| 198 // we can find the item using a linear search. | 209 // we can find the item using a linear search. |
| 199 for (var i = 0; i < model.length; ++i) { | 210 for (var i = 0; i < model.length; ++i) { |
| 200 if (model.item(i)[3] == index) { | 211 if (model.item(i)[3] == index) { |
| 201 index = i; | 212 index = i; |
| 202 break; | 213 break; |
| 203 } | 214 } |
| 204 } | 215 } |
| 205 } | 216 } |
| 206 | 217 |
| 207 // Reveal the password in the UI. | 218 // Reveal the password in the UI. |
| 208 var item = this.savedPasswordsList_.getListItemByIndex(index); | 219 var item = this.savedPasswordsList_.getListItemByIndex(index); |
| 209 item.showPassword(password); | 220 item.showPassword(password); |
| 210 }, | 221 }, |
| 222 |
| 223 /** |
| 224 * Forwards the validity of the origin to the Add New Entry row. |
| 225 * @param {string} url The origin. |
| 226 * @param {boolean} valid The validity of the origin for adding. |
| 227 * @private |
| 228 */ |
| 229 originValidityCheckComplete_: function(url, valid) { |
| 230 // There is no Add New Entry row when a filter is active. |
| 231 if (this.filterIsActive_) |
| 232 return; |
| 233 // Since no filter is active, the Add New Entry row always exists and its |
| 234 // item is the last one. |
| 235 assert(this.savedPasswordsList_.length > 0); |
| 236 var addRowItem = this.savedPasswordsList_.getListItemByIndex( |
| 237 this.savedPasswordsList_.length - 1); |
| 238 addRowItem.originValidityCheckComplete(url, valid); |
| 239 }, |
| 211 }; | 240 }; |
| 212 | 241 |
| 213 /** | 242 /** |
| 243 * Requests the browser to check the validity of the origin being edited by |
| 244 * the user in the Add New Entry row. |
| 245 * @param {string} url The origin being edited. |
| 246 */ |
| 247 PasswordManager.checkOriginValidityForAdding = function(url) { |
| 248 chrome.send('checkOriginValidityForAdding', [url]); |
| 249 }; |
| 250 |
| 251 /** |
| 252 * Adds a new password entry. |
| 253 * @param {string} url The origin. |
| 254 * @param {string} username The username value. |
| 255 * @param {string} password The password value. |
| 256 */ |
| 257 PasswordManager.addPassword = function(url, username, password) { |
| 258 chrome.send('addPassword', [url, username, password]); |
| 259 }; |
| 260 |
| 261 /** |
| 262 * Updates the password value of an entry. |
| 263 * @param {number} rowIndex The row to update. |
| 264 * @param {string} newPassword The new password value. |
| 265 */ |
| 266 PasswordManager.updatePassword = function(rowIndex, newPassword) { |
| 267 chrome.send('updatePassword', [String(rowIndex), newPassword]); |
| 268 }; |
| 269 |
| 270 /** |
| 214 * Removes a saved password. | 271 * Removes a saved password. |
| 215 * @param {number} rowIndex indicating the row to remove. | 272 * @param {number} rowIndex indicating the row to remove. |
| 216 */ | 273 */ |
| 217 PasswordManager.removeSavedPassword = function(rowIndex) { | 274 PasswordManager.removeSavedPassword = function(rowIndex) { |
| 218 chrome.send('removeSavedPassword', [String(rowIndex)]); | 275 chrome.send('removeSavedPassword', [String(rowIndex)]); |
| 219 }; | 276 }; |
| 220 | 277 |
| 221 /** | 278 /** |
| 222 * Removes a password exception. | 279 * Removes a password exception. |
| 223 * @param {number} rowIndex indicating the row to remove. | 280 * @param {number} rowIndex indicating the row to remove. |
| 224 */ | 281 */ |
| 225 PasswordManager.removePasswordException = function(rowIndex) { | 282 PasswordManager.removePasswordException = function(rowIndex) { |
| 226 chrome.send('removePasswordException', [String(rowIndex)]); | 283 chrome.send('removePasswordException', [String(rowIndex)]); |
| 227 }; | 284 }; |
| 228 | 285 |
| 229 PasswordManager.requestShowPassword = function(index) { | 286 PasswordManager.requestShowPassword = function(index) { |
| 230 chrome.send('requestShowPassword', [index]); | 287 chrome.send('requestShowPassword', [index]); |
| 231 }; | 288 }; |
| 232 | 289 |
| 233 // Forward public APIs to private implementations on the singleton instance. | 290 // Forward public APIs to private implementations on the singleton instance. |
| 234 [ | 291 [ |
| 235 'setSavedPasswordsList', | 292 'setSavedPasswordsList', |
| 236 'setPasswordExceptionsList', | 293 'setPasswordExceptionsList', |
| 237 'showPassword' | 294 'showPassword', |
| 295 'originValidityCheckComplete' |
| 238 ].forEach(function(name) { | 296 ].forEach(function(name) { |
| 239 PasswordManager[name] = function() { | 297 PasswordManager[name] = function() { |
| 240 var instance = PasswordManager.getInstance(); | 298 var instance = PasswordManager.getInstance(); |
| 241 return instance[name + '_'].apply(instance, arguments); | 299 return instance[name + '_'].apply(instance, arguments); |
| 242 }; | 300 }; |
| 243 }); | 301 }); |
| 244 | 302 |
| 245 // Export | 303 // Export |
| 246 return { | 304 return { |
| 247 PasswordManager: PasswordManager | 305 PasswordManager: PasswordManager |
| 248 }; | 306 }; |
| 249 | 307 |
| 250 }); | 308 }); |
| OLD | NEW |