1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_SubsumedPrincipalJSONHandler_h
7 #define mozilla_SubsumedPrincipalJSONHandler_h
9 #include <stddef.h> // size_t
10 #include <stdint.h> // uint32_t
12 #include "js/TypeDecls.h" // JS::Latin1Char
14 #include "mozilla/AlreadyAddRefed.h" // already_AddRefed
15 #include "mozilla/Variant.h" // Variant
16 #include "mozilla/RefPtr.h" // RefPtr
18 #include "nsDebug.h" // NS_WARNING
20 #include "BasePrincipal.h"
21 #include "ContentPrincipalJSONHandler.h"
22 #include "NullPrincipalJSONHandler.h"
23 #include "SharedJSONHandler.h"
27 class SubsumedPrincipalJSONHandlerTypes
{
32 // After the subsumed principal object's '{'.
35 // After the PrincipalKind property key for SystemPrincipal.
37 // After the SystemPrincipal's inner object's '{'.
38 SystemPrincipal_StartObject
,
39 // After the SystemPrincipal's inner object's '}'.
40 SystemPrincipal_EndObject
,
42 // After the PrincipalKind property key for NullPrincipal or
43 // ContentPrincipal, and also the entire inner object.
44 // Delegates to mInnerHandler until the inner object's '}'.
46 // Unlike PrincipalJSONHandler, subsumed principal doesn't contain
49 ContentPrincipal_Inner
,
51 // After the subsumed principal object's '}'.
58 Maybe
<Variant
<NullPrincipalJSONHandler
, ContentPrincipalJSONHandler
>>;
60 static constexpr bool CanContainExpandedPrincipal
= false;
63 // JSON parse handler for subsumed principal object inside ExpandedPrincipal's
66 // Subsumed principal object
68 // ----------------------------------
70 // {"2": {"0": [{"1": {"0": https://mozilla.com"}}]}}
72 // | ---------------------------
77 // For inner object except for the system principal case, this delegates
78 // to NullPrincipalJSONHandler or ContentPrincipalJSONHandler.
79 class SubsumedPrincipalJSONHandler
80 : public ContainerPrincipalJSONHandler
<SubsumedPrincipalJSONHandlerTypes
> {
81 using State
= SubsumedPrincipalJSONHandlerTypes::State
;
82 using InnerHandlerT
= SubsumedPrincipalJSONHandlerTypes::InnerHandlerT
;
85 SubsumedPrincipalJSONHandler() = default;
86 virtual ~SubsumedPrincipalJSONHandler() = default;
88 bool HasAccepted() const { return mState
== State::EndObject
; }
91 virtual void SetErrorState() override
{ mState
= State::Error
; }
94 } // namespace mozilla
96 #endif // mozilla_SubsumedPrincipalJSONHandler_h