mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
LibWeb: Add contentType attribute to Document
This commit is contained in:
parent
cf9419fc4f
commit
3ec54448f5
Notes:
sideshowbarker
2024-07-19 01:25:00 +09:00
Author: https://github.com/Lubrsi
Commit: 3ec54448f5
Pull-request: https://github.com/SerenityOS/serenity/pull/4069
3 changed files with 21 additions and 10 deletions
|
@ -194,6 +194,9 @@ public:
|
|||
|
||||
Window& window() { return *m_window; }
|
||||
|
||||
const String& content_type() const { return m_content_type; }
|
||||
void set_content_type(const String& content_type) { m_content_type = content_type; }
|
||||
|
||||
private:
|
||||
explicit Document(const URL&);
|
||||
|
||||
|
@ -254,6 +257,7 @@ private:
|
|||
RefPtr<Document> m_associated_inert_template_document;
|
||||
|
||||
String m_ready_state { "loading" };
|
||||
String m_content_type;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
interface Document : Node {
|
||||
|
||||
readonly attribute DOMString contentType;
|
||||
|
||||
Element? getElementById(DOMString id);
|
||||
Element? querySelector(DOMString selectors);
|
||||
ArrayFromVector getElementsByTagName(DOMString tagName);
|
||||
|
|
|
@ -132,21 +132,26 @@ static RefPtr<DOM::Document> create_gemini_document(const ByteBuffer& data, cons
|
|||
|
||||
RefPtr<DOM::Document> FrameLoader::create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding)
|
||||
{
|
||||
RefPtr<DOM::Document> document;
|
||||
|
||||
if (mime_type == "text/html" || mime_type == "image/svg+xml") {
|
||||
HTML::HTMLDocumentParser parser(data, encoding);
|
||||
parser.run(url);
|
||||
return parser.document();
|
||||
document = parser.document();
|
||||
} else if (mime_type.starts_with("image/")) {
|
||||
document = create_image_document(data, url);
|
||||
} else if (mime_type == "text/plain") {
|
||||
document = create_text_document(data, url);
|
||||
} else if (mime_type == "text/markdown") {
|
||||
document = create_markdown_document(data, url);
|
||||
} else if (mime_type == "text/gemini") {
|
||||
document = create_gemini_document(data, url);
|
||||
}
|
||||
if (mime_type.starts_with("image/"))
|
||||
return create_image_document(data, url);
|
||||
if (mime_type == "text/plain")
|
||||
return create_text_document(data, url);
|
||||
if (mime_type == "text/markdown")
|
||||
return create_markdown_document(data, url);
|
||||
if (mime_type == "text/gemini")
|
||||
return create_gemini_document(data, url);
|
||||
|
||||
return nullptr;
|
||||
if (document)
|
||||
document->set_content_type(mime_type);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
bool FrameLoader::load(const LoadRequest& request, Type type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue