#include "third_party/blink/renderer/modules/presentation/presentation_connection.h"
#include <memory>
#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/fileapi/file_error.h"
#include "third_party/blink/renderer/core/fileapi/file_reader_client.h"
#include "third_party/blink/renderer/core/fileapi/file_reader_loader.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/presentation/presentation.h"
#include "third_party/blink/renderer/modules/presentation/presentation_connection_available_event.h"
#include "third_party/blink/renderer/modules/presentation/presentation_connection_close_event.h"
#include "third_party/blink/renderer/modules/presentation/presentation_controller.h"
#include "third_party/blink/renderer/modules/presentation/presentation_receiver.h"
#include "third_party/blink/renderer/modules/presentation/presentation_request.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink {
namespace {
mojom::blink::PresentationConnectionMessagePtr MakeBinaryMessage(
const DOMArrayBuffer* buffer) { … }
mojom::blink::PresentationConnectionMessagePtr MakeTextMessage(
const String& text) { … }
const AtomicString& ConnectionStateToString(
mojom::blink::PresentationConnectionState state) { … }
const AtomicString& ConnectionCloseReasonToString(
mojom::blink::PresentationConnectionCloseReason reason) { … }
void ThrowPresentationDisconnectedError(ExceptionState& exception_state) { … }
}
class PresentationConnection::Message final
: public GarbageCollected<PresentationConnection::Message> { … };
class PresentationConnection::BlobLoader final
: public GarbageCollected<PresentationConnection::BlobLoader>,
public FileReaderAccumulator { … };
PresentationConnection::PresentationConnection(LocalDOMWindow& window,
const String& id,
const KURL& url)
: … { … }
PresentationConnection::~PresentationConnection() { … }
void PresentationConnection::OnMessage(
mojom::blink::PresentationConnectionMessagePtr message) { … }
void PresentationConnection::DidChangeState(
mojom::blink::PresentationConnectionState state) { … }
void PresentationConnection::DidClose(
mojom::blink::PresentationConnectionCloseReason reason) { … }
ControllerPresentationConnection* ControllerPresentationConnection::Take(
ScriptPromiseResolverBase* resolver,
const mojom::blink::PresentationInfo& presentation_info,
PresentationRequest* request) { … }
ControllerPresentationConnection* ControllerPresentationConnection::Take(
PresentationController* controller,
const mojom::blink::PresentationInfo& presentation_info,
PresentationRequest* request) { … }
ControllerPresentationConnection::ControllerPresentationConnection(
LocalDOMWindow& window,
PresentationController* controller,
const String& id,
const KURL& url)
: … { … }
ControllerPresentationConnection::~ControllerPresentationConnection() { … }
void ControllerPresentationConnection::Trace(Visitor* visitor) const { … }
void ControllerPresentationConnection::Init(
mojo::PendingRemote<mojom::blink::PresentationConnection> connection_remote,
mojo::PendingReceiver<mojom::blink::PresentationConnection>
connection_receiver) { … }
void ControllerPresentationConnection::CloseInternal() { … }
void ControllerPresentationConnection::TerminateInternal() { … }
ReceiverPresentationConnection* ReceiverPresentationConnection::Take(
PresentationReceiver* receiver,
const mojom::blink::PresentationInfo& presentation_info,
mojo::PendingRemote<mojom::blink::PresentationConnection>
controller_connection,
mojo::PendingReceiver<mojom::blink::PresentationConnection>
receiver_connection_receiver) { … }
ReceiverPresentationConnection::ReceiverPresentationConnection(
LocalDOMWindow& window,
PresentationReceiver* receiver,
const String& id,
const KURL& url)
: … { … }
ReceiverPresentationConnection::~ReceiverPresentationConnection() = default;
void ReceiverPresentationConnection::Init(
mojo::PendingRemote<mojom::blink::PresentationConnection>
controller_connection_remote,
mojo::PendingReceiver<mojom::blink::PresentationConnection>
receiver_connection_receiver) { … }
void ReceiverPresentationConnection::DidChangeState(
mojom::blink::PresentationConnectionState state) { … }
void ReceiverPresentationConnection::DidClose(
mojom::blink::PresentationConnectionCloseReason reason) { … }
void ReceiverPresentationConnection::CloseInternal() { … }
void ReceiverPresentationConnection::TerminateInternal() { … }
void ReceiverPresentationConnection::Trace(Visitor* visitor) const { … }
const AtomicString& PresentationConnection::InterfaceName() const { … }
ExecutionContext* PresentationConnection::GetExecutionContext() const { … }
void PresentationConnection::AddedEventListener(
const AtomicString& event_type,
RegisteredEventListener& registered_listener) { … }
void PresentationConnection::ContextDestroyed() { … }
void PresentationConnection::ContextLifecycleStateChanged(
mojom::FrameLifecycleState state) { … }
void PresentationConnection::CloseConnection() { … }
void PresentationConnection::Trace(Visitor* visitor) const { … }
const AtomicString& PresentationConnection::state() const { … }
void PresentationConnection::send(const String& message,
ExceptionState& exception_state) { … }
void PresentationConnection::send(DOMArrayBuffer* array_buffer,
ExceptionState& exception_state) { … }
void PresentationConnection::send(
NotShared<DOMArrayBufferView> array_buffer_view,
ExceptionState& exception_state) { … }
void PresentationConnection::send(Blob* data, ExceptionState& exception_state) { … }
void PresentationConnection::DoClose(
mojom::blink::PresentationConnectionCloseReason reason) { … }
bool PresentationConnection::CanSendMessage(ExceptionState& exception_state) { … }
void PresentationConnection::HandleMessageQueue() { … }
String PresentationConnection::binaryType() const { … }
void PresentationConnection::setBinaryType(const String& binary_type) { … }
void PresentationConnection::SendMessageToTargetConnection(
mojom::blink::PresentationConnectionMessagePtr message) { … }
void PresentationConnection::DidReceiveTextMessage(const WebString& message) { … }
void PresentationConnection::DidReceiveBinaryMessage(
base::span<const uint8_t> data) { … }
mojom::blink::PresentationConnectionState PresentationConnection::GetState()
const { … }
void PresentationConnection::close() { … }
void PresentationConnection::terminate() { … }
bool PresentationConnection::Matches(const String& id, const KURL& url) const { … }
void PresentationConnection::DidClose(
mojom::blink::PresentationConnectionCloseReason reason,
const String& message) { … }
void PresentationConnection::DidFinishLoadingBlob(DOMArrayBuffer* buffer) { … }
void PresentationConnection::DidFailLoadingBlob(FileErrorCode error_code) { … }
void PresentationConnection::TearDown() { … }
}