tor-browser

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

ScopedLogExtraInfo.h (2443B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
      8 #define DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
      9 
     10 #include <map>
     11 
     12 #include "mozilla/Attributes.h"
     13 #include "mozilla/Tainting.h"
     14 #include "mozilla/ThreadLocal.h"
     15 #include "mozilla/dom/quota/Config.h"
     16 #include "nsString.h"
     17 #include "nsXULAppAPI.h"
     18 
     19 namespace mozilla::dom::quota {
     20 
     21 struct MOZ_STACK_CLASS ScopedLogExtraInfo {
     22  static constexpr const char kTagQueryTainted[] = "query";
     23  static constexpr const char kTagContextTainted[] = "context";
     24  // Using the storage origin (instead of normal origin) on purpose to store
     25  // the masked origin (uuid based) on the stack for origins partitioned for
     26  // private browsing.
     27  static constexpr const char kTagStorageOriginTainted[] = "storage-origin";
     28 
     29 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
     30 private:
     31  static auto FindSlot(const char* aTag);
     32 
     33 public:
     34  template <size_t N>
     35  ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo)
     36      : mTag{aTag}, mPreviousValue(nullptr), mCurrentValue{aExtraInfo} {
     37    AddInfo();
     38  }
     39 
     40  ~ScopedLogExtraInfo();
     41 
     42  ScopedLogExtraInfo(ScopedLogExtraInfo&& aOther) noexcept;
     43  ScopedLogExtraInfo& operator=(ScopedLogExtraInfo&& aOther) = delete;
     44 
     45  ScopedLogExtraInfo(const ScopedLogExtraInfo&) = delete;
     46  ScopedLogExtraInfo& operator=(const ScopedLogExtraInfo&) = delete;
     47 
     48  using ScopedLogExtraInfoMap =
     49      std::map<const char*, const Tainted<nsCString>*>;
     50  static ScopedLogExtraInfoMap GetExtraInfoMap();
     51 
     52  static void Initialize();
     53 
     54 private:
     55  const char* mTag;
     56  const Tainted<nsCString>* mPreviousValue;
     57  Tainted<nsCString> mCurrentValue;
     58 
     59  static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sQueryValueTainted;
     60  static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sContextValueTainted;
     61  static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sStorageOriginValueTainted;
     62 
     63  void AddInfo();
     64 #else
     65  template <size_t N>
     66  ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo) {}
     67 
     68  // user-defined to silence unused variable warnings
     69  ~ScopedLogExtraInfo() {}
     70 #endif
     71 };
     72 
     73 }  // namespace mozilla::dom::quota
     74 
     75 #endif  // DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_