Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / netwerk / url-classifier / UrlClassifierFeaturePhishingProtection.cpp
blobd03f9c790bc634d1da32ae8748c77478af60c075
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "UrlClassifierFeaturePhishingProtection.h"
8 #include "mozilla/StaticPrefs_browser.h"
9 #include "nsCOMPtr.h"
11 namespace mozilla {
12 namespace net {
14 struct UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature {
15 const char* mName;
16 const char* mBlocklistPrefTables;
17 bool (*mPref)();
19 RefPtr<UrlClassifierFeaturePhishingProtection> mFeature;
22 namespace {
24 struct UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature
25 sPhishingProtectionFeaturesMap[] = {
26 {"malware", "urlclassifier.malwareTable",
27 StaticPrefs::browser_safebrowsing_malware_enabled},
28 {"phishing", "urlclassifier.phishTable",
29 StaticPrefs::browser_safebrowsing_phishing_enabled},
30 {"blockedURIs", "urlclassifier.blockedTable",
31 StaticPrefs::browser_safebrowsing_blockedURIs_enabled},
34 } // namespace
36 UrlClassifierFeaturePhishingProtection::UrlClassifierFeaturePhishingProtection(
37 const UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature&
38 aFeature)
39 : UrlClassifierFeatureBase(
40 nsDependentCString(aFeature.mName),
41 nsDependentCString(aFeature.mBlocklistPrefTables),
42 ""_ns, // aPrefEntitylistPrefTbles,
43 ""_ns, // aPrefBlocklistHosts
44 ""_ns, // aPrefEntitylistHosts
45 ""_ns, // aPrefBlocklistTableName
46 ""_ns, // aPrefEntitylistTableName
47 ""_ns) { // aPrefExceptionHosts
50 /* static */
51 void UrlClassifierFeaturePhishingProtection::GetFeatureNames(
52 nsTArray<nsCString>& aArray) {
53 for (const PhishingProtectionFeature& feature :
54 sPhishingProtectionFeaturesMap) {
55 if (feature.mPref()) {
56 aArray.AppendElement(nsDependentCString(feature.mName));
61 /* static */
62 void UrlClassifierFeaturePhishingProtection::MaybeInitialize() {
63 for (PhishingProtectionFeature& feature : sPhishingProtectionFeaturesMap) {
64 if (!feature.mFeature && feature.mPref()) {
65 feature.mFeature = new UrlClassifierFeaturePhishingProtection(feature);
66 feature.mFeature->InitializePreferences();
71 /* static */
72 void UrlClassifierFeaturePhishingProtection::MaybeShutdown() {
73 for (PhishingProtectionFeature& feature : sPhishingProtectionFeaturesMap) {
74 if (feature.mFeature) {
75 feature.mFeature->ShutdownPreferences();
76 feature.mFeature = nullptr;
81 /* static */
82 void UrlClassifierFeaturePhishingProtection::MaybeCreate(
83 nsTArray<RefPtr<nsIUrlClassifierFeature>>& aFeatures) {
84 MaybeInitialize();
86 for (const PhishingProtectionFeature& feature :
87 sPhishingProtectionFeaturesMap) {
88 if (feature.mPref()) {
89 MOZ_ASSERT(feature.mFeature);
90 aFeatures.AppendElement(feature.mFeature);
95 /* static */
96 already_AddRefed<nsIUrlClassifierFeature>
97 UrlClassifierFeaturePhishingProtection::GetIfNameMatches(
98 const nsACString& aName) {
99 MaybeInitialize();
101 for (const PhishingProtectionFeature& feature :
102 sPhishingProtectionFeaturesMap) {
103 if (feature.mPref() && aName.Equals(feature.mName)) {
104 MOZ_ASSERT(feature.mFeature);
105 nsCOMPtr<nsIUrlClassifierFeature> self = feature.mFeature.get();
106 return self.forget();
110 return nullptr;
113 NS_IMETHODIMP
114 UrlClassifierFeaturePhishingProtection::ProcessChannel(
115 nsIChannel* aChannel, const nsTArray<nsCString>& aList,
116 const nsTArray<nsCString>& aHashes, bool* aShouldContinue) {
117 return NS_ERROR_NOT_IMPLEMENTED;
120 NS_IMETHODIMP
121 UrlClassifierFeaturePhishingProtection::GetURIByListType(
122 nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
123 nsIUrlClassifierFeature::URIType* aURIType, nsIURI** aURI) {
124 return NS_ERROR_NOT_IMPLEMENTED;
127 } // namespace net
128 } // namespace mozilla