[Libreoffice-commits] core.git: 2 commits - comphelper/Library_comphelper.mk comphelper/source cui/source include/comphelper ucb/source

Giuseppe Castagno giuseppe.castagno at acca-esse.eu
Fri Apr 22 07:11:54 UTC 2016


 comphelper/Library_comphelper.mk                       |    1 
 comphelper/source/misc/simplefileaccessinteraction.cxx |  140 +++++++++++++++++
 cui/source/options/personalization.cxx                 |   18 ++
 include/comphelper/simplefileaccessinteraction.hxx     |   50 ++++++
 ucb/source/ucp/webdav-neon/webdavcontent.cxx           |   24 --
 5 files changed, 210 insertions(+), 23 deletions(-)

New commits:
commit 37d34e2b6a96569313178ce864096722230cb3b9
Author: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
Date:   Tue Apr 19 08:17:48 2016 +0200

    Related tdf#88502 a better implementation than the one in...
    
    ...commit 70bb8c257e7fc402da60fa70109cece1fe4c69d1.
    
    This commit reverts previous implementation in commit
    70bb8c257e7fc402da60fa70109cece1fe4c69d1 and makes use of a dedicated
    interaction wrapper instead.
    
    See comphelper::SimpleFileAccessInteraction for details.
    
    Change-Id: Ia037ea14267afaf66d8f9aa2324649264a7cb4bf
    Reviewed-on: https://gerrit.libreoffice.org/24275
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index 57298ae..799da44 100644
--- a/cui/source/options/personalization.cxx
+++ b/cui/source/options/personalization.cxx
@@ -29,10 +29,12 @@
 #include <dialmgr.hxx>
 #include "cuires.hrc"
 
+#include <com/sun/star/task/InteractionHandler.hpp>
 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
 #include <com/sun/star/xml/sax/XParser.hpp>
 #include <com/sun/star/xml/sax/Parser.hpp>
 #include "ucbhelper/content.hxx"
+#include <comphelper/simplefileaccessinteraction.hxx>
 
 using namespace com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -579,10 +581,26 @@ void SearchAndParseThread::execute()
             return;
 
         try {
+            css:: uno::Reference< task::XInteractionHandler > xIH(
+                css::task::InteractionHandler::createWithParent( xContext, nullptr ) );
+
+            xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) );
+
             xStream = xFileAccess->openFileRead( m_aURL );
+            if( !xStream.is() )
+            {
+                // in case of a returned CommandFailedException
+                // SimpleFileAccess serves it, returning an empty stream
+                sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR);
+                sProgress = sProgress.replaceAll("%1", m_aURL);
+                m_pPersonaDialog->SetProgress(sProgress);
+                return;
+            }
         }
         catch (...)
         {
+            // a catch all clause, in case the exception is not
+            // served elsewhere
             sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR);
             sProgress = sProgress.replaceAll("%1", m_aURL);
             m_pPersonaDialog->SetProgress(sProgress);
diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
index 625e2fe..e3c1dec 100644
--- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
@@ -51,7 +51,6 @@
 #include <com/sun/star/io/XOutputStream.hpp>
 #include <com/sun/star/lang/IllegalAccessException.hpp>
 #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp>
-#include <com/sun/star/task/InteractionHandler.hpp>
 #include <com/sun/star/ucb/CommandEnvironment.hpp>
 #include <com/sun/star/ucb/CommandFailedException.hpp>
 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
@@ -3436,27 +3435,6 @@ Content::ResourceType Content::getResourceType(
     }
     else
     {
-        // In case xEnv is present, uses the interaction handler provided
-        // in xEnv.
-        // In case xEnv is not present, supply a command env to PROPFIND()
-        // that contains an interaction handler in order to activate the
-        // credential dialog if the server request them.
-        // The command env is needed by lower level function for examples as
-        // NeonSession_CertificationNotify where it is used to check the server
-        // certificate or ask the user for a manual confirmation if the certificate
-        // needs the user visual check.
-        // xEnv is still used in cancelCommandExecution(), so the cancelling operates
-        // as the client application (e.g. framework) requested.
-        css::uno::Reference< css::ucb::XCommandEnvironment > xAuthEnv( xEnv );
-        if( !xAuthEnv.is() )
-        {
-            css:: uno::Reference< task::XInteractionHandler > xIH(
-                css::task::InteractionHandler::createWithParent( m_xContext, nullptr ), css::uno::UNO_QUERY_THROW );
-
-            xAuthEnv = css::ucb::CommandEnvironment::create(
-                m_xContext, xIH, css::uno::Reference< ucb::XProgressHandler >() ) ;
-        }
-
         try
         {
             // Try to fetch some frequently used property value, e.g. those
@@ -3473,7 +3451,7 @@ Content::ResourceType Content::getResourceType(
 
             ContentProperties::UCBNamesToDAVNames( aProperties, aPropNames );
 
-            rResAccess->PROPFIND( DAVZERO, aPropNames, resources, xAuthEnv );
+            rResAccess->PROPFIND( DAVZERO, aPropNames, resources, xEnv );
 
             if ( resources.size() == 1 )
             {
commit bbe51f039dffca2506ea542feb78571b6358b981
Author: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
Date:   Tue Apr 19 08:23:23 2016 +0200

    Add an interaction handler wrapper for simple file access.
    
    This wrapper is to be used when you want to avoid the error
    messages displayed when accessing a file (the messages activated
    by ucphelper::cancelCommandExecution), especially when accessing a
    Web/DAV connection to enable https certificate validation and
    optionally enabling the authentication dialog that may be needed
    in these operations.
    
    Change-Id: I19f3072b91b6c4f453a54b56a3d9883b3383dfa5
    Reviewed-on: https://gerrit.libreoffice.org/24274
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index 7047d8a..4d4e734 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -111,6 +111,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
     comphelper/source/misc/servicedecl \
     comphelper/source/misc/serviceinfohelper \
     comphelper/source/misc/sharedmutex \
+    comphelper/source/misc/simplefileaccessinteraction \
     comphelper/source/misc/solarmutex \
     comphelper/source/misc/stillreadwriteinteraction \
     comphelper/source/misc/anycompare \
diff --git a/comphelper/source/misc/simplefileaccessinteraction.cxx b/comphelper/source/misc/simplefileaccessinteraction.cxx
new file mode 100644
index 0000000..c513d49
--- /dev/null
+++ b/comphelper/source/misc/simplefileaccessinteraction.cxx
@@ -0,0 +1,140 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <comphelper/simplefileaccessinteraction.hxx>
+#include <com/sun/star/task/XInteractionAbort.hpp>
+#include <com/sun/star/task/XInteractionApprove.hpp>
+#include <com/sun/star/ucb/AuthenticationRequest.hpp>
+#include <com/sun/star/ucb/CertificateValidationRequest.hpp>
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#include <com/sun/star/ucb/InteractiveNetworkException.hpp>
+#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
+
+namespace comphelper {
+
+/// Will handle com::sun::star::ucb::InteractiveIOException and derived classes
+static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0;
+/// Will handle com::sun::star::ucb::UnsupportedDataSinkException
+static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
+/// Will handle com::sun::star::ucb::InteractiveNetworkException
+static const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION = 2;
+/// Will handle com::sun::star::ucb::CertificateValidationRequest
+static const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
+/// Will handle com::sun::star::ucb::AuthenticationRequest
+static const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4;
+
+SimpleFileAccessInteraction::SimpleFileAccessInteraction(
+    const css::uno::Reference< css::task::XInteractionHandler >& xHandler )
+{
+    ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
+    ::ucbhelper::InterceptedInteraction::InterceptedRequest                  aInterceptedRequest;
+
+    //intercept standard IO error exception (local file and WebDAV)
+    aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
+    aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
+    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+    aInterceptedRequest.MatchExact = false;
+    lInterceptions.push_back(aInterceptedRequest);
+
+    //intercept internal error
+    aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
+    aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
+    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+    aInterceptedRequest.MatchExact = false;
+    lInterceptions.push_back(aInterceptedRequest);
+
+    //intercept network error exception (WebDAV ucp provider)
+    aInterceptedRequest.Handle = HANDLE_INTERACTIVENETWORKEXCEPTION;
+    aInterceptedRequest.Request <<= css::ucb::InteractiveNetworkException();
+    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+    aInterceptedRequest.MatchExact = false;
+    lInterceptions.push_back(aInterceptedRequest);
+
+    //intercept certificate validation request (WebDAV ucp provider)
+    aInterceptedRequest.Handle = HANDLE_CERTIFICATEREQUEST;
+    aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
+    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+    aInterceptedRequest.MatchExact = false;
+    lInterceptions.push_back(aInterceptedRequest);
+
+    //intercept authentication request (WebDAV ucp provider)
+    aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUEST;
+    aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
+    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
+    aInterceptedRequest.MatchExact = false;
+    lInterceptions.push_back(aInterceptedRequest);
+
+    setInterceptedHandler(xHandler);
+    setInterceptions(lInterceptions);
+}
+
+SimpleFileAccessInteraction::~SimpleFileAccessInteraction()
+{
+}
+
+ucbhelper::InterceptedInteraction::EInterceptionState SimpleFileAccessInteraction::intercepted(
+    const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
+    const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
+{
+    bool bAbort = false;
+    switch(aRequest.Handle)
+    {
+        case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
+        case HANDLE_INTERACTIVENETWORKEXCEPTION:
+        case HANDLE_INTERACTIVEIOEXCEPTION:
+        {
+            bAbort = true;
+        }
+        break;
+
+        case HANDLE_CERTIFICATEREQUEST:
+        {
+            // use default internal handler.
+            if (m_xInterceptedHandler.is())
+            {
+                m_xInterceptedHandler->handle(xRequest);
+                return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
+            }
+            else
+                bAbort = true;
+            break;
+        }
+
+        case HANDLE_AUTHENTICATIONREQUEST:
+        {
+            // use default internal handler.
+            if (m_xInterceptedHandler.is())
+            {
+                m_xInterceptedHandler->handle(xRequest);
+                return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
+            }
+            else //simply abort
+                bAbort = true;
+        }
+        break;
+    }
+
+    // handle interaction by ourself, by not doing
+    // any selection...
+    if (bAbort)
+    {
+        css::uno::Reference< css::task::XInteractionContinuation > xAbort =
+            ::ucbhelper::InterceptedInteraction::extractContinuation(
+                xRequest->getContinuations(),
+                cppu::UnoType<css::task::XInteractionAbort>::get() );
+        if (!xAbort.is())
+            return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
+        return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
+    }
+
+    return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/simplefileaccessinteraction.hxx b/include/comphelper/simplefileaccessinteraction.hxx
new file mode 100644
index 0000000..fd05bb7
--- /dev/null
+++ b/include/comphelper/simplefileaccessinteraction.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_COMPHELPER_SIMPLEFILEACCESSINTERACTION_HXX
+#define INCLUDED_COMPHELPER_SIMPLEFILEACCESSINTERACTION_HXX
+
+#include <sal/config.h>
+#include <ucbhelper/interceptedinteraction.hxx>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <comphelper/comphelperdllapi.h>
+
+namespace comphelper {
+/** An interaction handler wrapper for simple file access.
+
+    This wrapper is to be used together with XSimpleFileAccess when
+    you want to avoid the error messages displayed when accessing a file (the messages activated
+    by ucphelper::cancelCommandExecution).
+
+    This wrapper is especially useful when you need to access a Web/DAV connection
+    enabling https certificate validation and optionally enabling the authentication
+    dialog that may be needed in these operations.
+
+    @param xHandler
+    Used handler, always needed.
+    It will be used for Certificate Validation dialog or authentication dialog.
+    The authentication is used in Web/DAV access when the server requests credentials to be accessed.
+*/
+class COMPHELPER_DLLPUBLIC SimpleFileAccessInteraction : public ::ucbhelper::InterceptedInteraction
+{
+
+public:
+    SimpleFileAccessInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
+    virtual ~SimpleFileAccessInteraction();
+
+private:
+
+    virtual ucbhelper::InterceptedInteraction::EInterceptionState intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
+        const css::uno::Reference< css::task::XInteractionRequest >& xRequest) override;
+
+};
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list