diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-08 21:18:41 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-08 21:46:43 +0200 |
commit | 4036f15728b50d0df2eed1b8264282eb28aff8c8 (patch) | |
tree | f7c81c9ee953f51c4224f7760f2743024e3a34e2 /Libraries/LibWeb | |
parent | 4ffac713b961e3e96f271877ae4d65f6d2d48680 (diff) | |
download | serenity-4036f15728b50d0df2eed1b8264282eb28aff8c8.zip |
LibWeb: Support relative URL's in XMLHttpRequest
In order to complete a relative URL, we need a Document. Fix this by
giving XMLHttpRequest a pointer to its window object. Then we can go
from the window to the document, and then we're home free. :^)
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/XMLHttpRequest.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/XMLHttpRequest.h | 6 |
3 files changed, 11 insertions, 5 deletions
diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp index e4d7b9238b..9f8bb9131f 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestConstructor.cpp @@ -50,7 +50,8 @@ JS::Value XMLHttpRequestConstructor::call(JS::Interpreter& interpreter) JS::Value XMLHttpRequestConstructor::construct(JS::Interpreter& interpreter) { - return interpreter.heap().allocate<XMLHttpRequestWrapper>(XMLHttpRequest::create()); + auto& window = static_cast<WindowObject&>(interpreter.global_object()); + return interpreter.heap().allocate<XMLHttpRequestWrapper>(XMLHttpRequest::create(window.impl())); } } diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp index d28ad8935d..82caf5b71b 100644 --- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp @@ -28,14 +28,17 @@ #include <LibJS/Runtime/Function.h> #include <LibWeb/Bindings/EventWrapper.h> #include <LibWeb/Bindings/XMLHttpRequestWrapper.h> +#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/EventListener.h> +#include <LibWeb/DOM/Window.h> #include <LibWeb/DOM/XMLHttpRequest.h> #include <LibWeb/ResourceLoader.h> namespace Web { -XMLHttpRequest::XMLHttpRequest() +XMLHttpRequest::XMLHttpRequest(Window& window) + : m_window(window) { } @@ -59,7 +62,7 @@ void XMLHttpRequest::open(const String& method, const String& url) void XMLHttpRequest::send() { ResourceLoader::the().load( - URL(m_url), + m_window->document().complete_url(m_url), [weak_this = make_weak_ptr()](auto& data) { if (!weak_this) return; diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.h b/Libraries/LibWeb/DOM/XMLHttpRequest.h index f2924977aa..88c197be07 100644 --- a/Libraries/LibWeb/DOM/XMLHttpRequest.h +++ b/Libraries/LibWeb/DOM/XMLHttpRequest.h @@ -42,7 +42,7 @@ class XMLHttpRequest final public: using WrapperType = Bindings::XMLHttpRequestWrapper; - static NonnullRefPtr<XMLHttpRequest> create() { return adopt(*new XMLHttpRequest); } + static NonnullRefPtr<XMLHttpRequest> create(Window& window) { return adopt(*new XMLHttpRequest(window)); } virtual ~XMLHttpRequest() override; @@ -58,7 +58,9 @@ private: virtual void unref_event_target() override { unref(); } virtual void dispatch_event(NonnullRefPtr<Event>) override; - XMLHttpRequest(); + explicit XMLHttpRequest(Window&); + + NonnullRefPtr<Window> m_window; String m_method; String m_url; |