mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-22 10:27:03 +00:00
Bug 1773701 - Part 2: Implement the email tracking data collection feature. r=dimi
Differential Revision: https://phabricator.services.mozilla.com/D151522
This commit is contained in:
parent
edd54f5806
commit
60b6f25dfe
@ -11725,6 +11725,12 @@
|
||||
value: @IS_NIGHTLY_BUILD@
|
||||
mirror: always
|
||||
|
||||
# Collecting 3rd party emailtracking telemetry.
|
||||
- name: privacy.trackingprotection.emailtracking.data_collection.enabled
|
||||
type: bool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Whether Origin Telemetry should be enabled.
|
||||
# NOTE: if telemetry.origin_telemetry_test_mode.enabled is enabled, this pref
|
||||
# won't have any effect.
|
||||
|
@ -0,0 +1,180 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "UrlClassifierFeatureEmailTrackingDataCollection.h"
|
||||
|
||||
#include "mozilla/net/UrlClassifierCommon.h"
|
||||
#include "mozilla/StaticPrefs_privacy.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIClassifiedChannel.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
namespace {
|
||||
|
||||
#define EMAILTRACKING_DATACOLLECTION_FEATURE_NAME \
|
||||
"emailtracking-data-collection"
|
||||
|
||||
#define URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_BLOCKLIST \
|
||||
"urlclassifier.features.emailtracking.datacollection.blocklistTables"
|
||||
#define URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_BLOCKLIST_TEST_ENTRIES \
|
||||
"urlclassifier.features.emailtracking.datacollection.blocklistHosts"
|
||||
#define URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_ENTITYLIST \
|
||||
"urlclassifier.features.emailtracking.datacollection.allowlistTables"
|
||||
#define URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_ENTITYLIST_TEST_ENTRIES \
|
||||
"urlclassifier.features.emailtracking.datacollection.allowlistHosts"
|
||||
#define URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_EXCEPTION_URLS \
|
||||
"urlclassifier.features.emailtracking.datacollection.skipURLs"
|
||||
#define TABLE_EMAILTRACKING_DATACOLLECTION_BLOCKLIST_PREF \
|
||||
"emailtracking-data-collection-blocklist-pref"
|
||||
#define TABLE_EMAILTRACKING_DATACOLLECTION_ENTITYLIST_PREF \
|
||||
"emailtracking-data-collection-allowlist-pref"
|
||||
|
||||
StaticRefPtr<UrlClassifierFeatureEmailTrackingDataCollection>
|
||||
gFeatureEmailTrackingDataCollection;
|
||||
} // namespace
|
||||
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::
|
||||
UrlClassifierFeatureEmailTrackingDataCollection()
|
||||
: UrlClassifierFeatureAntiTrackingBase(
|
||||
nsLiteralCString(EMAILTRACKING_DATACOLLECTION_FEATURE_NAME),
|
||||
nsLiteralCString(
|
||||
URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_BLOCKLIST),
|
||||
nsLiteralCString(
|
||||
URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_ENTITYLIST),
|
||||
nsLiteralCString(
|
||||
URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_BLOCKLIST_TEST_ENTRIES),
|
||||
nsLiteralCString(
|
||||
URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_ENTITYLIST_TEST_ENTRIES),
|
||||
nsLiteralCString(TABLE_EMAILTRACKING_DATACOLLECTION_BLOCKLIST_PREF),
|
||||
nsLiteralCString(TABLE_EMAILTRACKING_DATACOLLECTION_ENTITYLIST_PREF),
|
||||
nsLiteralCString(
|
||||
URLCLASSIFIER_EMAILTRACKING_DATACOLLECTION_EXCEPTION_URLS)) {}
|
||||
|
||||
/* static */
|
||||
const char* UrlClassifierFeatureEmailTrackingDataCollection::Name() {
|
||||
return EMAILTRACKING_DATACOLLECTION_FEATURE_NAME;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void UrlClassifierFeatureEmailTrackingDataCollection::MaybeInitialize() {
|
||||
UC_LOG_LEAK(
|
||||
("UrlClassifierFeatureEmailTrackingDataCollection::MaybeInitialize"));
|
||||
|
||||
if (!gFeatureEmailTrackingDataCollection) {
|
||||
gFeatureEmailTrackingDataCollection =
|
||||
new UrlClassifierFeatureEmailTrackingDataCollection();
|
||||
gFeatureEmailTrackingDataCollection->InitializePreferences();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
void UrlClassifierFeatureEmailTrackingDataCollection::MaybeShutdown() {
|
||||
UC_LOG_LEAK(
|
||||
("UrlClassifierFeatureEmailTrackingDataCollection::MaybeShutdown"));
|
||||
|
||||
if (gFeatureEmailTrackingDataCollection) {
|
||||
gFeatureEmailTrackingDataCollection->ShutdownPreferences();
|
||||
gFeatureEmailTrackingDataCollection = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<UrlClassifierFeatureEmailTrackingDataCollection>
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::MaybeCreate(
|
||||
nsIChannel* aChannel) {
|
||||
MOZ_ASSERT(aChannel);
|
||||
|
||||
UC_LOG_LEAK(
|
||||
("UrlClassifierFeatureEmailTrackingDataCollection::MaybeCreate - channel "
|
||||
"%p",
|
||||
aChannel));
|
||||
|
||||
if (!StaticPrefs::
|
||||
privacy_trackingprotection_emailtracking_data_collection_enabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MaybeInitialize();
|
||||
MOZ_ASSERT(gFeatureEmailTrackingDataCollection);
|
||||
|
||||
RefPtr<UrlClassifierFeatureEmailTrackingDataCollection> self =
|
||||
gFeatureEmailTrackingDataCollection;
|
||||
return self.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<nsIUrlClassifierFeature>
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::GetIfNameMatches(
|
||||
const nsACString& aName) {
|
||||
if (!aName.EqualsLiteral(EMAILTRACKING_DATACOLLECTION_FEATURE_NAME)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MaybeInitialize();
|
||||
MOZ_ASSERT(gFeatureEmailTrackingDataCollection);
|
||||
|
||||
RefPtr<UrlClassifierFeatureEmailTrackingDataCollection> self =
|
||||
gFeatureEmailTrackingDataCollection;
|
||||
return self.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::ProcessChannel(
|
||||
nsIChannel* aChannel, const nsTArray<nsCString>& aList,
|
||||
const nsTArray<nsCString>& aHashes, bool* aShouldContinue) {
|
||||
NS_ENSURE_ARG_POINTER(aChannel);
|
||||
NS_ENSURE_ARG_POINTER(aShouldContinue);
|
||||
|
||||
// This is not a blocking feature.
|
||||
*aShouldContinue = true;
|
||||
|
||||
UC_LOG(
|
||||
("UrlClassifierFeatureEmailTrackingDataCollection::ProcessChannel - "
|
||||
"annotating channel %p",
|
||||
aChannel));
|
||||
|
||||
static std::vector<UrlClassifierCommon::ClassificationData>
|
||||
sClassificationData = {
|
||||
{"base-email-track-"_ns,
|
||||
nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_EMAILTRACKING},
|
||||
{"content-email-track-"_ns,
|
||||
nsIClassifiedChannel::ClassificationFlags::
|
||||
CLASSIFIED_EMAILTRACKING_CONTENT},
|
||||
};
|
||||
|
||||
uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags(
|
||||
aList, sClassificationData,
|
||||
nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_EMAILTRACKING);
|
||||
|
||||
// The flags will be used for Telemetry in the later patch.
|
||||
Unused << flags;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::GetURIByListType(
|
||||
nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
|
||||
nsIUrlClassifierFeature::URIType* aURIType, nsIURI** aURI) {
|
||||
NS_ENSURE_ARG_POINTER(aChannel);
|
||||
NS_ENSURE_ARG_POINTER(aURIType);
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
if (aListType == nsIUrlClassifierFeature::blocklist) {
|
||||
*aURIType = nsIUrlClassifierFeature::blocklistURI;
|
||||
return aChannel->GetURI(aURI);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aListType == nsIUrlClassifierFeature::entitylist);
|
||||
|
||||
*aURIType = nsIUrlClassifierFeature::pairwiseEntitylistURI;
|
||||
return UrlClassifierCommon::CreatePairwiseEntityListURI(aChannel, aURI);
|
||||
}
|
||||
|
||||
} // namespace mozilla::net
|
@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_net_UrlClassifierFeatureEmailTrackingDataCollection_h
|
||||
#define mozilla_net_UrlClassifierFeatureEmailTrackingDataCollection_h
|
||||
|
||||
#include "UrlClassifierFeatureBase.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
class UrlClassifierFeatureEmailTrackingDataCollection final
|
||||
: public UrlClassifierFeatureAntiTrackingBase {
|
||||
public:
|
||||
static const char* Name();
|
||||
|
||||
static void MaybeShutdown();
|
||||
|
||||
static already_AddRefed<UrlClassifierFeatureEmailTrackingDataCollection>
|
||||
MaybeCreate(nsIChannel* aChannel);
|
||||
|
||||
static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
|
||||
const nsACString& aName);
|
||||
|
||||
NS_IMETHOD ProcessChannel(nsIChannel* aChannel,
|
||||
const nsTArray<nsCString>& aList,
|
||||
const nsTArray<nsCString>& aHashes,
|
||||
bool* aShouldContinue) override;
|
||||
|
||||
NS_IMETHOD GetURIByListType(nsIChannel* aChannel,
|
||||
nsIUrlClassifierFeature::listType aListType,
|
||||
nsIUrlClassifierFeature::URIType* aURIType,
|
||||
nsIURI** aURI) override;
|
||||
|
||||
private:
|
||||
UrlClassifierFeatureEmailTrackingDataCollection();
|
||||
|
||||
static void MaybeInitialize();
|
||||
};
|
||||
|
||||
} // namespace mozilla::net
|
||||
|
||||
#endif // mozilla_net_UrlClassifierFeatureEmailTrackingDataCollection_h
|
@ -9,6 +9,7 @@
|
||||
// List of Features
|
||||
#include "UrlClassifierFeatureCryptominingAnnotation.h"
|
||||
#include "UrlClassifierFeatureCryptominingProtection.h"
|
||||
#include "UrlClassifierFeatureEmailTrackingDataCollection.h"
|
||||
#include "UrlClassifierFeatureEmailTrackingProtection.h"
|
||||
#include "UrlClassifierFeatureFingerprintingAnnotation.h"
|
||||
#include "UrlClassifierFeatureFingerprintingProtection.h"
|
||||
@ -35,6 +36,7 @@ void UrlClassifierFeatureFactory::Shutdown() {
|
||||
|
||||
UrlClassifierFeatureCryptominingAnnotation::MaybeShutdown();
|
||||
UrlClassifierFeatureCryptominingProtection::MaybeShutdown();
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::MaybeShutdown();
|
||||
UrlClassifierFeatureEmailTrackingProtection::MaybeShutdown();
|
||||
UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown();
|
||||
UrlClassifierFeatureFingerprintingProtection::MaybeShutdown();
|
||||
@ -60,6 +62,16 @@ void UrlClassifierFeatureFactory::GetFeaturesFromChannel(
|
||||
// feature order, and this could produce different results with a different
|
||||
// feature ordering.
|
||||
|
||||
// Email Tracking Data Collection
|
||||
// This needs to be run before other features so that other blocking features
|
||||
// won't stop us to collect data for email trackers. Note that this feature
|
||||
// is not a blocking feature.
|
||||
feature =
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::MaybeCreate(aChannel);
|
||||
if (feature) {
|
||||
aFeatures.AppendElement(feature);
|
||||
}
|
||||
|
||||
// Email Tracking Protection
|
||||
feature = UrlClassifierFeatureEmailTrackingProtection::MaybeCreate(aChannel);
|
||||
if (feature) {
|
||||
@ -148,6 +160,13 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
|
||||
return feature.forget();
|
||||
}
|
||||
|
||||
// Email Tracking Data Collection
|
||||
feature =
|
||||
UrlClassifierFeatureEmailTrackingDataCollection::GetIfNameMatches(aName);
|
||||
if (feature) {
|
||||
return feature.forget();
|
||||
}
|
||||
|
||||
// Email Tracking Protection
|
||||
feature =
|
||||
UrlClassifierFeatureEmailTrackingProtection::GetIfNameMatches(aName);
|
||||
@ -230,6 +249,12 @@ void UrlClassifierFeatureFactory::GetFeatureNames(nsTArray<nsCString>& aArray) {
|
||||
aArray.AppendElement(name);
|
||||
}
|
||||
|
||||
// Email Tracking Data Collection
|
||||
name.Assign(UrlClassifierFeatureEmailTrackingDataCollection::Name());
|
||||
if (!name.IsEmpty()) {
|
||||
aArray.AppendElement(name);
|
||||
}
|
||||
|
||||
// Email Tracking Protection
|
||||
name.Assign(UrlClassifierFeatureEmailTrackingProtection::Name());
|
||||
if (!name.IsEmpty()) {
|
||||
|
@ -36,6 +36,7 @@ UNIFIED_SOURCES += [
|
||||
"UrlClassifierFeatureCryptominingAnnotation.cpp",
|
||||
"UrlClassifierFeatureCryptominingProtection.cpp",
|
||||
"UrlClassifierFeatureCustomTables.cpp",
|
||||
"UrlClassifierFeatureEmailTrackingDataCollection.cpp",
|
||||
"UrlClassifierFeatureEmailTrackingProtection.cpp",
|
||||
"UrlClassifierFeatureFactory.cpp",
|
||||
"UrlClassifierFeatureFingerprintingAnnotation.cpp",
|
||||
|
Loading…
x
Reference in New Issue
Block a user