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

Side by Side Diff: chrome/browser/resources/options/password_manager.js

Issue 489103004: Allow editing passwords in settings/passwords (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a type mismatch in password_manager.js Created 6 years, 3 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 unified diff | Download patch
OLDNEW
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
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
58 /** @override */ 65 /** @override */
59 initializePage: function() { 66 initializePage: function() {
60 Page.prototype.initializePage.call(this); 67 Page.prototype.initializePage.call(this);
61 68
62 $('password-manager-confirm').onclick = function() { 69 $('password-manager-confirm').onclick = function() {
63 PageManager.closeOverlay(); 70 PageManager.closeOverlay();
64 }; 71 };
65 72
66 $('password-search-box').addEventListener('search', 73 $('password-search-box').addEventListener('search',
67 this.handleSearchQueryChange_.bind(this)); 74 this.handleSearchQueryChange_.bind(this));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 list.hidden = empty; 158 list.hidden = empty;
152 $(listPlaceHolderID).hidden = !empty; 159 $(listPlaceHolderID).hidden = !empty;
153 }, 160 },
154 161
155 /** 162 /**
156 * Updates the data model for the saved passwords list with the values from 163 * Updates the data model for the saved passwords list with the values from
157 * |entries|. 164 * |entries|.
158 * @param {!Array} entries The list of saved password data. 165 * @param {!Array} entries The list of saved password data.
159 */ 166 */
160 setSavedPasswordsList_: function(entries) { 167 setSavedPasswordsList_: function(entries) {
168 this.filterIsActive_ = !!this.lastQuery_;
161 if (this.lastQuery_) { 169 if (this.lastQuery_) {
162 // Implement password searching here in javascript, rather than in C++. 170 // Implement password searching here in javascript, rather than in C++.
163 // The number of saved passwords shouldn't be too big for us to handle. 171 // The number of saved passwords shouldn't be too big for us to handle.
164 var query = this.lastQuery_; 172 var query = this.lastQuery_;
165 var filter = function(entry, index, list) { 173 var filter = function(entry, index, list) {
166 // Search both URL and username. 174 // Search both URL and username.
167 if (entry[0].toLowerCase().indexOf(query.toLowerCase()) >= 0 || 175 if (entry[0].toLowerCase().indexOf(query.toLowerCase()) >= 0 ||
168 entry[1].toLowerCase().indexOf(query.toLowerCase()) >= 0) { 176 entry[1].toLowerCase().indexOf(query.toLowerCase()) >= 0) {
169 // Keep the original index so we can delete correctly. See also 177 // Keep the original index so we can delete correctly. See also
170 // deleteItemAtIndex() in password_manager_list.js that uses this. 178 // deleteItemAtIndex() in password_manager_list.js that uses this.
171 entry[3] = index; 179 entry[3] = index;
172 return true; 180 return true;
173 } 181 }
174 return false; 182 return false;
175 }; 183 };
176 entries = entries.filter(filter); 184 entries = entries.filter(filter);
185 } else {
186 // Adds the Add New Entry row.
187 entries.push(null);
177 } 188 }
178 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); 189 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries);
179 this.updateListVisibility_(this.savedPasswordsList_); 190 this.updateListVisibility_(this.savedPasswordsList_);
180 }, 191 },
181 192
182 /** 193 /**
183 * Updates the data model for the password exceptions list with the values 194 * Updates the data model for the password exceptions list with the values
184 * from |entries|. 195 * from |entries|.
185 * @param {!Array} entries The list of password exception data. 196 * @param {!Array} entries The list of password exception data.
186 */ 197 */
187 setPasswordExceptionsList_: function(entries) { 198 setPasswordExceptionsList_: function(entries) {
188 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); 199 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries);
189 this.updateListVisibility_(this.passwordExceptionsList_); 200 this.updateListVisibility_(this.passwordExceptionsList_);
190 }, 201 },
191 202
192 /** 203 /**
193 * Reveals the password for a saved password entry. This is called by the 204 * Reveals the password for a saved password entry. This is called by the
194 * backend after it has authenticated the user. 205 * backend after it has authenticated the user.
195 * @param {number} index The original index of the entry in the model. 206 * @param {number} index The original index of the entry in the model.
196 * @param {string} password The saved password. 207 * @param {string} password The saved password.
197 */ 208 */
198 showPassword_: function(index, password) { 209 showPassword_: function(index, password) {
199 var model = this.savedPasswordsList_.dataModel; 210 var model = this.savedPasswordsList_.dataModel;
200 if (this.lastQuery_) { 211 if (this.filterIsActive_) {
201 // When a filter is active, |index| does not represent the current 212 // When a filter is active, |index| does not represent the current
202 // index in the model, but each entry stores its original index, so 213 // index in the model, but each entry stores its original index, so
203 // we can find the item using a linear search. 214 // we can find the item using a linear search.
204 for (var i = 0; i < model.length; ++i) { 215 for (var i = 0; i < model.length; ++i) {
205 if (model.item(i)[3] == index) { 216 if (model.item(i)[3] == index) {
206 index = i; 217 index = i;
207 break; 218 break;
208 } 219 }
209 } 220 }
210 } 221 }
211 222
212 // Reveal the password in the UI. 223 // Reveal the password in the UI.
213 var item = this.savedPasswordsList_.getListItemByIndex(index); 224 var item = this.savedPasswordsList_.getListItemByIndex(index);
214 item.showPassword(password); 225 item.showPassword(password);
215 }, 226 },
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 },
216 }; 246 };
217 247
218 /** 248 /**
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 /**
219 * Removes a saved password. 277 * Removes a saved password.
220 * @param {number} rowIndex indicating the row to remove. 278 * @param {number} rowIndex indicating the row to remove.
221 */ 279 */
222 PasswordManager.removeSavedPassword = function(rowIndex) { 280 PasswordManager.removeSavedPassword = function(rowIndex) {
223 chrome.send('removeSavedPassword', [String(rowIndex)]); 281 chrome.send('removeSavedPassword', [String(rowIndex)]);
224 }; 282 };
225 283
226 /** 284 /**
227 * Removes a password exception. 285 * Removes a password exception.
228 * @param {number} rowIndex indicating the row to remove. 286 * @param {number} rowIndex indicating the row to remove.
229 */ 287 */
230 PasswordManager.removePasswordException = function(rowIndex) { 288 PasswordManager.removePasswordException = function(rowIndex) {
231 chrome.send('removePasswordException', [String(rowIndex)]); 289 chrome.send('removePasswordException', [String(rowIndex)]);
232 }; 290 };
233 291
234 PasswordManager.requestShowPassword = function(index) { 292 PasswordManager.requestShowPassword = function(index) {
235 chrome.send('requestShowPassword', [index]); 293 chrome.send('requestShowPassword', [index]);
236 }; 294 };
237 295
238 // Forward public APIs to private implementations on the singleton instance. 296 // Forward public APIs to private implementations on the singleton instance.
239 cr.makePublic(PasswordManager, [ 297 cr.makePublic(PasswordManager, [
240 'setSavedPasswordsList', 298 'setSavedPasswordsList',
241 'setPasswordExceptionsList', 299 'setPasswordExceptionsList',
242 'showPassword' 300 'showPassword',
301 'originValidityCheckComplete'
243 ]); 302 ]);
244 303
245 // Export 304 // Export
246 return { 305 return {
247 PasswordManager: PasswordManager 306 PasswordManager: PasswordManager
248 }; 307 };
249 308
250 }); 309 });
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/options/password_manager_list.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698