michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: var SanitizeUI = { michael@0: _sanitizer: null, michael@0: michael@0: _privDataElement: null, michael@0: get _privData() { michael@0: if (this._privDataElement === null) { michael@0: this._privDataElement = document.getElementById("prefs-privdata"); michael@0: } michael@0: return this._privDataElement; michael@0: }, michael@0: michael@0: init: function () { michael@0: this._sanitizer = new Sanitizer(); michael@0: this._privData.addEventListener("CheckboxStateChange", this, true); michael@0: }, michael@0: michael@0: _clearNotificationTimeout: null, michael@0: onSanitize: function onSanitize() { michael@0: let button = document.getElementById("prefs-clear-data"); michael@0: let clearNotificationDeck = document.getElementById("clear-notification"); michael@0: let clearNotificationEmpty = document.getElementById("clear-notification-empty"); michael@0: let clearNotificationClearing = document.getElementById("clear-notification-clearing"); michael@0: let clearNotificationDone = document.getElementById("clear-notification-done"); michael@0: let allCheckboxes = SanitizeUI._privData.querySelectorAll("checkbox"); michael@0: let allSelected = SanitizeUI._privData.querySelectorAll( michael@0: "#prefs-privdata-history[checked], " + michael@0: "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]"); michael@0: michael@0: // disable button and checkboxes temporarily to indicate something is happening michael@0: button.disabled = true; michael@0: for (let checkbox of allCheckboxes) { michael@0: checkbox.disabled = true; michael@0: } michael@0: clearNotificationDeck.selectedPanel = clearNotificationClearing; michael@0: document.getElementById("clearprivacythrobber").enabled = true; michael@0: michael@0: // Run asynchronously to let UI update michael@0: setTimeout(function() { michael@0: for (let item of allSelected) { michael@0: let itemName = item.getAttribute("itemName"); michael@0: michael@0: try { michael@0: SanitizeUI._sanitizer.clearItem(itemName); michael@0: } catch(e) { michael@0: Components.utils.reportError("Error sanitizing " + itemName + ": " + e); michael@0: } michael@0: } michael@0: michael@0: button.disabled = false; michael@0: for (let checkbox of allCheckboxes) { michael@0: checkbox.disabled = false; michael@0: } michael@0: clearNotificationDeck.selectedPanel = clearNotificationDone; michael@0: document.getElementById("clearprivacythrobber").enabled = false; michael@0: michael@0: // Clear notifications after 4 seconds michael@0: clearTimeout(SanitizeUI._clearNotificationTimeout); michael@0: SanitizeUI._clearNotificationTimeout = setTimeout(function() { michael@0: clearNotificationDeck.selectedPanel = clearNotificationEmpty; michael@0: }, 4000); michael@0: }, 0); michael@0: }, michael@0: michael@0: /* Disable the clear button when nothing is selected */ michael@0: _onCheckboxChange: function _onCheckboxChange() { michael@0: let anySelected = SanitizeUI._privData.querySelector( michael@0: "#prefs-privdata-history[checked], " + michael@0: "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]"); michael@0: michael@0: let clearButton = document.getElementById("prefs-clear-data"); michael@0: clearButton.disabled = !anySelected; michael@0: }, michael@0: michael@0: handleEvent: function (aEvent) { michael@0: switch (aEvent.type) { michael@0: case "CheckboxStateChange": michael@0: this._onCheckboxChange(); michael@0: break; michael@0: } michael@0: }, michael@0: };