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

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

Issue 1318523011: [Password Manager] Copiable username and origin. Linkable origin elided from the left. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Icons appearance fixed Created 5 years, 2 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.passwordManager', function() { 5 cr.define('options.passwordManager', function() {
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
7 /** @const */ var DeletableItemList = options.DeletableItemList; 7 /** @const */ var DeletableItemList = options.DeletableItemList;
8 /** @const */ var DeletableItem = options.DeletableItem; 8 /** @const */ var DeletableItem = options.DeletableItem;
9 /** @const */ var List = cr.ui.List; 9 /** @const */ var List = cr.ui.List;
10 10
11 /** @const */ var URL_DATA_INDEX = 0; 11 // The following constants should be synchronized with the constants in
12 /** @const */ var USERNAME_DATA_INDEX = 1; 12 // chrome/browser/ui/webui/options/password_manager_handler.cc.
13 /** @const */ var PASSWORD_DATA_INDEX = 2; 13 /** @const */ var ORIGIN_FIELD = 'origin';
14 /** @const */ var FEDERATION_DATA_INDEX = 3; 14 /** @const */ var SHOWN_URL_FIELD = 'shownUrl';
15 /** @const */ var ORIGINAL_DATA_INDEX = 4; 15 /** @const */ var IS_SECURE_FIELD = 'isSecure';
16 /** @const */ var USERNAME_FIELD = 'username';
17 /** @const */ var PASSWORD_FIELD = 'password';
18 /** @const */ var FEDERATION_FIELD = 'federation';
19 /** @const */ var ORIGINAL_INDEX_FIELD = 'index';
16 20
17 /** 21 /**
18 * Creates a new passwords list item. 22 * Creates a new passwords list item.
19 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this 23 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this
20 * item. 24 * item.
21 * @param {Array} entry An array of the form [url, username, password, 25 * @param {Array} entry An array of the form [url, username, password,
22 * federation]. When the list has been filtered, a fifth element [index] 26 * federation]. When the list has been filtered, a fifth element [index]
23 * may be present. 27 * may be present.
24 * @param {boolean} showPasswords If true, add a button to the element to 28 * @param {boolean} showPasswords If true, add a button to the element to
25 * allow the user to reveal the saved password. 29 * allow the user to reveal the saved password.
(...skipping 12 matching lines...) Expand all
38 } 42 }
39 43
40 PasswordListItem.prototype = { 44 PasswordListItem.prototype = {
41 __proto__: DeletableItem.prototype, 45 __proto__: DeletableItem.prototype,
42 46
43 /** @override */ 47 /** @override */
44 decorate: function() { 48 decorate: function() {
45 DeletableItem.prototype.decorate.call(this); 49 DeletableItem.prototype.decorate.call(this);
46 50
47 // The URL of the site. 51 // The URL of the site.
48 var urlLabel = this.ownerDocument.createElement('div'); 52 var urlDiv = this.ownerDocument.createElement('div');
49 urlLabel.classList.add('favicon-cell'); 53 urlDiv.className = 'favicon-cell left-elided-url url';
50 urlLabel.classList.add('weakrtl'); 54 urlDiv.setAttribute('title', this.url);
51 urlLabel.classList.add('url'); 55 var urlLink = this.ownerDocument.createElement('a');
52 urlLabel.setAttribute('title', this.url); 56 urlLink.href = this.url;
53 urlLabel.textContent = this.url; 57 urlLink.textContent = this.shownUrl.split('').reverse().join('');
54 58 urlDiv.appendChild(urlLink);
55 // The favicon URL is prefixed with "origin/", which essentially removes 59 urlDiv.style.backgroundImage =
56 // the URL path past the top-level domain and ensures that a scheme (e.g., 60 getIconBasedOnUrlSecurity(this.url, this.isUrlSecure);
57 // http) is being used. This ensures that the favicon returned is the 61 this.contentElement.appendChild(urlDiv);
58 // default favicon for the domain and that the URL has a scheme if none
59 // is present in the password manager.
60 urlLabel.style.backgroundImage = getFaviconImageSet(
61 'origin/' + this.url, 16);
62 this.contentElement.appendChild(urlLabel);
63 62
64 // The stored username. 63 // The stored username.
65 var usernameLabel = this.ownerDocument.createElement('div'); 64 var usernameDiv = this.ownerDocument.createElement('div');
66 usernameLabel.className = 'name'; 65 usernameDiv.className = 'name';
67 usernameLabel.textContent = this.username; 66 usernameDiv.title = this.username;
68 usernameLabel.title = this.username; 67 this.contentElement.appendChild(usernameDiv);
69 this.contentElement.appendChild(usernameLabel); 68 var usernameInput = this.ownerDocument.createElement('input');
69 usernameInput.type = 'text';
70 usernameInput.className = 'inactive-item';
71 usernameInput.readOnly = true;
72 usernameInput.value = this.username;
73 usernameDiv.appendChild(usernameInput);
74 this.usernameField = usernameInput;
70 75
71 if (this.federation) { 76 if (this.federation) {
72 // The federation. 77 // The federation.
73 var federationDiv = this.ownerDocument.createElement('div'); 78 var federationDiv = this.ownerDocument.createElement('div');
74 federationDiv.className = 'federation'; 79 federationDiv.className = 'federation';
75 federationDiv.textContent = this.federation; 80 federationDiv.textContent = this.federation;
76 this.contentElement.appendChild(federationDiv); 81 this.contentElement.appendChild(federationDiv);
77 } else { 82 } else {
78 // The stored password. 83 // The stored password.
79 var passwordInputDiv = this.ownerDocument.createElement('div'); 84 var passwordInputDiv = this.ownerDocument.createElement('div');
80 passwordInputDiv.className = 'password'; 85 passwordInputDiv.className = 'password';
81 86
82 // The password input field. 87 // The password input field.
83 var passwordInput = this.ownerDocument.createElement('input'); 88 var passwordInput = this.ownerDocument.createElement('input');
84 passwordInput.type = 'password'; 89 passwordInput.type = 'password';
85 passwordInput.className = 'inactive-password'; 90 passwordInput.className = 'inactive-item';
86 passwordInput.readOnly = true; 91 passwordInput.readOnly = true;
87 passwordInput.value = this.showPasswords_ ? this.password : '********'; 92 passwordInput.value = this.showPasswords_ ? this.password : '********';
88 passwordInputDiv.appendChild(passwordInput); 93 passwordInputDiv.appendChild(passwordInput);
89 var deletableItem = this; 94 var deletableItem = this;
90 passwordInput.addEventListener('focus', function() { 95 passwordInput.addEventListener('focus', function() {
91 deletableItem.handleFocus(); 96 deletableItem.handleFocus();
92 }); 97 });
93 this.passwordField = passwordInput; 98 this.passwordField = passwordInput;
94 this.setFocusable_(false); 99 this.setFocusable_(false);
95 100
(...skipping 11 matching lines...) Expand all
107 event.stopPropagation(); 112 event.stopPropagation();
108 }, false); 113 }, false);
109 button.addEventListener('focus', function() { 114 button.addEventListener('focus', function() {
110 deletableItem.handleFocus(); 115 deletableItem.handleFocus();
111 }); 116 });
112 passwordInputDiv.appendChild(button); 117 passwordInputDiv.appendChild(button);
113 this.passwordShowButton = button; 118 this.passwordShowButton = button;
114 } 119 }
115 this.contentElement.appendChild(passwordInputDiv); 120 this.contentElement.appendChild(passwordInputDiv);
116 } 121 }
117
118 }, 122 },
119 123
120 /** @override */ 124 /** @override */
121 selectionChanged: function() { 125 selectionChanged: function() {
122 var input = this.passwordField; 126 var usernameInput = this.usernameField;
127 var passwordInput = this.passwordField;
123 var button = this.passwordShowButton; 128 var button = this.passwordShowButton;
124 // The button doesn't exist when passwords can't be shown. 129 // The button doesn't exist when passwords can't be shown.
125 if (!button) 130 if (!button)
126 return; 131 return;
127 132
128 if (this.selected) { 133 if (this.selected) {
129 input.classList.remove('inactive-password'); 134 usernameInput.classList.remove('inactive-item');
135 passwordInput.classList.remove('inactive-item');
130 this.setFocusable_(true); 136 this.setFocusable_(true);
131 button.hidden = false; 137 button.hidden = false;
132 input.focus(); 138 passwordInput.focus();
133 } else { 139 } else {
134 input.classList.add('inactive-password'); 140 usernameInput.classList.add('inactive-item');
141 passwordInput.classList.add('inactive-item');
135 this.setFocusable_(false); 142 this.setFocusable_(false);
136 button.hidden = true; 143 button.hidden = true;
137 } 144 }
138 }, 145 },
139 146
140 /** 147 /**
141 * Set the focusability of this row. 148 * Set the focusability of this row.
142 * @param {boolean} focusable 149 * @param {boolean} focusable
143 * @private 150 * @private
144 */ 151 */
(...skipping 24 matching lines...) Expand all
169 if (button) 176 if (button)
170 button.textContent = loadTimeData.getString('passwordShowButton'); 177 button.textContent = loadTimeData.getString('passwordShowButton');
171 }, 178 },
172 179
173 /** 180 /**
174 * Get the original index of this item in the data model. 181 * Get the original index of this item in the data model.
175 * @return {number} The index. 182 * @return {number} The index.
176 * @private 183 * @private
177 */ 184 */
178 getOriginalIndex_: function() { 185 getOriginalIndex_: function() {
179 var index = this.dataItem[ORIGINAL_DATA_INDEX]; 186 var index = this.dataItem[ORIGINAL_INDEX_FIELD];
180 return index ? index : this.dataModel.indexOf(this.dataItem); 187 return index ? index : this.dataModel.indexOf(this.dataItem);
181 }, 188 },
182 189
183 /** 190 /**
184 * On-click event handler. Swaps the type of the input field from password 191 * On-click event handler. Swaps the type of the input field from password
185 * to text and back. 192 * to text and back.
186 * @private 193 * @private
187 */ 194 */
188 onClick_: function(event) { 195 onClick_: function(event) {
189 if (this.passwordField.type == 'password') { 196 if (this.passwordField.type == 'password') {
190 // After the user is authenticated, showPassword() will be called. 197 // After the user is authenticated, showPassword() will be called.
191 PasswordManager.requestShowPassword(this.getOriginalIndex_()); 198 PasswordManager.requestShowPassword(this.getOriginalIndex_());
192 } else { 199 } else {
193 this.hidePassword(); 200 this.hidePassword();
194 } 201 }
195 }, 202 },
196 203
197 /** 204 /**
198 * Get and set the URL for the entry. 205 * Get and set the URL for the entry.
199 * @type {string} 206 * @type {string}
200 */ 207 */
201 get url() { 208 get url() {
202 return this.dataItem[URL_DATA_INDEX]; 209 return this.dataItem[ORIGIN_FIELD];
203 }, 210 },
204 set url(url) { 211 set url(url) {
205 this.dataItem[URL_DATA_INDEX] = url; 212 this.dataItem[ORIGIN_FIELD] = url;
206 }, 213 },
207 214
208 /** 215 /**
216 * Get and set the shown url for the entry.
217 * @type {string}
218 */
219 get shownUrl() {
220 return this.dataItem[SHOWN_URL_FIELD];
221 },
222 set shownUrl(shownUrl) {
223 this.dataItem[SHOWN_URL_FIELD] = shownUrl;
224 },
225
226 /**
227 * Get and set whether the origin uses secure scheme.
228 * @type {boolean}
229 */
230 get isUrlSecure() {
231 return this.dataItem[IS_SECURE_FIELD];
232 },
233 set isUrlSecure(isUrlSecure) {
234 this.dataItem[IS_SECURE_FIELD] = isUrlSecure;
235 },
236
237 /**
209 * Get and set the username for the entry. 238 * Get and set the username for the entry.
210 * @type {string} 239 * @type {string}
211 */ 240 */
212 get username() { 241 get username() {
213 return this.dataItem[USERNAME_DATA_INDEX]; 242 return this.dataItem[USERNAME_FIELD];
214 }, 243 },
215 set username(username) { 244 set username(username) {
216 this.dataItem[USERNAME_DATA_INDEX] = username; 245 this.dataItem[USERNAME_FIELD] = username;
217 }, 246 },
218 247
219 /** 248 /**
220 * Get and set the password for the entry. 249 * Get and set the password for the entry.
221 * @type {string} 250 * @type {string}
222 */ 251 */
223 get password() { 252 get password() {
224 return this.dataItem[PASSWORD_DATA_INDEX]; 253 return this.dataItem[PASSWORD_FIELD];
225 }, 254 },
226 set password(password) { 255 set password(password) {
227 this.dataItem[PASSWORD_DATA_INDEX] = password; 256 this.dataItem[PASSWORD_FIELD] = password;
228 }, 257 },
229 258
230 /** 259 /**
231 * Get and set the federation for the entry. 260 * Get and set the federation for the entry.
232 * @type {string} 261 * @type {string}
233 */ 262 */
234 get federation() { 263 get federation() {
235 return this.dataItem[FEDERATION_DATA_INDEX]; 264 return this.dataItem[FEDERATION_FIELD];
236 }, 265 },
237 set federation(federation) { 266 set federation(federation) {
238 this.dataItem[FEDERATION_DATA_INDEX] = federation; 267 this.dataItem[FEDERATION_FIELD] = federation;
239 }, 268 },
240 }; 269 };
241 270
242 /** 271 /**
243 * Creates a new PasswordExceptions list item. 272 * Creates a new PasswordExceptions list item.
244 * @param {Array} entry A pair of the form [url, username]. 273 * @param {Array} entry A pair of the form [url, username].
245 * @constructor 274 * @constructor
246 * @extends {options.DeletableItem} 275 * @extends {options.DeletableItem}
247 */ 276 */
248 function PasswordExceptionsListItem(entry) { 277 function PasswordExceptionsListItem(entry) {
249 var el = cr.doc.createElement('div'); 278 var el = cr.doc.createElement('div');
250 el.dataItem = entry; 279 el.dataItem = entry;
251 el.__proto__ = PasswordExceptionsListItem.prototype; 280 el.__proto__ = PasswordExceptionsListItem.prototype;
252 el.decorate(); 281 el.decorate();
253 282
254 return el; 283 return el;
255 } 284 }
256 285
257 PasswordExceptionsListItem.prototype = { 286 PasswordExceptionsListItem.prototype = {
258 __proto__: DeletableItem.prototype, 287 __proto__: DeletableItem.prototype,
259 288
260 /** 289 /**
261 * Call when an element is decorated as a list item. 290 * Call when an element is decorated as a list item.
262 */ 291 */
263 decorate: function() { 292 decorate: function() {
264 DeletableItem.prototype.decorate.call(this); 293 DeletableItem.prototype.decorate.call(this);
265 294
266 // The URL of the site. 295 // The URL of the site.
267 var urlLabel = this.ownerDocument.createElement('div'); 296 var urlDiv = this.ownerDocument.createElement('div');
268 urlLabel.className = 'url'; 297 urlDiv.className = 'url';
269 urlLabel.classList.add('favicon-cell'); 298 urlDiv.classList.add('favicon-cell');
270 urlLabel.classList.add('weakrtl'); 299 urlDiv.classList.add('left-elided-url');
271 urlLabel.textContent = this.url; 300 urlDiv.setAttribute('title', this.url);
272 301 var urlLink = this.ownerDocument.createElement('a');
273 // The favicon URL is prefixed with "origin/", which essentially removes 302 urlLink.href = this.url;
274 // the URL path past the top-level domain and ensures that a scheme (e.g., 303 urlLink.textContent = this.shownUrl.split('').reverse().join('');
275 // http) is being used. This ensures that the favicon returned is the 304 urlDiv.appendChild(urlLink);
276 // default favicon for the domain and that the URL has a scheme if none 305 urlDiv.style.backgroundImage =
277 // is present in the password manager. 306 getIconBasedOnUrlSecurity(this.url, this.isUrlSecure);
Evan Stade 2015/10/15 23:46:32 indent
kolos1 2015/10/16 14:19:25 Done.
278 urlLabel.style.backgroundImage = getFaviconImageSet( 307 this.contentElement.appendChild(urlDiv);
279 'origin/' + this.url, 16);
280 this.contentElement.appendChild(urlLabel);
281 }, 308 },
282 309
283 /** 310 /**
284 * Get the url for the entry. 311 * Get the url for the entry.
285 * @type {string} 312 * @type {string}
286 */ 313 */
287 get url() { 314 get url() {
288 return this.dataItem; 315 return this.dataItem[ORIGIN_FIELD];
289 }, 316 },
290 set url(url) { 317 set url(url) {
291 this.dataItem = url; 318 this.dataItem[ORIGIN_FIELD] = url;
319 },
320
321 /**
322 * Get and set the shown url for the entry.
323 * @type {string}
324 */
325 get shownUrl() {
326 return this.dataItem[SHOWN_URL_FIELD];
327 },
328 set shownUrl(shownUrl) {
329 this.dataItem[SHOWN_URL_FIELD] = shownUrl;
330 },
331
332 /**
333 * Get and set whether the origin uses secure scheme.
334 * @type {boolean}
335 */
336 get isUrlSecure() {
337 return this.dataItem[IS_SECURE_FIELD];
338 },
339 set isUrlSecure(isUrlSecure) {
340 this.dataItem[IS_SECURE_FIELD] = isUrlSecure;
292 }, 341 },
293 }; 342 };
294 343
295 /** 344 /**
296 * Create a new passwords list. 345 * Create a new passwords list.
297 * @constructor 346 * @constructor
298 * @extends {options.DeletableItemList} 347 * @extends {options.DeletableItemList}
299 */ 348 */
300 var PasswordsList = cr.ui.define('list'); 349 var PasswordsList = cr.ui.define('list');
301 350
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 386
338 if (loadTimeData.getBoolean('disableShowPasswords')) 387 if (loadTimeData.getBoolean('disableShowPasswords'))
339 showPasswords = false; 388 showPasswords = false;
340 389
341 return new PasswordListItem(this.dataModel, entry, showPasswords); 390 return new PasswordListItem(this.dataModel, entry, showPasswords);
342 }, 391 },
343 392
344 /** @override */ 393 /** @override */
345 deleteItemAtIndex: function(index) { 394 deleteItemAtIndex: function(index) {
346 var item = this.dataModel.item(index); 395 var item = this.dataModel.item(index);
347 if (item && item[ORIGINAL_DATA_INDEX] != undefined) { 396 if (item && item[ORIGINAL_INDEX_FIELD] != undefined) {
348 // The fifth element, if present, is the original index to delete. 397 // The fifth element, if present, is the original index to delete.
349 index = item[ORIGINAL_DATA_INDEX]; 398 index = item[ORIGINAL_INDEX_FIELD];
350 } 399 }
351 PasswordManager.removeSavedPassword(index); 400 PasswordManager.removeSavedPassword(index);
352 }, 401 },
353 402
354 /** 403 /**
355 * The length of the list. 404 * The length of the list.
356 */ 405 */
357 get length() { 406 get length() {
358 return this.dataModel.length; 407 return this.dataModel.length;
359 }, 408 },
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 get length() { 448 get length() {
400 return this.dataModel.length; 449 return this.dataModel.length;
401 }, 450 },
402 }; 451 };
403 452
404 return { 453 return {
405 PasswordListItem: PasswordListItem, 454 PasswordListItem: PasswordListItem,
406 PasswordExceptionsListItem: PasswordExceptionsListItem, 455 PasswordExceptionsListItem: PasswordExceptionsListItem,
407 PasswordsList: PasswordsList, 456 PasswordsList: PasswordsList,
408 PasswordExceptionsList: PasswordExceptionsList, 457 PasswordExceptionsList: PasswordExceptionsList,
458 ORIGIN_FIELD: ORIGIN_FIELD,
459 SHOWN_URL_FIELD: SHOWN_URL_FIELD,
460 IS_SECURE_FIELD: IS_SECURE_FIELD,
461 USERNAME_FIELD: USERNAME_FIELD,
462 PASSWORD_FIELD: PASSWORD_FIELD,
463 FEDERATION_FIELD: FEDERATION_FIELD,
464 ORIGINAL_INDEX_FIELD: ORIGINAL_INDEX_FIELD
409 }; 465 };
410 }); 466 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698