|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "config.h" |
|
20 #include "CookieJar.h" |
|
21 #include "PlatformString.h" |
|
22 #include "DeprecatedString.h" |
|
23 |
|
24 #include "KURL.h" |
|
25 #include "StaticObjectsContainer.h" |
|
26 #include "ResourceLoaderDelegate.h" |
|
27 #include "CookieHandler.h" |
|
28 |
|
29 #include <e32std.h> |
|
30 |
|
31 namespace WebCore { |
|
32 |
|
33 bool cookiesEnabled() |
|
34 { |
|
35 return StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->cookiesEnabled(); |
|
36 } |
|
37 |
|
38 String cookies( const KURL& url ) |
|
39 { |
|
40 if (cookiesEnabled() && StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->cookieHandler()) { |
|
41 long length = 0; |
|
42 unsigned short* cookies = StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->cookieHandler()->cookiesForUrl(url.des(), length); |
|
43 if (cookies) { |
|
44 TPtrC cookieDes(cookies, length); |
|
45 String cookieString( cookieDes ); |
|
46 User::Free( cookies ); |
|
47 return cookieString; |
|
48 } |
|
49 } |
|
50 return String(); |
|
51 } |
|
52 |
|
53 void setCookies( const KURL& url, const KURL& policyURL, const String& cookieStr ) |
|
54 { |
|
55 if (cookiesEnabled() && StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->cookieHandler()) { |
|
56 // <http://bugzilla.opendarwin.org/show_bug.cgi?id=6531>, <rdar://4409034> |
|
57 // cookiesWithResponseHeaderFields doesn't parse cookies without a value |
|
58 String cookieString = cookieStr.contains('=') ? cookieStr : cookieStr + "="; |
|
59 StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->cookieHandler()->addCookie( cookieString.des(), |
|
60 url.des(), policyURL.des() ); |
|
61 } |
|
62 } |
|
63 |
|
64 } |