From 3876875bd819a6f44c92a832dc15af6ebace4850 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 30 Mar 2024 10:04:31 +0000 Subject: [PATCH] LibWeb: Stub out missing cross origin properties on the window object Previously, trying to access the `close`, `closed` or `blur` properties on a cross origin window would cause a crash. --- .../HTML/cross-origin-window-properties.txt | 1 + .../HTML/cross-origin-window-properties.html | 35 +++++++++++++++++++ Userland/Libraries/LibWeb/HTML/Window.cpp | 21 +++++++++++ Userland/Libraries/LibWeb/HTML/Window.h | 3 ++ Userland/Libraries/LibWeb/HTML/Window.idl | 3 ++ 5 files changed, 63 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/HTML/cross-origin-window-properties.txt create mode 100644 Tests/LibWeb/Text/input/HTML/cross-origin-window-properties.html diff --git a/Tests/LibWeb/Text/expected/HTML/cross-origin-window-properties.txt b/Tests/LibWeb/Text/expected/HTML/cross-origin-window-properties.txt new file mode 100644 index 0000000000..3a2d263b04 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/cross-origin-window-properties.txt @@ -0,0 +1 @@ + PASS (didn't crash) diff --git a/Tests/LibWeb/Text/input/HTML/cross-origin-window-properties.html b/Tests/LibWeb/Text/input/HTML/cross-origin-window-properties.html new file mode 100644 index 0000000000..67a0f10d50 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/cross-origin-window-properties.html @@ -0,0 +1,35 @@ + + + + diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index d05553c099..183131131a 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -874,6 +874,21 @@ String Window::status() const return m_status; } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-close +void Window::close() +{ + // FIXME: Implement this properly + dbgln("(STUBBED) Window::close()"); +} + +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-closed +bool Window::closed() const +{ + // FIXME: Implement this properly + dbgln("(STUBBED) Window::closed"); + return false; +} + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status void Window::set_status(String const& status) { @@ -918,6 +933,12 @@ void Window::focus() // indicate to the user that the page is attempting to gain focus. } +// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-blur +void Window::blur() +{ + // The blur() method steps are to do nothing. +} + // https://html.spec.whatwg.org/multipage/window-object.html#dom-frames JS::NonnullGCPtr Window::frames() const { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index ba0a4a1cee..38213cf7c2 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -135,11 +135,14 @@ public: String name() const; void set_name(String const&); String status() const; + void close(); + bool closed() const; void set_status(String const&); [[nodiscard]] JS::NonnullGCPtr location(); JS::NonnullGCPtr history() const; JS::NonnullGCPtr navigation(); void focus(); + void blur(); JS::NonnullGCPtr frames() const; u32 length(); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 9de543783a..a0202afdcd 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -24,11 +24,14 @@ interface Window : EventTarget { [LegacyUnforgeable] readonly attribute Document document; attribute DOMString name; attribute DOMString status; + undefined close(); + readonly attribute boolean closed; [PutForwards=href, LegacyUnforgeable] readonly attribute Location location; readonly attribute History history; readonly attribute Navigation navigation; readonly attribute CustomElementRegistry customElements; undefined focus(); + undefined blur(); // other browsing contexts [Replaceable] readonly attribute WindowProxy frames;