1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX
21 #define INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX
23 #include <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/task/XInteractionRequest.hpp>
25 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionRetry.hpp>
27 #include <com/sun/star/task/XInteractionApprove.hpp>
28 #include <com/sun/star/task/XInteractionDisapprove.hpp>
29 #include <com/sun/star/ucb/XInteractionAuthFallback.hpp>
30 #include <com/sun/star/ucb/XInteractionReplaceExistingData.hpp>
31 #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
32 #include <rtl/ref.hxx>
33 #include <cppuhelper/weak.hxx>
34 #include <ucbhelper/ucbhelperdllapi.h>
39 class InteractionContinuation
;
42 struct InteractionRequest_Impl
;
45 * This class implements the interface XInteractionRequest. Instances can
46 * be passed directly to XInteractionHandler::handle(...). Each interaction
47 * request contains an exception describing the error and a number of
48 * interaction continuations describing the possible "answers" for the request.
49 * After the request was passed to XInteractionHandler::handle(...) the method
50 * getSelection() returns the continuation chosen by the interaction handler.
52 * The typical usage of this class would be:
54 * 1) Create exception object that shall be handled by the interaction handler.
55 * 2) Create InteractionRequest, supply exception as ctor parameter
56 * 3) Create continuations needed and add them to a sequence
57 * 4) Supply the continuations to the InteractionRequest by calling
58 * setContinuations(...)
60 * This class can also be used as base class for more specialized requests,
61 * like authentication requests.
63 class UCBHELPER_DLLPUBLIC InteractionRequest
: public cppu::OWeakObject
,
64 public css::lang::XTypeProvider
,
65 public css::task::XInteractionRequest
67 std::unique_ptr
<InteractionRequest_Impl
> m_pImpl
;
70 void setRequest( const css::uno::Any
& rRequest
);
73 virtual ~InteractionRequest() override
;
79 * @param rRequest is the exception describing the error.
81 InteractionRequest( const css::uno::Any
& rRequest
);
84 * This method sets the continuations for the request.
86 * @param rContinuations contains the possible continuations.
88 void setContinuations(
89 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > & rContinuations
);
92 virtual css::uno::Any SAL_CALL
93 queryInterface( const css::uno::Type
& rType
)
94 throw( css::uno::RuntimeException
, std::exception
) override
;
95 virtual void SAL_CALL
acquire()
97 virtual void SAL_CALL
release()
101 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
103 throw( css::uno::RuntimeException
, std::exception
) override
;
104 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
105 getImplementationId()
106 throw( css::uno::RuntimeException
, std::exception
) override
;
108 // XInteractionRequest
109 virtual css::uno::Any SAL_CALL
111 throw( css::uno::RuntimeException
, std::exception
) override
;
112 virtual css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > SAL_CALL
114 throw( css::uno::RuntimeException
, std::exception
) override
;
116 // Non-interface methods.
119 * After passing this request to XInteractionHandler::handle, this method
120 * returns the continuation that was chosen by the interaction handler.
122 * @return the continuation chosen by an interaction handler or an empty
123 * reference, if the request was not (yet) handled.
125 rtl::Reference
< InteractionContinuation
> const & getSelection() const;
128 * This method sets a continuation for the request. It also can be used
129 * to reset the continuation set by a previous XInteractionHandler::handle
130 * call in order to use this request object more than once.
132 * @param rxSelection is the interaction continuation to activate for
133 * the request or an empty reference in order to reset the
138 const rtl::Reference
< InteractionContinuation
> & rxSelection
);
142 struct InteractionContinuation_Impl
;
145 * This class is the base for implementations of the interface
146 * XInteractionContinuation. Classes derived from this bas class work together
147 * with class InteractionRequest.
149 * Derived classes must implement their XInteractionContinuation::select()
150 * method the way that they simply call recordSelection() which is provided by
153 class UCBHELPER_DLLPUBLIC InteractionContinuation
: public cppu::OWeakObject
155 std::unique_ptr
<InteractionContinuation_Impl
> m_pImpl
;
159 * This method marks this continuation as "selected" at the request it
162 * Derived classes must implement their XInteractionContinuation::select()
163 * method the way that they call this method.
165 void recordSelection();
166 virtual ~InteractionContinuation() override
;
169 InteractionContinuation( InteractionRequest
* pRequest
);
174 * This class implements a standard interaction continuation, namely the
175 * interface XInteractionAbort. Instances of this class can be passed
176 * along with an interaction request to indicate the possibility to abort
177 * the operation that caused the request.
179 class UCBHELPER_DLLPUBLIC InteractionAbort
: public InteractionContinuation
,
180 public css::lang::XTypeProvider
,
181 public css::task::XInteractionAbort
184 InteractionAbort( InteractionRequest
* pRequest
)
185 : InteractionContinuation( pRequest
) {}
188 virtual css::uno::Any SAL_CALL
189 queryInterface( const css::uno::Type
& rType
)
190 throw( css::uno::RuntimeException
, std::exception
) override
;
191 virtual void SAL_CALL
acquire()
193 virtual void SAL_CALL
release()
197 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
199 throw( css::uno::RuntimeException
, std::exception
) override
;
200 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
201 getImplementationId()
202 throw( css::uno::RuntimeException
, std::exception
) override
;
204 // XInteractionContinuation
205 virtual void SAL_CALL
select()
206 throw( css::uno::RuntimeException
, std::exception
) override
;
211 * This class implements a standard interaction continuation, namely the
212 * interface XInteractionRetry. Instances of this class can be passed
213 * along with an interaction request to indicate the possibility to retry
214 * the operation that caused the request.
216 class UCBHELPER_DLLPUBLIC InteractionRetry
: public InteractionContinuation
,
217 public css::lang::XTypeProvider
,
218 public css::task::XInteractionRetry
221 InteractionRetry( InteractionRequest
* pRequest
)
222 : InteractionContinuation( pRequest
) {}
225 virtual css::uno::Any SAL_CALL
226 queryInterface( const css::uno::Type
& rType
)
227 throw( css::uno::RuntimeException
, std::exception
) override
;
228 virtual void SAL_CALL
acquire()
230 virtual void SAL_CALL
release()
234 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
236 throw( css::uno::RuntimeException
, std::exception
) override
;
237 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
238 getImplementationId()
239 throw( css::uno::RuntimeException
, std::exception
) override
;
241 // XInteractionContinuation
242 virtual void SAL_CALL
select()
243 throw( css::uno::RuntimeException
, std::exception
) override
;
248 * This class implements a standard interaction continuation, namely the
249 * interface XInteractionApprove. Instances of this class can be passed
250 * along with an interaction request to indicate the possibility to approve
253 class UCBHELPER_DLLPUBLIC InteractionApprove
: public InteractionContinuation
,
254 public css::lang::XTypeProvider
,
255 public css::task::XInteractionApprove
258 InteractionApprove( InteractionRequest
* pRequest
)
259 : InteractionContinuation( pRequest
) {}
262 virtual css::uno::Any SAL_CALL
263 queryInterface( const css::uno::Type
& rType
)
264 throw( css::uno::RuntimeException
, std::exception
) override
;
265 virtual void SAL_CALL
acquire()
267 virtual void SAL_CALL
release()
271 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
273 throw( css::uno::RuntimeException
, std::exception
) override
;
274 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
275 getImplementationId()
276 throw( css::uno::RuntimeException
, std::exception
) override
;
278 // XInteractionContinuation
279 virtual void SAL_CALL
select()
280 throw( css::uno::RuntimeException
, std::exception
) override
;
285 * This class implements a standard interaction continuation, namely the
286 * interface XInteractionDisapprove. Instances of this class can be passed
287 * along with an interaction request to indicate the possibility to disapprove
290 class UCBHELPER_DLLPUBLIC InteractionDisapprove
: public InteractionContinuation
,
291 public css::lang::XTypeProvider
,
292 public css::task::XInteractionDisapprove
295 InteractionDisapprove( InteractionRequest
* pRequest
)
296 : InteractionContinuation( pRequest
) {}
299 virtual css::uno::Any SAL_CALL
300 queryInterface( const css::uno::Type
& rType
)
301 throw( css::uno::RuntimeException
, std::exception
) override
;
302 virtual void SAL_CALL
acquire()
304 virtual void SAL_CALL
release()
308 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
310 throw( css::uno::RuntimeException
, std::exception
) override
;
311 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
312 getImplementationId()
313 throw( css::uno::RuntimeException
, std::exception
) override
;
315 // XInteractionContinuation
316 virtual void SAL_CALL
select()
317 throw( css::uno::RuntimeException
, std::exception
) override
;
322 * This class implements a standard interaction continuation, namely the
323 * interface XInteractionSupplyAuthentication. Instances of this class can be
324 * passed along with an authentication interaction request to enable the
325 * interaction handler to supply the missing authentication data.
327 class UCBHELPER_DLLPUBLIC InteractionSupplyAuthentication
:
328 public InteractionContinuation
,
329 public css::lang::XTypeProvider
,
330 public css::ucb::XInteractionSupplyAuthentication2
332 css::uno::Sequence
< css::ucb::RememberAuthentication
>
333 m_aRememberPasswordModes
;
334 css::uno::Sequence
< css::ucb::RememberAuthentication
>
335 m_aRememberAccountModes
;
337 OUString m_aUserName
;
338 OUString m_aPassword
;
340 css::ucb::RememberAuthentication m_eRememberPasswordMode
;
341 css::ucb::RememberAuthentication m_eDefaultRememberPasswordMode
;
342 css::ucb::RememberAuthentication m_eRememberAccountMode
;
343 css::ucb::RememberAuthentication m_eDefaultRememberAccountMode
;
344 bool m_bCanSetRealm
: 1;
345 bool m_bCanSetUserName
: 1;
346 bool m_bCanSetPassword
: 1;
347 bool m_bCanSetAccount
: 1;
348 bool m_bCanUseSystemCredentials
: 1;
349 bool m_bUseSystemCredentials
: 1;
355 * Note: The remember-authentication stuff is interesting only for
356 * clients implementing own password storage functionality.
358 * @param rxRequest is the interaction request that owns this continuation.
359 * @param bCanSetRealm indicates, whether the realm given with the
360 * authentication request is read-only.
361 * @param bCanSetUserName indicates, whether the username given with the
362 * authentication request is read-only.
363 * @param bCanSetPassword indicates, whether the password given with the
364 * authentication request is read-only.
365 * @param bCanSetAccount indicates, whether the account given with the
366 * authentication request is read-only.
367 * @param rRememberPasswordModes specifies the authentication-remember-
368 * modes for passwords supported by the requesting client.
369 * @param eDefaultRememberPasswordMode specifies the default
370 * authentication-remember-mode for passwords preferred by the
372 * @param rRememberAccountModes specifies the authentication-remember-
373 * modes for accounts supported by the requesting client.
374 * @param eDefaultRememberAccountMode specifies the default
375 * authentication-remember-mode for accounts preferred by the
377 * @param bCanUseSystemCredentials indicates whether issuer of the
378 * authentication request can obtain and use system credentials
379 * for authentication.
381 * @see css::ucb::AuthenticationRequest
382 * @see css::ucb::RememberAuthentication
384 inline InteractionSupplyAuthentication(
385 InteractionRequest
* pRequest
,
387 bool bCanSetUserName
,
388 bool bCanSetPassword
,
390 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
391 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
392 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
393 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
394 bool bCanUseSystemCredentials
);
397 virtual css::uno::Any SAL_CALL
398 queryInterface( const css::uno::Type
& rType
)
399 throw( css::uno::RuntimeException
, std::exception
) override
;
400 virtual void SAL_CALL
acquire()
402 virtual void SAL_CALL
release()
406 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
408 throw( css::uno::RuntimeException
, std::exception
) override
;
409 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
410 getImplementationId()
411 throw( css::uno::RuntimeException
, std::exception
) override
;
413 // XInteractionContinuation
414 virtual void SAL_CALL
select()
415 throw( css::uno::RuntimeException
, std::exception
) override
;
417 // XInteractionSupplyAuthentication
418 virtual sal_Bool SAL_CALL
420 throw( css::uno::RuntimeException
, std::exception
) override
;
421 virtual void SAL_CALL
422 setRealm( const OUString
& Realm
)
423 throw( css::uno::RuntimeException
, std::exception
) override
;
425 virtual sal_Bool SAL_CALL
427 throw( css::uno::RuntimeException
, std::exception
) override
;
428 virtual void SAL_CALL
429 setUserName( const OUString
& UserName
)
430 throw( css::uno::RuntimeException
, std::exception
) override
;
432 virtual sal_Bool SAL_CALL
434 throw( css::uno::RuntimeException
, std::exception
) override
;
435 virtual void SAL_CALL
436 setPassword( const OUString
& Password
)
437 throw( css::uno::RuntimeException
, std::exception
) override
;
439 virtual css::uno::Sequence
<
440 css::ucb::RememberAuthentication
> SAL_CALL
441 getRememberPasswordModes(
442 css::ucb::RememberAuthentication
& Default
)
443 throw( css::uno::RuntimeException
, std::exception
) override
;
444 virtual void SAL_CALL
445 setRememberPassword( css::ucb::RememberAuthentication Remember
)
446 throw( css::uno::RuntimeException
, std::exception
) override
;
448 virtual sal_Bool SAL_CALL
450 throw( css::uno::RuntimeException
, std::exception
) override
;
451 virtual void SAL_CALL
452 setAccount( const OUString
& Account
)
453 throw( css::uno::RuntimeException
, std::exception
) override
;
455 virtual css::uno::Sequence
< css::ucb::RememberAuthentication
> SAL_CALL
456 getRememberAccountModes(
457 css::ucb::RememberAuthentication
& Default
)
458 throw( css::uno::RuntimeException
, std::exception
) override
;
459 virtual void SAL_CALL
460 setRememberAccount( css::ucb::RememberAuthentication Remember
)
461 throw( css::uno::RuntimeException
, std::exception
) override
;
463 // XInteractionSupplyAuthentication2
464 virtual sal_Bool SAL_CALL
canUseSystemCredentials( sal_Bool
& Default
)
465 throw ( css::uno::RuntimeException
, std::exception
) override
;
466 virtual void SAL_CALL
setUseSystemCredentials( sal_Bool UseSystemCredentials
)
467 throw ( css::uno::RuntimeException
, std::exception
) override
;
469 // Non-interface methods.
472 * This method returns the realm that was supplied by the interaction
477 const OUString
& getRealm() const { return m_aRealm
; }
480 * This method returns the username that was supplied by the interaction
483 * @return the username.
485 const OUString
& getUserName() const { return m_aUserName
; }
488 * This method returns the password that was supplied by the interaction
491 * @return the password.
493 const OUString
& getPassword() const { return m_aPassword
; }
496 * This method returns the authentication remember-mode for the password
497 * that was supplied by the interaction handler.
499 * @return the remember-mode for the password.
501 const css::ucb::RememberAuthentication
&
502 getRememberPasswordMode() const { return m_eRememberPasswordMode
; }
504 bool getUseSystemCredentials() const { return m_bUseSystemCredentials
; }
509 inline InteractionSupplyAuthentication::InteractionSupplyAuthentication(
510 InteractionRequest
* pRequest
,
512 bool bCanSetUserName
,
513 bool bCanSetPassword
,
515 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
516 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
517 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
518 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
519 bool bCanUseSystemCredentials
)
520 : InteractionContinuation( pRequest
),
521 m_aRememberPasswordModes( rRememberPasswordModes
),
522 m_aRememberAccountModes( rRememberAccountModes
),
523 m_eRememberPasswordMode( eDefaultRememberPasswordMode
),
524 m_eDefaultRememberPasswordMode( eDefaultRememberPasswordMode
),
525 m_eRememberAccountMode( eDefaultRememberAccountMode
),
526 m_eDefaultRememberAccountMode( eDefaultRememberAccountMode
),
527 m_bCanSetRealm( bCanSetRealm
),
528 m_bCanSetUserName( bCanSetUserName
),
529 m_bCanSetPassword( bCanSetPassword
),
530 m_bCanSetAccount( bCanSetAccount
),
531 m_bCanUseSystemCredentials( bCanUseSystemCredentials
),
532 m_bUseSystemCredentials( false )
538 * This class implements a standard interaction continuation, namely the
539 * interface XInteractionReplaceExistingData. Instances of this class can be
540 * passed along with an interaction request to indicate the possibility to
541 * replace existing data.
543 class InteractionReplaceExistingData
:
544 public InteractionContinuation
,
545 public css::lang::XTypeProvider
,
546 public css::ucb::XInteractionReplaceExistingData
549 InteractionReplaceExistingData( InteractionRequest
* pRequest
)
550 : InteractionContinuation( pRequest
) {}
553 virtual css::uno::Any SAL_CALL
554 queryInterface( const css::uno::Type
& rType
)
555 throw( css::uno::RuntimeException
, std::exception
) override
;
556 virtual void SAL_CALL
acquire()
558 virtual void SAL_CALL
release()
562 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
564 throw( css::uno::RuntimeException
, std::exception
) override
;
565 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
566 getImplementationId()
567 throw( css::uno::RuntimeException
, std::exception
) override
;
569 // XInteractionContinuation
570 virtual void SAL_CALL
select()
571 throw( css::uno::RuntimeException
, std::exception
) override
;
574 class UCBHELPER_DLLPUBLIC InteractionAuthFallback
:
575 public InteractionContinuation
,
576 public css::ucb::XInteractionAuthFallback
581 InteractionAuthFallback( InteractionRequest
* pRequest
)
582 : InteractionContinuation( pRequest
) {}
585 virtual css::uno::Any SAL_CALL
586 queryInterface( const css::uno::Type
& rType
)
587 throw( css::uno::RuntimeException
, std::exception
) override
;
588 virtual void SAL_CALL
acquire()
590 virtual void SAL_CALL
release()
593 // XInteractionContinuation
594 virtual void SAL_CALL
select()
595 throw( css::uno::RuntimeException
, std::exception
) override
;
598 virtual void SAL_CALL
setCode( const OUString
& code
)
599 throw (::css::uno::RuntimeException
, ::std::exception
) override
;
600 const OUString
& SAL_CALL
getCode()
601 throw (::css::uno::RuntimeException
, ::std::exception
);
607 } // namespace ucbhelper
609 #endif /* ! INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX */
611 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */