mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00: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
3 changed files with 11 additions and 5 deletions
|
@ -50,7 +50,8 @@ JS::Value XMLHttpRequestConstructor::call(JS::Interpreter& interpreter)
|
||||||
|
|
||||||
JS::Value XMLHttpRequestConstructor::construct(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 <LibJS/Runtime/Function.h>
|
||||||
#include <LibWeb/Bindings/EventWrapper.h>
|
#include <LibWeb/Bindings/EventWrapper.h>
|
||||||
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
||||||
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/DOM/EventListener.h>
|
#include <LibWeb/DOM/EventListener.h>
|
||||||
|
#include <LibWeb/DOM/Window.h>
|
||||||
#include <LibWeb/DOM/XMLHttpRequest.h>
|
#include <LibWeb/DOM/XMLHttpRequest.h>
|
||||||
#include <LibWeb/ResourceLoader.h>
|
#include <LibWeb/ResourceLoader.h>
|
||||||
|
|
||||||
namespace Web {
|
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()
|
void XMLHttpRequest::send()
|
||||||
{
|
{
|
||||||
ResourceLoader::the().load(
|
ResourceLoader::the().load(
|
||||||
URL(m_url),
|
m_window->document().complete_url(m_url),
|
||||||
[weak_this = make_weak_ptr()](auto& data) {
|
[weak_this = make_weak_ptr()](auto& data) {
|
||||||
if (!weak_this)
|
if (!weak_this)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -42,7 +42,7 @@ class XMLHttpRequest final
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::XMLHttpRequestWrapper;
|
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;
|
virtual ~XMLHttpRequest() override;
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ private:
|
||||||
virtual void unref_event_target() override { unref(); }
|
virtual void unref_event_target() override { unref(); }
|
||||||
virtual void dispatch_event(NonnullRefPtr<Event>) override;
|
virtual void dispatch_event(NonnullRefPtr<Event>) override;
|
||||||
|
|
||||||
XMLHttpRequest();
|
explicit XMLHttpRequest(Window&);
|
||||||
|
|
||||||
|
NonnullRefPtr<Window> m_window;
|
||||||
|
|
||||||
String m_method;
|
String m_method;
|
||||||
String m_url;
|
String m_url;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue