Changeset 256651 in webkit


Ignore:
Timestamp:
Feb 14, 2020 3:17:39 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

[Curl] Implement NetworkStorageSession::get/set/deleteCookie
https://bugs.webkit.org/show_bug.cgi?id=207450

Patch by Pavel Feldman <pavel.feldman@gmail.com> on 2020-02-14
Reviewed by Don Olmstead.

  • platform/network/curl/CookieJarCurl.cpp:

(WebCore::CookieJarCurl::getAllCookies const):
(WebCore::CookieJarCurl::setCookie const):
(WebCore::CookieJarCurl::deleteCookie const):

  • platform/network/curl/CookieJarCurl.h:
  • platform/network/curl/CookieJarDB.cpp:

(WebCore::CookieJarDB::getAllCookies):

  • platform/network/curl/CookieJarDB.h:
  • platform/network/curl/NetworkStorageSessionCurl.cpp:

(WebCore::NetworkStorageSession::NetworkStorageSession):
(WebCore::NetworkStorageSession::setCookie):
(WebCore::NetworkStorageSession::deleteCookie):
(WebCore::NetworkStorageSession::getAllCookies):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r256648 r256651  
     12020-02-14  Pavel Feldman  <pavel.feldman@gmail.com>
     2
     3        [Curl] Implement NetworkStorageSession::get/set/deleteCookie
     4        https://bugs.webkit.org/show_bug.cgi?id=207450
     5
     6        Reviewed by Don Olmstead.
     7
     8        * platform/network/curl/CookieJarCurl.cpp:
     9        (WebCore::CookieJarCurl::getAllCookies const):
     10        (WebCore::CookieJarCurl::setCookie const):
     11        (WebCore::CookieJarCurl::deleteCookie const):
     12        * platform/network/curl/CookieJarCurl.h:
     13        * platform/network/curl/CookieJarDB.cpp:
     14        (WebCore::CookieJarDB::getAllCookies):
     15        * platform/network/curl/CookieJarDB.h:
     16        * platform/network/curl/NetworkStorageSessionCurl.cpp:
     17        (WebCore::NetworkStorageSession::NetworkStorageSession):
     18        (WebCore::NetworkStorageSession::setCookie):
     19        (WebCore::NetworkStorageSession::deleteCookie):
     20        (WebCore::NetworkStorageSession::getAllCookies):
     21
    1222020-02-14  Nikos Mouchtaris  <nmouchtaris@apple.com>
    223
  • trunk/Source/WebCore/platform/network/curl/CookieJarCurl.cpp

    r248713 r256651  
    148148}
    149149
     150Vector<Cookie> CookieJarCurl::getAllCookies(const NetworkStorageSession& session) const
     151{
     152    CookieJarDB& cookieJarDB = session.cookieDatabase();
     153    return cookieJarDB.getAllCookies();
     154}
     155
     156void CookieJarCurl::setCookie(const NetworkStorageSession& session, const Cookie& cookie) const
     157{
     158    CookieJarDB& cookieJarDB = session.cookieDatabase();
     159    cookieJarDB.setCookie(cookie);
     160}
     161
     162void CookieJarCurl::deleteCookie(const NetworkStorageSession& session, const Cookie& cookie) const
     163{
     164    String url = makeString(cookie.secure ? "https"_s : "http"_s, "://"_s, cookie.domain, cookie.path);
     165    CookieJarDB& cookieJarDB = session.cookieDatabase();
     166    cookieJarDB.deleteCookie(url, cookie.name);
     167}
     168
    150169void CookieJarCurl::deleteAllCookiesModifiedSince(const NetworkStorageSession&, WallTime) const
    151170{
  • trunk/Source/WebCore/platform/network/curl/CookieJarCurl.h

    r248850 r256651  
    5959    void deleteAllCookies(const NetworkStorageSession&) const;
    6060    void deleteAllCookiesModifiedSince(const NetworkStorageSession&, WallTime) const;
     61    Vector<Cookie> getAllCookies(const NetworkStorageSession&) const;
     62    void setCookie(const NetworkStorageSession&, const Cookie&) const;
     63    void deleteCookie(const NetworkStorageSession&, const Cookie&) const;
    6164};
    6265
  • trunk/Source/WebCore/platform/network/curl/CookieJarDB.cpp

    r248846 r256651  
    446446}
    447447
     448Vector<Cookie> CookieJarDB::getAllCookies()
     449{
     450    Vector<Cookie> result;
     451    if (!isEnabled() || !m_database.isOpen())
     452        return result;
     453    const String sql = "SELECT name, value, domain, path, expires, httponly, secure, session FROM Cookie"_s;
     454    auto pstmt = makeUnique<SQLiteStatement>(m_database, sql);
     455    if (!pstmt)
     456        return result;
     457    pstmt->prepare();
     458    while (pstmt->step() == SQLITE_ROW) {
     459        Cookie cookie;
     460        cookie.name = pstmt->getColumnText(0);
     461        cookie.value = pstmt->getColumnText(1);
     462        cookie.domain = pstmt->getColumnText(2).convertToASCIILowercase();
     463        cookie.path = pstmt->getColumnText(3);
     464        cookie.expires = (double)pstmt->getColumnInt64(4) * 1000;
     465        cookie.httpOnly = (pstmt->getColumnInt(5) == 1);
     466        cookie.secure = (pstmt->getColumnInt(6) == 1);
     467        cookie.session = (pstmt->getColumnInt(7) == 1);
     468        result.append(WTFMove(cookie));
     469    }
     470    pstmt->finalize();
     471    return result;
     472}
     473
    448474bool CookieJarDB::hasHttpOnlyCookie(const String& name, const String& domain, const String& path)
    449475{
  • trunk/Source/WebCore/platform/network/curl/CookieJarDB.h

    r248762 r256651  
    5858
    5959    Optional<Vector<Cookie>> searchCookies(const URL& firstParty, const URL& requestUrl, const Optional<bool>& httpOnly, const Optional<bool>& secure, const Optional<bool>& session);
     60    Vector<Cookie> getAllCookies();
    6061    bool setCookie(const URL& firstParty, const URL&, const String& cookie, Source);
    6162    bool setCookie(const Cookie&);
  • trunk/Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp

    r254931 r256651  
    6363    : m_sessionID(sessionID)
    6464    , m_cookieStorage(makeUniqueRef<CookieJarCurl>())
    65     , m_cookieDatabase(makeUniqueRef<CookieJarDB>(defaultCookieJarPath()))
     65    // :memory: creates in-memory database, see https://www.sqlite.org/inmemorydb.html
     66    , m_cookieDatabase(makeUniqueRef<CookieJarDB>(sessionID.isEphemeral() ? ":memory:"_s : defaultCookieJarPath()))
    6667{
    6768}
     
    114115}
    115116
    116 void NetworkStorageSession::setCookie(const Cookie&)
    117 {
    118     // FIXME: Implement for WebKit to use.
    119 }
    120 
    121 void NetworkStorageSession::deleteCookie(const Cookie&)
    122 {
    123     // FIXME: Implement for WebKit to use.
     117void NetworkStorageSession::setCookie(const Cookie& cookie)
     118{
     119    cookieStorage().setCookie(*this, cookie);
     120}
     121
     122void NetworkStorageSession::deleteCookie(const Cookie& cookie)
     123{
     124    cookieStorage().deleteCookie(*this, cookie);
    124125}
    125126
     
    153154Vector<Cookie> NetworkStorageSession::getAllCookies()
    154155{
     156    return cookieStorage().getAllCookies(*this);
     157}
     158
     159void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
     160{
     161    cookieStorage().getHostnamesWithCookies(*this, hostnames);
     162}
     163
     164Vector<Cookie> NetworkStorageSession::getCookies(const URL&)
     165{
    155166    // FIXME: Implement for WebKit to use.
    156167    return { };
    157168}
    158169
    159 void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
    160 {
    161     cookieStorage().getHostnamesWithCookies(*this, hostnames);
    162 }
    163 
    164 Vector<Cookie> NetworkStorageSession::getCookies(const URL&)
    165 {
    166     // FIXME: Implement for WebKit to use.
    167     return { };
    168 }
    169 
    170170void NetworkStorageSession::hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&& completionHandler) const
    171171{
Note: See TracChangeset for help on using the changeset viewer.