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


#include "mozilla/PWebBrowserPersistDocumentParent.h"
#include "mozilla/AntiTrackingIPCUtils.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/WebBrowserPersistDocumentParent.h"
#include "mozilla/dom/DomSecurityIPCUtils.h"
#include "mozilla/dom/FeaturePolicyUtils.h"
#include "mozilla/dom/FetchIPCTypes.h"
#include "mozilla/dom/NavigationAPIIPCUtils.h"
#include "mozilla/dom/PropertyBagUtils.h"
#include "mozilla/dom/ReferrerInfoUtils.h"
#include "mozilla/dom/SessionHistoryEntry.h"
#include "mozilla/ipc/IPCCore.h"
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/net/CacheInfoIPCTypes.h"
#include "mozilla/net/ClassOfService.h"
#include "nsDOMNavigationTiming.h"
#include "nsDocShellLoadState.h"
#include "nsHttp.h"
#include "nsHttpResponseHead.h"
#include "nsIPropertyBag2.h"
#include "nsIReferrerInfo.h"

#include "mozilla/dom/PContentParent.h"
#include "mozilla/PWebBrowserPersistResourcesParent.h"
#include "mozilla/PWebBrowserPersistSerializeParent.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 {


MOZ_IMPLICIT PWebBrowserPersistDocumentParent::PWebBrowserPersistDocumentParent() :
    mozilla::ipc::IRefCountedProtocol(kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PWebBrowserPersistDocumentParent);
}

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

auto PWebBrowserPersistDocumentParent::ActorAlloc() -> void
{
    AddRef();
}

auto PWebBrowserPersistDocumentParent::ActorDealloc() -> void
{
    Release();
}

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

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

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

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

auto PWebBrowserPersistDocumentParent::ManagedPWebBrowserPersistResourcesParent(nsTArray<PWebBrowserPersistResourcesParent*>& aArr) const -> void
{
    mManagedPWebBrowserPersistResourcesParent.ToArray(aArr);
}

auto PWebBrowserPersistDocumentParent::ManagedPWebBrowserPersistResourcesParent() const -> const ManagedContainer<PWebBrowserPersistResourcesParent>&
{
    return mManagedPWebBrowserPersistResourcesParent;
}

auto PWebBrowserPersistDocumentParent::ManagedPWebBrowserPersistSerializeParent(nsTArray<PWebBrowserPersistSerializeParent*>& aArr) const -> void
{
    mManagedPWebBrowserPersistSerializeParent.ToArray(aArr);
}

auto PWebBrowserPersistDocumentParent::ManagedPWebBrowserPersistSerializeParent() const -> const ManagedContainer<PWebBrowserPersistSerializeParent>&
{
    return mManagedPWebBrowserPersistSerializeParent;
}

auto PWebBrowserPersistDocumentParent::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    static constexpr ::mozilla::ipc::ProtocolId sIds[] = {
        PWebBrowserPersistResourcesMsgStart,
        PWebBrowserPersistSerializeMsgStart
    };
    return sIds;
}

auto PWebBrowserPersistDocumentParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PWebBrowserPersistResourcesMsgStart:
        return (&(mManagedPWebBrowserPersistResourcesParent));
    case PWebBrowserPersistSerializeMsgStart:
        return (&(mManagedPWebBrowserPersistSerializeParent));
    default:
        return nullptr;
    }
}

auto PWebBrowserPersistDocumentParent::OpenPWebBrowserPersistResourcesEndpoint(PWebBrowserPersistResourcesParent* aActor) -> ManagedEndpoint<PWebBrowserPersistResourcesChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PWebBrowserPersistResourcesParent actor");
        return ManagedEndpoint<PWebBrowserPersistResourcesChild>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PWebBrowserPersistResourcesParent actor");
        return ManagedEndpoint<PWebBrowserPersistResourcesChild>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PWebBrowserPersistResourcesChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PWebBrowserPersistDocumentParent::BindPWebBrowserPersistResourcesEndpoint(
        ManagedEndpoint<PWebBrowserPersistResourcesParent> aEndpoint,
        PWebBrowserPersistResourcesParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PWebBrowserPersistDocumentParent::OpenPWebBrowserPersistSerializeEndpoint(PWebBrowserPersistSerializeParent* aActor) -> ManagedEndpoint<PWebBrowserPersistSerializeChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PWebBrowserPersistSerializeParent actor");
        return ManagedEndpoint<PWebBrowserPersistSerializeChild>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PWebBrowserPersistSerializeParent actor");
        return ManagedEndpoint<PWebBrowserPersistSerializeChild>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PWebBrowserPersistSerializeChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PWebBrowserPersistDocumentParent::BindPWebBrowserPersistSerializeEndpoint(
        ManagedEndpoint<PWebBrowserPersistSerializeParent> aEndpoint,
        PWebBrowserPersistSerializeParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PWebBrowserPersistDocumentParent::SendSetPersistFlags(const uint32_t& aNewFlags) -> bool
{
    UniquePtr<IPC::Message> msg__ = PWebBrowserPersistDocument::Msg_SetPersistFlags(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

auto PWebBrowserPersistDocumentParent::SendPWebBrowserPersistResourcesConstructor() -> PWebBrowserPersistResourcesParent*
{
    PWebBrowserPersistResourcesParent* actor = (static_cast<WebBrowserPersistDocumentParent*>(this))->AllocPWebBrowserPersistResourcesParent();
    return SendPWebBrowserPersistResourcesConstructor(std::move(actor));
}

auto PWebBrowserPersistDocumentParent::SendPWebBrowserPersistResourcesConstructor(PWebBrowserPersistResourcesParent* actor) -> PWebBrowserPersistResourcesParent*
{
    if (!actor) {
        NS_WARNING("Cannot bind null PWebBrowserPersistResourcesParent actor");
        return nullptr;
    }

    if (!actor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PWebBrowserPersistResourcesParent actor");
        return nullptr;
    }


    // Build our constructor message.
    UniquePtr<IPC::Message> msg__ = PWebBrowserPersistDocument::Msg_PWebBrowserPersistResourcesConstructor(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), (actor)->Id());
    // Sentinel = 'actorid'
    ((&(writer__)))->WriteSentinel(193725159);


    // Notify the other side about the newly created actor. This can
    // fail if our manager has already been destroyed.
    //
    // NOTE: If the send call fails due to toplevel channel teardown,
    // the `IProtocol::ChannelSend` wrapper absorbs the error for us,
    // so we don't tear down actors unexpectedly.

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

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


    // Warn, destroy the actor, and return null if the message failed to
    // send. Otherwise, return the successfully created actor reference.
    if (!sendok__) {
        NS_WARNING("Error sending PWebBrowserPersistResourcesParent constructor");
        actor->ActorDisconnected(FailedConstructor);

        return nullptr;
    }
    return actor;
}

auto PWebBrowserPersistDocumentParent::SendPWebBrowserPersistSerializeConstructor(
        const WebBrowserPersistURIMap& aMap,
        const nsACString& aRequestedContentType,
        const uint32_t& aEncoderFlags,
        const uint32_t& aWrapColumn) -> PWebBrowserPersistSerializeParent*
{
    PWebBrowserPersistSerializeParent* actor = (static_cast<WebBrowserPersistDocumentParent*>(this))->AllocPWebBrowserPersistSerializeParent(aMap, aRequestedContentType, aEncoderFlags, aWrapColumn);
    return SendPWebBrowserPersistSerializeConstructor(std::move(actor), std::move(aMap), std::move(aRequestedContentType), std::move(aEncoderFlags), std::move(aWrapColumn));
}

auto PWebBrowserPersistDocumentParent::SendPWebBrowserPersistSerializeConstructor(
        PWebBrowserPersistSerializeParent* actor,
        const WebBrowserPersistURIMap& aMap,
        const nsACString& aRequestedContentType,
        const uint32_t& aEncoderFlags,
        const uint32_t& aWrapColumn) -> PWebBrowserPersistSerializeParent*
{
    if (!actor) {
        NS_WARNING("Cannot bind null PWebBrowserPersistSerializeParent actor");
        return nullptr;
    }

    if (!actor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PWebBrowserPersistSerializeParent actor");
        return nullptr;
    }


    // Build our constructor message.
    UniquePtr<IPC::Message> msg__ = PWebBrowserPersistDocument::Msg_PWebBrowserPersistSerializeConstructor(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), (actor)->Id());
    // Sentinel = 'actorid'
    ((&(writer__)))->WriteSentinel(193725159);
    IPC::WriteParam((&(writer__)), aMap);
    // Sentinel = 'aMap'
    ((&(writer__)))->WriteSentinel(60883328);
    IPC::WriteParam((&(writer__)), aRequestedContentType);
    // Sentinel = 'aRequestedContentType'
    ((&(writer__)))->WriteSentinel(1563297937);
    IPC::WriteParam((&(writer__)), aEncoderFlags);
    // Sentinel = 'aEncoderFlags'
    ((&(writer__)))->WriteSentinel(582354191);
    IPC::WriteParam((&(writer__)), aWrapColumn);
    // Sentinel = 'aWrapColumn'
    ((&(writer__)))->WriteSentinel(432669802);


    // Notify the other side about the newly created actor. This can
    // fail if our manager has already been destroyed.
    //
    // NOTE: If the send call fails due to toplevel channel teardown,
    // the `IProtocol::ChannelSend` wrapper absorbs the error for us,
    // so we don't tear down actors unexpectedly.

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

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


    // Warn, destroy the actor, and return null if the message failed to
    // send. Otherwise, return the successfully created actor reference.
    if (!sendok__) {
        NS_WARNING("Error sending PWebBrowserPersistSerializeParent constructor");
        actor->ActorDisconnected(FailedConstructor);

        return nullptr;
    }
    return actor;
}

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


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

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

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

auto PWebBrowserPersistDocumentParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    switch (aProtocolId) {
    case PWebBrowserPersistResourcesMsgStart:
        static_cast<WebBrowserPersistDocumentParent*>(this)->DeallocPWebBrowserPersistResourcesParent(static_cast<PWebBrowserPersistResourcesParent*>(aListener));
        return;
    case PWebBrowserPersistSerializeMsgStart:
        static_cast<WebBrowserPersistDocumentParent*>(this)->DeallocPWebBrowserPersistSerializeParent(static_cast<PWebBrowserPersistSerializeParent*>(aListener));
        return;
    default:
        FatalError("unreached");
        return;
    }
}

auto PWebBrowserPersistDocumentParent::OnMessageReceived(const Message& msg__) -> PWebBrowserPersistDocumentParent::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 PWebBrowserPersistDocument::Msg_Attributes__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PWebBrowserPersistDocument", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PWebBrowserPersistDocumentParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PWebBrowserPersistDocument::Msg_Attributes", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__aAttrs = IPC::ReadParam<WebBrowserPersistDocumentAttrs>((&(reader__)));
            if (!maybe__aAttrs) {
                FatalError("Error deserializing 'WebBrowserPersistDocumentAttrs'");
                return MsgValueError;

            }
            auto& aAttrs = *maybe__aAttrs;
            // Sentinel = 'aAttrs'
            if ((!(((&(reader__)))->ReadSentinel(135529072)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'WebBrowserPersistDocumentAttrs'");
                return MsgValueError;
            }
            auto maybe__stream = IPC::ReadParam<mozilla::Maybe<IPCStream>>((&(reader__)));
            if (!maybe__stream) {
                FatalError("Error deserializing 'IPCStream?'");
                return MsgValueError;

            }
            auto& stream = *maybe__stream;
            // Sentinel = 'stream'
            if ((!(((&(reader__)))->ReadSentinel(153223821)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCStream?'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<WebBrowserPersistDocumentParent*>(this))->RecvAttributes(std::move(aAttrs), std::move(stream));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PWebBrowserPersistDocument::Msg_InitFailure__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PWebBrowserPersistDocument", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PWebBrowserPersistDocumentParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PWebBrowserPersistDocument::Msg_InitFailure", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__aStatus = IPC::ReadParam<nsresult>((&(reader__)));
            if (!maybe__aStatus) {
                FatalError("Error deserializing 'nsresult'");
                return MsgValueError;

            }
            auto& aStatus = *maybe__aStatus;
            // Sentinel = 'aStatus'
            if ((!(((&(reader__)))->ReadSentinel(186712806)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<WebBrowserPersistDocumentParent*>(this))->RecvInitFailure(std::move(aStatus));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PWebBrowserPersistDocument::Reply_PWebBrowserPersistResourcesConstructor__ID:
        {
            return MsgProcessed;
        }
    case PWebBrowserPersistDocument::Reply_PWebBrowserPersistSerializeConstructor__ID:
        {
            return MsgProcessed;
        }
    case PWebBrowserPersistDocument::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

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



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

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

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

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

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

} // namespace IPC
