mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-13 03:29:49 +00:00
LibWeb: Use proper enums in WorkerOptions dictionary
This commit is contained in:
parent
a0c07d1bb2
commit
1d43d5b086
Notes:
github-actions[bot]
2024-09-20 21:42:39 +00:00
Author: https://github.com/ADKaster
Commit: 1d43d5b086
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1404
Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 20 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
|||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/AbstractWorker.idl>
|
||||
#import <HTML/MessagePort.idl>
|
||||
#import <Fetch/Request.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/#worker
|
||||
[Exposed=(Window,DedicatedWorker,SharedWorker)]
|
||||
|
@ -18,9 +19,11 @@ interface Worker : EventTarget {
|
|||
};
|
||||
|
||||
dictionary WorkerOptions {
|
||||
USVString type = "classic";
|
||||
USVString credentials = "same-origin";
|
||||
WorkerType type = "classic";
|
||||
RequestCredentials credentials = "same-origin";
|
||||
DOMString name = "";
|
||||
};
|
||||
|
||||
enum WorkerType { "classic", "module" };
|
||||
|
||||
Worker includes AbstractWorker;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/RequestPrototype.h>
|
||||
#include <LibWeb/Bindings/WorkerPrototype.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/MessagePort.h>
|
||||
#include <LibWeb/Worker/WebWorkerClient.h>
|
||||
|
@ -13,8 +15,8 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
struct WorkerOptions {
|
||||
String type { "classic"_string };
|
||||
String credentials { "same-origin"_string };
|
||||
Bindings::WorkerType type { Bindings::WorkerType::Classic };
|
||||
Bindings::RequestCredentials credentials { Bindings::RequestCredentials::SameOrigin };
|
||||
String name { String {} };
|
||||
};
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
#include <LibIPC/File.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
#include <LibWeb/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
|
||||
#include <LibWeb/Bindings/WorkerPrototype.h>
|
||||
|
||||
endpoint WebWorkerServer {
|
||||
|
||||
start_dedicated_worker(URL::URL url, String type, String credentials, String name, Web::HTML::TransferDataHolder message_port, Web::HTML::SerializedEnvironmentSettingsObject outside_settings) =|
|
||||
start_dedicated_worker(URL::URL url, Web::Bindings::WorkerType type, Web::Bindings::RequestCredentials credentials, String name, Web::HTML::TransferDataHolder message_port, Web::HTML::SerializedEnvironmentSettingsObject outside_settings) =|
|
||||
|
||||
close_worker() =|
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ Web::Page const& ConnectionFromClient::page() const
|
|||
return m_page_host->page();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::start_dedicated_worker(URL::URL const& url, String const& type, String const&, String const& name, Web::HTML::TransferDataHolder const& implicit_port, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings)
|
||||
void ConnectionFromClient::start_dedicated_worker(URL::URL const& url, Web::Bindings::WorkerType const& type, Web::Bindings::RequestCredentials const&, String const& name, Web::HTML::TransferDataHolder const& implicit_port, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings)
|
||||
{
|
||||
m_worker_host = make_ref_counted<DedicatedWorkerHost>(url, type, name);
|
||||
// FIXME: Yikes, const_cast to move? Feels like a LibIPC bug.
|
||||
|
|
|
@ -41,7 +41,7 @@ private:
|
|||
Web::Page& page();
|
||||
Web::Page const& page() const;
|
||||
|
||||
virtual void start_dedicated_worker(URL::URL const& url, String const& type, String const&, String const& name, Web::HTML::TransferDataHolder const&, Web::HTML::SerializedEnvironmentSettingsObject const&) override;
|
||||
virtual void start_dedicated_worker(URL::URL const& url, Web::Bindings::WorkerType const& type, Web::Bindings::RequestCredentials const& credentials, String const& name, Web::HTML::TransferDataHolder const&, Web::HTML::SerializedEnvironmentSettingsObject const&) override;
|
||||
virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
|
||||
|
||||
JS::Handle<PageHost> m_page_host;
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
namespace WebWorker {
|
||||
|
||||
DedicatedWorkerHost::DedicatedWorkerHost(URL::URL url, String type, String name)
|
||||
DedicatedWorkerHost::DedicatedWorkerHost(URL::URL url, Web::Bindings::WorkerType type, String name)
|
||||
: m_url(move(url))
|
||||
, m_type(move(type))
|
||||
, m_type(type)
|
||||
, m_name(move(name))
|
||||
{
|
||||
}
|
||||
|
@ -219,14 +219,14 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans
|
|||
// and with onComplete and performFetch as defined below.
|
||||
// module: Fetch a module worker script graph given url, outside settings, destination, the value of the credentials member of options, inside settings,
|
||||
// and with onComplete and performFetch as defined below.
|
||||
if (m_type == "classic"sv) {
|
||||
if (m_type == Web::Bindings::WorkerType::Classic) {
|
||||
if (auto err = Web::HTML::fetch_classic_worker_script(m_url, outside_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) {
|
||||
dbgln("Failed to run worker script");
|
||||
// FIXME: Abort the worker properly
|
||||
TODO();
|
||||
}
|
||||
} else {
|
||||
VERIFY(m_type == "module"sv);
|
||||
VERIFY(m_type == Web::Bindings::WorkerType::Module);
|
||||
// FIXME: Pass credentials
|
||||
if (auto err = Web::HTML::fetch_module_worker_script_graph(m_url, outside_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) {
|
||||
dbgln("Failed to run worker script");
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Bindings/WorkerPrototype.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
|
@ -17,7 +18,7 @@ namespace WebWorker {
|
|||
|
||||
class DedicatedWorkerHost : public RefCounted<DedicatedWorkerHost> {
|
||||
public:
|
||||
explicit DedicatedWorkerHost(URL::URL url, String type, String name);
|
||||
explicit DedicatedWorkerHost(URL::URL url, Web::Bindings::WorkerType type, String name);
|
||||
~DedicatedWorkerHost();
|
||||
|
||||
void run(JS::NonnullGCPtr<Web::Page>, Web::HTML::TransferDataHolder message_port_data, Web::HTML::SerializedEnvironmentSettingsObject const&);
|
||||
|
@ -26,7 +27,7 @@ private:
|
|||
JS::Handle<Web::HTML::WorkerDebugConsoleClient> m_console;
|
||||
|
||||
URL::URL m_url;
|
||||
String m_type;
|
||||
Web::Bindings::WorkerType m_type;
|
||||
String m_name;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue