Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / caps / ContentPrincipalJSONHandler.h
blobe401af3000eee4f5e1aab7396954cd7af3ec8a77
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_ContentPrincipalJSONHandler_h
7 #define mozilla_ContentPrincipalJSONHandler_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/RefPtr.h" // RefPtr
17 #include "nsCOMPtr.h" // nsCOMPtr
18 #include "nsDebug.h" // NS_WARNING
19 #include "nsIURI.h" // nsIURI
21 #include "ContentPrincipal.h"
22 #include "OriginAttributes.h"
23 #include "SharedJSONHandler.h"
25 namespace mozilla {
27 // JSON parse handler for an inner object for ContentPrincipal.
28 // Used by PrincipalJSONHandler or SubsumedPrincipalJSONHandler.
29 class ContentPrincipalJSONHandler : public PrincipalJSONHandlerShared {
30 enum class State {
31 Init,
33 // After the inner object's '{'.
34 StartObject,
36 // After the property key for eURI.
37 URIKey,
39 // After the property key for eDomain.
40 DomainKey,
42 // After the property key for eSuffix.
43 SuffixKey,
45 // After the property value for eURI, eDomain, or eSuffix.
46 AfterPropertyValue,
48 // After the inner object's '}'.
49 EndObject,
51 Error,
54 public:
55 ContentPrincipalJSONHandler() = default;
56 virtual ~ContentPrincipalJSONHandler() = default;
58 virtual bool startObject() override;
60 using PrincipalJSONHandlerShared::propertyName;
61 virtual bool propertyName(const JS::Latin1Char* name, size_t length) override;
63 virtual bool endObject() override;
65 virtual bool startArray() override {
66 NS_WARNING("Unexpected array value");
67 mState = State::Error;
68 return false;
70 virtual bool endArray() override {
71 NS_WARNING("Unexpected array value");
72 mState = State::Error;
73 return false;
76 using PrincipalJSONHandlerShared::stringValue;
77 virtual bool stringValue(const JS::Latin1Char* str, size_t length) override;
79 bool HasAccepted() const { return mState == State::EndObject; }
81 protected:
82 virtual void SetErrorState() override { mState = State::Error; }
84 private:
85 State mState = State::Init;
87 nsCOMPtr<nsIURI> mPrincipalURI;
88 nsCOMPtr<nsIURI> mDomain;
89 OriginAttributes mAttrs;
92 } // namespace mozilla
94 #endif // mozilla_ContentPrincipalJSONHandler_h