diff options
Diffstat (limited to 'chromium/chrome/browser/resources/options/clear_browser_data_overlay.js')
-rw-r--r-- | chromium/chrome/browser/resources/options/clear_browser_data_overlay.js | 186 |
1 files changed, 123 insertions, 63 deletions
diff --git a/chromium/chrome/browser/resources/options/clear_browser_data_overlay.js b/chromium/chrome/browser/resources/options/clear_browser_data_overlay.js index 563a41a88ff..13f186e7ab0 100644 --- a/chromium/chrome/browser/resources/options/clear_browser_data_overlay.js +++ b/chromium/chrome/browser/resources/options/clear_browser_data_overlay.js @@ -22,17 +22,39 @@ cr.define('options', function() { // Inherit ClearBrowserDataOverlay from OptionsPage. __proto__: OptionsPage.prototype, - // Whether deleting history and downloads is allowed. + /** + * Whether deleting history and downloads is allowed. + * @type {boolean} + * @private + */ allowDeletingHistory_: true, /** + * Whether or not clearing browsing data is currently in progress. + * @type {boolean} + * @private + */ + isClearingInProgress_: false, + + /** + * Whether or not the WebUI handler has completed initialization. + * + * Unless this becomes true, it must be assumed that the above flags might + * not contain the authoritative values. + * + * @type {boolean} + * @private + */ + isInitializationComplete_: false, + + /** * Initialize the page. */ initializePage: function() { // Call base class implementation to starts preference initialization. OptionsPage.prototype.initializePage.call(this); - var f = this.updateCommitButtonState_.bind(this); + var f = this.updateStateOfControls_.bind(this); var types = ['browser.clear_data.browsing_history', 'browser.clear_data.download_history', 'browser.clear_data.cache', @@ -50,7 +72,6 @@ cr.define('options', function() { for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].onclick = f; } - this.updateCommitButtonState_(); this.createStuffRemainsFooter_(); @@ -58,16 +79,25 @@ cr.define('options', function() { ClearBrowserDataOverlay.dismiss(); }; $('clear-browser-data-commit').onclick = function(event) { - ClearBrowserDataOverlay.setClearingState(true); + ClearBrowserDataOverlay.setClearing(true); chrome.send('performClearBrowserData'); }; - var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes'); - this.showDeleteHistoryCheckboxes_(show); + // For managed profiles, hide the checkboxes controlling whether or not + // browsing and download history should be cleared. Note that this is + // different than just disabling them as a result of enterprise policies. + if (!loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes')) { + $('delete-browsing-history-container').hidden = true; + $('delete-download-history-container').hidden = true; + } + + this.updateStateOfControls_(); }, - // Create a footer that explains that some content is not cleared by the - // clear browsing history dialog. + /** + * Create a footer that explains that some content is not cleared by the + * clear browsing history dialog. + */ createStuffRemainsFooter_: function() { // The localized string is of the form "Saved [content settings] and // {search engines} will not be cleared and may reflect your browsing @@ -114,73 +144,101 @@ cr.define('options', function() { } }, - // Set the enabled state of the commit button. - updateCommitButtonState_: function() { - var checkboxes = document.querySelectorAll( - '#cbd-content-area input[type=checkbox]'); - var isChecked = false; - for (var i = 0; i < checkboxes.length; i++) { - if (checkboxes[i].checked) { - isChecked = true; - break; - } - } - $('clear-browser-data-commit').disabled = !isChecked; + /** + * Sets whether or not we are in the process of clearing data. + * @param {boolean} clearing Whether the browsing data is currently being + * cleared. + * @private + */ + setClearing_: function(clearing) { + this.isClearingInProgress_ = clearing; + this.updateStateOfControls_(); }, - setAllowDeletingHistory: function(allowed) { + /** + * Sets whether deleting history and downloads is disallowed by enterprise + * policies. This is called on initialization and in response to a change in + * the corresponding preference. + * @param {boolean} allowed Whether to allow deleting history and downloads. + * @private + */ + setAllowDeletingHistory_: function(allowed) { this.allowDeletingHistory_ = allowed; + this.updateStateOfControls_(); }, - showDeleteHistoryCheckboxes_: function(show) { - if (!show) { - $('delete-browsing-history-container').hidden = true; - $('delete-download-history-container').hidden = true; - } + /** + * Called by the WebUI handler to signal that it has finished calling all + * initialization methods. + * @private + */ + markInitializationComplete_: function() { + this.isInitializationComplete_ = true; + this.updateStateOfControls_(); }, - /** @override */ - didShowPage: function() { - var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_; - ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed); - }, + /** + * Updates the enabled/disabled/hidden status of all controls on the dialog. + * @private + */ + updateStateOfControls_: function() { + // The commit button is enabled if at least one data type selected to be + // cleared, and if we are not already in the process of clearing. + // To prevent the commit button from being hazardously enabled for a very + // short time before setClearing() is called the first time by the native + // side, also disable the button if |isInitializationComplete_| is false. + var enabled = false; + if (this.isInitializationComplete_ && !this.isClearingInProgress_) { + var checkboxes = document.querySelectorAll( + '#cbd-content-area input[type=checkbox]'); + for (var i = 0; i < checkboxes.length; i++) { + if (checkboxes[i].checked) { + enabled = true; + break; + } + } + } + $('clear-browser-data-commit').disabled = !enabled; + + // The checkboxes for clearing history/downloads are enabled unless they + // are disallowed by policies, or we are in the process of clearing data. + // To prevent flickering, these, and the rest of the controls can safely + // be enabled for a short time before the first call to setClearing(). + var enabled = this.allowDeletingHistory_ && !this.isClearingInProgress_; + $('delete-browsing-history-checkbox').disabled = !enabled; + $('delete-download-history-checkbox').disabled = !enabled; + if (!this.allowDeletingHistory_) { + $('delete-browsing-history-checkbox').checked = false; + $('delete-download-history-checkbox').checked = false; + } + + // Enable everything else unless we are in the process of clearing. + var clearing = this.isClearingInProgress_; + $('delete-cache-checkbox').disabled = clearing; + $('delete-cookies-checkbox').disabled = clearing; + $('delete-passwords-checkbox').disabled = clearing; + $('delete-form-data-checkbox').disabled = clearing; + $('delete-hosted-apps-data-checkbox').disabled = clearing; + $('deauthorize-content-licenses-checkbox').disabled = clearing; + $('clear-browser-data-time-period').disabled = clearing; + $('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden'; + $('clear-browser-data-dismiss').disabled = clearing; + } }; // // Chrome callbacks // - /** - * Updates the disabled status of the browsing-history and downloads - * checkboxes, also unchecking them if they are disabled. This is called in - * response to a change in the corresponding preference. - */ - ClearBrowserDataOverlay.updateHistoryCheckboxes = function(allowed) { - $('delete-browsing-history-checkbox').disabled = !allowed; - $('delete-download-history-checkbox').disabled = !allowed; - if (!allowed) { - $('delete-browsing-history-checkbox').checked = false; - $('delete-download-history-checkbox').checked = false; - } - ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed); + ClearBrowserDataOverlay.setAllowDeletingHistory = function(allowed) { + ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory_(allowed); + }; + + ClearBrowserDataOverlay.setClearing = function(clearing) { + ClearBrowserDataOverlay.getInstance().setClearing_(clearing); }; - ClearBrowserDataOverlay.setClearingState = function(state) { - $('delete-browsing-history-checkbox').disabled = state; - $('delete-download-history-checkbox').disabled = state; - $('delete-cache-checkbox').disabled = state; - $('delete-cookies-checkbox').disabled = state; - $('delete-passwords-checkbox').disabled = state; - $('delete-form-data-checkbox').disabled = state; - $('delete-hosted-apps-data-checkbox').disabled = state; - $('deauthorize-content-licenses-checkbox').disabled = state; - $('clear-browser-data-time-period').disabled = state; - $('cbd-throbber').style.visibility = state ? 'visible' : 'hidden'; - $('clear-browser-data-dismiss').disabled = state; - - if (state) - $('clear-browser-data-commit').disabled = true; - else - ClearBrowserDataOverlay.getInstance().updateCommitButtonState_(); + ClearBrowserDataOverlay.markInitializationComplete = function() { + ClearBrowserDataOverlay.getInstance().markInitializationComplete_(); }; ClearBrowserDataOverlay.setBannerVisibility = function(args) { @@ -193,13 +251,15 @@ cr.define('options', function() { // actually worked. Otherwise the dialog just vanishes instantly in most // cases. window.setTimeout(function() { + ClearBrowserDataOverlay.setClearing(false); ClearBrowserDataOverlay.dismiss(); }, 200); }; ClearBrowserDataOverlay.dismiss = function() { - OptionsPage.closeOverlay(); - this.setClearingState(false); + var topmostVisiblePage = OptionsPage.getTopmostVisiblePage(); + if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData') + OptionsPage.closeOverlay(); }; // Export |