nsChannelClassifier.h (1931B)
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/. */ 4 5 #ifndef nsChannelClassifier_h__ 6 #define nsChannelClassifier_h__ 7 8 #include "nsIObserver.h" 9 #include "nsIURIClassifier.h" 10 #include "nsCOMPtr.h" 11 12 #include <functional> 13 14 class nsIChannel; 15 16 namespace mozilla { 17 namespace net { 18 19 class nsChannelClassifier final : public nsIURIClassifierCallback, 20 public nsIObserver { 21 public: 22 explicit nsChannelClassifier(nsIChannel* aChannel); 23 24 NS_DECL_ISUPPORTS 25 NS_DECL_NSIURICLASSIFIERCALLBACK 26 NS_DECL_NSIOBSERVER 27 28 // Calls nsIURIClassifier.Classify with the principal of the given channel, 29 // and cancels the channel on a bad verdict. 30 void Start(); 31 32 private: 33 // True if the channel is on the allow list. 34 bool mIsAllowListed; 35 // True if the channel has been suspended. 36 bool mSuspendedChannel; 37 nsCOMPtr<nsIChannel> mChannel; 38 39 ~nsChannelClassifier(); 40 // Caches good classifications for the channel principal. 41 void MarkEntryClassified(nsresult status); 42 bool HasBeenClassified(nsIChannel* aChannel); 43 // Helper function so that we ensure we call ContinueBeginConnect once 44 // Start is called. Returns NS_OK if and only if we will get a callback 45 // from the classifier service. 46 nsresult StartInternal(); 47 // Helper function to check a URI against the hostname entitylist 48 bool IsHostnameEntitylisted(nsIURI* aUri, const nsACString& aEntitylisted); 49 50 void AddShutdownObserver(); 51 void RemoveShutdownObserver(); 52 static nsresult SendThreatHitReport(nsIChannel* aChannel, 53 const nsACString& aProvider, 54 const nsACString& aList, 55 const nsACString& aFullHash); 56 }; 57 58 } // namespace net 59 } // namespace mozilla 60 61 #endif