browser/metro/base/content/sanitizeUI.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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/. */
     6 "use strict";
     8 var SanitizeUI = {
     9   _sanitizer: null,
    11   _privDataElement: null,
    12   get _privData() {
    13     if (this._privDataElement === null) {
    14       this._privDataElement = document.getElementById("prefs-privdata");
    15     }
    16     return this._privDataElement;
    17   },
    19   init: function () {
    20     this._sanitizer = new Sanitizer();
    21     this._privData.addEventListener("CheckboxStateChange", this, true);
    22   },
    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]");
    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;
    44     // Run asynchronously to let UI update
    45     setTimeout(function() {
    46       for (let item of allSelected) {
    47         let itemName = item.getAttribute("itemName");
    49         try {
    50           SanitizeUI._sanitizer.clearItem(itemName);
    51         } catch(e) {
    52           Components.utils.reportError("Error sanitizing " + itemName + ": " + e);
    53         }
    54       }
    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;
    63       // Clear notifications after 4 seconds
    64       clearTimeout(SanitizeUI._clearNotificationTimeout);
    65       SanitizeUI._clearNotificationTimeout = setTimeout(function() {
    66         clearNotificationDeck.selectedPanel = clearNotificationEmpty;
    67       }, 4000);
    68     }, 0);
    69   },
    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]");
    77     let clearButton = document.getElementById("prefs-clear-data");
    78     clearButton.disabled = !anySelected;
    79   },
    81   handleEvent: function (aEvent) {
    82     switch (aEvent.type) {
    83       case "CheckboxStateChange":
    84         this._onCheckboxChange();
    85         break;
    86     }
    87   },
    88 };

mercurial