1// Copyright (c) 2011 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. 4 5cr.define('options', function() { 6 var OptionsPage = options.OptionsPage; 7 8 /** 9 * ClearBrowserDataOverlay class 10 * Encapsulated handling of the 'Clear Browser Data' overlay page. 11 * @class 12 */ 13 function ClearBrowserDataOverlay() { 14 OptionsPage.call(this, 'clearBrowserData', 15 templateData.clearBrowserDataOverlayTabTitle, 16 'clearBrowserDataOverlay'); 17 } 18 19 cr.addSingletonGetter(ClearBrowserDataOverlay); 20 21 ClearBrowserDataOverlay.prototype = { 22 // Inherit ClearBrowserDataOverlay from OptionsPage. 23 __proto__: OptionsPage.prototype, 24 25 /** 26 * Initialize the page. 27 */ 28 initializePage: function() { 29 // Call base class implementation to starts preference initialization. 30 OptionsPage.prototype.initializePage.call(this); 31 32 var f = this.updateCommitButtonState_.bind(this); 33 var types = ['browser.clear_data.browsing_history', 34 'browser.clear_data.download_history', 35 'browser.clear_data.cache', 36 'browser.clear_data.cookies', 37 'browser.clear_data.passwords', 38 'browser.clear_data.form_data']; 39 types.forEach(function(type) { 40 Preferences.getInstance().addEventListener(type, f); 41 }); 42 43 var checkboxes = document.querySelectorAll( 44 '#cbdContentArea input[type=checkbox]'); 45 for (var i = 0; i < checkboxes.length; i++) { 46 checkboxes[i].onclick = f; 47 } 48 this.updateCommitButtonState_(); 49 50 $('clearBrowserDataDismiss').onclick = function(event) { 51 ClearBrowserDataOverlay.dismiss(); 52 }; 53 $('clearBrowserDataCommit').onclick = function(event) { 54 chrome.send('performClearBrowserData'); 55 }; 56 }, 57 58 // Set the enabled state of the commit button. 59 updateCommitButtonState_: function() { 60 var checkboxes = document.querySelectorAll( 61 '#cbdContentArea input[type=checkbox]'); 62 var isChecked = false; 63 for (var i = 0; i < checkboxes.length; i++) { 64 if (checkboxes[i].checked) { 65 isChecked = true; 66 break; 67 } 68 } 69 $('clearBrowserDataCommit').disabled = !isChecked; 70 }, 71 }; 72 73 // 74 // Chrome callbacks 75 // 76 ClearBrowserDataOverlay.setClearingState = function(state) { 77 $('deleteBrowsingHistoryCheckbox').disabled = state; 78 $('deleteDownloadHistoryCheckbox').disabled = state; 79 $('deleteCacheCheckbox').disabled = state; 80 $('deleteCookiesCheckbox').disabled = state; 81 $('deletePasswordsCheckbox').disabled = state; 82 $('deleteFormDataCheckbox').disabled = state; 83 $('clearBrowserDataTimePeriod').disabled = state; 84 $('cbdThrobber').style.visibility = state ? 'visible' : 'hidden'; 85 86 if (state) 87 $('clearBrowserDataCommit').disabled = true; 88 else 89 ClearBrowserDataOverlay.getInstance().updateCommitButtonState_(); 90 }; 91 92 ClearBrowserDataOverlay.doneClearing = function() { 93 // The delay gives the user some feedback that the clearing 94 // actually worked. Otherwise the dialog just vanishes instantly in most 95 // cases. 96 window.setTimeout(function() { 97 ClearBrowserDataOverlay.dismiss(); 98 }, 200); 99 }; 100 101 ClearBrowserDataOverlay.dismiss = function() { 102 OptionsPage.closeOverlay(); 103 this.setClearingState(false); 104 }; 105 106 // Export 107 return { 108 ClearBrowserDataOverlay: ClearBrowserDataOverlay 109 }; 110}); 111