mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:08:10 +00:00
LibWeb: Set Cookie header on <script> resource requests
This required changing the load_sync API to take a LoadRequest instead of just a URL. Since HTMLScriptElement was the only (non-test) user of this API, it didn't seem useful to instead add an overload of load_sync for this.
This commit is contained in:
parent
3cc5286565
commit
347838a240
4 changed files with 14 additions and 6 deletions
|
@ -224,10 +224,12 @@ void HTMLScriptElement::prepare_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_script_type == ScriptType::Classic) {
|
if (m_script_type == ScriptType::Classic) {
|
||||||
|
auto request = LoadRequest::create_for_url_on_page(url, document().page());
|
||||||
|
|
||||||
// FIXME: This load should be made asynchronous and the parser should spin an event loop etc.
|
// FIXME: This load should be made asynchronous and the parser should spin an event loop etc.
|
||||||
m_script_filename = url.basename();
|
m_script_filename = url.basename();
|
||||||
ResourceLoader::the().load_sync(
|
ResourceLoader::the().load_sync(
|
||||||
url,
|
request,
|
||||||
[this, url](auto data, auto&, auto) {
|
[this, url](auto data, auto&, auto) {
|
||||||
if (data.is_null()) {
|
if (data.is_null()) {
|
||||||
dbgln("HTMLScriptElement: Failed to load {}", url);
|
dbgln("HTMLScriptElement: Failed to load {}", url);
|
||||||
|
|
|
@ -52,12 +52,12 @@ ResourceLoader::ResourceLoader()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceLoader::load_sync(const URL& url, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback)
|
void ResourceLoader::load_sync(const LoadRequest& request, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback)
|
||||||
{
|
{
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
||||||
load(
|
load(
|
||||||
url,
|
request,
|
||||||
[&](auto data, auto& response_headers, auto status_code) {
|
[&](auto data, auto& response_headers, auto status_code) {
|
||||||
success_callback(data, response_headers, status_code);
|
success_callback(data, response_headers, status_code);
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
|
|
||||||
void load(const LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
void load(const LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
||||||
void load(const URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
void load(const URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
||||||
void load_sync(const URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
void load_sync(const LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
||||||
|
|
||||||
Function<void()> on_load_counter_change;
|
Function<void()> on_load_counter_change;
|
||||||
|
|
||||||
|
|
|
@ -209,8 +209,11 @@ void TestRunner::run()
|
||||||
// give a new parser the existing document to work on.
|
// give a new parser the existing document to work on.
|
||||||
m_page_view->document()->remove_all_children();
|
m_page_view->document()->remove_all_children();
|
||||||
|
|
||||||
|
Web::LoadRequest request;
|
||||||
|
request.set_url(page_to_load);
|
||||||
|
|
||||||
Web::ResourceLoader::the().load_sync(
|
Web::ResourceLoader::the().load_sync(
|
||||||
page_to_load,
|
request,
|
||||||
[&](auto data, auto&, auto) {
|
[&](auto data, auto&, auto) {
|
||||||
Web::HTML::HTMLDocumentParser parser(*m_page_view->document(), data, "utf-8");
|
Web::HTML::HTMLDocumentParser parser(*m_page_view->document(), data, "utf-8");
|
||||||
parser.run(page_to_load);
|
parser.run(page_to_load);
|
||||||
|
@ -315,8 +318,11 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
||||||
|
|
||||||
JSFileResult file_result;
|
JSFileResult file_result;
|
||||||
|
|
||||||
|
Web::LoadRequest request;
|
||||||
|
request.set_url(page_to_load);
|
||||||
|
|
||||||
Web::ResourceLoader::the().load_sync(
|
Web::ResourceLoader::the().load_sync(
|
||||||
page_to_load,
|
request,
|
||||||
[&](auto data, auto&, auto) {
|
[&](auto data, auto&, auto) {
|
||||||
// Create a new parser and immediately get its document to replace the old interpreter.
|
// Create a new parser and immediately get its document to replace the old interpreter.
|
||||||
auto document = Web::DOM::Document::create();
|
auto document = Web::DOM::Document::create();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue