mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWebView: Handle missing URL for view source
Instead of potentially passing through an invalid URL.
This commit is contained in:
parent
f857c6a6e6
commit
2827374edc
Notes:
github-actions[bot]
2025-03-04 21:26:39 +00:00
Author: https://github.com/shannonbooth
Commit: 2827374edc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3668
Reviewed-by: https://github.com/trflynn89
3 changed files with 12 additions and 7 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <LibCore/Resource.h>
|
||||
#include <LibJS/MarkupGenerator.h>
|
||||
#include <LibURL/Parser.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWebView/Application.h>
|
||||
|
@ -97,8 +98,8 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
|
|||
m_inspector_web_view.run_javascript(MUST(builder.to_string()));
|
||||
};
|
||||
|
||||
m_content_web_view.on_received_style_sheet_source = [this](Web::CSS::StyleSheetIdentifier const& identifier, auto const& base_url, String const& source) {
|
||||
auto html = highlight_source(identifier.url.value_or({}), base_url, source, Syntax::Language::CSS, HighlightOutputMode::SourceOnly);
|
||||
m_content_web_view.on_received_style_sheet_source = [this](Web::CSS::StyleSheetIdentifier const& identifier, URL::URL const& base_url, String const& source) {
|
||||
auto html = highlight_source(URL::Parser::basic_parse(identifier.url.value_or({})), base_url, source, Syntax::Language::CSS, HighlightOutputMode::SourceOnly);
|
||||
auto script = MUST(String::formatted("inspector.setStyleSheetSource({}, \"{}\");",
|
||||
style_sheet_identifier_to_json(identifier),
|
||||
MUST(encode_base64(html.bytes()))));
|
||||
|
|
|
@ -147,7 +147,7 @@ void SourceHighlighterClient::highlighter_did_set_folding_regions(Vector<Syntax:
|
|||
document().set_folding_regions(move(folding_regions));
|
||||
}
|
||||
|
||||
String highlight_source(URL::URL const& url, URL::URL const& base_url, String const& source, Syntax::Language language, HighlightOutputMode mode)
|
||||
String highlight_source(Optional<URL::URL> const& url, URL::URL const& base_url, String const& source, Syntax::Language language, HighlightOutputMode mode)
|
||||
{
|
||||
SourceHighlighterClient highlighter_client { source, language };
|
||||
return highlighter_client.to_html_string(url, base_url, mode);
|
||||
|
@ -268,7 +268,7 @@ StringView SourceHighlighterClient::class_for_token(u64 token_type) const
|
|||
}
|
||||
}
|
||||
|
||||
String SourceHighlighterClient::to_html_string(URL::URL const& url, URL::URL const& base_url, HighlightOutputMode mode) const
|
||||
String SourceHighlighterClient::to_html_string(Optional<URL::URL> const& url, URL::URL const& base_url, HighlightOutputMode mode) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
|
@ -302,7 +302,11 @@ String SourceHighlighterClient::to_html_string(URL::URL const& url, URL::URL con
|
|||
<head>
|
||||
<meta name="color-scheme" content="dark light">)~~~"sv);
|
||||
|
||||
builder.appendff("<title>View Source - {}</title>", escape_html_entities(url.serialize_for_display()));
|
||||
if (url.has_value())
|
||||
builder.appendff("<title>View Source - {}</title>", escape_html_entities(url->serialize_for_display()));
|
||||
else
|
||||
builder.append("<title>View Source</title>"sv);
|
||||
|
||||
builder.appendff("<style type=\"text/css\">{}</style>", HTML_HIGHLIGHTER_STYLE);
|
||||
builder.append(R"~~~(
|
||||
</head>
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
SourceHighlighterClient(String const& source, Syntax::Language);
|
||||
virtual ~SourceHighlighterClient() = default;
|
||||
|
||||
String to_html_string(URL::URL const& url, URL::URL const& base_url, HighlightOutputMode) const;
|
||||
String to_html_string(Optional<URL::URL> const&, URL::URL const& base_url, HighlightOutputMode) const;
|
||||
|
||||
private:
|
||||
// ^ Syntax::HighlighterClient
|
||||
|
@ -75,7 +75,7 @@ private:
|
|||
OwnPtr<Syntax::Highlighter> m_highlighter;
|
||||
};
|
||||
|
||||
String highlight_source(URL::URL const& url, URL::URL const& base_url, String const& source, Syntax::Language, HighlightOutputMode);
|
||||
String highlight_source(Optional<URL::URL> const&, URL::URL const& base_url, String const& source, Syntax::Language, HighlightOutputMode);
|
||||
|
||||
constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
|
||||
@media (prefers-color-scheme: dark) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue