diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 6cd3843904..0b406511b8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3114,6 +3114,7 @@ using namespace Web::UIEvents; using namespace Web::URL; using namespace Web::XHR; using namespace Web::WebAssembly; +using namespace Web::WebAudio; using namespace Web::WebGL; using namespace Web::WebIDL; @@ -3330,6 +3331,7 @@ using namespace Web::UserTiming; using namespace Web::URL; using namespace Web::XHR; using namespace Web::WebAssembly; +using namespace Web::WebAudio; using namespace Web::WebGL; using namespace Web::WebIDL; @@ -3713,6 +3715,7 @@ using namespace Web::UserTiming; using namespace Web::WebSockets; using namespace Web::XHR; using namespace Web::WebAssembly; +using namespace Web::WebAudio; using namespace Web::WebGL; using namespace Web::WebIDL; @@ -3843,6 +3846,7 @@ using namespace Web::XHR; using namespace Web::UIEvents; using namespace Web::URL; using namespace Web::UserTiming; +using namespace Web::WebAudio; using namespace Web::WebGL; using namespace Web::WebIDL; @@ -3994,6 +3998,7 @@ using namespace Web::SVG; using namespace Web::UIEvents; using namespace Web::URL; using namespace Web::UserTiming; +using namespace Web::WebAudio; using namespace Web::WebSockets; using namespace Web::XHR; using namespace Web::WebGL; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h index 19593e63f5..6fd5580dfd 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/Namespaces.h @@ -31,6 +31,7 @@ static constexpr Array libweb_interface_namespaces = { "Selection"sv, "UIEvents"sv, "URL"sv, + "WebAudio"sv, "WebGL"sv, "WebIDL"sv, "WebSockets"sv, diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 0fefdb1a33..6727d24d10 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -540,6 +540,8 @@ set(SOURCES WebAssembly/Module.cpp WebAssembly/Table.cpp WebAssembly/WebAssembly.cpp + WebAudio/AudioContext.cpp + WebAudio/BaseAudioContext.cpp WebDriver/Capabilities.cpp WebDriver/Client.cpp WebDriver/Contexts.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index b7941fd62a..ae77031791 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -577,6 +577,11 @@ class Module; class Table; } +namespace Web::WebAudio { +class AudioContext; +class BaseAudioContext; +} + namespace Web::WebGL { class WebGLContextEvent; class WebGLRenderingContext; diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp new file mode 100644 index 0000000000..1be57a3983 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::WebAudio { + +// https://webaudio.github.io/web-audio-api/#dom-audiocontext-audiocontext +WebIDL::ExceptionOr> AudioContext::construct_impl(JS::Realm& realm) +{ + dbgln("(STUBBED) new AudioContext()"); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm)); +} + +AudioContext::AudioContext(JS::Realm& realm) + : BaseAudioContext(realm) +{ +} + +AudioContext::~AudioContext() = default; + +JS::ThrowCompletionOr AudioContext::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "AudioContext")); + + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioContext.h b/Userland/Libraries/LibWeb/WebAudio/AudioContext.h new file mode 100644 index 0000000000..a0fc18acf3 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/AudioContext.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::WebAudio { + +// https://webaudio.github.io/web-audio-api/#AudioContext +class AudioContext final : public BaseAudioContext { + WEB_PLATFORM_OBJECT(AudioContext, BaseAudioContext); + +public: + static WebIDL::ExceptionOr> construct_impl(JS::Realm&); + + virtual ~AudioContext() override; + +private: + explicit AudioContext(JS::Realm&); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioContext.idl b/Userland/Libraries/LibWeb/WebAudio/AudioContext.idl new file mode 100644 index 0000000000..b3a41552de --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/AudioContext.idl @@ -0,0 +1,8 @@ +#import + +// https://webaudio.github.io/web-audio-api/#AudioContext +[Exposed=Window] +interface AudioContext : BaseAudioContext { + // FIXME: Should be constructor (optional AudioContextOptions contextOptions = {}); + constructor(); +}; diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp new file mode 100644 index 0000000000..02b8a119f0 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::WebAudio { + +BaseAudioContext::BaseAudioContext(JS::Realm& realm) + : DOM::EventTarget(realm) +{ +} + +BaseAudioContext::~BaseAudioContext() = default; + +JS::ThrowCompletionOr BaseAudioContext::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "BaseAudioContext")); + + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h new file mode 100644 index 0000000000..6b6365a4a0 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::WebAudio { + +// https://webaudio.github.io/web-audio-api/#BaseAudioContext +class BaseAudioContext : public DOM::EventTarget { + WEB_PLATFORM_OBJECT(BaseAudioContext, DOM::EventTarget); + +public: + virtual ~BaseAudioContext() override; + +protected: + explicit BaseAudioContext(JS::Realm&); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl new file mode 100644 index 0000000000..a246460979 --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl @@ -0,0 +1,6 @@ +#import + +// https://webaudio.github.io/web-audio-api/#BaseAudioContext +[Exposed=Window] +interface BaseAudioContext : EventTarget { +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 9d6166dbe7..69da343304 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -227,6 +227,8 @@ libweb_js_bindings(WebAssembly/Memory) libweb_js_bindings(WebAssembly/Module) libweb_js_bindings(WebAssembly/Table) libweb_js_bindings(WebAssembly/WebAssembly NAMESPACE) +libweb_js_bindings(WebAudio/AudioContext) +libweb_js_bindings(WebAudio/BaseAudioContext) libweb_js_bindings(WebGL/WebGLContextEvent) libweb_js_bindings(WebGL/WebGLRenderingContext) libweb_js_bindings(WebIDL/DOMException)