tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SubsumedPrincipalJSONHandler.h (3044B)


      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/. */
      5 
      6 #ifndef mozilla_SubsumedPrincipalJSONHandler_h
      7 #define mozilla_SubsumedPrincipalJSONHandler_h
      8 
      9 #include <stddef.h>  // size_t
     10 #include <stdint.h>  // uint32_t
     11 
     12 #include "js/TypeDecls.h"  // JS::Latin1Char
     13 
     14 #include "mozilla/Variant.h"  // Variant
     15 #include "mozilla/RefPtr.h"   // RefPtr
     16 
     17 #include "nsDebug.h"  // NS_WARNING
     18 
     19 #include "BasePrincipal.h"
     20 #include "ContentPrincipalJSONHandler.h"
     21 #include "NullPrincipalJSONHandler.h"
     22 #include "SharedJSONHandler.h"
     23 
     24 namespace mozilla {
     25 
     26 class SubsumedPrincipalJSONHandlerTypes {
     27 public:
     28  enum class State {
     29    Init,
     30 
     31    // After the subsumed principal object's '{'.
     32    StartObject,
     33 
     34    // After the PrincipalKind property key for SystemPrincipal.
     35    SystemPrincipal_Key,
     36    // After the SystemPrincipal's inner object's '{'.
     37    SystemPrincipal_StartObject,
     38    // After the SystemPrincipal's inner object's '}'.
     39    SystemPrincipal_EndObject,
     40 
     41    // After the PrincipalKind property key for NullPrincipal or
     42    // ContentPrincipal, and also the entire inner object.
     43    // Delegates to mInnerHandler until the inner object's '}'.
     44    //
     45    // Unlike PrincipalJSONHandler, subsumed principal doesn't contain
     46    // ExpandedPrincipal.
     47    NullPrincipal_Inner,
     48    ContentPrincipal_Inner,
     49 
     50    // After the subsumed principal object's '}'.
     51    EndObject,
     52 
     53    Error,
     54  };
     55 
     56  using InnerHandlerT =
     57      Maybe<Variant<NullPrincipalJSONHandler, ContentPrincipalJSONHandler>>;
     58 
     59  static constexpr bool CanContainExpandedPrincipal = false;
     60 };
     61 
     62 // JSON parse handler for subsumed principal object inside ExpandedPrincipal's
     63 // new format.
     64 //
     65 //                       Subsumed principal object
     66 //                               |
     67 //              ----------------------------------
     68 //              |                                |
     69 // {"2": {"0": [{"1": {"0": https://mozilla.com"}}]}}
     70 //                |   |                         |
     71 //                |   ---------------------------
     72 //                |                |
     73 //                |         inner object
     74 //          PrincipalKind
     75 //
     76 // For inner object except for the system principal case, this delegates
     77 // to NullPrincipalJSONHandler or ContentPrincipalJSONHandler.
     78 class SubsumedPrincipalJSONHandler
     79    : public ContainerPrincipalJSONHandler<SubsumedPrincipalJSONHandlerTypes> {
     80  using State = SubsumedPrincipalJSONHandlerTypes::State;
     81  using InnerHandlerT = SubsumedPrincipalJSONHandlerTypes::InnerHandlerT;
     82 
     83 public:
     84  SubsumedPrincipalJSONHandler() = default;
     85  virtual ~SubsumedPrincipalJSONHandler() = default;
     86 
     87  bool HasAccepted() const { return mState == State::EndObject; }
     88 
     89 protected:
     90  virtual void SetErrorState() override { mState = State::Error; }
     91 };
     92 
     93 }  // namespace mozilla
     94 
     95 #endif  // mozilla_SubsumedPrincipalJSONHandler_h