Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 * @type {boolean} |
| 35 * @private | 35 * @private |
| 36 */ | 36 */ |
| 37 isClearingInProgress_: true, | 37 isClearingInProgress_: false, |
| 38 | |
| 39 /** | |
| 40 * Whether or not the WebUI handler have completed initialization. | |
| 41 * | |
| 42 * Unless this becomes true, it must be assumed that the above flags might | |
| 43 * not contain the authoritative values. | |
| 44 * | |
| 45 * @type {boolean} | |
| 46 * @private | |
| 47 */ | |
| 48 isInitializationComplete_: false, | |
| 38 | 49 |
| 39 /** | 50 /** |
| 40 * Initialize the page. | 51 * Initialize the page. |
| 41 */ | 52 */ |
| 42 initializePage: function() { | 53 initializePage: function() { |
| 43 // Call base class implementation to starts preference initialization. | 54 // Call base class implementation to starts preference initialization. |
| 44 OptionsPage.prototype.initializePage.call(this); | 55 OptionsPage.prototype.initializePage.call(this); |
| 45 | 56 |
| 46 var f = this.updateCommitButtonState_.bind(this); | 57 var f = this.updateStateOfControls_.bind(this); |
| 47 var types = ['browser.clear_data.browsing_history', | 58 var types = ['browser.clear_data.browsing_history', |
| 48 'browser.clear_data.download_history', | 59 'browser.clear_data.download_history', |
| 49 'browser.clear_data.cache', | 60 'browser.clear_data.cache', |
| 50 'browser.clear_data.cookies', | 61 'browser.clear_data.cookies', |
| 51 'browser.clear_data.passwords', | 62 'browser.clear_data.passwords', |
| 52 'browser.clear_data.form_data', | 63 'browser.clear_data.form_data', |
| 53 'browser.clear_data.hosted_apps_data', | 64 'browser.clear_data.hosted_apps_data', |
| 54 'browser.clear_data.content_licenses']; | 65 'browser.clear_data.content_licenses']; |
| 55 types.forEach(function(type) { | 66 types.forEach(function(type) { |
| 56 Preferences.getInstance().addEventListener(type, f); | 67 Preferences.getInstance().addEventListener(type, f); |
| 57 }); | 68 }); |
| 58 | 69 |
| 59 var checkboxes = document.querySelectorAll( | 70 var checkboxes = document.querySelectorAll( |
| 60 '#cbd-content-area input[type=checkbox]'); | 71 '#cbd-content-area input[type=checkbox]'); |
| 61 for (var i = 0; i < checkboxes.length; i++) { | 72 for (var i = 0; i < checkboxes.length; i++) { |
| 62 checkboxes[i].onclick = f; | 73 checkboxes[i].onclick = f; |
| 63 } | 74 } |
| 64 | 75 |
| 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_(); | 76 this.createStuffRemainsFooter_(); |
| 72 | 77 |
| 73 $('clear-browser-data-dismiss').onclick = function(event) { | 78 $('clear-browser-data-dismiss').onclick = function(event) { |
| 74 ClearBrowserDataOverlay.dismiss(); | 79 ClearBrowserDataOverlay.dismiss(); |
| 75 }; | 80 }; |
| 76 $('clear-browser-data-commit').onclick = function(event) { | 81 $('clear-browser-data-commit').onclick = function(event) { |
| 77 ClearBrowserDataOverlay.setClearing(true); | 82 ClearBrowserDataOverlay.setClearing(true); |
| 78 chrome.send('performClearBrowserData'); | 83 chrome.send('performClearBrowserData'); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes'); | 86 // For managed profiles, hide the checkboxes controlling whether or not |
| 82 this.showDeleteHistoryCheckboxes_(show); | 87 // browsing and download history should be cleared. Note that this is |
| 88 // different than just disabling them as a result of enterprise policies. | |
| 89 if (!loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes')) { | |
| 90 $('delete-browsing-history-container').hidden = true; | |
| 91 $('delete-download-history-container').hidden = true; | |
| 92 } | |
| 93 | |
| 94 this.updateStateOfControls_(); | |
| 83 }, | 95 }, |
| 84 | 96 |
| 85 /** | 97 /** |
| 86 * Create a footer that explains that some content is not cleared by the | 98 * Create a footer that explains that some content is not cleared by the |
| 87 * clear browsing history dialog. | 99 * clear browsing history dialog. |
| 88 */ | 100 */ |
| 89 createStuffRemainsFooter_: function() { | 101 createStuffRemainsFooter_: function() { |
| 90 // The localized string is of the form "Saved [content settings] and | 102 // The localized string is of the form "Saved [content settings] and |
| 91 // {search engines} will not be cleared and may reflect your browsing | 103 // {search engines} will not be cleared and may reflect your browsing |
| 92 // habits.". The following parses out the parts in brackts and braces and | 104 // 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) { | 138 function(event) { |
| 127 OptionsPage.navigateToPage('content'); | 139 OptionsPage.navigateToPage('content'); |
| 128 } | 140 } |
| 129 $('open-search-engines-from-clear-browsing-data').onclick = | 141 $('open-search-engines-from-clear-browsing-data').onclick = |
| 130 function(event) { | 142 function(event) { |
| 131 OptionsPage.navigateToPage('searchEngines'); | 143 OptionsPage.navigateToPage('searchEngines'); |
| 132 } | 144 } |
| 133 }, | 145 }, |
| 134 | 146 |
| 135 /** | 147 /** |
| 136 * Sets the enabled state of the checkboxes and buttons based on whether or | 148 * Sets whether or not we are in the process of clearing data. |
| 137 * not we are in the process of clearing data. | 149 * @param {boolean} clearing Whether the browsing data is currently being |
| 138 * @param {boolean} clearing Whether the browsing history is currently | 150 * cleared. |
| 139 * being cleared. | 151 * @private |
| 140 */ | 152 */ |
| 141 setClearing: function(clearing) { | 153 setClearing_: function(clearing) { |
| 142 $('delete-browsing-history-checkbox').disabled = clearing; | 154 this.isClearingInProgress_ = clearing; |
| 143 $('delete-download-history-checkbox').disabled = clearing; | 155 this.updateStateOfControls_(); |
| 156 }, | |
| 157 | |
| 158 /** | |
| 159 * Sets whether deleting history and downloads is disallowed by enterprise | |
| 160 * policies. This is called on initialization and in response to a change in | |
| 161 * the corresponding preference. | |
| 162 * @param {boolean} allowed Whether to allow deleting history and downloads. | |
| 163 * @private | |
| 164 */ | |
| 165 setAllowDeletingHistory_: function(allowed) { | |
| 166 this.allowDeletingHistory_ = allowed; | |
| 167 this.updateStateOfControls_(); | |
| 168 }, | |
| 169 | |
| 170 /** | |
| 171 * Called by the WebUI handler to signal that it has finished calling all | |
| 172 * initialization methods. | |
| 173 * @private | |
| 174 */ | |
| 175 markInitializationComplete_: function() { | |
| 176 this.isInitializationComplete_ = true; | |
| 177 this.updateStateOfControls_(); | |
| 178 }, | |
| 179 | |
| 180 /** | |
| 181 * Updates the enabled/disabled/hidden status of all controls on the dialog. | |
| 182 * @private | |
| 183 */ | |
| 184 updateStateOfControls_: function() { | |
| 185 // The commit button is enabled if at least one data type selected to be | |
| 186 // cleared, and if we are not already in the process of clearing. | |
| 187 // To prevent the commit button from being hazardously enabled for a very | |
| 188 // short time before setClearing() is called the first time by the native | |
| 189 // side, also disable the button if |isInitializationComplete_| is false. | |
| 190 if (this.isClearingInProgress_ || !this.isInitializationComplete) { | |
|
Dan Beam
2014/05/19 21:41:16
isInitializationComplete -> isInitializationComple
engedy
2014/05/19 23:19:22
Done. Thanks, sorry, working through SSH...
| |
| 191 $('clear-browser-data-commit').disabled = true; | |
| 192 } else { | |
| 193 var checkboxes = document.querySelectorAll( | |
| 194 '#cbd-content-area input[type=checkbox]'); | |
| 195 var isChecked = false; | |
| 196 for (var i = 0; i < checkboxes.length; i++) { | |
| 197 if (checkboxes[i].checked) { | |
| 198 isChecked = true; | |
|
Dan Beam
2014/05/19 21:41:16
just remove isCheck and inline
$('clear-browser
Dan Beam
2014/05/19 21:41:34
isChecked**
engedy
2014/05/19 23:19:22
In that case we would need a "disabled = false" ca
engedy
2014/05/19 23:20:20
... Are visual styles *applied* possibly...
On 20
Dan Beam
2014/05/20 00:07:49
that seems highly unlikely but here's an alternati
engedy
2014/05/20 01:02:33
Done something along these lines.
| |
| 199 break; | |
| 200 } | |
| 201 } | |
| 202 $('clear-browser-data-commit').disabled = !isChecked; | |
| 203 } | |
| 204 | |
| 205 // The checkboxes for clearing history/downloads are enabled unless they | |
| 206 // are disallowed by policies, or we are in the process of clearing data. | |
| 207 // To prevent flickering, these, and the rest of the controls can safely | |
| 208 // be enabled for a short time before the first call to setClearing(). | |
| 209 var enabled = this.allowDeletingHistory_ && !this.isClearingInProgress_; | |
|
Dan Beam
2014/05/19 21:41:16
don't we need to check isInitializationComplete_ h
engedy
2014/05/19 23:19:22
To avoid all the controls becoming disabled then e
Dan Beam
2014/05/20 00:07:49
can we make them readonly instead of disabled in t
engedy
2014/05/20 01:02:33
As discussed off-line, there is no risk in leaving
| |
| 210 $('delete-browsing-history-checkbox').disabled = !enabled; | |
| 211 $('delete-download-history-checkbox').disabled = !enabled; | |
| 212 if (!this.allowDeletingHistory_) { | |
| 213 $('delete-browsing-history-checkbox').checked = false; | |
| 214 $('delete-download-history-checkbox').checked = false; | |
| 215 } | |
| 216 | |
| 217 // Enable everything else unless we are in the process of clearing. | |
| 218 var clearing = this.isClearingInProgress_; | |
| 144 $('delete-cache-checkbox').disabled = clearing; | 219 $('delete-cache-checkbox').disabled = clearing; |
| 145 $('delete-cookies-checkbox').disabled = clearing; | 220 $('delete-cookies-checkbox').disabled = clearing; |
| 146 $('delete-passwords-checkbox').disabled = clearing; | 221 $('delete-passwords-checkbox').disabled = clearing; |
| 147 $('delete-form-data-checkbox').disabled = clearing; | 222 $('delete-form-data-checkbox').disabled = clearing; |
| 148 $('delete-hosted-apps-data-checkbox').disabled = clearing; | 223 $('delete-hosted-apps-data-checkbox').disabled = clearing; |
| 149 $('deauthorize-content-licenses-checkbox').disabled = clearing; | 224 $('deauthorize-content-licenses-checkbox').disabled = clearing; |
| 150 $('clear-browser-data-time-period').disabled = clearing; | 225 $('clear-browser-data-time-period').disabled = clearing; |
| 151 $('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden'; | 226 $('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden'; |
| 152 $('clear-browser-data-dismiss').disabled = clearing; | 227 $('clear-browser-data-dismiss').disabled = clearing; |
| 153 | 228 } |
| 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; | |
| 157 this.updateCommitButtonState_(); | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * Sets the enabled state of the commit button. | |
| 162 */ | |
| 163 updateCommitButtonState_: function() { | |
| 164 var checkboxes = document.querySelectorAll( | |
| 165 '#cbd-content-area input[type=checkbox]'); | |
| 166 var isChecked = false; | |
| 167 for (var i = 0; i < checkboxes.length; i++) { | |
| 168 if (checkboxes[i].checked) { | |
| 169 isChecked = true; | |
| 170 break; | |
| 171 } | |
| 172 } | |
| 173 $('clear-browser-data-commit').disabled = | |
| 174 !isChecked || this.isClearingInProgress_; | |
| 175 }, | |
| 176 | |
| 177 setAllowDeletingHistory: function(allowed) { | |
| 178 this.allowDeletingHistory_ = allowed; | |
| 179 }, | |
| 180 | |
| 181 showDeleteHistoryCheckboxes_: function(show) { | |
| 182 if (!show) { | |
| 183 $('delete-browsing-history-container').hidden = true; | |
| 184 $('delete-download-history-container').hidden = true; | |
| 185 } | |
| 186 }, | |
| 187 | |
| 188 /** @override */ | |
| 189 didShowPage: function() { | |
| 190 var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_; | |
| 191 ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed); | |
| 192 }, | |
| 193 }; | 229 }; |
| 194 | 230 |
| 195 // | 231 // |
| 196 // Chrome callbacks | 232 // Chrome callbacks |
| 197 // | 233 // |
| 198 /** | 234 ClearBrowserDataOverlay.setAllowDeletingHistory = function(allowed) { |
| 199 * Updates the disabled status of the browsing-history and downloads | 235 ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory_(allowed); |
| 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); | |
| 211 }; | 236 }; |
| 212 | 237 |
| 213 ClearBrowserDataOverlay.setClearing = function(clearing) { | 238 ClearBrowserDataOverlay.setClearing = function(clearing) { |
| 214 ClearBrowserDataOverlay.getInstance().setClearing(clearing); | 239 ClearBrowserDataOverlay.getInstance().setClearing_(clearing); |
| 240 }; | |
| 241 | |
| 242 ClearBrowserDataOverlay.markInitializationComplete = function() { | |
| 243 ClearBrowserDataOverlay.getInstance().markInitializationComplete_(); | |
| 215 }; | 244 }; |
| 216 | 245 |
| 217 ClearBrowserDataOverlay.setBannerVisibility = function(args) { | 246 ClearBrowserDataOverlay.setBannerVisibility = function(args) { |
| 218 var visible = args[0]; | 247 var visible = args[0]; |
| 219 $('clear-browser-data-info-banner').hidden = !visible; | 248 $('clear-browser-data-info-banner').hidden = !visible; |
| 220 }; | 249 }; |
| 221 | 250 |
| 222 ClearBrowserDataOverlay.doneClearing = function() { | 251 ClearBrowserDataOverlay.doneClearing = function() { |
| 223 // The delay gives the user some feedback that the clearing | 252 // The delay gives the user some feedback that the clearing |
| 224 // actually worked. Otherwise the dialog just vanishes instantly in most | 253 // actually worked. Otherwise the dialog just vanishes instantly in most |
| 225 // cases. | 254 // cases. |
| 226 window.setTimeout(function() { | 255 window.setTimeout(function() { |
| 256 ClearBrowserDataOverlay.setClearing(false); | |
| 227 ClearBrowserDataOverlay.dismiss(); | 257 ClearBrowserDataOverlay.dismiss(); |
| 228 }, 200); | 258 }, 200); |
| 229 }; | 259 }; |
| 230 | 260 |
| 231 ClearBrowserDataOverlay.dismiss = function() { | 261 ClearBrowserDataOverlay.dismiss = function() { |
| 232 var topmostVisiblePage = OptionsPage.getTopmostVisiblePage(); | 262 var topmostVisiblePage = OptionsPage.getTopmostVisiblePage(); |
| 233 if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData') | 263 if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData') |
| 234 OptionsPage.closeOverlay(); | 264 OptionsPage.closeOverlay(); |
| 235 this.setClearing(false); | |
| 236 }; | 265 }; |
| 237 | 266 |
| 238 // Export | 267 // Export |
| 239 return { | 268 return { |
| 240 ClearBrowserDataOverlay: ClearBrowserDataOverlay | 269 ClearBrowserDataOverlay: ClearBrowserDataOverlay |
| 241 }; | 270 }; |
| 242 }); | 271 }); |
| OLD | NEW |