1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* Copyright (C) 2011, 2012 Research In Motion Limited. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
* Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
*/
#include "config.h"
#include "CookieJar.h"
#include "Cookie.h"
#include "CookieManager.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoaderClientBlackBerry.h"
#include "KURL.h"
#include "NotImplemented.h"
#include "Page.h"
#include "PageGroupLoadDeferrer.h"
#include "Settings.h"
#include <wtf/text/CString.h>
namespace WebCore {
String cookies(Document const* document, KURL const& url)
{
Frame* frame = document->frame();
Page* page = frame ? frame->page() : 0;
if (!page)
return String();
if (!(frame && frame->loader() && frame->loader()->client()))
return String();
if (!static_cast<FrameLoaderClientBlackBerry*>(frame->loader()->client())->cookiesEnabled())
return String();
ASSERT(document && url == document->cookieURL());
// 'HttpOnly' cookies should no be accessible from scripts, so we filter them out here
return cookieManager().getCookie(url, NoHttpOnlyCookie);
}
void setCookies(Document* document, KURL const& url, String const& value)
{
Frame* frame = document->frame();
Page* page = frame ? frame->page() : 0;
if (!page)
return;
if (!(frame && frame->loader() && frame->loader()->client()))
return;
if (!static_cast<FrameLoaderClientBlackBerry*>(frame->loader()->client())->cookiesEnabled())
return;
ASSERT(document && url == document->cookieURL());
cookieManager().setCookies(url, value);
}
bool cookiesEnabled(Document const*)
{
// FIXME. Currently cookie is enabled by default, no setting on property page.
return true;
}
bool getRawCookies(const Document* document, const KURL& url, Vector<Cookie>& rawCookies)
{
Vector<ParsedCookie*> result;
cookieManager().getRawCookies(result, url, WithHttpOnlyCookies);
for (size_t i = 0; i < result.size(); i++)
result[i]->appendWebCoreCookie(rawCookies);
return true;
}
void deleteCookie(const Document* document, const KURL& url, const String& cookieName)
{
// Cookies are not bound to the document. Therefore, we don't need to pass
// in the document object to find the targeted cookies in cookie manager.
cookieManager().removeCookieWithName(url, cookieName);
}
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url)
{
ASSERT(document);
if (!(document->frame() && document->frame()->loader() && document->frame()->loader()->client()))
return String();
if (!static_cast<FrameLoaderClientBlackBerry*>(document->frame()->loader()->client())->cookiesEnabled())
return String();
return cookieManager().getCookie(url, WithHttpOnlyCookies);
}
} // namespace WebCore
|