summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-21 00:24:02 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-21 11:51:17 +0200
commitd4fc1367f6eb0ef463fd6e5676b2c852c7c73275 (patch)
treebfc65c3c5f85a8b28ebfa9ff5a9e34fb312d98d8
parent270de12d5900f17c98bc9349ddc3f7fa6d9ce174 (diff)
downloadserenity-d4fc1367f6eb0ef463fd6e5676b2c852c7c73275.zip
LibWeb: Save document load timing when creating browsing context
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp12
-rw-r--r--Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp19
-rw-r--r--Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h14
4 files changed, 43 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index bf2ba79cb4..a3de5c4cb4 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -269,6 +269,7 @@ set(SOURCES
HTML/WorkerGlobalScope.cpp
HTML/WorkerLocation.cpp
HTML/WorkerNavigator.cpp
+ HighResolutionTime/CoarsenTime.cpp
HighResolutionTime/Performance.cpp
Infra/ByteSequences.cpp
IntersectionObserver/IntersectionObserver.cpp
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
index 0e5cfd934b..038f6dbdbd 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
@@ -19,6 +19,7 @@
#include <LibWeb/HTML/SandboxingFlagSet.h>
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
#include <LibWeb/HTML/Window.h>
+#include <LibWeb/HighResolutionTime/CoarsenTime.h>
#include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/TextNode.h>
@@ -158,8 +159,12 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
top_level_creation_url,
top_level_origin);
- // FIXME: 12. Let loadTimingInfo be a new document load timing info with its navigation start time set to the result of calling
- // coarsen time with unsafeContextCreationTime and the new environment settings object's cross-origin isolated capability.
+ // 12. Let loadTimingInfo be a new document load timing info with its navigation start time set to the result of calling
+ // coarsen time with unsafeContextCreationTime and the new environment settings object's cross-origin isolated capability.
+ auto load_timing_info = DOM::DocumentLoadTimingInfo();
+ load_timing_info.navigation_start_time = HighResolutionTime::coarsen_time(
+ unsafe_context_creation_time,
+ verify_cast<WindowEnvironmentSettingsObject>(window->realm().host_defined())->cross_origin_isolated_capability() == CanUseCrossOriginIsolatedAPIs::Yes);
// 13. Let coop be a new cross-origin opener policy.
auto coop = CrossOriginOpenerPolicy {};
@@ -179,7 +184,7 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
// FIXME: active sandboxing flag set is sandboxFlags,
// FIXME: permissions policy is permissionsPolicy,
// cross-origin opener policy is coop,
- // FIXME: load timing info is loadTimingInfo,
+ // load timing info is loadTimingInfo,
// FIXME: navigation id is null,
// and which is ready for post-load tasks.
auto document = DOM::Document::create(*window);
@@ -193,6 +198,7 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
document->set_origin(origin);
document->set_url(AK::URL("about:blank"));
document->set_cross_origin_opener_policy(coop);
+ document->set_load_timing_info(load_timing_info);
document->set_ready_for_post_load_tasks(true);
// FIXME: 16. Assert: document's URL and document's relevant settings object's creation URL are about:blank.
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp
new file mode 100644
index 0000000000..0d5739e629
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/HighResolutionTime/CoarsenTime.h>
+
+namespace Web::HighResolutionTime {
+
+// https://w3c.github.io/hr-time/#dfn-coarsen-time
+double coarsen_time(double timestamp, bool cross_origin_isolated_capability)
+{
+ // FIXME: Implement this.
+ (void)cross_origin_isolated_capability;
+ return timestamp;
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h
new file mode 100644
index 0000000000..91fa541c46
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HighResolutionTime/CoarsenTime.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace Web::HighResolutionTime {
+
+// https://w3c.github.io/hr-time/#dfn-coarsen-time
+double coarsen_time(double timestamp, bool cross_origin_isolated_capability = false);
+
+}