Skip to content

Truly independent web browser

1.6 KB
Raw Blame
/*
 * Copyright (c) 2026-present, the Ladybird developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/String.h>
#include <AK/Variant.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibIPC/Forward.h>
#include <LibURL/BlobURLEntry.h>
#include <LibURL/Origin.h>
#include <LibWebCommon/Export.h>
#include <LibWebCommon/HTML/SerializedPolicyContainer.h>

namespace Web::FileAPI {

// https://w3c.github.io/FileAPI/#blob-url-entry
struct SerializedBlobURLEntry {
    struct Blob {
        URL::BlobURLEntry::Token token { 0 };
        String type;
        Core::AnonymousBuffer data;
    };

    struct MediaSource { };

    using Object = Variant<Blob, MediaSource>;

    Object object;
    URL::Origin origin;

    // The policy container of the entry's environment.
    HTML::SerializedPolicyContainer environment_policy_container;
};

class WEBCOMMON_API BlobURLObject final : public URL::BlobURLEntry::OpaqueObject {
public:
    static NonnullRefPtr<BlobURLObject> create(String type, Core::AnonymousBuffer data)
    {
        return adopt_ref(*new BlobURLObject(move(type), move(data)));
    }

    String const& type() const { return m_type; }
    Core::AnonymousBuffer const& data() const { return m_data; }

private:
    BlobURLObject(String type, Core::AnonymousBuffer data)
        : m_type(move(type))
        , m_data(move(data))
    {
    }

    String m_type;
    Core::AnonymousBuffer m_data;
};

}

namespace IPC {

template<>
WEBCOMMON_API ErrorOr<void> encode(Encoder&, Web::FileAPI::SerializedBlobURLEntry const&);

template<>
WEBCOMMON_API ErrorOr<Web::FileAPI::SerializedBlobURLEntry> decode(Decoder&);

}