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 #ifndef mozilla_net_UrlClassifierCommon_h
8 #define mozilla_net_UrlClassifierCommon_h
10 #include "mozilla/Logging.h"
18 #define UC_LOG(args) MOZ_LOG(UrlClassifierCommon::sLog, LogLevel::Info, args)
19 #define UC_LOG_DEBUG(args) \
20 MOZ_LOG(UrlClassifierCommon::sLog, LogLevel::Debug, args)
21 #define UC_LOG_WARN(args) \
22 MOZ_LOG(UrlClassifierCommon::sLog, LogLevel::Warning, args)
23 #define UC_LOG_LEAK(args) \
24 MOZ_LOG(UrlClassifierCommon::sLogLeak, LogLevel::Info, args)
26 #define UC_LOG_ENABLED() \
27 MOZ_LOG_TEST(UrlClassifierCommon::sLog, LogLevel::Info) || \
28 MOZ_LOG_TEST(UrlClassifierCommon::sLogLeak, LogLevel::Info)
33 class UrlClassifierCommon final
{
35 static const nsCString::size_type sMaxSpecLength
;
37 static LazyLogModule sLog
;
38 static LazyLogModule sLogLeak
;
40 static bool AddonMayLoad(nsIChannel
* aChannel
, nsIURI
* aURI
);
42 static bool ShouldEnableProtectionForChannel(nsIChannel
* aChannel
);
44 static nsresult
SetBlockedContent(nsIChannel
* channel
, nsresult aErrorCode
,
45 const nsACString
& aList
,
46 const nsACString
& aProvider
,
47 const nsACString
& aFullHash
);
49 static nsresult
SetTrackingInfo(nsIChannel
* channel
,
50 const nsTArray
<nsCString
>& aLists
,
51 const nsTArray
<nsCString
>& aFullHashes
);
53 // Use this function only when you are looking for a pairwise entitylist uri
54 // with the format: http://toplevel.page/?resource=channel.uri.domain
55 static nsresult
CreatePairwiseEntityListURI(nsIChannel
* aChannel
,
58 static void AnnotateChannel(nsIChannel
* aChannel
,
59 uint32_t aClassificationFlags
,
60 uint32_t aLoadingState
);
62 static bool IsAllowListed(nsIChannel
* aChannel
);
64 static bool IsTrackingClassificationFlag(uint32_t aFlag
, bool aIsPrivate
);
66 static bool IsSocialTrackingClassificationFlag(uint32_t aFlag
);
68 static bool IsCryptominingClassificationFlag(uint32_t aFlag
, bool aIsPrivate
);
70 // Join the table names in 1 single string.
71 static void TablesToString(const nsTArray
<nsCString
>& aList
,
74 struct ClassificationData
{
79 // Checks if the entries in aList are part of the ClassificationData vector
80 // and it returns the corresponding flags. If none of them is found, the
81 // default flag is returned.
82 static uint32_t TablesToClassificationFlags(
83 const nsTArray
<nsCString
>& aList
,
84 const std::vector
<ClassificationData
>& aData
, uint32_t aDefaultFlag
);
86 static bool IsPassiveContent(nsIChannel
* aChannel
);
88 static void SetClassificationFlagsHelper(nsIChannel
* aChannel
,
89 uint32_t aClassificationFlags
,
93 static uint32_t TableToClassificationFlag(
94 const nsACString
& aTable
, const std::vector
<ClassificationData
>& aData
);
96 friend class AsyncUrlChannelClassifier
;
97 static nsresult
GetTopWindowURI(nsIChannel
* aChannel
, nsIURI
** aURI
);
101 } // namespace mozilla
103 #endif // mozilla_net_UrlClassifierCommon_h