forked from upstream-mirrors/OrcaSlicer
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bff760df7 | |||
| a7e146786f | |||
| b8069c37df | |||
| fc2a88ba72 | |||
| 113b42da33 | |||
| e740246f7e | |||
| 20c01cfc7e | |||
| 3ba5ddfe19 | |||
| 83de33416e | |||
| 15030ef560 | |||
| b29f06a0ab | |||
| 9ec0d39592 | |||
| 0b9b05ed85 |
@@ -372,6 +372,7 @@ src/slic3r/Utils/MoonrakerPrinterAgent.cpp
|
||||
src/slic3r/Utils/BBLNetworkPlugin.cpp
|
||||
src/slic3r/Utils/OrcaCloudServiceAgent.cpp
|
||||
src/slic3r/plugin/PluginAuditManager.cpp
|
||||
src/slic3r/plugin/PluginBrowserProfile.cpp
|
||||
src/slic3r/plugin/PluginConfig.cpp
|
||||
src/slic3r/plugin/PluginResolver.cpp
|
||||
src/slic3r/plugin/CloudPluginService.cpp
|
||||
|
||||
@@ -709,6 +709,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
plugin/host/PluginResourceTextures.hpp
|
||||
plugin/CloudPluginService.cpp
|
||||
plugin/CloudPluginService.hpp
|
||||
plugin/PluginBrowserProfile.cpp
|
||||
plugin/PluginBrowserProfile.hpp
|
||||
plugin/PluginFsUtils.cpp
|
||||
plugin/PluginFsUtils.hpp
|
||||
plugin/PluginJsonPy.hpp
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -114,6 +114,15 @@ public:
|
||||
bool pending() const override { return !built() && !m_failed; }
|
||||
int prebuild_order() const override { return m_order; }
|
||||
|
||||
// A null factory result marks the object failed. LazyPage lets the next explicit show retry
|
||||
// a transient failure (for example a plugin profile lease held by another instance).
|
||||
bool failed() const { return m_failed; }
|
||||
void reset_failed()
|
||||
{
|
||||
if (!built())
|
||||
m_failed = false;
|
||||
}
|
||||
|
||||
// The factory is the first unit, then one StagedBuild step each. A unit that pumps the
|
||||
// event loop cannot re-enter; a nested call does nothing.
|
||||
bool build_step() override
|
||||
|
||||
@@ -28,10 +28,12 @@ public:
|
||||
LazyPage(wxWindow* parent, std::string name, int order, Factory make = [](wxWindow* parent) { return new Panel(parent); })
|
||||
: wxPanel(parent), Lazy<Panel>(std::move(name), order, [this, make = std::move(make)] {
|
||||
Panel* panel = make(this);
|
||||
GetSizer()->Add(panel, 1, wxEXPAND);
|
||||
// Hidden while its page is, as an inserted page would be.
|
||||
if (!IsShown())
|
||||
panel->Hide();
|
||||
if (panel != nullptr) {
|
||||
GetSizer()->Add(panel, 1, wxEXPAND);
|
||||
// Hidden while its page is, as an inserted page would be.
|
||||
if (!IsShown())
|
||||
panel->Hide();
|
||||
}
|
||||
return panel;
|
||||
})
|
||||
{
|
||||
@@ -61,8 +63,11 @@ public:
|
||||
// Built before this page is shown, as an idle prebuild builds it. On MSW every control
|
||||
// created or moved inside a shown window re-clips and repaints its shown siblings, so
|
||||
// building a large panel into a shown page took seconds.
|
||||
if (show && wxGetTopLevelParent(this)->IsShown())
|
||||
if (show && wxGetTopLevelParent(this)->IsShown()) {
|
||||
if (!this->built() && this->failed())
|
||||
this->reset_failed();
|
||||
this->ensure();
|
||||
}
|
||||
const bool changed = wxPanel::Show(show);
|
||||
if (show) {
|
||||
// The book shows its first page as it is inserted, before startup has chosen the
|
||||
|
||||
@@ -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,74 @@ 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 std::map<wxString, wxWebViewConfiguration>& profile_configurations()
|
||||
{
|
||||
static std::map<wxString, wxWebViewConfiguration> configs;
|
||||
return configs;
|
||||
}
|
||||
|
||||
static const wxWebViewConfiguration& profile_configuration(const wxString& profile)
|
||||
{
|
||||
auto& configs = profile_configurations();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Erase the cached configuration, which owns the WebView2 environment / WebKitWebContext. The
|
||||
// caller must have destroyed every view of the profile first.
|
||||
static void release_profile_configuration(const wxString& profile)
|
||||
{
|
||||
profile_configurations().erase(profile);
|
||||
}
|
||||
#endif // !__WXOSX__
|
||||
|
||||
void WebView::ReleaseProfile(const wxString& profile)
|
||||
{
|
||||
#if !defined(__WXOSX__)
|
||||
release_profile_configuration(profile);
|
||||
#else
|
||||
// Drop the shared in-memory website data store for this profile. Views must already be gone;
|
||||
// the caller holds the profile lease until the last view is destroyed.
|
||||
Slic3r::GUI::WKWebViewConfiguration_releaseSharedNonPersistentDataStore(profile);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
// Run Download and Install in another thread so we don't block the UI thread
|
||||
DWORD DownloadAndInstallWV2RT() {
|
||||
@@ -144,6 +216,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 +297,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
explicit WebViewWebKit(const wxWebViewConfiguration& config)
|
||||
: wxWebViewWebKit(config)
|
||||
{
|
||||
}
|
||||
|
||||
~WebViewWebKit() override
|
||||
{
|
||||
RemoveScriptMessageHandler("wx");
|
||||
@@ -310,7 +390,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 +410,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 +459,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,16 @@ 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);
|
||||
|
||||
// Drops the cached configuration/environment for an isolated profile. Call on the GUI thread
|
||||
// after every view of it has been destroyed. Needed before deleting the profile directory.
|
||||
static void ReleaseProfile(const wxString& profile);
|
||||
#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,8 @@ 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 WKWebViewConfiguration_releaseSharedNonPersistentDataStore(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,44 @@ 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.
|
||||
static NSMutableDictionary<NSString *, WKWebsiteDataStore *> * sharedNonPersistentStores()
|
||||
{
|
||||
static NSMutableDictionary<NSString *, WKWebsiteDataStore *> * stores = nil;
|
||||
if (stores == nil)
|
||||
stores = [[NSMutableDictionary alloc] init];
|
||||
return stores;
|
||||
}
|
||||
|
||||
void WKWebViewConfiguration_setSharedNonPersistentDataStore(void * configuration, const wxString & profile)
|
||||
{
|
||||
wxCFStringRef key_ref(profile);
|
||||
NSString * key = key_ref.AsNSString();
|
||||
NSMutableDictionary<NSString *, WKWebsiteDataStore *> * stores = sharedNonPersistentStores();
|
||||
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;
|
||||
}
|
||||
|
||||
// Drops the profile's in-memory store once every view using it has been destroyed. Without this,
|
||||
// a deleted/reinstalled plugin's old cookie/session store would stay alive for the process
|
||||
// lifetime because the profile id is never reused.
|
||||
void WKWebViewConfiguration_releaseSharedNonPersistentDataStore(const wxString & profile)
|
||||
{
|
||||
wxCFStringRef key_ref(profile);
|
||||
[sharedNonPersistentStores() removeObjectForKey:key_ref.AsNSString()];
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <slic3r/GUI/GUI_App.hpp>
|
||||
#include <slic3r/GUI/MsgDialog.hpp>
|
||||
#include <slic3r/GUI/format.hpp>
|
||||
#include <slic3r/plugin/PluginBrowserProfile.hpp>
|
||||
#include <slic3r/plugin/PluginFsUtils.hpp>
|
||||
#include <slic3r/plugin/PluginManager.hpp>
|
||||
#include <string>
|
||||
@@ -890,8 +891,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)
|
||||
@@ -2288,12 +2291,20 @@ void seed_install_metadata(const PluginDescriptor& descriptor, PluginInstallStat
|
||||
state.enabled = true;
|
||||
}
|
||||
|
||||
bool audit_state_belongs_to_loaded_identity(const std::string& plugin_key, const std::string& plugin_root,
|
||||
const std::string& installation_revision);
|
||||
|
||||
// Serialize the sidecar read-modify-write against every other writer. The lock is taken before
|
||||
// the descriptor lookup, keeping the shared install-state -> PluginManager::m_mutex order.
|
||||
bool persist_permission(const std::string& plugin_key, AuditEventCategory category, bool by_event,
|
||||
const std::string& target)
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << lock_error;
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
if (!PluginManager::instance().try_get_plugin_descriptor(plugin_key, descriptor) || descriptor.plugin_root.empty())
|
||||
@@ -2305,6 +2316,11 @@ bool persist_permission(const std::string& plugin_key, AuditEventCategory catego
|
||||
// existing sidecar that cannot be read must not be replaced, or its grants would be lost.
|
||||
if (read_install_state_status(root, state) == InstallStateReadStatus::Unreadable)
|
||||
return false;
|
||||
if (!audit_state_belongs_to_loaded_identity(plugin_key, descriptor.plugin_root, state.installation_revision)) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "[AUDIT] Refusing to persist a grant for a replaced installation: "
|
||||
<< plugin_key;
|
||||
return false;
|
||||
}
|
||||
seed_install_metadata(descriptor, state);
|
||||
|
||||
std::vector<std::string>* permission_list = permission_list_for(category, by_event, state.permissions);
|
||||
@@ -2330,7 +2346,12 @@ bool persist_permission(const std::string& plugin_key, AuditEventCategory catego
|
||||
// Threading is a boolean grant, so it has no target list to append to.
|
||||
bool persist_threading_grant(const std::string& plugin_key)
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << lock_error;
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
if (!PluginManager::instance().try_get_plugin_descriptor(plugin_key, descriptor) || descriptor.plugin_root.empty())
|
||||
@@ -2341,6 +2362,11 @@ bool persist_threading_grant(const std::string& plugin_key)
|
||||
// Same rule as persist_permission: seed a missing sidecar, never replace an unreadable one.
|
||||
if (read_install_state_status(root, state) == InstallStateReadStatus::Unreadable)
|
||||
return false;
|
||||
if (!audit_state_belongs_to_loaded_identity(plugin_key, descriptor.plugin_root, state.installation_revision)) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "[AUDIT] Refusing to persist a threading grant for a replaced installation: "
|
||||
<< plugin_key;
|
||||
return false;
|
||||
}
|
||||
seed_install_metadata(descriptor, state);
|
||||
state.permissions.threading = true;
|
||||
return write_install_state(root, state);
|
||||
@@ -2823,6 +2849,16 @@ bool request_recursive_delete_consent(const std::string& plugin_key, const std::
|
||||
return finish_audit_prompt(nullptr, granted && recursive_delete_generation(plugin_key) == generation);
|
||||
}
|
||||
|
||||
// Audit state must belong to the loaded installation, not a replacement installed by another
|
||||
// process under the same plugin key. A missing identity is a fail-closed denial.
|
||||
bool audit_state_belongs_to_loaded_identity(const std::string& plugin_key, const std::string& plugin_root,
|
||||
const std::string& installation_revision)
|
||||
{
|
||||
const PluginBrowserProfileIdentityRef identity = current_plugin_browser_profile_identity(plugin_key);
|
||||
return identity && !identity->installation_revision.empty() && identity->plugin_root == plugin_root &&
|
||||
identity->installation_revision == installation_revision;
|
||||
}
|
||||
|
||||
// Records a grant in the plugin's sidecar so it is not asked again. Each persist helper re-reads
|
||||
// the sidecar under the shared lock, because the async prompt outlives the caller's copy of it.
|
||||
// Returns true when at least one write succeeded, and only then notifies an existing Plugins
|
||||
@@ -2859,7 +2895,12 @@ bool persist_declared_permissions(const std::string& plugin_key, const std::vect
|
||||
|
||||
bool persisted = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << lock_error;
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginInstallState state;
|
||||
const boost::filesystem::path root(descriptor.plugin_root);
|
||||
@@ -2870,6 +2911,11 @@ bool persist_declared_permissions(const std::string& plugin_key, const std::vect
|
||||
return false;
|
||||
if (status == InstallStateReadStatus::Absent && sidecar_was_readable)
|
||||
return false;
|
||||
if (!audit_state_belongs_to_loaded_identity(plugin_key, descriptor.plugin_root, state.installation_revision)) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "[AUDIT] Refusing to persist declared permissions for a replaced installation: "
|
||||
<< plugin_key;
|
||||
return false;
|
||||
}
|
||||
|
||||
seed_install_metadata(descriptor, state);
|
||||
for (const AuditPromptBucket& bucket : buckets) {
|
||||
@@ -3351,7 +3397,12 @@ bool authorize_hardlink_source(PluginAuditManager& mgr, const std::string& event
|
||||
return true;
|
||||
|
||||
PluginInstallState state;
|
||||
const bool have_state = PluginManager::instance().get_install_state(mgr.current_plugin(), state);
|
||||
PluginDescriptor descriptor;
|
||||
const bool have_state =
|
||||
PluginManager::instance().get_install_state(mgr.current_plugin(), state) &&
|
||||
PluginManager::instance().try_get_plugin_descriptor(mgr.current_plugin(), descriptor) &&
|
||||
audit_state_belongs_to_loaded_identity(mgr.current_plugin(), descriptor.plugin_root,
|
||||
state.installation_revision);
|
||||
if (have_state && state.permissions.full_access)
|
||||
return true;
|
||||
if (have_state &&
|
||||
@@ -3469,9 +3520,15 @@ int audit_plugin_event(PluginAuditManager& mgr, const std::string& event_name, A
|
||||
}
|
||||
|
||||
PluginInstallState state;
|
||||
const bool have_install_state = PluginManager::instance().get_install_state(mgr.current_plugin(), state);
|
||||
PluginDescriptor descriptor;
|
||||
const bool have_install_state =
|
||||
PluginManager::instance().get_install_state(mgr.current_plugin(), state) &&
|
||||
PluginManager::instance().try_get_plugin_descriptor(mgr.current_plugin(), descriptor) &&
|
||||
audit_state_belongs_to_loaded_identity(mgr.current_plugin(), descriptor.plugin_root,
|
||||
state.installation_revision);
|
||||
if (!have_install_state) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " Failed to get install state for " << mgr.current_plugin();
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " Refusing install state for a missing or replaced installation: "
|
||||
<< mgr.current_plugin();
|
||||
}
|
||||
|
||||
const std::string plugin_name = state.plugin_name.empty() ? mgr.current_plugin() : state.plugin_name;
|
||||
@@ -3742,7 +3799,12 @@ bool PluginAuditManager::request_permissions(const std::string& plugin_key, cons
|
||||
PluginInstallState state;
|
||||
InstallStateReadStatus state_status;
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << lock_error;
|
||||
return false;
|
||||
}
|
||||
state_status = read_install_state_status(boost::filesystem::path(descriptor.plugin_root), state);
|
||||
}
|
||||
|
||||
@@ -3751,6 +3813,10 @@ bool PluginAuditManager::request_permissions(const std::string& plugin_key, cons
|
||||
// that has not been given one yet and is seeded when the grant is saved.
|
||||
if (state_status == InstallStateReadStatus::Unreadable)
|
||||
return false;
|
||||
if (!PluginAuditDetail::audit_state_belongs_to_loaded_identity(plugin_key, descriptor.plugin_root, state.installation_revision)) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "[AUDIT] Refusing to read permissions for a replaced installation: " << plugin_key;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Full access is an explicit opt-out of auditing: a declaration neither prompts nor adds a
|
||||
// grant. Only a readable sidecar that stores the flag counts, so a missing file is never
|
||||
|
||||
@@ -0,0 +1,727 @@
|
||||
#include "PluginBrowserProfile.hpp"
|
||||
|
||||
#include "PluginDescriptor.hpp"
|
||||
#include "PluginFsUtils.hpp"
|
||||
#include "PluginManager.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
#include "slic3r/GUI/MsgDialog.hpp"
|
||||
#include "slic3r/GUI/PluginsDialog.hpp"
|
||||
#include "slic3r/GUI/Widgets/WebView.hpp"
|
||||
#include "slic3r/GUI/format.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/nowide/convert.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/thread.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/toplevel.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
// boost::filesystem::exists() may surface a missing path as an error on some Windows
|
||||
// configurations. Treat only genuine file/path-not-found as absence; every other error is a
|
||||
// real failure and must still be reported.
|
||||
bool is_path_not_found(const boost::system::error_code& ec)
|
||||
{
|
||||
if (!ec)
|
||||
return false;
|
||||
if (ec == boost::system::errc::no_such_file_or_directory)
|
||||
return true;
|
||||
#ifdef _WIN32
|
||||
if (ec.category() == boost::system::system_category()) {
|
||||
const DWORD code = static_cast<DWORD>(ec.value());
|
||||
return code == ERROR_FILE_NOT_FOUND || code == ERROR_PATH_NOT_FOUND;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
fs::path profiles_root()
|
||||
{
|
||||
return fs::path(Slic3r::data_dir()) / "web_profiles";
|
||||
}
|
||||
|
||||
// Same sanitizer the base WebView::isolated_profile_path uses, so the old plugin-key-named
|
||||
// directory can be reported exactly.
|
||||
std::string sanitize_profile_name(const std::string& profile)
|
||||
{
|
||||
std::string safe;
|
||||
safe.reserve(profile.size());
|
||||
for (unsigned char ch : profile) {
|
||||
const bool keep = std::isalnum(ch) != 0 || ch == '.' || ch == '-' || ch == '_';
|
||||
safe += keep ? static_cast<char>(ch) : '_';
|
||||
}
|
||||
return safe.empty() ? std::string("default") : safe;
|
||||
}
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
fs::path lease_path(const std::string& profile_id)
|
||||
{
|
||||
return profiles_root() / (".lease-" + profile_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Non-blocking cross-process lock. Deliberately not InstanceLock: a lease is held across UI
|
||||
// lifetimes and may be released on a different thread.
|
||||
class ProfileFileLock
|
||||
{
|
||||
public:
|
||||
ProfileFileLock() = default;
|
||||
~ProfileFileLock() { close(); }
|
||||
ProfileFileLock(const ProfileFileLock&) = delete;
|
||||
ProfileFileLock& operator=(const ProfileFileLock&) = delete;
|
||||
|
||||
bool open(const std::string& path)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
const std::wstring wide = boost::nowide::widen(path);
|
||||
HANDLE handle = ::CreateFileW(wide.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
m_handle = handle;
|
||||
#elif !defined(__APPLE__)
|
||||
m_fd = ::open(path.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0644);
|
||||
if (m_fd < 0)
|
||||
return false;
|
||||
if (::flock(m_fd, LOCK_EX | LOCK_NB) != 0) {
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void) path; // in-memory store; no cross-process disk lease
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (m_handle != nullptr) {
|
||||
::CloseHandle(static_cast<HANDLE>(m_handle));
|
||||
m_handle = nullptr;
|
||||
}
|
||||
#elif !defined(__APPLE__)
|
||||
if (m_fd >= 0) {
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(_WIN32)
|
||||
void* m_handle{nullptr};
|
||||
#elif !defined(__APPLE__)
|
||||
int m_fd{-1};
|
||||
#endif
|
||||
};
|
||||
|
||||
struct LeaseState
|
||||
{
|
||||
ProfileFileLock lock;
|
||||
};
|
||||
|
||||
struct LeaseEntry
|
||||
{
|
||||
std::shared_ptr<LeaseState> lease;
|
||||
unsigned uses{0};
|
||||
bool releasing{false};
|
||||
};
|
||||
|
||||
std::mutex& leases_mutex()
|
||||
{
|
||||
static auto* mutex = new std::mutex;
|
||||
return *mutex;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, LeaseEntry>& leases()
|
||||
{
|
||||
static auto* map = new std::unordered_map<std::string, LeaseEntry>;
|
||||
return *map;
|
||||
}
|
||||
|
||||
std::mutex& identities_mutex()
|
||||
{
|
||||
static auto* mutex = new std::mutex;
|
||||
return *mutex;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, PluginBrowserProfileIdentityRef>& identities()
|
||||
{
|
||||
static auto* map = new std::unordered_map<std::string, PluginBrowserProfileIdentityRef>;
|
||||
return *map;
|
||||
}
|
||||
|
||||
void show_profile_warning(const std::string& message)
|
||||
{
|
||||
// ShowModal runs a nested event loop. Queue subsequent warnings rather than stacking dialogs.
|
||||
static std::deque<std::string> pending;
|
||||
static bool showing = false;
|
||||
pending.push_back(message);
|
||||
if (showing)
|
||||
return;
|
||||
showing = true;
|
||||
while (!pending.empty() && wxTheApp != nullptr && !GUI::wxGetApp().is_closing()) {
|
||||
std::string current = std::move(pending.front());
|
||||
pending.pop_front();
|
||||
|
||||
wxWindow* parent = wxGetActiveWindow();
|
||||
if (parent == nullptr || !parent->IsShownOnScreen() || parent->IsBeingDeleted() ||
|
||||
parent == GUI::wxGetApp().GetTopWindow()) {
|
||||
parent = nullptr;
|
||||
for (wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext()) {
|
||||
wxWindow* window = node->GetData();
|
||||
if (dynamic_cast<GUI::PluginsDialog*>(window) && window->IsShownOnScreen() && !window->IsBeingDeleted()) {
|
||||
parent = window;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parent == nullptr)
|
||||
parent = GUI::wxGetApp().GetTopWindow();
|
||||
}
|
||||
if (parent && !parent->IsBeingDeleted()) {
|
||||
GUI::WarningDialog dialog(parent, wxString::FromUTF8(current));
|
||||
dialog.ShowModal();
|
||||
}
|
||||
}
|
||||
pending.clear();
|
||||
showing = false;
|
||||
}
|
||||
|
||||
// Startup/reset warnings can be produced before the plater exists. Retry briefly instead of
|
||||
// dropping the only warning the user would see.
|
||||
class WarningRetryTimer : public wxTimer
|
||||
{
|
||||
public:
|
||||
WarningRetryTimer(std::string message, int attempts) : m_message(std::move(message)), m_attempts(attempts) {}
|
||||
|
||||
void Notify() override
|
||||
{
|
||||
if (wxTheApp == nullptr || GUI::wxGetApp().is_closing())
|
||||
return; // process is going away; leave the timer to the app teardown
|
||||
if (GUI::wxGetApp().plater() != nullptr) {
|
||||
show_profile_warning(m_message);
|
||||
GUI::wxGetApp().CallAfter([this]() { delete this; });
|
||||
} else if (--m_attempts > 0) {
|
||||
StartOnce(500);
|
||||
} else {
|
||||
GUI::wxGetApp().CallAfter([this]() { delete this; });
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
int m_attempts;
|
||||
};
|
||||
|
||||
void warn_profile(const std::string& plugin_key, const std::string& message)
|
||||
{
|
||||
static auto* mutex = new std::mutex;
|
||||
static auto* reported = new std::unordered_set<std::string>;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(*mutex);
|
||||
if (!reported->insert(plugin_key + '\n' + message).second)
|
||||
return;
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(warning) << message;
|
||||
if (wxTheApp == nullptr)
|
||||
return;
|
||||
GUI::wxGetApp().CallAfter([message]() {
|
||||
if (wxTheApp == nullptr || GUI::wxGetApp().is_closing())
|
||||
return;
|
||||
if (GUI::wxGetApp().plater() != nullptr) {
|
||||
show_profile_warning(message);
|
||||
return;
|
||||
}
|
||||
auto* timer = new WarningRetryTimer(message, 10);
|
||||
timer->StartOnce(500);
|
||||
});
|
||||
}
|
||||
|
||||
std::string legacy_name(const std::string& plugin_key)
|
||||
{
|
||||
return plugin_key.empty() ? std::string() : sanitize_profile_name(plugin_key);
|
||||
}
|
||||
|
||||
void delete_profile_on_ui_thread(const std::string& plugin_key, const std::string& profile_id,
|
||||
const std::string& installation_root, int retries_left);
|
||||
|
||||
void schedule_profile_delete(const std::string& plugin_key, const std::string& profile_id,
|
||||
const std::string& installation_root, int retries_left)
|
||||
{
|
||||
if (wxTheApp == nullptr)
|
||||
return;
|
||||
GUI::wxGetApp().CallAfter([plugin_key, profile_id, installation_root, retries_left]() {
|
||||
if (wxTheApp == nullptr || GUI::wxGetApp().is_closing())
|
||||
return;
|
||||
delete_profile_on_ui_thread(plugin_key, profile_id, installation_root, retries_left);
|
||||
});
|
||||
}
|
||||
|
||||
void delete_profile_on_ui_thread(const std::string& plugin_key, const std::string& profile_id,
|
||||
const std::string& installation_root, int retries_left)
|
||||
{
|
||||
// Never let a hand-edited sidecar turn this into a path traversal outside web_profiles.
|
||||
if (!is_uuid(profile_id))
|
||||
return;
|
||||
if (!wxIsMainThread()) {
|
||||
schedule_profile_delete(plugin_key, profile_id, installation_root, retries_left);
|
||||
return;
|
||||
}
|
||||
|
||||
// Serialize with every sidecar/package writer across processes. A replacement that appears
|
||||
// at this root after the package was removed must keep its profile.
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile could not be cleaned up: %1%"),
|
||||
lock_error));
|
||||
return;
|
||||
}
|
||||
if (!installation_root.empty()) {
|
||||
boost::system::error_code exists_ec;
|
||||
const fs::path root(installation_root);
|
||||
const bool root_exists = fs::exists(root, exists_ec);
|
||||
if (exists_ec && !is_path_not_found(exists_ec)) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile could not be checked: %1%"),
|
||||
exists_ec.message()));
|
||||
return;
|
||||
}
|
||||
if (root_exists) {
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin was replaced by another OrcaSlicer instance, so its browser profile "
|
||||
"was left untouched."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If this process still has a closing view, give the GUI queue a few turns to destroy it.
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(leases_mutex());
|
||||
auto it = leases().find(profile_id);
|
||||
if (it != leases().end()) {
|
||||
if (it->second.uses > 0 || it->second.releasing) {
|
||||
if (retries_left > 0)
|
||||
schedule_profile_delete(plugin_key, profile_id, installation_root, retries_left - 1);
|
||||
else
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin was removed, but its browser profile is still in use by a "
|
||||
"closing plugin window. The profile was left untouched."));
|
||||
return;
|
||||
}
|
||||
leases().erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// The macOS profile store is in-memory and per process; there is no disk profile to delete,
|
||||
// but an explicit delete/reset must drop its cookie/session store.
|
||||
WebView::ReleaseProfile(wxString::FromUTF8(profile_id));
|
||||
(void) profile_id;
|
||||
return;
|
||||
#else
|
||||
std::shared_ptr<LeaseState> lease = std::make_shared<LeaseState>();
|
||||
boost::system::error_code ec;
|
||||
fs::create_directories(profiles_root(), ec);
|
||||
if (ec) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile could not be deleted: %1%"),
|
||||
ec.message()));
|
||||
return;
|
||||
}
|
||||
if (!lease->lock.open(lease_path(profile_id).string())) {
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin was removed, but its browser profile is in use by another OrcaSlicer "
|
||||
"instance. The profile was left untouched."));
|
||||
return;
|
||||
}
|
||||
|
||||
// All views are gone (the lease excludes every process). Release the cached WebView2
|
||||
// environment / WebKitWebContext before touching the directory.
|
||||
WebView::ReleaseProfile(wxString::FromUTF8(profile_id));
|
||||
|
||||
const fs::path live = profiles_root() / profile_id;
|
||||
const bool live_exists = fs::exists(live, ec);
|
||||
if (ec && !is_path_not_found(ec)) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile could not be checked: %1%"),
|
||||
ec.message()));
|
||||
lease->lock.close();
|
||||
return;
|
||||
}
|
||||
if (!live_exists) {
|
||||
lease->lock.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const fs::path tombstone = profiles_root() /
|
||||
("__deleted-" + profile_id + "-" + fs::unique_path("%%%%-%%%%-%%%%").string());
|
||||
ec.clear();
|
||||
fs::rename(live, tombstone, ec);
|
||||
if (ec) {
|
||||
lease->lock.close();
|
||||
// WebView2 can keep the environment's files open for a moment after the configuration is
|
||||
// dropped; retry on later GUI iterations before giving up.
|
||||
if (retries_left > 0) {
|
||||
schedule_profile_delete(plugin_key, profile_id, installation_root, retries_left - 1);
|
||||
return;
|
||||
}
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile could not be deleted: %1%"),
|
||||
ec.message()));
|
||||
return;
|
||||
}
|
||||
|
||||
fs::remove_all(tombstone, ec);
|
||||
if (ec) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("The plugin was removed, but its browser profile tombstone could not be fully "
|
||||
"deleted: %1%"),
|
||||
ec.message()));
|
||||
}
|
||||
lease->lock.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string ensure_plugin_browser_profile(const std::string& plugin_key, bool* fresh, std::string* legacy_path,
|
||||
std::string* installation_revision, const std::string* expected_root,
|
||||
const std::string* expected_revision)
|
||||
{
|
||||
if (fresh != nullptr)
|
||||
*fresh = false;
|
||||
if (legacy_path != nullptr)
|
||||
legacy_path->clear();
|
||||
if (installation_revision != nullptr)
|
||||
installation_revision->clear();
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
if (!PluginManager::instance().try_get_plugin_descriptor(plugin_key, descriptor) || descriptor.plugin_root.empty())
|
||||
throw std::runtime_error(
|
||||
GUI::format(_u8L("Cannot resolve the browser profile of an unknown plugin: %1%"), plugin_key));
|
||||
|
||||
const fs::path root = (expected_root != nullptr && !expected_root->empty()) ? fs::path(*expected_root)
|
||||
: fs::path(descriptor.plugin_root);
|
||||
std::string profile_id;
|
||||
|
||||
{
|
||||
std::lock_guard<PluginInstallStateMutex> lock(install_state_mutex());
|
||||
|
||||
PluginInstallState state;
|
||||
const InstallStateReadStatus status = read_install_state_status(root, state);
|
||||
if (status == InstallStateReadStatus::Unreadable)
|
||||
throw std::runtime_error(GUI::format(_u8L("Cannot read the plugin install state at %1%."),
|
||||
(root / INSTALL_STATE_FILE).string()));
|
||||
|
||||
// Compare the selected descriptor with the sidecar before binding or writing anything.
|
||||
// A stale load must not adopt a replacement's identity/revision.
|
||||
if (expected_revision != nullptr && !expected_revision->empty()) {
|
||||
if (status != InstallStateReadStatus::Readable || state.installation_revision != *expected_revision)
|
||||
throw std::runtime_error(
|
||||
_u8L("The installed plugin changed while it was loading. Refresh the plugin list and try again."));
|
||||
} else if (status == InstallStateReadStatus::Readable && !state.installation_revision.empty()) {
|
||||
// The descriptor has no selected revision, but the sidecar has one: this process's
|
||||
// view of the installation is stale (or another instance replaced it).
|
||||
throw std::runtime_error(
|
||||
_u8L("The installed plugin revision is stale. Refresh the plugin list and try again."));
|
||||
}
|
||||
|
||||
if (status == InstallStateReadStatus::Readable && !state.browser_profile_id.empty()) {
|
||||
if (!is_uuid(state.browser_profile_id))
|
||||
throw std::runtime_error(GUI::format(
|
||||
_u8L("The plugin install state at %1% has an invalid browser profile id. Reinstall the plugin "
|
||||
"or repair the file; the id was left untouched."),
|
||||
(root / INSTALL_STATE_FILE).string()));
|
||||
profile_id = state.browser_profile_id;
|
||||
// A first load of a pre-identity/pre-revision install must not leave an empty revision:
|
||||
// delete and audit compare that token against the package on disk.
|
||||
if (state.installation_revision.empty()) {
|
||||
state.installation_revision = make_plugin_installation_revision();
|
||||
if (!write_install_state(root, state))
|
||||
throw std::runtime_error(GUI::format(_u8L("Cannot write the plugin install state at %1%."),
|
||||
(root / INSTALL_STATE_FILE).string()));
|
||||
PluginManager::instance().set_plugin_installation_revision(plugin_key, root.string(),
|
||||
state.installation_revision);
|
||||
}
|
||||
} else {
|
||||
if (status == InstallStateReadStatus::Absent)
|
||||
seed_install_metadata(state, descriptor);
|
||||
state.browser_profile_id = make_plugin_browser_profile_id();
|
||||
state.installation_revision = make_plugin_installation_revision();
|
||||
if (!write_install_state(root, state))
|
||||
throw std::runtime_error(GUI::format(_u8L("Cannot write the plugin install state at %1%."),
|
||||
(root / INSTALL_STATE_FILE).string()));
|
||||
PluginManager::instance().set_plugin_installation_revision(plugin_key, root.string(),
|
||||
state.installation_revision);
|
||||
profile_id = state.browser_profile_id;
|
||||
}
|
||||
if (installation_revision != nullptr)
|
||||
*installation_revision = state.installation_revision;
|
||||
}
|
||||
|
||||
// The old WebView profile was named by plugin_key. Its data is ambiguous: it may belong to a
|
||||
// different installation of the same plugin. Never reuse, move or delete it. Check even when
|
||||
// the installer already wrote the fresh id (a cloud update of a pre-identity install), so the
|
||||
// user still learns why the old login did not carry over. warn_profile deduplicates.
|
||||
const std::string legacy = legacy_name(plugin_key);
|
||||
if (!legacy.empty() && legacy != profile_id) {
|
||||
const fs::path old = profiles_root() / legacy;
|
||||
boost::system::error_code ec;
|
||||
const bool exists = fs::exists(old, ec);
|
||||
if (ec && !is_path_not_found(ec)) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("A previous browser profile at %1% could not be checked: %2%"),
|
||||
old.string(), ec.message()));
|
||||
} else if (exists) {
|
||||
if (fresh != nullptr)
|
||||
*fresh = true;
|
||||
if (legacy_path != nullptr)
|
||||
*legacy_path = old.string();
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("A previous browser profile exists at %1%. A new browser profile was "
|
||||
"created; the old data was left untouched."),
|
||||
old.string()));
|
||||
}
|
||||
}
|
||||
return profile_id;
|
||||
}
|
||||
|
||||
static void release_profile_use(const std::string& profile_id)
|
||||
{
|
||||
bool schedule = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(leases_mutex());
|
||||
auto it = leases().find(profile_id);
|
||||
if (it == leases().end())
|
||||
return;
|
||||
if (it->second.uses > 0)
|
||||
--it->second.uses;
|
||||
if (it->second.uses == 0 && !it->second.releasing) {
|
||||
it->second.releasing = true;
|
||||
schedule = true;
|
||||
}
|
||||
}
|
||||
if (!schedule || wxTheApp == nullptr)
|
||||
return;
|
||||
|
||||
// Release the cached WebView environment/context only after the last view's destructor has
|
||||
// finished, then close the OS lease. Holding the lease until then is what prevents another
|
||||
// process from deleting a live backend.
|
||||
GUI::wxGetApp().CallAfter([profile_id]() {
|
||||
std::shared_ptr<LeaseState> lease;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(leases_mutex());
|
||||
auto it = leases().find(profile_id);
|
||||
if (it == leases().end() || it->second.uses > 0 || !it->second.releasing)
|
||||
return;
|
||||
lease = std::move(it->second.lease);
|
||||
leases().erase(it);
|
||||
}
|
||||
if (lease) {
|
||||
#if !defined(__APPLE__)
|
||||
// Disk-backed profiles release the cached backend environment on close. On macOS the
|
||||
// store itself is the in-memory session, so it must survive closing all views and is
|
||||
// released only by an explicit delete/reset.
|
||||
WebView::ReleaseProfile(wxString::FromUTF8(profile_id));
|
||||
#endif
|
||||
lease->lock.close();
|
||||
// The lease file is deliberately never unlinked: another process may have opened the
|
||||
// same inode and not locked it yet. Removing it would let two processes lock different
|
||||
// inodes for the same profile.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
BrowserProfileLease acquire_plugin_browser_profile_lease(const PluginBrowserProfileIdentityRef& identity)
|
||||
{
|
||||
if (!identity || !is_uuid(identity->profile_id))
|
||||
return nullptr;
|
||||
const std::string profile_id = identity->profile_id;
|
||||
if (!plugin_browser_profile_is_current(identity))
|
||||
return nullptr;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(leases_mutex());
|
||||
auto& entry = leases()[profile_id];
|
||||
if (!entry.lease) {
|
||||
#if defined(__APPLE__)
|
||||
entry.lease = std::make_shared<LeaseState>(); // in-memory store; no disk lease
|
||||
#else
|
||||
boost::system::error_code ec;
|
||||
fs::create_directories(profiles_root(), ec);
|
||||
entry.lease = std::make_shared<LeaseState>();
|
||||
if (!entry.lease->lock.open(lease_path(profile_id).string())) {
|
||||
leases().erase(profile_id);
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
++entry.uses;
|
||||
entry.releasing = false;
|
||||
}
|
||||
|
||||
// Revalidate after taking the lease: the load instance may have been replaced in between,
|
||||
// or the sidecar on disk may now describe a different installation/revision.
|
||||
if (!plugin_browser_profile_is_current(identity) || !plugin_browser_profile_installation_is_current(identity)) {
|
||||
release_profile_use(profile_id);
|
||||
return nullptr;
|
||||
}
|
||||
return BrowserProfileLease(reinterpret_cast<void*>(1), [profile_id](void*) { release_profile_use(profile_id); });
|
||||
}
|
||||
|
||||
PluginBrowserProfileIdentityRef begin_plugin_browser_profile(const std::string& plugin_key,
|
||||
const std::string& expected_plugin_root,
|
||||
const std::string& expected_revision)
|
||||
{
|
||||
std::string revision;
|
||||
const std::string profile_id = ensure_plugin_browser_profile(plugin_key, nullptr, nullptr, &revision,
|
||||
&expected_plugin_root, &expected_revision);
|
||||
auto identity = std::make_shared<PluginBrowserProfileIdentity>(
|
||||
PluginBrowserProfileIdentity{plugin_key, profile_id, expected_plugin_root, revision});
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(identities_mutex());
|
||||
identities()[plugin_key] = identity;
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
void end_plugin_browser_profile(const std::string& plugin_key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(identities_mutex());
|
||||
identities().erase(plugin_key);
|
||||
}
|
||||
|
||||
PluginBrowserProfileIdentityRef current_plugin_browser_profile_identity(const std::string& plugin_key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(identities_mutex());
|
||||
auto it = identities().find(plugin_key);
|
||||
return it == identities().end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
bool plugin_browser_profile_is_current(const PluginBrowserProfileIdentityRef& identity)
|
||||
{
|
||||
if (!identity)
|
||||
return false;
|
||||
std::lock_guard<std::mutex> lock(identities_mutex());
|
||||
auto it = identities().find(identity->plugin_key);
|
||||
return it != identities().end() && it->second == identity;
|
||||
}
|
||||
|
||||
bool plugin_browser_profile_installation_is_current(const PluginBrowserProfileIdentityRef& identity)
|
||||
{
|
||||
if (!identity || identity->plugin_root.empty() || identity->installation_revision.empty())
|
||||
return false;
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error))
|
||||
return false;
|
||||
PluginInstallState state;
|
||||
if (read_install_state_status(boost::filesystem::path(identity->plugin_root), state) !=
|
||||
InstallStateReadStatus::Readable)
|
||||
return false;
|
||||
return state.browser_profile_id == identity->profile_id &&
|
||||
state.installation_revision == identity->installation_revision;
|
||||
}
|
||||
|
||||
void warn_plugin_browser_profile_in_use(const std::string& plugin_key)
|
||||
{
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin's browser profile is in use by another OrcaSlicer instance. Its plugin UI "
|
||||
"was not opened."));
|
||||
}
|
||||
|
||||
void warn_plugin_browser_profile_reset(const std::string& plugin_key)
|
||||
{
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin was reinstalled, so its browser profile and sign-in session were reset."));
|
||||
}
|
||||
|
||||
void warn_plugin_browser_profile_cleanup_unknown(const std::string& plugin_key)
|
||||
{
|
||||
warn_profile(plugin_key,
|
||||
_u8L("The plugin was removed, but its browser profile could not be identified and may have been "
|
||||
"left on disk."));
|
||||
}
|
||||
|
||||
void warn_legacy_plugin_browser_profile(const std::string& plugin_key, const std::string& current_profile_id)
|
||||
{
|
||||
const std::string legacy = legacy_name(plugin_key);
|
||||
if (legacy.empty() || legacy == current_profile_id)
|
||||
return;
|
||||
const fs::path old = profiles_root() / legacy;
|
||||
boost::system::error_code ec;
|
||||
const bool exists = fs::exists(old, ec);
|
||||
if (ec && !is_path_not_found(ec)) {
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("A previous browser profile at %1% could not be checked: %2%"),
|
||||
old.string(), ec.message()));
|
||||
return;
|
||||
}
|
||||
if (exists)
|
||||
warn_profile(plugin_key,
|
||||
GUI::format(_u8L("A previous browser profile exists at %1%. A new browser profile was "
|
||||
"created; the old data was left untouched."),
|
||||
old.string()));
|
||||
}
|
||||
|
||||
void delete_plugin_browser_profile(const std::string& plugin_key, const std::string& profile_id,
|
||||
const std::string& installation_root)
|
||||
{
|
||||
if (profile_id.empty()) {
|
||||
#if defined(__APPLE__)
|
||||
// The pre-identity macOS store was keyed by the plugin key; drop it on delete/reset too.
|
||||
const std::string legacy = legacy_name(plugin_key);
|
||||
if (wxTheApp != nullptr && !legacy.empty())
|
||||
WebView::ReleaseProfile(wxString::FromUTF8(legacy));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (!is_uuid(profile_id)) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "Refusing to delete an invalid browser profile id for " << plugin_key;
|
||||
return;
|
||||
}
|
||||
if (wxTheApp == nullptr)
|
||||
return;
|
||||
if (wxIsMainThread())
|
||||
delete_profile_on_ui_thread(plugin_key, profile_id, installation_root, 20);
|
||||
else
|
||||
schedule_profile_delete(plugin_key, profile_id, installation_root, 20);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// A shared, process-local lease on one installation's browser profile. The lease owns the
|
||||
// non-blocking cross-process lock on the profile's data directory; it lives as long as a webview
|
||||
// that uses the profile. `std::shared_ptr<void>` keeps this type out of UI headers.
|
||||
using BrowserProfileLease = std::shared_ptr<void>;
|
||||
|
||||
// One loaded instance's browser-profile identity. Refreshing this object binds UI and callbacks
|
||||
// to a particular load: a reload creates a new object even when the profile id is unchanged, so
|
||||
// callbacks captured from the old instance cannot run against the replacement.
|
||||
struct PluginBrowserProfileIdentity
|
||||
{
|
||||
std::string plugin_key;
|
||||
std::string profile_id;
|
||||
std::string plugin_root; // package root this load instance was bound to
|
||||
std::string installation_revision; // sidecar revision of that package
|
||||
};
|
||||
using PluginBrowserProfileIdentityRef = std::shared_ptr<const PluginBrowserProfileIdentity>;
|
||||
|
||||
// Returns the installation-scoped browser profile id for `plugin_key`, creating and persisting a
|
||||
// random id before any plugin code runs when the sidecar has none. A pre-identity directory found
|
||||
// under the old plugin-key name is never reused, moved or deleted; fresh=true reports that a fresh
|
||||
// profile was started because of it. Throws std::runtime_error when the sidecar cannot be read or
|
||||
// written.
|
||||
std::string ensure_plugin_browser_profile(const std::string& plugin_key, bool* fresh = nullptr,
|
||||
std::string* legacy_path = nullptr,
|
||||
std::string* installation_revision = nullptr,
|
||||
const std::string* expected_root = nullptr,
|
||||
const std::string* expected_revision = nullptr);
|
||||
|
||||
// Binds one load instance to its profile id. Call before plugin code runs; an existing binding
|
||||
// for the key is replaced, so callbacks from the previous load become stale. Compares the
|
||||
// descriptor's selected root/revision with the sidecar before binding: a stale load of a
|
||||
// replaced installation throws instead of adopting the replacement's identity.
|
||||
PluginBrowserProfileIdentityRef begin_plugin_browser_profile(const std::string& plugin_key,
|
||||
const std::string& expected_plugin_root,
|
||||
const std::string& expected_revision);
|
||||
|
||||
// Drops the binding for a key on unload or a failed load.
|
||||
void end_plugin_browser_profile(const std::string& plugin_key);
|
||||
|
||||
// The binding for the loaded instance, or null when the plugin is not bound.
|
||||
PluginBrowserProfileIdentityRef current_plugin_browser_profile_identity(const std::string& plugin_key);
|
||||
|
||||
// True when `identity` is still the current binding for its key. A reload, keep-local rekey or
|
||||
// unload invalidates every previous identity, even when the underlying profile id is unchanged.
|
||||
bool plugin_browser_profile_is_current(const PluginBrowserProfileIdentityRef& identity);
|
||||
|
||||
// Re-reads the identity's own package root and requires the same profile id and installation
|
||||
// revision. Use at UI creation and before persisting audit state, not on every message callback.
|
||||
bool plugin_browser_profile_installation_is_current(const PluginBrowserProfileIdentityRef& identity);
|
||||
|
||||
// Acquires a non-blocking lease on the identity's profile id. Returns null when another process
|
||||
// owns the profile or the load instance was already replaced; callers must not create a webview
|
||||
// then.
|
||||
BrowserProfileLease acquire_plugin_browser_profile_lease(const PluginBrowserProfileIdentityRef& identity);
|
||||
|
||||
// Reports (once) that this process could not take the profile lease, so plugin UI was not opened.
|
||||
void warn_plugin_browser_profile_in_use(const std::string& plugin_key);
|
||||
|
||||
// Reports (once) that a reinstall replaced the old profile with a fresh identity.
|
||||
void warn_plugin_browser_profile_reset(const std::string& plugin_key);
|
||||
|
||||
// Reports (once) that uninstall could not identify a profile to delete, so old profile data may
|
||||
// remain on disk.
|
||||
void warn_plugin_browser_profile_cleanup_unknown(const std::string& plugin_key);
|
||||
|
||||
// Reports (once) that an old plugin-key-named profile exists and is not used by this installation.
|
||||
// Used when the identity is created outside the normal load path (keep-local rekeying).
|
||||
void warn_legacy_plugin_browser_profile(const std::string& plugin_key, const std::string& current_profile_id);
|
||||
|
||||
// Attempts to delete the profile after the plugin package has been removed. Non-blocking:
|
||||
// another process's lease means the cleanup is skipped and a warning is shown. When this process
|
||||
// still has a closing view, the attempt is retried on the GUI thread. A tombstone rename ensures
|
||||
// the live directory is removed before recursive deletion. `installation_root` is checked under
|
||||
// the cross-process install-state lock on every attempt: if a replacement package exists there,
|
||||
// its profile is left untouched. Pass an empty root when the caller has just installed a new
|
||||
// package at a known root (the local reinstall path).
|
||||
void delete_plugin_browser_profile(const std::string& plugin_key, const std::string& profile_id,
|
||||
const std::string& installation_root = std::string());
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -58,6 +58,7 @@ struct PluginDescriptor
|
||||
std::string version; // Selected plugin version
|
||||
std::string latest_version; // Authoritative latest available cloud version.
|
||||
std::string installed_version; // Locally installed package version. Preserved across cloud merges, which overwrite `version` with the latest cloud version. Empty when not installed.
|
||||
std::string installation_revision; // Sidecar revision of the selected installed package; compare-and-delete token.
|
||||
std::vector<std::string> display_types; // Display-only "compatibility" labels (cloud: raw service labels; local: from real capabilities). Never used for dispatch.
|
||||
std::string plugin_root; // Installed plugin directory, even when entry_path is invalid or ambiguous.
|
||||
std::string entry_path; // Full path to the installed plugin entry file
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/nowide/convert.hpp>
|
||||
#include <boost/nowide/cstdio.hpp>
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <ios>
|
||||
|
||||
@@ -21,6 +25,10 @@
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "PluginAuditManager.hpp"
|
||||
@@ -36,6 +44,7 @@
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
@@ -45,7 +54,11 @@
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
@@ -53,13 +66,316 @@ namespace Slic3r {
|
||||
|
||||
const char* const INSTALL_STATE_FILE = ".install_state.json";
|
||||
|
||||
std::mutex& install_state_mutex()
|
||||
namespace {
|
||||
|
||||
// Cross-process half of install_state_mutex(). The lock file lives in the host-managed profile
|
||||
// directory and is never unlinked: deleting it would let two processes lock different inodes and
|
||||
// both believe they hold the sidecar lock.
|
||||
class InstallStateFileLock
|
||||
{
|
||||
public:
|
||||
// Fails closed: returns false with an actionable reason. There is deliberately no
|
||||
// process-local-only fallback, because that would let two OrcaSlicer instances mutate the
|
||||
// same package/sidecar without isolation.
|
||||
bool lock(std::string& error)
|
||||
{
|
||||
error.clear();
|
||||
const std::string base = data_dir();
|
||||
if (base.empty()) {
|
||||
error = _u8L("The OrcaSlicer data directory is not initialized, so the plugin install-state lock "
|
||||
"cannot be acquired.");
|
||||
return false;
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
const boost::filesystem::path lock_dir = boost::filesystem::path(base) / "web_profiles";
|
||||
boost::filesystem::create_directories(lock_dir, ec);
|
||||
if (ec) {
|
||||
// TRN %1% is the lock folder, %2% the system error.
|
||||
error = GUI::format(_u8L("Cannot create the plugin install-state lock directory %1%: %2%. "
|
||||
"Check that the OrcaSlicer data directory is writable."),
|
||||
lock_dir.string(), ec.message());
|
||||
return false;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
if (m_handle != nullptr)
|
||||
return true;
|
||||
const std::string narrow_path = (boost::filesystem::path(base) / "web_profiles" /
|
||||
".install_state.lock").string();
|
||||
const std::wstring path = boost::nowide::widen(narrow_path);
|
||||
HANDLE handle = ::CreateFileW(path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
// TRN %1% is the lock file, %2% the numeric Windows error.
|
||||
error = GUI::format(_u8L("Cannot open the plugin install-state lock file %1% (error %2%). "
|
||||
"Check that the file and its folder are writable."),
|
||||
narrow_path, std::to_string(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
// Bounded wait: never hold the GUI indefinitely behind another instance.
|
||||
constexpr auto deadline = std::chrono::milliseconds(1500);
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
OVERLAPPED overlapped{};
|
||||
for (;;) {
|
||||
overlapped = OVERLAPPED{};
|
||||
if (::LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, MAXDWORD, MAXDWORD,
|
||||
&overlapped))
|
||||
break;
|
||||
const DWORD code = ::GetLastError();
|
||||
if (code == ERROR_LOCK_VIOLATION && std::chrono::steady_clock::now() - start < deadline) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||
continue;
|
||||
}
|
||||
::CloseHandle(handle);
|
||||
// TRN %1% is the lock file, %2% the numeric Windows error.
|
||||
error = GUI::format(_u8L("Cannot lock the plugin install-state lock file %1% (error %2%). "
|
||||
"Another OrcaSlicer instance is holding it; close it and retry."),
|
||||
narrow_path, std::to_string(code));
|
||||
return false;
|
||||
}
|
||||
m_overlapped = overlapped;
|
||||
m_handle = handle;
|
||||
#else
|
||||
if (m_fd >= 0)
|
||||
return true;
|
||||
const std::string path =
|
||||
(boost::filesystem::path(base) / "web_profiles" / ".install_state.lock").string();
|
||||
m_fd = ::open(path.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0644);
|
||||
if (m_fd < 0) {
|
||||
// TRN %1% is the lock file, %2% the system error.
|
||||
error = GUI::format(_u8L("Cannot open the plugin install-state lock file %1%: %2%. "
|
||||
"Check that the file and its folder are writable."),
|
||||
path, std::string(std::strerror(errno)));
|
||||
return false;
|
||||
}
|
||||
constexpr auto deadline = std::chrono::milliseconds(1500);
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for (;;) {
|
||||
if (::flock(m_fd, LOCK_EX | LOCK_NB) == 0)
|
||||
break;
|
||||
const int code = errno;
|
||||
if ((code == EWOULDBLOCK || code == EAGAIN) && std::chrono::steady_clock::now() - start < deadline) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||
continue;
|
||||
}
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
// TRN %1% is the lock file, %2% the system error.
|
||||
error = GUI::format(_u8L("Cannot lock the plugin install-state lock file %1%: %2%. "
|
||||
"Another OrcaSlicer instance is holding it; close it and retry."),
|
||||
path, std::string(std::strerror(code)));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (m_handle != nullptr) {
|
||||
::UnlockFileEx(m_handle, 0, MAXDWORD, MAXDWORD, &m_overlapped);
|
||||
::CloseHandle(m_handle);
|
||||
m_handle = nullptr;
|
||||
}
|
||||
#else
|
||||
if (m_fd >= 0) {
|
||||
::flock(m_fd, LOCK_UN);
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(_WIN32)
|
||||
void* m_handle{nullptr};
|
||||
OVERLAPPED m_overlapped{};
|
||||
#else
|
||||
int m_fd{-1};
|
||||
#endif
|
||||
};
|
||||
|
||||
InstallStateFileLock& install_state_file_lock()
|
||||
{
|
||||
static auto* lock = new InstallStateFileLock;
|
||||
return *lock;
|
||||
}
|
||||
|
||||
// Reentrancy is per thread: a nested read-modify-write must not try to take the OS lock again.
|
||||
thread_local unsigned t_install_state_depth = 0;
|
||||
|
||||
// One non-blocking exclusive lock per package key, independent of the sidecar lock. Holding it
|
||||
// across Python import prevents a concurrent install/delete from swapping the package files under
|
||||
// a module that was selected under the old identity.
|
||||
class PackageLeaseLock
|
||||
{
|
||||
public:
|
||||
PackageLeaseLock() = default;
|
||||
|
||||
bool open(const std::string& path, std::string& error)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
const std::wstring wide = boost::nowide::widen(path);
|
||||
HANDLE handle = ::CreateFileW(wide.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
// TRN %1% is the lease file, %2% the numeric Windows error.
|
||||
error = GUI::format(_u8L("The plugin package is being loaded, installed, or removed by another "
|
||||
"OrcaSlicer instance (lease %1%, error %2%). Retry after that operation finishes."),
|
||||
path, std::to_string(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
m_handle = handle;
|
||||
#else
|
||||
m_fd = ::open(path.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0644);
|
||||
if (m_fd < 0) {
|
||||
// TRN %1% is the lease file, %2% the system error.
|
||||
error = GUI::format(_u8L("Cannot open the plugin package lease %1%: %2%."), path,
|
||||
std::string(std::strerror(errno)));
|
||||
return false;
|
||||
}
|
||||
if (::flock(m_fd, LOCK_EX | LOCK_NB) != 0) {
|
||||
const int code = errno;
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
// TRN %1% is the lease file, %2% the system error.
|
||||
error = GUI::format(_u8L("The plugin package is being loaded, installed, or removed by another "
|
||||
"OrcaSlicer instance (lease %1%, error %2%). Retry after that operation finishes."),
|
||||
path, std::string(std::strerror(code)));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
~PackageLeaseLock() { close(); }
|
||||
PackageLeaseLock(const PackageLeaseLock&) = delete;
|
||||
PackageLeaseLock& operator=(const PackageLeaseLock&) = delete;
|
||||
|
||||
private:
|
||||
void close()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (m_handle != nullptr) {
|
||||
::CloseHandle(static_cast<HANDLE>(m_handle));
|
||||
m_handle = nullptr;
|
||||
}
|
||||
#else
|
||||
if (m_fd >= 0) {
|
||||
::flock(m_fd, LOCK_UN);
|
||||
::close(m_fd);
|
||||
m_fd = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
void* m_handle{nullptr};
|
||||
#else
|
||||
int m_fd{-1};
|
||||
#endif
|
||||
};
|
||||
|
||||
uint64_t plugin_package_lease_hash(const std::string& plugin_key)
|
||||
{
|
||||
uint64_t hash = 1469598103934665603ull;
|
||||
for (unsigned char ch : plugin_key) {
|
||||
hash ^= ch;
|
||||
hash *= 1099511628211ull;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
struct PackageLeaseState
|
||||
{
|
||||
PackageLeaseLock lock;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void PluginInstallStateMutex::lock()
|
||||
{
|
||||
if (t_install_state_depth != 0) {
|
||||
++t_install_state_depth;
|
||||
return;
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
std::string error;
|
||||
bool locked = false;
|
||||
try {
|
||||
locked = install_state_file_lock().lock(error);
|
||||
} catch (...) {
|
||||
m_mutex.unlock();
|
||||
throw;
|
||||
}
|
||||
if (!locked) {
|
||||
m_mutex.unlock();
|
||||
throw std::runtime_error(error.empty() ? std::string(_u8L("The plugin install-state lock is unavailable.")) : error);
|
||||
}
|
||||
t_install_state_depth = 1;
|
||||
}
|
||||
|
||||
void PluginInstallStateMutex::unlock()
|
||||
{
|
||||
if (t_install_state_depth == 0)
|
||||
return;
|
||||
if (--t_install_state_depth == 0) {
|
||||
install_state_file_lock().unlock();
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
PluginInstallStateMutex& install_state_mutex()
|
||||
{
|
||||
// Function-local static: safe to use from any writer regardless of static initialization order.
|
||||
static std::mutex mutex;
|
||||
static PluginInstallStateMutex mutex;
|
||||
return mutex;
|
||||
}
|
||||
|
||||
bool try_lock_plugin_install_state(std::unique_lock<PluginInstallStateMutex>& lock, std::string& error)
|
||||
{
|
||||
error.clear();
|
||||
try {
|
||||
lock = std::unique_lock<PluginInstallStateMutex>(install_state_mutex());
|
||||
return true;
|
||||
} catch (const std::exception& ex) {
|
||||
error = ex.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PluginPackageLease acquire_plugin_package_lease(const std::string& plugin_key, std::string& error)
|
||||
{
|
||||
error.clear();
|
||||
if (plugin_key.empty()) {
|
||||
error = _u8L("Cannot lease a plugin package without a plugin key.");
|
||||
return nullptr;
|
||||
}
|
||||
const std::string base = data_dir();
|
||||
if (base.empty()) {
|
||||
error = _u8L("The OrcaSlicer data directory is not initialized, so the plugin package lease cannot be acquired.");
|
||||
return nullptr;
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
const boost::filesystem::path dir = boost::filesystem::path(base) / "web_profiles";
|
||||
boost::filesystem::create_directories(dir, ec);
|
||||
if (ec) {
|
||||
// TRN %1% is the lease folder, %2% the system error.
|
||||
error = GUI::format(_u8L("Cannot create the plugin package lease directory %1%: %2%."), dir.string(),
|
||||
ec.message());
|
||||
return nullptr;
|
||||
}
|
||||
std::ostringstream name;
|
||||
name << ".package-" << std::hex << std::setw(16) << std::setfill('0') << plugin_package_lease_hash(plugin_key)
|
||||
<< ".lease";
|
||||
auto state = std::make_unique<PackageLeaseState>();
|
||||
if (!state->lock.open((dir / name.str()).string(), error))
|
||||
return nullptr;
|
||||
return PluginPackageLease(state.release(), [](void* p) { delete static_cast<PackageLeaseState*>(p); });
|
||||
}
|
||||
|
||||
std::string get_orca_plugins_dir()
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
@@ -305,7 +621,7 @@ void scan_plugin_directory(const std::string& dir_path, std::vector<PluginDescri
|
||||
if (entry_path.empty()) {
|
||||
descriptor.set_error(entry_error);
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::lock_guard<PluginInstallStateMutex> state_lock(install_state_mutex());
|
||||
descriptor.install_state_valid = read_install_state(plugin_dir, descriptor);
|
||||
}
|
||||
assign_discovered_plugin_key(descriptor, plugin_dir);
|
||||
@@ -321,7 +637,7 @@ void scan_plugin_directory(const std::string& dir_path, std::vector<PluginDescri
|
||||
if (!parsed) {
|
||||
descriptor.set_error(meta_error);
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::lock_guard<PluginInstallStateMutex> state_lock(install_state_mutex());
|
||||
descriptor.install_state_valid = read_install_state(plugin_dir, descriptor);
|
||||
}
|
||||
assign_discovered_plugin_key(descriptor, entry_path);
|
||||
@@ -338,7 +654,7 @@ void scan_plugin_directory(const std::string& dir_path, std::vector<PluginDescri
|
||||
// Cloud identity and the package-level auto-load flag. plugin_key is always derived
|
||||
// below, never read from the sidecar.
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::lock_guard<PluginInstallStateMutex> state_lock(install_state_mutex());
|
||||
descriptor.install_state_valid = read_install_state(plugin_dir, descriptor);
|
||||
}
|
||||
assign_discovered_plugin_key(descriptor, entry_path);
|
||||
@@ -893,6 +1209,7 @@ bool read_install_state(const boost::filesystem::path& plugin_dir, PluginDescrip
|
||||
entry.installed_version = state.installed_version;
|
||||
if (!state.cloud_uuid.empty())
|
||||
entry.cloud = CloudPluginState{state.cloud_uuid, true, false, false};
|
||||
entry.installation_revision = state.installation_revision;
|
||||
|
||||
// Package-level auto-load flag only. The per-capability enable flags stay in the sidecar: a
|
||||
// capability has no existence — and so no state — until it is materialized, at which point the
|
||||
@@ -957,6 +1274,10 @@ InstallStateReadStatus read_install_state_status(const boost::filesystem::path&
|
||||
parsed.plugin_name = state["plugin_name"].get<std::string>();
|
||||
if (state.contains("cloud_uuid") && state["cloud_uuid"].is_string())
|
||||
parsed.cloud_uuid = state["cloud_uuid"].get<std::string>();
|
||||
if (state.contains("browser_profile_id") && state["browser_profile_id"].is_string())
|
||||
parsed.browser_profile_id = state["browser_profile_id"].get<std::string>();
|
||||
if (state.contains("installation_revision") && state["installation_revision"].is_string())
|
||||
parsed.installation_revision = state["installation_revision"].get<std::string>();
|
||||
|
||||
if (state.contains("permissions") && state["permissions"].is_object()) {
|
||||
const auto& permissions = state["permissions"];
|
||||
@@ -1128,6 +1449,16 @@ void seed_install_metadata(PluginInstallState& state, const PluginDescriptor& en
|
||||
state.enabled = true;
|
||||
}
|
||||
|
||||
std::string make_plugin_browser_profile_id()
|
||||
{
|
||||
return boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
}
|
||||
|
||||
std::string make_plugin_installation_revision()
|
||||
{
|
||||
return boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
}
|
||||
|
||||
bool write_install_state(const boost::filesystem::path& plugin_dir, const PluginInstallState& state)
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
@@ -1140,6 +1471,10 @@ bool write_install_state(const boost::filesystem::path& plugin_dir, const Plugin
|
||||
json["enabled"] = state.enabled;
|
||||
if (!state.cloud_uuid.empty())
|
||||
json["cloud_uuid"] = state.cloud_uuid;
|
||||
if (!state.browser_profile_id.empty())
|
||||
json["browser_profile_id"] = state.browser_profile_id;
|
||||
if (!state.installation_revision.empty())
|
||||
json["installation_revision"] = state.installation_revision;
|
||||
|
||||
json["permissions"] = {
|
||||
{"fs_read", state.permissions.fs_read},
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -59,6 +60,13 @@ struct PluginInstallState {
|
||||
std::string installed_version;
|
||||
std::string plugin_name;
|
||||
std::string cloud_uuid; // empty for local
|
||||
// Random installation-scoped browser profile identity. Persisted before plugin code runs.
|
||||
// Empty on sidecars written before this field existed; the loader assigns one before import.
|
||||
std::string browser_profile_id;
|
||||
// Changes on every package install/replacement. Delete uses it as a compare-and-delete token
|
||||
// so a replacement with the same profile id and version is still detected. Empty on older
|
||||
// sidecars, where the field comparisons and entry mtime are the fallback.
|
||||
std::string installation_revision;
|
||||
|
||||
PluginPermissions permissions;
|
||||
|
||||
@@ -137,15 +145,44 @@ std::vector<std::string> collect_resource_texture_files(const std::string& dir,
|
||||
const std::string& plugin_root,
|
||||
std::string& error);
|
||||
|
||||
// Process-wide mutex serializing every in-process read and read-modify-write of a plugin's
|
||||
// .install_state.json sidecar. Hold it across the read and the matching write so two writers
|
||||
// cannot overwrite each other's grants, and around standalone reads so a reader cannot observe a
|
||||
// state while another thread is replacing it. It is not a file lock: another OrcaSlicer process
|
||||
// writing the same sidecar is not serialized.
|
||||
// Serializes every read and read-modify-write of a plugin's .install_state.json sidecar, across
|
||||
// processes and across threads in this process. Hold it across the read and the matching write so
|
||||
// two writers cannot overwrite each other's grants or browser-profile identity, and around
|
||||
// standalone reads so a reader cannot observe a state while another process is replacing it.
|
||||
// The cross-process part is a blocking OS file lock in the host-managed web_profiles directory;
|
||||
// the per-thread lock is reentrant so a writer may take it again around an inner read.
|
||||
// lock() fails closed: if the OS lock cannot be created or acquired it throws std::runtime_error
|
||||
// with a user-actionable reason after releasing the process mutex. Callers must let that failure
|
||||
// abort the sidecar operation instead of proceeding unlocked.
|
||||
//
|
||||
// Lock order: install-state mutex -> PluginManager::m_mutex. Code that already holds the manager
|
||||
// Lock order: install-state lock -> PluginManager::m_mutex. Code that already holds the manager
|
||||
// lock must not acquire this one.
|
||||
std::mutex& install_state_mutex();
|
||||
class PluginInstallStateMutex
|
||||
{
|
||||
public:
|
||||
PluginInstallStateMutex() = default;
|
||||
PluginInstallStateMutex(const PluginInstallStateMutex&) = delete;
|
||||
PluginInstallStateMutex& operator=(const PluginInstallStateMutex&) = delete;
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
PluginInstallStateMutex& install_state_mutex();
|
||||
|
||||
// Non-throwing acquisition for callers that must report an actionable error instead of
|
||||
// propagating. On failure `lock` stays unlocked and `error` holds the reason.
|
||||
bool try_lock_plugin_install_state(std::unique_lock<PluginInstallStateMutex>& lock, std::string& error);
|
||||
|
||||
// A non-blocking cross-process lease on one plugin package. Load holds it across selected
|
||||
// identity verification, Python import and on_load; install/delete/keep-local hold it across
|
||||
// package mutation. It is separate from the install-state lock, so Python callbacks can still
|
||||
// read/write audit sidecars while it is held.
|
||||
using PluginPackageLease = std::shared_ptr<void>;
|
||||
PluginPackageLease acquire_plugin_package_lease(const std::string& plugin_key, std::string& error);
|
||||
|
||||
// Canonical writer: emits the .install_state.json schema for the given state.
|
||||
// The file is replaced strictly atomically: the payload is written to a uniquely named temporary
|
||||
@@ -171,6 +208,12 @@ bool write_install_state(const boost::filesystem::path& plugin_dir, const Plugin
|
||||
// that creates a sidecar on demand.
|
||||
void seed_install_metadata(PluginInstallState& state, const PluginDescriptor& entry);
|
||||
|
||||
// A random UUID used as the installation-scoped browser profile identity.
|
||||
std::string make_plugin_browser_profile_id();
|
||||
|
||||
// A random UUID that changes on every installed-package revision.
|
||||
std::string make_plugin_installation_revision();
|
||||
|
||||
// Outcome of a sidecar read. Callers that may write a sidecar must distinguish Absent from
|
||||
// Unreadable: a missing file is a new install whose metadata may be seeded, while an existing file
|
||||
// that cannot be parsed -- or that cannot be examined because of a filesystem error -- holds state
|
||||
@@ -192,8 +235,8 @@ InstallStateReadStatus read_install_state_status(const boost::filesystem::path&
|
||||
|
||||
// Reads install state back into the descriptor; plugin_key is always derived. Returns whether the
|
||||
// sidecar was present and valid.
|
||||
// Caller must hold install_state_mutex(); it is not recursive, so a caller already holding the
|
||||
// lock must call this raw overload, not PluginManager::get_install_state().
|
||||
// Caller must hold install_state_mutex(); prefer this raw overload over
|
||||
// PluginManager::get_install_state() inside a locked read-modify-write.
|
||||
bool read_install_state(const boost::filesystem::path& plugin_dir, PluginDescriptor& entry);
|
||||
// Full read of the sidecar; returns false if there is no/invalid sidecar.
|
||||
// Caller must hold install_state_mutex(); see the note above.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// service header stays free of the manager.
|
||||
#include "PluginManager.hpp"
|
||||
|
||||
#include "PluginBrowserProfile.hpp"
|
||||
#include "PluginConfig.hpp"
|
||||
#include "PluginFsUtils.hpp"
|
||||
#include "PythonInterpreter.hpp"
|
||||
@@ -261,6 +262,19 @@ bool load(const PluginDescriptor& descriptor,
|
||||
static std::mutex load_serializer;
|
||||
std::lock_guard<std::mutex> load_lock(load_serializer);
|
||||
|
||||
// Hold the package lease across selected-identity verification, Python import and on_load.
|
||||
// Install/delete/keep-local take the same lease non-blocking, so the package cannot be swapped
|
||||
// under the module while it is being selected/imported.
|
||||
PluginPackageLease package_lease;
|
||||
if (!descriptor.plugin_root.empty()) {
|
||||
std::string lease_error;
|
||||
package_lease = acquire_plugin_package_lease(descriptor.plugin_key, lease_error);
|
||||
if (!package_lease) {
|
||||
error = GUI::format(_u8L("Cannot load the plugin while its package is being updated: %1%"), lease_error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// A sidecar whose contents do not parse (cut short by a crash, or broken by a hand edit) would
|
||||
// make every writer refuse it, so a plugin that declares permissions could never load and no
|
||||
// grant or capability choice could be saved. Set it aside before any plugin code runs, so this
|
||||
@@ -270,7 +284,12 @@ bool load(const PluginDescriptor& descriptor,
|
||||
// Anything else at the sidecar path (a link, a directory, a file that cannot be opened or read
|
||||
// in full) is left alone, so its writers keep refusing.
|
||||
if (!descriptor.plugin_root.empty()) {
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
error = GUI::format(_u8L("Cannot inspect the plugin install state: %1%"), lock_error);
|
||||
return false;
|
||||
}
|
||||
const boost::filesystem::path plugin_root(descriptor.plugin_root);
|
||||
PluginInstallState unused_state;
|
||||
bool malformed = false;
|
||||
@@ -287,6 +306,31 @@ bool load(const PluginDescriptor& descriptor,
|
||||
}
|
||||
}
|
||||
|
||||
// Persist a random installation browser-profile id and bind this load instance to it before
|
||||
// any plugin code runs. A failed load unbinds it so callbacks from an abandoned attempt cannot
|
||||
// run against a later replacement.
|
||||
struct ProfileBinding
|
||||
{
|
||||
explicit ProfileBinding(const std::string& plugin_key) : key(plugin_key) {}
|
||||
~ProfileBinding()
|
||||
{
|
||||
if (active)
|
||||
end_plugin_browser_profile(key);
|
||||
}
|
||||
std::string key;
|
||||
bool active{false};
|
||||
} profile_binding(descriptor.plugin_key);
|
||||
if (!descriptor.plugin_root.empty()) {
|
||||
try {
|
||||
(void) begin_plugin_browser_profile(descriptor.plugin_key, descriptor.plugin_root,
|
||||
descriptor.installation_revision);
|
||||
profile_binding.active = true;
|
||||
} catch (const std::exception& ex) {
|
||||
error = GUI::format(_u8L("Failed to prepare the plugin browser profile: %1%"), ex.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Plugin plugin;
|
||||
plugin.descriptor = descriptor;
|
||||
plugin.module_name = plugin_module_name(descriptor);
|
||||
@@ -345,7 +389,12 @@ bool load(const PluginDescriptor& descriptor,
|
||||
PluginInstallState install_state;
|
||||
bool have_install_state = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::unique_lock<PluginInstallStateMutex> state_lock;
|
||||
std::string lock_error;
|
||||
if (!try_lock_plugin_install_state(state_lock, lock_error)) {
|
||||
error = GUI::format(_u8L("Cannot read the plugin install state: %1%"), lock_error);
|
||||
return false;
|
||||
}
|
||||
have_install_state = !descriptor.plugin_root.empty() &&
|
||||
read_install_state(boost::filesystem::path(descriptor.plugin_root), install_state);
|
||||
}
|
||||
@@ -500,6 +549,9 @@ bool load(const PluginDescriptor& descriptor,
|
||||
|
||||
out = std::move(plugin);
|
||||
|
||||
// The load owns the binding from here on; PluginManager::unload_plugin ends it.
|
||||
profile_binding.active = false;
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "[plugin_loader::load] SUCCESS plugin=" << descriptor.plugin_key
|
||||
<< " thread=" << std::this_thread::get_id();
|
||||
return true;
|
||||
@@ -661,29 +713,58 @@ bool install_plugin(const boost::filesystem::path& filepath, const std::string&
|
||||
return install_plugin(filepath, cloud_user_id, descriptor, error);
|
||||
}
|
||||
|
||||
std::string local_plugin_package_key(const boost::filesystem::path& filepath)
|
||||
{
|
||||
return make_local_plugin_key(canonical_or_absolute(filepath).filename().stem().string());
|
||||
}
|
||||
|
||||
bool install_plugin(const boost::filesystem::path& filepath,
|
||||
const std::string& cloud_user_id,
|
||||
PluginDescriptor& plugin_descriptor,
|
||||
std::string& error,
|
||||
bool* install_target_intact,
|
||||
const PluginInstallState* preserved_state)
|
||||
const PluginInstallState* preserved_state,
|
||||
std::shared_ptr<void> package_lease)
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
if (install_target_intact != nullptr)
|
||||
*install_target_intact = true;
|
||||
|
||||
auto fail = [&error](const std::string& message) {
|
||||
error = GUI::format(_u8L("Plugin installation failed: %1%"), message);
|
||||
return false;
|
||||
};
|
||||
|
||||
// Package lease first, then the sidecar lock. The loader uses the same order, so a package
|
||||
// cannot be replaced or deleted between its identity check and Python import. A caller that
|
||||
// unloaded the old package first passes its lease in, so the lease failure cannot happen
|
||||
// after the unload.
|
||||
if (!package_lease) {
|
||||
const std::string lease_key = !plugin_descriptor.cloud_uuid().empty()
|
||||
? plugin_descriptor.cloud_uuid()
|
||||
: local_plugin_package_key(filepath);
|
||||
std::string lease_error;
|
||||
package_lease = acquire_plugin_package_lease(lease_key, lease_error);
|
||||
if (!package_lease)
|
||||
return fail(_u8L("Cannot install the plugin while its package is being loaded or updated: ") + lease_error);
|
||||
}
|
||||
|
||||
// Serialize the package and sidecar mutation with other processes. The sidecar writes below
|
||||
// take the same lock again and are reentrant on this thread.
|
||||
std::unique_lock<PluginInstallStateMutex> install_lock;
|
||||
std::string install_lock_error;
|
||||
if (!try_lock_plugin_install_state(install_lock, install_lock_error)) {
|
||||
return fail(_u8L("Cannot install the plugin because its install-state lock is unavailable: ") +
|
||||
install_lock_error);
|
||||
}
|
||||
|
||||
const std::string cloud_uuid = plugin_descriptor.cloud_uuid();
|
||||
const bool is_cloud_install = !cloud_uuid.empty();
|
||||
|
||||
fs::path backup_dir;
|
||||
bool backup_created = false;
|
||||
|
||||
auto fail = [&error](const std::string& message) {
|
||||
error = GUI::format(_u8L("Plugin installation failed: %1%"), message);
|
||||
return false;
|
||||
};
|
||||
|
||||
boost::system::error_code ec;
|
||||
const fs::path source_path = canonical_or_absolute(filepath);
|
||||
|
||||
@@ -796,9 +877,11 @@ bool install_plugin(const boost::filesystem::path& filepath,
|
||||
plugin_descriptor.clear_error();
|
||||
|
||||
// Write install state sidecar before removing the backup. The write takes the shared
|
||||
// install-state mutex so it cannot interleave with an in-process read-modify-write writer.
|
||||
// install-state lock so it cannot interleave with a reader or writer in any process.
|
||||
std::string previous_profile_id;
|
||||
std::string installed_profile_id;
|
||||
{
|
||||
std::lock_guard<std::mutex> state_lock(install_state_mutex());
|
||||
std::lock_guard<PluginInstallStateMutex> state_lock(install_state_mutex());
|
||||
|
||||
// Seed the metadata of the package being installed. An update supplies the previous
|
||||
// activation and capability choices; permissions are always reset because the new
|
||||
@@ -810,6 +893,38 @@ bool install_plugin(const boost::filesystem::path& filepath,
|
||||
state.capabilities = preserved_state->capabilities;
|
||||
}
|
||||
|
||||
// Installation browser-profile id. A same-target cloud update of the same UUID keeps it,
|
||||
// so an installed plugin stays signed in across updates and restarts. A local install or
|
||||
// reinstallation gets a fresh id, and the previous profile is removed after the commit.
|
||||
PluginInstallState previous_state;
|
||||
const bool had_previous_state = backup_created && read_install_state(backup_dir, previous_state);
|
||||
std::string profile_id;
|
||||
if (had_previous_state && !previous_state.browser_profile_id.empty() &&
|
||||
!is_uuid(previous_state.browser_profile_id))
|
||||
BOOST_LOG_TRIVIAL(warning) << "Ignoring an invalid browser profile id in " << backup_dir.string()
|
||||
<< "; the replacement starts with a fresh profile";
|
||||
if (is_cloud_install && had_previous_state && previous_state.cloud_uuid == cloud_uuid &&
|
||||
is_uuid(previous_state.browser_profile_id))
|
||||
profile_id = previous_state.browser_profile_id;
|
||||
try {
|
||||
if (profile_id.empty())
|
||||
profile_id = make_plugin_browser_profile_id();
|
||||
state.installation_revision = make_plugin_installation_revision();
|
||||
} catch (const std::exception& ex) {
|
||||
// The backup is already in place; do not let a throwing UUID generator escape without
|
||||
// restoring the package this call replaced.
|
||||
restore_backup();
|
||||
return fail(GUI::format(_u8L("Cannot create a plugin installation identity: %1%"), ex.what()));
|
||||
} catch (...) {
|
||||
restore_backup();
|
||||
return fail(_u8L("Cannot create a plugin installation identity."));
|
||||
}
|
||||
state.browser_profile_id = profile_id;
|
||||
plugin_descriptor.installation_revision = state.installation_revision;
|
||||
installed_profile_id = profile_id;
|
||||
if (had_previous_state && is_uuid(previous_state.browser_profile_id))
|
||||
previous_profile_id = previous_state.browser_profile_id;
|
||||
|
||||
if (!write_install_state(final_dir, state)) {
|
||||
// Roll back: remove new files and restore backup.
|
||||
restore_backup();
|
||||
@@ -829,6 +944,17 @@ bool install_plugin(const boost::filesystem::path& filepath,
|
||||
BOOST_LOG_TRIVIAL(warning) << "Failed to remove plugin backup " << backup_dir.string() << ": " << remove_ec.message();
|
||||
}
|
||||
|
||||
// A replacement with a fresh id must not leave the old installation's profile behind. A
|
||||
// same-id cloud update does not reach here. Best effort: a live lease warns and skips.
|
||||
if (!previous_profile_id.empty() && previous_profile_id != installed_profile_id) {
|
||||
warn_plugin_browser_profile_reset(plugin_descriptor.plugin_key);
|
||||
delete_plugin_browser_profile(plugin_descriptor.plugin_key, previous_profile_id);
|
||||
} else if (backup_created && previous_profile_id.empty()) {
|
||||
// The replaced package had no usable identity (legacy/missing sidecar), so this install
|
||||
// starts a fresh profile. Report the reset rather than dropping the old session silently.
|
||||
warn_plugin_browser_profile_reset(plugin_descriptor.plugin_key);
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Installed plugin " << plugin_descriptor.name << " to " << final_dir.string();
|
||||
|
||||
if (is_cloud_install) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -59,7 +60,12 @@ bool install_plugin(const boost::filesystem::path& filepath,
|
||||
PluginDescriptor& plugin_descriptor,
|
||||
std::string& error,
|
||||
bool* install_target_intact = nullptr,
|
||||
const PluginInstallState* preserved_state = nullptr);
|
||||
const PluginInstallState* preserved_state = nullptr,
|
||||
std::shared_ptr<void> package_lease = {});
|
||||
bool install_plugin(const boost::filesystem::path& filepath, const std::string& cloud_user_id, std::string& error);
|
||||
|
||||
// Canonical local plugin key for a source path, used both for the installed key and for the
|
||||
// package lease. Symlink names therefore cannot select a different lease.
|
||||
std::string local_plugin_package_key(const boost::filesystem::path& filepath);
|
||||
|
||||
} // namespace Slic3r::plugin_loader
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
||||
#include "slic3r/plugin/PluginFsUtils.hpp"
|
||||
#include <slic3r/plugin/PythonPluginInterface.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -35,6 +36,22 @@ namespace Slic3r {
|
||||
|
||||
class OrcaCloudServiceAgent;
|
||||
|
||||
// Explicit result of an unsubscribe-keep-local request. The conversion is committed separately
|
||||
// from the reload so a pending reload is neither success nor failure. For Pending, observe
|
||||
// local_plugin_key through is_plugin_loaded()/subscribe_on_load_callback(); a later failure is
|
||||
// also surfaced as a warning notification. Failed with local_copy_kept=true means the conversion
|
||||
// committed but the reload failed or could not start; reload distinguishes those outcomes.
|
||||
enum class PluginRemovalStatus { Failed, Pending, Succeeded };
|
||||
enum class PluginReloadStatus { NotNeeded, Running, Succeeded, Failed, Cancelled, Busy };
|
||||
struct CloudUnsubscribeResult
|
||||
{
|
||||
PluginRemovalStatus status = PluginRemovalStatus::Failed;
|
||||
bool local_copy_kept = false;
|
||||
PluginReloadStatus reload = PluginReloadStatus::NotNeeded;
|
||||
std::string local_plugin_key; // set once the local conversion is committed
|
||||
std::string error;
|
||||
};
|
||||
|
||||
// One discovered plugin package: one .py/.whl file -> one descriptor + one Python module +
|
||||
// N materialized capabilities.
|
||||
//
|
||||
@@ -179,6 +196,11 @@ public:
|
||||
// Packages that materialize at least one capability of this type. A package's capability types
|
||||
// are only known once it has been loaded, so a never-loaded package never matches.
|
||||
bool try_get_plugin_descriptor(const std::string& plugin_key, PluginDescriptor& out) const;
|
||||
|
||||
// Records the installation revision the loader just wrote for a package root. Used so a
|
||||
// later reload compares against the same installation instead of accepting a replacement.
|
||||
void set_plugin_installation_revision(const std::string& plugin_key, const std::string& plugin_root,
|
||||
const std::string& revision);
|
||||
// Same, but only for packages that are loadable (i.e. not an invalid package).
|
||||
bool try_get_valid_plugin_descriptor(const std::string& plugin_key, PluginDescriptor& out) const;
|
||||
// Packages that were present in the previous discovery pass but were not found on disk in the
|
||||
@@ -213,7 +235,7 @@ public:
|
||||
|
||||
// Reads the sidecar under install_state_mutex(), so the result is not interleaved with a
|
||||
// permission write. Returns false when the plugin is unknown or has no readable sidecar.
|
||||
// Must not be called while already holding install_state_mutex(); the lock is not recursive.
|
||||
// The lock is reentrant per thread, but new code should still avoid nesting it.
|
||||
bool get_install_state(const std::string& plugin_key, PluginInstallState& install_state);
|
||||
|
||||
// Applies a granular edit to the plugin's latest sidecar contents in one locked read-modify-
|
||||
@@ -292,7 +314,9 @@ public:
|
||||
bool update_cloud_plugin(const std::string& plugin_key, std::string& error, std::string version = "");
|
||||
|
||||
bool delete_plugin(const std::string& plugin_key, std::string& error);
|
||||
bool unsubscribe_cloud_plugin(const std::string& plugin_key, std::string& error);
|
||||
// Returns the committed conversion and reload outcome separately. No current UI caller; any
|
||||
// future caller must handle Pending and observe the eventual load result.
|
||||
CloudUnsubscribeResult unsubscribe_cloud_plugin(const std::string& plugin_key);
|
||||
bool delete_and_unsubscribe_cloud_plugin(const std::string& plugin_key, std::string& error);
|
||||
|
||||
ExecutionResult run_script_capability(const std::string& plugin_key, const std::string& capability_name, std::string& error);
|
||||
@@ -350,6 +374,41 @@ private:
|
||||
bool cancel_plugin_load_locked(const std::string& plugin_key);
|
||||
bool is_plugin_load_cancelled_locked(const std::string& plugin_key) const;
|
||||
void notify_plugin_load_state_changed(bool changed);
|
||||
|
||||
// Outcome of a pending keep-local reload, captured under m_mutex so exactly one observer (the
|
||||
// load worker, or the keep-local caller when the load already finished) reports a failure.
|
||||
enum class PendingReloadOwner
|
||||
{
|
||||
Caller, // synchronous keep-local caller takes the outcome after its wait returns
|
||||
Worker, // the load worker reports the eventual outcome
|
||||
};
|
||||
struct PendingReloadOutcome
|
||||
{
|
||||
bool pending = false; // the mark existed at capture time
|
||||
bool claimed = false; // this caller removed the mark and owns reporting
|
||||
bool in_progress = false;
|
||||
bool update_in_progress = false;
|
||||
bool loaded = false;
|
||||
bool cancelled = false;
|
||||
std::string error;
|
||||
};
|
||||
// A resolved entry keeps the exact outcome captured when the load released its slot, so a
|
||||
// later retry cannot change what the synchronous caller reports.
|
||||
struct PendingReloadState
|
||||
{
|
||||
PendingReloadOwner owner = PendingReloadOwner::Worker;
|
||||
bool resolved = false;
|
||||
bool update_at_start = false; // an update already owned the key when marked
|
||||
PendingReloadOutcome outcome;
|
||||
};
|
||||
// Caller holds m_mutex and must not remove the mark.
|
||||
PendingReloadOutcome capture_pending_reload_outcome_locked(const std::string& plugin_key) const;
|
||||
// Caller must not hold m_mutex. Claims an already-finished reload; a running load is marked
|
||||
// for worker reporting and returned as pending, so the caller never reports a running load as
|
||||
// finished. A frozen Caller outcome is returned as-is.
|
||||
PendingReloadOutcome take_finished_pending_reload_outcome(const std::string& plugin_key);
|
||||
// Reports a claimed pending reload outcome outside m_mutex. No-op unless it is a real failure.
|
||||
void report_pending_reload_outcome(const PendingReloadOutcome& outcome);
|
||||
void release_load_slot(const std::string& plugin_key);
|
||||
void cancel_and_wait_for_capabilities(
|
||||
const std::vector<std::shared_ptr<PluginCapabilityInterface>>& capabilities);
|
||||
@@ -369,7 +428,9 @@ private:
|
||||
// read or written is left untouched.
|
||||
void mark_plugin_install_state_disabled(const std::string& plugin_key);
|
||||
// Revoke permissions after a package replacement so the new package must request them again.
|
||||
void revoke_plugin_permissions(const std::string& plugin_key);
|
||||
// Returns false when the sidecar could not be updated, so an install must fail closed instead
|
||||
// of letting new code inherit the replaced package's grants.
|
||||
bool revoke_plugin_permissions(const std::string& plugin_key);
|
||||
|
||||
// Keep the cloud install directory in step with the signed-in agent, as every cloud install
|
||||
// must land in _subscribed/<user_id>/.
|
||||
@@ -394,7 +455,8 @@ private:
|
||||
std::string& error,
|
||||
bool* install_target_intact,
|
||||
const PluginInstallState* preserved_state = nullptr,
|
||||
bool mark_error_on_failure = true);
|
||||
bool mark_error_on_failure = true,
|
||||
std::shared_ptr<void> package_lease = {});
|
||||
|
||||
// Installs an already downloaded cloud package and updates the in-memory descriptor. The
|
||||
// caller owns the package file: it is removed here on both success and failure. cloud_user_id,
|
||||
@@ -409,7 +471,8 @@ private:
|
||||
const std::string* cloud_user_id,
|
||||
std::string& error,
|
||||
CloudUpdateFailure* failure = nullptr,
|
||||
const PluginInstallState* preserved_state = nullptr);
|
||||
const PluginInstallState* preserved_state = nullptr,
|
||||
std::shared_ptr<void> package_lease = {});
|
||||
// Puts back the sidecar (permissions, capability choices and enabled flag) that the unload
|
||||
// step overwrote when a replacement failed and the previous package is still in place.
|
||||
void restore_plugin_state_after_failed_update(const PluginDescriptor& previous,
|
||||
@@ -417,9 +480,12 @@ private:
|
||||
bool had_previous_state,
|
||||
bool was_enabled);
|
||||
|
||||
bool finalize_cloud_plugin_removal(const PluginDescriptor& plugin, bool keep_local, std::string& error);
|
||||
// Conversion + reload outcome for unsubscribe-keep-local.
|
||||
CloudUnsubscribeResult finalize_cloud_unsubscribe(const PluginDescriptor& plugin);
|
||||
CloudUnsubscribeResult keep_installed_plugin_as_local(const PluginDescriptor& plugin_descriptor);
|
||||
// Removal path used when the local package is deleted, not kept.
|
||||
bool finalize_cloud_plugin_removal(const PluginDescriptor& plugin, std::string& error);
|
||||
bool delete_installed_plugin_package(const PluginDescriptor& plugin, std::string& error);
|
||||
bool keep_installed_plugin_as_local(const PluginDescriptor& plugin_descriptor, std::string& error);
|
||||
|
||||
bool m_initialized = false;
|
||||
CloudPluginService m_cloud_service;
|
||||
@@ -448,6 +514,10 @@ private:
|
||||
// Keys whose most recent load attempt failed without being cancelled. Kept separately from
|
||||
// m_load_errors so clearing it never changes the error a load waiter reads.
|
||||
std::unordered_set<std::string> m_failed_loads;
|
||||
// Keep-local conversions with an unresolved reload. Caller-owned entries are resolved by the
|
||||
// load worker at release and kept for the synchronous caller; Worker-owned entries are
|
||||
// captured and reported by the worker. Only one owner ever reports a failure.
|
||||
std::unordered_map<std::string, PendingReloadState> m_pending_local_reloads;
|
||||
std::map<std::string, std::string> m_load_errors;
|
||||
mutable std::condition_variable m_load_cv;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <pybind11/gil.h>
|
||||
#include <pybind11/cast.h>
|
||||
#include "slic3r/plugin/PluginAuditManager.hpp"
|
||||
#include "slic3r/plugin/PluginBrowserProfile.hpp"
|
||||
#include "slic3r/plugin/PythonInterpreter.hpp" // PythonGILState
|
||||
#include "slic3r/plugin/PluginJsonPy.hpp"
|
||||
|
||||
@@ -89,15 +90,28 @@ 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.
|
||||
bool browser_profile_callback_allowed(const PluginBrowserProfileIdentityRef& identity)
|
||||
{
|
||||
return plugin_browser_profile_is_current(identity);
|
||||
}
|
||||
|
||||
GUI::WebDialog::MessageHandler make_message_adapter(py::object on_message, std::string plugin_key,
|
||||
PluginBrowserProfileIdentityRef identity)
|
||||
{
|
||||
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), identity = std::move(identity)](const json& data) {
|
||||
if (!browser_profile_callback_allowed(identity))
|
||||
return;
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn(json_to_py(data));
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -107,15 +121,19 @@ 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,
|
||||
PluginBrowserProfileIdentityRef identity)
|
||||
{
|
||||
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), identity = std::move(identity)](const json& data) {
|
||||
if (!browser_profile_callback_allowed(identity))
|
||||
return;
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn(json_to_py(data));
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -127,14 +145,18 @@ 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,
|
||||
const PluginBrowserProfileIdentityRef& identity)
|
||||
{
|
||||
if (!holder)
|
||||
return nullptr;
|
||||
return [holder]() {
|
||||
return [holder, plugin_key = std::move(plugin_key), identity]() {
|
||||
if (!browser_profile_callback_allowed(identity))
|
||||
return;
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
ScopedPluginAuditContext audit(plugin_key);
|
||||
try {
|
||||
holder->fn();
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -144,6 +166,43 @@ 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;
|
||||
}
|
||||
|
||||
struct UiProfile
|
||||
{
|
||||
std::string plugin_key;
|
||||
std::string profile_id;
|
||||
PluginBrowserProfileIdentityRef identity;
|
||||
BrowserProfileLease lease;
|
||||
};
|
||||
|
||||
// Use the identity bound to this load instance, never a freshly read sidecar: a replacement
|
||||
// installed by another process must not hand its profile/session to an old loaded plugin.
|
||||
UiProfile ui_profile_for(const char* api_name)
|
||||
{
|
||||
UiProfile ui;
|
||||
ui.plugin_key = plugin_identity_for_ui(api_name);
|
||||
ui.identity = current_plugin_browser_profile_identity(ui.plugin_key);
|
||||
if (!ui.identity)
|
||||
throw std::runtime_error("The plugin is not loaded; its browser profile is unavailable");
|
||||
ui.profile_id = ui.identity->profile_id;
|
||||
ui.lease = acquire_plugin_browser_profile_lease(ui.identity);
|
||||
if (!ui.lease) {
|
||||
warn_plugin_browser_profile_in_use(ui.plugin_key);
|
||||
throw std::runtime_error("The plugin browser profile is in use by another OrcaSlicer instance");
|
||||
}
|
||||
return ui;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// 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.
|
||||
@@ -162,17 +221,20 @@ public:
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
return m_next_id++;
|
||||
}
|
||||
void bind(int id, wxWindow* window, const std::string& plugin_key)
|
||||
void bind(int id, wxWindow* window, const std::string& plugin_key, BrowserProfileLease lease = {})
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
m_resources[id] = window;
|
||||
m_owners[id] = plugin_key;
|
||||
if (lease)
|
||||
m_leases[id] = std::move(lease);
|
||||
}
|
||||
void remove(int id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
m_resources.erase(id);
|
||||
m_owners.erase(id);
|
||||
m_leases.erase(id);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -198,6 +260,10 @@ public:
|
||||
auto rit = m_resources.find(it->first);
|
||||
if (rit != m_resources.end()) {
|
||||
out.push_back(rit->second);
|
||||
// A pending (windowless) creation is abandoned now, so its lease must go.
|
||||
// A live window keeps its lease until the destructor's remove().
|
||||
if (rit->second == nullptr)
|
||||
m_leases.erase(it->first);
|
||||
m_resources.erase(rit);
|
||||
}
|
||||
it = m_owners.erase(it);
|
||||
@@ -232,8 +298,9 @@ public:
|
||||
|
||||
private:
|
||||
std::mutex m_mtx;
|
||||
std::unordered_map<int, wxWindow*> m_resources;
|
||||
std::unordered_map<int, std::string> m_owners;
|
||||
std::unordered_map<int, wxWindow*> m_resources;
|
||||
std::unordered_map<int, std::string> m_owners;
|
||||
std::unordered_map<int, BrowserProfileLease> m_leases;
|
||||
std::unordered_map<std::string, std::vector<std::weak_ptr<GilSafeCallable>>> m_callbacks;
|
||||
int m_next_id{1};
|
||||
};
|
||||
@@ -373,13 +440,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 +447,16 @@ 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");
|
||||
|
||||
UiProfile ui = ui_profile_for("orca.host.ui.create_window");
|
||||
const std::string plugin_key = ui.plugin_key;
|
||||
const std::string profile_id = ui.profile_id;
|
||||
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, ui.identity);
|
||||
auto submit_adapter = make_submit_adapter(std::move(on_submit), plugin_key, ui.identity);
|
||||
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,
|
||||
@@ -405,9 +475,9 @@ py::object ui_create_window(const std::string& html, const std::string& title, i
|
||||
// FIFO-ordered after the creation below, and a plugin teardown claims the pending
|
||||
// id (take_for_plugin), which the creation detects and skips — no orphan window.
|
||||
const int new_id = UiRegistry::instance().reserve_id();
|
||||
UiRegistry::instance().bind(new_id, nullptr, plugin_key);
|
||||
UiRegistry::instance().bind(new_id, nullptr, plugin_key, ui.lease);
|
||||
|
||||
GUI::wxGetApp().CallAfter([new_id, plugin_key, html, title, w, h,
|
||||
GUI::wxGetApp().CallAfter([new_id, plugin_key, profile_id, identity = ui.identity, lease = ui.lease, html, title, w, h,
|
||||
msg_adapter = std::move(msg_adapter),
|
||||
submit_adapter = std::move(submit_adapter),
|
||||
close_holder = std::move(close_holder), modal]() mutable {
|
||||
@@ -415,14 +485,15 @@ 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, identity);
|
||||
// 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);
|
||||
UiRegistry::instance().bind(new_id, dlg, plugin_key);
|
||||
std::move(on_close), std::move(on_destroyed), PLUGIN_WX_STYLE,
|
||||
wxString::FromUTF8(profile_id));
|
||||
UiRegistry::instance().bind(new_id, dlg, plugin_key, lease);
|
||||
if (modal) {
|
||||
dlg->ShowModal();
|
||||
// Plugin teardown may already have removed and destroyed this dialog
|
||||
@@ -492,20 +563,23 @@ 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");
|
||||
|
||||
UiProfile ui = ui_profile_for("orca.host.ui.create_dock_panel");
|
||||
const std::string plugin_key = ui.plugin_key;
|
||||
const std::string profile_id = ui.profile_id;
|
||||
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, ui.identity);
|
||||
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);
|
||||
UiRegistry::instance().bind(new_id, nullptr, plugin_key, ui.lease);
|
||||
|
||||
run_when_plater_shown([new_id, plugin_key, html, title, dock, w, h,
|
||||
run_when_plater_shown([new_id, plugin_key, profile_id, identity = ui.identity, lease = ui.lease, html, title, dock, w, h,
|
||||
msg_adapter = std::move(msg_adapter),
|
||||
close_holder = std::move(close_holder)](GUI::Plater* plater) mutable {
|
||||
if (!UiRegistry::instance().is_open(new_id))
|
||||
@@ -517,9 +591,10 @@ 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));
|
||||
UiRegistry::instance().bind(new_id, panel, plugin_key);
|
||||
auto* panel = new GUI::DockPanel(plater, html, std::move(msg_adapter),
|
||||
make_close_adapter(close_holder, plugin_key, identity),
|
||||
std::move(on_destroyed), wxString::FromUTF8(profile_id));
|
||||
UiRegistry::instance().bind(new_id, panel, plugin_key, lease);
|
||||
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 +715,32 @@ 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)
|
||||
PluginBrowserProfileIdentityRef identity;
|
||||
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");
|
||||
identity = current_plugin_browser_profile_identity(plugin_key);
|
||||
if (!identity)
|
||||
throw std::runtime_error("The plugin is not loaded; its browser profile is unavailable");
|
||||
UiRegistry::instance().bind_callback(holder, plugin_key);
|
||||
}
|
||||
|
||||
std::function<bool(wxEvtHandler*)> callback;
|
||||
if (holder) {
|
||||
callback = [holder](wxEvtHandler*) -> bool {
|
||||
callback = [holder, plugin_key, identity](wxEvtHandler*) -> bool {
|
||||
if (!holder->active.load(std::memory_order_acquire))
|
||||
return false;
|
||||
if (!browser_profile_callback_allowed(identity))
|
||||
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>();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <cstddef>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "slic3r/plugin/PluginBrowserProfile.hpp"
|
||||
#include "slic3r/plugin/pluginTypes/pages/PagesPluginCapability.hpp"
|
||||
#include "slic3r/GUI/WebPanel.hpp"
|
||||
#include <optional>
|
||||
@@ -77,10 +78,13 @@ 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)
|
||||
PluginPage::PluginPage(wxWindow* parent, std::shared_ptr<PagesPluginCapability> capability,
|
||||
PluginBrowserProfileIdentityRef identity, const wxString& profile, BrowserProfileLease lease)
|
||||
: GUI::WebPanel(parent, PLUGIN_PAGE_BRIDGE_JS, profile)
|
||||
, m_cap(std::move(capability))
|
||||
, m_lifetime(std::make_shared<std::atomic<PluginPage*>>(this))
|
||||
, m_lease(std::move(lease))
|
||||
, m_identity(std::move(identity))
|
||||
{
|
||||
browser()->Bind(wxEVT_WEBVIEW_NEWWINDOW, &PluginPage::on_new_window, this);
|
||||
|
||||
@@ -143,6 +147,8 @@ bool PluginPage::on_page_message(const std::string& kind, const nlohmann::json&
|
||||
return false;
|
||||
if (!m_cap)
|
||||
return true;
|
||||
if (!plugin_browser_profile_is_current(m_identity))
|
||||
return true;
|
||||
|
||||
try {
|
||||
m_cap->on_message(data.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
|
||||
@@ -221,6 +227,14 @@ bool PluginPages::create_page(const PluginCapabilityId& id)
|
||||
if (!capability)
|
||||
return false;
|
||||
|
||||
PluginBrowserProfileIdentityRef identity = current_plugin_browser_profile_identity(id.plugin_key);
|
||||
if (!identity) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " The plugin is not loaded; no browser profile for "
|
||||
<< id.plugin_key;
|
||||
return false;
|
||||
}
|
||||
const std::string profile_id = identity->profile_id;
|
||||
|
||||
std::string icon;
|
||||
try {
|
||||
icon = capability->get_icon();
|
||||
@@ -249,10 +263,21 @@ bool PluginPages::create_page(const PluginCapabilityId& id)
|
||||
// Built the first time its tab is shown, so a language switch never creates the page's browser
|
||||
// while the main window is being rebuilt. Never prebuilt: the idle queue cannot drop a page
|
||||
// that remove_page() destroys.
|
||||
auto* page = new GUI::LazyPage<PluginPage>(m_parent, GUI::into_u8(page_tab_id(id)), -1,
|
||||
[capability = std::move(capability)](wxWindow* parent) {
|
||||
return new PluginPage(parent, capability);
|
||||
});
|
||||
auto* page = new GUI::LazyPage<PluginPage>(
|
||||
m_parent, GUI::into_u8(page_tab_id(id)), -1,
|
||||
[capability = std::move(capability), identity, plugin_key = id.plugin_key,
|
||||
profile = wxString::FromUTF8(profile_id)](wxWindow* parent) -> PluginPage* {
|
||||
// Take the lease only when the page is actually built. A failed attempt returns null
|
||||
// and LazyPage retries on the next show instead of permanently failing the tab.
|
||||
BrowserProfileLease lease = acquire_plugin_browser_profile_lease(identity);
|
||||
if (!lease) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "PluginPages: the plugin browser profile is in use by another "
|
||||
<< "OrcaSlicer instance: " << plugin_key;
|
||||
warn_plugin_browser_profile_in_use(plugin_key);
|
||||
return nullptr;
|
||||
}
|
||||
return new PluginPage(parent, capability, identity, profile, lease);
|
||||
});
|
||||
|
||||
m_pages.emplace(id, Page{page, bitmap});
|
||||
m_order.push_back(id);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <slic3r/GUI/LazyPage.hpp>
|
||||
#include <slic3r/GUI/WebPanel.hpp>
|
||||
#include <slic3r/plugin/PluginBrowserProfile.hpp>
|
||||
#include <slic3r/plugin/PythonPluginInterface.hpp>
|
||||
#include <slic3r/plugin/pluginTypes/pages/PagesPluginCapability.hpp>
|
||||
|
||||
@@ -26,7 +27,8 @@ namespace Slic3r {
|
||||
class PluginPage : public GUI::WebPanel
|
||||
{
|
||||
public:
|
||||
PluginPage(wxWindow* parent, std::shared_ptr<PagesPluginCapability> capability);
|
||||
PluginPage(wxWindow* parent, std::shared_ptr<PagesPluginCapability> capability,
|
||||
PluginBrowserProfileIdentityRef identity, const wxString& profile, BrowserProfileLease lease);
|
||||
~PluginPage() override;
|
||||
|
||||
PluginPage() = delete;
|
||||
@@ -41,8 +43,10 @@ protected:
|
||||
private:
|
||||
void on_new_window(wxWebViewEvent& event);
|
||||
|
||||
std::shared_ptr<PagesPluginCapability> m_cap;
|
||||
std::shared_ptr<PagesPluginCapability> m_cap;
|
||||
std::shared_ptr<std::atomic<PluginPage*>> m_lifetime;
|
||||
BrowserProfileLease m_lease;
|
||||
PluginBrowserProfileIdentityRef m_identity;
|
||||
};
|
||||
|
||||
class PluginPages
|
||||
|
||||
@@ -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