browser/metro/base/content/flyoutpanels/PrefsFlyoutPanel.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/. */
     5 'use strict';
     7 Components.utils.import("resource://gre/modules/Services.jsm");
     9 let PrefsFlyoutPanel = {
    10   _isInitialized: false,
    11   _hasShown: false,
    12   init: function pv_init() {
    13     if (this._isInitialized) {
    14       Cu.reportError("Attempting to re-initialize PreferencesPanelView");
    15       return;
    16     }
    18     Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    19     this._isInitialized = true;
    20     let self = this;
    22     this._elements = {};
    23     [
    24       ['PrefsFlyoutPanel',  'prefs-flyoutpanel'],
    25     ].forEach(function(aElement) {
    26       let [name, id] = aElement;
    27       XPCOMUtils.defineLazyGetter(self._elements, name, function() {
    28         return document.getElementById(id);
    29       });
    30     });
    32     this.observe(null, null, "privacy.donottrackheader.value");
    33     this._updateSubmitURLs();
    34     this._topmostElement = this._elements.PrefsFlyoutPanel;
    35   },
    37   _show: function() {
    38     if (!this._hasShown) {
    39       SanitizeUI.init();
    40       this._hasShown = true;
    42       Services.prefs.addObserver("privacy.donottrackheader.value",
    43                                  this,
    44                                  false);
    45       Services.prefs.addObserver("privacy.donottrackheader.enabled",
    46                                  this,
    47                                  false);
    48       Services.prefs.addObserver("app.crashreporter.autosubmit",
    49                                  this,
    50                                  false);
    51       Services.prefs.addObserver("app.crashreporter.submitURLs",
    52                                  this,
    53                                  false);
    54     }
    56     this._topmostElement.show();
    57   },
    59   observe: function(subject, topic, data) {
    60     let value = -1;
    61     try {
    62       value = Services.prefs.getIntPref("privacy.donottrackheader.value");
    63     } catch(e) {
    64     }
    66     let isEnabled = Services.prefs.getBoolPref("privacy.donottrackheader.enabled");
    68     switch (data) {
    69       case "privacy.donottrackheader.value":
    70         // If the user has selected to explicitly tell sites that tracking
    71         // is OK, or if the user has selected to explicitly tell sites that
    72         // tracking is NOT OK, we must enable sending the dnt header
    73         if (((1 == value) || (0 == value)) && !isEnabled) {
    74           Services.prefs.setBoolPref('privacy.donottrackheader.enabled', true);
    75         }
    77         // If the user has made no selection about whether tracking
    78         // is OK or not, we must diable the dnt header
    79         if (((1 != value) && (0 != value)) && isEnabled) {
    80           Services.prefs.setBoolPref('privacy.donottrackheader.enabled', false);
    81         }
    82         break;
    84       case "privacy.donottrackheader.enabled":
    85         // If someone or something modifies this pref, we should update the
    86         // other pref as well so our UI doesn't give false information
    87         if (((1 == value) || (0 == value)) && !isEnabled) {
    88           Services.prefs.setIntPref('privacy.donottrackheader.value', -1);
    89         }
    90         break;
    92       case "app.crashreporter.autosubmit":
    93         let autosubmit = Services.prefs.getBoolPref("app.crashreporter.autosubmit");
    94         let urlCheckbox = document.getElementById("prefs-reporting-submitURLs");
    95         if (!autosubmit) {
    96           // disables the submitURLs ui if no crashreports will be submited, but doesn't change the pref 
    97           urlCheckbox.setAttribute("disabled", true);
    98         }
    99         else {
   100           urlCheckbox.setAttribute("disabled", false);
   101         }
   102         break;
   104       case "app.crashreporter.submitURLs":
   105         this._updateSubmitURLs();
   106         break;
   107     }
   108   },
   110   _updateSubmitURLs: function() {
   111     let submitURLs = Services.prefs.getBoolPref("app.crashreporter.submitURLs");
   112     let urlCheckbox = document.getElementById("prefs-reporting-submitURLs");
   113     if (submitURLs) {
   114       urlCheckbox.checked = true; 
   115     }
   116     else {
   117       urlCheckbox.checked = false;
   118     }
   119   },
   120 };

mercurial