forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1773701 - Part 2: Implement the email tracking data collection fe…
…ature. r=dimi Differential Revision: https://phabricator.services.mozilla.com/D151522
- Loading branch information
Showing
5 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
netwerk/url-classifier/UrlClassifierFeatureEmailTrackingDataCollection.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* -*- 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" | ||
|
||
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 |
45 changes: 45 additions & 0 deletions
45
netwerk/url-classifier/UrlClassifierFeatureEmailTrackingDataCollection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters