Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / caps / ExpandedPrincipalJSONHandler.h
blob0e037cf044938e05039dacb1e7c52248e2c333c4
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"
28 namespace mozilla {
30 // JSON parse handler for an inner object for ExpandedPrincipal.
32 // # Legacy format
34 // inner object
35 // |
36 // -------------------------------------------------
37 // | |
38 // {"2": {"0": "eyIxIjp7IjAiOiJodHRwczovL2EuY29tLyJ9fQ=="}}
39 // | | |
40 // | ---------- Value
41 // | |
42 // PrincipalKind |
43 // |
44 // SerializableKeys
46 // The value is a CSV list of Base64 encoded prinipcals.
48 // # New format
50 // inner object
51 // |
52 // -------------------------------------------
53 // | |
54 // | Subsumed principals |
55 // | | |
56 // | ------------------------------------|
57 // | | ||
58 // {"2": {"0": [{"1": {"0": https://mozilla.com"}}]}}
59 // | | |
60 // -------------- Value
61 // |
62 // PrincipalKind
64 // Used by PrincipalJSONHandler.
65 class ExpandedPrincipalJSONHandler : public PrincipalJSONHandlerShared {
66 enum class State {
67 Init,
69 // After the inner object's '{'.
70 StartObject,
72 // After the property key for eSpecs.
73 SpecsKey,
75 // After the property key for eSuffix.
76 SuffixKey,
78 // After the subsumed principals array's '['.
79 StartArray,
81 // Subsumed principals array's item.
82 // Delegates to mSubsumedHandler until the subsumed object's '}'.
83 SubsumedPrincipal,
85 // After the property value for eSpecs or eSuffix,
86 // including after the subsumed principals array's ']'.
87 AfterPropertyValue,
89 // After the inner object's '}'.
90 EndObject,
92 Error,
95 public:
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; }
114 protected:
115 virtual void SetErrorState() override { mState = State::Error; }
117 private:
118 bool ProcessSubsumedResult(bool aResult);
120 private:
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