Skip to content

Truly independent web browser

1.6 KB
Raw Blame
/*
 * Copyright (c) 2023, Linus Groh <[email protected]>
 * Copyright (c) 2023, Luke Wilde <[email protected]>
 * Copyright (c) 2024, Shannon Booth <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Forward.h>
#include <LibGC/HeapVector.h>
#include <LibGC/Weak.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Scripting/ImportMap.h>

namespace Web::HTML {

// https://whatpr.org/html/9893/webappapis.html#universalglobalscope-mixin
class UniversalGlobalScopeMixin {
public:
    virtual ~UniversalGlobalScopeMixin();

    virtual DOM::EventTarget& this_impl() = 0;
    virtual DOM::EventTarget const& this_impl() const = 0;

    void push_onto_outstanding_rejected_promises_weak_set(GC::Ptr<JS::Promise>);
    bool remove_from_outstanding_rejected_promises_weak_set(GC::Ptr<JS::Promise>);

    void push_onto_about_to_be_notified_rejected_promises_list(GC::Ref<JS::Promise>);
    bool remove_from_about_to_be_notified_rejected_promises_list(GC::Ref<JS::Promise>);

    void notify_about_rejected_promises(Badge<EventLoop>);

    ImportMap& import_map() { return m_import_map; }
    ImportMap const& import_map() const { return m_import_map; }
    void set_import_map(ImportMap const& import_map) { m_import_map = import_map; }

    static WEB_API void set_experimental_interfaces_exposed(bool);
    static WEB_API bool expose_experimental_interfaces();

protected:
    void visit_edges(GC::Cell::Visitor&);

private:
    GC::Ptr<GC::HeapVector<GC::Ref<JS::Promise>>> m_about_to_be_notified_rejected_promises_list;
    Vector<GC::Weak<JS::Promise>> m_outstanding_rejected_promises_weak_set;
    ImportMap m_import_map;
};

}