LibWebView: Handle missing URL for view source

Instead of potentially passing through an invalid URL.
This commit is contained in:
Shannon Booth 2025-02-22 21:02:32 +13:00 committed by Tim Flynn
parent f857c6a6e6
commit 2827374edc
Notes: github-actions[bot] 2025-03-04 21:26:39 +00:00
3 changed files with 12 additions and 7 deletions

View file

@ -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()))));