basctl/source/basicide/docsignature.cxx | 2 - include/sfx2/docfile.hxx | 3 + include/sfx2/objsh.hxx | 2 - sfx2/source/doc/docfile.cxx | 8 +++-- sfx2/source/doc/objserv.cxx | 51 +++++++++++++++++++------------- 5 files changed, 40 insertions(+), 26 deletions(-)
New commits: commit de0bc0a2c30a76144b47e9abb17770043813133c Author: Miklos Vajna <[email protected]> AuthorDate: Fri Sep 6 09:47:25 2024 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Sep 6 12:25:48 2024 +0200 cool#9992 lok doc sign: make SfxMedium::SignContents_Impl() async Currently SfxObjectShell::CheckIsReadonly() has a hack for the LOK case to show the signatures dialog read-only, as only that is async. The next step to get rid of this hack is to make SfxMedium::SignContents_Impl() async, now that SfxObjectShell::SignDocumentContent() is async. This requires all callers of SfxMedium::SignContents_Impl() to be async, most notably SfxObjectShell::SignScriptingContent() has to be converted as well. Note that no lifecycle problem is expected here for the callback, since the object shell and its medium is typically around for as long as the document is loaded. Change-Id: I57f2c747f8448b9adc0398f874ede36211fed817 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172934 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]> diff --git a/basctl/source/basicide/docsignature.cxx b/basctl/source/basicide/docsignature.cxx index 08d7a1ab9c13..ee04435274db 100644 --- a/basctl/source/basicide/docsignature.cxx +++ b/basctl/source/basicide/docsignature.cxx @@ -60,7 +60,7 @@ namespace basctl { OSL_PRECOND( supportsSignatures(), "DocumentSignature::signScriptingContent: signatures not supported by this document!" ); if ( m_pShell ) - m_pShell->SignScriptingContent(pDialogParent); + m_pShell->SignScriptingContent(pDialogParent, [](bool /*bSigned*/){}); } SignatureState DocumentSignature::getScriptingSignatureState() const diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx index 9f7217cd01f4..e2b826886c45 100644 --- a/include/sfx2/docfile.hxx +++ b/include/sfx2/docfile.hxx @@ -272,9 +272,10 @@ public: const INetURLObject& aDest, const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv ); - SAL_DLLPRIVATE bool + SAL_DLLPRIVATE void SignContents_Impl(weld::Window* pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, + const std::function<void(bool)>& rCallback, const OUString& aSignatureLineId = OUString(), const css::uno::Reference<css::security::XCertificate>& xCert = css::uno::Reference<css::security::XCertificate>(), diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index ef1c0a5ce992..bad832977f65 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -377,7 +377,7 @@ public: const css::uno::Reference<css::graphic::XGraphic>& xInvalidGraphic, const OUString& aComment); SignatureState GetScriptingSignatureState(); - bool SignScriptingContent(weld::Window* pDialogParent); + void SignScriptingContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback); DECL_DLLPRIVATE_LINK(SignDocumentHandler, weld::Button&, void); virtual std::shared_ptr<SfxDocumentInfoDialog> CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet& rItemSet); diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 286495b7918f..ee9308f51bfe 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -4304,9 +4304,10 @@ bool SfxMedium::SignDocumentContentUsingCertificate( } // note: this is the only function creating scripting signature -bool SfxMedium::SignContents_Impl(weld::Window* pDialogParent, +void SfxMedium::SignContents_Impl(weld::Window* pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, + const std::function<void(bool)>& rCallback, const OUString& aSignatureLineId, const Reference<XCertificate>& xCert, const Reference<XGraphic>& xValidGraphic, @@ -4318,7 +4319,8 @@ bool SfxMedium::SignContents_Impl(weld::Window* pDialogParent, if (IsOpen() || GetErrorIgnoreWarning()) { SAL_WARN("sfx.doc", "The medium must be closed by the signer!"); - return bChanges; + rCallback(bChanges); + return; } // The component should know if there was a valid document signature, since @@ -4500,7 +4502,7 @@ bool SfxMedium::SignContents_Impl(weld::Window* pDialogParent, ResetError(); - return bChanges; + rCallback(bChanges); } diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 47ca96f0338e..786c03d9593c 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -607,7 +607,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) } else { - bHaveWeSigned |= SignScriptingContent(pDialogParent); + // Async, all code before return has to go into the callback. + SignScriptingContent(pDialogParent, [this, pDialogParent] (bool bSigned) { + AfterSignContent(bSigned, pDialogParent); + }); + return; } AfterSignContent(bHaveWeSigned, pDialogParent); @@ -2144,11 +2148,12 @@ void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent, const std: return; } - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures()); - - AfterSigning(bSignSuccess, false); + // Async, all code before the end has to go into the callback. + GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures(), [this, rCallback](bool bSignSuccess) { + AfterSigning(bSignSuccess, false); - rCallback(bSignSuccess); + rCallback(bSignSuccess); + }); } bool SfxObjectShell::ResignDocument(uno::Sequence< security::DocumentSignatureInformation >& rSignaturesInfo) @@ -2259,15 +2264,15 @@ void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, if (CheckIsReadonly(false, pDialogParent)) return; - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, - false, HasValidSignatures(), aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); - - AfterSigning(bSignSuccess, false); + GetMedium()->SignContents_Impl(pDialogParent, + false, HasValidSignatures(), [this](bool bSignSuccess) { + AfterSigning(bSignSuccess, false); - // Reload the document to get the updated graphic - // FIXME: Update just the signature line graphic instead of reloading the document - if (SfxViewFrame* pFrame = GetFrame()) - pFrame->GetDispatcher()->Execute(SID_RELOAD); + // Reload the document to get the updated graphic + // FIXME: Update just the signature line graphic instead of reloading the document + if (SfxViewFrame* pFrame = GetFrame()) + pFrame->GetDispatcher()->Execute(SID_RELOAD); + }, aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); } SignatureState SfxObjectShell::GetScriptingSignatureState() @@ -2275,19 +2280,25 @@ SignatureState SfxObjectShell::GetScriptingSignatureState() return ImplGetSignatureState( true ); } -bool SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent) +void SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback) { if (!PrepareForSigning(pDialogParent)) - return false; + { + rCallback(false); + return; + } if (CheckIsReadonly(true, pDialogParent)) - return false; - - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures()); + { + rCallback(false); + return; + } - AfterSigning(bSignSuccess, true); + GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures(), [this, rCallback](bool bSignSuccess) { + AfterSigning(bSignSuccess, true); - return bSignSuccess; + rCallback(bSignSuccess); + }); } const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
