tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

UrlClassifierCommon.h (3958B)


      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/. */
      6 
      7 #ifndef mozilla_net_UrlClassifierCommon_h
      8 #define mozilla_net_UrlClassifierCommon_h
      9 
     10 #include "mozilla/Logging.h"
     11 #include "nsString.h"
     12 
     13 #include <vector>
     14 
     15 class nsIChannel;
     16 class nsIURI;
     17 
     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)
     25 
     26 #define UC_LOG_ENABLED()                                     \
     27  MOZ_LOG_TEST(UrlClassifierCommon::sLog, LogLevel::Info) || \
     28      MOZ_LOG_TEST(UrlClassifierCommon::sLogLeak, LogLevel::Info)
     29 
     30 namespace mozilla {
     31 namespace net {
     32 
     33 class UrlClassifierCommon final {
     34 public:
     35  static const nsCString::size_type sMaxSpecLength;
     36 
     37  static LazyLogModule sLog;
     38  static LazyLogModule sLogLeak;
     39 
     40  static bool AddonMayLoad(nsIChannel* aChannel, nsIURI* aURI);
     41 
     42  static bool ShouldEnableProtectionForChannel(nsIChannel* aChannel);
     43 
     44  static nsresult SetBlockedContent(nsIChannel* channel, nsresult aErrorCode,
     45                                    const nsACString& aList,
     46                                    const nsACString& aProvider,
     47                                    const nsACString& aFullHash);
     48 
     49  static nsresult SetTrackingInfo(nsIChannel* channel,
     50                                  const nsTArray<nsCString>& aLists,
     51                                  const nsTArray<nsCString>& aFullHashes);
     52 
     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,
     56                                              nsIURI** aURI);
     57 
     58  static void AnnotateChannel(nsIChannel* aChannel,
     59                              uint32_t aClassificationFlags,
     60                              uint32_t aLoadingState);
     61 
     62  static void AnnotateChannelWithoutNotifying(nsIChannel* aChannel,
     63                                              uint32_t aClassificationFlags);
     64 
     65  static bool IsAllowListed(nsIChannel* aChannel);
     66 
     67  static bool IsTrackingClassificationFlag(uint32_t aFlag, bool aIsPrivate);
     68 
     69  static bool IsSocialTrackingClassificationFlag(uint32_t aFlag);
     70 
     71  static bool IsCryptominingClassificationFlag(uint32_t aFlag, bool aIsPrivate);
     72 
     73  // Join the table names in 1 single string.
     74  static void TablesToString(const nsTArray<nsCString>& aList,
     75                             nsACString& aString);
     76 
     77  struct ClassificationData {
     78    nsCString mPrefix;
     79    uint32_t mFlag;
     80  };
     81 
     82  // Checks if the entries in aList are part of the ClassificationData vector
     83  // and it returns the corresponding flags. If none of them is found, the
     84  // default flag is returned.
     85  static uint32_t TablesToClassificationFlags(
     86      const nsTArray<nsCString>& aList,
     87      const std::vector<ClassificationData>& aData, uint32_t aDefaultFlag);
     88 
     89  static bool IsPassiveContent(nsIChannel* aChannel);
     90 
     91  static void SetClassificationFlagsHelper(nsIChannel* aChannel,
     92                                           uint32_t aClassificationFlags,
     93                                           bool aIsThirdParty);
     94  static nsresult GetTopWindowURI(nsIChannel* aChannel, nsIURI** aURI);
     95 
     96  static bool ShouldProcessWithProtectionFeature(nsIChannel* aChannel);
     97 
     98 private:
     99  static uint32_t TableToClassificationFlag(
    100      const nsACString& aTable, const std::vector<ClassificationData>& aData);
    101 };
    102 
    103 }  // namespace net
    104 }  // namespace mozilla
    105 
    106 #endif  // mozilla_net_UrlClassifierCommon_h