diff --git a/Base/home/anon/www/location.html b/Base/home/anon/www/location.html index fd04896897..d7e08fe5d4 100644 --- a/Base/home/anon/www/location.html +++ b/Base/home/anon/www/location.html @@ -3,12 +3,14 @@ window.location test

-    
Click me to navigate away!
+
Click me to set location.href!
+
Click me to call location.reload()!
diff --git a/Libraries/LibWeb/Bindings/LocationObject.cpp b/Libraries/LibWeb/Bindings/LocationObject.cpp index 472fb7bc92..0b3b3df9b2 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -45,6 +45,8 @@ LocationObject::LocationObject() put_native_property("hash", hash_getter, nullptr); put_native_property("search", search_getter, nullptr); put_native_property("protocol", protocol_getter, nullptr); + + put_native_function("reload", reload); } LocationObject::~LocationObject() @@ -110,6 +112,13 @@ JS::Value LocationObject::protocol_getter(JS::Interpreter& interpreter) return JS::js_string(interpreter, builder.to_string()); } +JS::Value LocationObject::reload(JS::Interpreter& interpreter) +{ + auto& window = static_cast(interpreter.global_object()); + window.impl().did_call_location_reload({}); + return JS::js_undefined(); +} + } } diff --git a/Libraries/LibWeb/Bindings/LocationObject.h b/Libraries/LibWeb/Bindings/LocationObject.h index 4cabdf88e3..3e253913fe 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Libraries/LibWeb/Bindings/LocationObject.h @@ -40,6 +40,8 @@ public: private: virtual const char* class_name() const override { return "LocationObject"; } + static JS::Value reload(JS::Interpreter&); + static JS::Value href_getter(JS::Interpreter&); static void href_setter(JS::Interpreter&, JS::Value); diff --git a/Libraries/LibWeb/DOM/Window.cpp b/Libraries/LibWeb/DOM/Window.cpp index 01bf4ca225..898e466bc0 100644 --- a/Libraries/LibWeb/DOM/Window.cpp +++ b/Libraries/LibWeb/DOM/Window.cpp @@ -119,4 +119,15 @@ void Window::did_set_location_href(Badge, const String view->load(new_href); } +void Window::did_call_location_reload(Badge) +{ + auto* frame = document().frame(); + if (!frame) + return; + auto* view = frame->html_view(); + if (!view) + return; + view->reload(); +} + } diff --git a/Libraries/LibWeb/DOM/Window.h b/Libraries/LibWeb/DOM/Window.h index 77214a7de6..0428dc6cfc 100644 --- a/Libraries/LibWeb/DOM/Window.h +++ b/Libraries/LibWeb/DOM/Window.h @@ -50,6 +50,7 @@ public: void set_timeout(JS::Function&, i32); void did_set_location_href(Badge, const String& new_href); + void did_call_location_reload(Badge); private: explicit Window(Document&);