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