2019-03-14 17:48:20 +00:00
|
|
|
/* -*- 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 "UrlClassifierFeatureFingerprintingAnnotation.h"
|
|
|
|
|
|
|
|
#include "mozilla/net/UrlClassifierCommon.h"
|
2019-10-19 04:30:24 +00:00
|
|
|
#include "nsIClassifiedChannel.h"
|
2019-03-14 17:48:20 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
2021-10-27 08:52:25 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsIChannel.h"
|
2019-03-14 17:48:20 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
#define FINGERPRINTING_ANNOTATION_FEATURE_NAME "fingerprinting-annotation"
|
|
|
|
|
2020-07-07 16:17:11 +00:00
|
|
|
#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLOCKLIST \
|
2019-03-14 17:48:20 +00:00
|
|
|
"urlclassifier.features.fingerprinting.annotate.blacklistTables"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLOCKLIST_TEST_ENTRIES \
|
2019-03-14 17:48:20 +00:00
|
|
|
"urlclassifier.features.fingerprinting.annotate.blacklistHosts"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_ENTITYLIST \
|
2019-03-14 17:48:20 +00:00
|
|
|
"urlclassifier.features.fingerprinting.annotate.whitelistTables"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_ENTITYLIST_TEST_ENTRIES \
|
2019-03-14 17:48:20 +00:00
|
|
|
"urlclassifier.features.fingerprinting.annotate.whitelistHosts"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_EXCEPTION_URLS \
|
2019-04-10 15:11:19 +00:00
|
|
|
"urlclassifier.features.fingerprinting.annotate.skipURLs"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define TABLE_FINGERPRINTING_ANNOTATION_BLOCKLIST_PREF \
|
2019-03-14 17:48:20 +00:00
|
|
|
"fingerprinting-annotate-blacklist-pref"
|
2020-07-07 16:17:11 +00:00
|
|
|
#define TABLE_FINGERPRINTING_ANNOTATION_ENTITYLIST_PREF \
|
2019-03-14 17:48:20 +00:00
|
|
|
"fingerprinting-annotate-whitelist-pref"
|
|
|
|
|
|
|
|
StaticRefPtr<UrlClassifierFeatureFingerprintingAnnotation>
|
|
|
|
gFeatureFingerprintingAnnotation;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation()
|
2021-08-26 15:13:10 +00:00
|
|
|
: UrlClassifierFeatureAntiTrackingBase(
|
2019-03-14 17:48:20 +00:00
|
|
|
nsLiteralCString(FINGERPRINTING_ANNOTATION_FEATURE_NAME),
|
2020-07-07 16:17:11 +00:00
|
|
|
nsLiteralCString(URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLOCKLIST),
|
|
|
|
nsLiteralCString(URLCLASSIFIER_FINGERPRINTING_ANNOTATION_ENTITYLIST),
|
2019-03-14 17:48:20 +00:00
|
|
|
nsLiteralCString(
|
2020-07-07 16:17:11 +00:00
|
|
|
URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLOCKLIST_TEST_ENTRIES),
|
2019-03-14 17:48:20 +00:00
|
|
|
nsLiteralCString(
|
2020-07-07 16:17:11 +00:00
|
|
|
URLCLASSIFIER_FINGERPRINTING_ANNOTATION_ENTITYLIST_TEST_ENTRIES),
|
|
|
|
nsLiteralCString(TABLE_FINGERPRINTING_ANNOTATION_BLOCKLIST_PREF),
|
|
|
|
nsLiteralCString(TABLE_FINGERPRINTING_ANNOTATION_ENTITYLIST_PREF),
|
|
|
|
nsLiteralCString(
|
|
|
|
URLCLASSIFIER_FINGERPRINTING_ANNOTATION_EXCEPTION_URLS)) {}
|
2019-03-14 17:48:20 +00:00
|
|
|
|
|
|
|
/* static */ const char* UrlClassifierFeatureFingerprintingAnnotation::Name() {
|
|
|
|
return FINGERPRINTING_ANNOTATION_FEATURE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFingerprintingAnnotation::MaybeInitialize() {
|
2020-07-20 10:09:37 +00:00
|
|
|
UC_LOG_LEAK(
|
|
|
|
("UrlClassifierFeatureFingerprintingAnnotation::MaybeInitialize"));
|
2019-03-14 17:48:20 +00:00
|
|
|
|
|
|
|
if (!gFeatureFingerprintingAnnotation) {
|
|
|
|
gFeatureFingerprintingAnnotation =
|
|
|
|
new UrlClassifierFeatureFingerprintingAnnotation();
|
|
|
|
gFeatureFingerprintingAnnotation->InitializePreferences();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown() {
|
2020-07-20 10:09:37 +00:00
|
|
|
UC_LOG_LEAK(("UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown"));
|
2019-03-14 17:48:20 +00:00
|
|
|
|
|
|
|
if (gFeatureFingerprintingAnnotation) {
|
|
|
|
gFeatureFingerprintingAnnotation->ShutdownPreferences();
|
|
|
|
gFeatureFingerprintingAnnotation = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<UrlClassifierFeatureFingerprintingAnnotation>
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::MaybeCreate(
|
|
|
|
nsIChannel* aChannel) {
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
2020-07-20 10:09:37 +00:00
|
|
|
UC_LOG_LEAK(
|
|
|
|
("UrlClassifierFeatureFingerprintingAnnotation::MaybeCreate - channel %p",
|
2019-03-14 17:48:20 +00:00
|
|
|
aChannel));
|
|
|
|
|
2020-04-02 06:32:44 +00:00
|
|
|
if (UrlClassifierCommon::IsPassiveContent(aChannel)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-03-14 17:48:20 +00:00
|
|
|
MaybeInitialize();
|
|
|
|
MOZ_ASSERT(gFeatureFingerprintingAnnotation);
|
|
|
|
|
|
|
|
RefPtr<UrlClassifierFeatureFingerprintingAnnotation> self =
|
|
|
|
gFeatureFingerprintingAnnotation;
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIUrlClassifierFeature>
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::GetIfNameMatches(
|
|
|
|
const nsACString& aName) {
|
|
|
|
if (!aName.EqualsLiteral(FINGERPRINTING_ANNOTATION_FEATURE_NAME)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeInitialize();
|
|
|
|
MOZ_ASSERT(gFeatureFingerprintingAnnotation);
|
|
|
|
|
|
|
|
RefPtr<UrlClassifierFeatureFingerprintingAnnotation> self =
|
|
|
|
gFeatureFingerprintingAnnotation;
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::ProcessChannel(
|
2019-04-04 05:31:44 +00:00
|
|
|
nsIChannel* aChannel, const nsTArray<nsCString>& aList,
|
2019-04-26 13:02:35 +00:00
|
|
|
const nsTArray<nsCString>& aHashes, bool* aShouldContinue) {
|
2019-03-14 17:48:20 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aShouldContinue);
|
|
|
|
|
|
|
|
// This is not a blocking feature.
|
|
|
|
*aShouldContinue = true;
|
|
|
|
|
|
|
|
UC_LOG(
|
2020-07-20 10:09:37 +00:00
|
|
|
("UrlClassifierFeatureFingerprintingAnnotation::ProcessChannel - "
|
|
|
|
"annotating channel %p",
|
2019-03-14 17:48:20 +00:00
|
|
|
aChannel));
|
|
|
|
|
2019-04-04 05:31:44 +00:00
|
|
|
static std::vector<UrlClassifierCommon::ClassificationData>
|
|
|
|
sClassificationData = {
|
|
|
|
{"content-fingerprinting-track-"_ns,
|
2019-10-19 04:30:24 +00:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::
|
2019-04-04 05:31:44 +00:00
|
|
|
CLASSIFIED_FINGERPRINTING_CONTENT},
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags(
|
|
|
|
aList, sClassificationData,
|
2019-10-19 04:30:24 +00:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING);
|
2019-04-04 05:31:44 +00:00
|
|
|
|
2019-05-02 16:06:56 +00:00
|
|
|
UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes);
|
|
|
|
|
2019-03-14 17:48:20 +00:00
|
|
|
UrlClassifierCommon::AnnotateChannel(
|
2019-08-07 15:54:54 +00:00
|
|
|
aChannel, flags,
|
2019-03-14 17:48:20 +00:00
|
|
|
nsIWebProgressListener::STATE_LOADED_FINGERPRINTING_CONTENT);
|
2019-04-04 05:31:44 +00:00
|
|
|
|
2019-03-14 17:48:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::GetURIByListType(
|
|
|
|
nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
|
2019-09-27 13:22:18 +00:00
|
|
|
nsIUrlClassifierFeature::URIType* aURIType, nsIURI** aURI) {
|
2019-03-14 17:48:20 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
2019-09-27 13:22:18 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURIType);
|
2019-03-14 17:48:20 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
2020-07-07 16:17:11 +00:00
|
|
|
if (aListType == nsIUrlClassifierFeature::blocklist) {
|
|
|
|
*aURIType = nsIUrlClassifierFeature::blocklistURI;
|
2019-03-14 17:48:20 +00:00
|
|
|
return aChannel->GetURI(aURI);
|
|
|
|
}
|
|
|
|
|
2020-07-07 16:17:11 +00:00
|
|
|
MOZ_ASSERT(aListType == nsIUrlClassifierFeature::entitylist);
|
2019-09-27 13:22:18 +00:00
|
|
|
|
2020-07-07 16:17:11 +00:00
|
|
|
*aURIType = nsIUrlClassifierFeature::pairwiseEntitylistURI;
|
|
|
|
return UrlClassifierCommon::CreatePairwiseEntityListURI(aChannel, aURI);
|
2019-03-14 17:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|