mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:47:35 +00:00
LibWeb: Make HTMLLinkElement responsible for its own loading
This is the last use of CSSLoader, which can now be deleted.
This commit is contained in:
parent
6fc1810190
commit
60867703c0
2 changed files with 46 additions and 10 deletions
|
@ -1,11 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -16,11 +18,7 @@ namespace Web::HTML {
|
|||
|
||||
HTMLLinkElement::HTMLLinkElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
, m_css_loader(*this)
|
||||
{
|
||||
m_css_loader.on_load = [&] {
|
||||
document.update_style();
|
||||
};
|
||||
}
|
||||
|
||||
HTMLLinkElement::~HTMLLinkElement()
|
||||
|
@ -32,9 +30,11 @@ void HTMLLinkElement::inserted()
|
|||
HTMLElement::inserted();
|
||||
|
||||
if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) {
|
||||
m_css_loader.load_from_url(document().parse_url(href()));
|
||||
if (auto sheet = m_css_loader.style_sheet())
|
||||
document().style_sheets().add_sheet(sheet.release_nonnull());
|
||||
auto url = document().parse_url(href());
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Loading import URL: {}", url);
|
||||
auto request = LoadRequest::create_for_url_on_page(url, document().page());
|
||||
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
|
||||
m_document_load_event_delayer.emplace(document());
|
||||
}
|
||||
|
||||
if (m_relationship & Relationship::Preload) {
|
||||
|
@ -69,4 +69,33 @@ void HTMLLinkElement::parse_attribute(const FlyString& name, const String& value
|
|||
}
|
||||
}
|
||||
|
||||
void HTMLLinkElement::resource_did_fail()
|
||||
{
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Resource did fail. URL: {}", resource()->url());
|
||||
|
||||
m_document_load_event_delayer.clear();
|
||||
}
|
||||
|
||||
void HTMLLinkElement::resource_did_load()
|
||||
{
|
||||
VERIFY(resource());
|
||||
|
||||
m_document_load_event_delayer.clear();
|
||||
|
||||
if (!resource()->has_encoded_data()) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Resource did load, no encoded data. URL: {}", resource()->url());
|
||||
} else {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Resource did load, has encoded data. URL: {}", resource()->url());
|
||||
}
|
||||
|
||||
auto sheet = parse_css(CSS::ParsingContext(document()), resource()->encoded_data());
|
||||
if (!sheet) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Failed to parse stylesheet: {}", resource()->url());
|
||||
return;
|
||||
}
|
||||
|
||||
sheet->set_owner_node(this);
|
||||
document().style_sheets().add_sheet(sheet.release_nonnull());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue