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"
14 struct UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature
{
16 const char* mBlocklistPrefTables
;
19 RefPtr
<UrlClassifierFeaturePhishingProtection
> mFeature
;
24 MOZ_RUNINIT
struct UrlClassifierFeaturePhishingProtection::
25 PhishingProtectionFeature 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
},
36 UrlClassifierFeaturePhishingProtection::UrlClassifierFeaturePhishingProtection(
37 const UrlClassifierFeaturePhishingProtection::PhishingProtectionFeature
&
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
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
));
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();
72 void UrlClassifierFeaturePhishingProtection::MaybeShutdown() {
73 for (PhishingProtectionFeature
& feature
: sPhishingProtectionFeaturesMap
) {
74 if (feature
.mFeature
) {
75 feature
.mFeature
->ShutdownPreferences();
76 feature
.mFeature
= nullptr;
82 void UrlClassifierFeaturePhishingProtection::MaybeCreate(
83 nsTArray
<RefPtr
<nsIUrlClassifierFeature
>>& aFeatures
) {
86 for (const PhishingProtectionFeature
& feature
:
87 sPhishingProtectionFeaturesMap
) {
88 if (feature
.mPref()) {
89 MOZ_ASSERT(feature
.mFeature
);
90 aFeatures
.AppendElement(feature
.mFeature
);
96 already_AddRefed
<nsIUrlClassifierFeature
>
97 UrlClassifierFeaturePhishingProtection::GetIfNameMatches(
98 const nsACString
& aName
) {
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();
114 UrlClassifierFeaturePhishingProtection::ProcessChannel(
115 nsIChannel
* aChannel
, const nsTArray
<nsCString
>& aList
,
116 const nsTArray
<nsCString
>& aHashes
, bool* aShouldContinue
) {
117 return NS_ERROR_NOT_IMPLEMENTED
;
121 UrlClassifierFeaturePhishingProtection::GetURIByListType(
122 nsIChannel
* aChannel
, nsIUrlClassifierFeature::listType aListType
,
123 nsIUrlClassifierFeature::URIType
* aURIType
, nsIURI
** aURI
) {
124 return NS_ERROR_NOT_IMPLEMENTED
;
128 } // namespace mozilla