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

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: Changes with StringPiece Created 5 years, 1 month 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.
26 * @constructor 30 * @constructor
27 * @extends {options.DeletableItem} 31 * @extends {options.DeletableItem}
28 */ 32 */
29 function PasswordListItem(dataModel, entry, showPasswords) { 33 function PasswordListItem(dataModel, entry, showPasswords) {
30 var el = cr.doc.createElement('div'); 34 var el = cr.doc.createElement('div');
31 el.dataItem = entry; 35 el.dataItem = entry;
32 el.dataModel = dataModel; 36 el.dataModel = dataModel;
33 el.__proto__ = PasswordListItem.prototype; 37 el.__proto__ = PasswordListItem.prototype;
34 el.showPasswords_ = showPasswords; 38 el.showPasswords_ = showPasswords;
35 el.decorate(); 39 el.decorate();
36 40
37 return el; 41 return el;
38 } 42 }
39 43
44 /**
45 * Returns title for password's origin (removes the scheme if the url is
46 * insecure and removes trailing punctuation symbols).
47 * @param {string} url The url.
48 * @param {boolean} isSecure True if the url is secure.
49 * @return {string} The title for password's origin.
50 */
51 function getTitleForPasswordOrigin(url, isSecure) {
52 if (!isSecure) {
53 var ind = url.indexOf('://');
54 if (ind >= 0) {
55 url = url.substring(ind + 3);
56 }
57 }
58 // Since the direction is switched to RTL, punctuation symbols appear on the
59 // left side, that is wrong. So, just remove trailing punctuation symbols.
60 url = url.replace(/[^A-Za-z0-9]+$/, '');
61 return url;
62 }
63
40 PasswordListItem.prototype = { 64 PasswordListItem.prototype = {
41 __proto__: DeletableItem.prototype, 65 __proto__: DeletableItem.prototype,
42 66
43 /** @override */ 67 /** @override */
44 decorate: function() { 68 decorate: function() {
45 DeletableItem.prototype.decorate.call(this); 69 DeletableItem.prototype.decorate.call(this);
46 70
47 // The URL of the site. 71 // The URL of the site.
48 var urlLabel = this.ownerDocument.createElement('div'); 72 var urlDiv = this.ownerDocument.createElement('div');
49 urlLabel.classList.add('favicon-cell'); 73 urlDiv.className = 'favicon-cell left-elided-url url';
50 urlLabel.classList.add('weakrtl'); 74 urlDiv.setAttribute(
51 urlLabel.classList.add('url'); 75 'title', getTitleForPasswordOrigin(this.url, this.isUrlSecure));
52 urlLabel.setAttribute('title', this.url); 76 var urlLink = this.ownerDocument.createElement('a');
53 urlLabel.textContent = this.url; 77 urlLink.href = this.url;
54 78 urlLink.textContent = this.shownUrl.split('').reverse().join('');
55 // The favicon URL is prefixed with "origin/", which essentially removes 79 urlDiv.appendChild(urlLink);
56 // the URL path past the top-level domain and ensures that a scheme (e.g., 80 urlDiv.style.backgroundImage = getFaviconImageSet(
57 // http) is being used. This ensures that the favicon returned is the
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); 81 'origin/' + this.url, 16);
62 this.contentElement.appendChild(urlLabel); 82 this.contentElement.appendChild(urlDiv);
63 83
64 // The stored username. 84 // The stored username.
65 var usernameLabel = this.ownerDocument.createElement('div'); 85 var usernameDiv = this.ownerDocument.createElement('div');
66 usernameLabel.className = 'name'; 86 usernameDiv.className = 'name';
67 usernameLabel.textContent = this.username; 87 usernameDiv.title = this.username;
68 usernameLabel.title = this.username; 88 this.contentElement.appendChild(usernameDiv);
69 this.contentElement.appendChild(usernameLabel); 89 var usernameInput = this.ownerDocument.createElement('input');
90 usernameInput.type = 'text';
91 usernameInput.className = 'inactive-item';
92 usernameInput.readOnly = true;
93 usernameInput.value = this.username;
94 usernameDiv.appendChild(usernameInput);
95 this.usernameField = usernameInput;
70 96
71 if (this.federation) { 97 if (this.federation) {
72 // The federation. 98 // The federation.
73 var federationDiv = this.ownerDocument.createElement('div'); 99 var federationDiv = this.ownerDocument.createElement('div');
74 federationDiv.className = 'federation'; 100 federationDiv.className = 'federation';
75 federationDiv.textContent = this.federation; 101 federationDiv.textContent = this.federation;
76 this.contentElement.appendChild(federationDiv); 102 this.contentElement.appendChild(federationDiv);
77 } else { 103 } else {
78 // The stored password. 104 // The stored password.
79 var passwordInputDiv = this.ownerDocument.createElement('div'); 105 var passwordInputDiv = this.ownerDocument.createElement('div');
80 passwordInputDiv.className = 'password'; 106 passwordInputDiv.className = 'password';
81 107
82 // The password input field. 108 // The password input field.
83 var passwordInput = this.ownerDocument.createElement('input'); 109 var passwordInput = this.ownerDocument.createElement('input');
84 passwordInput.type = 'password'; 110 passwordInput.type = 'password';
85 passwordInput.className = 'inactive-password'; 111 passwordInput.className = 'inactive-item';
86 passwordInput.readOnly = true; 112 passwordInput.readOnly = true;
87 passwordInput.value = this.showPasswords_ ? this.password : '********'; 113 passwordInput.value = this.showPasswords_ ? this.password : '********';
88 passwordInputDiv.appendChild(passwordInput); 114 passwordInputDiv.appendChild(passwordInput);
89 var deletableItem = this; 115 var deletableItem = this;
90 passwordInput.addEventListener('focus', function() { 116 passwordInput.addEventListener('focus', function() {
91 deletableItem.handleFocus(); 117 deletableItem.handleFocus();
92 }); 118 });
93 this.passwordField = passwordInput; 119 this.passwordField = passwordInput;
94 this.setFocusable_(false); 120 this.setFocusable_(false);
95 121
(...skipping 11 matching lines...) Expand all
107 event.stopPropagation(); 133 event.stopPropagation();
108 }, false); 134 }, false);
109 button.addEventListener('focus', function() { 135 button.addEventListener('focus', function() {
110 deletableItem.handleFocus(); 136 deletableItem.handleFocus();
111 }); 137 });
112 passwordInputDiv.appendChild(button); 138 passwordInputDiv.appendChild(button);
113 this.passwordShowButton = button; 139 this.passwordShowButton = button;
114 } 140 }
115 this.contentElement.appendChild(passwordInputDiv); 141 this.contentElement.appendChild(passwordInputDiv);
116 } 142 }
117
118 }, 143 },
119 144
120 /** @override */ 145 /** @override */
121 selectionChanged: function() { 146 selectionChanged: function() {
122 var input = this.passwordField; 147 var usernameInput = this.usernameField;
148 var passwordInput = this.passwordField;
123 var button = this.passwordShowButton; 149 var button = this.passwordShowButton;
124 // The button doesn't exist when passwords can't be shown. 150 // The button doesn't exist when passwords can't be shown.
125 if (!button) 151 if (!button)
126 return; 152 return;
127 153
128 if (this.selected) { 154 if (this.selected) {
129 input.classList.remove('inactive-password'); 155 usernameInput.classList.remove('inactive-item');
156 passwordInput.classList.remove('inactive-item');
130 this.setFocusable_(true); 157 this.setFocusable_(true);
131 button.hidden = false; 158 button.hidden = false;
132 input.focus(); 159 passwordInput.focus();
133 } else { 160 } else {
134 input.classList.add('inactive-password'); 161 usernameInput.classList.add('inactive-item');
162 passwordInput.classList.add('inactive-item');
135 this.setFocusable_(false); 163 this.setFocusable_(false);
136 button.hidden = true; 164 button.hidden = true;
137 } 165 }
138 }, 166 },
139 167
140 /** 168 /**
141 * Set the focusability of this row. 169 * Set the focusability of this row.
142 * @param {boolean} focusable 170 * @param {boolean} focusable
143 * @private 171 * @private
144 */ 172 */
(...skipping 24 matching lines...) Expand all
169 if (button) 197 if (button)
170 button.textContent = loadTimeData.getString('passwordShowButton'); 198 button.textContent = loadTimeData.getString('passwordShowButton');
171 }, 199 },
172 200
173 /** 201 /**
174 * Get the original index of this item in the data model. 202 * Get the original index of this item in the data model.
175 * @return {number} The index. 203 * @return {number} The index.
176 * @private 204 * @private
177 */ 205 */
178 getOriginalIndex_: function() { 206 getOriginalIndex_: function() {
179 var index = this.dataItem[ORIGINAL_DATA_INDEX]; 207 var index = this.dataItem[ORIGINAL_INDEX_FIELD];
180 return index ? index : this.dataModel.indexOf(this.dataItem); 208 return index ? index : this.dataModel.indexOf(this.dataItem);
181 }, 209 },
182 210
183 /** 211 /**
184 * On-click event handler. Swaps the type of the input field from password 212 * On-click event handler. Swaps the type of the input field from password
185 * to text and back. 213 * to text and back.
186 * @private 214 * @private
187 */ 215 */
188 onClick_: function(event) { 216 onClick_: function(event) {
189 if (this.passwordField.type == 'password') { 217 if (this.passwordField.type == 'password') {
190 // After the user is authenticated, showPassword() will be called. 218 // After the user is authenticated, showPassword() will be called.
191 PasswordManager.requestShowPassword(this.getOriginalIndex_()); 219 PasswordManager.requestShowPassword(this.getOriginalIndex_());
192 } else { 220 } else {
193 this.hidePassword(); 221 this.hidePassword();
194 } 222 }
195 }, 223 },
196 224
197 /** 225 /**
198 * Get and set the URL for the entry. 226 * Get and set the URL for the entry.
199 * @type {string} 227 * @type {string}
200 */ 228 */
201 get url() { 229 get url() {
202 return this.dataItem[URL_DATA_INDEX]; 230 return this.dataItem[ORIGIN_FIELD];
203 }, 231 },
204 set url(url) { 232 set url(url) {
205 this.dataItem[URL_DATA_INDEX] = url; 233 this.dataItem[ORIGIN_FIELD] = url;
206 }, 234 },
207 235
208 /** 236 /**
237 * Get and set the shown url for the entry.
238 * @type {string}
239 */
240 get shownUrl() {
241 return this.dataItem[SHOWN_URL_FIELD];
242 },
243 set shownUrl(shownUrl) {
244 this.dataItem[SHOWN_URL_FIELD] = shownUrl;
245 },
246
247 /**
248 * Get and set whether the origin uses secure scheme.
249 * @type {boolean}
250 */
251 get isUrlSecure() {
252 return this.dataItem[IS_SECURE_FIELD];
253 },
254 set isUrlSecure(isUrlSecure) {
255 this.dataItem[IS_SECURE_FIELD] = isUrlSecure;
256 },
257
258 /**
209 * Get and set the username for the entry. 259 * Get and set the username for the entry.
210 * @type {string} 260 * @type {string}
211 */ 261 */
212 get username() { 262 get username() {
213 return this.dataItem[USERNAME_DATA_INDEX]; 263 return this.dataItem[USERNAME_FIELD];
214 }, 264 },
215 set username(username) { 265 set username(username) {
216 this.dataItem[USERNAME_DATA_INDEX] = username; 266 this.dataItem[USERNAME_FIELD] = username;
217 }, 267 },
218 268
219 /** 269 /**
220 * Get and set the password for the entry. 270 * Get and set the password for the entry.
221 * @type {string} 271 * @type {string}
222 */ 272 */
223 get password() { 273 get password() {
224 return this.dataItem[PASSWORD_DATA_INDEX]; 274 return this.dataItem[PASSWORD_FIELD];
225 }, 275 },
226 set password(password) { 276 set password(password) {
227 this.dataItem[PASSWORD_DATA_INDEX] = password; 277 this.dataItem[PASSWORD_FIELD] = password;
228 }, 278 },
229 279
230 /** 280 /**
231 * Get and set the federation for the entry. 281 * Get and set the federation for the entry.
232 * @type {string} 282 * @type {string}
233 */ 283 */
234 get federation() { 284 get federation() {
235 return this.dataItem[FEDERATION_DATA_INDEX]; 285 return this.dataItem[FEDERATION_FIELD];
236 }, 286 },
237 set federation(federation) { 287 set federation(federation) {
238 this.dataItem[FEDERATION_DATA_INDEX] = federation; 288 this.dataItem[FEDERATION_FIELD] = federation;
239 }, 289 },
240 }; 290 };
241 291
242 /** 292 /**
243 * Creates a new PasswordExceptions list item. 293 * Creates a new PasswordExceptions list item.
244 * @param {Array} entry A pair of the form [url, username]. 294 * @param {Array} entry A pair of the form [url, username].
245 * @constructor 295 * @constructor
246 * @extends {options.DeletableItem} 296 * @extends {options.DeletableItem}
247 */ 297 */
248 function PasswordExceptionsListItem(entry) { 298 function PasswordExceptionsListItem(entry) {
249 var el = cr.doc.createElement('div'); 299 var el = cr.doc.createElement('div');
250 el.dataItem = entry; 300 el.dataItem = entry;
251 el.__proto__ = PasswordExceptionsListItem.prototype; 301 el.__proto__ = PasswordExceptionsListItem.prototype;
252 el.decorate(); 302 el.decorate();
253 303
254 return el; 304 return el;
255 } 305 }
256 306
257 PasswordExceptionsListItem.prototype = { 307 PasswordExceptionsListItem.prototype = {
258 __proto__: DeletableItem.prototype, 308 __proto__: DeletableItem.prototype,
259 309
260 /** 310 /**
261 * Call when an element is decorated as a list item. 311 * Call when an element is decorated as a list item.
262 */ 312 */
263 decorate: function() { 313 decorate: function() {
264 DeletableItem.prototype.decorate.call(this); 314 DeletableItem.prototype.decorate.call(this);
265 315
266 // The URL of the site. 316 // The URL of the site.
267 var urlLabel = this.ownerDocument.createElement('div'); 317 var urlDiv = this.ownerDocument.createElement('div');
268 urlLabel.className = 'url'; 318 urlDiv.className = 'url';
269 urlLabel.classList.add('favicon-cell'); 319 urlDiv.classList.add('favicon-cell');
270 urlLabel.classList.add('weakrtl'); 320 urlDiv.classList.add('left-elided-url');
271 urlLabel.textContent = this.url; 321 urlDiv.setAttribute(
272 322 'title', getTitleForPasswordOrigin(this.url, this.isUrlSecure));
273 // The favicon URL is prefixed with "origin/", which essentially removes 323 var urlLink = this.ownerDocument.createElement('a');
274 // the URL path past the top-level domain and ensures that a scheme (e.g., 324 urlLink.href = this.url;
275 // http) is being used. This ensures that the favicon returned is the 325 urlLink.textContent = this.shownUrl.split('').reverse().join('');
276 // default favicon for the domain and that the URL has a scheme if none 326 urlDiv.appendChild(urlLink);
277 // is present in the password manager. 327 urlDiv.style.backgroundImage = getFaviconImageSet(
278 urlLabel.style.backgroundImage = getFaviconImageSet(
279 'origin/' + this.url, 16); 328 'origin/' + this.url, 16);
280 this.contentElement.appendChild(urlLabel); 329 this.contentElement.appendChild(urlDiv);
281 }, 330 },
282 331
283 /** 332 /**
284 * Get the url for the entry. 333 * Get the url for the entry.
285 * @type {string} 334 * @type {string}
286 */ 335 */
287 get url() { 336 get url() {
288 return this.dataItem; 337 return this.dataItem[ORIGIN_FIELD];
289 }, 338 },
290 set url(url) { 339 set url(url) {
291 this.dataItem = url; 340 this.dataItem[ORIGIN_FIELD] = url;
341 },
342
343 /**
344 * Get and set the shown url for the entry.
345 * @type {string}
346 */
347 get shownUrl() {
348 return this.dataItem[SHOWN_URL_FIELD];
349 },
350 set shownUrl(shownUrl) {
351 this.dataItem[SHOWN_URL_FIELD] = shownUrl;
352 },
353
354 /**
355 * Get and set whether the origin uses secure scheme.
356 * @type {boolean}
357 */
358 get isUrlSecure() {
359 return this.dataItem[IS_SECURE_FIELD];
360 },
361 set isUrlSecure(isUrlSecure) {
362 this.dataItem[IS_SECURE_FIELD] = isUrlSecure;
292 }, 363 },
293 }; 364 };
294 365
295 /** 366 /**
296 * Create a new passwords list. 367 * Create a new passwords list.
297 * @constructor 368 * @constructor
298 * @extends {options.DeletableItemList} 369 * @extends {options.DeletableItemList}
299 */ 370 */
300 var PasswordsList = cr.ui.define('list'); 371 var PasswordsList = cr.ui.define('list');
301 372
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 408
338 if (loadTimeData.getBoolean('disableShowPasswords')) 409 if (loadTimeData.getBoolean('disableShowPasswords'))
339 showPasswords = false; 410 showPasswords = false;
340 411
341 return new PasswordListItem(this.dataModel, entry, showPasswords); 412 return new PasswordListItem(this.dataModel, entry, showPasswords);
342 }, 413 },
343 414
344 /** @override */ 415 /** @override */
345 deleteItemAtIndex: function(index) { 416 deleteItemAtIndex: function(index) {
346 var item = this.dataModel.item(index); 417 var item = this.dataModel.item(index);
347 if (item && item[ORIGINAL_DATA_INDEX] != undefined) { 418 if (item && item[ORIGINAL_INDEX_FIELD] != undefined) {
348 // The fifth element, if present, is the original index to delete. 419 // The fifth element, if present, is the original index to delete.
349 index = item[ORIGINAL_DATA_INDEX]; 420 index = item[ORIGINAL_INDEX_FIELD];
350 } 421 }
351 PasswordManager.removeSavedPassword(index); 422 PasswordManager.removeSavedPassword(index);
352 }, 423 },
353 424
354 /** 425 /**
355 * The length of the list. 426 * The length of the list.
356 */ 427 */
357 get length() { 428 get length() {
358 return this.dataModel.length; 429 return this.dataModel.length;
359 }, 430 },
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 get length() { 470 get length() {
400 return this.dataModel.length; 471 return this.dataModel.length;
401 }, 472 },
402 }; 473 };
403 474
404 return { 475 return {
405 PasswordListItem: PasswordListItem, 476 PasswordListItem: PasswordListItem,
406 PasswordExceptionsListItem: PasswordExceptionsListItem, 477 PasswordExceptionsListItem: PasswordExceptionsListItem,
407 PasswordsList: PasswordsList, 478 PasswordsList: PasswordsList,
408 PasswordExceptionsList: PasswordExceptionsList, 479 PasswordExceptionsList: PasswordExceptionsList,
480 ORIGIN_FIELD: ORIGIN_FIELD,
481 SHOWN_URL_FIELD: SHOWN_URL_FIELD,
482 IS_SECURE_FIELD: IS_SECURE_FIELD,
483 USERNAME_FIELD: USERNAME_FIELD,
484 PASSWORD_FIELD: PASSWORD_FIELD,
485 FEDERATION_FIELD: FEDERATION_FIELD,
486 ORIGINAL_INDEX_FIELD: ORIGINAL_INDEX_FIELD
409 }; 487 };
410 }); 488 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698