[Libreoffice-commits] core.git: include/unotools sfx2/source unotools/source
Giuseppe Castagno
giuseppe.castagno at acca-esse.eu
Mon Oct 17 10:45:25 UTC 2016
include/unotools/ucbhelper.hxx | 30 ++++++++++++++++++++++++++++++
sfx2/source/doc/docfile.cxx | 7 +++++--
unotools/source/ucbhelper/ucbhelper.cxx | 18 ++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
New commits:
commit 26c99e42db233e375a007c49e1e903359caa1ce3
Author: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
Date: Sat Oct 15 16:21:42 2016 +0200
tdf#103274: Add helper for a default XCommandEnvironment reference.
This helper should be used where the empty XCommandEnvironment
e.g. something like:
css::uno::Reference< css::ucb::XCommandEnvironment >()
is currently used.
See comment in the committed code (include/unotools/ucbhelper.hxx)
for details.
A case use is presented in this commit, please see:
sfx2/source/doc/docfile.cxx for details.
Change-Id: Ieb97c0ed61f31ef8df532c8be0e7ff1035327915
Reviewed-on: https://gerrit.libreoffice.org/29927
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
diff --git a/include/unotools/ucbhelper.hxx b/include/unotools/ucbhelper.hxx
index 1777a40..653d828 100644
--- a/include/unotools/ucbhelper.hxx
+++ b/include/unotools/ucbhelper.hxx
@@ -80,6 +80,36 @@ UNOTOOLS_DLLPUBLIC bool IsSubPath(
UNOTOOLS_DLLPUBLIC bool EqualURLs(
OUString const & url1, OUString const & url2);
+/**
+* Returns a default XCommandEnvironment to be used
+* when creating a ucbhelper::Content.
+*
+* Due to the way the WebDAV UCP provider works, an interaction handler
+* is always needed:
+* 1) to activate the credential dialog or to provide the cached credentials
+* whenever the server requests them;
+*
+* 2) in case of ssl connection (https) to activate the dialog to show the
+* certificate if said certificate looks wrong or dubious.
+*
+* This helper provides the XCommandEnvironment with an interaction
+* handler that intercepts:
+* 1) css::ucb::AuthenticationRequest()
+* 2) css::ucb::CertificateValidationRequest()
+* 3) css::ucb::InteractiveIOException()
+* 4) css::ucb::UnsupportedDataSinkException()
+*
+* Exception 1) and 2) will be passed to the UI handler, e.g. shown to
+* the user for interaction.
+*
+* Exception 3) and 4) will be have a default 'Abort' result.
+* See comphelper::StillReadWriteInteraction for details.
+* comphelper::StillReadWriteInteraction was introduced in
+* commit bbe51f039dffca2506ea542feb78571b6358b981.
+*/
+UNOTOOLS_DLLPUBLIC
+ css::uno::Reference< css::ucb::XCommandEnvironment > getDefaultCommandEnvironment();
+
} }
#endif
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 2179f82..e41f716 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -394,8 +394,11 @@ util::DateTime SfxMedium::GetInitFileDate( bool bIgnoreOldValue )
{
try
{
- uno::Reference< css::ucb::XCommandEnvironment > xDummyEnv;
- ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
+ // add a default css::ucb::XCommandEnvironment
+ // in order to have the WebDAV UCP provider manage http/https authentication correctly
+ ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ),
+ utl::UCBContentHelper::getDefaultCommandEnvironment(),
+ comphelper::getProcessComponentContext() );
aContent.getPropertyValue("DateModified") >>= pImpl->m_aDateTime;
pImpl->m_bGotDateTime = true;
diff --git a/unotools/source/ucbhelper/ucbhelper.cxx b/unotools/source/ucbhelper/ucbhelper.cxx
index acbc63f..aa751b6 100644
--- a/unotools/source/ucbhelper/ucbhelper.cxx
+++ b/unotools/source/ucbhelper/ucbhelper.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/ucb/ContentInfo.hpp>
#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
@@ -46,6 +47,7 @@
#include <com/sun/star/util/DateTime.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/exc_hlp.hxx>
+#include <comphelper/simplefileaccessinteraction.hxx>
#include <osl/file.hxx>
#include <rtl/string.h>
#include <rtl/ustring.h>
@@ -120,6 +122,22 @@ DateTime convert(css::util::DateTime const & dt) {
}
+css::uno::Reference< css::ucb::XCommandEnvironment > utl::UCBContentHelper::getDefaultCommandEnvironment()
+{
+ css::uno::Reference< css::task::XInteractionHandler > xIH(
+ css::task::InteractionHandler::createWithParent(
+ comphelper::getProcessComponentContext(), nullptr ) );
+
+ css::uno::Reference< css::ucb::XProgressHandler > xProgress;
+ ucbhelper::CommandEnvironment* pCommandEnv =
+ new ::ucbhelper::CommandEnvironment(
+ new comphelper::SimpleFileAccessInteraction( xIH ), xProgress );
+
+ css::uno::Reference < css::ucb::XCommandEnvironment > xEnv(
+ static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY );
+ return xEnv;
+}
+
bool utl::UCBContentHelper::IsDocument(OUString const & url) {
try {
return content(url).isDocument();
More information about the Libreoffice-commits
mailing list