Bug 1877661 - use non-shippable geckoview for android source tests. r=bhearsum,releng...
[gecko.git] / caps / NullPrincipalJSONHandler.h
blob3c5f9e16314a58555345570cf1b5a2ed80a8a93c
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"
26 namespace mozilla {
28 // JSON parse handler for an inner object for NullPrincipal.
29 // Used by PrincipalJSONHandler or SubsumedPrincipalJSONHandler.
30 class NullPrincipalJSONHandler : public PrincipalJSONHandlerShared {
31 enum class State {
32 Init,
34 // After the inner object's '{'.
35 StartObject,
37 // After the property key for eSpec.
38 SpecKey,
40 // After the property key for eSuffix.
41 SuffixKey,
43 // After the property value for eSpec or eSuffix.
44 AfterPropertyValue,
46 // After the inner object's '}'.
47 EndObject,
49 Error,
52 public:
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;
66 return false;
68 virtual bool endArray() override {
69 NS_WARNING("Unexpected array value");
70 mState = State::Error;
71 return false;
74 using PrincipalJSONHandlerShared::stringValue;
75 virtual bool stringValue(const JS::Latin1Char* str, size_t length) override;
77 bool HasAccepted() const { return mState == State::EndObject; }
79 protected:
80 virtual void SetErrorState() override { mState = State::Error; }
82 private:
83 State mState = State::Init;
85 nsCOMPtr<nsIURI> mUri;
86 OriginAttributes mAttrs;
89 } // namespace mozilla
91 #endif // mozilla_NullPrincipalJSONHandler_h