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 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 | 7 |
8 /** | 8 /** |
9 * ClearBrowserDataOverlay class | 9 * ClearBrowserDataOverlay class |
10 * Encapsulated handling of the 'Clear Browser Data' overlay page. | 10 * Encapsulated handling of the 'Clear Browser Data' overlay page. |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 /** | 25 /** |
26 * Whether deleting history and downloads is allowed. | 26 * Whether deleting history and downloads is allowed. |
27 * @type {boolean} | 27 * @type {boolean} |
28 * @private | 28 * @private |
29 */ | 29 */ |
30 allowDeletingHistory_: true, | 30 allowDeletingHistory_: true, |
31 | 31 |
32 /** | 32 /** |
33 * Whether or not clearing browsing data is currently in progress. | 33 * Whether or not clearing browsing data is currently in progress. |
34 * @type {boolean} | 34 * |
35 * This is null until we get the authoritative value in the first call to | |
36 * setClearing(). In this intermediary state, the commit button is disabled, | |
37 * but everything else can still be enabled. | |
38 * | |
39 * @type {?boolean} | |
35 * @private | 40 * @private |
36 */ | 41 */ |
37 isClearingInProgress_: true, | 42 isClearingInProgress_: null, |
Dan Beam
2014/05/19 17:39:07
overall I think it's pretty dubious to have a vari
engedy
2014/05/19 21:32:59
I have introduces a third boolean that indicates w
| |
38 | 43 |
39 /** | 44 /** |
40 * Initialize the page. | 45 * Initialize the page. |
41 */ | 46 */ |
42 initializePage: function() { | 47 initializePage: function() { |
43 // Call base class implementation to starts preference initialization. | 48 // Call base class implementation to starts preference initialization. |
44 OptionsPage.prototype.initializePage.call(this); | 49 OptionsPage.prototype.initializePage.call(this); |
45 | 50 |
46 var f = this.updateCommitButtonState_.bind(this); | 51 var f = this.updateStateOfControls_.bind(this); |
47 var types = ['browser.clear_data.browsing_history', | 52 var types = ['browser.clear_data.browsing_history', |
48 'browser.clear_data.download_history', | 53 'browser.clear_data.download_history', |
49 'browser.clear_data.cache', | 54 'browser.clear_data.cache', |
50 'browser.clear_data.cookies', | 55 'browser.clear_data.cookies', |
51 'browser.clear_data.passwords', | 56 'browser.clear_data.passwords', |
52 'browser.clear_data.form_data', | 57 'browser.clear_data.form_data', |
53 'browser.clear_data.hosted_apps_data', | 58 'browser.clear_data.hosted_apps_data', |
54 'browser.clear_data.content_licenses']; | 59 'browser.clear_data.content_licenses']; |
55 types.forEach(function(type) { | 60 types.forEach(function(type) { |
56 Preferences.getInstance().addEventListener(type, f); | 61 Preferences.getInstance().addEventListener(type, f); |
57 }); | 62 }); |
58 | 63 |
59 var checkboxes = document.querySelectorAll( | 64 var checkboxes = document.querySelectorAll( |
60 '#cbd-content-area input[type=checkbox]'); | 65 '#cbd-content-area input[type=checkbox]'); |
61 for (var i = 0; i < checkboxes.length; i++) { | 66 for (var i = 0; i < checkboxes.length; i++) { |
62 checkboxes[i].onclick = f; | 67 checkboxes[i].onclick = f; |
63 } | 68 } |
64 | 69 |
65 // At this point, assume that we are currently in the process of clearing | |
66 // data, so as to prevent the controls from being hazardously enabled for | |
67 // a very short time before ClearBrowserDataOverlay.setClearing() is | |
68 // called by the native side with the authoritative state. | |
69 this.setClearing(true); | |
70 | |
71 this.createStuffRemainsFooter_(); | 70 this.createStuffRemainsFooter_(); |
72 | 71 |
73 $('clear-browser-data-dismiss').onclick = function(event) { | 72 $('clear-browser-data-dismiss').onclick = function(event) { |
74 ClearBrowserDataOverlay.dismiss(); | 73 ClearBrowserDataOverlay.dismiss(); |
75 }; | 74 }; |
76 $('clear-browser-data-commit').onclick = function(event) { | 75 $('clear-browser-data-commit').onclick = function(event) { |
77 ClearBrowserDataOverlay.setClearing(true); | 76 ClearBrowserDataOverlay.setClearing(true); |
78 chrome.send('performClearBrowserData'); | 77 chrome.send('performClearBrowserData'); |
79 }; | 78 }; |
80 | 79 |
81 var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes'); | 80 // For managed profiles, hide the checkboxes controlling whether or not |
82 this.showDeleteHistoryCheckboxes_(show); | 81 // browsing and download history should be cleared. Note that this is |
82 // different than just disabling them as a result of enterprise policies. | |
83 if (!loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes')) { | |
84 $('delete-browsing-history-container').hidden = true; | |
85 $('delete-download-history-container').hidden = true; | |
86 } | |
Dan Beam
2014/05/19 17:39:07
can this be in |updateStateOfControls_|?
engedy
2014/05/19 21:32:59
I would prefer keeping this separate. This is a lo
| |
87 | |
88 this.updateStateOfControls_(); | |
83 }, | 89 }, |
84 | 90 |
85 /** | 91 /** |
86 * Create a footer that explains that some content is not cleared by the | 92 * Create a footer that explains that some content is not cleared by the |
87 * clear browsing history dialog. | 93 * clear browsing history dialog. |
88 */ | 94 */ |
89 createStuffRemainsFooter_: function() { | 95 createStuffRemainsFooter_: function() { |
90 // The localized string is of the form "Saved [content settings] and | 96 // The localized string is of the form "Saved [content settings] and |
91 // {search engines} will not be cleared and may reflect your browsing | 97 // {search engines} will not be cleared and may reflect your browsing |
92 // habits.". The following parses out the parts in brackts and braces and | 98 // habits.". The following parses out the parts in brackts and braces and |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 function(event) { | 132 function(event) { |
127 OptionsPage.navigateToPage('content'); | 133 OptionsPage.navigateToPage('content'); |
128 } | 134 } |
129 $('open-search-engines-from-clear-browsing-data').onclick = | 135 $('open-search-engines-from-clear-browsing-data').onclick = |
130 function(event) { | 136 function(event) { |
131 OptionsPage.navigateToPage('searchEngines'); | 137 OptionsPage.navigateToPage('searchEngines'); |
132 } | 138 } |
133 }, | 139 }, |
134 | 140 |
135 /** | 141 /** |
136 * Sets the enabled state of the checkboxes and buttons based on whether or | 142 * Sets whether or not we are in the process of clearing data. |
137 * not we are in the process of clearing data. | 143 * @param {boolean} clearing Whether the browsing data is currently being |
138 * @param {boolean} clearing Whether the browsing history is currently | 144 * cleared. |
139 * being cleared. | |
140 */ | 145 */ |
141 setClearing: function(clearing) { | 146 setClearing: function(clearing) { |
142 $('delete-browsing-history-checkbox').disabled = clearing; | |
143 $('delete-download-history-checkbox').disabled = clearing; | |
144 $('delete-cache-checkbox').disabled = clearing; | |
145 $('delete-cookies-checkbox').disabled = clearing; | |
146 $('delete-passwords-checkbox').disabled = clearing; | |
147 $('delete-form-data-checkbox').disabled = clearing; | |
148 $('delete-hosted-apps-data-checkbox').disabled = clearing; | |
149 $('deauthorize-content-licenses-checkbox').disabled = clearing; | |
150 $('clear-browser-data-time-period').disabled = clearing; | |
151 $('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden'; | |
152 $('clear-browser-data-dismiss').disabled = clearing; | |
153 | |
154 // The enabled state of the commit button is further based on whether or | |
155 // not any of the check boxes are checked. | |
156 this.isClearingInProgress_ = clearing; | 147 this.isClearingInProgress_ = clearing; |
157 this.updateCommitButtonState_(); | 148 this.updateStateOfControls_(); |
158 }, | 149 }, |
159 | 150 |
160 /** | 151 /** |
161 * Sets the enabled state of the commit button. | 152 * Sets whether deleting history and downloads is disallowed by enterprise |
153 * policies. This is called on initialization and in response to a change in | |
154 * the corresponding preference. | |
155 * @param {boolean} allowed Whether to allow deleting history and downloads. | |
162 */ | 156 */ |
163 updateCommitButtonState_: function() { | 157 setAllowDeletingHistory: function(allowed) { |
Dan Beam
2014/05/19 17:39:07
nit: setAllowDeletingHistory_ + @private if only u
engedy
2014/05/19 21:32:59
Done.
| |
158 this.allowDeletingHistory_ = allowed; | |
159 this.updateStateOfControls_(); | |
160 }, | |
161 | |
162 /** | |
163 * Updates the enabled/disabled/hidden status of all controls on the dialog. | |
Dan Beam
2014/05/19 17:39:07
@private
engedy
2014/05/19 21:32:59
Done.
| |
164 */ | |
165 updateStateOfControls_: function() { | |
166 // The commit button is enabled if at least one data type selected to be | |
167 // cleared, and if we are not already in the process of clearing. | |
Dan Beam
2014/05/19 17:39:07
can we do the |isClearingInProgress_| check first?
engedy
2014/05/19 21:32:59
Done.
| |
164 var checkboxes = document.querySelectorAll( | 168 var checkboxes = document.querySelectorAll( |
165 '#cbd-content-area input[type=checkbox]'); | 169 '#cbd-content-area input[type=checkbox]'); |
166 var isChecked = false; | 170 var isChecked = false; |
167 for (var i = 0; i < checkboxes.length; i++) { | 171 for (var i = 0; i < checkboxes.length; i++) { |
168 if (checkboxes[i].checked) { | 172 if (checkboxes[i].checked) { |
169 isChecked = true; | 173 isChecked = true; |
170 break; | 174 break; |
171 } | 175 } |
172 } | 176 } |
177 // To prevent the commit button from being hazardously enabled for a very | |
178 // short time before setClearing() is called the first time by the native | |
179 // side, also disable the button if |isClearingInProgress_| is null. | |
173 $('clear-browser-data-commit').disabled = | 180 $('clear-browser-data-commit').disabled = |
174 !isChecked || this.isClearingInProgress_; | 181 !isChecked || (this.isClearingInProgress_ !== false); |
175 }, | |
176 | 182 |
177 setAllowDeletingHistory: function(allowed) { | 183 // The checkboxes for clearing history/downloads are enabled unless they |
178 this.allowDeletingHistory_ = allowed; | 184 // are disallowed by policies, or we are in the process of clearing data. |
179 }, | 185 // To prevent flickering, these, and the rest of the controls can safely |
186 // be enabled for a short time before the first call to setClearing(). | |
187 var enabled = this.allowDeletingHistory_ && !this.isClearingInProgress_; | |
188 $('delete-browsing-history-checkbox').disabled = !enabled; | |
189 $('delete-download-history-checkbox').disabled = !enabled; | |
190 if (!this.allowDeletingHistory_) { | |
191 $('delete-browsing-history-checkbox').checked = false; | |
192 $('delete-download-history-checkbox').checked = false; | |
193 } | |
180 | 194 |
181 showDeleteHistoryCheckboxes_: function(show) { | 195 // Enable everything else unless we are in the process of clearing. |
182 if (!show) { | 196 var clearing = !!this.isClearingInProgress_; |
183 $('delete-browsing-history-container').hidden = true; | 197 $('delete-cache-checkbox').disabled = clearing; |
184 $('delete-download-history-container').hidden = true; | 198 $('delete-cookies-checkbox').disabled = clearing; |
185 } | 199 $('delete-passwords-checkbox').disabled = clearing; |
186 }, | 200 $('delete-form-data-checkbox').disabled = clearing; |
187 | 201 $('delete-hosted-apps-data-checkbox').disabled = clearing; |
188 /** @override */ | 202 $('deauthorize-content-licenses-checkbox').disabled = clearing; |
189 didShowPage: function() { | 203 $('clear-browser-data-time-period').disabled = clearing; |
190 var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_; | 204 $('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden'; |
191 ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed); | 205 $('clear-browser-data-dismiss').disabled = clearing; |
192 }, | 206 } |
193 }; | 207 }; |
194 | 208 |
195 // | 209 // |
196 // Chrome callbacks | 210 // Chrome callbacks |
197 // | 211 // |
198 /** | 212 ClearBrowserDataOverlay.setAllowDeletingHistory = function(allowed) { |
199 * Updates the disabled status of the browsing-history and downloads | |
200 * checkboxes, also unchecking them if they are disabled. This is called in | |
201 * response to a change in the corresponding preference. | |
202 */ | |
203 ClearBrowserDataOverlay.updateHistoryCheckboxes = function(allowed) { | |
204 $('delete-browsing-history-checkbox').disabled = !allowed; | |
205 $('delete-download-history-checkbox').disabled = !allowed; | |
206 if (!allowed) { | |
207 $('delete-browsing-history-checkbox').checked = false; | |
208 $('delete-download-history-checkbox').checked = false; | |
209 } | |
210 ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed); | 213 ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed); |
211 }; | 214 }; |
212 | 215 |
213 ClearBrowserDataOverlay.setClearing = function(clearing) { | 216 ClearBrowserDataOverlay.setClearing = function(clearing) { |
214 ClearBrowserDataOverlay.getInstance().setClearing(clearing); | 217 ClearBrowserDataOverlay.getInstance().setClearing(clearing); |
215 }; | 218 }; |
216 | 219 |
217 ClearBrowserDataOverlay.setBannerVisibility = function(args) { | 220 ClearBrowserDataOverlay.setBannerVisibility = function(args) { |
218 var visible = args[0]; | 221 var visible = args[0]; |
219 $('clear-browser-data-info-banner').hidden = !visible; | 222 $('clear-browser-data-info-banner').hidden = !visible; |
220 }; | 223 }; |
221 | 224 |
222 ClearBrowserDataOverlay.doneClearing = function() { | 225 ClearBrowserDataOverlay.doneClearing = function() { |
223 // The delay gives the user some feedback that the clearing | 226 // The delay gives the user some feedback that the clearing |
224 // actually worked. Otherwise the dialog just vanishes instantly in most | 227 // actually worked. Otherwise the dialog just vanishes instantly in most |
225 // cases. | 228 // cases. |
226 window.setTimeout(function() { | 229 window.setTimeout(function() { |
230 ClearBrowserDataOverlay.getInstance().setClearing(false); | |
Dan Beam
2014/05/19 17:39:07
nit: ClearBrowserDataOverlay.setClearing(false);
engedy
2014/05/19 21:32:59
Done.
| |
227 ClearBrowserDataOverlay.dismiss(); | 231 ClearBrowserDataOverlay.dismiss(); |
228 }, 200); | 232 }, 200); |
229 }; | 233 }; |
230 | 234 |
231 ClearBrowserDataOverlay.dismiss = function() { | 235 ClearBrowserDataOverlay.dismiss = function() { |
232 var topmostVisiblePage = OptionsPage.getTopmostVisiblePage(); | 236 var topmostVisiblePage = OptionsPage.getTopmostVisiblePage(); |
233 if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData') | 237 if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData') |
234 OptionsPage.closeOverlay(); | 238 OptionsPage.closeOverlay(); |
235 this.setClearing(false); | |
236 }; | 239 }; |
237 | 240 |
238 // Export | 241 // Export |
239 return { | 242 return { |
240 ClearBrowserDataOverlay: ClearBrowserDataOverlay | 243 ClearBrowserDataOverlay: ClearBrowserDataOverlay |
241 }; | 244 }; |
242 }); | 245 }); |
OLD | NEW |