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"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_privacy.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/net/UrlClassifierCommon.h"
|
2019-10-19 07:30:24 +03:00
|
|
|
#include "nsIClassifiedChannel.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,
|
2019-04-26 16:02:35 +03:00
|
|
|
const nsTArray<nsCString>& aHashes, 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-"),
|
2019-10-19 07:30:24 +03:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING_AD},
|
2019-04-04 08:31:44 +03:00
|
|
|
{NS_LITERAL_CSTRING("analytics-track-"),
|
2019-10-19 07:30:24 +03:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::
|
|
|
|
CLASSIFIED_TRACKING_ANALYTICS},
|
2019-04-04 08:31:44 +03:00
|
|
|
{NS_LITERAL_CSTRING("social-track-"),
|
2019-10-19 07:30:24 +03:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::
|
|
|
|
CLASSIFIED_TRACKING_SOCIAL},
|
2019-04-04 08:31:44 +03:00
|
|
|
{NS_LITERAL_CSTRING("content-track-"),
|
2019-10-19 07:30:24 +03:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::
|
|
|
|
CLASSIFIED_TRACKING_CONTENT},
|
2019-04-04 08:31:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags(
|
|
|
|
aList, sClassificationData,
|
2019-10-19 07:30:24 +03:00
|
|
|
nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING);
|
2019-03-15 21:38:27 +03:00
|
|
|
|
2019-04-26 16:04:41 +03:00
|
|
|
UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes);
|
|
|
|
|
2019-03-14 20:48:20 +03:00
|
|
|
UrlClassifierCommon::AnnotateChannel(
|
2019-08-07 18:54:54 +03:00
|
|
|
aChannel, 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,
|
2019-09-27 16:22:18 +03:00
|
|
|
nsIUrlClassifierFeature::URIType* aURIType, nsIURI** aURI) {
|
2019-01-04 16:45:42 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
2019-09-27 16:22:18 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aURIType);
|
2019-01-04 16:45:42 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
if (aListType == nsIUrlClassifierFeature::blacklist) {
|
2019-09-27 16:22:18 +03:00
|
|
|
*aURIType = nsIUrlClassifierFeature::blacklistURI;
|
2019-01-04 16:45:42 +03:00
|
|
|
return aChannel->GetURI(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist);
|
2019-09-27 16:22:18 +03:00
|
|
|
|
|
|
|
*aURIType = nsIUrlClassifierFeature::pairwiseWhitelistURI;
|
2019-01-04 16:45:42 +03:00
|
|
|
return UrlClassifierCommon::CreatePairwiseWhiteListURI(aChannel, aURI);
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|