| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 * @param {!cr.ui.List} list The list to toggle visilibility for. | 164 * @param {!cr.ui.List} list The list to toggle visilibility for. |
| 165 */ | 165 */ |
| 166 updateListVisibility_: function(list) { | 166 updateListVisibility_: function(list) { |
| 167 var empty = list.dataModel.length == 0; | 167 var empty = list.dataModel.length == 0; |
| 168 var listPlaceHolderID = list.id + '-empty-placeholder'; | 168 var listPlaceHolderID = list.id + '-empty-placeholder'; |
| 169 list.hidden = empty; | 169 list.hidden = empty; |
| 170 $(listPlaceHolderID).hidden = !empty; | 170 $(listPlaceHolderID).hidden = !empty; |
| 171 }, | 171 }, |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * Updates eliding of origins. If there is no enough space to show the full | |
| 175 * origin, the origin is elided from the left with ellipsis. | |
| 176 * @param {!cr.ui.List} list The list to update eliding. | |
| 177 */ | |
| 178 updateOriginsEliding_: function(list) { | |
| 179 var entries = list.getElementsByClassName('deletable-item'); | |
| 180 if (entries.length == 0) | |
| 181 return; | |
| 182 var entry = entries[0]; | |
| 183 var computedStyle = window.getComputedStyle(entry.urlDiv); | |
| 184 var columnWidth = entry.urlDiv.offsetWidth - | |
| 185 parseInt(computedStyle.webkitMarginStart, 10) - | |
| 186 parseInt(computedStyle.webkitPaddingStart, 10); | |
| 187 | |
| 188 // We use a canvas context to compute text widths. This canvas is not | |
| 189 // part of the DOM and thus avoids layout thrashing when updating the | |
| 190 // contained text. | |
| 191 var canvas = document.createElement('canvas'); | |
| 192 var ctx = canvas.getContext('2d'); | |
| 193 ctx.font = computedStyle.font; | |
| 194 | |
| 195 for (var i = 0; i < entries.length; ++i) { | |
| 196 entry = entries[i]; | |
| 197 // For android://com.example, elide from the right. | |
| 198 if (!entry.isClickable) | |
| 199 continue; | |
| 200 var cellWidth = columnWidth; | |
| 201 if (entry.androidUriSuffix) | |
| 202 cellWidth -= entry.androidUriSuffix.offsetWidth; | |
| 203 var urlLink = entry.urlLink; | |
| 204 if (cellWidth <= 0) { | |
| 205 console.error('cellWidth <= 0. Skip origins eliding for ' + | |
| 206 urlLink.textContent); | |
| 207 continue; | |
| 208 } | |
| 209 | |
| 210 var textContent = urlLink.textContent; | |
| 211 if (ctx.measureText(textContent).width <= cellWidth) | |
| 212 continue; | |
| 213 | |
| 214 textContent = '…' + textContent.substring(1); | |
| 215 while (ctx.measureText(textContent).width > cellWidth) | |
| 216 textContent = '…' + textContent.substring(2); | |
| 217 | |
| 218 // Write the elided origin back to the DOM. | |
| 219 urlLink.textContent = textContent; | |
| 220 } | |
| 221 }, | |
| 222 | |
| 223 /** | |
| 224 * Updates the data model for the saved passwords list with the values from | 174 * Updates the data model for the saved passwords list with the values from |
| 225 * |entries|. | 175 * |entries|. |
| 226 * @param {!Array} entries The list of saved password data. | 176 * @param {!Array} entries The list of saved password data. |
| 227 */ | 177 */ |
| 228 setSavedPasswordsList_: function(entries) { | 178 setSavedPasswordsList_: function(entries) { |
| 229 if (this.lastQuery_) { | 179 if (this.lastQuery_) { |
| 230 // Implement password searching here in javascript, rather than in C++. | 180 // Implement password searching here in javascript, rather than in C++. |
| 231 // The number of saved passwords shouldn't be too big for us to handle. | 181 // The number of saved passwords shouldn't be too big for us to handle. |
| 232 var query = this.lastQuery_; | 182 var query = this.lastQuery_; |
| 233 var filter = function(entry, index, list) { | 183 var filter = function(entry, index, list) { |
| 234 // Search both shown URL and username. | 184 // Search both shown URL and username. |
| 235 var shownOrigin = entry[options.passwordManager.SHOWN_ORIGIN_FIELD]; | 185 var shownOrigin = entry[options.passwordManager.SHOWN_ORIGIN_FIELD]; |
| 236 var username = entry[options.passwordManager.USERNAME_FIELD]; | 186 var username = entry[options.passwordManager.USERNAME_FIELD]; |
| 237 if (shownOrigin.toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 187 if (shownOrigin.toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
| 238 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 188 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
| 239 // Keep the original index so we can delete correctly. See also | 189 // Keep the original index so we can delete correctly. See also |
| 240 // deleteItemAtIndex() in password_manager_list.js that uses this. | 190 // deleteItemAtIndex() in password_manager_list.js that uses this. |
| 241 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; | 191 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; |
| 242 return true; | 192 return true; |
| 243 } | 193 } |
| 244 return false; | 194 return false; |
| 245 }; | 195 }; |
| 246 entries = entries.filter(filter); | 196 entries = entries.filter(filter); |
| 247 } | 197 } |
| 248 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 198 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
| 249 this.updateListVisibility_(this.savedPasswordsList_); | 199 this.updateListVisibility_(this.savedPasswordsList_); |
| 250 // updateOriginsEliding_ should be called after updateListVisibility_, | |
| 251 // otherwise updateOrigins... might be not able to read width of elements. | |
| 252 this.updateOriginsEliding_(this.savedPasswordsList_); | |
| 253 }, | 200 }, |
| 254 | 201 |
| 255 /** | 202 /** |
| 256 * Updates the data model for the password exceptions list with the values | 203 * Updates the data model for the password exceptions list with the values |
| 257 * from |entries|. | 204 * from |entries|. |
| 258 * @param {!Array} entries The list of password exception data. | 205 * @param {!Array} entries The list of password exception data. |
| 259 */ | 206 */ |
| 260 setPasswordExceptionsList_: function(entries) { | 207 setPasswordExceptionsList_: function(entries) { |
| 261 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 208 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
| 262 this.updateListVisibility_(this.passwordExceptionsList_); | 209 this.updateListVisibility_(this.passwordExceptionsList_); |
| 263 // updateOriginsEliding_ should be called after updateListVisibility_, | |
| 264 // otherwise updateOrigins... might be not able to read width of elements. | |
| 265 this.updateOriginsEliding_(this.passwordExceptionsList_); | |
| 266 }, | 210 }, |
| 267 | 211 |
| 268 /** | 212 /** |
| 269 * Reveals the password for a saved password entry. This is called by the | 213 * Reveals the password for a saved password entry. This is called by the |
| 270 * backend after it has authenticated the user. | 214 * backend after it has authenticated the user. |
| 271 * @param {number} index The original index of the entry in the model. | 215 * @param {number} index The original index of the entry in the model. |
| 272 * @param {string} password The saved password. | 216 * @param {string} password The saved password. |
| 273 */ | 217 */ |
| 274 showPassword_: function(index, password) { | 218 showPassword_: function(index, password) { |
| 275 var model = this.savedPasswordsList_.dataModel; | 219 var model = this.savedPasswordsList_.dataModel; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 'showImportExportButton', | 278 'showImportExportButton', |
| 335 'showPassword', | 279 'showPassword', |
| 336 ]); | 280 ]); |
| 337 | 281 |
| 338 // Export | 282 // Export |
| 339 return { | 283 return { |
| 340 PasswordManager: PasswordManager | 284 PasswordManager: PasswordManager |
| 341 }; | 285 }; |
| 342 | 286 |
| 343 }); | 287 }); |
| OLD | NEW |