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_NullPrincipalJSONHandler_h
7 #define mozilla_NullPrincipalJSONHandler_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/Assertions.h" // MOZ_ASSERT_UNREACHABLE
16 #include "mozilla/RefPtr.h" // RefPtr
18 #include "nsCOMPtr.h" // nsCOMPtr
19 #include "nsDebug.h" // NS_WARNING
20 #include "nsIURI.h" // nsIURI
22 #include "NullPrincipal.h"
23 #include "OriginAttributes.h"
24 #include "SharedJSONHandler.h"
28 // JSON parse handler for an inner object for NullPrincipal.
29 // Used by PrincipalJSONHandler or SubsumedPrincipalJSONHandler.
30 class NullPrincipalJSONHandler
: public PrincipalJSONHandlerShared
{
34 // After the inner object's '{'.
37 // After the property key for eSpec.
40 // After the property key for eSuffix.
43 // After the property value for eSpec or eSuffix.
46 // After the inner object's '}'.
53 NullPrincipalJSONHandler() = default;
54 virtual ~NullPrincipalJSONHandler() = default;
56 virtual bool startObject() override
;
58 using PrincipalJSONHandlerShared::propertyName
;
59 virtual bool propertyName(const JS::Latin1Char
* name
, size_t length
) override
;
61 virtual bool endObject() override
;
63 virtual bool startArray() override
{
64 NS_WARNING("Unexpected array value");
65 mState
= State::Error
;
68 virtual bool endArray() override
{
69 NS_WARNING("Unexpected array value");
70 mState
= State::Error
;
74 using PrincipalJSONHandlerShared::stringValue
;
75 virtual bool stringValue(const JS::Latin1Char
* str
, size_t length
) override
;
77 bool HasAccepted() const { return mState
== State::EndObject
; }
80 virtual void SetErrorState() override
{ mState
= State::Error
; }
83 State mState
= State::Init
;
85 nsCOMPtr
<nsIURI
> mUri
;
86 OriginAttributes mAttrs
;
89 } // namespace mozilla
91 #endif // mozilla_NullPrincipalJSONHandler_h