mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibWeb: Add the Web::URL namespace and move URLEncoder to it
This namespace will be used for all interfaces defined in the URL specification, like URL and URLSearchParams. This has the unfortunate side-effect of requiring us to use the fully qualified AK::URL name whenever we want to refer to the AK class, so this commit also fixes all such references.
This commit is contained in:
parent
2b78e227f2
commit
4629f2e4ad
54 changed files with 236 additions and 225 deletions
|
@ -92,7 +92,7 @@ String HTMLCanvasElement::to_data_url(const String& type, [[maybe_unused]] Optio
|
|||
if (type != "image/png")
|
||||
return {};
|
||||
auto encoded_bitmap = Gfx::PNGWriter::encode(*m_bitmap);
|
||||
return URL::create_with_data(type, encode_base64(encoded_bitmap), true).to_string();
|
||||
return AK::URL::create_with_data(type, encode_base64(encoded_bitmap), true).to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <LibWeb/HTML/SubmitEvent.h>
|
||||
#include <LibWeb/Page/BrowsingContext.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/URLEncoder.h>
|
||||
#include <LibWeb/URL/URL.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -75,7 +75,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
|
|||
return;
|
||||
}
|
||||
|
||||
URL url(document().parse_url(action()));
|
||||
AK::URL url(document().parse_url(action()));
|
||||
|
||||
if (!url.is_valid()) {
|
||||
dbgln("Failed to submit form: Invalid URL: {}", action());
|
||||
|
@ -96,7 +96,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
|
|||
return;
|
||||
}
|
||||
|
||||
Vector<URLQueryParam> parameters;
|
||||
Vector<URL::QueryParam> parameters;
|
||||
|
||||
for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& input) {
|
||||
if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
|
||||
|
@ -105,14 +105,14 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
|
|||
});
|
||||
|
||||
if (effective_method == "get") {
|
||||
url.set_query(urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded));
|
||||
url.set_query(url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded));
|
||||
}
|
||||
|
||||
LoadRequest request;
|
||||
request.set_url(url);
|
||||
|
||||
if (effective_method == "post") {
|
||||
auto body = urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer();
|
||||
auto body = url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer();
|
||||
request.set_method("POST");
|
||||
request.set_header("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.set_header("Content-Length", String::number(body.size()));
|
||||
|
|
|
@ -304,7 +304,7 @@ void HTMLScriptElement::prepare_script()
|
|||
document().interpreter();
|
||||
|
||||
// FIXME: This is all ad-hoc and needs work.
|
||||
auto script = ClassicScript::create(url.to_string(), data, document().interpreter().realm(), URL());
|
||||
auto script = ClassicScript::create(url.to_string(), data, document().interpreter().realm(), AK::URL());
|
||||
|
||||
// When the chosen algorithm asynchronously completes, set the script's script to the result. At that time, the script is ready.
|
||||
m_script = script;
|
||||
|
@ -331,7 +331,7 @@ void HTMLScriptElement::prepare_script()
|
|||
document().interpreter();
|
||||
|
||||
// FIXME: Pass settings, base URL and options.
|
||||
auto script = ClassicScript::create(m_document->url().to_string(), source_text, document().interpreter().realm(), URL());
|
||||
auto script = ClassicScript::create(m_document->url().to_string(), source_text, document().interpreter().realm(), AK::URL());
|
||||
|
||||
// 2. Set the script's script to script.
|
||||
m_script = script;
|
||||
|
|
|
@ -93,7 +93,7 @@ static Vector<FlyString> s_quirks_public_ids = {
|
|||
"-//WebTechs//DTD Mozilla HTML//"
|
||||
};
|
||||
|
||||
RefPtr<DOM::Document> parse_html_document(const StringView& data, const URL& url, const String& encoding)
|
||||
RefPtr<DOM::Document> parse_html_document(const StringView& data, const AK::URL& url, const String& encoding)
|
||||
{
|
||||
auto document = DOM::Document::create(url);
|
||||
HTMLDocumentParser parser(document, data, encoding);
|
||||
|
@ -116,7 +116,7 @@ HTMLDocumentParser::~HTMLDocumentParser()
|
|||
m_document->set_should_invalidate_styles_on_attribute_changes(true);
|
||||
}
|
||||
|
||||
void HTMLDocumentParser::run(const URL& url)
|
||||
void HTMLDocumentParser::run(const AK::URL& url)
|
||||
{
|
||||
m_document->set_url(url);
|
||||
m_document->set_source(m_tokenizer.source());
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Web::HTML {
|
|||
__ENUMERATE_INSERTION_MODE(AfterAfterBody) \
|
||||
__ENUMERATE_INSERTION_MODE(AfterAfterFrameset)
|
||||
|
||||
RefPtr<DOM::Document> parse_html_document(const StringView&, const URL&, const String& encoding);
|
||||
RefPtr<DOM::Document> parse_html_document(const StringView&, const AK::URL&, const String& encoding);
|
||||
|
||||
class HTMLDocumentParser {
|
||||
public:
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
static NonnullOwnPtr<HTMLDocumentParser> create_with_uncertain_encoding(DOM::Document&, const ByteBuffer& input);
|
||||
|
||||
void run(const URL&);
|
||||
void run(const AK::URL&);
|
||||
|
||||
DOM::Document& document();
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script
|
||||
NonnullRefPtr<ClassicScript> ClassicScript::create(String filename, StringView source, JS::Realm& realm, URL base_url, MutedErrors muted_errors)
|
||||
NonnullRefPtr<ClassicScript> ClassicScript::create(String filename, StringView source, JS::Realm& realm, AK::URL base_url, MutedErrors muted_errors)
|
||||
{
|
||||
// 1. If muted errors was not provided, let it be false. (NOTE: This is taken care of by the default argument.)
|
||||
|
||||
|
@ -65,7 +65,7 @@ JS::Value ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
return vm.last_value();
|
||||
}
|
||||
|
||||
ClassicScript::ClassicScript(URL base_url, String filename)
|
||||
ClassicScript::ClassicScript(AK::URL base_url, String filename)
|
||||
: Script(move(base_url), move(filename))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
No,
|
||||
Yes,
|
||||
};
|
||||
static NonnullRefPtr<ClassicScript> create(String filename, StringView source, JS::Realm&, URL base_url, MutedErrors = MutedErrors::No);
|
||||
static NonnullRefPtr<ClassicScript> create(String filename, StringView source, JS::Realm&, AK::URL base_url, MutedErrors = MutedErrors::No);
|
||||
|
||||
JS::Script* script_record() { return m_script_record; }
|
||||
JS::Script const* script_record() const { return m_script_record; }
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
JS::Value run(RethrowErrors = RethrowErrors::No);
|
||||
|
||||
private:
|
||||
ClassicScript(URL base_url, String filename);
|
||||
ClassicScript(AK::URL base_url, String filename);
|
||||
|
||||
RefPtr<JS::Script> m_script_record;
|
||||
MutedErrors m_muted_errors { MutedErrors::No };
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
Script::Script(URL base_url, String filename)
|
||||
Script::Script(AK::URL base_url, String filename)
|
||||
: m_base_url(move(base_url))
|
||||
, m_filename(move(filename))
|
||||
{
|
||||
|
|
|
@ -16,14 +16,14 @@ class Script : public RefCounted<Script> {
|
|||
public:
|
||||
virtual ~Script();
|
||||
|
||||
URL const& base_url() const { return m_base_url; }
|
||||
AK::URL const& base_url() const { return m_base_url; }
|
||||
String const& filename() const { return m_filename; }
|
||||
|
||||
protected:
|
||||
Script(URL base_url, String filename);
|
||||
Script(AK::URL base_url, String filename);
|
||||
|
||||
private:
|
||||
URL m_base_url;
|
||||
AK::URL m_base_url;
|
||||
String m_filename;
|
||||
};
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ WebSocketClientManager::WebSocketClientManager()
|
|||
{
|
||||
}
|
||||
|
||||
RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const URL& url)
|
||||
RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const AK::URL& url)
|
||||
{
|
||||
return m_websocket_client->connect(url);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const URL& url)
|
|||
// https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface
|
||||
DOM::ExceptionOr<NonnullRefPtr<WebSocket>> WebSocket::create_with_global_object(Bindings::WindowObject& window, const String& url)
|
||||
{
|
||||
URL url_record(url);
|
||||
AK::URL url_record(url);
|
||||
if (!url_record.is_valid())
|
||||
return DOM::SyntaxError::create("Invalid URL");
|
||||
if (!url_record.protocol().is_one_of("ws", "wss"))
|
||||
|
@ -61,7 +61,7 @@ DOM::ExceptionOr<NonnullRefPtr<WebSocket>> WebSocket::create_with_global_object(
|
|||
return WebSocket::create(window.impl(), url_record);
|
||||
}
|
||||
|
||||
WebSocket::WebSocket(DOM::Window& window, URL& url)
|
||||
WebSocket::WebSocket(DOM::Window& window, AK::URL& url)
|
||||
: EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.associated_document()))
|
||||
, m_window(window)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ class WebSocketClientManager : public Core::Object {
|
|||
public:
|
||||
static WebSocketClientManager& the();
|
||||
|
||||
RefPtr<Protocol::WebSocket> connect(const URL&);
|
||||
RefPtr<Protocol::WebSocket> connect(const AK::URL&);
|
||||
|
||||
private:
|
||||
WebSocketClientManager();
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
using WrapperType = Bindings::WebSocketWrapper;
|
||||
|
||||
static NonnullRefPtr<WebSocket> create(DOM::Window& window, URL& url)
|
||||
static NonnullRefPtr<WebSocket> create(DOM::Window& window, AK::URL& url)
|
||||
{
|
||||
return adopt_ref(*new WebSocket(window, url));
|
||||
}
|
||||
|
@ -102,11 +102,11 @@ private:
|
|||
void on_error();
|
||||
void on_close(u16 code, String reason, bool was_clean);
|
||||
|
||||
explicit WebSocket(DOM::Window&, URL&);
|
||||
explicit WebSocket(DOM::Window&, AK::URL&);
|
||||
|
||||
NonnullRefPtr<DOM::Window> m_window;
|
||||
|
||||
URL m_url;
|
||||
AK::URL m_url;
|
||||
String m_binary_type { "blob" };
|
||||
RefPtr<Protocol::WebSocket> m_websocket;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue