tdf#158321 No error message when file doesn't exist

Revert "reduce allocations in InterceptedInteraction"

This reverts commit e3c961e6a3917d95534652e0f982918cc1079015.

Change-Id: I26ba0acaa088dff1800ccd69513056f821bd4d7f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159762
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/comphelper/source/misc/simplefileaccessinteraction.cxx b/comphelper/source/misc/simplefileaccessinteraction.cxx
index 15029a1..8cd77af 100644
--- a/comphelper/source/misc/simplefileaccessinteraction.cxx
+++ b/comphelper/source/misc/simplefileaccessinteraction.cxx
@@ -29,9 +29,10 @@ const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
/// Will handle com::sun::star::ucb::AuthenticationRequest
const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4;

static std::span<const ::ucbhelper::InterceptedInteraction::InterceptedRequest> getInterceptions()
SimpleFileAccessInteraction::SimpleFileAccessInteraction(
    const css::uno::Reference<css::task::XInteractionHandler>& xHandler)
{
    static const ::ucbhelper::InterceptedInteraction::InterceptedRequest lInterceptions[]{
    std::vector<::ucbhelper::InterceptedInteraction::InterceptedRequest> lInterceptions{
        { //intercept standard IO error exception (local file and WebDAV)
          css::uno::Any(css::ucb::InteractiveIOException()),
          cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_INTERACTIVEIOEXCEPTION },
@@ -51,14 +52,9 @@ static std::span<const ::ucbhelper::InterceptedInteraction::InterceptedRequest> 
          css::uno::Any(css::ucb::AuthenticationRequest()),
          cppu::UnoType<css::task::XInteractionApprove>::get(), HANDLE_AUTHENTICATIONREQUEST }
    };
    return lInterceptions;
}

SimpleFileAccessInteraction::SimpleFileAccessInteraction(
    const css::uno::Reference<css::task::XInteractionHandler>& xHandler)
    : InterceptedInteraction(getInterceptions())
{
    setInterceptedHandler(xHandler);
    setInterceptions(std::move(lInterceptions));
}

SimpleFileAccessInteraction::~SimpleFileAccessInteraction() {}
diff --git a/comphelper/source/misc/stillreadwriteinteraction.cxx b/comphelper/source/misc/stillreadwriteinteraction.cxx
index 191b751..88bc25b 100644
--- a/comphelper/source/misc/stillreadwriteinteraction.cxx
+++ b/comphelper/source/misc/stillreadwriteinteraction.cxx
@@ -34,42 +34,43 @@

namespace comphelper{

const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION       = 0;
const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
const sal_Int32 HANDLE_AUTHENTICATIONREQUESTEXCEPTION = 2;
const sal_Int32 HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION = 3;

static std::span<const ::ucbhelper::InterceptedInteraction::InterceptedRequest> getInterceptions()
{
    static const ::ucbhelper::InterceptedInteraction::InterceptedRequest lInterceptions[] {
        {
          css::uno::Any(css::ucb::InteractiveIOException()),
          cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_INTERACTIVEIOEXCEPTION
        },
        {
          css::uno::Any(css::ucb::UnsupportedDataSinkException()),
          cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_UNSUPPORTEDDATASINKEXCEPTION
        },
        {
          css::uno::Any(css::ucb::AuthenticationRequest()),
          cppu::UnoType<css::task::XInteractionApprove>::get(), HANDLE_AUTHENTICATIONREQUESTEXCEPTION
        },
        {
          css::uno::Any(css::ucb::CertificateValidationRequest()),
          cppu::UnoType<css::task::XInteractionApprove>::get(), HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION
        },
    };
    return lInterceptions;
}

StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
                                                     css::uno::Reference< css::task::XInteractionHandler > xAuxiliaryHandler)
             : InterceptedInteraction(getInterceptions())
             , m_bUsed                    (false)
             : m_bUsed                    (false)
             , m_bHandledByMySelf         (false)
             , m_xAuxiliaryHandler(std::move(xAuxiliaryHandler))
{
    std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
    lInterceptions.reserve(4);
    ::ucbhelper::InterceptedInteraction::InterceptedRequest                  aInterceptedRequest;

    aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
    aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
    lInterceptions.push_back(aInterceptedRequest);

    aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
    aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
    lInterceptions.push_back(aInterceptedRequest);

    aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
    aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
    lInterceptions.push_back(aInterceptedRequest);

    aInterceptedRequest.Handle = HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION;
    aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
    aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
    lInterceptions.push_back(aInterceptedRequest);

    setInterceptedHandler(xHandler);
    setInterceptions(std::move(lInterceptions));
}

void StillReadWriteInteraction::resetInterceptions()
{
    setInterceptions(std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
}

void StillReadWriteInteraction::resetErrorStates()
diff --git a/include/comphelper/stillreadwriteinteraction.hxx b/include/comphelper/stillreadwriteinteraction.hxx
index 6347e03..fb03a7a 100644
--- a/include/comphelper/stillreadwriteinteraction.hxx
+++ b/include/comphelper/stillreadwriteinteraction.hxx
@@ -33,6 +33,11 @@ namespace comphelper{
class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) StillReadWriteInteraction final : public ::ucbhelper::InterceptedInteraction
{
private:
    static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION       = 0;
    static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
    static const sal_Int32 HANDLE_AUTHENTICATIONREQUESTEXCEPTION = 2;
    static const sal_Int32 HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION = 3;

    bool m_bUsed;
    bool m_bHandledByMySelf;

@@ -40,6 +45,7 @@ public:
    StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
                              css::uno::Reference< css::task::XInteractionHandler > xAuxiliaryHandler);

    void resetInterceptions();
    void resetErrorStates();
    bool wasWriteError() const { return (m_bUsed && m_bHandledByMySelf);}

diff --git a/include/ucbhelper/interceptedinteraction.hxx b/include/ucbhelper/interceptedinteraction.hxx
index b7ac770..738c0f2 100644
--- a/include/ucbhelper/interceptedinteraction.hxx
+++ b/include/ucbhelper/interceptedinteraction.hxx
@@ -78,6 +78,16 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public InterceptedInteraction
            sal_Int32 Handle;


            /** @short  default ctor.

                @descr  Such constructed object can't be used really.
                        Might it will crash if it's used!
                        Don't forget to initialize all(!) members...
             */
            InterceptedRequest()
            {
                Handle     = INVALID_HANDLE;
            }
            InterceptedRequest(css::uno::Any Request_, css::uno::Type Continuation_, sal_Int32 Handle_)
                : Request(std::move(Request_)), Continuation(std::move(Continuation_)), Handle(Handle_)
            {
@@ -120,22 +130,16 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public InterceptedInteraction

        /** @short  these list contains the requests, which should be intercepted.
         */
        std::span< const InterceptedRequest > m_lInterceptions;
        ::std::vector< InterceptedRequest > m_lInterceptions;


    // native interface
    public:

        /** @short  initialise with a list of intercepted interactions.

            @attention  If the interface method handle() will be overwritten by
                        a derived class, the functionality behind these static list
                        can't be used.

            @param  lInterceptions
                    the list of intercepted requests.
        /** @short  initialize a new instance with default values.
         */
        InterceptedInteraction(std::span< const InterceptedRequest > m_lInterceptions);
        InterceptedInteraction();


        /** @short  initialize a new instance with the interaction handler,
@@ -152,6 +156,18 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public InterceptedInteraction
        void setInterceptedHandler(const css::uno::Reference< css::task::XInteractionHandler >& xInterceptedHandler);


        /** @short  set a new list of intercepted interactions.

            @attention  If the interface method handle() will be overwritten by
                        a derived class, the functionality behind these static list
                        can't be used.

            @param  lInterceptions
                    the list of intercepted requests.
         */
        void setInterceptions(::std::vector< InterceptedRequest >&& lInterceptions);


        /** @short  extract a requested continuation from the list of available ones.

            @param  lContinuations
diff --git a/ucbhelper/source/client/interceptedinteraction.cxx b/ucbhelper/source/client/interceptedinteraction.cxx
index 15b1b31..96b3fd3 100644
--- a/ucbhelper/source/client/interceptedinteraction.cxx
+++ b/ucbhelper/source/client/interceptedinteraction.cxx
@@ -23,8 +23,7 @@

namespace ucbhelper{

InterceptedInteraction::InterceptedInteraction(std::span< const InterceptedRequest > lInterceptions)
    : m_lInterceptions(lInterceptions)
InterceptedInteraction::InterceptedInteraction()
{
}

@@ -33,6 +32,11 @@ void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< cs
    m_xInterceptedHandler = xInterceptedHandler;
}

void InterceptedInteraction::setInterceptions(::std::vector< InterceptedRequest >&& lInterceptions)
{
    m_lInterceptions = std::move(lInterceptions);
}

InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
    const InterceptedRequest&,
    const css::uno::Reference< css::task::XInteractionRequest >&)
diff --git a/unotools/source/misc/mediadescriptor.cxx b/unotools/source/misc/mediadescriptor.cxx
index d4567c4..b8bb7f1 100644
--- a/unotools/source/misc/mediadescriptor.cxx
+++ b/unotools/source/misc/mediadescriptor.cxx
@@ -459,6 +459,7 @@ bool MediaDescriptor::impl_openStreamWithURL( const OUString& sURL, bool bLockFi
        if ( bReadOnly )
               (*this)[MediaDescriptor::PROP_READONLY] <<= bReadOnly;

        xInteraction->resetInterceptions();
        xInteraction->resetErrorStates();
        try
        {