summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sfx2/objsh.hxx3
-rw-r--r--sfx2/source/doc/objserv.cxx50
-rw-r--r--sfx2/source/view/viewfrm.cxx32
3 files changed, 55 insertions, 30 deletions
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index b3627a6b8788..4c0ea7f22f09 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -761,6 +761,9 @@ public:
/// Is this read-only object shell opened via .uno:SignPDF?
bool IsSignPDF() const;
+
+ /// Gets the certificate that is already picked by the user but not yet used for signing.
+ css::uno::Reference<css::security::XCertificate> GetSignPDFCertificate() const;
};
#define SFX_GLOBAL_CLASSID \
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 96c23314a5cb..09e4bba8bde8 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -122,6 +122,7 @@
#include <cppuhelper/implbase.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/streamwrap.hxx>
+#include <comphelper/sequenceashashmap.hxx>
#include <svx/unoshape.hxx>
#include <svx/xlineit0.hxx>
@@ -423,6 +424,36 @@ bool SfxObjectShell::IsSignPDF() const
return false;
}
+uno::Reference<security::XCertificate> SfxObjectShell::GetSignPDFCertificate() const
+{
+ uno::Reference<frame::XModel> xModel = GetBaseModel();
+ if (!xModel.is())
+ {
+ return uno::Reference<security::XCertificate>();
+ }
+
+ uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY);
+ if (!xShapes.is() || xShapes->getCount() < 1)
+ {
+ return uno::Reference<security::XCertificate>();
+ }
+
+ uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY);
+ if (!xShapeProps.is())
+ {
+ return uno::Reference<security::XCertificate>();
+ }
+
+ comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag"));
+ auto it = aMap.find("SignatureCertificate");
+ if (it == aMap.end())
+ {
+ return uno::Reference<security::XCertificate>();
+ }
+
+ return uno::Reference<security::XCertificate>(it->second, uno::UNO_QUERY);
+}
+
void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
{
weld::Window* pDialogParent = rReq.GetFrameWeld();
@@ -440,7 +471,24 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId )
{
if ( QueryHiddenInformation( HiddenWarningFact::WhenSigning, nullptr ) == RET_YES )
- ( SID_SIGNATURE == nId ) ? SignDocumentContent(pDialogParent) : SignScriptingContent(pDialogParent);
+ {
+ if (SID_SIGNATURE == nId)
+ {
+ uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate();
+ if (xCertificate.is())
+ {
+ SignDocumentContentUsingCertificate(xCertificate);
+ }
+ else
+ {
+ SignDocumentContent(pDialogParent);
+ }
+ }
+ else
+ {
+ SignScriptingContent(pDialogParent);
+ }
+ }
return;
}
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 8d0d94a6181d..75ec246b4fb6 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1238,41 +1238,15 @@ const SvBorder& SfxViewFrame::GetBorderPixelImpl() const
return m_pImpl->aBorder;
}
-namespace
-{
-/// Does the current selection have a shape with an associated signing certificate?
-bool IsSignWithCert(SfxViewShell* pViewShell)
-{
- uno::Reference<frame::XModel> xModel = pViewShell->GetCurrentDocument();
- if (!xModel.is())
- {
- return false;
- }
-
- uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY);
- if (!xShapes.is() || xShapes->getCount() < 1)
- {
- return false;
- }
-
- uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY);
- if (!xShapeProps.is())
- {
- return false;
- }
-
- comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag"));
- return aMap.find("SignatureCertificate") != aMap.end();
-}
-}
-
void SfxViewFrame::AppendReadOnlyInfobar()
{
bool bSignPDF = m_xObjSh->IsSignPDF();
bool bSignWithCert = false;
if (bSignPDF)
{
- bSignWithCert = IsSignWithCert(GetViewShell());
+ SfxObjectShell* pObjectShell = GetObjectShell();
+ uno::Reference<security::XCertificate> xCertificate = pObjectShell->GetSignPDFCertificate();
+ bSignWithCert = xCertificate.is();
}
auto pInfoBar = AppendInfoBar("readonly", "",