/* THIS FILE IS AUTOGENERATED FROM RTCPeerConnectionStatic.webidl BY Codegen.py - DO NOT EDIT */

#ifndef mozilla_dom_RTCPeerConnectionStaticBinding_h
#define mozilla_dom_RTCPeerConnectionStaticBinding_h

#include "js/RootingAPI.h"
#include "jspubtd.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CallbackFunction.h"
#include "mozilla/dom/CallbackInterface.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsWeakReference.h"

namespace mozilla {
namespace dom {

struct NativePropertyHooks;
class PeerConnectionLifecycleCallback;
class ProtoAndIfaceCache;
class RTCPeerConnection;
class RTCPeerConnectionStatic;
struct RTCPeerConnectionStaticAtoms;

} // namespace dom
} // namespace mozilla

namespace mozilla {
namespace dom {

enum class RTCLifecycleEvent : uint32_t {
  Initialized,
  Icegatheringstatechange,
  Iceconnectionstatechange,
  EndGuard_
};

namespace RTCLifecycleEventValues {
extern const EnumEntry strings[4];
} // namespace RTCLifecycleEventValues


class PeerConnectionLifecycleCallback : public CallbackFunction
{
public:
  explicit inline PeerConnectionLifecycleCallback(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : CallbackFunction(aCx, aCallback, aIncumbentGlobal)
  {
    MOZ_ASSERT(JS::IsCallable(mCallback));
  }

  explicit inline PeerConnectionLifecycleCallback(CallbackFunction* aOther)
    : CallbackFunction(aOther)
  {
  }

  template <typename T>
  inline void
  Call(const T& thisVal, RTCPeerConnection& pc, uint64_t windowId, RTCLifecycleEvent eventType, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "PeerConnectionLifecycleCallback";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    JS::Rooted<JS::Value> thisValJS(s.GetContext());
    if (!ToJSValue(s.GetContext(), thisVal, &thisValJS)) {
      aRv.Throw(NS_ERROR_FAILURE);
      return;
    }
    return Call(s.GetContext(), thisValJS, pc, windowId, eventType, aRv);
  }

  inline void
  Call(RTCPeerConnection& pc, uint64_t windowId, RTCLifecycleEvent eventType, ErrorResult& aRv, const char* aExecutionReason = nullptr, ExceptionHandling aExceptionHandling = eReportExceptions, JSCompartment* aCompartment = nullptr)
  {
    if (!aExecutionReason) {
      aExecutionReason = "PeerConnectionLifecycleCallback";
    }
    CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
    if (!s.GetContext()) {
      aRv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
    return Call(s.GetContext(), JS::UndefinedHandleValue, pc, windowId, eventType, aRv);
  }

  inline bool
  operator==(const PeerConnectionLifecycleCallback& aOther) const
  {
    return CallbackFunction::operator==(aOther);
  }

private:
  void Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, RTCPeerConnection& pc, uint64_t windowId, RTCLifecycleEvent eventType, ErrorResult& aRv);
};


namespace RTCPeerConnectionStaticBinding {

  typedef mozilla::dom::RTCPeerConnectionStatic NativeType;

  // We declare this as an array so that retrieving a pointer to this
  // binding's property hooks only requires compile/link-time resolvable
  // address arithmetic.  Declaring it as a pointer instead would require
  // doing a run-time load to fetch a pointer to this binding's property
  // hooks.  And then structures which embedded a pointer to this structure
  // would require a run-time load for proper initialization, which would
  // then induce static constructors.  Lots of static constructors.
  extern const NativePropertyHooks sNativePropertyHooks[];

  JSObject*
  DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal);

  bool
  ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj);

  const JSClass*
  GetJSClass();

  bool
  Wrap(JSContext* aCx, mozilla::dom::RTCPeerConnectionStatic* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);

  template <class T>
  inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
  {
    JS::Rooted<JSObject*> reflector(aCx);
    return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
  }

  void
  CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal);

  JS::Handle<JSObject*>
  GetProtoObjectHandle(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

  JS::Handle<JSObject*>
  GetConstructorObjectHandle(JSContext* aCx, JS::Handle<JSObject*> aGlobal, bool aDefineOnGlobal = true);

  JSObject*
  GetConstructorObject(JSContext* aCx, JS::Handle<JSObject*> aGlobal);

} // namespace RTCPeerConnectionStaticBinding



class RTCPeerConnectionStaticJSImpl : public CallbackInterface
{
public:
  explicit inline RTCPeerConnectionStaticJSImpl(JSContext* aCx, JS::Handle<JSObject*> aCallback, nsIGlobalObject* aIncumbentGlobal)
    : CallbackInterface(aCx, aCallback, aIncumbentGlobal)
  {
  }

  void RegisterPeerConnectionLifecycleCallback(PeerConnectionLifecycleCallback& cb, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);

  void __Init(ErrorResult& aRv, JSCompartment* aCompartment = nullptr);

  inline bool
  operator==(const RTCPeerConnectionStaticJSImpl& aOther) const
  {
    return CallbackInterface::operator==(aOther);
  }

private:
  static bool
  InitIds(JSContext* cx, RTCPeerConnectionStaticAtoms* atomsCache);
};


class RTCPeerConnectionStatic final : public nsSupportsWeakReference,
                                      public nsWrapperCache
{
public:
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(RTCPeerConnectionStatic)

private:
  RefPtr<RTCPeerConnectionStaticJSImpl> mImpl;
  nsCOMPtr<nsISupports> mParent;

public:
  RTCPeerConnectionStatic(JS::Handle<JSObject*> aJSImplObject, nsIGlobalObject* aParent);

private:
  ~RTCPeerConnectionStatic();

public:
  nsISupports* GetParentObject() const;

  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

  static already_AddRefed<RTCPeerConnectionStatic> Constructor(const GlobalObject& global, JSContext* cx, ErrorResult& aRv);

  void RegisterPeerConnectionLifecycleCallback(PeerConnectionLifecycleCallback& cb, ErrorResult& aRv, JSCompartment* aCompartment = nullptr);

  static bool
  _Create(JSContext* cx, unsigned argc, JS::Value* vp);
};


} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_RTCPeerConnectionStaticBinding_h
