Restore Plugin HTML After a WebKit Reload

Plugin dialog content is injected with SetPage, so on the WebKit backends a
reload (context menu, keyboard shortcut or location.reload()) re-fetches the
SetPage base URL instead of the injected document, and the plugin UI is gone
for good: load_plugin_content() returned early once m_content_loaded was set.

On GTK and macOS, re-inject the plugin HTML when a main-frame load arrives
after the initial swap. m_own_page_load marks the load caused by our own
SetPage so it is not mistaken for a reload, and a post-load error is left
alone, as it only ever means a failed subresource.

MSW is left out: WebView2 reloads NavigateToString content from its own
history entry, so the page already survives a reload there, and the backend
reports in-document navigation (a page setting location.hash) as a load,
which re-injection would turn into a page wipe.
This commit is contained in:
Hanif Koh
2026-09-17 15:46:14 +08:00
parent ca668a3bc9
commit 99422df857
2 changed files with 20 additions and 6 deletions
+19 -6
View File
@@ -139,19 +139,32 @@ void PluginWebDialog::destroy_for_plugin(PluginWebDialog* dialog)
void PluginWebDialog::on_bootstrap_event(wxWebViewEvent& event)
{
// The first bootstrap load (or its error) triggers the swap to plugin HTML;
// the resulting plugin-page load is ignored (guarded by m_content_loaded).
load_plugin_content();
// The first bootstrap load (or its error) triggers the swap to plugin HTML.
if (!m_content_loaded)
load_plugin_content();
#ifndef __WXMSW__
// WebKit reloads the SetPage base URL rather than the injected page, so a later main-frame
// load that is not our own SetPage is a browser reload, and the plugin HTML has to be put
// back. A post-load error only ever means a failed subresource. WebView2 reloads SetPage
// content from its own history entry, and reports in-document navigation as a load, so
// MSW needs neither the re-injection nor a guard against it.
else if (event.GetEventType() == wxEVT_WEBVIEW_LOADED) {
if (m_own_page_load)
m_own_page_load = false;
else
load_plugin_content();
}
#endif
event.Skip();
}
void PluginWebDialog::load_plugin_content()
{
if (m_content_loaded)
return;
m_content_loaded = true;
if (wxWebView* wv = browser())
if (wxWebView* wv = browser()) {
m_own_page_load = true;
wv->SetPage(wxString::FromUTF8(m_html), web_base_url());
}
}
void PluginWebDialog::on_script_message(const nlohmann::json& payload)
+1
View File
@@ -72,6 +72,7 @@ private:
std::string m_html;
bool m_content_loaded{false};
bool m_own_page_load{false}; // a SetPage of the plugin HTML is in flight
bool m_open{true};
bool m_close_fired{false};
std::optional<nlohmann::json> m_result;