Bug 1522265 - Moving malware, phishing and blocked URIs to features - part 1 - feature no channel, r=dimi

This commit is contained in:
Andrea Marchesini 2019-01-29 10:11:33 +01:00
parent c10c92ae4e
commit f43141ec0a
6 changed files with 190 additions and 7 deletions

View File

@ -1941,6 +1941,27 @@ VARCACHE_PREF(
bool, false
)
// Malware protection
VARCACHE_PREF(
"browser.safebrowsing.malware.enabled",
browser_safebrowsing_malware_enabled,
bool, true
)
// Phishing protection
VARCACHE_PREF(
"browser.safebrowsing.phishing.enabled",
browser_safebrowsing_phishing_enabled,
bool, true
)
// Blocked plugin content
VARCACHE_PREF(
"browser.safebrowsing.blockedURIs.enabled",
browser_safebrowsing_blockedURIs_enabled,
bool, true
)
//---------------------------------------------------------------------------
// ChannelClassifier prefs
//---------------------------------------------------------------------------

View File

@ -5587,9 +5587,7 @@ pref("urlclassifier.update.timeout_ms", 90000);
// Name of the about: page to display Safe Browsing warnings (bug 399233)
pref("urlclassifier.alternate_error_page", "blocked");
// Enable phishing & malware protection.
pref("browser.safebrowsing.phishing.enabled", true);
pref("browser.safebrowsing.malware.enabled", true);
// Enable safe-browsing debugging
pref("browser.safebrowsing.debug", false);
// Allow users to ignore Safe Browsing warnings.
@ -5652,7 +5650,6 @@ pref("browser.safebrowsing.provider.mozilla.lists.base", "moz-std");
pref("browser.safebrowsing.provider.mozilla.lists.content", "moz-full");
// The table and global pref for blocking plugin content
pref("browser.safebrowsing.blockedURIs.enabled", true);
pref("urlclassifier.blockedTable", "test-block-simple,mozplugin-block-digest256");
// Flash blocking tables

View File

@ -11,6 +11,7 @@
#include "UrlClassifierFeatureFingerprinting.h"
#include "UrlClassifierFeatureFlash.h"
#include "UrlClassifierFeatureLoginReputation.h"
#include "UrlClassifierFeatureNoChannel.h"
#include "UrlClassifierFeatureTrackingProtection.h"
#include "UrlClassifierFeatureTrackingAnnotation.h"
#include "UrlClassifierFeatureCustomTables.h"
@ -30,6 +31,7 @@ namespace net {
UrlClassifierFeatureFingerprinting::MaybeShutdown();
UrlClassifierFeatureFlash::MaybeShutdown();
UrlClassifierFeatureLoginReputation::MaybeShutdown();
UrlClassifierFeatureNoChannel::MaybeShutdown();
UrlClassifierFeatureTrackingAnnotation::MaybeShutdown();
UrlClassifierFeatureTrackingProtection::MaybeShutdown();
}
@ -127,6 +129,12 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
return feature.forget();
}
// NoChannel features
feature = UrlClassifierFeatureNoChannel::GetIfNameMatches(aName);
if (feature) {
return feature.forget();
}
return nullptr;
}
@ -168,9 +176,18 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
}
// Flash features
nsTArray<nsCString> features;
UrlClassifierFeatureFlash::GetFeatureNames(features);
aArray.AppendElements(features);
{
nsTArray<nsCString> features;
UrlClassifierFeatureFlash::GetFeatureNames(features);
aArray.AppendElements(features);
}
// NoChannel features
{
nsTArray<nsCString> features;
UrlClassifierFeatureNoChannel::GetFeatureNames(features);
aArray.AppendElements(features);
}
}
/* static */ already_AddRefed<nsIUrlClassifierFeature>

View File

@ -0,0 +1,104 @@
/* -*- 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 "UrlClassifierFeatureNoChannel.h"
namespace mozilla {
namespace net {
struct UrlClassifierFeatureNoChannel::NoChannelFeature {
const char* mName;
const char* mBlacklistPrefTables;
bool (*mPref)();
RefPtr<UrlClassifierFeatureNoChannel> mFeature;
};
namespace {
struct UrlClassifierFeatureNoChannel::NoChannelFeature sNoChannelFeaturesMap[] =
{
{"malware", "urlclassifier.malwareTable",
StaticPrefs::browser_safebrowsing_malware_enabled},
{"phishing", "urlclassifier.phishTable",
StaticPrefs::browser_safebrowsing_phishing_enabled},
{"blockedURIs", "urlclassifier.blockedTable",
StaticPrefs::browser_safebrowsing_blockedURIs_enabled},
};
} // namespace
UrlClassifierFeatureNoChannel::UrlClassifierFeatureNoChannel(
const UrlClassifierFeatureNoChannel::NoChannelFeature& aFeature)
: UrlClassifierFeatureBase(
nsDependentCString(aFeature.mName),
nsDependentCString(aFeature.mBlacklistPrefTables),
EmptyCString(), // aPrefWhitelistPrefTbles,
EmptyCString(), // aPrefBlacklistHosts
EmptyCString(), // aPrefWhitelistHosts
EmptyCString(), // aPrefBlacklistTableName
EmptyCString(), // aPrefWhitelistTableName
EmptyCString()) { // aPrefSkipHosts
}
/* static */ void UrlClassifierFeatureNoChannel::GetFeatureNames(
nsTArray<nsCString>& aArray) {
for (const NoChannelFeature& feature : sNoChannelFeaturesMap) {
if (feature.mPref()) {
aArray.AppendElement(nsDependentCString(feature.mName));
}
}
}
/* static */ void UrlClassifierFeatureNoChannel::MaybeInitialize() {
for (NoChannelFeature& feature : sNoChannelFeaturesMap) {
if (!feature.mFeature && feature.mPref()) {
feature.mFeature = new UrlClassifierFeatureNoChannel(feature);
feature.mFeature->InitializePreferences();
}
}
}
/* static */ void UrlClassifierFeatureNoChannel::MaybeShutdown() {
for (NoChannelFeature& feature : sNoChannelFeaturesMap) {
if (feature.mFeature) {
feature.mFeature->ShutdownPreferences();
feature.mFeature = nullptr;
}
}
}
/* static */ already_AddRefed<nsIUrlClassifierFeature>
UrlClassifierFeatureNoChannel::GetIfNameMatches(const nsACString& aName) {
MaybeInitialize();
for (const NoChannelFeature& feature : sNoChannelFeaturesMap) {
if (feature.mPref() && aName.Equals(feature.mName)) {
MOZ_ASSERT(feature.mFeature);
nsCOMPtr<nsIUrlClassifierFeature> self = feature.mFeature.get();
return self.forget();
}
}
return nullptr;
}
NS_IMETHODIMP
UrlClassifierFeatureNoChannel::ProcessChannel(nsIChannel* aChannel,
const nsACString& aList,
bool* aShouldContinue) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
UrlClassifierFeatureNoChannel::GetURIByListType(
nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
nsIURI** aURI) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace net
} // namespace mozilla

View File

@ -0,0 +1,43 @@
/* -*- 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_UrlClassifierFeatureNoChannel_h
#define mozilla_UrlClassifierFeatureNoChannel_h
#include "UrlClassifierFeatureBase.h"
namespace mozilla {
namespace net {
class UrlClassifierFeatureNoChannel final : public UrlClassifierFeatureBase {
public:
struct NoChannelFeature;
static void GetFeatureNames(nsTArray<nsCString>& aNames);
static void MaybeShutdown();
static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
const nsACString& aName);
NS_IMETHOD
ProcessChannel(nsIChannel* aChannel, const nsACString& aList,
bool* aShouldContinue) override;
NS_IMETHOD GetURIByListType(nsIChannel* aChannel,
nsIUrlClassifierFeature::listType aListType,
nsIURI** aURI) override;
private:
explicit UrlClassifierFeatureNoChannel(const NoChannelFeature& aFeature);
static void MaybeInitialize();
};
} // namespace net
} // namespace mozilla
#endif // mozilla_UrlClassifierFeatureNoChannel_h

View File

@ -28,6 +28,7 @@ UNIFIED_SOURCES += [
'UrlClassifierFeatureFingerprinting.cpp',
'UrlClassifierFeatureFlash.cpp',
'UrlClassifierFeatureLoginReputation.cpp',
'UrlClassifierFeatureNoChannel.cpp',
'UrlClassifierFeatureResult.cpp',
'UrlClassifierFeatureTrackingAnnotation.cpp',
'UrlClassifierFeatureTrackingProtection.cpp',