browser/metro/base/content/sanitizeUI.js

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

mercurial