1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "com/sun/star/ucb/HandleCookiesRequest.hpp"
29 #include "com/sun/star/ucb/XInteractionCookieHandling.hpp"
30 #include "com/sun/star/task/XInteractionRequest.hpp"
32 #include "vos/mutex.hxx"
33 #include "tools/list.hxx"
34 #include "svl/httpcook.hxx"
35 #include "vcl/svapp.hxx"
37 #include "cookiedg.hxx"
41 using namespace com::sun::star
;
45 class CookieList
: public List
48 ~CookieList() SAL_THROW(());
51 CookieList::~CookieList() SAL_THROW(())
54 delete static_cast< CntHTTPCookie
* >(Remove(Count() - 1));
58 executeCookieDialog(Window
* pParent
, CntHTTPCookieRequest
& rRequest
)
59 SAL_THROW((uno::RuntimeException
))
63 vos::OGuard
aGuard(Application::GetSolarMutex());
65 std::auto_ptr
< ResMgr
> xManager(
66 ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui
)));
67 std::auto_ptr
< CookiesDialog
> xDialog(
68 new CookiesDialog(pParent
, &rRequest
, xManager
.get()));
71 catch (std::bad_alloc
const &)
73 throw uno::RuntimeException(
74 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
75 uno::Reference
< uno::XInterface
>());
80 handleCookiesRequest_(
82 ucb::HandleCookiesRequest
const & rRequest
,
83 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
85 SAL_THROW((uno::RuntimeException
))
88 for (sal_Int32 i
= 0; i
< rRequest
.Cookies
.getLength(); ++i
)
92 std::auto_ptr
< CntHTTPCookie
> xCookie(new CntHTTPCookie
);
93 xCookie
->m_aName
= UniString(rRequest
.Cookies
[i
].Name
);
94 xCookie
->m_aValue
= UniString(rRequest
.Cookies
[i
].Value
);
95 xCookie
->m_aDomain
= UniString(rRequest
.Cookies
[i
].Domain
);
96 xCookie
->m_aPath
= UniString(rRequest
.Cookies
[i
].Path
);
98 = DateTime(Date(rRequest
.Cookies
[i
].Expires
.Day
,
99 rRequest
.Cookies
[i
].Expires
.Month
,
100 rRequest
.Cookies
[i
].Expires
.Year
),
101 Time(rRequest
.Cookies
[i
].Expires
.Hours
,
102 rRequest
.Cookies
[i
].Expires
.Minutes
,
103 rRequest
.Cookies
[i
].Expires
.Seconds
,
104 rRequest
.Cookies
[i
].Expires
.HundredthSeconds
));
106 = rRequest
.Cookies
[i
].Secure
? CNTHTTP_COOKIE_FLAG_SECURE
: 0;
107 switch (rRequest
.Cookies
[i
].Policy
)
109 case ucb::CookiePolicy_CONFIRM
:
110 xCookie
->m_nPolicy
= CNTHTTP_COOKIE_POLICY_INTERACTIVE
;
113 case ucb::CookiePolicy_ACCEPT
:
114 xCookie
->m_nPolicy
= CNTHTTP_COOKIE_POLICY_ACCEPTED
;
117 case ucb::CookiePolicy_IGNORE
:
118 xCookie
->m_nPolicy
= CNTHTTP_COOKIE_POLICY_BANNED
;
125 aCookies
.Insert(xCookie
.get(), LIST_APPEND
);
128 catch (std::bad_alloc
const &)
130 throw uno::RuntimeException(
131 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
133 uno::Reference
< uno::XInterface
>());
138 aRequest(rRequest
.URL
,
140 rRequest
.Request
== ucb::CookieRequest_RECEIVE
141 ? CNTHTTP_COOKIE_REQUEST_RECV
142 : CNTHTTP_COOKIE_REQUEST_SEND
);
143 executeCookieDialog(pParent
, aRequest
);
144 for (sal_Int32 i
= 0; i
< rContinuations
.getLength(); ++i
)
146 uno::Reference
< ucb::XInteractionCookieHandling
>
147 xCookieHandling(rContinuations
[i
], uno::UNO_QUERY
);
148 if (xCookieHandling
.is())
150 switch (aRequest
.m_nRet
)
152 case CNTHTTP_COOKIE_POLICY_INTERACTIVE
:
154 setGeneralPolicy(ucb::CookiePolicy_CONFIRM
);
157 case CNTHTTP_COOKIE_POLICY_ACCEPTED
:
159 setGeneralPolicy(ucb::CookiePolicy_ACCEPT
);
162 case CNTHTTP_COOKIE_POLICY_BANNED
:
164 setGeneralPolicy(ucb::CookiePolicy_IGNORE
);
167 for (sal_Int32 j
= 0; j
< rRequest
.Cookies
.getLength(); ++j
)
168 if (rRequest
.Cookies
[j
].Policy
169 == ucb::CookiePolicy_CONFIRM
)
170 switch (static_cast< CntHTTPCookie
* >(aCookies
.
174 case CNTHTTP_COOKIE_POLICY_ACCEPTED
:
176 setSpecificPolicy(rRequest
.Cookies
[j
], true);
179 case CNTHTTP_COOKIE_POLICY_BANNED
:
181 setSpecificPolicy(rRequest
.Cookies
[j
], false);
184 xCookieHandling
->select();
193 UUIInteractionHelper::handleCookiesRequest(
194 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
195 SAL_THROW((uno::RuntimeException
))
197 uno::Any
aAnyRequest(rRequest
->getRequest());
199 ucb::HandleCookiesRequest aCookiesRequest
;
200 if (aAnyRequest
>>= aCookiesRequest
)
202 handleCookiesRequest_(getParentProperty(),
204 rRequest
->getContinuations());