1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set expandtab ts=2 sw=2 sts=2 cin: */
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 #ifndef mozilla_net_ChannelClassifierService_h
8 #define mozilla_net_ChannelClassifierService_h
10 #include "nsIChannelClassifierService.h"
11 #include "mozilla/net/UrlClassifierCommon.h"
16 enum class ChannelBlockDecision
{
22 class UrlClassifierBlockedChannel final
23 : public nsIUrlClassifierBlockedChannel
{
26 NS_DECL_NSIURLCLASSIFIERBLOCKEDCHANNEL
28 explicit UrlClassifierBlockedChannel(nsIChannel
* aChannel
);
30 bool IsUnblocked() const {
31 return mDecision
!= ChannelBlockDecision::Blocked
;
34 ChannelBlockDecision
GetDecision() { return mDecision
; };
36 void SetReason(const nsACString
& aFeatureName
, const nsACString
& aTableName
);
39 ~UrlClassifierBlockedChannel() = default;
42 nsCOMPtr
<nsIChannel
> mChannel
;
43 ChannelBlockDecision mDecision
;
48 class ChannelClassifierService final
: public nsIChannelClassifierService
{
51 NS_DECL_NSICHANNELCLASSIFIERSERVICE
53 friend class UrlClassifierBlockedChannel
;
55 static already_AddRefed
<nsIChannelClassifierService
> GetSingleton();
57 static ChannelBlockDecision
OnBeforeBlockChannel(
58 nsIChannel
* aChannel
, const nsACString
& aFeatureName
,
59 const nsACString
& aTableName
);
61 nsresult
OnBeforeBlockChannel(nsIChannel
* aChannel
,
62 const nsACString
& aFeatureName
,
63 const nsACString
& aTableName
,
64 ChannelBlockDecision
& aDecision
);
66 bool HasListener() const { return !mListeners
.IsEmpty(); }
69 ChannelClassifierService();
70 ~ChannelClassifierService() = default;
72 nsTArray
<nsCOMPtr
<nsIObserver
>> mListeners
;
76 } // namespace mozilla
78 #endif // mozilla_net_ChannelClassifierService_h