bug 897121. Move handling of DNT pref to prefsFlyout.js. Correctly (hopefully :) deal with the various pref values that are possible. r=rsilveira

This commit is contained in:
Tim Abraldes 2013-08-05 23:29:55 -07:00
Родитель cc4c6104ab
Коммит bceaaae272
3 изменённых файлов: 44 добавлений и 14 удалений

Просмотреть файл

@ -721,11 +721,11 @@
<setting pref="app.crashreporter.autosubmit" type="bool" title="&optionsHeader.reporting.crashes.label;" oncommand="BrowserUI.crashReportingPrefChanged(this.value);"/>
</settings>
<settings id="prefs-telemetry" label="&optionsHeader.telemetry.title;">
<setting pref="toolkit.telemetry.enabled" type="bool" title="&optionsHeader.telemetry.label;" oncommand="FlyoutPanelsUI.PrefsFlyoutPanel.onTelemetryPreferenceChanged(this.value);"/>
<setting pref="toolkit.telemetry.enabled" type="bool" title="&optionsHeader.telemetry.label;"/>
</settings>
<settings id="prefs-dnt" label="&doNotTrack.title;">
<description>&doNotTrack.desc;</description>
<setting id="prefs-dnt-value" pref="privacy.donottrackheader.value" onpreferencechanged="FlyoutPanelsUI.PrefsFlyoutPanel.onDNTPreferenceChanged();" type="radio" >
<setting id="prefs-dnt-value" pref="privacy.donottrackheader.value" type="radio" >
<radiogroup id="prefs-dnt-options">
<radio id="prefs-dnt-notrack" label="&doNotTrack.options.trackingNotOkay;" value="1"/>
<radio id="prefs-dnt-nopref" label="&doNotTrack.options.noPreference;" value="-1"/>

Просмотреть файл

@ -52,7 +52,7 @@ let FlyoutPanelsUI = {
}
this._currentFlyout = this[aToShow];
if (this._currentFlyout.show) {
if (this._currentFlyout._show) {
this._currentFlyout._show();
} else {
this._currentFlyout._topmostElement.show();

Просмотреть файл

@ -22,8 +22,6 @@ let PrefsFlyoutPanel = {
this._elements = {};
[
['PrefsFlyoutPanel', 'prefs-flyoutpanel'],
['dntNoPref', 'prefs-dnt-nopref'],
['telemetryPref','prefs-telemetry'],
].forEach(function(aElement) {
let [name, id] = aElement;
XPCOMUtils.defineLazyGetter(self._elements, name, function() {
@ -31,6 +29,7 @@ let PrefsFlyoutPanel = {
});
});
this._prefObserver(null, null, "privacy.donottrackheader.value");
this._topmostElement = this._elements.PrefsFlyoutPanel;
},
@ -38,19 +37,50 @@ let PrefsFlyoutPanel = {
if (!this._hasShown) {
SanitizeUI.init();
this._hasShown = true;
Services.prefs.addObserver("privacy.donottrackheader.value",
this._prefObserver,
false);
Services.prefs.addObserver("privacy.donottrackheader.enabled",
this._prefObserver,
false);
}
this._elements.PrefsFlyoutPanel.show();
this._topmostElement.show();
},
onDNTPreferenceChanged: function onDNTPreferenceChanged() {
let selected = this._elements.dntNoPref.selected;
_prefObserver: function(subject, topic, data) {
let value = -1;
try {
value = Services.prefs.getIntPref("privacy.donottrackheader.value");
} catch(e) {
}
// When "tell sites nothing about my preferences" is selected, disable do not track.
Services.prefs.setBoolPref("privacy.donottrackheader.enabled", !selected);
let isEnabled = Services.prefs.getBoolPref("privacy.donottrackheader.enabled");
switch (data) {
case "privacy.donottrackheader.value":
// If the user has selected to explicitly tell sites that tracking
// is OK, or if the user has selected to explicitly tell sites that
// tracking is NOT OK, we must enable sending the dnt header
if (((1 == value) || (0 == value)) && !isEnabled) {
Services.prefs.setBoolPref('privacy.donottrackheader.enabled', true);
}
// If the user has made no selection about whether tracking
// is OK or not, we must diable the dnt header
if (((1 != value) && (0 != value)) && isEnabled) {
Services.prefs.setBoolPref('privacy.donottrackheader.enabled', false);
}
break;
case "privacy.donottrackheader.enabled":
// If someone or something modifies this pref, we should update the
// other pref as well so our UI doesn't give false information
if (((1 == value) || (0 == value)) && !isEnabled) {
Services.prefs.setIntPref('privacy.donottrackheader.value', -1);
}
break;
}
},
onTelemetryPreferenceChanged: function onTelemetryPreferenceChanged(aBool) {
Services.prefs.setBoolPref("toolkit.telemetry.enabled", aBool);
}
};