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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 * @param {!cr.ui.List} list The list to toggle visilibility for. | 158 * @param {!cr.ui.List} list The list to toggle visilibility for. |
159 */ | 159 */ |
160 updateListVisibility_: function(list) { | 160 updateListVisibility_: function(list) { |
161 var empty = list.dataModel.length == 0; | 161 var empty = list.dataModel.length == 0; |
162 var listPlaceHolderID = list.id + '-empty-placeholder'; | 162 var listPlaceHolderID = list.id + '-empty-placeholder'; |
163 list.hidden = empty; | 163 list.hidden = empty; |
164 $(listPlaceHolderID).hidden = !empty; | 164 $(listPlaceHolderID).hidden = !empty; |
165 }, | 165 }, |
166 | 166 |
167 /** | 167 /** |
| 168 * Updates eliding of origins. If there is no enough space to show the full |
| 169 * origin, the origin is elided from the left with ellipsis. |
| 170 * @param {!cr.ui.List} list The list to update eliding. |
| 171 */ |
| 172 updateOriginsEliding_: function(list) { |
| 173 var entries = list.getElementsByClassName('deletable-item'); |
| 174 if (entries.length == 0) |
| 175 return; |
| 176 var entry = entries[0]; |
| 177 var computedStyle = window.getComputedStyle(entry.urlDiv); |
| 178 var columnWidth = entry.urlDiv.offsetWidth - |
| 179 parseInt(computedStyle.webkitMarginStart, 10) - |
| 180 parseInt(computedStyle.webkitPaddingStart, 10); |
| 181 if (columnWidth <= 0) { |
| 182 console.error('Estimated column width <= 0. Skip origins eliding.'); |
| 183 return; |
| 184 } |
| 185 for (var i = 0; i < entries.length; ++i) { |
| 186 var urlLink = entries[i].urlLink; |
| 187 if (entries[i].isAndroidUri || urlLink.offsetWidth <= columnWidth) |
| 188 continue; |
| 189 urlLink.textContent = '…' + urlLink.textContent.substring(1); |
| 190 while (urlLink.offsetWidth > columnWidth) |
| 191 urlLink.textContent = '…' + urlLink.textContent.substring(2); |
| 192 } |
| 193 }, |
| 194 |
| 195 /** |
168 * Updates the data model for the saved passwords list with the values from | 196 * Updates the data model for the saved passwords list with the values from |
169 * |entries|. | 197 * |entries|. |
170 * @param {!Array} entries The list of saved password data. | 198 * @param {!Array} entries The list of saved password data. |
171 */ | 199 */ |
172 setSavedPasswordsList_: function(entries) { | 200 setSavedPasswordsList_: function(entries) { |
173 if (this.lastQuery_) { | 201 if (this.lastQuery_) { |
174 // Implement password searching here in javascript, rather than in C++. | 202 // Implement password searching here in javascript, rather than in C++. |
175 // The number of saved passwords shouldn't be too big for us to handle. | 203 // The number of saved passwords shouldn't be too big for us to handle. |
176 var query = this.lastQuery_; | 204 var query = this.lastQuery_; |
177 var filter = function(entry, index, list) { | 205 var filter = function(entry, index, list) { |
178 // Search both shown URL and username. | 206 // Search both shown URL and username. |
179 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; | 207 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; |
180 var username = entry[options.passwordManager.USERNAME_FIELD]; | 208 var username = entry[options.passwordManager.USERNAME_FIELD]; |
181 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 209 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
182 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 210 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
183 // Keep the original index so we can delete correctly. See also | 211 // Keep the original index so we can delete correctly. See also |
184 // deleteItemAtIndex() in password_manager_list.js that uses this. | 212 // deleteItemAtIndex() in password_manager_list.js that uses this. |
185 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; | 213 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; |
186 return true; | 214 return true; |
187 } | 215 } |
188 return false; | 216 return false; |
189 }; | 217 }; |
190 entries = entries.filter(filter); | 218 entries = entries.filter(filter); |
191 } | 219 } |
192 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 220 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
193 this.updateListVisibility_(this.savedPasswordsList_); | 221 this.updateListVisibility_(this.savedPasswordsList_); |
| 222 // updateOriginsEliding_ should be called after updateListVisibility_, |
| 223 // otherwise updateOrigins... might be not able to read width of elements. |
| 224 this.updateOriginsEliding_(this.savedPasswordsList_); |
194 }, | 225 }, |
195 | 226 |
196 /** | 227 /** |
197 * Updates the data model for the password exceptions list with the values | 228 * Updates the data model for the password exceptions list with the values |
198 * from |entries|. | 229 * from |entries|. |
199 * @param {!Array} entries The list of password exception data. | 230 * @param {!Array} entries The list of password exception data. |
200 */ | 231 */ |
201 setPasswordExceptionsList_: function(entries) { | 232 setPasswordExceptionsList_: function(entries) { |
202 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 233 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
203 this.updateListVisibility_(this.passwordExceptionsList_); | 234 this.updateListVisibility_(this.passwordExceptionsList_); |
| 235 // updateOriginsEliding_ should be called after updateListVisibility_, |
| 236 // otherwise updateOrigins... might be not able to read width of elements. |
| 237 this.updateOriginsEliding_(this.passwordExceptionsList_); |
204 }, | 238 }, |
205 | 239 |
206 /** | 240 /** |
207 * Reveals the password for a saved password entry. This is called by the | 241 * Reveals the password for a saved password entry. This is called by the |
208 * backend after it has authenticated the user. | 242 * backend after it has authenticated the user. |
209 * @param {number} index The original index of the entry in the model. | 243 * @param {number} index The original index of the entry in the model. |
210 * @param {string} password The saved password. | 244 * @param {string} password The saved password. |
211 */ | 245 */ |
212 showPassword_: function(index, password) { | 246 showPassword_: function(index, password) { |
213 var model = this.savedPasswordsList_.dataModel; | 247 var model = this.savedPasswordsList_.dataModel; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 'setPasswordExceptionsList', | 292 'setPasswordExceptionsList', |
259 'showPassword' | 293 'showPassword' |
260 ]); | 294 ]); |
261 | 295 |
262 // Export | 296 // Export |
263 return { | 297 return { |
264 PasswordManager: PasswordManager | 298 PasswordManager: PasswordManager |
265 }; | 299 }; |
266 | 300 |
267 }); | 301 }); |
OLD | NEW |