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) - | |
180 parseInt(computedStyle.webkitPaddingStart); | |
181 for (var i = 0; i < entries.length; ++i) { | |
182 var urlLink = entries[i].urlLink; | |
183 if (entries[i].isAndroidUri || urlLink.offsetWidth <= columnWidth) | |
184 continue; | |
185 urlLink.textContent = '…' + urlLink.textContent.substring(1); | |
186 while (urlLink.offsetWidth > columnWidth) | |
187 urlLink.textContent = '…' + urlLink.textContent.substring(2); | |
188 } | |
189 }, | |
190 | |
191 /** | |
192 * Updates the data model for the saved passwords list with the values from | 168 * Updates the data model for the saved passwords list with the values from |
193 * |entries|. | 169 * |entries|. |
194 * @param {!Array} entries The list of saved password data. | 170 * @param {!Array} entries The list of saved password data. |
195 */ | 171 */ |
196 setSavedPasswordsList_: function(entries) { | 172 setSavedPasswordsList_: function(entries) { |
197 if (this.lastQuery_) { | 173 if (this.lastQuery_) { |
198 // Implement password searching here in javascript, rather than in C++. | 174 // Implement password searching here in javascript, rather than in C++. |
199 // The number of saved passwords shouldn't be too big for us to handle. | 175 // The number of saved passwords shouldn't be too big for us to handle. |
200 var query = this.lastQuery_; | 176 var query = this.lastQuery_; |
201 var filter = function(entry, index, list) { | 177 var filter = function(entry, index, list) { |
202 // Search both shown URL and username. | 178 // Search both shown URL and username. |
203 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; | 179 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; |
204 var username = entry[options.passwordManager.USERNAME_FIELD]; | 180 var username = entry[options.passwordManager.USERNAME_FIELD]; |
205 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 181 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
206 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 182 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
207 // Keep the original index so we can delete correctly. See also | 183 // Keep the original index so we can delete correctly. See also |
208 // deleteItemAtIndex() in password_manager_list.js that uses this. | 184 // deleteItemAtIndex() in password_manager_list.js that uses this. |
209 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; | 185 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; |
210 return true; | 186 return true; |
211 } | 187 } |
212 return false; | 188 return false; |
213 }; | 189 }; |
214 entries = entries.filter(filter); | 190 entries = entries.filter(filter); |
215 } | 191 } |
216 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 192 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
217 this.updateOriginsEliding_(this.savedPasswordsList_); | |
218 this.updateListVisibility_(this.savedPasswordsList_); | 193 this.updateListVisibility_(this.savedPasswordsList_); |
219 }, | 194 }, |
220 | 195 |
221 /** | 196 /** |
222 * Updates the data model for the password exceptions list with the values | 197 * Updates the data model for the password exceptions list with the values |
223 * from |entries|. | 198 * from |entries|. |
224 * @param {!Array} entries The list of password exception data. | 199 * @param {!Array} entries The list of password exception data. |
225 */ | 200 */ |
226 setPasswordExceptionsList_: function(entries) { | 201 setPasswordExceptionsList_: function(entries) { |
227 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 202 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
228 this.updateOriginsEliding_(this.passwordExceptionsList_); | |
229 this.updateListVisibility_(this.passwordExceptionsList_); | 203 this.updateListVisibility_(this.passwordExceptionsList_); |
230 }, | 204 }, |
231 | 205 |
232 /** | 206 /** |
233 * Reveals the password for a saved password entry. This is called by the | 207 * Reveals the password for a saved password entry. This is called by the |
234 * backend after it has authenticated the user. | 208 * backend after it has authenticated the user. |
235 * @param {number} index The original index of the entry in the model. | 209 * @param {number} index The original index of the entry in the model. |
236 * @param {string} password The saved password. | 210 * @param {string} password The saved password. |
237 */ | 211 */ |
238 showPassword_: function(index, password) { | 212 showPassword_: function(index, password) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 'setPasswordExceptionsList', | 258 'setPasswordExceptionsList', |
285 'showPassword' | 259 'showPassword' |
286 ]); | 260 ]); |
287 | 261 |
288 // Export | 262 // Export |
289 return { | 263 return { |
290 PasswordManager: PasswordManager | 264 PasswordManager: PasswordManager |
291 }; | 265 }; |
292 | 266 |
293 }); | 267 }); |
OLD | NEW |