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 this.createStuffRemainsFooter_();
57 $('clear-browser-data-dismiss').onclick = function(event) {
58 ClearBrowserDataOverlay.dismiss();
60 $('clear-browser-data-commit').onclick = function(event) {
61 ClearBrowserDataOverlay.setClearingState(true);
62 chrome.send('performClearBrowserData');
65 var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes');
66 this.showDeleteHistoryCheckboxes_(show);
69 // Create a footer that explains that some content is not cleared by the
70 // clear browsing history dialog.
71 createStuffRemainsFooter_: function() {
72 // The localized string is of the form "Saved [content settings] and
73 // {search engines} will not be cleared and may reflect your browsing
74 // habits.". The following parses out the parts in brackts and braces and
75 // converts them into buttons whereas the remainders are represented as
78 document.querySelector('#some-stuff-remains-footer p');
80 loadTimeData.getString('contentSettingsAndSearchEnginesRemain')
82 for (var i = 0; i < footerFragments.length;) {
84 if (i + 2 < footerFragments.length) {
85 if (footerFragments[i] == '|' && footerFragments[i + 2] == '|') {
86 buttonId = 'open-content-settings-from-clear-browsing-data';
87 } else if (footerFragments[i] == '#' &&
88 footerFragments[i + 2] == '#') {
89 buttonId = 'open-search-engines-from-clear-browsing-data';
94 var button = document.createElement('button');
95 button.setAttribute('id', buttonId);
96 button.setAttribute('class', 'link-button');
97 button.textContent = footerFragments[i + 1];
98 footer.appendChild(button);
101 var span = document.createElement('span');
102 span.textContent = footerFragments[i];
103 footer.appendChild(span);
107 $('open-content-settings-from-clear-browsing-data').onclick =
109 OptionsPage.navigateToPage('content');
111 $('open-search-engines-from-clear-browsing-data').onclick =
113 OptionsPage.navigateToPage('searchEngines');
117 // Set the enabled state of the commit button.
118 updateCommitButtonState_: function() {
119 var checkboxes = document.querySelectorAll(
120 '#cbd-content-area input[type=checkbox]');
121 var isChecked = false;
122 for (var i = 0; i < checkboxes.length; i++) {
123 if (checkboxes[i].checked) {
128 $('clear-browser-data-commit').disabled = !isChecked;
131 setAllowDeletingHistory: function(allowed) {
132 this.allowDeletingHistory_ = allowed;
135 showDeleteHistoryCheckboxes_: function(show) {
137 $('delete-browsing-history-container').hidden = true;
138 $('delete-download-history-container').hidden = true;
143 didShowPage: function() {
144 var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_;
145 ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed);
153 * Updates the disabled status of the browsing-history and downloads
154 * checkboxes, also unchecking them if they are disabled. This is called in
155 * response to a change in the corresponding preference.
157 ClearBrowserDataOverlay.updateHistoryCheckboxes = function(allowed) {
158 $('delete-browsing-history-checkbox').disabled = !allowed;
159 $('delete-download-history-checkbox').disabled = !allowed;
161 $('delete-browsing-history-checkbox').checked = false;
162 $('delete-download-history-checkbox').checked = false;
164 ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed);
167 ClearBrowserDataOverlay.setClearingState = function(state) {
168 $('delete-browsing-history-checkbox').disabled = state;
169 $('delete-download-history-checkbox').disabled = state;
170 $('delete-cache-checkbox').disabled = state;
171 $('delete-cookies-checkbox').disabled = state;
172 $('delete-passwords-checkbox').disabled = state;
173 $('delete-form-data-checkbox').disabled = state;
174 $('delete-hosted-apps-data-checkbox').disabled = state;
175 $('deauthorize-content-licenses-checkbox').disabled = state;
176 $('clear-browser-data-time-period').disabled = state;
177 $('cbd-throbber').style.visibility = state ? 'visible' : 'hidden';
178 $('clear-browser-data-dismiss').disabled = state;
181 $('clear-browser-data-commit').disabled = true;
183 ClearBrowserDataOverlay.getInstance().updateCommitButtonState_();
186 ClearBrowserDataOverlay.setBannerVisibility = function(args) {
187 var visible = args[0];
188 $('clear-browser-data-info-banner').hidden = !visible;
191 ClearBrowserDataOverlay.doneClearing = function() {
192 // The delay gives the user some feedback that the clearing
193 // actually worked. Otherwise the dialog just vanishes instantly in most
195 window.setTimeout(function() {
196 ClearBrowserDataOverlay.dismiss();
200 ClearBrowserDataOverlay.dismiss = function() {
201 var topmostVisiblePage = OptionsPage.getTopmostVisiblePage();
202 if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData')
203 OptionsPage.closeOverlay();
204 this.setClearingState(false);
209 ClearBrowserDataOverlay: ClearBrowserDataOverlay