browser/metro/base/content/sanitizeUI.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/sanitizeUI.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +var SanitizeUI = {
    1.12 +  _sanitizer: null,
    1.13 +
    1.14 +  _privDataElement: null,
    1.15 +  get _privData() {
    1.16 +    if (this._privDataElement === null) {
    1.17 +      this._privDataElement = document.getElementById("prefs-privdata");
    1.18 +    }
    1.19 +    return this._privDataElement;
    1.20 +  },
    1.21 +
    1.22 +  init: function () {
    1.23 +    this._sanitizer = new Sanitizer();
    1.24 +    this._privData.addEventListener("CheckboxStateChange", this, true);
    1.25 +  },
    1.26 +
    1.27 +  _clearNotificationTimeout: null,
    1.28 +  onSanitize: function onSanitize() {
    1.29 +    let button = document.getElementById("prefs-clear-data");
    1.30 +    let clearNotificationDeck = document.getElementById("clear-notification");
    1.31 +    let clearNotificationEmpty = document.getElementById("clear-notification-empty");
    1.32 +    let clearNotificationClearing = document.getElementById("clear-notification-clearing");
    1.33 +    let clearNotificationDone = document.getElementById("clear-notification-done");
    1.34 +    let allCheckboxes = SanitizeUI._privData.querySelectorAll("checkbox");
    1.35 +    let allSelected = SanitizeUI._privData.querySelectorAll(
    1.36 +      "#prefs-privdata-history[checked], " +
    1.37 +      "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]");
    1.38 +
    1.39 +    // disable button and checkboxes temporarily to indicate something is happening
    1.40 +    button.disabled = true;
    1.41 +    for (let checkbox of allCheckboxes) {
    1.42 +      checkbox.disabled = true;
    1.43 +    }
    1.44 +    clearNotificationDeck.selectedPanel = clearNotificationClearing;
    1.45 +    document.getElementById("clearprivacythrobber").enabled = true;
    1.46 +
    1.47 +    // Run asynchronously to let UI update
    1.48 +    setTimeout(function() {
    1.49 +      for (let item of allSelected) {
    1.50 +        let itemName = item.getAttribute("itemName");
    1.51 +
    1.52 +        try {
    1.53 +          SanitizeUI._sanitizer.clearItem(itemName);
    1.54 +        } catch(e) {
    1.55 +          Components.utils.reportError("Error sanitizing " + itemName + ": " + e);
    1.56 +        }
    1.57 +      }
    1.58 +
    1.59 +      button.disabled = false;
    1.60 +      for (let checkbox of allCheckboxes) {
    1.61 +        checkbox.disabled = false;
    1.62 +      }
    1.63 +      clearNotificationDeck.selectedPanel = clearNotificationDone;
    1.64 +      document.getElementById("clearprivacythrobber").enabled = false;
    1.65 +
    1.66 +      // Clear notifications after 4 seconds
    1.67 +      clearTimeout(SanitizeUI._clearNotificationTimeout);
    1.68 +      SanitizeUI._clearNotificationTimeout = setTimeout(function() {
    1.69 +        clearNotificationDeck.selectedPanel = clearNotificationEmpty;
    1.70 +      }, 4000);
    1.71 +    }, 0);
    1.72 +  },
    1.73 +
    1.74 +  /* Disable the clear button when nothing is selected */
    1.75 +  _onCheckboxChange: function _onCheckboxChange() {
    1.76 +    let anySelected = SanitizeUI._privData.querySelector(
    1.77 +      "#prefs-privdata-history[checked], " +
    1.78 +      "#prefs-privdata-other[checked] + #prefs-privdata-subitems .privdata-subitem-item[checked]");
    1.79 +
    1.80 +    let clearButton = document.getElementById("prefs-clear-data");
    1.81 +    clearButton.disabled = !anySelected;
    1.82 +  },
    1.83 +
    1.84 +  handleEvent: function (aEvent) {
    1.85 +    switch (aEvent.type) {
    1.86 +      case "CheckboxStateChange":
    1.87 +        this._onCheckboxChange();
    1.88 +        break;
    1.89 +    }
    1.90 +  },
    1.91 +};
    1.92 \ No newline at end of file

mercurial