mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +00:00
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.
This commit is contained in:
parent
558fef237c
commit
3876875bd8
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/tcl3
Commit: 3876875bd8
Pull-request: https://github.com/SerenityOS/serenity/pull/23771
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/kalenikaliaksandr
Reviewed-by: https://github.com/shannonbooth
5 changed files with 63 additions and 0 deletions
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't crash)
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<iframe name="testFrame"></iframe>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
const frame = document.querySelector("iframe");
|
||||||
|
// Taken from: https://html.spec.whatwg.org/multipage/nav-history-apis.html#crossoriginproperties-(-o-)
|
||||||
|
const crossOriginWindowProperties = [
|
||||||
|
"window",
|
||||||
|
"self",
|
||||||
|
"location",
|
||||||
|
"close",
|
||||||
|
"closed",
|
||||||
|
"focus",
|
||||||
|
"blur",
|
||||||
|
"frames",
|
||||||
|
"length",
|
||||||
|
"top",
|
||||||
|
"opener",
|
||||||
|
"parent",
|
||||||
|
"postMessage",
|
||||||
|
];
|
||||||
|
frame.onload = () => {
|
||||||
|
for (const property of crossOriginWindowProperties) {
|
||||||
|
const value = frame.contentWindow[property];
|
||||||
|
}
|
||||||
|
println("PASS (didn't crash)");
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: about:newtab is being used here, as it is a simple way to load a cross origin URL using local files.
|
||||||
|
// This should be replaced with something less fragile if it becomes available.
|
||||||
|
window.open("about:newtab", "testFrame");
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -874,6 +874,21 @@ String Window::status() const
|
||||||
return m_status;
|
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
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status
|
||||||
void Window::set_status(String const& 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.
|
// 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
|
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
|
||||||
JS::NonnullGCPtr<WindowProxy> Window::frames() const
|
JS::NonnullGCPtr<WindowProxy> Window::frames() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,11 +135,14 @@ public:
|
||||||
String name() const;
|
String name() const;
|
||||||
void set_name(String const&);
|
void set_name(String const&);
|
||||||
String status() const;
|
String status() const;
|
||||||
|
void close();
|
||||||
|
bool closed() const;
|
||||||
void set_status(String const&);
|
void set_status(String const&);
|
||||||
[[nodiscard]] JS::NonnullGCPtr<Location> location();
|
[[nodiscard]] JS::NonnullGCPtr<Location> location();
|
||||||
JS::NonnullGCPtr<History> history() const;
|
JS::NonnullGCPtr<History> history() const;
|
||||||
JS::NonnullGCPtr<Navigation> navigation();
|
JS::NonnullGCPtr<Navigation> navigation();
|
||||||
void focus();
|
void focus();
|
||||||
|
void blur();
|
||||||
|
|
||||||
JS::NonnullGCPtr<WindowProxy> frames() const;
|
JS::NonnullGCPtr<WindowProxy> frames() const;
|
||||||
u32 length();
|
u32 length();
|
||||||
|
|
|
@ -24,11 +24,14 @@ interface Window : EventTarget {
|
||||||
[LegacyUnforgeable] readonly attribute Document document;
|
[LegacyUnforgeable] readonly attribute Document document;
|
||||||
attribute DOMString name;
|
attribute DOMString name;
|
||||||
attribute DOMString status;
|
attribute DOMString status;
|
||||||
|
undefined close();
|
||||||
|
readonly attribute boolean closed;
|
||||||
[PutForwards=href, LegacyUnforgeable] readonly attribute Location location;
|
[PutForwards=href, LegacyUnforgeable] readonly attribute Location location;
|
||||||
readonly attribute History history;
|
readonly attribute History history;
|
||||||
readonly attribute Navigation navigation;
|
readonly attribute Navigation navigation;
|
||||||
readonly attribute CustomElementRegistry customElements;
|
readonly attribute CustomElementRegistry customElements;
|
||||||
undefined focus();
|
undefined focus();
|
||||||
|
undefined blur();
|
||||||
|
|
||||||
// other browsing contexts
|
// other browsing contexts
|
||||||
[Replaceable] readonly attribute WindowProxy frames;
|
[Replaceable] readonly attribute WindowProxy frames;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue