browser/metro/base/content/flyoutpanels/PrefsFlyoutPanel.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/flyoutpanels/PrefsFlyoutPanel.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     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 +'use strict';
     1.9 +
    1.10 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.11 +
    1.12 +let PrefsFlyoutPanel = {
    1.13 +  _isInitialized: false,
    1.14 +  _hasShown: false,
    1.15 +  init: function pv_init() {
    1.16 +    if (this._isInitialized) {
    1.17 +      Cu.reportError("Attempting to re-initialize PreferencesPanelView");
    1.18 +      return;
    1.19 +    }
    1.20 +
    1.21 +    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.22 +    this._isInitialized = true;
    1.23 +    let self = this;
    1.24 +
    1.25 +    this._elements = {};
    1.26 +    [
    1.27 +      ['PrefsFlyoutPanel',  'prefs-flyoutpanel'],
    1.28 +    ].forEach(function(aElement) {
    1.29 +      let [name, id] = aElement;
    1.30 +      XPCOMUtils.defineLazyGetter(self._elements, name, function() {
    1.31 +        return document.getElementById(id);
    1.32 +      });
    1.33 +    });
    1.34 +
    1.35 +    this.observe(null, null, "privacy.donottrackheader.value");
    1.36 +    this._updateSubmitURLs();
    1.37 +    this._topmostElement = this._elements.PrefsFlyoutPanel;
    1.38 +  },
    1.39 +
    1.40 +  _show: function() {
    1.41 +    if (!this._hasShown) {
    1.42 +      SanitizeUI.init();
    1.43 +      this._hasShown = true;
    1.44 +
    1.45 +      Services.prefs.addObserver("privacy.donottrackheader.value",
    1.46 +                                 this,
    1.47 +                                 false);
    1.48 +      Services.prefs.addObserver("privacy.donottrackheader.enabled",
    1.49 +                                 this,
    1.50 +                                 false);
    1.51 +      Services.prefs.addObserver("app.crashreporter.autosubmit",
    1.52 +                                 this,
    1.53 +                                 false);
    1.54 +      Services.prefs.addObserver("app.crashreporter.submitURLs",
    1.55 +                                 this,
    1.56 +                                 false);
    1.57 +    }
    1.58 +
    1.59 +    this._topmostElement.show();
    1.60 +  },
    1.61 +
    1.62 +  observe: function(subject, topic, data) {
    1.63 +    let value = -1;
    1.64 +    try {
    1.65 +      value = Services.prefs.getIntPref("privacy.donottrackheader.value");
    1.66 +    } catch(e) {
    1.67 +    }
    1.68 +
    1.69 +    let isEnabled = Services.prefs.getBoolPref("privacy.donottrackheader.enabled");
    1.70 +
    1.71 +    switch (data) {
    1.72 +      case "privacy.donottrackheader.value":
    1.73 +        // If the user has selected to explicitly tell sites that tracking
    1.74 +        // is OK, or if the user has selected to explicitly tell sites that
    1.75 +        // tracking is NOT OK, we must enable sending the dnt header
    1.76 +        if (((1 == value) || (0 == value)) && !isEnabled) {
    1.77 +          Services.prefs.setBoolPref('privacy.donottrackheader.enabled', true);
    1.78 +        }
    1.79 +
    1.80 +        // If the user has made no selection about whether tracking
    1.81 +        // is OK or not, we must diable the dnt header
    1.82 +        if (((1 != value) && (0 != value)) && isEnabled) {
    1.83 +          Services.prefs.setBoolPref('privacy.donottrackheader.enabled', false);
    1.84 +        }
    1.85 +        break;
    1.86 +
    1.87 +      case "privacy.donottrackheader.enabled":
    1.88 +        // If someone or something modifies this pref, we should update the
    1.89 +        // other pref as well so our UI doesn't give false information
    1.90 +        if (((1 == value) || (0 == value)) && !isEnabled) {
    1.91 +          Services.prefs.setIntPref('privacy.donottrackheader.value', -1);
    1.92 +        }
    1.93 +        break;
    1.94 +
    1.95 +      case "app.crashreporter.autosubmit":
    1.96 +        let autosubmit = Services.prefs.getBoolPref("app.crashreporter.autosubmit");
    1.97 +        let urlCheckbox = document.getElementById("prefs-reporting-submitURLs");
    1.98 +        if (!autosubmit) {
    1.99 +          // disables the submitURLs ui if no crashreports will be submited, but doesn't change the pref 
   1.100 +          urlCheckbox.setAttribute("disabled", true);
   1.101 +        }
   1.102 +        else {
   1.103 +          urlCheckbox.setAttribute("disabled", false);
   1.104 +        }
   1.105 +        break;
   1.106 +
   1.107 +      case "app.crashreporter.submitURLs":
   1.108 +        this._updateSubmitURLs();
   1.109 +        break;
   1.110 +    }
   1.111 +  },
   1.112 +
   1.113 +  _updateSubmitURLs: function() {
   1.114 +    let submitURLs = Services.prefs.getBoolPref("app.crashreporter.submitURLs");
   1.115 +    let urlCheckbox = document.getElementById("prefs-reporting-submitURLs");
   1.116 +    if (submitURLs) {
   1.117 +      urlCheckbox.checked = true; 
   1.118 +    }
   1.119 +    else {
   1.120 +      urlCheckbox.checked = false;
   1.121 +    }
   1.122 +  },
   1.123 +};

mercurial