Bug 1929040 - [wpt-sync] Update web-platform-tests to d4fb35c4980b6581ce0535b2dac71cb...
[gecko.git] / netwerk / url-classifier / nsChannelClassifier.h
blobddd89e2976d463434440360b4d5c8c1d5062367b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsChannelClassifier_h__
6 #define nsChannelClassifier_h__
8 #include "nsIObserver.h"
9 #include "nsIURIClassifier.h"
10 #include "nsCOMPtr.h"
11 #include "mozilla/Attributes.h"
13 #include <functional>
15 class nsIChannel;
17 namespace mozilla {
18 namespace net {
20 class nsChannelClassifier final : public nsIURIClassifierCallback,
21 public nsIObserver {
22 public:
23 explicit nsChannelClassifier(nsIChannel* aChannel);
25 NS_DECL_ISUPPORTS
26 NS_DECL_NSIURICLASSIFIERCALLBACK
27 NS_DECL_NSIOBSERVER
29 // Calls nsIURIClassifier.Classify with the principal of the given channel,
30 // and cancels the channel on a bad verdict.
31 void Start();
33 private:
34 // True if the channel is on the allow list.
35 bool mIsAllowListed;
36 // True if the channel has been suspended.
37 bool mSuspendedChannel;
38 nsCOMPtr<nsIChannel> mChannel;
40 ~nsChannelClassifier();
41 // Caches good classifications for the channel principal.
42 void MarkEntryClassified(nsresult status);
43 bool HasBeenClassified(nsIChannel* aChannel);
44 // Helper function so that we ensure we call ContinueBeginConnect once
45 // Start is called. Returns NS_OK if and only if we will get a callback
46 // from the classifier service.
47 nsresult StartInternal();
48 // Helper function to check a URI against the hostname entitylist
49 bool IsHostnameEntitylisted(nsIURI* aUri, const nsACString& aEntitylisted);
51 void AddShutdownObserver();
52 void RemoveShutdownObserver();
53 static nsresult SendThreatHitReport(nsIChannel* aChannel,
54 const nsACString& aProvider,
55 const nsACString& aList,
56 const nsACString& aFullHash);
58 public:
59 // If we are blocking content, update the corresponding flag in the respective
60 // docshell and call nsDocLoader::OnSecurityChange.
61 static nsresult SetBlockedContent(nsIChannel* channel, nsresult aErrorCode,
62 const nsACString& aList,
63 const nsACString& aProvider,
64 const nsACString& aFullHash);
67 } // namespace net
68 } // namespace mozilla
70 #endif