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
3 // found in the LICENSE file.
5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage;
9 * ClearBrowserDataOverlay class
10 * Encapsulated handling of the 'Clear Browser Data' overlay page.
13 function ClearBrowserDataOverlay() {
14 OptionsPage.call(this, 'clearBrowserData',
15 loadTimeData.getString('clearBrowserDataOverlayTabTitle'),
16 'clear-browser-data-overlay');
19 cr.addSingletonGetter(ClearBrowserDataOverlay);
21 ClearBrowserDataOverlay.prototype = {
22 // Inherit ClearBrowserDataOverlay from OptionsPage.
23 __proto__: OptionsPage.prototype,
25 // Whether deleting history and downloads is allowed.
26 allowDeletingHistory_: true,
29 * Initialize the page.
31 initializePage: function() {
32 // Call base class implementation to starts preference initialization.
33 OptionsPage.prototype.initializePage.call(this);
35 var f = this.updateCommitButtonState_.bind(this);
36 var types = ['browser.clear_data.browsing_history',
37 'browser.clear_data.download_history',
38 'browser.clear_data.cache',
39 'browser.clear_data.cookies',
40 'browser.clear_data.passwords',
41 'browser.clear_data.form_data',
42 'browser.clear_data.hosted_apps_data',
43 'browser.clear_data.content_licenses'];
44 types.forEach(function(type) {
45 Preferences.getInstance().addEventListener(type, f);
48 var checkboxes = document.querySelectorAll(
49 '#cbd-content-area input[type=checkbox]');
50 for (var i = 0; i < checkboxes.length; i++) {
51 checkboxes[i].onclick = f;
53 this.updateCommitButtonState_();
55 $('clear-browser-data-dismiss').onclick = function(event) {
56 ClearBrowserDataOverlay.dismiss();
58 $('clear-browser-data-commit').onclick = function(event) {
59 ClearBrowserDataOverlay.setClearingState(true);
60 chrome.send('performClearBrowserData');
63 var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes');
64 this.showDeleteHistoryCheckboxes_(show);
67 // Set the enabled state of the commit button.
68 updateCommitButtonState_: function() {
69 var checkboxes = document.querySelectorAll(
70 '#cbd-content-area input[type=checkbox]');
71 var isChecked = false;
72 for (var i = 0; i < checkboxes.length; i++) {
73 if (checkboxes[i].checked) {
78 $('clear-browser-data-commit').disabled = !isChecked;
81 setAllowDeletingHistory: function(allowed) {
82 this.allowDeletingHistory_ = allowed;
85 showDeleteHistoryCheckboxes_: function(show) {
87 $('delete-browsing-history-container').hidden = true;
88 $('delete-download-history-container').hidden = true;
93 didShowPage: function() {
94 var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_;
95 ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed);
103 * Updates the disabled status of the browsing-history and downloads
104 * checkboxes, also unchecking them if they are disabled. This is called in
105 * response to a change in the corresponding preference.
107 ClearBrowserDataOverlay.updateHistoryCheckboxes = function(allowed) {
108 $('delete-browsing-history-checkbox').disabled = !allowed;
109 $('delete-download-history-checkbox').disabled = !allowed;
111 $('delete-browsing-history-checkbox').checked = false;
112 $('delete-download-history-checkbox').checked = false;
114 ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed);
117 ClearBrowserDataOverlay.setClearingState = function(state) {
118 $('delete-browsing-history-checkbox').disabled = state;
119 $('delete-download-history-checkbox').disabled = state;
120 $('delete-cache-checkbox').disabled = state;
121 $('delete-cookies-checkbox').disabled = state;
122 $('delete-passwords-checkbox').disabled = state;
123 $('delete-form-data-checkbox').disabled = state;
124 $('delete-hosted-apps-data-checkbox').disabled = state;
125 $('deauthorize-content-licenses-checkbox').disabled = state;
126 $('clear-browser-data-time-period').disabled = state;
127 $('cbd-throbber').style.visibility = state ? 'visible' : 'hidden';
128 $('clear-browser-data-dismiss').disabled = state;
131 $('clear-browser-data-commit').disabled = true;
133 ClearBrowserDataOverlay.getInstance().updateCommitButtonState_();
136 ClearBrowserDataOverlay.setBannerVisibility = function(args) {
137 var visible = args[0];
138 $('clear-browser-data-info-banner').hidden = !visible;
141 ClearBrowserDataOverlay.doneClearing = function() {
142 // The delay gives the user some feedback that the clearing
143 // actually worked. Otherwise the dialog just vanishes instantly in most
145 window.setTimeout(function() {
146 ClearBrowserDataOverlay.dismiss();
150 ClearBrowserDataOverlay.dismiss = function() {
151 OptionsPage.closeOverlay();
152 this.setClearingState(false);
157 ClearBrowserDataOverlay: ClearBrowserDataOverlay