summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sfx2/digitalsignatures.hxx3
-rw-r--r--include/sfx2/docfile.hxx2
-rw-r--r--sfx2/source/doc/docfile.cxx7
-rw-r--r--sfx2/source/doc/objserv.cxx14
-rw-r--r--xmlsecurity/inc/digitalsignaturesdialog.hxx4
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx13
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx10
7 files changed, 38 insertions, 15 deletions
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();
}