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/. */
7 #ifndef DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
8 #define DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
10 #include "mozilla/dom/quota/Config.h"
13 #include "mozilla/Assertions.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Tainting.h"
16 #include "mozilla/ThreadLocal.h"
18 #include "nsXULAppAPI.h"
20 namespace mozilla::dom::quota
{
22 struct MOZ_STACK_CLASS ScopedLogExtraInfo
{
23 static constexpr const char kTagQueryTainted
[] = "query";
24 static constexpr const char kTagContextTainted
[] = "context";
25 // Using the storage origin (instead of normal origin) on purpose to store
26 // the masked origin (uuid based) on the stack for origins partitioned for
28 static constexpr const char kTagStorageOriginTainted
[] = "storage-origin";
30 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
32 static auto FindSlot(const char* aTag
);
36 ScopedLogExtraInfo(const char (&aTag
)[N
], const nsACString
& aExtraInfo
)
37 : mTag
{aTag
}, mPreviousValue(nullptr), mCurrentValue
{aExtraInfo
} {
41 ~ScopedLogExtraInfo();
43 ScopedLogExtraInfo(ScopedLogExtraInfo
&& aOther
) noexcept
;
44 ScopedLogExtraInfo
& operator=(ScopedLogExtraInfo
&& aOther
) = delete;
46 ScopedLogExtraInfo(const ScopedLogExtraInfo
&) = delete;
47 ScopedLogExtraInfo
& operator=(const ScopedLogExtraInfo
&) = delete;
49 using ScopedLogExtraInfoMap
=
50 std::map
<const char*, const Tainted
<nsCString
>*>;
51 static ScopedLogExtraInfoMap
GetExtraInfoMap();
53 static void Initialize();
57 const Tainted
<nsCString
>* mPreviousValue
;
58 Tainted
<nsCString
> mCurrentValue
;
60 static MOZ_THREAD_LOCAL(const Tainted
<nsCString
>*) sQueryValueTainted
;
61 static MOZ_THREAD_LOCAL(const Tainted
<nsCString
>*) sContextValueTainted
;
62 static MOZ_THREAD_LOCAL(const Tainted
<nsCString
>*) sStorageOriginValueTainted
;
67 ScopedLogExtraInfo(const char (&aTag
)[N
], const nsACString
& aExtraInfo
) {}
69 // user-defined to silence unused variable warnings
70 ~ScopedLogExtraInfo() {}
74 } // namespace mozilla::dom::quota
76 #endif // DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_