diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.tar.xz firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp')
-rw-r--r-- | netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp new file mode 100644 index 0000000000..d03f9c790b --- /dev/null +++ b/netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp @@ -0,0 +1,128 @@ +/* -*- 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 "UrlClassifierFeaturePhishingProtection.h" +#include "mozilla/StaticPrefs_browser.h" +#include "nsCOMPtr.h" + +namespace mozilla { +namespace net { + +struct UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature { + const char* mName; + const char* mBlocklistPrefTables; + bool (*mPref)(); + + RefPtr<UrlClassifierFeaturePhishingProtection> mFeature; +}; + +namespace { + +struct UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature + sPhishingProtectionFeaturesMap[] = { + {"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 + +UrlClassifierFeaturePhishingProtection::UrlClassifierFeaturePhishingProtection( + const UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature& + aFeature) + : UrlClassifierFeatureBase( + nsDependentCString(aFeature.mName), + nsDependentCString(aFeature.mBlocklistPrefTables), + ""_ns, // aPrefEntitylistPrefTbles, + ""_ns, // aPrefBlocklistHosts + ""_ns, // aPrefEntitylistHosts + ""_ns, // aPrefBlocklistTableName + ""_ns, // aPrefEntitylistTableName + ""_ns) { // aPrefExceptionHosts +} + +/* static */ +void UrlClassifierFeaturePhishingProtection::GetFeatureNames( + nsTArray<nsCString>& aArray) { + for (const PhishingProtectionFeature& feature : + sPhishingProtectionFeaturesMap) { + if (feature.mPref()) { + aArray.AppendElement(nsDependentCString(feature.mName)); + } + } +} + +/* static */ +void UrlClassifierFeaturePhishingProtection::MaybeInitialize() { + for (PhishingProtectionFeature& feature : sPhishingProtectionFeaturesMap) { + if (!feature.mFeature && feature.mPref()) { + feature.mFeature = new UrlClassifierFeaturePhishingProtection(feature); + feature.mFeature->InitializePreferences(); + } + } +} + +/* static */ +void UrlClassifierFeaturePhishingProtection::MaybeShutdown() { + for (PhishingProtectionFeature& feature : sPhishingProtectionFeaturesMap) { + if (feature.mFeature) { + feature.mFeature->ShutdownPreferences(); + feature.mFeature = nullptr; + } + } +} + +/* static */ +void UrlClassifierFeaturePhishingProtection::MaybeCreate( + nsTArray<RefPtr<nsIUrlClassifierFeature>>& aFeatures) { + MaybeInitialize(); + + for (const PhishingProtectionFeature& feature : + sPhishingProtectionFeaturesMap) { + if (feature.mPref()) { + MOZ_ASSERT(feature.mFeature); + aFeatures.AppendElement(feature.mFeature); + } + } +} + +/* static */ +already_AddRefed<nsIUrlClassifierFeature> +UrlClassifierFeaturePhishingProtection::GetIfNameMatches( + const nsACString& aName) { + MaybeInitialize(); + + for (const PhishingProtectionFeature& feature : + sPhishingProtectionFeaturesMap) { + if (feature.mPref() && aName.Equals(feature.mName)) { + MOZ_ASSERT(feature.mFeature); + nsCOMPtr<nsIUrlClassifierFeature> self = feature.mFeature.get(); + return self.forget(); + } + } + + return nullptr; +} + +NS_IMETHODIMP +UrlClassifierFeaturePhishingProtection::ProcessChannel( + nsIChannel* aChannel, const nsTArray<nsCString>& aList, + const nsTArray<nsCString>& aHashes, bool* aShouldContinue) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +UrlClassifierFeaturePhishingProtection::GetURIByListType( + nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType, + nsIUrlClassifierFeature::URIType* aURIType, nsIURI** aURI) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +} // namespace net +} // namespace mozilla |