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

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

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6 const OptionsPage = options.OptionsPage;
7 const ArrayDataModel = cr.ui.ArrayDataModel;
8
9 /////////////////////////////////////////////////////////////////////////////
10 // PasswordManager class:
11
12 /**
13 * Encapsulated handling of password and exceptions page.
14 * @constructor
15 */
16 function PasswordManager() {
17 this.activeNavTab = null;
18 OptionsPage.call(this,
19 'passwords',
20 templateData.passwordsPageTabTitle,
21 'password-manager');
22 }
23
24 cr.addSingletonGetter(PasswordManager);
25
26 PasswordManager.prototype = {
27 __proto__: OptionsPage.prototype,
28
29 /**
30 * The saved passwords list.
31 * @type {DeletableItemList}
32 * @private
33 */
34 savedPasswordsList_: null,
35
36 /**
37 * The password exceptions list.
38 * @type {DeletableItemList}
39 * @private
40 */
41 passwordExceptionsList_: null,
42
43 /**
44 * The timer id of the timer set on search query change events.
45 * @type {number}
46 * @private
47 */
48 queryDelayTimerId_: 0,
49
50 /**
51 * The most recent search query, or null if the query is empty.
52 * @type {?string}
53 * @private
54 */
55 lastQuery_: null,
56
57 /** @inheritDoc */
58 initializePage: function() {
59 OptionsPage.prototype.initializePage.call(this);
60
61 $('password-search-box').addEventListener('search',
62 this.handleSearchQueryChange_.bind(this));
63
64 this.createSavedPasswordsList_();
65 this.createPasswordExceptionsList_();
66 },
67
68 /** @inheritDoc */
69 canShowPage: function() {
70 return !PersonalOptions.disablePasswordManagement();
71 },
72
73 /** @inheritDoc */
74 didShowPage: function() {
75 // Updating the password lists may cause a blocking platform dialog pop up
76 // (Mac, Linux), so we delay this operation until the page is shown.
77 chrome.send('updatePasswordLists');
78 $('password-search-box').focus();
79 },
80
81 /**
82 * Creates, decorates and initializes the saved passwords list.
83 * @private
84 */
85 createSavedPasswordsList_: function() {
86 this.savedPasswordsList_ = $('saved-passwords-list');
87 options.passwordManager.PasswordsList.decorate(this.savedPasswordsList_);
88 this.savedPasswordsList_.autoExpands = true;
89 },
90
91 /**
92 * Creates, decorates and initializes the password exceptions list.
93 * @private
94 */
95 createPasswordExceptionsList_: function() {
96 this.passwordExceptionsList_ = $('password-exceptions-list');
97 options.passwordManager.PasswordExceptionsList.decorate(
98 this.passwordExceptionsList_);
99 this.passwordExceptionsList_.autoExpands = true;
100 },
101
102 /**
103 * Handles search query changes.
104 * @param {!Event} e The event object.
105 * @private
106 */
107 handleSearchQueryChange_: function(e) {
108 if (this.queryDelayTimerId_)
109 window.clearTimeout(this.queryDelayTimerId_);
110
111 // Searching cookies uses a timeout of 500ms. We use a shorter timeout
112 // because there are probably fewer passwords and we want the UI to be
113 // snappier since users will expect that it's "less work."
114 this.queryDelayTimerId_ = window.setTimeout(
115 this.searchPasswords_.bind(this), 250);
116 },
117
118 /**
119 * Search passwords using text in |password-search-box|.
120 * @private
121 */
122 searchPasswords_: function() {
123 this.queryDelayTimerId_ = 0;
124 var filter = $('password-search-box').value;
125 filter = (filter == '') ? null : filter;
126 if (this.lastQuery_ != filter) {
127 this.lastQuery_ = filter;
128 // Searching for passwords has the side effect of requerying the
129 // underlying password store. This is done intentionally, as on OS X and
130 // Linux they can change from outside and we won't be notified of it.
131 chrome.send('updatePasswordLists');
132 }
133 },
134
135 /**
136 * Updates the visibility of the list and empty list placeholder.
137 * @param {!List} list The list to toggle visilibility for.
138 */
139 updateListVisibility_: function(list) {
140 var empty = list.dataModel.length == 0;
141 var listPlaceHolderID = list.id + '-empty-placeholder';
142 list.hidden = empty;
143 $(listPlaceHolderID).hidden = !empty;
144 },
145
146 /**
147 * Updates the data model for the saved passwords list with the values from
148 * |entries|.
149 * @param {Array} entries The list of saved password data.
150 */
151 setSavedPasswordsList_: function(entries) {
152 if (this.lastQuery_) {
153 // Implement password searching here in javascript, rather than in C++.
154 // The number of saved passwords shouldn't be too big for us to handle.
155 var query = this.lastQuery_;
156 var filter = function(entry, index, list) {
157 // Search both URL and username.
158 if (entry[0].indexOf(query) >= 0 || entry[1].indexOf(query) >= 0) {
159 // Keep the original index so we can delete correctly. See also
160 // deleteItemAtIndex() in password_manager_list.js that uses this.
161 entry[3] = index;
162 return true;
163 }
164 return false;
165 };
166 entries = entries.filter(filter);
167 }
168 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries);
169 this.updateListVisibility_(this.savedPasswordsList_);
170 },
171
172 /**
173 * Updates the data model for the password exceptions list with the values
174 * from |entries|.
175 * @param {Array} entries The list of password exception data.
176 */
177 setPasswordExceptionsList_: function(entries) {
178 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries);
179 this.updateListVisibility_(this.passwordExceptionsList_);
180 },
181 };
182
183 /**
184 * Call to remove a saved password.
185 * @param rowIndex indicating the row to remove.
186 */
187 PasswordManager.removeSavedPassword = function(rowIndex) {
188 chrome.send('removeSavedPassword', [String(rowIndex)]);
189 };
190
191 /**
192 * Call to remove a password exception.
193 * @param rowIndex indicating the row to remove.
194 */
195 PasswordManager.removePasswordException = function(rowIndex) {
196 chrome.send('removePasswordException', [String(rowIndex)]);
197 };
198
199 /**
200 * Call to remove all saved passwords.
201 * @param tab contentType of the tab currently on.
202 */
203 PasswordManager.removeAllPasswords = function() {
204 chrome.send('removeAllSavedPasswords');
205 };
206
207 /**
208 * Call to remove all saved passwords.
209 * @param tab contentType of the tab currently on.
210 */
211 PasswordManager.removeAllPasswordExceptions = function() {
212 chrome.send('removeAllPasswordExceptions');
213 };
214
215 PasswordManager.setSavedPasswordsList = function(entries) {
216 PasswordManager.getInstance().setSavedPasswordsList_(entries);
217 };
218
219 PasswordManager.setPasswordExceptionsList = function(entries) {
220 PasswordManager.getInstance().setPasswordExceptionsList_(entries);
221 };
222
223 // Export
224 return {
225 PasswordManager: PasswordManager
226 };
227
228 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698