#pragma once
#include "MessageReceiver.h"
#include "MessageSender.h"
#include "WebSocketIdentifier.h"
#include <WebCore/SocketStreamHandle.h>
namespace IPC {
class Connection;
class Decoder;
class DataReference;
}
namespace WebCore {
class SocketStreamError;
}
namespace WebKit {
class WebSocketStream : public IPC::MessageSender, public IPC::MessageReceiver, public WebCore::SocketStreamHandle {
public:
static Ref<WebSocketStream> create(const URL&, WebCore::SocketStreamHandleClient&, const String& credentialPartition);
static void networkProcessCrashed();
static WebSocketStream* streamWithIdentifier(WebSocketIdentifier);
void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
void platformSend(const uint8_t*, size_t, Function<void(bool)>&&) final;
void platformSendHandshake(const uint8_t*, size_t, const Optional<WebCore::CookieRequestHeaderFieldProxy>&, Function<void(bool, bool)>&&);
void platformClose() final;
size_t bufferedAmount() final;
void didOpenSocketStream();
void didCloseSocketStream();
void didReceiveSocketStreamData(const IPC::DataReference&);
void didFailToReceiveSocketStreamData();
void didUpdateBufferedAmount(uint64_t);
void didFailSocketStream(WebCore::SocketStreamError&&);
void didSendData(uint64_t, bool success);
void didSendHandshake(uint64_t, bool success, bool didAccessSecureCookies);
private:
IPC::Connection* messageSenderConnection() const final;
uint64_t messageSenderDestinationID() const final;
WebSocketStream(const URL&, WebCore::SocketStreamHandleClient&, const String& credentialPartition);
~WebSocketStream();
WebSocketIdentifier m_identifier;
size_t m_bufferedAmount { 0 };
WebCore::SocketStreamHandleClient& m_client;
HashMap<uint64_t, Function<void(bool)>> m_sendDataCallbacks;
HashMap<uint64_t, Function<void(bool, bool)>> m_sendHandshakeCallbacks;
};
}