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 "mozilla/net/UrlClassifierFeatureFactory.h"
|
|
|
|
|
|
|
|
// List of Features
|
2019-01-09 14:16:04 +03:00
|
|
|
#include "UrlClassifierFeatureCryptomining.h"
|
2019-01-09 14:16:04 +03:00
|
|
|
#include "UrlClassifierFeatureFingerprinting.h"
|
2019-01-04 16:45:42 +03:00
|
|
|
#include "UrlClassifierFeatureFlash.h"
|
2018-12-15 11:54:02 +03:00
|
|
|
#include "UrlClassifierFeatureLoginReputation.h"
|
2019-01-29 12:11:33 +03:00
|
|
|
#include "UrlClassifierFeatureNoChannel.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
#include "UrlClassifierFeatureTrackingProtection.h"
|
|
|
|
#include "UrlClassifierFeatureTrackingAnnotation.h"
|
2019-01-05 11:10:45 +03:00
|
|
|
#include "UrlClassifierFeatureCustomTables.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
|
|
|
|
#include "nsAppRunner.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
/* static */ void UrlClassifierFeatureFactory::Shutdown() {
|
|
|
|
// We want to expose Features only in the parent process.
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
UrlClassifierFeatureCryptomining::MaybeShutdown();
|
2019-01-09 14:16:04 +03:00
|
|
|
UrlClassifierFeatureFingerprinting::MaybeShutdown();
|
2019-01-05 11:11:06 +03:00
|
|
|
UrlClassifierFeatureFlash::MaybeShutdown();
|
2018-12-15 11:54:02 +03:00
|
|
|
UrlClassifierFeatureLoginReputation::MaybeShutdown();
|
2019-01-29 12:11:33 +03:00
|
|
|
UrlClassifierFeatureNoChannel::MaybeShutdown();
|
2019-01-05 11:11:06 +03:00
|
|
|
UrlClassifierFeatureTrackingAnnotation::MaybeShutdown();
|
|
|
|
UrlClassifierFeatureTrackingProtection::MaybeShutdown();
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void UrlClassifierFeatureFactory::GetFeaturesFromChannel(
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
|
|
|
|
|
|
// Note that the order of the features is extremely important! When more than
|
|
|
|
// 1 feature classifies the channel, we call ::ProcessChannel() following this
|
|
|
|
// feature order, and this could produce different results with a different
|
|
|
|
// feature ordering.
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Cryptomining
|
|
|
|
feature = UrlClassifierFeatureCryptomining::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Fingerprinting
|
|
|
|
feature = UrlClassifierFeatureFingerprinting::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
// Tracking Protection
|
|
|
|
feature = UrlClassifierFeatureTrackingProtection::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Annotation
|
|
|
|
feature = UrlClassifierFeatureTrackingAnnotation::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
2019-01-04 16:45:42 +03:00
|
|
|
|
|
|
|
// Flash
|
|
|
|
nsTArray<nsCOMPtr<nsIUrlClassifierFeature>> flashFeatures;
|
|
|
|
UrlClassifierFeatureFlash::MaybeCreate(aChannel, flashFeatures);
|
|
|
|
aFeatures.AppendElements(flashFeatures);
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 12:11:33 +03:00
|
|
|
/* static */ void UrlClassifierFeatureFactory::GetFeaturesNoChannel(
|
|
|
|
nsTArray<RefPtr<nsIUrlClassifierFeature>>& aFeatures) {
|
|
|
|
UrlClassifierFeatureNoChannel::MaybeCreate(aFeatures);
|
|
|
|
}
|
|
|
|
|
2018-12-15 11:54:02 +03:00
|
|
|
/* static */
|
|
|
|
nsIUrlClassifierFeature*
|
|
|
|
UrlClassifierFeatureFactory::GetFeatureLoginReputation() {
|
|
|
|
return UrlClassifierFeatureLoginReputation::MaybeGetOrCreate();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
/* static */ already_AddRefed<nsIUrlClassifierFeature>
|
|
|
|
UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
|
2019-01-05 11:11:06 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Cryptomining
|
|
|
|
feature = UrlClassifierFeatureCryptomining::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Fingerprinting
|
|
|
|
feature = UrlClassifierFeatureFingerprinting::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
// Tracking Protection
|
|
|
|
feature = UrlClassifierFeatureTrackingProtection::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Annotation
|
|
|
|
feature = UrlClassifierFeatureTrackingAnnotation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login reputation
|
|
|
|
feature = UrlClassifierFeatureLoginReputation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We use Flash feature just for document loading.
|
|
|
|
feature = UrlClassifierFeatureFlash::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:11:33 +03:00
|
|
|
// NoChannel features
|
|
|
|
feature = UrlClassifierFeatureNoChannel::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-09 01:05:40 +03:00
|
|
|
/* static */ void UrlClassifierFeatureFactory::GetFeatureNames(
|
|
|
|
nsTArray<nsCString>& aArray) {
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Cryptomining
|
2019-01-09 13:15:44 +03:00
|
|
|
nsAutoCString name;
|
2019-01-09 14:16:04 +03:00
|
|
|
name.Assign(UrlClassifierFeatureCryptomining::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fingerprinting
|
2019-01-09 14:16:04 +03:00
|
|
|
name.Assign(UrlClassifierFeatureFingerprinting::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Protection
|
2019-01-09 01:05:40 +03:00
|
|
|
name.Assign(UrlClassifierFeatureTrackingProtection::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Annotation
|
|
|
|
name.Assign(UrlClassifierFeatureTrackingAnnotation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login reputation
|
|
|
|
name.Assign(UrlClassifierFeatureLoginReputation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flash features
|
2019-01-29 12:11:33 +03:00
|
|
|
{
|
|
|
|
nsTArray<nsCString> features;
|
|
|
|
UrlClassifierFeatureFlash::GetFeatureNames(features);
|
|
|
|
aArray.AppendElements(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NoChannel features
|
|
|
|
{
|
|
|
|
nsTArray<nsCString> features;
|
|
|
|
UrlClassifierFeatureNoChannel::GetFeatureNames(features);
|
|
|
|
aArray.AppendElements(features);
|
|
|
|
}
|
2019-01-09 01:05:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
/* static */ already_AddRefed<nsIUrlClassifierFeature>
|
|
|
|
UrlClassifierFeatureFactory::CreateFeatureWithTables(
|
|
|
|
const nsACString& aName, const nsTArray<nsCString>& aBlacklistTables,
|
|
|
|
const nsTArray<nsCString>& aWhitelistTables) {
|
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature =
|
|
|
|
new UrlClassifierFeatureCustomTables(aName, aBlacklistTables,
|
|
|
|
aWhitelistTables);
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|