2018-12-14 14:40:16 +03: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 "UrlClassifierFeatureTrackingAnnotation.h"
|
|
|
|
|
2019-03-15 21:38:27 +03:00
|
|
|
#include "Classifier.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
#include "mozilla/AntiTrackingCommon.h"
|
|
|
|
#include "mozilla/Logging.h"
|
|
|
|
#include "mozilla/StaticPrefs.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/net/UrlClassifierCommon.h"
|
2018-12-14 14:40:17 +03:00
|
|
|
#include "nsContentUtils.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
#define TRACKING_ANNOTATION_FEATURE_NAME "tracking-annotation"
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
#define URLCLASSIFIER_ANNOTATION_BLACKLIST \
|
|
|
|
"urlclassifier.trackingAnnotationTable"
|
|
|
|
#define URLCLASSIFIER_ANNOTATION_BLACKLIST_TEST_ENTRIES \
|
|
|
|
"urlclassifier.trackingAnnotationTable.testEntries"
|
|
|
|
#define URLCLASSIFIER_ANNOTATION_WHITELIST \
|
|
|
|
"urlclassifier.trackingAnnotationWhitelistTable"
|
|
|
|
#define URLCLASSIFIER_ANNOTATION_WHITELIST_TEST_ENTRIES \
|
|
|
|
"urlclassifier.trackingAnnotationWhitelistTable.testEntries"
|
2018-12-14 14:40:17 +03:00
|
|
|
#define URLCLASSIFIER_TRACKING_ANNOTATION_SKIP_URLS \
|
|
|
|
"urlclassifier.trackingAnnotationSkipURLs"
|
2018-12-14 14:40:16 +03:00
|
|
|
#define TABLE_ANNOTATION_BLACKLIST_PREF "annotation-blacklist-pref"
|
|
|
|
#define TABLE_ANNOTATION_WHITELIST_PREF "annotation-whitelist-pref"
|
|
|
|
|
|
|
|
StaticRefPtr<UrlClassifierFeatureTrackingAnnotation> gFeatureTrackingAnnotation;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
UrlClassifierFeatureTrackingAnnotation::UrlClassifierFeatureTrackingAnnotation()
|
|
|
|
: UrlClassifierFeatureBase(
|
2019-01-05 11:10:45 +03:00
|
|
|
NS_LITERAL_CSTRING(TRACKING_ANNOTATION_FEATURE_NAME),
|
2018-12-14 14:40:16 +03:00
|
|
|
NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST),
|
|
|
|
NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_WHITELIST),
|
|
|
|
NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST_TEST_ENTRIES),
|
|
|
|
NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_WHITELIST_TEST_ENTRIES),
|
|
|
|
NS_LITERAL_CSTRING(TABLE_ANNOTATION_BLACKLIST_PREF),
|
2018-12-14 14:40:17 +03:00
|
|
|
NS_LITERAL_CSTRING(TABLE_ANNOTATION_WHITELIST_PREF),
|
|
|
|
NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_ANNOTATION_SKIP_URLS)) {}
|
2018-12-14 14:40:16 +03:00
|
|
|
|
2019-01-09 01:05:40 +03:00
|
|
|
/* static */ const char* UrlClassifierFeatureTrackingAnnotation::Name() {
|
|
|
|
return TRACKING_ANNOTATION_FEATURE_NAME;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureTrackingAnnotation::MaybeInitialize() {
|
2019-01-05 11:11:06 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
UC_LOG(("UrlClassifierFeatureTrackingAnnotation: MaybeInitialize"));
|
2018-12-14 14:40:16 +03:00
|
|
|
|
2019-01-05 11:11:06 +03:00
|
|
|
if (!gFeatureTrackingAnnotation) {
|
|
|
|
gFeatureTrackingAnnotation = new UrlClassifierFeatureTrackingAnnotation();
|
|
|
|
gFeatureTrackingAnnotation->InitializePreferences();
|
|
|
|
}
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureTrackingAnnotation::MaybeShutdown() {
|
2019-01-05 11:11:06 +03:00
|
|
|
UC_LOG(("UrlClassifierFeatureTrackingAnnotation: MaybeShutdown"));
|
2018-12-14 14:40:16 +03:00
|
|
|
|
2019-01-05 11:11:06 +03:00
|
|
|
if (gFeatureTrackingAnnotation) {
|
|
|
|
gFeatureTrackingAnnotation->ShutdownPreferences();
|
|
|
|
gFeatureTrackingAnnotation = nullptr;
|
|
|
|
}
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<UrlClassifierFeatureTrackingAnnotation>
|
2018-12-14 14:40:16 +03:00
|
|
|
UrlClassifierFeatureTrackingAnnotation::MaybeCreate(nsIChannel* aChannel) {
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
|
|
|
UC_LOG(("UrlClassifierFeatureTrackingAnnotation: MaybeCreate for channel %p",
|
|
|
|
aChannel));
|
|
|
|
|
|
|
|
if (!StaticPrefs::privacy_trackingprotection_annotate_channels()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-27 02:51:14 +03:00
|
|
|
if (!UrlClassifierCommon::ShouldEnableClassifier(aChannel)) {
|
2018-12-14 14:40:16 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:11:06 +03:00
|
|
|
MaybeInitialize();
|
|
|
|
MOZ_ASSERT(gFeatureTrackingAnnotation);
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
RefPtr<UrlClassifierFeatureTrackingAnnotation> self =
|
|
|
|
gFeatureTrackingAnnotation;
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIUrlClassifierFeature>
|
2019-01-05 11:10:45 +03:00
|
|
|
UrlClassifierFeatureTrackingAnnotation::GetIfNameMatches(
|
|
|
|
const nsACString& aName) {
|
|
|
|
if (!aName.EqualsLiteral(TRACKING_ANNOTATION_FEATURE_NAME)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:11:06 +03:00
|
|
|
MaybeInitialize();
|
|
|
|
MOZ_ASSERT(gFeatureTrackingAnnotation);
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
RefPtr<UrlClassifierFeatureTrackingAnnotation> self =
|
|
|
|
gFeatureTrackingAnnotation;
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:17 +03:00
|
|
|
NS_IMETHODIMP
|
2019-04-04 08:31:44 +03:00
|
|
|
UrlClassifierFeatureTrackingAnnotation::ProcessChannel(
|
|
|
|
nsIChannel* aChannel, const nsTArray<nsCString>& aList,
|
|
|
|
bool* aShouldContinue) {
|
2018-12-14 14:40:17 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aShouldContinue);
|
|
|
|
|
|
|
|
// This is not a blocking feature.
|
|
|
|
*aShouldContinue = true;
|
|
|
|
|
2019-04-04 08:31:44 +03:00
|
|
|
static std::vector<UrlClassifierCommon::ClassificationData>
|
|
|
|
sClassificationData = {
|
|
|
|
{NS_LITERAL_CSTRING("ads-track-"),
|
|
|
|
nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_AD},
|
|
|
|
{NS_LITERAL_CSTRING("analytics-track-"),
|
|
|
|
nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_ANALYTICS},
|
|
|
|
{NS_LITERAL_CSTRING("social-track-"),
|
|
|
|
nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_SOCIAL},
|
|
|
|
{NS_LITERAL_CSTRING("content-track-"),
|
|
|
|
nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_CONTENT},
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags(
|
|
|
|
aList, sClassificationData,
|
|
|
|
nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING);
|
2019-03-15 21:38:27 +03:00
|
|
|
|
2019-03-14 20:48:20 +03:00
|
|
|
UrlClassifierCommon::AnnotateChannel(
|
2019-04-04 08:31:44 +03:00
|
|
|
aChannel, AntiTrackingCommon::eTrackingAnnotations, flags,
|
|
|
|
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
|
2018-12-14 14:40:17 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-04 16:45:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
UrlClassifierFeatureTrackingAnnotation::GetURIByListType(
|
|
|
|
nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
|
|
|
|
nsIURI** aURI) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
if (aListType == nsIUrlClassifierFeature::blacklist) {
|
|
|
|
return aChannel->GetURI(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist);
|
|
|
|
return UrlClassifierCommon::CreatePairwiseWhiteListURI(aChannel, aURI);
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|