include/sfx2/digitalsignatures.hxx | 3 ++ include/sfx2/docfile.hxx | 2 + sfx2/source/doc/docfile.cxx | 7 +++--- sfx2/source/doc/objserv.cxx | 14 +++++++++---- xmlsecurity/inc/digitalsignaturesdialog.hxx | 4 ++- xmlsecurity/source/component/documentdigitalsignatures.cxx | 13 +++++++----- xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 10 +++++++-- 7 files changed, 38 insertions(+), 15 deletions(-)
New commits: commit c57434559cf5ffd82c3c72e8a0884d4874885dca Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Sep 26 09:07:41 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Sep 26 11:06:06 2024 +0200 cool#9992 lok doc sign: conditionally show the add button in the sign dialog Open the sign dialog, the Add button is hidden, even if the LOK clients initializes the view with a working signing certificate. SfxMedium::SignContents_Impl() knows the correct view, but by the time the execution arrives to the DigitalSignaturesDialog ctor, this info is lost, so we don't know what is the current view. Fix the problem by looking up the view of the object shell at UNO command dispatch time, and passing that around, so the signature dialog can also access it. If the view has a signing certificate configured, then allow signing. The certificate chooser triggered by this button still needs fixing. Change-Id: I1fae63cea27ea1e68e938879f4507f53ade484f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173964 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/include/sfx2/digitalsignatures.hxx b/include/sfx2/digitalsignatures.hxx index 856e1c5bf61a..84b77fd759dd 100644 --- a/include/sfx2/digitalsignatures.hxx +++ b/include/sfx2/digitalsignatures.hxx @@ -18,6 +18,8 @@ #include <sal/types.h> +class SfxViewShell; + namespace sfx2 { /// Extension of css::security::XDocumentDigitalSignatures for internal purposes. @@ -35,6 +37,7 @@ public: /// Async replacement for signDocumentContent(). virtual void SignDocumentContentAsync(const css::uno::Reference<css::embed::XStorage>& xStorage, const css::uno::Reference<css::io::XStream>& xSignStream, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback) = 0; diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx index e2b826886c45..17d409c8d134 100644 --- a/include/sfx2/docfile.hxx +++ b/include/sfx2/docfile.hxx @@ -53,6 +53,7 @@ class SfxFilter; class SfxMedium_Impl; class INetURLObject; class SfxFrame; +class SfxViewShell; class DateTime; struct ImplSVEvent; @@ -275,6 +276,7 @@ public: SAL_DLLPRIVATE void SignContents_Impl(weld::Window* pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback, const OUString& aSignatureLineId = OUString(), const css::uno::Reference<css::security::XCertificate>& xCert diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 72632cd16b83..016b25429098 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -4312,6 +4312,7 @@ bool SfxMedium::SignDocumentContentUsingCertificate( void SfxMedium::SignContents_Impl(weld::Window* pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback, const OUString& aSignatureLineId, const Reference<XCertificate>& xCert, @@ -4501,7 +4502,7 @@ void SfxMedium::SignContents_Impl(weld::Window* pDialogParent, // Async, all code before return has to go into the callback. xModelSigner->SignDocumentContentAsync(GetZipStorageToSign_Impl(), - xStream, [onODFSignDocumentContentFinished, onSignDocumentContentFinished](bool bRet) { + xStream, pViewShell, [onODFSignDocumentContentFinished, onSignDocumentContentFinished](bool bRet) { if (bRet) { onODFSignDocumentContentFinished(); @@ -4541,7 +4542,7 @@ void SfxMedium::SignContents_Impl(weld::Window* pDialogParent, { // We need read-write to be able to add the signature relation. xModelSigner->SignDocumentContentAsync( - GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream, [onOOXMLSignDocumentContentFinished, onSignDocumentContentFinished](bool bRet) { + GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream, pViewShell, [onOOXMLSignDocumentContentFinished, onSignDocumentContentFinished](bool bRet) { if (bRet) { onOOXMLSignDocumentContentFinished(); @@ -4563,7 +4564,7 @@ void SfxMedium::SignContents_Impl(weld::Window* pDialogParent, // Something not ZIP based: e.g. PDF. std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ | StreamMode::WRITE)); uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(std::move(pStream))); - xModelSigner->SignDocumentContentAsync(uno::Reference<embed::XStorage>(), xStream, [onSignDocumentContentFinished](bool bRet) { + xModelSigner->SignDocumentContentAsync(uno::Reference<embed::XStorage>(), xStream, pViewShell, [onSignDocumentContentFinished](bool bRet) { onSignDocumentContentFinished(bRet); }); return; diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 1973ba4f29da..a6ac42734c17 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -2147,8 +2147,10 @@ void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent, const std: return; } + SfxViewFrame* pFrame = GetFrame(); + SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; // Async, all code before the end has to go into the callback. - GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures(), [this, rCallback](bool bSignSuccess) { + GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures(), pViewShell, [this, rCallback](bool bSignSuccess) { AfterSigning(bSignSuccess, false); rCallback(bSignSuccess); @@ -2263,13 +2265,15 @@ void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, if (CheckIsReadonly(false, pDialogParent)) return; + SfxViewFrame* pFrame = GetFrame(); + SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; GetMedium()->SignContents_Impl(pDialogParent, - false, HasValidSignatures(), [this](bool bSignSuccess) { + false, HasValidSignatures(), pViewShell, [this, pFrame](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()) + if (pFrame) pFrame->GetDispatcher()->Execute(SID_RELOAD); }, aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); } @@ -2293,7 +2297,9 @@ void SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent, const std return; } - GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures(), [this, rCallback](bool bSignSuccess) { + SfxViewFrame* pFrame = GetFrame(); + SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; + GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures(), pViewShell, [this, rCallback](bool bSignSuccess) { AfterSigning(bSignSuccess, true); rCallback(bSignSuccess); diff --git a/xmlsecurity/inc/digitalsignaturesdialog.hxx b/xmlsecurity/inc/digitalsignaturesdialog.hxx index a821d1487d0c..11331ff7db36 100644 --- a/xmlsecurity/inc/digitalsignaturesdialog.hxx +++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx @@ -34,6 +34,7 @@ namespace com::sun::star { class HeaderBar; class CertificateViewer; +class SfxViewShell; class DigitalSignaturesDialog final : public weld::GenericDialogController { @@ -99,7 +100,8 @@ private: public: DigitalSignaturesDialog(weld::Window* pParent, const css::uno::Reference< css::uno::XComponentContext >& rxCtx, DocumentSignatureMode eMode, - bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature); + bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature, + SfxViewShell* pViewShell); virtual ~DigitalSignaturesDialog() override; // Initialize the dialog and the security environment, returns TRUE on success diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 07512080cf9e..af6551d7c7e5 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -85,6 +85,7 @@ private: void ImplViewSignatures(const css::uno::Reference<css::embed::XStorage>& rxStorage, const css::uno::Reference<css::io::XStream>& xSignStream, DocumentSignatureMode eMode, bool bReadOnly, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback); /// @throws css::uno::RuntimeException void ImplViewSignatures(const css::uno::Reference<css::embed::XStorage>& rxStorage, @@ -195,6 +196,7 @@ public: /// See sfx2::DigitalSignatures::SignDocumentContentAsync(). void SignDocumentContentAsync(const css::uno::Reference<css::embed::XStorage>& xStorage, const css::uno::Reference<css::io::XStream>& xSignStream, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback) override; /// See sfx2::DigitalSignatures::SignScriptingContentAsync(). void SignScriptingContentAsync(const css::uno::Reference<css::embed::XStorage>& xStorage, @@ -364,17 +366,17 @@ void DocumentDigitalSignatures::ImplViewSignatures( Reference< io::XStream > xStream; if ( xSignStream.is() ) xStream.set( xSignStream, UNO_QUERY ); - ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly, [](bool /*bSuccess*/){} ); + ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly, nullptr, [](bool /*bSuccess*/){} ); } void DocumentDigitalSignatures::ImplViewSignatures( const Reference< css::embed::XStorage >& rxStorage, const Reference< css::io::XStream >& xSignStream, - DocumentSignatureMode eMode, bool bReadOnly, const std::function<void(bool)>& rCallback ) + DocumentSignatureMode eMode, bool bReadOnly, SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback ) { bool bChanges = false; auto xSignaturesDialog = std::make_shared<DigitalSignaturesDialog>( Application::GetFrameWeld(mxParentWindow), mxCtx, eMode, bReadOnly, m_sODFVersion, - m_bHasDocumentSignature); + m_bHasDocumentSignature, pViewShell); bool bInit = xSignaturesDialog->Init(); SAL_WARN_IF( !bInit, "xmlsecurity.comp", "Error initializing security context!" ); if ( bInit ) @@ -773,10 +775,11 @@ bool DocumentDigitalSignatures::SignModelWithCertificate( void DocumentDigitalSignatures::SignDocumentContentAsync(const css::uno::Reference<css::embed::XStorage>& rxStorage, const css::uno::Reference<css::io::XStream>& xSignStream, + SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback) { OSL_ENSURE(!m_sODFVersion.isEmpty(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2"); - ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Content, false, rCallback ); + ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Content, false, pViewShell, rCallback ); } void DocumentDigitalSignatures::SignScriptingContentAsync( @@ -785,7 +788,7 @@ void DocumentDigitalSignatures::SignScriptingContentAsync( { OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2"); OSL_ENSURE(m_nArgumentsCount == 2, "DocumentDigitalSignatures: Service was not initialized properly"); - ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Macros, false, rCallback ); + ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Macros, false, nullptr, rCallback ); } void DocumentDigitalSignatures::SetSignScriptingContent( diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index b66158e454ed..4dcd9d387ccc 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -52,6 +52,7 @@ #include <utility> #include <vcl/weld.hxx> #include <vcl/svapp.hxx> +#include <sfx2/viewsh.hxx> #ifdef _WIN32 #include <o3tl/char16_t2wchar_t.hxx> @@ -192,7 +193,8 @@ bool IsThereCertificateMgr() DigitalSignaturesDialog::DigitalSignaturesDialog( weld::Window* pParent, const uno::Reference< uno::XComponentContext >& rxCtx, DocumentSignatureMode eMode, - bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature) + bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature, + SfxViewShell* pViewShell) : GenericDialogController(pParent, u"xmlsec/ui/digitalsignaturesdialog.ui"_ustr, u"DigitalSignaturesDialog"_ustr) , maSignatureManager(rxCtx, eMode) , m_sODFVersion (std::move(sODFVersion)) @@ -259,7 +261,11 @@ DigitalSignaturesDialog::DigitalSignaturesDialog( if (comphelper::LibreOfficeKit::isActive()) { - m_xAddBtn->hide(); + // If the view has a signing certificate, then allow adding a signature. + if (!pViewShell || !pViewShell->GetSigningCertificate().is()) + { + m_xAddBtn->hide(); + } m_xStartCertMgrBtn->hide(); }