2015-07-01 00:02:39 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
let TrackingProtection = {
|
2015-07-16 23:38:20 +03:00
|
|
|
MAX_INTROS: 0,
|
2015-07-10 02:19:30 +03:00
|
|
|
PREF_ENABLED_GLOBALLY: "privacy.trackingprotection.enabled",
|
|
|
|
PREF_ENABLED_IN_PRIVATE_WINDOWS: "privacy.trackingprotection.pbmode.enabled",
|
|
|
|
enabledGlobally: false,
|
|
|
|
enabledInPrivateWindows: false,
|
2015-07-24 06:37:17 +03:00
|
|
|
container: null,
|
|
|
|
content: null,
|
|
|
|
icon: null,
|
|
|
|
activeTooltipText: null,
|
|
|
|
disabledTooltipText: null,
|
2015-07-01 00:02:39 +03:00
|
|
|
|
|
|
|
init() {
|
|
|
|
let $ = selector => document.querySelector(selector);
|
|
|
|
this.container = $("#tracking-protection-container");
|
|
|
|
this.content = $("#tracking-protection-content");
|
2015-07-13 20:38:13 +03:00
|
|
|
this.icon = $("#tracking-protection-icon");
|
2015-07-01 00:02:39 +03:00
|
|
|
|
|
|
|
this.updateEnabled();
|
2015-07-10 02:19:30 +03:00
|
|
|
Services.prefs.addObserver(this.PREF_ENABLED_GLOBALLY, this, false);
|
|
|
|
Services.prefs.addObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this, false);
|
2015-07-01 00:02:39 +03:00
|
|
|
|
2015-07-24 06:37:17 +03:00
|
|
|
this.activeTooltipText =
|
|
|
|
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip");
|
|
|
|
this.disabledTooltipText =
|
|
|
|
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip");
|
|
|
|
|
2015-07-10 02:19:30 +03:00
|
|
|
this.enabledHistogram.add(this.enabledGlobally);
|
2015-07-01 00:02:39 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
uninit() {
|
2015-07-10 02:19:30 +03:00
|
|
|
Services.prefs.removeObserver(this.PREF_ENABLED_GLOBALLY, this);
|
|
|
|
Services.prefs.removeObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this);
|
2015-07-01 00:02:39 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
observe() {
|
|
|
|
this.updateEnabled();
|
|
|
|
},
|
|
|
|
|
2015-07-10 02:19:30 +03:00
|
|
|
get enabled() {
|
|
|
|
return this.enabledGlobally ||
|
|
|
|
(this.enabledInPrivateWindows &&
|
|
|
|
PrivateBrowsingUtils.isWindowPrivate(window));
|
|
|
|
},
|
|
|
|
|
2015-07-01 00:02:39 +03:00
|
|
|
updateEnabled() {
|
2015-07-10 02:19:30 +03:00
|
|
|
this.enabledGlobally =
|
|
|
|
Services.prefs.getBoolPref(this.PREF_ENABLED_GLOBALLY);
|
|
|
|
this.enabledInPrivateWindows =
|
|
|
|
Services.prefs.getBoolPref(this.PREF_ENABLED_IN_PRIVATE_WINDOWS);
|
2015-07-01 00:02:39 +03:00
|
|
|
this.container.hidden = !this.enabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
get enabledHistogram() {
|
|
|
|
return Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED");
|
|
|
|
},
|
|
|
|
|
|
|
|
get eventsHistogram() {
|
|
|
|
return Services.telemetry.getHistogramById("TRACKING_PROTECTION_EVENTS");
|
|
|
|
},
|
|
|
|
|
2015-07-23 23:55:32 +03:00
|
|
|
onSecurityChange(state, isSimulated) {
|
2015-07-01 00:02:39 +03:00
|
|
|
if (!this.enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-23 23:55:32 +03:00
|
|
|
// Only animate the shield if the event was not fired directly from
|
|
|
|
// the tabbrowser (due to a browser change).
|
|
|
|
if (isSimulated) {
|
|
|
|
this.icon.removeAttribute("animate");
|
|
|
|
} else {
|
|
|
|
this.icon.setAttribute("animate", "true");
|
|
|
|
}
|
|
|
|
|
2015-07-24 06:37:17 +03:00
|
|
|
let isBlocking = state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT;
|
|
|
|
let isAllowing = state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT;
|
|
|
|
|
|
|
|
if (isBlocking) {
|
|
|
|
this.icon.setAttribute("tooltiptext", this.activeTooltipText);
|
|
|
|
this.icon.setAttribute("state", "blocked-tracking-content");
|
|
|
|
this.content.setAttribute("state", "blocked-tracking-content");
|
2015-07-01 00:02:39 +03:00
|
|
|
|
2015-07-16 23:38:20 +03:00
|
|
|
// Open the tracking protection introduction panel, if applicable.
|
|
|
|
let introCount = gPrefService.getIntPref("privacy.trackingprotection.introCount");
|
|
|
|
if (introCount < TrackingProtection.MAX_INTROS) {
|
|
|
|
gPrefService.setIntPref("privacy.trackingprotection.introCount", ++introCount);
|
|
|
|
gPrefService.savePrefFile(null);
|
|
|
|
this.showIntroPanel();
|
|
|
|
}
|
2015-07-24 06:37:17 +03:00
|
|
|
} else if (isAllowing) {
|
|
|
|
this.icon.setAttribute("tooltiptext", this.disabledTooltipText);
|
|
|
|
this.icon.setAttribute("state", "loaded-tracking-content");
|
|
|
|
this.content.setAttribute("state", "loaded-tracking-content");
|
|
|
|
} else {
|
|
|
|
this.icon.removeAttribute("tooltiptext");
|
|
|
|
this.icon.removeAttribute("state");
|
|
|
|
this.content.removeAttribute("state");
|
2015-07-16 23:38:20 +03:00
|
|
|
}
|
|
|
|
|
2015-07-01 00:02:39 +03:00
|
|
|
// Telemetry for state change.
|
|
|
|
this.eventsHistogram.add(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
disableForCurrentPage() {
|
|
|
|
// Convert document URI into the format used by
|
|
|
|
// nsChannelClassifier::ShouldEnableTrackingProtection.
|
|
|
|
// Any scheme turned into https is correct.
|
|
|
|
let normalizedUrl = Services.io.newURI(
|
|
|
|
"https://" + gBrowser.selectedBrowser.currentURI.hostPort,
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
// Add the current host in the 'trackingprotection' consumer of
|
|
|
|
// the permission manager using a normalized URI. This effectively
|
|
|
|
// places this host on the tracking protection allowlist.
|
|
|
|
Services.perms.add(normalizedUrl,
|
|
|
|
"trackingprotection", Services.perms.ALLOW_ACTION);
|
|
|
|
|
|
|
|
// Telemetry for disable protection.
|
|
|
|
this.eventsHistogram.add(1);
|
|
|
|
|
|
|
|
BrowserReload();
|
|
|
|
},
|
|
|
|
|
|
|
|
enableForCurrentPage() {
|
|
|
|
// Remove the current host from the 'trackingprotection' consumer
|
|
|
|
// of the permission manager. This effectively removes this host
|
|
|
|
// from the tracking protection allowlist.
|
2015-07-07 21:22:45 +03:00
|
|
|
let normalizedUrl = Services.io.newURI(
|
|
|
|
"https://" + gBrowser.selectedBrowser.currentURI.hostPort,
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
Services.perms.remove(normalizedUrl,
|
2015-07-01 00:02:39 +03:00
|
|
|
"trackingprotection");
|
|
|
|
|
|
|
|
// Telemetry for enable protection.
|
|
|
|
this.eventsHistogram.add(2);
|
|
|
|
|
|
|
|
BrowserReload();
|
|
|
|
},
|
2015-07-16 23:38:20 +03:00
|
|
|
|
|
|
|
showIntroPanel: Task.async(function*() {
|
|
|
|
let mm = gBrowser.selectedBrowser.messageManager;
|
|
|
|
let brandBundle = document.getElementById("bundle_brand");
|
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
|
|
|
|
let openStep2 = () => {
|
|
|
|
// When the user proceeds in the tour, adjust the counter to indicate that
|
|
|
|
// the user doesn't need to see the intro anymore.
|
|
|
|
gPrefService.setIntPref("privacy.trackingprotection.introCount",
|
|
|
|
this.MAX_INTROS);
|
|
|
|
gPrefService.savePrefFile(null);
|
|
|
|
|
|
|
|
let nextURL = Services.urlFormatter.formatURLPref("privacy.trackingprotection.introURL") +
|
|
|
|
"#step2";
|
|
|
|
switchToTabHavingURI(nextURL, true, {
|
|
|
|
// Ignore the fragment in case the intro is shown on the tour page
|
|
|
|
// (e.g. if the user manually visited the tour or clicked the link from
|
|
|
|
// about:privatebrowsing) so we can avoid a reload.
|
|
|
|
ignoreFragment: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
let buttons = [
|
|
|
|
{
|
|
|
|
label: gNavigatorBundle.getString("trackingProtection.intro.step1of3"),
|
|
|
|
style: "text",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
callback: openStep2,
|
|
|
|
label: gNavigatorBundle.getString("trackingProtection.intro.nextButton.label"),
|
|
|
|
style: "primary",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
let panelTarget = yield UITour.getTarget(window, "trackingProtection");
|
|
|
|
UITour.initForBrowser(gBrowser.selectedBrowser);
|
|
|
|
UITour.showInfo(window, mm, panelTarget,
|
|
|
|
gNavigatorBundle.getString("trackingProtection.intro.title"),
|
|
|
|
gNavigatorBundle.getFormattedString("trackingProtection.intro.description",
|
|
|
|
[brandShortName]),
|
|
|
|
undefined, buttons);
|
|
|
|
}),
|
2015-07-01 00:02:39 +03:00
|
|
|
};
|