mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibWeb: Add contentType attribute to Document
This commit is contained in:
parent
cf9419fc4f
commit
3ec54448f5
3 changed files with 21 additions and 10 deletions
|
@ -194,6 +194,9 @@ public:
|
||||||
|
|
||||||
Window& window() { return *m_window; }
|
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:
|
private:
|
||||||
explicit Document(const URL&);
|
explicit Document(const URL&);
|
||||||
|
|
||||||
|
@ -254,6 +257,7 @@ private:
|
||||||
RefPtr<Document> m_associated_inert_template_document;
|
RefPtr<Document> m_associated_inert_template_document;
|
||||||
|
|
||||||
String m_ready_state { "loading" };
|
String m_ready_state { "loading" };
|
||||||
|
String m_content_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
interface Document : Node {
|
interface Document : Node {
|
||||||
|
|
||||||
|
readonly attribute DOMString contentType;
|
||||||
|
|
||||||
Element? getElementById(DOMString id);
|
Element? getElementById(DOMString id);
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector getElementsByTagName(DOMString tagName);
|
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> 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") {
|
if (mime_type == "text/html" || mime_type == "image/svg+xml") {
|
||||||
HTML::HTMLDocumentParser parser(data, encoding);
|
HTML::HTMLDocumentParser parser(data, encoding);
|
||||||
parser.run(url);
|
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)
|
bool FrameLoader::load(const LoadRequest& request, Type type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue