ladybird/Libraries/LibWeb/Bindings/Transferable.h
Timothy Flynn 64abc6101d LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder
and decoder to serialize JS values. It also used a u32 buffer under the
hood, which made using its structures a bit awkward. We had previously
worked around its data structures in transferable streams, which nested
transfers of MessagePort instances. We basically had to add hooks into
the MessagePort to route to the correct transfer receiving steps, and
we could not invoke the correct AOs directly as the spec dictates.

We now use IPC mechanics to encode and decode data. This works because,
although we are encoding JS values, we are only ultimately encoding
primitive and basic AK types. The resulting data structures actually
enforce that we implement transferable streams exactly as the spec is
worded (I had planned to do that in a separate commit, but the fallout
of this patch actually required that change).
2025-07-18 10:09:02 -04:00

36 lines
1,019 B
C++

/*
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibIPC/Forward.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::Bindings {
// https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects
class Transferable {
public:
virtual ~Transferable() = default;
// NOTE: It is an error to call Base::transfer_steps in your impl
virtual WebIDL::ExceptionOr<void> transfer_steps(HTML::TransferDataEncoder&) = 0;
// NOTE: It is an error to call Base::transfer_receiving_steps in your impl
virtual WebIDL::ExceptionOr<void> transfer_receiving_steps(HTML::TransferDataDecoder&) = 0;
virtual HTML::TransferType primary_interface() const = 0;
bool is_detached() const { return m_detached; }
void set_detached(bool b) { m_detached = b; }
private:
// https://html.spec.whatwg.org/multipage/structured-data.html#detached
bool m_detached = false;
};
}