From 9e45594dc83d75e3bec90e5e519e8473f808ec85 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Jan 2021 15:06:13 +0100 Subject: LibWeb: Stub out the PerformanceTiming object from Navigation Timing Just have all the timing functions return 0 for now. We can now run the Shynet JS on https://linus.dev/ although the XHR is rejected by our same-origin policy. --- .../Libraries/LibWeb/Bindings/WindowObjectHelper.h | 3 + Userland/Libraries/LibWeb/CMakeLists.txt | 2 + .../LibWeb/CodeGenerators/WrapperGenerator.cpp | 13 +++- Userland/Libraries/LibWeb/Forward.h | 5 ++ .../LibWeb/HighResolutionTime/Performance.cpp | 1 + .../LibWeb/HighResolutionTime/Performance.h | 5 ++ .../LibWeb/HighResolutionTime/Performance.idl | 2 + .../LibWeb/NavigationTiming/PerformanceTiming.cpp | 51 ++++++++++++++++ .../LibWeb/NavigationTiming/PerformanceTiming.h | 71 ++++++++++++++++++++++ .../LibWeb/NavigationTiming/PerformanceTiming.idl | 25 ++++++++ 10 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp create mode 100644 Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h create mode 100644 Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index b37afe1894..94b115ef19 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -198,6 +198,8 @@ #include #include #include +#include +#include #include #include #include @@ -308,6 +310,7 @@ ADD_WINDOW_OBJECT_INTERFACE(MouseEvent) \ ADD_WINDOW_OBJECT_INTERFACE(Node) \ ADD_WINDOW_OBJECT_INTERFACE(Performance) \ + ADD_WINDOW_OBJECT_INTERFACE(PerformanceTiming) \ ADD_WINDOW_OBJECT_INTERFACE(ShadowRoot) \ ADD_WINDOW_OBJECT_INTERFACE(SubmitEvent) \ ADD_WINDOW_OBJECT_INTERFACE(SVGElement) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7e97391a76..eef44ab9a1 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -185,6 +185,7 @@ set(SOURCES Loader/Resource.cpp Loader/ResourceLoader.cpp Namespace.cpp + NavigationTiming/PerformanceTiming.cpp OutOfProcessWebView.cpp Page/EventHandler.cpp Page/EditEventHandler.cpp @@ -365,6 +366,7 @@ libweb_js_wrapper(HTML/HTMLVideoElement) libweb_js_wrapper(HTML/ImageData) libweb_js_wrapper(HTML/SubmitEvent) libweb_js_wrapper(HighResolutionTime/Performance) +libweb_js_wrapper(NavigationTiming/PerformanceTiming) libweb_js_wrapper(SVG/SVGElement) libweb_js_wrapper(SVG/SVGGeometryElement) libweb_js_wrapper(SVG/SVGGraphicsElement) diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 7578776aec..d50186e88a 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -363,7 +363,7 @@ int main(int argc, char** argv) return 1; } - if (namespace_.is_one_of("DOM", "HTML", "UIEvents", "HighResolutionTime", "SVG")) { + if (namespace_.is_one_of("DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG")) { StringBuilder builder; builder.append(namespace_); builder.append("::"); @@ -474,6 +474,8 @@ static void generate_header(const IDL::Interface& interface) # include #elif __has_include() # include +#elif __has_include() +# include #elif __has_include() # include #endif @@ -586,7 +588,7 @@ namespace Web::Bindings { if (interface.wrapper_base_class == "Wrapper") { generator.append(R"~~~( @wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl) - : Wrapper(*global_object.object_prototype()) + : Wrapper(static_cast(global_object).ensure_web_prototype<@prototype_class@>("@name@")) , m_impl(impl) { } @@ -692,6 +694,8 @@ void generate_constructor_implementation(const IDL::Interface& interface) # include #elif __has_include() # include +#elif __has_include() +# include #elif __has_include() # include #endif @@ -836,12 +840,14 @@ void generate_prototype_implementation(const IDL::Interface& interface) #include #include #include +#include #include #include #include #include #include #include +#include #include #if __has_include() @@ -855,6 +861,8 @@ void generate_prototype_implementation(const IDL::Interface& interface) # include #elif __has_include() # include +#elif __has_include() +# include #elif __has_include() # include #endif @@ -862,6 +870,7 @@ void generate_prototype_implementation(const IDL::Interface& interface) // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. using namespace Web::DOM; using namespace Web::HTML; +using namespace Web::NavigationTiming; namespace Web::Bindings { diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 445b7222fa..7c50a1a759 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -142,6 +142,10 @@ namespace Web::HighResolutionTime { class Performance; } +namespace Web::NavigationTiming { +class PerformanceTiming; +} + namespace Web::SVG { class SVGElement; class SVGGeometryElement; @@ -274,6 +278,7 @@ class ImageDataWrapper; class LocationObject; class MouseEventWrapper; class NodeWrapper; +class PerformanceTimingWrapper; class PerformanceWrapper; class ScriptExecutionContext; class SubmitEventWrapper; diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp index 1de64d81fb..ffafa8d2b1 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp @@ -36,6 +36,7 @@ namespace Web::HighResolutionTime { Performance::Performance(DOM::Window& window) : DOM::EventTarget(static_cast(window.document())) , m_window(window) + , m_timing(make(window)) { m_timer.start(); } diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h index 7848beedcc..c51d4ad080 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace Web::HighResolutionTime { @@ -46,6 +47,8 @@ public: double now() const { return m_timer.elapsed(); } double time_origin() const; + RefPtr timing() { return *m_timing; } + virtual void ref_event_target() override; virtual void unref_event_target() override; @@ -55,6 +58,8 @@ public: private: DOM::Window& m_window; Core::ElapsedTimer m_timer; + + OwnPtr m_timing; }; } diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.idl b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.idl index 889760a08a..278bffde4b 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.idl +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.idl @@ -1,4 +1,6 @@ interface Performance : EventTarget { double now(); readonly attribute double timeOrigin; + + readonly attribute PerformanceTiming timing; }; diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp new file mode 100644 index 0000000000..b5b8efbf41 --- /dev/null +++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Web::NavigationTiming { + +PerformanceTiming::PerformanceTiming(DOM::Window& window) + : m_window(window) +{ +} + +PerformanceTiming::~PerformanceTiming() +{ +} + +void PerformanceTiming::ref() +{ + m_window.ref(); +} + +void PerformanceTiming::unref() +{ + m_window.unref(); +} + +} diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h new file mode 100644 index 0000000000..1460ccee50 --- /dev/null +++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include + +namespace Web::NavigationTiming { + +class PerformanceTiming final : public Bindings::Wrappable { +public: + using WrapperType = Bindings::PerformanceTimingWrapper; + using AllowOwnPtr = AK::TrueType; + + explicit PerformanceTiming(DOM::Window&); + ~PerformanceTiming(); + + void ref(); + void unref(); + + u32 navigation_start() { return 0; } + u32 unload_event_start() { return 0; } + u32 unload_event_end() { return 0; } + u32 redirect_start() { return 0; } + u32 redirect_end() { return 0; } + u32 fetch_start() { return 0; } + u32 domain_lookup_start() { return 0; } + u32 domain_lookup_end() { return 0; } + u32 connect_start() { return 0; } + u32 connect_end() { return 0; } + u32 secure_connection_start() { return 0; } + u32 request_start() { return 0; } + u32 response_start() { return 0; } + u32 response_end() { return 0; } + u32 dom_loading() { return 0; } + u32 dom_interactive() { return 0; } + u32 dom_content_loaded_event_start() { return 0; } + u32 dom_content_loaded_event_end() { return 0; } + u32 dom_complete() { return 0; } + u32 load_event_start() { return 0; } + u32 load_event_end() { return 0; } + +private: + DOM::Window& m_window; +}; + +} diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl new file mode 100644 index 0000000000..87c87c64a3 --- /dev/null +++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl @@ -0,0 +1,25 @@ +interface PerformanceTiming { + + readonly attribute unsigned long navigationStart; + readonly attribute unsigned long unloadEventStart; + readonly attribute unsigned long unloadEventEnd; + readonly attribute unsigned long redirectStart; + readonly attribute unsigned long redirectEnd; + readonly attribute unsigned long fetchStart; + readonly attribute unsigned long domainLookupStart; + readonly attribute unsigned long domainLookupEnd; + readonly attribute unsigned long connectStart; + readonly attribute unsigned long connectEnd; + readonly attribute unsigned long secureConnectionStart; + readonly attribute unsigned long requestStart; + readonly attribute unsigned long responseStart; + readonly attribute unsigned long responseEnd; + readonly attribute unsigned long domLoading; + readonly attribute unsigned long domInteractive; + readonly attribute unsigned long domContentLoadedEventStart; + readonly attribute unsigned long domContentLoadedEventEnd; + readonly attribute unsigned long domComplete; + readonly attribute unsigned long loadEventStart; + readonly attribute unsigned long loadEventEnd; + +}; -- cgit v1.2.3