browser/metro/base/content/sanitizeUI.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 var SanitizeUI = {
michael@0 9 _sanitizer: null,
michael@0 10
michael@0 11 _privDataElement: null,
michael@0 12 get _privData() {
michael@0 13 if (this._privDataElement === null) {
michael@0 14 this._privDataElement = document.getElementById("prefs-privdata");
michael@0 15 }
michael@0 16 return this._privDataElement;
michael@0 17 },
michael@0 18
michael@0 19 init: function () {
michael@0 20 this._sanitizer = new Sanitizer();
michael@0 21 this._privData.addEventListener("CheckboxStateChange", this, true);
michael@0 22 },
michael@0 23
michael@0 24 _clearNotificationTimeout: null,
michael@0 25 onSanitize: function onSanitize() {
michael@0 26 let button = document.getElementById("prefs-clear-data");
michael@0 27 let clearNotificationDeck = document.getElementById("clear-notification");
michael@0 28 let clearNotificationEmpty = document.getElementById("clear-notification-empty");
michael@0 29 let clearNotificationClearing = document.getElementById("clear-notification-clearing");
michael@0 30 let clearNotificationDone = document.getElementById("clear-notification-done");
michael@0 31 let allCheckboxes = SanitizeUI._privData.querySelectorAll("checkbox");
michael@0 32 let allSelected = SanitizeUI._privData.querySelectorAll(
michael@0 33 "#prefs-privdata-history[checked], " +
michael@0 34 "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]");
michael@0 35
michael@0 36 // disable button and checkboxes temporarily to indicate something is happening
michael@0 37 button.disabled = true;
michael@0 38 for (let checkbox of allCheckboxes) {
michael@0 39 checkbox.disabled = true;
michael@0 40 }
michael@0 41 clearNotificationDeck.selectedPanel = clearNotificationClearing;
michael@0 42 document.getElementById("clearprivacythrobber").enabled = true;
michael@0 43
michael@0 44 // Run asynchronously to let UI update
michael@0 45 setTimeout(function() {
michael@0 46 for (let item of allSelected) {
michael@0 47 let itemName = item.getAttribute("itemName");
michael@0 48
michael@0 49 try {
michael@0 50 SanitizeUI._sanitizer.clearItem(itemName);
michael@0 51 } catch(e) {
michael@0 52 Components.utils.reportError("Error sanitizing " + itemName + ": " + e);
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 button.disabled = false;
michael@0 57 for (let checkbox of allCheckboxes) {
michael@0 58 checkbox.disabled = false;
michael@0 59 }
michael@0 60 clearNotificationDeck.selectedPanel = clearNotificationDone;
michael@0 61 document.getElementById("clearprivacythrobber").enabled = false;
michael@0 62
michael@0 63 // Clear notifications after 4 seconds
michael@0 64 clearTimeout(SanitizeUI._clearNotificationTimeout);
michael@0 65 SanitizeUI._clearNotificationTimeout = setTimeout(function() {
michael@0 66 clearNotificationDeck.selectedPanel = clearNotificationEmpty;
michael@0 67 }, 4000);
michael@0 68 }, 0);
michael@0 69 },
michael@0 70
michael@0 71 /* Disable the clear button when nothing is selected */
michael@0 72 _onCheckboxChange: function _onCheckboxChange() {
michael@0 73 let anySelected = SanitizeUI._privData.querySelector(
michael@0 74 "#prefs-privdata-history[checked], " +
michael@0 75 "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]");
michael@0 76
michael@0 77 let clearButton = document.getElementById("prefs-clear-data");
michael@0 78 clearButton.disabled = !anySelected;
michael@0 79 },
michael@0 80
michael@0 81 handleEvent: function (aEvent) {
michael@0 82 switch (aEvent.type) {
michael@0 83 case "CheckboxStateChange":
michael@0 84 this._onCheckboxChange();
michael@0 85 break;
michael@0 86 }
michael@0 87 },
michael@0 88 };

mercurial