소스 검색

LibWeb: Implement 'Queue a fetch task' AO

Linus Groh 2 년 전
부모
커밋
14e722617c

+ 1 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -140,6 +140,7 @@ set(SOURCES
     Fetch/Infrastructure/MimeTypeBlocking.cpp
     Fetch/Infrastructure/NoSniffBlocking.cpp
     Fetch/Infrastructure/PortBlocking.cpp
+    Fetch/Infrastructure/Task.cpp
     Fetch/Infrastructure/URL.cpp
     Fetch/Request.cpp
     Fetch/Response.cpp

+ 21 - 0
Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Fetch/Infrastructure/Task.h>
+#include <LibWeb/HTML/EventLoop/EventLoop.h>
+
+namespace Web::Fetch::Infrastructure {
+
+// https://fetch.spec.whatwg.org/#queue-a-fetch-task
+void queue_fetch_task(JS::Object& task_destination, JS::SafeFunction<void()> algorithm)
+{
+    // FIXME: 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination.
+
+    // 2. Otherwise, queue a global task on the networking task source with taskDestination and algorithm.
+    HTML::queue_global_task(HTML::Task::Source::Networking, task_destination, move(algorithm));
+}
+
+}

+ 16 - 0
Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.h

@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibJS/Forward.h>
+#include <LibJS/SafeFunction.h>
+
+namespace Web::Fetch::Infrastructure {
+
+void queue_fetch_task(JS::Object&, JS::SafeFunction<void()>);
+
+}