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"
27 // JSON parse handler for an inner object for ContentPrincipal.
28 // Used by PrincipalJSONHandler or SubsumedPrincipalJSONHandler.
29 class ContentPrincipalJSONHandler
: public PrincipalJSONHandlerShared
{
33 // After the inner object's '{'.
36 // After the property key for eURI.
39 // After the property key for eDomain.
42 // After the property key for eSuffix.
45 // After the property value for eURI, eDomain, or eSuffix.
48 // After the inner object's '}'.
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
;
70 virtual bool endArray() override
{
71 NS_WARNING("Unexpected array value");
72 mState
= State::Error
;
76 using PrincipalJSONHandlerShared::stringValue
;
77 virtual bool stringValue(const JS::Latin1Char
* str
, size_t length
) override
;
79 bool HasAccepted() const { return mState
== State::EndObject
; }
82 virtual void SetErrorState() override
{ mState
= State::Error
; }
85 State mState
= State::Init
;
87 nsCOMPtr
<nsIURI
> mPrincipalURI
;
88 nsCOMPtr
<nsIURI
> mDomain
;
89 OriginAttributes mAttrs
;
92 } // namespace mozilla
94 #endif // mozilla_ContentPrincipalJSONHandler_h