mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 18:27:00 +00:00
fix: only the top level frame should have the orca syles and bridges injected
This commit is contained in:
@@ -48,13 +48,14 @@ std::string plugin_defaults_user_script()
|
|||||||
return WebViewHostDialog::document_start_injector(css, "orca-plugin-defaults", "beforeend");
|
return WebViewHostDialog::document_start_injector(css, "orca-plugin-defaults", "beforeend");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Injected into every page at document start (before the plugin's own scripts).
|
// Injected into the top-level page at document start (before the plugin's own
|
||||||
// Defines window.orca as the only host surface the page may use. It references
|
// scripts). Defines window.orca as the only host surface the page may use. It
|
||||||
// window.wx lazily (at call time) so it never races the backend's deferred
|
// references window.wx lazily (at call time) so it never races the backend's
|
||||||
// registration of the "wx" message handler. Guarded against double-injection so
|
// deferred registration of the "wx" message handler. Guarded against
|
||||||
// it is harmless if also prepended.
|
// double-injection so it is harmless if also prepended.
|
||||||
constexpr char ORCA_BRIDGE_JS[] = R"JS(
|
constexpr char ORCA_BRIDGE_JS[] = R"JS(
|
||||||
(function () {
|
(function () {
|
||||||
|
if (window.top !== window.self) return;
|
||||||
if (window.orca) return;
|
if (window.orca) return;
|
||||||
var handlers = [];
|
var handlers = [];
|
||||||
function send(kind, data) {
|
function send(kind, data) {
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ std::string WebViewHostDialog::document_start_injector(const std::string& markup
|
|||||||
const std::string literal = nlohmann::json(markup).dump();
|
const std::string literal = nlohmann::json(markup).dump();
|
||||||
std::string s;
|
std::string s;
|
||||||
s += "(function(){";
|
s += "(function(){";
|
||||||
|
// wxWebView's AddUserScript runs in child frames too (including cross-origin
|
||||||
|
// frames on WebView2). Host theme state belongs only to the top-level page.
|
||||||
|
s += "if(window.top!==window.self)return;";
|
||||||
s += prelude;
|
s += prelude;
|
||||||
s += "var css=" + literal + ";";
|
s += "var css=" + literal + ";";
|
||||||
s += "function inject(){";
|
s += "function inject(){";
|
||||||
|
|||||||
Reference in New Issue
Block a user