Kaydet (Commit) f1e77547 authored tarafından Miklos Vajna's avatar Miklos Vajna

framework: allow storeSelf() on the main thread

This is similar to commit 22aa6508
(framework: allow dispatching a command on the main thread, 2019-01-29),
except it addresses the scenario where save is performed with an UNO API
call, not with a dispatched command.

This way both load and save is possible on the main thread, providing a
safe way to interact with documents containing OLE objects on Windows.

Change-Id: I3516c944ece8ed0e26aa13fc9def5857b8344404
Reviewed-on: https://gerrit.libreoffice.org/67109Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst 7d6f30d0
......@@ -125,6 +125,7 @@
#include "printhelper.hxx"
#include <sfx2/sfxresid.hxx>
#include <comphelper/profilezone.hxx>
#include <vcl/threadex.hxx>
// namespaces
......@@ -1494,6 +1495,14 @@ sal_Bool SAL_CALL SfxBaseModel::isReadonly()
return !m_pData->m_pObjectShell.is() || m_pData->m_pObjectShell->IsReadOnly();
}
/**
* Proxy around SfxObjectShell::Save_Impl(), as vcl::solarthread::syncExecute()
* does not seem to accept lambdas.
*/
static bool SaveImplStatic(SfxObjectShell* pThis, const SfxItemSet* pParams)
{
return pThis->Save_Impl(pParams);
}
// XStorable2
......@@ -1507,6 +1516,7 @@ void SAL_CALL SfxBaseModel::storeSelf( const Sequence< beans::PropertyValue >
SfxSaveGuard aSaveGuard(this, m_pData.get());
bool bCheckIn = false;
bool bOnMainThread = false;
for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
{
// check that only acceptable parameters are provided here
......@@ -1516,7 +1526,8 @@ void SAL_CALL SfxBaseModel::storeSelf( const Sequence< beans::PropertyValue >
&& aSeqArgs[nInd].Name != "VersionMajor"
&& aSeqArgs[nInd].Name != "FailOnWarning"
&& aSeqArgs[nInd].Name != "CheckIn"
&& aSeqArgs[nInd].Name != "NoFileSync" )
&& aSeqArgs[nInd].Name != "NoFileSync"
&& aSeqArgs[nInd].Name != "OnMainThread" )
{
const OUString aMessage( "Unexpected MediaDescriptor parameter: " + aSeqArgs[nInd].Name );
throw lang::IllegalArgumentException( aMessage, Reference< XInterface >(), 1 );
......@@ -1525,6 +1536,10 @@ void SAL_CALL SfxBaseModel::storeSelf( const Sequence< beans::PropertyValue >
{
aSeqArgs[nInd].Value >>= bCheckIn;
}
else if (aSeqArgs[nInd].Name == "OnMainThread")
{
aSeqArgs[nInd].Value >>= bOnMainThread;
}
}
// Remove CheckIn property if needed
......@@ -1576,7 +1591,11 @@ void SAL_CALL SfxBaseModel::storeSelf( const Sequence< beans::PropertyValue >
{
// Tell the SfxMedium if we are in checkin instead of normal save
m_pData->m_pObjectShell->GetMedium( )->SetInCheckIn( nSlotId == SID_CHECKIN );
bRet = m_pData->m_pObjectShell->Save_Impl( pParams.get() );
if (bOnMainThread)
bRet = vcl::solarthread::syncExecute(
std::bind(&SaveImplStatic, m_pData->m_pObjectShell.get(), pParams.get()));
else
bRet = m_pData->m_pObjectShell->Save_Impl(pParams.get());
m_pData->m_pObjectShell->GetMedium( )->SetInCheckIn( nSlotId != SID_CHECKIN );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment