summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-07-14 10:32:46 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-07-14 11:52:00 +0200
commit19d473da14ac877cb0721063c7b18e16cb6f2b76 (patch)
treeac94142829df1dc22303ef02f6bac7d76334a50c /sfx2/source
parent686b2d70fe6361835a9c549ca13ecf0837b82296 (diff)
sfx2: handle OnMainThread=true in SfxOfficeDispatch::dispatch()
This is needed when an out of process Java UNO client registers their command dispatch interceptor, Windows OleInitialize() has been called already on the main thread and then dispatching e.g. uno:Paste (which would interact with OLE) would call OLE functions on a thread, which would fail with RPC_E_CHANGED_MODE. In other words, a situation similar to commit 22aa6508e0a65e65a6f9410b498fe4fd6c236639 (framework: allow dispatching a command on the main thread, 2019-01-29), but that one was for DispatchHelper, this one is for XDispatch implementations. Change-Id: If5a80fe36962e014e781d2a8c156055f127e69a5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118886 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/control/unoctitm.cxx21
1 files changed, 20 insertions, 1 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 0a98f806d708..bc07f2af71d3 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -78,6 +78,8 @@
#include <comphelper/lok.hxx>
#include <desktop/crashreport.hxx>
+#include <vcl/threadex.hxx>
+#include <unotools/mediadescriptor.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -233,7 +235,24 @@ void SAL_CALL SfxOfficeDispatch::dispatch( const css::util::URL& aURL, const css
#if HAVE_FEATURE_JAVA
std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext());
#endif
- pImpl->dispatch( aURL, aArgs, css::uno::Reference < css::frame::XDispatchResultListener >() );
+ utl::MediaDescriptor aDescriptor(aArgs);
+ bool bOnMainThread = aDescriptor.getUnpackedValueOrDefault("OnMainThread", false);
+ if (bOnMainThread)
+ {
+ // Make sure that we own the solar mutex, otherwise later
+ // vcl::SolarThreadExecutor::execute() will release the solar mutex, even if it's owned by
+ // an other thread, leading to an std::abort() at the end.
+ SolarMutexGuard aGuard;
+ vcl::solarthread::syncExecute([this, &aURL, &aArgs]() {
+ pImpl->dispatch(aURL, aArgs,
+ css::uno::Reference<css::frame::XDispatchResultListener>());
+ });
+ }
+ else
+ {
+ pImpl->dispatch(aURL, aArgs,
+ css::uno::Reference<css::frame::XDispatchResultListener>());
+ }
}
}