forked from upstream-mirrors/OrcaSlicer
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fc2a88ba72 | |||
| 113b42da33 | |||
| e740246f7e | |||
| 20c01cfc7e | |||
| 3ba5ddfe19 | |||
| 83de33416e | |||
| 15030ef560 | |||
| b29f06a0ab | |||
| 9ec0d39592 | |||
| 0b9b05ed85 |
@@ -26,8 +26,9 @@ DockPanel::DockPanel(wxWindow* parent,
|
||||
const std::string& html,
|
||||
MessageHandler on_message,
|
||||
CloseHandler on_close,
|
||||
CloseHandler on_destroyed)
|
||||
: WebPanel(parent, web_hosting::orca_bridge_script())
|
||||
CloseHandler on_destroyed,
|
||||
const wxString& profile)
|
||||
: WebPanel(parent, web_hosting::orca_bridge_script(), profile)
|
||||
, m_html(html)
|
||||
, m_on_message(std::move(on_message))
|
||||
, m_on_close(std::move(on_close))
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <wx/string.h>
|
||||
|
||||
class wxWindow;
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
@@ -27,7 +29,8 @@ public:
|
||||
const std::string& html,
|
||||
MessageHandler on_message,
|
||||
CloseHandler on_close,
|
||||
CloseHandler on_destroyed);
|
||||
CloseHandler on_destroyed,
|
||||
const wxString& profile = wxEmptyString);
|
||||
~DockPanel() override;
|
||||
|
||||
// Main thread only.
|
||||
|
||||
@@ -28,7 +28,8 @@ WebDialog::WebDialog(wxWindow* parent,
|
||||
SubmitHandler on_submit,
|
||||
CloseHandler on_close,
|
||||
CloseHandler on_destroyed,
|
||||
long wx_style)
|
||||
long wx_style,
|
||||
const wxString& profile)
|
||||
: WebViewHostDialog(parent, wxID_ANY, title, wxDefaultPosition, size, wx_style)
|
||||
, m_html(html)
|
||||
, m_on_message(std::move(on_message))
|
||||
@@ -38,7 +39,7 @@ WebDialog::WebDialog(wxWindow* parent,
|
||||
{
|
||||
// A tiny bundled bootstrap page brings the webview up; the real plugin HTML
|
||||
// is swapped in via SetPage once the bootstrap finishes loading.
|
||||
create_webview(web_hosting::BOOTSTRAP_PAGE, title, size, wxSize(320, 240));
|
||||
create_webview(web_hosting::BOOTSTRAP_PAGE, title, size, wxSize(320, 240), profile);
|
||||
|
||||
// Paint the window/webview in the themed background so there is no white
|
||||
// flash before the (transparent) bootstrap page and plugin HTML render.
|
||||
|
||||
@@ -49,7 +49,8 @@ public:
|
||||
SubmitHandler on_submit,
|
||||
CloseHandler on_close,
|
||||
CloseHandler on_destroyed,
|
||||
long wx_style = wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER);
|
||||
long wx_style = wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER,
|
||||
const wxString& profile = wxEmptyString);
|
||||
~WebDialog() override;
|
||||
|
||||
static void post_message(WebDialog* dialog, const nlohmann::json& data);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
WebPanel::WebPanel(wxWindow* parent, const char* bridge_script)
|
||||
WebPanel::WebPanel(wxWindow* parent, const char* bridge_script, const wxString& profile)
|
||||
: wxPanel(parent, wxID_ANY)
|
||||
{
|
||||
SetBackgroundColour(wxGetApp().get_window_default_clr());
|
||||
@@ -26,7 +26,7 @@ WebPanel::WebPanel(wxWindow* parent, const char* bridge_script)
|
||||
SetSizer(sizer);
|
||||
|
||||
// Never null: WebView::CreateWebView substitutes a placeholder view when no backend is available.
|
||||
m_browser = WebView::CreateWebView(this, web_hosting::bootstrap_url());
|
||||
m_browser = WebView::CreateWebView(this, web_hosting::bootstrap_url(), profile);
|
||||
m_browser->SetBackgroundColour(GetBackgroundColour());
|
||||
m_browser->AddUserScript(wxString::FromUTF8(WebViewHostDialog::theme_user_script()));
|
||||
m_browser->AddUserScript(wxString::FromUTF8(WebViewHostDialog::element_defaults_user_script()));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <wx/event.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/webview.h>
|
||||
|
||||
#include <optional>
|
||||
@@ -22,7 +23,7 @@ namespace Slic3r { namespace GUI {
|
||||
class WebPanel : public wxPanel
|
||||
{
|
||||
public:
|
||||
WebPanel(wxWindow* parent, const char* bridge_script);
|
||||
WebPanel(wxWindow* parent, const char* bridge_script, const wxString& profile = wxEmptyString);
|
||||
|
||||
protected:
|
||||
wxWebView* browser() const { return m_browser; }
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/Utils/MacDarkMode.hpp"
|
||||
|
||||
#include <libslic3r/Utils.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
@@ -10,8 +12,10 @@
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include <wx/chartype.h>
|
||||
#include <wx/setup.h>
|
||||
#include <wx/webview.h>
|
||||
#include <wx/string.h>
|
||||
@@ -81,6 +85,50 @@ webkit_get_minor_version (void);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Private storage root for an isolated (plugin) profile. Plugin pages must not reach the shared
|
||||
// default store's cookies/session (e.g. the OrcaCloud login), so each profile gets its own dir,
|
||||
// shared by every view of that profile. macOS isolates with an in-memory store instead (see
|
||||
// CreateWebView), so this is unused there.
|
||||
#if !defined(__WXOSX__)
|
||||
static wxString isolated_profile_path(const wxString& profile)
|
||||
{
|
||||
wxString safe;
|
||||
safe.reserve(profile.size());
|
||||
for (wxString::const_iterator it = profile.begin(); it != profile.end(); ++it) {
|
||||
const wxChar c = *it;
|
||||
const bool keep = (c >= wxT('a') && c <= wxT('z')) || (c >= wxT('A') && c <= wxT('Z')) ||
|
||||
(c >= wxT('0') && c <= wxT('9')) || c == wxT('.') || c == wxT('-') || c == wxT('_');
|
||||
safe += keep ? c : wxT('_');
|
||||
}
|
||||
if (safe.empty())
|
||||
safe = wxT("default");
|
||||
return wxString::FromUTF8((boost::filesystem::path(Slic3r::data_dir()) / "web_profiles" / safe.ToStdString()).string());
|
||||
}
|
||||
|
||||
// A profile's backend state - the cookie jar, storage and the live session - belongs to the object
|
||||
// wx builds from a wxWebViewConfiguration: the WebView2 environment on Windows, the
|
||||
// WebKitWebContext on Linux. One configuration per profile is therefore what lets two views of the
|
||||
// same plugin see each other's login; a configuration per view would share only the directory on
|
||||
// disk, not the session in memory.
|
||||
static const wxWebViewConfiguration& profile_configuration(const wxString& profile)
|
||||
{
|
||||
static std::map<wxString, wxWebViewConfiguration> configs;
|
||||
|
||||
const auto existing = configs.find(profile);
|
||||
if (existing != configs.end())
|
||||
return existing->second;
|
||||
|
||||
#if defined(__WIN32__)
|
||||
wxWebViewConfiguration config = wxWebView::NewConfiguration(wxWebViewBackendEdge);
|
||||
#else
|
||||
wxWebViewConfiguration config = wxWebView::NewConfiguration(wxWebViewBackendWebKit);
|
||||
#endif
|
||||
// Has to precede the first view, i.e. the environment/context built from the configuration.
|
||||
config.SetDataPath(isolated_profile_path(profile));
|
||||
return configs.emplace(profile, config).first->second;
|
||||
}
|
||||
#endif // !__WXOSX__
|
||||
|
||||
#ifdef __WIN32__
|
||||
// Run Download and Install in another thread so we don't block the UI thread
|
||||
DWORD DownloadAndInstallWV2RT() {
|
||||
@@ -144,6 +192,9 @@ DWORD DownloadAndInstallWV2RT() {
|
||||
class WebViewEdge : public wxWebViewEdge
|
||||
{
|
||||
public:
|
||||
WebViewEdge() = default;
|
||||
explicit WebViewEdge(const wxWebViewConfiguration& config) : wxWebViewEdge(config) {}
|
||||
|
||||
bool SetUserAgent(const wxString &userAgent) override
|
||||
{
|
||||
bool dark = userAgent.Contains("dark");
|
||||
@@ -222,6 +273,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
explicit WebViewWebKit(const wxWebViewConfiguration& config)
|
||||
: wxWebViewWebKit(config)
|
||||
{
|
||||
}
|
||||
|
||||
~WebViewWebKit() override
|
||||
{
|
||||
RemoveScriptMessageHandler("wx");
|
||||
@@ -310,7 +366,7 @@ static wxString linux_user_agent()
|
||||
}
|
||||
#endif
|
||||
|
||||
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url, wxString const & profile)
|
||||
{
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
// Check if a fixed version of edge is present in
|
||||
@@ -330,12 +386,38 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
if (!url2.empty()) { url2 = wxURI(url2).BuildURI(); }
|
||||
BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << ": " << url2.ToUTF8();
|
||||
|
||||
const bool isolated = !profile.IsEmpty();
|
||||
|
||||
#ifdef __WIN32__
|
||||
wxWebView* webView = new WebViewEdge;
|
||||
wxWebView* webView = nullptr;
|
||||
if (isolated) {
|
||||
// Reusing the configuration reuses its WebView2 environment, so every view of a profile
|
||||
// belongs to the same browser profile and a login in one view is visible in another.
|
||||
webView = new WebViewEdge(profile_configuration(profile));
|
||||
} else {
|
||||
webView = new WebViewEdge;
|
||||
}
|
||||
#elif defined(__WXOSX__)
|
||||
wxWebView* webView = new WebViewWebKit;
|
||||
wxWebView* webView = nullptr;
|
||||
if (isolated) {
|
||||
// wx has no SetDataPath on macOS, and WKWebView copies the configuration for each view
|
||||
// (wx's "wx" script message handler lives on that per-view copy), so the views keep one
|
||||
// configuration each and share a session through the profile's in-memory data store.
|
||||
wxWebViewConfiguration config = wxWebView::NewConfiguration(wxWebViewBackendWebKit);
|
||||
Slic3r::GUI::WKWebViewConfiguration_setSharedNonPersistentDataStore(config.GetNativeConfiguration(), profile);
|
||||
webView = new WebViewWebKit(config);
|
||||
} else {
|
||||
webView = new WebViewWebKit;
|
||||
}
|
||||
#else
|
||||
auto webView = wxWebView::New();
|
||||
wxWebView* webView = nullptr;
|
||||
if (isolated) {
|
||||
// Reusing the configuration reuses its WebKitWebContext, so every view of a profile shares
|
||||
// the same cookies, storage and live session.
|
||||
webView = wxWebView::New(profile_configuration(profile));
|
||||
} else {
|
||||
webView = wxWebView::New();
|
||||
}
|
||||
#endif
|
||||
if (webView) {
|
||||
webView->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
|
||||
@@ -353,14 +435,25 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
||||
#else
|
||||
// With WKWebView handlers need to be registered before creation.
|
||||
// On Linux (WebKit2GTK), URI schemes are registered globally and can only
|
||||
// be registered once, so guard against multiple registrations.
|
||||
#ifdef __linux__
|
||||
// WebKitGTK registers a URI scheme on a WebKitWebContext, once per context, and wx answers
|
||||
// a request through the view whose RegisterHandler() registered it. A view of the shared
|
||||
// store has a context of its own, so it registers here. The views of a profile share one
|
||||
// context, but registering from one of them would make every other view depend on that
|
||||
// view's lifetime and would give untrusted plugin pages the local-file access of "wxfs";
|
||||
// plugin pages load their own document only, so their context registers no scheme.
|
||||
if (!isolated) {
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
||||
}
|
||||
#else
|
||||
static bool s_schemes_registered = false;
|
||||
if (!s_schemes_registered) {
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
||||
s_schemes_registered = true;
|
||||
}
|
||||
#endif
|
||||
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
#ifdef __linux__
|
||||
webView->SetUserAgent(linux_user_agent());
|
||||
|
||||
@@ -14,7 +14,12 @@ wxDECLARE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent);
|
||||
class WebView
|
||||
{
|
||||
public:
|
||||
static wxWebView *CreateWebView(wxWindow *parent, wxString const &url);
|
||||
// `profile` empty -> the shared default backend store used by all trusted UI.
|
||||
// `profile` non-empty -> a private store keyed by `profile`, so this view shares no
|
||||
// cookies/storage/session with the shared store or any other profile. Views created
|
||||
// with the same `profile` share one store, and therefore one live session. Used for
|
||||
// plugin-supplied (untrusted) content.
|
||||
static wxWebView *CreateWebView(wxWindow *parent, wxString const &url, wxString const &profile = wxEmptyString);
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
static bool CheckWebViewRuntime();
|
||||
static bool DownloadAndInstallWebViewRuntime();
|
||||
|
||||
@@ -172,7 +172,8 @@ WebViewHostDialog::WebViewHostDialog(wxWindow* parent,
|
||||
bool WebViewHostDialog::create_webview(const std::string& resource_path,
|
||||
const wxString& title,
|
||||
const wxSize& dialog_size,
|
||||
const wxSize& min_size)
|
||||
const wxSize& min_size,
|
||||
const wxString& profile)
|
||||
{
|
||||
SetTitle(title);
|
||||
SetMinSize(FromDIP(min_size));
|
||||
@@ -181,7 +182,7 @@ bool WebViewHostDialog::create_webview(const std::string& resource_path,
|
||||
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
// Created empty and loaded below, after the user scripts are added, so the first load already has them.
|
||||
m_browser = WebView::CreateWebView(this, wxEmptyString);
|
||||
m_browser = WebView::CreateWebView(this, wxEmptyString, profile);
|
||||
if (m_browser == nullptr) {
|
||||
wxLogError("Could not init m_browser");
|
||||
delete topsizer;
|
||||
|
||||
@@ -38,7 +38,8 @@ public:
|
||||
bool create_webview(const std::string& resource_path,
|
||||
const wxString& title,
|
||||
const wxSize& dialog_size = wxSize(820, 660),
|
||||
const wxSize& min_size = wxSize(640, 640));
|
||||
const wxSize& min_size = wxSize(640, 640),
|
||||
const wxString& profile = wxEmptyString);
|
||||
|
||||
void load_url(const wxString& url);
|
||||
bool run_script(const wxString& script);
|
||||
|
||||
@@ -12,6 +12,7 @@ extern double mac_max_scaling_factor();
|
||||
extern void set_miniaturizable(void * window);
|
||||
void WKWebView_evaluateJavaScript(void * web, wxString const & script, void (*callback)(wxString const &));
|
||||
void WKWebView_setTransparentBackground(void * web);
|
||||
void WKWebViewConfiguration_setSharedNonPersistentDataStore(void * configuration, const wxString & profile);
|
||||
void WKWebView_force_display(void * web);
|
||||
void set_tag_when_enter_full_screen(bool isfullscreen);
|
||||
void set_title_colour_after_set_title(void * window);
|
||||
|
||||
@@ -102,6 +102,30 @@ void WKWebView_setTransparentBackground(void * web)
|
||||
[webView registerForDraggedTypes: @[NSFilenamesPboardType]];
|
||||
}
|
||||
|
||||
// Give a WKWebViewConfiguration the in-memory website data store of its profile, so the views of
|
||||
// one profile share that store's cookies and storage without any of it reaching the disk or the
|
||||
// default store. Views share a session only through a common store, and
|
||||
// +nonPersistentDataStore makes a new one on every call, so one store is kept per profile for the
|
||||
// process lifetime. Used to isolate plugin web views.
|
||||
void WKWebViewConfiguration_setSharedNonPersistentDataStore(void * configuration, const wxString & profile)
|
||||
{
|
||||
static NSMutableDictionary<NSString *, WKWebsiteDataStore *> * stores = nil;
|
||||
if (stores == nil)
|
||||
stores = [[NSMutableDictionary alloc] init];
|
||||
|
||||
wxCFStringRef key_ref(profile);
|
||||
NSString * key = key_ref.AsNSString();
|
||||
WKWebsiteDataStore * store = [stores objectForKey:key];
|
||||
if (store == nil) {
|
||||
store = [WKWebsiteDataStore nonPersistentDataStore];
|
||||
[stores setObject:store forKey:key];
|
||||
}
|
||||
|
||||
WKWebViewConfiguration * config = (WKWebViewConfiguration*)configuration;
|
||||
if (config)
|
||||
config.websiteDataStore = store;
|
||||
}
|
||||
|
||||
// Force a WKWebView to re-lay-out and repaint. Needed for chrome-less popups: the window is
|
||||
// transparent, so a WKWebView whose layer has no pending frame leaves the whole window invisible
|
||||
// until the user generates input (scroll/arrow). setNeedsDisplay alone does not always reach the
|
||||
|
||||
@@ -890,8 +890,10 @@ std::vector<std::string> PluginAuditManager::default_denied_path_keywords()
|
||||
// resources_dir()/cert/..., which would become reachable the moment resources_dir() is
|
||||
// granted as a read-only allowed root). Match as whole path components, not substrings, so
|
||||
// imports such as numpy/__config__.py and stdlib configparser.py remain usable. Inside
|
||||
// data_dir() they match below that root only; see is_denied_path_keyword().
|
||||
return {"secret", "secrets", "cert", "certs", "certificate", "certificates", "conf", "config"};
|
||||
// data_dir() they match below that root only; see is_denied_path_keyword(). The WebView
|
||||
// browser profiles are host-managed storage and must not be reachable through the broad
|
||||
// data_dir() grant given to plugins (see Widgets/WebView.cpp:87-105).
|
||||
return {"secret", "secrets", "cert", "certs", "certificate", "certificates", "conf", "config", "web_profiles"};
|
||||
}
|
||||
|
||||
static bool has_denied_config_extension(std::string name)
|
||||
|
||||
@@ -89,15 +89,20 @@ CallablePtr make_holder(py::object obj)
|
||||
|
||||
// Adapt a Python callable to a GUI message handler that acquires the GIL and
|
||||
// swallows/logs exceptions (a raising handler must not escape into wx events).
|
||||
GUI::WebDialog::MessageHandler make_message_adapter(py::object on_message)
|
||||
//
|
||||
// The handler runs later, from a wx event with no plugin call on the stack, so it restores the
|
||||
// plugin's audit context captured at registration. Without that scope, audit events raised by
|
||||
// the callback would be unattributed and allowed, like host code.
|
||||
GUI::WebDialog::MessageHandler make_message_adapter(py::object on_message, std::string plugin_key)
|
||||
{
|
||||
CallablePtr holder = make_holder(std::move(on_message));
|
||||
if (!holder)
|
||||
return nullptr;
|
||||
return [holder](const json& data) {
|
||||
return [holder, plugin_key = std::move(plugin_key)](const json& data) {
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn(json_to_py(data));
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -107,15 +112,16 @@ GUI::WebDialog::MessageHandler make_message_adapter(py::object on_message)
|
||||
};
|
||||
}
|
||||
|
||||
GUI::WebDialog::SubmitHandler make_submit_adapter(py::object on_submit)
|
||||
GUI::WebDialog::SubmitHandler make_submit_adapter(py::object on_submit, std::string plugin_key)
|
||||
{
|
||||
CallablePtr holder = make_holder(std::move(on_submit));
|
||||
if (!holder)
|
||||
return nullptr;
|
||||
return [holder](const json& data) {
|
||||
return [holder, plugin_key = std::move(plugin_key)](const json& data) {
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn(json_to_py(data));
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -127,14 +133,15 @@ GUI::WebDialog::SubmitHandler make_submit_adapter(py::object on_submit)
|
||||
|
||||
// The plugin's on_close: fired only on a user/JS-initiated close (not forced teardown), while the
|
||||
// window is alive. Empty if the plugin passed None.
|
||||
std::function<void()> make_close_adapter(const CallablePtr& holder)
|
||||
std::function<void()> make_close_adapter(const CallablePtr& holder, std::string plugin_key)
|
||||
{
|
||||
if (!holder)
|
||||
return nullptr;
|
||||
return [holder]() {
|
||||
return [holder, plugin_key = std::move(plugin_key)]() {
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn();
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -144,6 +151,17 @@ std::function<void()> make_close_adapter(const CallablePtr& holder)
|
||||
};
|
||||
}
|
||||
|
||||
// A window or panel is untrusted plugin content, isolated by a per-plugin webview profile.
|
||||
// An empty key would fall back to the shared profile used by trusted host UI, so refuse it
|
||||
// instead of creating a window that silently shares the host's cookies and session.
|
||||
std::string plugin_identity_for_ui(const char* api_name)
|
||||
{
|
||||
std::string plugin_key = PluginAuditManager::instance().current_plugin();
|
||||
if (plugin_key.empty())
|
||||
throw std::runtime_error(std::string(api_name) + " must be called from a plugin callback");
|
||||
return plugin_key;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Registry of live plugin UI resources. Keyed by an opaque id; tracks the
|
||||
// owning plugin so all of a plugin's UI can be torn down on unload.
|
||||
@@ -373,13 +391,6 @@ struct UiProgressHandle
|
||||
py::object ui_create_window(const std::string& html, const std::string& title, int width, int height,
|
||||
py::object on_message, py::object on_close, long style, py::object on_submit)
|
||||
{
|
||||
auto msg_adapter = make_message_adapter(std::move(on_message));
|
||||
auto submit_adapter = make_submit_adapter(std::move(on_submit));
|
||||
CallablePtr close_holder = make_holder(std::move(on_close));
|
||||
const std::string plugin_key = PluginAuditManager::instance().current_plugin();
|
||||
const int w = width > 0 ? width : 820;
|
||||
const int h = height > 0 ? height : 600;
|
||||
|
||||
if ((style & ~WINDOW_MODAL) != 0)
|
||||
throw std::invalid_argument("unsupported orca.host.ui.create_window style flags");
|
||||
const bool modal = (style & WINDOW_MODAL) != 0;
|
||||
@@ -387,6 +398,14 @@ py::object ui_create_window(const std::string& html, const std::string& title, i
|
||||
if (wxTheApp == nullptr)
|
||||
throw std::runtime_error("OrcaSlicer application is not initialized");
|
||||
|
||||
const std::string plugin_key = plugin_identity_for_ui("orca.host.ui.create_window");
|
||||
const int w = width > 0 ? width : 820;
|
||||
const int h = height > 0 ? height : 600;
|
||||
|
||||
auto msg_adapter = make_message_adapter(std::move(on_message), plugin_key);
|
||||
auto submit_adapter = make_submit_adapter(std::move(on_submit), plugin_key);
|
||||
CallablePtr close_holder = make_holder(std::move(on_close));
|
||||
|
||||
// The whole wxWindow/webview creation is deferred to a clean main-loop iteration.
|
||||
// The WebKit backends deliver script messages synchronously from inside the native
|
||||
// callback (GTK: HandleWindowEvent in wxgtk_webview_webkit_script_message_received,
|
||||
@@ -415,13 +434,14 @@ py::object ui_create_window(const std::string& html, const std::string& title, i
|
||||
if (!UiRegistry::instance().is_open(new_id))
|
||||
return;
|
||||
|
||||
GUI::WebDialog::CloseHandler on_close = make_close_adapter(close_holder);
|
||||
GUI::WebDialog::CloseHandler on_close = make_close_adapter(close_holder, plugin_key);
|
||||
// Registry cleanup: GIL-free, runs from the dialog destructor on every path.
|
||||
auto on_destroyed = [new_id]() { UiRegistry::instance().remove(new_id); };
|
||||
|
||||
auto* dlg = new GUI::WebDialog(ui_parent(), wxString::FromUTF8(title), html,
|
||||
wxSize(w, h), std::move(msg_adapter), std::move(submit_adapter),
|
||||
std::move(on_close), std::move(on_destroyed), PLUGIN_WX_STYLE);
|
||||
std::move(on_close), std::move(on_destroyed), PLUGIN_WX_STYLE,
|
||||
wxString::FromUTF8(plugin_key));
|
||||
UiRegistry::instance().bind(new_id, dlg, plugin_key);
|
||||
if (modal) {
|
||||
dlg->ShowModal();
|
||||
@@ -492,15 +512,16 @@ py::object ui_create_dock_panel(const std::string& html, const std::string& titl
|
||||
if (std::find(std::begin(DOCK_POSITIONS), std::end(DOCK_POSITIONS), dock) == std::end(DOCK_POSITIONS))
|
||||
throw std::invalid_argument("orca.host.ui.create_dock_panel dock must be \"left\", \"right\", \"bottom\" or \"float\"");
|
||||
|
||||
auto msg_adapter = make_message_adapter(std::move(on_message));
|
||||
CallablePtr close_holder = make_holder(std::move(on_close));
|
||||
const std::string plugin_key = PluginAuditManager::instance().current_plugin();
|
||||
const int w = width > 0 ? width : 320;
|
||||
const int h = height > 0 ? height : 480;
|
||||
|
||||
if (wxTheApp == nullptr)
|
||||
throw std::runtime_error("OrcaSlicer application is not initialized");
|
||||
|
||||
const std::string plugin_key = plugin_identity_for_ui("orca.host.ui.create_dock_panel");
|
||||
const int w = width > 0 ? width : 320;
|
||||
const int h = height > 0 ? height : 480;
|
||||
|
||||
auto msg_adapter = make_message_adapter(std::move(on_message), plugin_key);
|
||||
CallablePtr close_holder = make_holder(std::move(on_close));
|
||||
|
||||
// Deferred and pre-bound for the same reasons as create_window().
|
||||
const int new_id = UiRegistry::instance().reserve_id();
|
||||
UiRegistry::instance().bind(new_id, nullptr, plugin_key);
|
||||
@@ -517,8 +538,8 @@ py::object ui_create_dock_panel(const std::string& html, const std::string& titl
|
||||
}
|
||||
|
||||
auto on_destroyed = [new_id]() { UiRegistry::instance().remove(new_id); };
|
||||
auto* panel = new GUI::DockPanel(plater, html, std::move(msg_adapter), make_close_adapter(close_holder),
|
||||
std::move(on_destroyed));
|
||||
auto* panel = new GUI::DockPanel(plater, html, std::move(msg_adapter), make_close_adapter(close_holder, plugin_key),
|
||||
std::move(on_destroyed), wxString::FromUTF8(plugin_key));
|
||||
UiRegistry::instance().bind(new_id, panel, plugin_key);
|
||||
plater->add_dock_pane(panel, GUI::plugin_pane_name(plugin_key, title), wxString::FromUTF8(title), dock,
|
||||
wxSize(w, h), [panel]() { panel->fire_close(); });
|
||||
@@ -640,18 +661,26 @@ void plater_notification(GUI::NotificationManager::NotificationLevel notificatio
|
||||
{
|
||||
const std::string plugin_key = PluginAuditManager::instance().current_plugin();
|
||||
CallablePtr holder = make_holder(std::move(on_click));
|
||||
if (holder)
|
||||
if (holder) {
|
||||
// The click runs later, from a wx event with no plugin call on the stack. Without an
|
||||
// identity there is no audit context to restore, so refuse the callback rather than run
|
||||
// plugin code unattributed and allowed like host code. A notification with no callback
|
||||
// keeps its previous behavior.
|
||||
if (plugin_key.empty())
|
||||
throw std::runtime_error("orca.host.ui.push_notification on_click must be called from a plugin callback");
|
||||
UiRegistry::instance().bind_callback(holder, plugin_key);
|
||||
}
|
||||
|
||||
std::function<bool(wxEvtHandler*)> callback;
|
||||
if (holder) {
|
||||
callback = [holder](wxEvtHandler*) -> bool {
|
||||
callback = [holder, plugin_key](wxEvtHandler*) -> bool {
|
||||
if (!holder->active.load(std::memory_order_acquire))
|
||||
return false;
|
||||
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return false;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
py::object result = holder->fn();
|
||||
return result.is_none() || result.cast<bool>();
|
||||
|
||||
@@ -78,7 +78,8 @@ constexpr char PLUGIN_PAGE_BRIDGE_JS[] = R"JS(
|
||||
} // namespace
|
||||
|
||||
PluginPage::PluginPage(wxWindow* parent, std::shared_ptr<PagesPluginCapability> capability)
|
||||
: GUI::WebPanel(parent, PLUGIN_PAGE_BRIDGE_JS)
|
||||
: GUI::WebPanel(parent, PLUGIN_PAGE_BRIDGE_JS,
|
||||
wxString::FromUTF8(capability ? capability->identity().plugin_key : std::string()))
|
||||
, m_cap(std::move(capability))
|
||||
, m_lifetime(std::make_shared<std::atomic<PluginPage*>>(this))
|
||||
{
|
||||
|
||||
@@ -1118,6 +1118,22 @@ TEST_CASE("Plugin audit checks denied keywords below data_dir, not in the direct
|
||||
CHECK(decision.reason == "denied path keyword");
|
||||
}
|
||||
|
||||
SECTION("host-managed browser profiles are blocked despite the allowed root")
|
||||
{
|
||||
const fs::path browser_cookie = flatpak_data_dir / "web_profiles" / "example_plugin" / "Cookies";
|
||||
|
||||
AuditDecision read_decision = mgr.check_open(browser_cookie.string(), "r");
|
||||
CHECK_FALSE(read_decision.allowed);
|
||||
CHECK(read_decision.reason == "denied path keyword");
|
||||
|
||||
AuditDecision write_decision = mgr.check_open(browser_cookie.string(), "w");
|
||||
CHECK_FALSE(write_decision.allowed);
|
||||
CHECK(write_decision.reason == "denied path keyword");
|
||||
|
||||
// The rule is scoped to the host-owned browser subtree, not normal plugin storage.
|
||||
CHECK(mgr.check_open((flatpak_data_dir / "orca_plugins" / "test_plugin" / "state.json").string(), "w").allowed);
|
||||
}
|
||||
|
||||
SECTION("the app config below data_dir() is still denied by name")
|
||||
{
|
||||
AuditDecision decision = mgr.check_open((flatpak_data_dir / (SLIC3R_APP_KEY ".conf")).string(), "r");
|
||||
|
||||
Reference in New Issue
Block a user