/src/libreoffice/comphelper/source/misc/simplefileaccessinteraction.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | */ |
9 | | |
10 | | #include <comphelper/simplefileaccessinteraction.hxx> |
11 | | #include <com/sun/star/task/XInteractionAbort.hpp> |
12 | | #include <com/sun/star/task/XInteractionApprove.hpp> |
13 | | #include <com/sun/star/ucb/AuthenticationRequest.hpp> |
14 | | #include <com/sun/star/ucb/CertificateValidationRequest.hpp> |
15 | | #include <com/sun/star/ucb/InteractiveIOException.hpp> |
16 | | #include <com/sun/star/ucb/InteractiveNetworkException.hpp> |
17 | | #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> |
18 | | |
19 | | namespace comphelper |
20 | | { |
21 | | /// Will handle com::sun::star::ucb::InteractiveIOException and derived classes |
22 | | const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0; |
23 | | /// Will handle com::sun::star::ucb::UnsupportedDataSinkException |
24 | | const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1; |
25 | | /// Will handle com::sun::star::ucb::InteractiveNetworkException |
26 | | const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION = 2; |
27 | | /// Will handle com::sun::star::ucb::CertificateValidationRequest |
28 | | const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3; |
29 | | /// Will handle com::sun::star::ucb::AuthenticationRequest |
30 | | const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4; |
31 | | |
32 | | SimpleFileAccessInteraction::SimpleFileAccessInteraction( |
33 | | const css::uno::Reference<css::task::XInteractionHandler>& xHandler) |
34 | 211k | { |
35 | 211k | std::vector<::ucbhelper::InterceptedInteraction::InterceptedRequest> lInterceptions{ |
36 | 211k | { //intercept standard IO error exception (local file and WebDAV) |
37 | 211k | css::uno::Any(css::ucb::InteractiveIOException()), |
38 | 211k | cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_INTERACTIVEIOEXCEPTION }, |
39 | 211k | { //intercept internal error |
40 | 211k | css::uno::Any(css::ucb::UnsupportedDataSinkException()), |
41 | 211k | cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_UNSUPPORTEDDATASINKEXCEPTION }, |
42 | 211k | { |
43 | | //intercept network error exception (WebDAV ucp provider) |
44 | 211k | css::uno::Any(css::ucb::InteractiveNetworkException()), |
45 | 211k | cppu::UnoType<css::task::XInteractionAbort>::get(), |
46 | 211k | HANDLE_INTERACTIVENETWORKEXCEPTION, |
47 | 211k | }, |
48 | 211k | { //intercept certificate validation request (WebDAV ucp provider) |
49 | 211k | css::uno::Any(css::ucb::CertificateValidationRequest()), |
50 | 211k | cppu::UnoType<css::task::XInteractionAbort>::get(), HANDLE_CERTIFICATEREQUEST }, |
51 | 211k | { //intercept authentication request (WebDAV ucp provider) |
52 | 211k | css::uno::Any(css::ucb::AuthenticationRequest()), |
53 | 211k | cppu::UnoType<css::task::XInteractionApprove>::get(), HANDLE_AUTHENTICATIONREQUEST } |
54 | 211k | }; |
55 | | |
56 | 211k | setInterceptedHandler(xHandler); |
57 | 211k | setInterceptions(std::move(lInterceptions)); |
58 | 211k | } |
59 | | |
60 | 211k | SimpleFileAccessInteraction::~SimpleFileAccessInteraction() {} |
61 | | |
62 | | ucbhelper::InterceptedInteraction::EInterceptionState SimpleFileAccessInteraction::intercepted( |
63 | | const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest, |
64 | | const css::uno::Reference<css::task::XInteractionRequest>& xRequest) |
65 | 0 | { |
66 | 0 | bool bAbort = false; |
67 | 0 | switch (aRequest.Handle) |
68 | 0 | { |
69 | 0 | case HANDLE_UNSUPPORTEDDATASINKEXCEPTION: |
70 | 0 | case HANDLE_INTERACTIVENETWORKEXCEPTION: |
71 | 0 | case HANDLE_INTERACTIVEIOEXCEPTION: |
72 | 0 | { |
73 | 0 | bAbort = true; |
74 | 0 | } |
75 | 0 | break; |
76 | | |
77 | 0 | case HANDLE_CERTIFICATEREQUEST: |
78 | 0 | { |
79 | | // use default internal handler. |
80 | 0 | if (m_xInterceptedHandler.is()) |
81 | 0 | { |
82 | 0 | m_xInterceptedHandler->handle(xRequest); |
83 | 0 | return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; |
84 | 0 | } |
85 | 0 | else |
86 | 0 | bAbort = true; |
87 | 0 | break; |
88 | 0 | } |
89 | | |
90 | 0 | case HANDLE_AUTHENTICATIONREQUEST: |
91 | 0 | { |
92 | | // use default internal handler. |
93 | 0 | if (m_xInterceptedHandler.is()) |
94 | 0 | { |
95 | 0 | m_xInterceptedHandler->handle(xRequest); |
96 | 0 | return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; |
97 | 0 | } |
98 | 0 | else //simply abort |
99 | 0 | bAbort = true; |
100 | 0 | } |
101 | 0 | break; |
102 | 0 | } |
103 | | |
104 | | // handle interaction by ourself, by not doing |
105 | | // any selection... |
106 | 0 | if (bAbort) |
107 | 0 | { |
108 | 0 | css::uno::Reference<css::task::XInteractionContinuation> xAbort |
109 | 0 | = ::ucbhelper::InterceptedInteraction::extractContinuation( |
110 | 0 | xRequest->getContinuations(), cppu::UnoType<css::task::XInteractionAbort>::get()); |
111 | 0 | if (!xAbort.is()) |
112 | 0 | return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND; |
113 | 0 | return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; |
114 | 0 | } |
115 | | |
116 | 0 | return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; |
117 | 0 | } |
118 | | } |
119 | | |
120 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |