Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | 'use strict'; |
michael@0 | 6 | |
michael@0 | 7 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | let PrefsFlyoutPanel = { |
michael@0 | 10 | _isInitialized: false, |
michael@0 | 11 | _hasShown: false, |
michael@0 | 12 | init: function pv_init() { |
michael@0 | 13 | if (this._isInitialized) { |
michael@0 | 14 | Cu.reportError("Attempting to re-initialize PreferencesPanelView"); |
michael@0 | 15 | return; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 19 | this._isInitialized = true; |
michael@0 | 20 | let self = this; |
michael@0 | 21 | |
michael@0 | 22 | this._elements = {}; |
michael@0 | 23 | [ |
michael@0 | 24 | ['PrefsFlyoutPanel', 'prefs-flyoutpanel'], |
michael@0 | 25 | ].forEach(function(aElement) { |
michael@0 | 26 | let [name, id] = aElement; |
michael@0 | 27 | XPCOMUtils.defineLazyGetter(self._elements, name, function() { |
michael@0 | 28 | return document.getElementById(id); |
michael@0 | 29 | }); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | this.observe(null, null, "privacy.donottrackheader.value"); |
michael@0 | 33 | this._updateSubmitURLs(); |
michael@0 | 34 | this._topmostElement = this._elements.PrefsFlyoutPanel; |
michael@0 | 35 | }, |
michael@0 | 36 | |
michael@0 | 37 | _show: function() { |
michael@0 | 38 | if (!this._hasShown) { |
michael@0 | 39 | SanitizeUI.init(); |
michael@0 | 40 | this._hasShown = true; |
michael@0 | 41 | |
michael@0 | 42 | Services.prefs.addObserver("privacy.donottrackheader.value", |
michael@0 | 43 | this, |
michael@0 | 44 | false); |
michael@0 | 45 | Services.prefs.addObserver("privacy.donottrackheader.enabled", |
michael@0 | 46 | this, |
michael@0 | 47 | false); |
michael@0 | 48 | Services.prefs.addObserver("app.crashreporter.autosubmit", |
michael@0 | 49 | this, |
michael@0 | 50 | false); |
michael@0 | 51 | Services.prefs.addObserver("app.crashreporter.submitURLs", |
michael@0 | 52 | this, |
michael@0 | 53 | false); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | this._topmostElement.show(); |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | observe: function(subject, topic, data) { |
michael@0 | 60 | let value = -1; |
michael@0 | 61 | try { |
michael@0 | 62 | value = Services.prefs.getIntPref("privacy.donottrackheader.value"); |
michael@0 | 63 | } catch(e) { |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | let isEnabled = Services.prefs.getBoolPref("privacy.donottrackheader.enabled"); |
michael@0 | 67 | |
michael@0 | 68 | switch (data) { |
michael@0 | 69 | case "privacy.donottrackheader.value": |
michael@0 | 70 | // If the user has selected to explicitly tell sites that tracking |
michael@0 | 71 | // is OK, or if the user has selected to explicitly tell sites that |
michael@0 | 72 | // tracking is NOT OK, we must enable sending the dnt header |
michael@0 | 73 | if (((1 == value) || (0 == value)) && !isEnabled) { |
michael@0 | 74 | Services.prefs.setBoolPref('privacy.donottrackheader.enabled', true); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // If the user has made no selection about whether tracking |
michael@0 | 78 | // is OK or not, we must diable the dnt header |
michael@0 | 79 | if (((1 != value) && (0 != value)) && isEnabled) { |
michael@0 | 80 | Services.prefs.setBoolPref('privacy.donottrackheader.enabled', false); |
michael@0 | 81 | } |
michael@0 | 82 | break; |
michael@0 | 83 | |
michael@0 | 84 | case "privacy.donottrackheader.enabled": |
michael@0 | 85 | // If someone or something modifies this pref, we should update the |
michael@0 | 86 | // other pref as well so our UI doesn't give false information |
michael@0 | 87 | if (((1 == value) || (0 == value)) && !isEnabled) { |
michael@0 | 88 | Services.prefs.setIntPref('privacy.donottrackheader.value', -1); |
michael@0 | 89 | } |
michael@0 | 90 | break; |
michael@0 | 91 | |
michael@0 | 92 | case "app.crashreporter.autosubmit": |
michael@0 | 93 | let autosubmit = Services.prefs.getBoolPref("app.crashreporter.autosubmit"); |
michael@0 | 94 | let urlCheckbox = document.getElementById("prefs-reporting-submitURLs"); |
michael@0 | 95 | if (!autosubmit) { |
michael@0 | 96 | // disables the submitURLs ui if no crashreports will be submited, but doesn't change the pref |
michael@0 | 97 | urlCheckbox.setAttribute("disabled", true); |
michael@0 | 98 | } |
michael@0 | 99 | else { |
michael@0 | 100 | urlCheckbox.setAttribute("disabled", false); |
michael@0 | 101 | } |
michael@0 | 102 | break; |
michael@0 | 103 | |
michael@0 | 104 | case "app.crashreporter.submitURLs": |
michael@0 | 105 | this._updateSubmitURLs(); |
michael@0 | 106 | break; |
michael@0 | 107 | } |
michael@0 | 108 | }, |
michael@0 | 109 | |
michael@0 | 110 | _updateSubmitURLs: function() { |
michael@0 | 111 | let submitURLs = Services.prefs.getBoolPref("app.crashreporter.submitURLs"); |
michael@0 | 112 | let urlCheckbox = document.getElementById("prefs-reporting-submitURLs"); |
michael@0 | 113 | if (submitURLs) { |
michael@0 | 114 | urlCheckbox.checked = true; |
michael@0 | 115 | } |
michael@0 | 116 | else { |
michael@0 | 117 | urlCheckbox.checked = false; |
michael@0 | 118 | } |
michael@0 | 119 | }, |
michael@0 | 120 | }; |