mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 09:18:05 +03:00
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. :^)
This commit is contained in:
parent
4ffac713b9
commit
4036f15728
Notes:
sideshowbarker
2024-07-19 07:47:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4036f15728b
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user