Skip to content

Truly independent web browser

LibWeb: Report no link of a replaced document from the render clock

Andreas Kling2507caee8387
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 00eed7840d3..6366c25ec72 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -5794,10 +5794,15 @@ void EventHandler::reset_hover_for_document_replacement(Badge<HTML::LocalNavigab
m_mouse_pointer.capture_target = nullptr;
m_mouse_pointer.buttons = 0;
m_additional_pointers.clear();
+ // A hover of the render clock shows the frame on screen, which may be of the outgoing document for a while yet. It
+ // must not bring back a link of that document once the client has heard that the hover ended.
+ auto document = m_navigable->active_document();
+ if (document)
+ document->hover_link_reporter().retire();
if (m_navigable->page().hover_reporting_navigable() == m_navigable)
report_hovered_node_to_client(nullptr);
// A hover of the render clock may have told of a link there, of which no handler has heard yet.
- if (auto document = m_navigable->active_document())
+ if (document)
m_navigable->page().hover_link().withdraw(document->unique_id());
}
diff --git a/Libraries/LibWeb/Page/PageHoverLink.cpp b/Libraries/LibWeb/Page/PageHoverLink.cpp
index c19a4b91052..1344f7d1f80 100644
--- a/Libraries/LibWeb/Page/PageHoverLink.cpp
+++ b/Libraries/LibWeb/Page/PageHoverLink.cpp
@@ -104,13 +104,14 @@ bool HoverLinkReporter::is_link(u32 element) const
void HoverLinkReporter::report(u32 element)
{
+ // NB: The lock keeps the string live here, so this thread takes no reference to it. And it keeps a report from
+ // coming after retire(), and so after the hover of a replaced document has ended.
+ MutexLocker locker(m_mutex);
+ if (m_is_retired)
+ return;
Optional<URL::URL> url;
- {
- // NB: The lock keeps the string live here, so this thread takes no reference to it.
- MutexLocker locker(m_mutex);
- if (auto link = m_links.find(element); link != m_links.end())
- url = URL::Parser::basic_parse(link->value.utf16_view(), m_base_url, m_encoding_name.bytes_as_string_view());
- }
+ if (auto link = m_links.find(element); link != m_links.end())
+ url = URL::Parser::basic_parse(link->value.utf16_view(), m_base_url, m_encoding_name.bytes_as_string_view());
m_hover_link->request(move(url), m_document);
}
@@ -119,4 +120,10 @@ void HoverLinkReporter::withdraw()
m_hover_link->withdraw(m_document);
}
+void HoverLinkReporter::retire()
+{
+ MutexLocker locker(m_mutex);
+ m_is_retired = true;
+}
+
}
diff --git a/Libraries/LibWeb/Page/PageHoverLink.h b/Libraries/LibWeb/Page/PageHoverLink.h
index c89d7267d0e..2ce19d104d8 100644
--- a/Libraries/LibWeb/Page/PageHoverLink.h
+++ b/Libraries/LibWeb/Page/PageHoverLink.h
@@ -78,6 +78,10 @@ public:
// Tells the page that the pointer left the document. From any thread.
void withdraw();
+ // Tells the page of no more links, as the document is being replaced. A hover of the render clock shows the frame on
+ // screen, which may still be of this document after the client has heard that its hover ended.
+ void retire();
+
private:
HoverLinkReporter(NonnullRefPtr<PageHoverLink>, UniqueNodeID document);
@@ -89,6 +93,7 @@ private:
URL::URL m_base_url;
Utf16String m_encoding;
String m_encoding_name;
+ bool m_is_retired { false };
};
}