diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-18 22:05:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-18 22:05:13 +0200 |
commit | 3b11e471bd5e796edd7311bed17c4ca14afc89a3 (patch) | |
tree | 26e5620aa7e6a471b0b99f28a247b76506c4ef04 /Libraries | |
parent | 71007f6ebbfe181472d82cd003698189974c6df2 (diff) | |
download | serenity-3b11e471bd5e796edd7311bed17c4ca14afc89a3.zip |
LibWeb: Allow reloading the current page with location.reload()
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/Bindings/LocationObject.cpp | 9 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/LocationObject.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Window.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Window.h | 1 |
4 files changed, 23 insertions, 0 deletions
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<WindowObject&>(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<Bindings::LocationObject>, const String view->load(new_href); } +void Window::did_call_location_reload(Badge<Bindings::LocationObject>) +{ + 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<Bindings::LocationObject>, const String& new_href); + void did_call_location_reload(Badge<Bindings::LocationObject>); private: explicit Window(Document&); |