Changeset 112234 in webkit


Ignore:
Timestamp:
Mar 27, 2012 2:42:59 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[SOUP] Implement missing methods in CookieJarSoup
https://bugs.webkit.org/show_bug.cgi?id=82082

Reviewed by Martin Robinson.

Source/WebCore:

  • platform/network/soup/CookieJarSoup.cpp:

(WebCore::defaultCookieJar): Return a global GRefPtr to store the
default cookie jar.
(WebCore::soupCookieJar): Return the current cookie jar or create
a new one.
(WebCore::setSoupCookieJar): Set the current cookie jar.
(WebCore::setCookies): Fix coding style.
(WebCore::cookiesForDocument): Helper function to get the list of
cookies as a string.
(WebCore::cookies): Use cookiesForDocument().
(WebCore::cookieRequestHeaderFieldValue): Ditto.
(WebCore::getRawCookies): Get the list of cookies for the given
document and url.
(WebCore::deleteCookie): Delete the given cookie.
(WebCore::getHostnamesWithCookies): Use GOwnPtr.
(WebCore::deleteCookiesForHostname): Use GOwnPtr and
soup_cookie_domain_matches() instead of comparing the domain
directly with the given hostname.
(WebCore::deleteAllCookies): Use GOwnPtr.

  • platform/network/soup/CookieJarSoup.h:
  • platform/network/soup/GOwnPtrSoup.cpp:

(WTF::SoupCookie): Add GOwnPtr template for SoupCookie.

  • platform/network/soup/GOwnPtrSoup.h:
  • platform/network/soup/ResourceHandleSoup.cpp:

(WebCore::ensureSessionIsInitialized): Use soupCookieJar() instead
of defaultCookieJar().

Source/WebKit/efl:

  • ewk/ewk_cookies.cpp:

(ewk_cookies_clear): Use soupCookieJar() instead of
defaultCookieJar().
(ewk_cookies_get_all): Ditto.
(ewk_cookies_cookie_del): Ditto.
(ewk_cookies_policy_set): Ditto.
(ewk_cookies_policy_get): Ditto.

Source/WebKit2:

  • WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:

(WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy): Use
soupCookieJar() instead of defaultCookieJar().
(WebKit::WebCookieManager::platformGetHTTPCookieAcceptPolicy): Ditto.

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r112231 r112234  
     12012-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Implement missing methods in CookieJarSoup
     4        https://bugs.webkit.org/show_bug.cgi?id=82082
     5
     6        Reviewed by Martin Robinson.
     7
     8        * platform/network/soup/CookieJarSoup.cpp:
     9        (WebCore::defaultCookieJar): Return a global GRefPtr to store the
     10        default cookie jar.
     11        (WebCore::soupCookieJar): Return the current cookie jar or create
     12        a new one.
     13        (WebCore::setSoupCookieJar): Set the current cookie jar.
     14        (WebCore::setCookies): Fix coding style.
     15        (WebCore::cookiesForDocument): Helper function to get the list of
     16        cookies as a string.
     17        (WebCore::cookies): Use cookiesForDocument().
     18        (WebCore::cookieRequestHeaderFieldValue): Ditto.
     19        (WebCore::getRawCookies): Get the list of cookies for the given
     20        document and url.
     21        (WebCore::deleteCookie): Delete the given cookie.
     22        (WebCore::getHostnamesWithCookies): Use GOwnPtr.
     23        (WebCore::deleteCookiesForHostname): Use GOwnPtr and
     24        soup_cookie_domain_matches() instead of comparing the domain
     25        directly with the given hostname.
     26        (WebCore::deleteAllCookies): Use GOwnPtr.
     27        * platform/network/soup/CookieJarSoup.h:
     28        * platform/network/soup/GOwnPtrSoup.cpp:
     29        (WTF::SoupCookie): Add GOwnPtr template for SoupCookie.
     30        * platform/network/soup/GOwnPtrSoup.h:
     31        * platform/network/soup/ResourceHandleSoup.cpp:
     32        (WebCore::ensureSessionIsInitialized): Use soupCookieJar() instead
     33        of defaultCookieJar().
     34
    1352012-03-27  Nikolas Zimmermann  <nzimmermann@rim.com>
    236
  • trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp

    r107854 r112234  
    3030#include "NetworkingContext.h"
    3131#include "ResourceHandle.h"
     32#include <wtf/gobject/GRefPtr.h>
    3233#include <wtf/text/CString.h>
    3334
    3435namespace WebCore {
    35 
    36 static bool cookiesInitialized;
    37 static SoupCookieJar* cookieJar;
    3836
    3937static SoupCookieJar* cookieJarForDocument(const Document* document)
     
    5351}
    5452
    55 SoupCookieJar* defaultCookieJar()
     53static GRefPtr<SoupCookieJar>& defaultCookieJar()
    5654{
    57     if (!cookiesInitialized) {
    58         cookiesInitialized = true;
    59 
    60         cookieJar = soup_cookie_jar_new();
    61         soup_cookie_jar_set_accept_policy(cookieJar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
    62     }
    63 
     55    DEFINE_STATIC_LOCAL(GRefPtr<SoupCookieJar>, cookieJar, ());
    6456    return cookieJar;
    6557}
    6658
    67 void setDefaultCookieJar(SoupCookieJar* jar)
     59SoupCookieJar* soupCookieJar()
    6860{
    69     cookiesInitialized = true;
     61    if (GRefPtr<SoupCookieJar>& jar = defaultCookieJar())
     62        return jar.get();
    7063
    71     if (cookieJar)
    72         g_object_unref(cookieJar);
     64    SoupCookieJar* jar = soup_cookie_jar_new();
     65    soup_cookie_jar_set_accept_policy(jar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
     66    setSoupCookieJar(jar);
     67    return jar;
     68}
    7369
    74     cookieJar = jar;
    75 
    76     if (cookieJar)
    77         g_object_ref(cookieJar);
     70void setSoupCookieJar(SoupCookieJar* jar)
     71{
     72    defaultCookieJar() = jar;
    7873}
    7974
     
    8580
    8681    GOwnPtr<SoupURI> origin(soup_uri_new(url.string().utf8().data()));
    87 
    8882    GOwnPtr<SoupURI> firstParty(soup_uri_new(document->firstPartyForCookies().string().utf8().data()));
    89 
    90     soup_cookie_jar_set_cookie_with_first_party(jar,
    91                                                 origin.get(),
    92                                                 firstParty.get(),
    93                                                 value.utf8().data());
     83    soup_cookie_jar_set_cookie_with_first_party(jar, origin.get(), firstParty.get(), value.utf8().data());
    9484}
    9585
    96 String cookies(const Document* document, const KURL& url)
     86static String cookiesForDocument(const Document* document, const KURL& url, bool forHTTPHeader)
    9787{
    9888    SoupCookieJar* jar = cookieJarForDocument(document);
     
    10090        return String();
    10191
    102     SoupURI* uri = soup_uri_new(url.string().utf8().data());
    103     char* cookies = soup_cookie_jar_get_cookies(jar, uri, FALSE);
    104     soup_uri_free(uri);
     92    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
     93    GOwnPtr<char> cookies(soup_cookie_jar_get_cookies(jar, uri.get(), forHTTPHeader));
     94    return String::fromUTF8(cookies.get());
     95}
    10596
    106     String result(String::fromUTF8(cookies));
    107     g_free(cookies);
    108 
    109     return result;
     97String cookies(const Document* document, const KURL& url)
     98{
     99    return cookiesForDocument(document, url, false);
    110100}
    111101
    112102String cookieRequestHeaderFieldValue(const Document* document, const KURL& url)
    113103{
    114     SoupCookieJar* jar = cookieJarForDocument(document);
    115     if (!jar)
    116         return String();
    117 
    118     SoupURI* uri = soup_uri_new(url.string().utf8().data());
    119     char* cookies = soup_cookie_jar_get_cookies(jar, uri, TRUE);
    120     soup_uri_free(uri);
    121 
    122     String result(String::fromUTF8(cookies));
    123     g_free(cookies);
    124 
    125     return result;
     104    return cookiesForDocument(document, url, true);
    126105}
    127106
     
    131110}
    132111
    133 bool getRawCookies(const Document*, const KURL&, Vector<Cookie>& rawCookies)
     112bool getRawCookies(const Document* document, const KURL& url, Vector<Cookie>& rawCookies)
    134113{
    135     // FIXME: Not yet implemented
    136114    rawCookies.clear();
    137     return false; // return true when implemented
     115    SoupCookieJar* jar = cookieJarForDocument(document);
     116    if (!jar)
     117        return false;
     118
     119    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
     120    if (!cookies)
     121        return false;
     122
     123    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
     124    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
     125        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
     126        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
     127            continue;
     128        // FIXME: we are currently passing false always for session because there's no API to know
     129        // whether SoupCookieJar is persistent or not. We could probably add soup_cookie_jar_is_persistent().
     130        rawCookies.append(Cookie(String::fromUTF8(cookie->name), String::fromUTF8(cookie->value), String::fromUTF8(cookie->domain),
     131                                 String::fromUTF8(cookie->path), static_cast<double>(soup_date_to_time_t(cookie->expires)) * 1000,
     132                                 cookie->http_only, cookie->secure, false));
     133    }
     134
     135    return true;
    138136}
    139137
    140 void deleteCookie(const Document*, const KURL&, const String&)
     138void deleteCookie(const Document* document, const KURL& url, const String& name)
    141139{
    142     // FIXME: Not yet implemented
     140    SoupCookieJar* jar = cookieJarForDocument(document);
     141    if (!jar)
     142        return;
     143
     144    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
     145    if (!cookies)
     146        return;
     147
     148    CString cookieName = name.utf8();
     149    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
     150    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
     151        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
     152        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
     153            continue;
     154        if (cookieName == cookie->name)
     155            soup_cookie_jar_delete_cookie(jar, cookie.get());
     156    }
    143157}
    144158
    145159void getHostnamesWithCookies(HashSet<String>& hostnames)
    146160{
    147     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
    148     GSList* cookies = soup_cookie_jar_all_cookies(cookieJar);
    149     for (GSList* item = cookies; item; item = item->next) {
    150         SoupCookie* soupCookie = static_cast<SoupCookie*>(item->data);
    151         if (char* domain = const_cast<char*>(soup_cookie_get_domain(soupCookie)))
    152             hostnames.add(String::fromUTF8(domain));
     161    SoupCookieJar* cookieJar = soupCookieJar();
     162    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
     163    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
     164        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(item->data));
     165        if (!cookie->domain)
     166            continue;
     167        hostnames.add(String::fromUTF8(cookie->domain));
    153168    }
    154 
    155     soup_cookies_free(cookies);
    156169}
    157170
     
    159172{
    160173    CString hostNameString = hostname.utf8();
    161 
    162     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
    163     GSList* cookies = soup_cookie_jar_all_cookies(cookieJar);
    164     for (GSList* item = cookies; item; item = item->next) {
    165         SoupCookie* soupCookie = static_cast<SoupCookie*>(item->data);
    166         if (hostNameString == soup_cookie_get_domain(soupCookie))
    167             soup_cookie_jar_delete_cookie(cookieJar, soupCookie);
     174    SoupCookieJar* cookieJar = soupCookieJar();
     175    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
     176    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
     177        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
     178        if (soup_cookie_domain_matches(cookie, hostNameString.data()))
     179            soup_cookie_jar_delete_cookie(cookieJar, cookie);
     180        soup_cookie_free(cookie);
    168181    }
    169 
    170     soup_cookies_free(cookies);
    171182}
    172183
    173184void deleteAllCookies()
    174185{
    175     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
    176     GSList* cookies = soup_cookie_jar_all_cookies(cookieJar);
    177     for (GSList* item = cookies; item; item = item->next)
    178         soup_cookie_jar_delete_cookie(cookieJar, static_cast<SoupCookie*>(item->data));
    179 
    180     soup_cookies_free(cookies);
     186    SoupCookieJar* cookieJar = soupCookieJar();
     187    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
     188    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
     189        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
     190        soup_cookie_jar_delete_cookie(cookieJar, cookie);
     191        soup_cookie_free(cookie);
     192    }
    181193}
    182194
  • trunk/Source/WebCore/platform/network/soup/CookieJarSoup.h

    r41139 r112234  
    3232
    3333namespace WebCore {
    34     SoupCookieJar* defaultCookieJar();
    35     void setDefaultCookieJar(SoupCookieJar* jar);
     34
     35SoupCookieJar* soupCookieJar();
     36void setSoupCookieJar(SoupCookieJar*);
     37
    3638}
    3739
  • trunk/Source/WebCore/platform/network/soup/GOwnPtrSoup.cpp

    r95901 r112234  
    2121#include "GOwnPtrSoup.h"
    2222
     23#include <libsoup/soup-cookie.h>
    2324#include <libsoup/soup-uri.h>
    2425
     
    3132}
    3233
     34template <> void freeOwnedGPtr<SoupCookie>(SoupCookie* ptr)
     35{
     36    if (ptr)
     37        soup_cookie_free(ptr);
    3338}
     39
     40}
  • trunk/Source/WebCore/platform/network/soup/GOwnPtrSoup.h

    r111354 r112234  
    2424
    2525typedef struct _SoupURI SoupURI;
     26typedef struct _SoupCookie SoupCookie;
    2627
    2728namespace WTF {
    2829
    2930template<> void freeOwnedGPtr<SoupURI>(SoupURI* ptr);
     31template<> void freeOwnedGPtr<SoupCookie>(SoupCookie* ptr);
    3032
    3133}
  • trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp

    r110669 r112234  
    160160        SoupCookieJar* jar = SOUP_COOKIE_JAR(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
    161161        if (!jar)
    162             soup_session_add_feature(session, SOUP_SESSION_FEATURE(defaultCookieJar()));
     162            soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCookieJar()));
    163163        else
    164             setDefaultCookieJar(jar);
     164            setSoupCookieJar(jar);
    165165    }
    166166
  • trunk/Source/WebKit/efl/ChangeLog

    r111835 r112234  
     12012-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Implement missing methods in CookieJarSoup
     4        https://bugs.webkit.org/show_bug.cgi?id=82082
     5
     6        Reviewed by Martin Robinson.
     7
     8        * ewk/ewk_cookies.cpp:
     9        (ewk_cookies_clear): Use soupCookieJar() instead of
     10        defaultCookieJar().
     11        (ewk_cookies_get_all): Ditto.
     12        (ewk_cookies_cookie_del): Ditto.
     13        (ewk_cookies_policy_set): Ditto.
     14        (ewk_cookies_policy_get): Ditto.
     15
    1162012-03-23  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
    217
  • trunk/Source/WebKit/efl/ewk/ewk_cookies.cpp

    r109205 r112234  
    4848        soup_session_remove_feature(session, oldjar);
    4949
    50     WebCore::setDefaultCookieJar(cookieJar);
     50    WebCore::setSoupCookieJar(cookieJar);
    5151    soup_session_add_feature(session, SOUP_SESSION_FEATURE(cookieJar));
    5252
     
    5858    GSList* list;
    5959    GSList* p;
    60     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     60    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    6161
    6262    list = soup_cookie_jar_all_cookies(cookieJar);
     
    7272    GSList* list;
    7373    GSList* p;
    74     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     74    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    7575
    7676    list = soup_cookie_jar_all_cookies(cookieJar);
     
    9898    GSList* list;
    9999    GSList* p;
    100     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     100    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    101101    SoupCookie* cookie1 = soup_cookie_new(
    102102        cookie->name, cookie->value, cookie->domain, cookie->path, -1);
     
    127127void ewk_cookies_policy_set(Ewk_Cookie_Policy cookiePolicy)
    128128{
    129     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     129    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    130130    SoupCookieJarAcceptPolicy policy;
    131131
     
    149149{
    150150    Ewk_Cookie_Policy ewkPolicy = EWK_COOKIE_JAR_ACCEPT_ALWAYS;
    151     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     151    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    152152    SoupCookieJarAcceptPolicy policy;
    153153
  • trunk/Source/WebKit2/ChangeLog

    r112227 r112234  
     12012-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Implement missing methods in CookieJarSoup
     4        https://bugs.webkit.org/show_bug.cgi?id=82082
     5
     6        Reviewed by Martin Robinson.
     7
     8        * WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:
     9        (WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy): Use
     10        soupCookieJar() instead of defaultCookieJar().
     11        (WebKit::WebCookieManager::platformGetHTTPCookieAcceptPolicy): Ditto.
     12
    1132012-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
    214
  • trunk/Source/WebKit2/WebProcess/Cookies/soup/WebCookieManagerSoup.cpp

    r100362 r112234  
    3636void WebCookieManager::platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
    3737{
    38     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     38    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    3939    SoupCookieJarAcceptPolicy soupPolicy;
    4040
     
    5656HTTPCookieAcceptPolicy WebCookieManager::platformGetHTTPCookieAcceptPolicy()
    5757{
    58     SoupCookieJar* cookieJar = WebCore::defaultCookieJar();
     58    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
    5959    SoupCookieJarAcceptPolicy soupPolicy;
    6060
Note: See TracChangeset for help on using the changeset viewer.