Bug 1559431 - Add social tracking to the ETP graph r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D40476

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Erica Wright 2019-08-11 21:43:58 +00:00
parent a48224800a
commit c338fe4e07
7 changed files with 108 additions and 19 deletions

View File

@ -38,6 +38,7 @@ let idToTextMap = new Map([
[Ci.nsITrackingDBService.TRACKING_COOKIES_ID, "cookie"],
[Ci.nsITrackingDBService.CRYPTOMINERS_ID, "cryptominer"],
[Ci.nsITrackingDBService.FINGERPRINTERS_ID, "fingerprinter"],
[Ci.nsITrackingDBService.SOCIAL_ID, "social"],
]);
const MONITOR_API_ENDPOINT = "https://monitor.firefox.com/user/breach-stats";

View File

@ -39,7 +39,7 @@
<div id="graph-wrapper">
<div id="graph"></div>
<div id="legend">
<input id="tab-social" data-type="social" type="radio" name="tabs" checked>
<input id="tab-social" data-type="social" type="radio" name="tabs">
<label for="tab-social" data-type="social"></label>
<input id="tab-cookie" data-type="cookie" type="radio" name="tabs">

View File

@ -166,12 +166,32 @@ document.addEventListener("DOMContentLoaded", e => {
// Hide the trackers tab if the user is in standard and
// has no recorded trackers blocked.
if (weekTypeCounts.tracker == 0 && cbCategory == "standard") {
legend.style.gridTemplateAreas =
"'social cookie fingerprinter cryptominer'";
legend.style.gridTemplateAreas = legend.style.gridTemplateAreas.replace(
"tracker",
""
);
let radio = document.getElementById("tab-tracker");
radio.setAttribute("disabled", true);
document.querySelector("#tab-tracker ~ label").style.display = "none";
}
let socialEnabled = RPMGetBoolPref(
"privacy.socialtracking.block_cookies.enabled",
false
);
if (weekTypeCounts.social == 0 && !socialEnabled) {
legend.style.gridTemplateAreas = legend.style.gridTemplateAreas.replace(
"social",
""
);
let radio = document.getElementById("tab-social");
radio.setAttribute("disabled", true);
document.querySelector("#tab-social ~ label").style.display = "none";
}
let firstRadio = document.querySelector("input:not(:disabled)");
firstRadio.checked = true;
document.body.setAttribute("focuseddatatype", firstRadio.dataset.type);
addListeners();
};

View File

@ -49,7 +49,7 @@ add_task(async function test_graph_display() {
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.FINGERPRINTERS_ID,
count: 3,
count: 2,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
@ -57,6 +57,11 @@ add_task(async function test_graph_display() {
count: 4,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.SOCIAL_ID,
count: 1,
timestamp: date,
});
date = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).toISOString();
await db.execute(SQL.insertCustomTimeEvent, {
@ -74,6 +79,11 @@ add_task(async function test_graph_display() {
count: 2,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.SOCIAL_ID,
count: 1,
timestamp: date,
});
date = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString();
await db.execute(SQL.insertCustomTimeEvent, {
@ -91,6 +101,11 @@ add_task(async function test_graph_display() {
count: 1,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.SOCIAL_ID,
count: 1,
timestamp: date,
});
date = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString();
await db.execute(SQL.insertCustomTimeEvent, {
@ -108,6 +123,11 @@ add_task(async function test_graph_display() {
count: 1,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.SOCIAL_ID,
count: 1,
timestamp: date,
});
date = new Date(Date.now() - 4 * 24 * 60 * 60 * 1000).toISOString();
await db.execute(SQL.insertCustomTimeEvent, {
@ -125,6 +145,11 @@ add_task(async function test_graph_display() {
count: 1,
timestamp: date,
});
await db.execute(SQL.insertCustomTimeEvent, {
type: TrackingDBService.SOCIAL_ID,
count: 1,
timestamp: date,
});
date = new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString();
await db.execute(SQL.insertCustomTimeEvent, {
@ -153,7 +178,13 @@ add_task(async function test_graph_display() {
gBrowser,
});
await ContentTask.spawn(tab.linkedBrowser, {}, async function() {
const DATA_TYPES = ["cryptominer", "fingerprinter", "tracker", "cookie"];
const DATA_TYPES = [
"cryptominer",
"fingerprinter",
"tracker",
"cookie",
"social",
];
let allBars = null;
await ContentTaskUtils.waitForCondition(() => {
allBars = content.document.querySelectorAll(".graph-bar");
@ -186,14 +217,19 @@ add_task(async function test_graph_display() {
);
is(
allBars[6].querySelector(".fingerprinter-bar").style.height,
"30%",
"fingerprinters take 30%"
"20%",
"fingerprinters take 20%"
);
is(
allBars[6].querySelector(".cookie-bar").style.height,
"40%",
"cross site tracking cookies take 40%"
);
is(
allBars[6].querySelector(".social-bar").style.height,
"10%",
"social trackers take 10%"
);
is(
allBars[5].querySelectorAll(".inner-bar").length,
@ -235,7 +271,15 @@ add_task(async function test_graph_display() {
"there is no tracker section 1 day ago."
);
// TODO test for social missing
is(
allBars[1].querySelectorAll(".inner-bar").length,
DATA_TYPES.length - 1,
"5 days ago is missing one type"
);
ok(
!allBars[1].querySelector(".social-bar"),
"there is no social section 1 day ago."
);
is(
allBars[0].querySelectorAll(".inner-bar").length,

View File

@ -20,6 +20,13 @@ XPCOMUtils.defineLazyGetter(this, "DB_PATH", function() {
return OS.Path.join(OS.Constants.Path.profileDir, "protections.sqlite");
});
XPCOMUtils.defineLazyPreferenceGetter(
this,
"social_enabled",
"privacy.socialtracking.block_cookies.enabled",
false
);
ChromeUtils.defineModuleGetter(
this,
"AsyncShutdown",
@ -166,29 +173,44 @@ TrackingDBService.prototype = {
isTracker = true;
}
if (blocked) {
if (state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT) {
result = Ci.nsITrackingDBService.TRACKERS_ID;
}
if (
state & Ci.nsIWebProgressListener.STATE_BLOCKED_FINGERPRINTING_CONTENT
) {
result = Ci.nsITrackingDBService.FINGERPRINTERS_ID;
}
if (
state & Ci.nsIWebProgressListener.STATE_BLOCKED_CRYPTOMINING_CONTENT
} else if (
// If STP is enabled and either a social tracker is blocked,
// or a cookie was blocked with a social tracking event
social_enabled &&
((state &
Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT &&
state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER) ||
state &
Ci.nsIWebProgressListener.STATE_BLOCKED_SOCIALTRACKING_CONTENT)
) {
result = Ci.nsITrackingDBService.SOCIAL_ID;
} else if (
// If there is a tracker blocked. If there is a social tracker blocked, but STP is not enabled.
state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT ||
state & Ci.nsIWebProgressListener.STATE_BLOCKED_SOCIALTRACKING_CONTENT
) {
result = Ci.nsITrackingDBService.TRACKERS_ID;
} else if (
// If a tracking cookie was blocked attribute it to tracking cookies. Possible social tracking content,
// but STP is not enabled.
state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER
) {
result = Ci.nsITrackingDBService.CRYPTOMINERS_ID;
}
if (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER) {
result = Ci.nsITrackingDBService.TRACKING_COOKIES_ID;
}
if (
} else if (
state &
Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_BY_PERMISSION ||
state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL ||
state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_FOREIGN
) {
result = Ci.nsITrackingDBService.OTHER_COOKIES_BLOCKED_ID;
} else if (
state & Ci.nsIWebProgressListener.STATE_BLOCKED_CRYPTOMINING_CONTENT
) {
result = Ci.nsITrackingDBService.CRYPTOMINERS_ID;
}
}
}

View File

@ -60,4 +60,5 @@ interface nsITrackingDBService : nsISupports
const unsigned long TRACKING_COOKIES_ID = 2;
const unsigned long CRYPTOMINERS_ID = 3;
const unsigned long FINGERPRINTERS_ID = 4;
const unsigned long SOCIAL_ID = 5;
};

View File

@ -61,6 +61,7 @@ let RPMAccessManager = {
getBoolPref: [
"browser.contentblocking.report.lockwise.enabled",
"browser.contentblocking.report.monitor.enabled",
"privacy.socialtracking.block_cookies.enabled",
],
getStringPref: [
"browser.contentblocking.category",