//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/dom/PSharedWorkerParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/ClientIPCUtils.h"
#include "mozilla/dom/ReferrerInfoUtils.h"
#include "mozilla/dom/SharedWorkerParent.h"
#include "mozilla/dom/WorkerIPCUtils.h"
#include "mozilla/ipc/IPCCore.h"
#include "nsIPrincipal.h"

#include "mozilla/ipc/PBackgroundParent.h"

#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"

namespace mozilla {
namespace dom {


MOZ_IMPLICIT PSharedWorkerParent::PSharedWorkerParent() :
    mozilla::ipc::IProtocol(kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PSharedWorkerParent);
}

PSharedWorkerParent::~PSharedWorkerParent()
{
    MOZ_COUNT_DTOR(PSharedWorkerParent);
}

auto PSharedWorkerParent::ActorAlloc() -> void
{
}

auto PSharedWorkerParent::ActorDealloc() -> void
{
    if (Manager()) {
        Manager()->DeallocManagee(kProtocolId, this);
    }
}

auto PSharedWorkerParent::OtherPid() const -> ::base::ProcessId
{
    ::base::ProcessId pid =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherPidMaybeInvalid();
    MOZ_RELEASE_ASSERT(pid != ::base::kInvalidProcessId);
    return pid;
}

auto PSharedWorkerParent::OtherChildID() const -> ::GeckoChildID
{
    ::GeckoChildID childID =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherChildIDMaybeInvalid();
    MOZ_RELEASE_ASSERT(childID != -1);
    return childID;
}

auto PSharedWorkerParent::OtherEndpointProcInfo() const -> ::mozilla::ipc::EndpointProcInfo
{
    return ::mozilla::ipc::EndpointProcInfo{OtherPid(), OtherChildID()};
}

auto PSharedWorkerParent::Manager() const -> PBackgroundParent*
{
    return static_cast<PBackgroundParent*>(IProtocol::Manager());
}

auto PSharedWorkerParent::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PSharedWorkerParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PSharedWorkerParent::SendError(const ErrorValue& value) -> bool
{
    UniquePtr<IPC::Message> msg__ = PSharedWorker::Msg_Error(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), value);
    // Sentinel = 'value'
    ((&(writer__)))->WriteSentinel(107610654);


    if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PSharedWorkerParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PSharedWorker::Msg_Error", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PSharedWorkerParent::SendNotifyLock(const bool& aCreated) -> bool
{
    UniquePtr<IPC::Message> msg__ = PSharedWorker::Msg_NotifyLock(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aCreated);
    // Sentinel = 'aCreated'
    ((&(writer__)))->WriteSentinel(228066074);


    if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PSharedWorkerParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PSharedWorker::Msg_NotifyLock", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PSharedWorkerParent::SendNotifyWebTransport(const bool& aCreated) -> bool
{
    UniquePtr<IPC::Message> msg__ = PSharedWorker::Msg_NotifyWebTransport(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aCreated);
    // Sentinel = 'aCreated'
    ((&(writer__)))->WriteSentinel(228066074);


    if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PSharedWorkerParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PSharedWorker::Msg_NotifyWebTransport", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PSharedWorkerParent::SendTerminate() -> bool
{
    UniquePtr<IPC::Message> msg__ = PSharedWorker::Msg_Terminate(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PSharedWorkerParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PSharedWorker::Msg_Terminate", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PSharedWorkerParent::Send__delete__(PSharedWorkerParent* actor) -> bool
{
    if (!actor || !actor->CanSend()) {
        NS_WARNING("Attempt to __delete__ missing or closed actor");
        return false;
    }
    UniquePtr<IPC::Message> msg__ = PSharedWorker::Msg___delete__((actor)->Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            actor};


    if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PSharedWorkerParent",
            actor->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PSharedWorker::Msg___delete__", OTHER);

    bool sendok__ = (actor)->ChannelSend(std::move(msg__));

    actor->ActorDisconnected(Deletion);
    return sendok__;
}

auto PSharedWorkerParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PSharedWorkerParent::OnMessageReceived(const Message& msg__) -> PSharedWorkerParent::Result
{
    switch (msg__.type()) {
    case MANAGED_ENDPOINT_BOUND_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            return MsgProcessed;
        }
    case MANAGED_ENDPOINT_DROPPED_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            this->ActorDisconnected(ManagedEndpointDropped);
            return MsgProcessed;
        }
    case PSharedWorker::Msg_Close__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSharedWorkerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSharedWorker::Msg_Close", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<SharedWorkerParent*>(this))->RecvClose();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PSharedWorker::Msg_Suspend__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSharedWorkerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSharedWorker::Msg_Suspend", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<SharedWorkerParent*>(this))->RecvSuspend();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PSharedWorker::Msg_Resume__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSharedWorkerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSharedWorker::Msg_Resume", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<SharedWorkerParent*>(this))->RecvResume();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PSharedWorker::Msg_Freeze__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSharedWorkerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSharedWorker::Msg_Freeze", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<SharedWorkerParent*>(this))->RecvFreeze();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PSharedWorker::Msg_Thaw__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSharedWorker", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSharedWorkerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSharedWorker::Msg_Thaw", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<SharedWorkerParent*>(this))->RecvThaw();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PSharedWorker::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PSharedWorkerParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PSharedWorkerParent::Result
{
    return MsgNotKnown;
}



} // namespace dom
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::dom::PSharedWorkerParent*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PSharedWorker'
    (aWriter)->WriteSentinel(581109026);
}

auto ParamTraits<::mozilla::dom::PSharedWorkerParent*>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe__actor = IPC::ReadParam<mozilla::ipc::IProtocol*>(aReader);
    if (!maybe__actor) {
        aReader->FatalError("Error deserializing managed PSharedWorker actor");
        return {};

    }
    auto& actor = *maybe__actor;
    // Sentinel = 'PSharedWorker'
    if ((!((aReader)->ReadSentinel(581109026)))) {
        mozilla::ipc::SentinelReadError("Error deserializing managed PSharedWorker actor");
        return {};
    }

    if (actor && actor->GetProtocolId() != PSharedWorkerMsgStart) {
        aReader->FatalError("Unexpected actor type (expected PSharedWorker)");

        return {};
    }
    return static_cast<::mozilla::dom::PSharedWorkerParent*>(actor);
}

} // namespace IPC
