mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:38:11 +00:00
LibHTML: Use ResourceLoader in HTMLLinkElement
This makes loading external stylesheets from http:// URLs work. :^)
This commit is contained in:
parent
75b5638f1c
commit
475c6d7112
1 changed files with 14 additions and 20 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include <LibHTML/DOM/Document.h>
|
#include <LibHTML/DOM/Document.h>
|
||||||
#include <LibHTML/DOM/HTMLLinkElement.h>
|
#include <LibHTML/DOM/HTMLLinkElement.h>
|
||||||
#include <LibHTML/Parser/CSSParser.h>
|
#include <LibHTML/Parser/CSSParser.h>
|
||||||
|
#include <LibHTML/ResourceLoader.h>
|
||||||
|
|
||||||
HTMLLinkElement::HTMLLinkElement(Document& document, const String& tag_name)
|
HTMLLinkElement::HTMLLinkElement(Document& document, const String& tag_name)
|
||||||
: HTMLElement(document, tag_name)
|
: HTMLElement(document, tag_name)
|
||||||
|
@ -17,25 +18,18 @@ void HTMLLinkElement::inserted_into(Node&)
|
||||||
{
|
{
|
||||||
if (rel() == "stylesheet") {
|
if (rel() == "stylesheet") {
|
||||||
URL url = document().complete_url(href());
|
URL url = document().complete_url(href());
|
||||||
if (url.protocol() != "file") {
|
ResourceLoader::the().load(url, [&](auto data) {
|
||||||
ASSERT_NOT_REACHED();
|
if (data.is_null()) {
|
||||||
}
|
dbg() << "HTMLLinkElement: Failed to load stylesheet: " << href();
|
||||||
auto file = CFile::construct(url.path());
|
return;
|
||||||
if (!file->open(CIODevice::ReadOnly)) {
|
}
|
||||||
dbg() << "Failed to open " << url.to_string();
|
auto sheet = parse_css(data);
|
||||||
ASSERT_NOT_REACHED();
|
if (!sheet) {
|
||||||
return;
|
dbg() << "HTMLLinkElement: Failed to parse stylesheet: " << href();
|
||||||
}
|
return;
|
||||||
auto data = file->read_all();
|
}
|
||||||
auto sheet = parse_css(data);
|
document().add_sheet(*sheet);
|
||||||
|
document().invalidate_layout();
|
||||||
if (!sheet) {
|
});
|
||||||
dbg() << "Failed to parse " << url.to_string();
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document().add_sheet(*sheet);
|
|
||||||
document().invalidate_layout();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue