android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / misc / stillreadwriteinteraction.cxx
blob88bc25bc46cb792ba49c45f1f7e0ef9486fbd780
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/stillreadwriteinteraction.hxx>
22 #include <com/sun/star/ucb/InteractiveIOException.hpp>
24 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionApprove.hpp>
28 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
30 #include <com/sun/star/ucb/AuthenticationRequest.hpp>
32 #include <com/sun/star/ucb/CertificateValidationRequest.hpp>
33 #include <utility>
35 namespace comphelper{
37 StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
38 css::uno::Reference< css::task::XInteractionHandler > xAuxiliaryHandler)
39 : m_bUsed (false)
40 , m_bHandledByMySelf (false)
41 , m_xAuxiliaryHandler(std::move(xAuxiliaryHandler))
43 std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
44 lInterceptions.reserve(4);
45 ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
47 aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
48 aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
49 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
50 lInterceptions.push_back(aInterceptedRequest);
52 aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
53 aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
54 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
55 lInterceptions.push_back(aInterceptedRequest);
57 aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
58 aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
59 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
60 lInterceptions.push_back(aInterceptedRequest);
62 aInterceptedRequest.Handle = HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION;
63 aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
64 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
65 lInterceptions.push_back(aInterceptedRequest);
67 setInterceptedHandler(xHandler);
68 setInterceptions(std::move(lInterceptions));
71 void StillReadWriteInteraction::resetInterceptions()
73 setInterceptions(std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
76 void StillReadWriteInteraction::resetErrorStates()
78 m_bUsed = false;
79 m_bHandledByMySelf = false;
83 ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
84 const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
86 // we are used!
87 m_bUsed = true;
89 // check if it's a real interception - might some parameters are not the right ones ...
90 bool bAbort = false;
91 switch(aRequest.Handle)
93 case HANDLE_INTERACTIVEIOEXCEPTION:
95 css::ucb::InteractiveIOException exIO;
96 xRequest->getRequest() >>= exIO;
97 bAbort = (
98 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
99 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
100 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
101 // At least on Linux, a request to open some fuse-mounted file O_RDWR may fail with
102 // EOPNOTSUPP (mapped to osl_File_E_NOSYS to IOErrorCode_NOT_SUPPORTED) when opening
103 // it O_RDONLY would succeed:
104 || (exIO.Code == css::ucb::IOErrorCode_NOT_SUPPORTED )
105 #ifdef MACOSX
106 // this is a workaround for MAC, on this platform if the file is locked
107 // the returned error code looks to be wrong
108 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
109 #endif
112 break;
114 case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
116 bAbort = true;
118 break;
119 case HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION:
120 case HANDLE_AUTHENTICATIONREQUESTEXCEPTION:
122 //use internal auxiliary handler and return
123 if (m_xAuxiliaryHandler.is())
125 m_xAuxiliaryHandler->handle(xRequest);
126 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
128 else //simply abort
129 bAbort = true;
131 break;
134 // handle interaction by ourself
135 if (bAbort)
137 m_bHandledByMySelf = true;
138 css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
139 xRequest->getContinuations(),
140 cppu::UnoType<css::task::XInteractionAbort>::get() );
141 if (!xAbort.is())
142 return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
143 xAbort->select();
144 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
147 // Otherwise use internal handler.
148 if (m_xInterceptedHandler.is())
150 m_xInterceptedHandler->handle(xRequest);
152 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */