vcl/jsdialog/enabled.cxx | 1 xmlsecurity/inc/certificatechooser.hxx | 5 - xmlsecurity/source/component/documentdigitalsignatures.cxx | 2 xmlsecurity/source/dialogs/certificatechooser.cxx | 17 +++ xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 57 +++++++------ 5 files changed, 50 insertions(+), 32 deletions(-)
New commits: commit a20c92d864acb93be42bf1585b2aec4717b8409b Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Sep 30 13:13:32 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Oct 1 10:31:08 2024 +0200 cool#9992 lok doc sign: convert the certificate chooser dialog to async 1) Move the try-catch around assing a signature inside the block that already got the response from the certificate chooser, it's unlikely that choosing the certificate (and not yet signing) would fail. 2) Convert the dialog to async and allow it to be a jsdialog. 3) Hide not relevant widgets for LOK: we have a single signing certificate, so the search entry is not useful. The refresh button has an unclear purpose, as it was initially added in commit fb9874231fb242b4a6a7d1ce097e66dd4ed8f32e (Caching Certificates in the CertificateChooser dialog session-wise, 2023-08-26), but later commit efe414c4a88fde0e2ee1d4016010f21fbd6d01d7 (Don't reuse CertificateChooser instances, 2024-02-07) disabled this chaching. In any case, the certificate won't change during the lifetime of a single LOK view, so hide that as well. 4) Invoke the inner certificate viewer in an async way, too. (cherry picked from commit ced420ca708eb8df5b20c7d537166bd9ec29a0e5) Conflicts: xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx Change-Id: Ibf618ea7632cf801d1d9180b9aa7dd193c45ffda Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174308 Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx index 4a4ec205d3c5..c932806820fb 100644 --- a/vcl/jsdialog/enabled.cxx +++ b/vcl/jsdialog/enabled.cxx @@ -286,6 +286,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool bMobile) || rUIFile == u"xmlsec/ui/certgeneral.ui" || rUIFile == u"xmlsec/ui/certpage.ui" || rUIFile == u"xmlsec/ui/digitalsignaturesdialog.ui" + || rUIFile == u"xmlsec/ui/selectcertificatedialog.ui" || rUIFile == u"xmlsec/ui/viewcertdialog.ui" ) { diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx index 344a9d48f3c2..ecd511ad8f24 100644 --- a/xmlsecurity/inc/certificatechooser.hxx +++ b/xmlsecurity/inc/certificatechooser.hxx @@ -93,7 +93,7 @@ public: UserAction eAction); virtual ~CertificateChooser() override; - static std::unique_ptr<CertificateChooser> getInstance(weld::Window* _pParent, + static std::shared_ptr<CertificateChooser> getInstance(weld::Window* _pParent, SfxViewShell* pViewShell, std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts, UserAction eAction) { @@ -105,9 +105,10 @@ public: // in the Digital Signatures dialog // 2. File > Save As the document, check the "Encrypt with GPG key" // checkbox, press Encrypt, and crash in Dialog::ImplStartExecute() - return std::make_unique<CertificateChooser>(_pParent, pViewShell, std::move(rxSecurityContexts), eAction); + return std::make_shared<CertificateChooser>(_pParent, pViewShell, std::move(rxSecurityContexts), eAction); } + void BeforeRun(); short run() override; css::uno::Sequence<css::uno::Reference< css::security::XCertificate > > GetSelectedCertificates(); diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 5168ca46855c..5b5d29d37b8b 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -722,7 +722,7 @@ DocumentDigitalSignatures::chooseCertificatesImpl(std::map<OUString, OUString>& xSecContexts.push_back(aSignatureManager.getGpgSecurityContext()); } - std::unique_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), nullptr, std::move(xSecContexts), eAction); + std::shared_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), nullptr, std::move(xSecContexts), eAction); if (aChooser->run() != RET_OK) return { Reference< css::security::XCertificate >(nullptr) }; diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx index de106c408ac8..19e08399bd66 100644 --- a/xmlsecurity/source/dialogs/certificatechooser.cxx +++ b/xmlsecurity/source/dialogs/certificatechooser.cxx @@ -80,13 +80,19 @@ CertificateChooser::CertificateChooser(weld::Window* _pParent, // disable buttons CertificateHighlightHdl(*m_xCertLB); + + if (comphelper::LibreOfficeKit::isActive()) + { + m_xSearchBox->hide(); + m_xReloadBtn->hide(); + } } CertificateChooser::~CertificateChooser() { } -short CertificateChooser::run() +void CertificateChooser::BeforeRun() { // #i48432# // We can't check for personal certificates before raising this dialog, @@ -103,6 +109,11 @@ short CertificateChooser::run() m_xDialog->show(); ImplInitialize(); +} + +short CertificateChooser::run() +{ + BeforeRun(); return GenericDialogController::run(); } @@ -398,8 +409,8 @@ void CertificateChooser::ImplShowCertificateDetails() if (!userData->xSecurityEnvironment.is() || !userData->xCertificate.is()) return; - CertificateViewer aViewer(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this); - aViewer.run(); + auto xViewer = std::make_shared<CertificateViewer>(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this); + weld::DialogController::runAsync(xViewer, [] (int) {}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index e3f0a42f8881..fcfdfd04c0d5 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -530,27 +530,32 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) { if( ! canAdd()) return; - try + std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> xSecContexts { - std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> xSecContexts + maSignatureManager.getSecurityContext() + }; + // Gpg signing is only possible with ODF >= 1.2 documents + if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.getStore(), m_sODFVersion)) + xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); + + std::shared_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, std::move(xSecContexts), UserAction::Sign); + aChooser->BeforeRun(); + weld::DialogController::runAsync(aChooser, [this, aChooser](sal_Int32 nRet) { + if (nRet != RET_OK) { - maSignatureManager.getSecurityContext() - }; - // Gpg signing is only possible with ODF >= 1.2 documents - if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.getStore(), m_sODFVersion)) - xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); - - std::unique_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, std::move(xSecContexts), UserAction::Sign); - if (aChooser->run() == RET_OK) + return; + } + + try { sal_Int32 nSecurityId; if (moScriptSignatureManager) { if (!moScriptSignatureManager->add(aChooser->GetSelectedCertificates()[0], - aChooser->GetSelectedSecurityContext(), - aChooser->GetDescription(), nSecurityId, - m_bAdESCompliant)) + aChooser->GetSelectedSecurityContext(), + aChooser->GetDescription(), nSecurityId, + m_bAdESCompliant)) { return; } @@ -562,7 +567,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) } if (!maSignatureManager.add(aChooser->GetSelectedCertificates()[0], aChooser->GetSelectedSecurityContext(), - aChooser->GetDescription(), nSecurityId, m_bAdESCompliant)) + aChooser->GetDescription(), nSecurityId, m_bAdESCompliant)) return; mbSignaturesChanged = true; @@ -585,18 +590,18 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) ImplFillSignaturesBox(); } } - } - catch ( uno::Exception& ) - { - TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" ); - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Error, VclButtonsType::Ok, - XsResId(STR_XMLSECDLG_SIGNING_FAILED))); - xBox->run(); - // Don't keep invalid entries... - ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); - ImplFillSignaturesBox(); - } + catch ( uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" ); + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), + VclMessageType::Error, VclButtonsType::Ok, + XsResId(STR_XMLSECDLG_SIGNING_FAILED))); + xBox->run(); + // Don't keep invalid entries... + ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); + ImplFillSignaturesBox(); + } + }); } IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void)