Bug 1589476 - Emit a separate notification when a tracker from the Level 2 Disconnect blocklist is observed on a page and use this code to avoid using the URL classifer service in the front-end; r=nhnt11,droeh

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-11-18 20:56:36 +00:00
Родитель ddad5ae430
Коммит 8909341af2
15 изменённых файлов: 186 добавлений и 88 удалений

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

@ -285,6 +285,8 @@ var TrackingProtection = {
PREF_ENABLED_IN_PRIVATE_WINDOWS: "privacy.trackingprotection.pbmode.enabled",
PREF_TRACKING_TABLE: "urlclassifier.trackingTable",
PREF_TRACKING_ANNOTATION_TABLE: "urlclassifier.trackingAnnotationTable",
PREF_ANNOTATIONS_LEVEL_2_ENABLED:
"privacy.annotate_channels.strict_list.enabled",
enabledGlobally: false,
enabledInPrivateWindows: false,
@ -350,6 +352,12 @@ var TrackingProtection = {
this.PREF_TRACKING_ANNOTATION_TABLE,
false
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"annotationsLevel2Enabled",
this.PREF_ANNOTATIONS_LEVEL_2_ENABLED,
false
);
},
uninit() {
@ -361,6 +369,11 @@ var TrackingProtection = {
this.updateEnabled();
},
get trackingProtectionLevel2Enabled() {
const CONTENT_TABLE = "content-track-digest256";
return this.trackingTable.includes(CONTENT_TABLE);
},
get enabled() {
return (
this.enabledGlobally ||
@ -385,12 +398,26 @@ var TrackingProtection = {
);
},
isAllowing(state) {
isAllowingLevel1(state) {
return (
(state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) != 0
(state &
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT) !=
0
);
},
isAllowingLevel2(state) {
return (
(state &
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_2_TRACKING_CONTENT) !=
0
);
},
isAllowing(state) {
return this.isAllowingLevel1(state) || this.isAllowingLevel2(state);
},
isDetected(state) {
return this.isBlocking(state) || this.isAllowing(state);
},
@ -453,28 +480,6 @@ var TrackingProtection = {
}
},
// Given a URI from a source that was tracking-annotated, figure out
// if it's really on the tracking table or just on the annotation table.
_isOnTrackingTable(uri) {
if (this.trackingTable == this.trackingAnnotationTable) {
return true;
}
let feature = classifierService.getFeatureByName("tracking-protection");
if (!feature) {
return false;
}
return new Promise(resolve => {
classifierService.asyncClassifyLocalWithFeatures(
uri,
[feature],
Ci.nsIUrlClassifierFeature.blacklist,
list => resolve(!!list.length)
);
});
},
async _createListItem(origin, actions) {
// Figure out if this list entry was actually detected by TP or something else.
let isAllowed = actions.some(([state]) => this.isAllowing(state));
@ -490,8 +495,16 @@ var TrackingProtection = {
// Because we might use different lists for annotation vs. blocking, we
// need to make sure that this is a tracker that we would actually have blocked
// before showing it to the user.
let isTracker = await this._isOnTrackingTable(uri);
if (!isTracker) {
if (
this.annotationsLevel2Enabled &&
!this.trackingProtectionLevel2Enabled &&
actions.some(
([state]) =>
(state &
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_2_TRACKING_CONTENT) !=
0
)
) {
return null;
}

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

@ -30,7 +30,7 @@ const LOG = {
"https://6.example.com": [
[
Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL |
Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT,
true,
4,
],

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

@ -34,9 +34,12 @@ class ContentBlockingLog final {
};
struct OriginDataEntry {
OriginDataEntry() : mHasTrackingContentLoaded(false) {}
OriginDataEntry()
: mHasLevel1TrackingContentLoaded(false),
mHasLevel2TrackingContentLoaded(false) {}
bool mHasTrackingContentLoaded;
bool mHasLevel1TrackingContentLoaded;
bool mHasLevel2TrackingContentLoaded;
Maybe<bool> mHasCookiesLoaded;
Maybe<bool> mHasTrackerCookiesLoaded;
Maybe<bool> mHasSocialTrackerCookiesLoaded;
@ -142,8 +145,12 @@ class ContentBlockingLog final {
entry->mOrigin = aOrigin;
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
entry->mData->mHasTrackingContentLoaded = aBlocked;
if (aType ==
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT) {
entry->mData->mHasLevel1TrackingContentLoaded = aBlocked;
} else if (aType ==
nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT) {
entry->mData->mHasLevel2TrackingContentLoaded = aBlocked;
} else if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
MOZ_ASSERT(entry->mData->mHasCookiesLoaded.isNothing());
entry->mData->mHasCookiesLoaded.emplace(aBlocked);
@ -208,8 +215,14 @@ class ContentBlockingLog final {
continue;
}
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
if (entry.mData->mHasTrackingContentLoaded) {
if (aType ==
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT) {
if (entry.mData->mHasLevel1TrackingContentLoaded) {
return true;
}
} else if (aType == nsIWebProgressListener::
STATE_LOADED_LEVEL_2_TRACKING_CONTENT) {
if (entry.mData->mHasLevel2TrackingContentLoaded) {
return true;
}
} else if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
@ -257,8 +270,14 @@ class ContentBlockingLog final {
private:
bool RecordLogEntryInCustomField(uint32_t aType, OriginEntry& aEntry,
bool aBlocked) {
if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
aEntry.mData->mHasTrackingContentLoaded = aBlocked;
if (aType ==
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT) {
aEntry.mData->mHasLevel1TrackingContentLoaded = aBlocked;
return true;
}
if (aType ==
nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT) {
aEntry.mData->mHasLevel2TrackingContentLoaded = aBlocked;
return true;
}
if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
@ -289,11 +308,21 @@ class ContentBlockingLog final {
}
void StringifyCustomFields(const OriginEntry& aEntry, JSONWriter& aWriter) {
if (aEntry.mData->mHasTrackingContentLoaded) {
if (aEntry.mData->mHasLevel1TrackingContentLoaded) {
aWriter.StartArrayElement(aWriter.SingleLineStyle);
{
aWriter.IntElement(
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT);
aWriter.BoolElement(true); // blocked
aWriter.IntElement(1); // repeat count
}
aWriter.EndArray();
}
if (aEntry.mData->mHasLevel2TrackingContentLoaded) {
aWriter.StartArrayElement(aWriter.SingleLineStyle);
{
aWriter.IntElement(
nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT);
aWriter.BoolElement(true); // blocked
aWriter.IntElement(1); // repeat count
}

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

@ -1341,20 +1341,40 @@ class Document : public nsINode,
}
/**
* Get tracking content loaded flag for this document.
* Get level 1 tracking content loaded flag for this document.
*/
bool GetHasTrackingContentLoaded() {
bool GetHasLevel1TrackingContentLoaded() {
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT);
}
/**
* Set the tracking content loaded flag for this document.
* Set the level 1 tracking content loaded flag for this document.
*/
void SetHasTrackingContentLoaded(bool aHasTrackingContentLoaded,
const nsACString& aOriginBlocked) {
void SetHasLevel1TrackingContentLoaded(bool aHasTrackingContentLoaded,
const nsACString& aOriginBlocked) {
RecordContentBlockingLog(
aOriginBlocked, nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT,
aOriginBlocked,
nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT,
aHasTrackingContentLoaded);
}
/**
* Get level 2 tracking content loaded flag for this document.
*/
bool GetHasLevel2TrackingContentLoaded() {
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT);
}
/**
* Set the level 2 tracking content loaded flag for this document.
*/
void SetHasLevel2TrackingContentLoaded(bool aHasTrackingContentLoaded,
const nsACString& aOriginBlocked) {
RecordContentBlockingLog(
aOriginBlocked,
nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT,
aHasTrackingContentLoaded);
}

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

@ -5410,11 +5410,17 @@ void nsGlobalWindowOuter::NotifyContentBlockingEvent(
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentBlocked();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
doc->SetHasTrackingContentLoaded(aBlocked, origin);
} else if (aEvent == nsIWebProgressListener::
STATE_LOADED_LEVEL_1_TRACKING_CONTENT) {
doc->SetHasLevel1TrackingContentLoaded(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentLoaded();
unblocked = !doc->GetHasLevel1TrackingContentLoaded();
}
} else if (aEvent == nsIWebProgressListener::
STATE_LOADED_LEVEL_2_TRACKING_CONTENT) {
doc->SetHasLevel2TrackingContentLoaded(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasLevel2TrackingContentLoaded();
}
} else if (aEvent == nsIWebProgressListener::
STATE_BLOCKED_FINGERPRINTING_CONTENT) {

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

@ -317,8 +317,9 @@ package org.mozilla.geckoview {
field public static final int COOKIES_PARTITIONED_FOREIGN = -2147483648;
field public static final int LOADED_CRYPTOMINING_CONTENT = 2097152;
field public static final int LOADED_FINGERPRINTING_CONTENT = 1024;
field public static final int LOADED_LEVEL_1_TRACKING_CONTENT = 8192;
field public static final int LOADED_LEVEL_2_TRACKING_CONTENT = 1048576;
field public static final int LOADED_SOCIALTRACKING_CONTENT = 131072;
field public static final int LOADED_TRACKING_CONTENT = 8192;
}
@AnyThread public class ContentBlockingController.ExceptionList {

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

@ -212,9 +212,14 @@ public class ContentBlockingController {
public static final int BLOCKED_TRACKING_CONTENT = 0x00001000;
/**
* Tracking content has been loaded.
* Level 1 tracking content has been loaded.
*/
public static final int LOADED_TRACKING_CONTENT = 0x00002000;
public static final int LOADED_LEVEL_1_TRACKING_CONTENT = 0x00002000;
/**
* Level 2 tracking content has been loaded.
*/
public static final int LOADED_LEVEL_2_TRACKING_CONTENT = 0x00100000;
/**
* Fingerprinting content has been blocked from loading.
@ -320,15 +325,16 @@ public class ContentBlockingController {
*/
public static class BlockingData {
@Retention(RetentionPolicy.SOURCE)
@IntDef({ Event.BLOCKED_TRACKING_CONTENT, Event.LOADED_TRACKING_CONTENT,
Event.BLOCKED_FINGERPRINTING_CONTENT, Event.LOADED_FINGERPRINTING_CONTENT,
Event.BLOCKED_CRYPTOMINING_CONTENT, Event.LOADED_CRYPTOMINING_CONTENT,
Event.BLOCKED_UNSAFE_CONTENT, Event.COOKIES_LOADED,
Event.COOKIES_LOADED_TRACKER, Event.COOKIES_LOADED_SOCIALTRACKER,
Event.COOKIES_BLOCKED_BY_PERMISSION, Event.COOKIES_BLOCKED_TRACKER,
Event.COOKIES_BLOCKED_SOCIALTRACKER, Event.COOKIES_BLOCKED_ALL,
Event.COOKIES_PARTITIONED_FOREIGN, Event.COOKIES_BLOCKED_FOREIGN,
Event.BLOCKED_SOCIALTRACKING_CONTENT, Event.LOADED_SOCIALTRACKING_CONTENT })
@IntDef({ Event.BLOCKED_TRACKING_CONTENT, Event.LOADED_LEVEL_1_TRACKING_CONTENT,
Event.LOADED_LEVEL_2_TRACKING_CONTENT, Event.BLOCKED_FINGERPRINTING_CONTENT,
Event.LOADED_FINGERPRINTING_CONTENT, Event.BLOCKED_CRYPTOMINING_CONTENT,
Event.LOADED_CRYPTOMINING_CONTENT, Event.BLOCKED_UNSAFE_CONTENT,
Event.COOKIES_LOADED, Event.COOKIES_LOADED_TRACKER,
Event.COOKIES_LOADED_SOCIALTRACKER, Event.COOKIES_BLOCKED_BY_PERMISSION,
Event.COOKIES_BLOCKED_TRACKER, Event.COOKIES_BLOCKED_SOCIALTRACKER,
Event.COOKIES_BLOCKED_ALL, Event.COOKIES_PARTITIONED_FOREIGN,
Event.COOKIES_BLOCKED_FOREIGN, Event.BLOCKED_SOCIALTRACKING_CONTENT,
Event.LOADED_SOCIALTRACKING_CONTENT })
/* package */ @interface LogEvent {}
/**

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

@ -43,6 +43,9 @@ exclude: true
- Added support for Browser and Page Action from the WebExtension API.
See [`WebExtension.Action`][72.14].
([bug 1530402]({{bugzilla}}1530402))
- ⚠️ Split [`ContentBlockingController.Event.LOADED_TRACKING_CONTENT`][72.15] into
[`ContentBlockingController.Event.LOADED_LEVEL_1_TRACKING_CONTENT`][72.16] and
[`ContentBlockingController.Event.LOADED_LEVEL_2_TRACKING_CONTENT`][72.17].
[72.1]: {{javadoc_uri}}/GeckoSession.NavigationDelegate.LoadRequest#hasUserGesture-
[72.2]: {{javadoc_uri}}/Autofill.html
@ -58,6 +61,9 @@ exclude: true
[72.12]: https://developer.android.com/reference/android/view/TextureView
[72.13]: https://developer.android.com/reference/android/view/SurfaceView
[72.14]: {{javadoc_uri}}/WebExtension.Action.html
[72.15]: {{javadoc_uri}}/ContentBlockingController.Event.html#LOADED_TRACKING_CONTENT
[72.16]: {{javadoc_uri}}/ContentBlockingController.Event.html#LOADED_LEVEL_1_TRACKING_CONTENT
[72.17]: {{javadoc_uri}}/ContentBlockingController.Event.html#LOADED_LEVEL_2_TRACKING_CONTENT
## v71
- Added a content blocking flag for blocked social cookies to [`ContentBlocking`][70.17].

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

@ -146,8 +146,13 @@ UrlClassifierFeatureTrackingAnnotation::ProcessChannel(
UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes);
UrlClassifierCommon::AnnotateChannel(
aChannel, flags, nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
uint32_t notification =
((flags & nsIClassifiedChannel::ClassificationFlags::
CLASSIFIED_TRACKING_CONTENT) != 0)
? nsIWebProgressListener::STATE_LOADED_LEVEL_2_TRACKING_CONTENT
: nsIWebProgressListener::STATE_LOADED_LEVEL_1_TRACKING_CONTENT;
UrlClassifierCommon::AnnotateChannel(aChannel, flags, notification);
return NS_OK;
}

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

@ -185,8 +185,12 @@ void nsSecureBrowserUIImpl::CheckForContentBlockingEvents() {
mEvent |= STATE_BLOCKED_TRACKING_CONTENT;
}
if (doc->GetHasTrackingContentLoaded()) {
mEvent |= STATE_LOADED_TRACKING_CONTENT;
if (doc->GetHasLevel1TrackingContentLoaded()) {
mEvent |= STATE_LOADED_LEVEL_1_TRACKING_CONTENT;
}
if (doc->GetHasLevel2TrackingContentLoaded()) {
mEvent |= STATE_LOADED_LEVEL_2_TRACKING_CONTENT;
}
// Has fingerprinting content been blocked or loaded?

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

@ -193,7 +193,11 @@ TrackingDBService.prototype = {
let result = null;
let isTracker = false;
for (let [state, blocked] of events) {
if (state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) {
if (
state &
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT ||
state & Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_2_TRACKING_CONTENT
) {
isTracker = true;
}
if (blocked) {

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

@ -91,7 +91,7 @@ add_task(async function() {
let expectTrackerFound = item => {
is(
item[0],
Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT,
"Correct blocking type reported"
);
is(item[1], true, "Correct blocking status reported");

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

@ -208,7 +208,7 @@ add_task(async function() {
let expectTrackerFound = item => {
is(
item[0],
Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT,
"Correct blocking type reported"
);
is(item[1], true, "Correct blocking status reported");

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

@ -58,7 +58,7 @@ const LOG = {
"https://6.example.com": [
[
Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL |
Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
Ci.nsIWebProgressListener.STATE_LOADED_LEVEL_1_TRACKING_CONTENT,
true,
4,
],

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

@ -268,8 +268,11 @@ interface nsIWebProgressListener : nsISupports
* STATE_BLOCKED_TRACKING_CONTENT
* Tracking content has been blocked from loading.
*
* STATE_LOADED_TRACKING_CONTENT
* Tracking content has been loaded.
* STATE_LOADED_LEVEL_1_TRACKING_CONTENT
* Tracking content from the Disconnect Level 1 list has been loaded.
*
* STATE_LOADED_LEVEL_2_TRACKING_CONTENT
* Tracking content from the Disconnect Level 2 list has been loaded.
*
* STATE_BLOCKED_FINGERPRINTING_CONTENT
* Fingerprinting content has been blocked from loading.
@ -330,24 +333,25 @@ interface nsIWebProgressListener : nsISupports
* STATE_LOADED_SOCIALTRACKING_CONTENT
* SocialTracking content has been loaded.
*/
const unsigned long STATE_BLOCKED_TRACKING_CONTENT = 0x00001000;
const unsigned long STATE_LOADED_TRACKING_CONTENT = 0x00002000;
const unsigned long STATE_BLOCKED_FINGERPRINTING_CONTENT = 0x00000040;
const unsigned long STATE_LOADED_FINGERPRINTING_CONTENT = 0x00000400;
const unsigned long STATE_BLOCKED_CRYPTOMINING_CONTENT = 0x00000800;
const unsigned long STATE_LOADED_CRYPTOMINING_CONTENT = 0x00200000;
const unsigned long STATE_BLOCKED_UNSAFE_CONTENT = 0x00004000;
const unsigned long STATE_COOKIES_LOADED = 0x00008000;
const unsigned long STATE_COOKIES_LOADED_TRACKER = 0x00040000;
const unsigned long STATE_COOKIES_LOADED_SOCIALTRACKER = 0x00080000;
const unsigned long STATE_COOKIES_BLOCKED_BY_PERMISSION = 0x10000000;
const unsigned long STATE_COOKIES_BLOCKED_TRACKER = 0x20000000;
const unsigned long STATE_COOKIES_BLOCKED_SOCIALTRACKER = 0x01000000;
const unsigned long STATE_COOKIES_BLOCKED_ALL = 0x40000000;
const unsigned long STATE_COOKIES_PARTITIONED_FOREIGN = 0x80000000;
const unsigned long STATE_COOKIES_BLOCKED_FOREIGN = 0x00000080;
const unsigned long STATE_BLOCKED_SOCIALTRACKING_CONTENT = 0x00010000;
const unsigned long STATE_LOADED_SOCIALTRACKING_CONTENT = 0x00020000;
const unsigned long STATE_BLOCKED_TRACKING_CONTENT = 0x00001000;
const unsigned long STATE_LOADED_LEVEL_1_TRACKING_CONTENT = 0x00002000;
const unsigned long STATE_LOADED_LEVEL_2_TRACKING_CONTENT = 0x00100000;
const unsigned long STATE_BLOCKED_FINGERPRINTING_CONTENT = 0x00000040;
const unsigned long STATE_LOADED_FINGERPRINTING_CONTENT = 0x00000400;
const unsigned long STATE_BLOCKED_CRYPTOMINING_CONTENT = 0x00000800;
const unsigned long STATE_LOADED_CRYPTOMINING_CONTENT = 0x00200000;
const unsigned long STATE_BLOCKED_UNSAFE_CONTENT = 0x00004000;
const unsigned long STATE_COOKIES_LOADED = 0x00008000;
const unsigned long STATE_COOKIES_LOADED_TRACKER = 0x00040000;
const unsigned long STATE_COOKIES_LOADED_SOCIALTRACKER = 0x00080000;
const unsigned long STATE_COOKIES_BLOCKED_BY_PERMISSION = 0x10000000;
const unsigned long STATE_COOKIES_BLOCKED_TRACKER = 0x20000000;
const unsigned long STATE_COOKIES_BLOCKED_SOCIALTRACKER = 0x01000000;
const unsigned long STATE_COOKIES_BLOCKED_ALL = 0x40000000;
const unsigned long STATE_COOKIES_PARTITIONED_FOREIGN = 0x80000000;
const unsigned long STATE_COOKIES_BLOCKED_FOREIGN = 0x00000080;
const unsigned long STATE_BLOCKED_SOCIALTRACKING_CONTENT = 0x00010000;
const unsigned long STATE_LOADED_SOCIALTRACKING_CONTENT = 0x00020000;
/**
* Notification indicating the state has changed for one of the requests