From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../UrlClassifierFeaturePhishingProtection.cpp | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp (limited to 'netwerk/url-classifier/UrlClassifierFeaturePhishingProtection.cpp') 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 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& 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>& aFeatures) { + MaybeInitialize(); + + for (const PhishingProtectionFeature& feature : + sPhishingProtectionFeaturesMap) { + if (feature.mPref()) { + MOZ_ASSERT(feature.mFeature); + aFeatures.AppendElement(feature.mFeature); + } + } +} + +/* static */ +already_AddRefed +UrlClassifierFeaturePhishingProtection::GetIfNameMatches( + const nsACString& aName) { + MaybeInitialize(); + + for (const PhishingProtectionFeature& feature : + sPhishingProtectionFeaturesMap) { + if (feature.mPref() && aName.Equals(feature.mName)) { + MOZ_ASSERT(feature.mFeature); + nsCOMPtr self = feature.mFeature.get(); + return self.forget(); + } + } + + return nullptr; +} + +NS_IMETHODIMP +UrlClassifierFeaturePhishingProtection::ProcessChannel( + nsIChannel* aChannel, const nsTArray& aList, + const nsTArray& 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 -- cgit v1.2.3