mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
Userland+Ladybird: Always specify url to be about:srcdoc in load_html()
After moving to navigables, we started reusing the code that populates session history entries with the srcdoc attribute value from iframes in `Page::load_html()` for loading HTML. This change addresses a crash in `determine_the_origin` which occurred because this method expected the URL to be `about:srcdoc` if we also provided HTML content (previously, it was the URL passed along with the HTML content into `load_html()`).
This commit is contained in:
parent
8e832a174e
commit
3c675e3f25
18 changed files with 31 additions and 32 deletions
|
@ -40,7 +40,7 @@
|
||||||
- (instancetype)init:(id<LadybirdWebViewObserver>)observer;
|
- (instancetype)init:(id<LadybirdWebViewObserver>)observer;
|
||||||
|
|
||||||
- (void)loadURL:(URL const&)url;
|
- (void)loadURL:(URL const&)url;
|
||||||
- (void)loadHTML:(StringView)html url:(URL const&)url;
|
- (void)loadHTML:(StringView)html;
|
||||||
|
|
||||||
- (WebView::ViewImplementation&)view;
|
- (WebView::ViewImplementation&)view;
|
||||||
- (String const&)handle;
|
- (String const&)handle;
|
||||||
|
|
|
@ -109,9 +109,9 @@ struct HideCursor {
|
||||||
m_web_view_bridge->load(url);
|
m_web_view_bridge->load(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)loadHTML:(StringView)html url:(URL const&)url
|
- (void)loadHTML:(StringView)html
|
||||||
{
|
{
|
||||||
m_web_view_bridge->load_html(html, url);
|
m_web_view_bridge->load_html(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (WebView::ViewImplementation&)view
|
- (WebView::ViewImplementation&)view
|
||||||
|
|
|
@ -91,7 +91,7 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
- (void)loadHTML:(StringView)html url:(URL const&)url
|
- (void)loadHTML:(StringView)html url:(URL const&)url
|
||||||
{
|
{
|
||||||
[[self tab].web_view loadHTML:html url:url];
|
[[self tab].web_view loadHTML:html];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect
|
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect
|
||||||
|
|
|
@ -442,10 +442,10 @@ Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tab& BrowserWindow::new_tab(StringView html, URL const& url, Web::HTML::ActivateTab activate_tab)
|
Tab& BrowserWindow::new_tab(StringView html, Web::HTML::ActivateTab activate_tab)
|
||||||
{
|
{
|
||||||
auto& tab = create_new_tab(activate_tab);
|
auto& tab = create_new_tab(activate_tab);
|
||||||
tab.load_html(html, url);
|
tab.load_html(html);
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public slots:
|
||||||
void tab_title_changed(int index, QString const&);
|
void tab_title_changed(int index, QString const&);
|
||||||
void tab_favicon_changed(int index, QIcon const& icon);
|
void tab_favicon_changed(int index, QIcon const& icon);
|
||||||
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
|
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
|
||||||
Tab& new_tab(StringView html, URL const& url, Web::HTML::ActivateTab);
|
Tab& new_tab(StringView html, Web::HTML::ActivateTab);
|
||||||
void activate_tab(int index);
|
void activate_tab(int index);
|
||||||
void close_tab(int index);
|
void close_tab(int index);
|
||||||
void close_current_tab();
|
void close_current_tab();
|
||||||
|
|
|
@ -217,7 +217,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView::
|
||||||
|
|
||||||
view().on_received_source = [this](auto const& url, auto const& source) {
|
view().on_received_source = [this](auto const& url, auto const& source) {
|
||||||
auto html = WebView::highlight_source(url, source);
|
auto html = WebView::highlight_source(url, source);
|
||||||
m_window->new_tab(html, url, Web::HTML::ActivateTab::Yes);
|
m_window->new_tab(html, Web::HTML::ActivateTab::Yes);
|
||||||
};
|
};
|
||||||
|
|
||||||
view().on_navigate_back = [this]() {
|
view().on_navigate_back = [this]() {
|
||||||
|
@ -550,9 +550,9 @@ void Tab::navigate(QString url_qstring)
|
||||||
view().load(url_string);
|
view().load(url_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::load_html(StringView html, URL const& url)
|
void Tab::load_html(StringView html)
|
||||||
{
|
{
|
||||||
view().load_html(html, url);
|
view().load_html(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::back()
|
void Tab::back()
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
WebContentView& view() { return *m_view; }
|
WebContentView& view() { return *m_view; }
|
||||||
|
|
||||||
void navigate(QString);
|
void navigate(QString);
|
||||||
void load_html(StringView, URL const&);
|
void load_html(StringView);
|
||||||
|
|
||||||
void back();
|
void back();
|
||||||
void forward();
|
void forward();
|
||||||
|
|
|
@ -505,5 +505,5 @@ void MailWidget::selected_email_to_load(GUI::ModelIndex const& index)
|
||||||
// FIXME: I'm not sure what the URL should be. Just use the default URL "about:blank".
|
// FIXME: I'm not sure what the URL should be. Just use the default URL "about:blank".
|
||||||
// FIXME: It would be nice if we could pass over the charset.
|
// FIXME: It would be nice if we could pass over the charset.
|
||||||
// FIXME: Add ability to cancel the load when we switch to another email. Feels very sluggish on heavy emails otherwise
|
// FIXME: Add ability to cancel the load when we switch to another email. Feels very sluggish on heavy emails otherwise
|
||||||
m_web_view->load_html(decoded_data, "about:blank"sv);
|
m_web_view->load_html(decoded_data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ void PresenterWidget::set_file(StringView file_name)
|
||||||
m_current_presentation = presentation.release_value();
|
m_current_presentation = presentation.release_value();
|
||||||
window()->set_title(DeprecatedString::formatted(title_template, m_current_presentation->title(), m_current_presentation->author()));
|
window()->set_title(DeprecatedString::formatted(title_template, m_current_presentation->title(), m_current_presentation->author()));
|
||||||
set_min_size(m_current_presentation->normative_size());
|
set_min_size(m_current_presentation->normative_size());
|
||||||
m_web_view->load_html(MUST(m_current_presentation->render()), "presenter://slide.html"sv);
|
m_web_view->load_html(MUST(m_current_presentation->render()));
|
||||||
update_slides_actions();
|
update_slides_actions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -909,7 +909,7 @@ void MainWidget::update_markdown_preview()
|
||||||
if (document) {
|
if (document) {
|
||||||
auto html = document->render_to_html();
|
auto html = document->render_to_html();
|
||||||
auto current_scroll_pos = m_page_view->visible_content_rect();
|
auto current_scroll_pos = m_page_view->visible_content_rect();
|
||||||
m_page_view->load_html(html, URL::create_with_file_scheme(m_path));
|
m_page_view->load_html(html);
|
||||||
m_page_view->scroll_into_view(current_scroll_pos, true, true);
|
m_page_view->scroll_into_view(current_scroll_pos, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -917,7 +917,7 @@ void MainWidget::update_markdown_preview()
|
||||||
void MainWidget::update_html_preview()
|
void MainWidget::update_html_preview()
|
||||||
{
|
{
|
||||||
auto current_scroll_pos = m_page_view->visible_content_rect();
|
auto current_scroll_pos = m_page_view->visible_content_rect();
|
||||||
m_page_view->load_html(m_editor->text(), URL::create_with_file_scheme(m_path));
|
m_page_view->load_html(m_editor->text());
|
||||||
m_page_view->scroll_into_view(current_scroll_pos, true, true);
|
m_page_view->scroll_into_view(current_scroll_pos, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ void Editor::show_documentation_tooltip_if_available(DeprecatedString const& hov
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_tooltip_page_view->load_html(man_document->render_to_html("<style>body { background-color: #dac7b5; }</style>"sv), {});
|
s_tooltip_page_view->load_html(man_document->render_to_html("<style>body { background-color: #dac7b5; }</style>"sv));
|
||||||
|
|
||||||
s_tooltip_window->set_rect(0, 0, 500, 400);
|
s_tooltip_window->set_rect(0, 0, 500, 400);
|
||||||
s_tooltip_window->move_to(screen_location.translated(4, 4));
|
s_tooltip_window->move_to(screen_location.translated(4, 4));
|
||||||
|
@ -722,7 +722,7 @@ void Editor::handle_function_parameters_hint_request()
|
||||||
}
|
}
|
||||||
html.append("<style>body { background-color: #dac7b5; }</style>"sv);
|
html.append("<style>body { background-color: #dac7b5; }</style>"sv);
|
||||||
|
|
||||||
s_tooltip_page_view->load_html(html.to_deprecated_string(), {});
|
s_tooltip_page_view->load_html(html.to_deprecated_string());
|
||||||
|
|
||||||
auto cursor_rect = current_editor().cursor_content_rect().location().translated(screen_relative_rect().location());
|
auto cursor_rect = current_editor().cursor_content_rect().location().translated(screen_relative_rect().location());
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,9 @@ void Page::load(const AK::URL& url)
|
||||||
(void)top_level_traversable()->navigate(url, *top_level_traversable()->active_document());
|
(void)top_level_traversable()->navigate(url, *top_level_traversable()->active_document());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Page::load_html(StringView html, const AK::URL& url)
|
void Page::load_html(StringView html)
|
||||||
{
|
{
|
||||||
(void)top_level_traversable()->navigate(url, *top_level_traversable()->active_document(), String::from_utf8(html).release_value_but_fixme_should_propagate_errors());
|
(void)top_level_traversable()->navigate("about:srcdoc"sv, *top_level_traversable()->active_document(), String::from_utf8(html).release_value_but_fixme_should_propagate_errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Page::has_ongoing_navigation() const
|
bool Page::has_ongoing_navigation() const
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
|
|
||||||
void load(const AK::URL&);
|
void load(const AK::URL&);
|
||||||
|
|
||||||
void load_html(StringView, const AK::URL&);
|
void load_html(StringView);
|
||||||
|
|
||||||
bool has_ongoing_navigation() const;
|
bool has_ongoing_navigation() const;
|
||||||
|
|
||||||
|
|
|
@ -86,15 +86,14 @@ void ViewImplementation::load(AK::URL const& url)
|
||||||
client().async_load_url(url);
|
client().async_load_url(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewImplementation::load_html(StringView html, AK::URL const& url)
|
void ViewImplementation::load_html(StringView html)
|
||||||
{
|
{
|
||||||
m_url = url;
|
client().async_load_html(html);
|
||||||
client().async_load_html(html, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewImplementation::load_empty_document()
|
void ViewImplementation::load_empty_document()
|
||||||
{
|
{
|
||||||
load_html(""sv, {});
|
load_html(""sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewImplementation::zoom_in()
|
void ViewImplementation::zoom_in()
|
||||||
|
@ -328,7 +327,7 @@ void ViewImplementation::handle_web_content_process_crash()
|
||||||
auto escaped_url = escape_html_entities(m_url.to_deprecated_string());
|
auto escaped_url = escape_html_entities(m_url.to_deprecated_string());
|
||||||
builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escaped_url, escaped_url);
|
builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escaped_url, escaped_url);
|
||||||
builder.append("</body></html>"sv);
|
builder.append("</body></html>"sv);
|
||||||
load_html(builder.to_deprecated_string(), m_url);
|
load_html(builder.to_deprecated_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> ViewImplementation::take_screenshot(ScreenshotType type)
|
ErrorOr<void> ViewImplementation::take_screenshot(ScreenshotType type)
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
void server_did_change_selection(Badge<WebContentClient>);
|
void server_did_change_selection(Badge<WebContentClient>);
|
||||||
|
|
||||||
void load(AK::URL const&);
|
void load(AK::URL const&);
|
||||||
void load_html(StringView, AK::URL const&);
|
void load_html(StringView);
|
||||||
void load_empty_document();
|
void load_empty_document();
|
||||||
|
|
||||||
void zoom_in();
|
void zoom_in();
|
||||||
|
|
|
@ -119,10 +119,10 @@ void ConnectionFromClient::load_url(const URL& url)
|
||||||
page().load(url);
|
page().load(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionFromClient::load_html(DeprecatedString const& html, const URL& url)
|
void ConnectionFromClient::load_html(DeprecatedString const& html)
|
||||||
{
|
{
|
||||||
dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadHTML: html={}, url={}", html, url);
|
dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadHTML: html={}", html);
|
||||||
page().load_html(html, url);
|
page().load_html(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionFromClient::set_viewport_rect(Gfx::IntRect const& rect)
|
void ConnectionFromClient::set_viewport_rect(Gfx::IntRect const& rect)
|
||||||
|
@ -481,7 +481,7 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec
|
||||||
auto maybe_link = document->query_selector("link[rel=match]"sv);
|
auto maybe_link = document->query_selector("link[rel=match]"sv);
|
||||||
if (maybe_link.is_error() || !maybe_link.value()) {
|
if (maybe_link.is_error() || !maybe_link.value()) {
|
||||||
// To make sure that we fail the ref-test if the link is missing, load the error page.
|
// To make sure that we fail the ref-test if the link is missing, load the error page.
|
||||||
load_html("<h1>Failed to find <link rel="match" /> in ref test page!</h1> Make sure you added it.", "about:blank"sv);
|
load_html("<h1>Failed to find <link rel="match" /> in ref test page!</h1> Make sure you added it.");
|
||||||
} else {
|
} else {
|
||||||
auto link = maybe_link.release_value();
|
auto link = maybe_link.release_value();
|
||||||
auto url = document->parse_url(link->get_attribute(Web::HTML::AttributeNames::href));
|
auto url = document->parse_url(link->get_attribute(Web::HTML::AttributeNames::href));
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
virtual void update_system_fonts(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
|
virtual void update_system_fonts(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
|
||||||
virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
|
virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
|
||||||
virtual void load_url(URL const&) override;
|
virtual void load_url(URL const&) override;
|
||||||
virtual void load_html(DeprecatedString const&, URL const&) override;
|
virtual void load_html(DeprecatedString const&) override;
|
||||||
virtual void paint(Gfx::IntRect const&, i32) override;
|
virtual void paint(Gfx::IntRect const&, i32) override;
|
||||||
virtual void set_viewport_rect(Gfx::IntRect const&) override;
|
virtual void set_viewport_rect(Gfx::IntRect const&) override;
|
||||||
virtual void mouse_down(Gfx::IntPoint, Gfx::IntPoint, unsigned, unsigned, unsigned) override;
|
virtual void mouse_down(Gfx::IntPoint, Gfx::IntPoint, unsigned, unsigned, unsigned) override;
|
||||||
|
|
|
@ -19,7 +19,7 @@ endpoint WebContentServer
|
||||||
update_screen_rects(Vector<Gfx::IntRect> rects, u32 main_screen_index) =|
|
update_screen_rects(Vector<Gfx::IntRect> rects, u32 main_screen_index) =|
|
||||||
|
|
||||||
load_url(URL url) =|
|
load_url(URL url) =|
|
||||||
load_html(DeprecatedString html, URL url) =|
|
load_html(DeprecatedString html) =|
|
||||||
|
|
||||||
add_backing_store(i32 backing_store_id, Gfx::ShareableBitmap bitmap) =|
|
add_backing_store(i32 backing_store_id, Gfx::ShareableBitmap bitmap) =|
|
||||||
remove_backing_store(i32 backing_store_id) =|
|
remove_backing_store(i32 backing_store_id) =|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue