~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/efl/ewk/ewk_cookies.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2010 ProFUSION embedded systems
 
3
    Copyright (C) 2010 Samsung Electronics
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
    Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "config.h"
 
22
#include "ewk_cookies.h"
 
23
 
 
24
#include "CookieJarSoup.h"
 
25
#include "ResourceHandle.h"
 
26
#include <Eina.h>
 
27
#include <eina_safety_checks.h>
 
28
#include <glib.h>
 
29
#include <libsoup/soup.h>
 
30
#include <wtf/text/CString.h>
 
31
 
 
32
Eina_Bool ewk_cookies_file_set(const char* filename)
 
33
{
 
34
    SoupCookieJar* cookieJar = 0;
 
35
    if (filename)
 
36
        cookieJar = soup_cookie_jar_text_new(filename, FALSE);
 
37
    else
 
38
        cookieJar = soup_cookie_jar_new();
 
39
 
 
40
    if (!cookieJar)
 
41
        return false;
 
42
 
 
43
    soup_cookie_jar_set_accept_policy(cookieJar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
 
44
 
 
45
    SoupSession* session = WebCore::ResourceHandle::defaultSession();
 
46
    SoupSessionFeature* oldjar = soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR);
 
47
    if (oldjar)
 
48
        soup_session_remove_feature(session, oldjar);
 
49
 
 
50
    WebCore::setSoupCookieJar(cookieJar);
 
51
    soup_session_add_feature(session, SOUP_SESSION_FEATURE(cookieJar));
 
52
 
 
53
    return true;
 
54
}
 
55
 
 
56
void ewk_cookies_clear(void)
 
57
{
 
58
    GSList* list;
 
59
    GSList* p;
 
60
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
 
61
 
 
62
    list = soup_cookie_jar_all_cookies(cookieJar);
 
63
    for (p = list; p; p = p->next)
 
64
        soup_cookie_jar_delete_cookie(cookieJar, (SoupCookie*)p->data);
 
65
 
 
66
    soup_cookies_free(list);
 
67
}
 
68
 
 
69
Eina_List* ewk_cookies_get_all(void)
 
70
{
 
71
    Eina_List* result = 0;
 
72
    GSList* list;
 
73
    GSList* p;
 
74
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
 
75
 
 
76
    list = soup_cookie_jar_all_cookies(cookieJar);
 
77
    for (p = list; p; p = p->next) {
 
78
        SoupCookie* cookie = static_cast<SoupCookie*>(p->data);
 
79
        Ewk_Cookie* ewkCookie = new Ewk_Cookie;
 
80
        ewkCookie->name = eina_stringshare_add(cookie->name);
 
81
        ewkCookie->value = eina_stringshare_add(cookie->value);
 
82
        ewkCookie->domain = eina_stringshare_add(cookie->domain);
 
83
        ewkCookie->path = eina_stringshare_add(cookie->path);
 
84
        ewkCookie->expires = soup_date_to_time_t(cookie->expires);
 
85
        ewkCookie->secure = static_cast<Eina_Bool>(cookie->secure);
 
86
        ewkCookie->http_only = static_cast<Eina_Bool>(cookie->http_only);
 
87
        result = eina_list_append(result, ewkCookie);
 
88
    }
 
89
 
 
90
    soup_cookies_free(list);
 
91
 
 
92
    return result;
 
93
}
 
94
 
 
95
void ewk_cookies_cookie_del(Ewk_Cookie* cookie)
 
96
{
 
97
    EINA_SAFETY_ON_NULL_RETURN(cookie);
 
98
    GSList* list;
 
99
    GSList* p;
 
100
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
 
101
    SoupCookie* cookie1 = soup_cookie_new(
 
102
        cookie->name, cookie->value, cookie->domain, cookie->path, -1);
 
103
 
 
104
    list = soup_cookie_jar_all_cookies(cookieJar);
 
105
    for (p = list; p; p = p->next) {
 
106
        SoupCookie* cookie2 = static_cast<SoupCookie*>(p->data);
 
107
        if (soup_cookie_equal(cookie1, cookie2)) {
 
108
            soup_cookie_jar_delete_cookie(cookieJar, cookie2);
 
109
            break;
 
110
        }
 
111
    }
 
112
 
 
113
    soup_cookie_free(cookie1);
 
114
    soup_cookies_free(list);
 
115
}
 
116
 
 
117
void ewk_cookies_cookie_free(Ewk_Cookie* cookie)
 
118
{
 
119
    EINA_SAFETY_ON_NULL_RETURN(cookie);
 
120
    eina_stringshare_del(cookie->name);
 
121
    eina_stringshare_del(cookie->value);
 
122
    eina_stringshare_del(cookie->domain);
 
123
    eina_stringshare_del(cookie->path);
 
124
    delete cookie;
 
125
}
 
126
 
 
127
void ewk_cookies_policy_set(Ewk_Cookie_Policy cookiePolicy)
 
128
{
 
129
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
 
130
    SoupCookieJarAcceptPolicy policy;
 
131
 
 
132
    policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
 
133
    switch (cookiePolicy) {
 
134
    case EWK_COOKIE_JAR_ACCEPT_NEVER:
 
135
        policy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
 
136
        break;
 
137
    case EWK_COOKIE_JAR_ACCEPT_ALWAYS:
 
138
        policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
 
139
        break;
 
140
    case EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY:
 
141
        policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
 
142
        break;
 
143
    }
 
144
 
 
145
    soup_cookie_jar_set_accept_policy(cookieJar, policy);
 
146
}
 
147
 
 
148
Ewk_Cookie_Policy ewk_cookies_policy_get(void)
 
149
{
 
150
    Ewk_Cookie_Policy ewkPolicy = EWK_COOKIE_JAR_ACCEPT_ALWAYS;
 
151
    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
 
152
    SoupCookieJarAcceptPolicy policy;
 
153
 
 
154
    policy = soup_cookie_jar_get_accept_policy(cookieJar);
 
155
    switch (policy) {
 
156
    case SOUP_COOKIE_JAR_ACCEPT_NEVER:
 
157
        ewkPolicy = EWK_COOKIE_JAR_ACCEPT_NEVER;
 
158
        break;
 
159
    case SOUP_COOKIE_JAR_ACCEPT_ALWAYS:
 
160
        ewkPolicy = EWK_COOKIE_JAR_ACCEPT_ALWAYS;
 
161
        break;
 
162
    case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY:
 
163
        ewkPolicy = EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
 
164
        break;
 
165
    }
 
166
 
 
167
    return ewkPolicy;
 
168
}