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_ExpandedPrincipalJSONHandler_h
7 #define mozilla_ExpandedPrincipalJSONHandler_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/Maybe.h" // Maybe
16 #include "mozilla/RefPtr.h" // RefPtr
18 #include "nsCOMPtr.h" // nsCOMPtr
19 #include "nsDebug.h" // NS_WARNING
20 #include "nsIPrincipal.h" // nsIPrincipal
21 #include "nsTArray.h" // nsTArray
23 #include "OriginAttributes.h"
24 #include "ExpandedPrincipal.h"
25 #include "SubsumedPrincipalJSONHandler.h"
26 #include "SharedJSONHandler.h"
30 // JSON parse handler for an inner object for ExpandedPrincipal.
36 // -------------------------------------------------
38 // {"2": {"0": "eyIxIjp7IjAiOiJodHRwczovL2EuY29tLyJ9fQ=="}}
46 // The value is a CSV list of Base64 encoded prinipcals.
52 // -------------------------------------------
54 // | Subsumed principals |
56 // | ------------------------------------|
58 // {"2": {"0": [{"1": {"0": https://mozilla.com"}}]}}
60 // -------------- Value
64 // Used by PrincipalJSONHandler.
65 class ExpandedPrincipalJSONHandler
: public PrincipalJSONHandlerShared
{
69 // After the inner object's '{'.
72 // After the property key for eSpecs.
75 // After the property key for eSuffix.
78 // After the subsumed principals array's '['.
81 // Subsumed principals array's item.
82 // Delegates to mSubsumedHandler until the subsumed object's '}'.
85 // After the property value for eSpecs or eSuffix,
86 // including after the subsumed principals array's ']'.
89 // After the inner object's '}'.
96 ExpandedPrincipalJSONHandler() = default;
97 virtual ~ExpandedPrincipalJSONHandler() = default;
99 virtual bool startObject() override
;
101 using PrincipalJSONHandlerShared::propertyName
;
102 virtual bool propertyName(const JS::Latin1Char
* name
, size_t length
) override
;
104 virtual bool endObject() override
;
106 virtual bool startArray() override
;
107 virtual bool endArray() override
;
109 using PrincipalJSONHandlerShared::stringValue
;
110 virtual bool stringValue(const JS::Latin1Char
* str
, size_t length
) override
;
112 bool HasAccepted() const { return mState
== State::EndObject
; }
115 virtual void SetErrorState() override
{ mState
= State::Error
; }
118 bool ProcessSubsumedResult(bool aResult
);
121 State mState
= State::Init
;
123 nsTArray
<nsCOMPtr
<nsIPrincipal
>> mAllowList
;
124 OriginAttributes mAttrs
;
125 Maybe
<SubsumedPrincipalJSONHandler
> mSubsumedHandler
;
128 } // namespace mozilla
130 #endif // mozilla_ExpandedPrincipalJSONHandler_h