1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

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.
This commit is contained in:
Andreas Kling 2021-01-18 15:06:13 +01:00
parent c99e35485a
commit 9e45594dc8
10 changed files with 176 additions and 2 deletions

View file

@ -198,6 +198,8 @@
#include <LibWeb/Bindings/NodePrototype.h>
#include <LibWeb/Bindings/PerformanceConstructor.h>
#include <LibWeb/Bindings/PerformancePrototype.h>
#include <LibWeb/Bindings/PerformanceTimingConstructor.h>
#include <LibWeb/Bindings/PerformanceTimingPrototype.h>
#include <LibWeb/Bindings/SVGElementConstructor.h>
#include <LibWeb/Bindings/SVGElementPrototype.h>
#include <LibWeb/Bindings/SVGGeometryElementConstructor.h>
@ -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) \

View file

@ -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)

View file

@ -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 <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#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<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"))
, m_impl(impl)
{
}
@ -692,6 +694,8 @@ void generate_constructor_implementation(const IDL::Interface& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#endif
@ -836,12 +840,14 @@ void generate_prototype_implementation(const IDL::Interface& interface)
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
#include <LibWeb/Bindings/ImageDataWrapper.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h>
#include <LibWeb/Bindings/PerformanceTimingWrapper.h>
#include <LibWeb/Bindings/TextWrapper.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/EventListener.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
#include <LibWeb/Origin.h>
#if __has_include(<LibWeb/Bindings/@prototype_base_class@.h>)
@ -855,6 +861,8 @@ void generate_prototype_implementation(const IDL::Interface& interface)
# include <LibWeb/UIEvents/@name@.h>
#elif __has_include(<LibWeb/HighResolutionTime/@name@.h>)
# include <LibWeb/HighResolutionTime/@name@.h>
#elif __has_include(<LibWeb/NavigationTiming/@name@.h>)
# include <LibWeb/NavigationTiming/@name@.h>
#elif __has_include(<LibWeb/SVG/@name@.h>)
# include <LibWeb/SVG/@name@.h>
#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 {

View file

@ -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;

View file

@ -36,6 +36,7 @@ namespace Web::HighResolutionTime {
Performance::Performance(DOM::Window& window)
: DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.document()))
, m_window(window)
, m_timing(make<NavigationTiming::PerformanceTiming>(window))
{
m_timer.start();
}

View file

@ -30,6 +30,7 @@
#include <LibCore/ElapsedTimer.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
namespace Web::HighResolutionTime {
@ -46,6 +47,8 @@ public:
double now() const { return m_timer.elapsed(); }
double time_origin() const;
RefPtr<NavigationTiming::PerformanceTiming> 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<NavigationTiming::PerformanceTiming> m_timing;
};
}

View file

@ -1,4 +1,6 @@
interface Performance : EventTarget {
double now();
readonly attribute double timeOrigin;
readonly attribute PerformanceTiming timing;
};

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* 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 <LibWeb/DOM/Window.h>
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
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();
}
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* 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 <AK/StdLibExtras.h>
#include <LibWeb/Bindings/Wrappable.h>
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;
};
}

View file

@ -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;
};