michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: let PrefsFlyoutPanel = { michael@0: _isInitialized: false, michael@0: _hasShown: false, michael@0: init: function pv_init() { michael@0: if (this._isInitialized) { michael@0: Cu.reportError("Attempting to re-initialize PreferencesPanelView"); michael@0: return; michael@0: } michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: this._isInitialized = true; michael@0: let self = this; michael@0: michael@0: this._elements = {}; michael@0: [ michael@0: ['PrefsFlyoutPanel', 'prefs-flyoutpanel'], michael@0: ].forEach(function(aElement) { michael@0: let [name, id] = aElement; michael@0: XPCOMUtils.defineLazyGetter(self._elements, name, function() { michael@0: return document.getElementById(id); michael@0: }); michael@0: }); michael@0: michael@0: this.observe(null, null, "privacy.donottrackheader.value"); michael@0: this._updateSubmitURLs(); michael@0: this._topmostElement = this._elements.PrefsFlyoutPanel; michael@0: }, michael@0: michael@0: _show: function() { michael@0: if (!this._hasShown) { michael@0: SanitizeUI.init(); michael@0: this._hasShown = true; michael@0: michael@0: Services.prefs.addObserver("privacy.donottrackheader.value", michael@0: this, michael@0: false); michael@0: Services.prefs.addObserver("privacy.donottrackheader.enabled", michael@0: this, michael@0: false); michael@0: Services.prefs.addObserver("app.crashreporter.autosubmit", michael@0: this, michael@0: false); michael@0: Services.prefs.addObserver("app.crashreporter.submitURLs", michael@0: this, michael@0: false); michael@0: } michael@0: michael@0: this._topmostElement.show(); michael@0: }, michael@0: michael@0: observe: function(subject, topic, data) { michael@0: let value = -1; michael@0: try { michael@0: value = Services.prefs.getIntPref("privacy.donottrackheader.value"); michael@0: } catch(e) { michael@0: } michael@0: michael@0: let isEnabled = Services.prefs.getBoolPref("privacy.donottrackheader.enabled"); michael@0: michael@0: switch (data) { michael@0: case "privacy.donottrackheader.value": michael@0: // If the user has selected to explicitly tell sites that tracking michael@0: // is OK, or if the user has selected to explicitly tell sites that michael@0: // tracking is NOT OK, we must enable sending the dnt header michael@0: if (((1 == value) || (0 == value)) && !isEnabled) { michael@0: Services.prefs.setBoolPref('privacy.donottrackheader.enabled', true); michael@0: } michael@0: michael@0: // If the user has made no selection about whether tracking michael@0: // is OK or not, we must diable the dnt header michael@0: if (((1 != value) && (0 != value)) && isEnabled) { michael@0: Services.prefs.setBoolPref('privacy.donottrackheader.enabled', false); michael@0: } michael@0: break; michael@0: michael@0: case "privacy.donottrackheader.enabled": michael@0: // If someone or something modifies this pref, we should update the michael@0: // other pref as well so our UI doesn't give false information michael@0: if (((1 == value) || (0 == value)) && !isEnabled) { michael@0: Services.prefs.setIntPref('privacy.donottrackheader.value', -1); michael@0: } michael@0: break; michael@0: michael@0: case "app.crashreporter.autosubmit": michael@0: let autosubmit = Services.prefs.getBoolPref("app.crashreporter.autosubmit"); michael@0: let urlCheckbox = document.getElementById("prefs-reporting-submitURLs"); michael@0: if (!autosubmit) { michael@0: // disables the submitURLs ui if no crashreports will be submited, but doesn't change the pref michael@0: urlCheckbox.setAttribute("disabled", true); michael@0: } michael@0: else { michael@0: urlCheckbox.setAttribute("disabled", false); michael@0: } michael@0: break; michael@0: michael@0: case "app.crashreporter.submitURLs": michael@0: this._updateSubmitURLs(); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: _updateSubmitURLs: function() { michael@0: let submitURLs = Services.prefs.getBoolPref("app.crashreporter.submitURLs"); michael@0: let urlCheckbox = document.getElementById("prefs-reporting-submitURLs"); michael@0: if (submitURLs) { michael@0: urlCheckbox.checked = true; michael@0: } michael@0: else { michael@0: urlCheckbox.checked = false; michael@0: } michael@0: }, michael@0: };