Changeset 199167 in webkit


Ignore:
Timestamp:
Apr 7, 2016 12:00:53 PM (8 years ago)
Author:
BJ Burg
Message:

CookieJar should support adding synthetic cookies for developer tools
https://bugs.webkit.org/show_bug.cgi?id=156091
<rdar://problem/25581340>

Reviewed by Timothy Hatcher.

Source/WebCore:

This patch adds an API that can set an arbitrary cookie in cookie storage
in order to support developer tools and automated testing. It delegates storing
the cookie to a platform implementation.

No new tests because the code isn't used by any clients yet.

  • loader/CookieJar.cpp:

(WebCore::addCookie): Added.

  • loader/CookieJar.h:
  • platform/Cookie.h:

Remove an outdated comment. This struct is used in many places.

  • platform/CookiesStrategy.h: Add new method.
  • platform/network/PlatformCookieJar.h: Add new method.
  • platform/network/cf/CookieJarCFNet.cpp:

(WebCore::addCookie): Add a stub.

  • platform/network/curl/CookieJarCurl.cpp:

(WebCore::addCookie): Add a stub.

  • platform/network/mac/CookieJarMac.mm:

(WebCore::addCookie): Add an implementation that turns the WebCore::Cookie into
an NSHTTPCookie and converts it again to CFHTTPCookie if necessary.

  • platform/network/soup/CookieJarSoup.cpp:

(WebCore::addCookie): Add a stub.

  • platform/spi/cf/CFNetworkSPI.h:

Add -[NSHTTPCookie _CFHTTPCookie] SPI.

Source/WebKit/mac:

  • WebCoreSupport/WebPlatformStrategies.h:
  • WebCoreSupport/WebPlatformStrategies.mm:

(WebPlatformStrategies::addCookie):
Add new method override.

Source/WebKit/win:

  • WebCoreSupport/WebPlatformStrategies.h:
  • WebCoreSupport/WebPlatformStrategies.cpp:

Add new method override.

Source/WebKit2:

Plumb the new method through the strategy and out to the network process.

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::addCookie):

  • NetworkProcess/NetworkConnectionToWebProcess.h:
  • NetworkProcess/NetworkConnectionToWebProcess.messages.in:
  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

(WebKit::WebPlatformStrategies::addCookie):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.h:
Location:
trunk/Source
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r199164 r199167  
     12016-04-07  Brian Burg  <bburg@apple.com>
     2
     3        CookieJar should support adding synthetic cookies for developer tools
     4        https://bugs.webkit.org/show_bug.cgi?id=156091
     5        <rdar://problem/25581340>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        This patch adds an API that can set an arbitrary cookie in cookie storage
     10        in order to support developer tools and automated testing. It delegates storing
     11        the cookie to a platform implementation.
     12
     13        No new tests because the code isn't used by any clients yet.
     14
     15        * loader/CookieJar.cpp:
     16        (WebCore::addCookie): Added.
     17        * loader/CookieJar.h:
     18
     19        * platform/Cookie.h:
     20        Remove an outdated comment. This struct is used in many places.
     21
     22        * platform/CookiesStrategy.h: Add new method.
     23        * platform/network/PlatformCookieJar.h: Add new method.
     24        * platform/network/cf/CookieJarCFNet.cpp:
     25        (WebCore::addCookie): Add a stub.
     26        * platform/network/curl/CookieJarCurl.cpp:
     27        (WebCore::addCookie): Add a stub.
     28        * platform/network/mac/CookieJarMac.mm:
     29        (WebCore::addCookie): Add an implementation that turns the WebCore::Cookie into
     30        an NSHTTPCookie and converts it again to CFHTTPCookie if necessary.
     31
     32        * platform/network/soup/CookieJarSoup.cpp:
     33        (WebCore::addCookie): Add a stub.
     34
     35        * platform/spi/cf/CFNetworkSPI.h:
     36        Add -[NSHTTPCookie _CFHTTPCookie] SPI.
     37
    1382016-04-07  Commit Queue  <commit-queue@webkit.org>
    239
  • trunk/Source/WebCore/loader/CookieJar.cpp

    r198632 r199167  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8585}
    8686
     87void addCookie(const Document* document, const URL& url, const Cookie& cookie)
     88{
     89    platformStrategies()->cookiesStrategy()->addCookie(storageSession(document), url, cookie);
    8790}
     91
     92}
  • trunk/Source/WebCore/loader/CookieJar.h

    r172814 r199167  
    11/*
    2  * Copyright (C) 2003, 2006, 2008, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003, 2006, 2008, 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4848WEBCORE_EXPORT bool getRawCookies(const Document*, const URL&, Vector<Cookie>&);
    4949WEBCORE_EXPORT void deleteCookie(const Document*, const URL&, const String& cookieName);
     50WEBCORE_EXPORT void addCookie(const Document*, const URL&, const Cookie&);
    5051
    5152}
  • trunk/Source/WebCore/platform/Cookie.h

    r181709 r199167  
    3131
    3232namespace WebCore {
    33 
    34     // This struct is currently only used to provide more cookies information
    35     // to the Web Inspector.
    3633
    3734    struct Cookie {
  • trunk/Source/WebCore/platform/CookiesStrategy.h

    r156550 r199167  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4646    virtual bool getRawCookies(const NetworkStorageSession&, const URL& firstParty, const URL&, Vector<Cookie>&) = 0;
    4747    virtual void deleteCookie(const NetworkStorageSession&, const URL&, const String& cookieName) = 0;
     48    virtual void addCookie(const NetworkStorageSession&, const URL&, const Cookie&) = 0;
    4849
    4950protected:
  • trunk/Source/WebCore/platform/network/PlatformCookieJar.h

    r187375 r199167  
    11/*
    2  * Copyright (C) 2003, 2006, 2008, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003, 2006, 2008, 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4747WEBCORE_EXPORT bool getRawCookies(const NetworkStorageSession&, const URL& firstParty, const URL&, Vector<Cookie>&);
    4848WEBCORE_EXPORT void deleteCookie(const NetworkStorageSession&, const URL&, const String&);
     49WEBCORE_EXPORT void addCookie(const NetworkStorageSession&, const URL&, const Cookie&);
    4950WEBCORE_EXPORT void getHostnamesWithCookies(const NetworkStorageSession&, HashSet<String>& hostnames);
    5051WEBCORE_EXPORT void deleteCookiesForHostnames(const NetworkStorageSession&, const Vector<String>& cookieHostNames);
  • trunk/Source/WebCore/platform/network/cf/CookieJarCFNet.cpp

    r194318 r199167  
    11/*
    2  * Copyright (C) 2006, 2007, 2008, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007, 2008, 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333#include "URL.h"
    3434#include "NetworkStorageSession.h"
     35#include "NotImplemented.h"
    3536#include "SoftLinking.h"
    3637#include <CFNetwork/CFHTTPCookiesPriv.h>
     
    217218}
    218219
     220void addCookie(const NetworkStorageSession&, const URL&, const Cookie&)
     221{
     222    // FIXME: implement this command. <https://webkit.org/b/156298>
     223    notImplemented();
     224}
     225
    219226void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
    220227{
  • trunk/Source/WebCore/platform/network/curl/CookieJarCurl.cpp

    r196223 r199167  
    2121
    2222#include "Cookie.h"
     23#include "NotImplemented.h"
    2324#include "URL.h"
    2425#include "ResourceHandleManager.h"
     
    326327}
    327328
     329void addCookie(const NetworkStorageSession&, const URL&, const Cookie&)
     330{
     331    // FIXME: implement this command. <https://webkit.org/b/156296>
     332    notImplemented();
     333}
     334
    328335void getHostnamesWithCookies(const NetworkStorageSession&, HashSet<String>& hostnames)
    329336{
  • trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm

    r197518 r199167  
    3232#import "WebCoreSystemInterface.h"
    3333
     34namespace WebCore {
     35static NSHTTPCookieStorage *cookieStorage(const NetworkStorageSession&);
     36}
     37
    3438#if !USE(CFNETWORK)
    3539
     
    243247}
    244248
     249void addCookie(const NetworkStorageSession& session, const URL& url, const Cookie& cookie)
     250{
     251    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     252
     253    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = session.cookieStorage();
     254
     255    // FIXME: existing APIs do not provide a way to set httpOnly without parsing headers from scratch.
     256
     257    NSURL *originURL = url;
     258    NSHTTPCookie *httpCookie = [NSHTTPCookie cookieWithProperties:@{
     259        NSHTTPCookieName: cookie.name,
     260        NSHTTPCookieValue: cookie.value,
     261        NSHTTPCookieDomain: cookie.domain,
     262        NSHTTPCookiePath: cookie.path,
     263        NSHTTPCookieOriginURL: originURL,
     264        NSHTTPCookieSecure: @(cookie.secure),
     265        NSHTTPCookieDiscard: @(cookie.session),
     266        NSHTTPCookieExpires: [NSDate dateWithTimeIntervalSince1970:cookie.expires / 1000.0],
     267    }];
     268
     269#if !USE(CFNETWORK)
     270    if (!cookieStorage) {
     271        [WebCore::cookieStorage(session) setCookie:httpCookie];
     272        return;
     273    }
     274#endif // !USE(CFNETWORK)
     275
     276    CFHTTPCookieStorageSetCookie(cookieStorage.get(), [httpCookie _CFHTTPCookie]);
     277
     278    END_BLOCK_OBJC_EXCEPTIONS;
     279}
     280
    245281void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
    246282{
  • trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp

    r187375 r199167  
    2929#include "URL.h"
    3030#include "NetworkingContext.h"
     31#include "NotImplemented.h"
    3132#include "PlatformCookieJar.h"
    3233#include "SoupNetworkSession.h"
     
    190191        soup_cookie_free(cookie);
    191192    }
     193}
     194
     195void addCookie(const NetworkStorageSession&, const URL&, const Cookie&)
     196{
     197    // FIXME: implement this command. <https://webkit.org/b/156295>
     198    notImplemented();
    192199}
    193200
  • trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h

    r198457 r199167  
    5757#endif // defined(__OBJC__) && PLATFORM(COCOA)
    5858
    59 #else // PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
     59#else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
    6060
    6161typedef CF_ENUM(int64_t, _TimingDataOptions)
     
    7070typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
    7171typedef const struct __CFData* CFDataRef;
     72typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
    7273typedef struct _CFURLConnection* CFURLConnectionRef;
    7374typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
     
    9899@end
    99100
     101@interface NSHTTPCookie ()
     102- (CFHTTPCookieRef)_CFHTTPCookie;
     103@end
     104
    100105#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)
    101106@interface NSURLSessionConfiguration ()
     
    123128#endif // defined(__OBJC__)
    124129
    125 #endif // PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
     130#endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
    126131
    127132EXTERN_C void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
     
    153158
    154159EXTERN_C CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
     160EXTERN_C void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
    155161EXTERN_C void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
    156162EXTERN_C void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
  • trunk/Source/WebKit/mac/ChangeLog

    r199109 r199167  
     12016-04-07  Brian Burg  <bburg@apple.com>
     2
     3        CookieJar should support adding synthetic cookies for developer tools
     4        https://bugs.webkit.org/show_bug.cgi?id=156091
     5        <rdar://problem/25581340>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * WebCoreSupport/WebPlatformStrategies.h:
     10        * WebCoreSupport/WebPlatformStrategies.mm:
     11        (WebPlatformStrategies::addCookie):
     12        Add new method override.
     13
    1142016-04-06  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h

    r198177 r199167  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5757    bool getRawCookies(const WebCore::NetworkStorageSession&, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&) override;
    5858    void deleteCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const String&) override;
    59 
     59    void addCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const WebCore::Cookie&) override;
    6060
    6161    // WebCore::PluginStrategy
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm

    r198177 r199167  
    113113}
    114114
     115void WebPlatformStrategies::addCookie(const NetworkStorageSession& session, const URL& url, const Cookie& cookie)
     116{
     117    WebCore::addCookie(session, url, cookie);
     118}
     119
    115120void WebPlatformStrategies::refreshPlugins()
    116121{
  • trunk/Source/WebKit/win/ChangeLog

    r198655 r199167  
     12016-04-07  Brian Burg  <bburg@apple.com>
     2
     3        CookieJar should support adding synthetic cookies for developer tools
     4        https://bugs.webkit.org/show_bug.cgi?id=156091
     5        <rdar://problem/25581340>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * WebCoreSupport/WebPlatformStrategies.h:
     10        * WebCoreSupport/WebPlatformStrategies.cpp:
     11        Add new method override.
     12
    1132016-03-24  Said Abou-Hallawa  <sabouhallawa@apple,com>
    214
  • trunk/Source/WebKit/win/WebCoreSupport/WebPlatformStrategies.cpp

    r192995 r199167  
    11/*
    2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    105105}
    106106
     107void WebPlatformStrategies::addCookie(const NetworkStorageSession& session, const URL& url, const Cookie& cookie)
     108{
     109    WebCore::addCookie(session, url, cookie);
     110}
     111
    107112void WebPlatformStrategies::refreshPlugins()
    108113{
  • trunk/Source/WebKit/win/WebCoreSupport/WebPlatformStrategies.h

    r192995 r199167  
    11/*
    2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5353    virtual bool getRawCookies(const WebCore::NetworkStorageSession&, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
    5454    virtual void deleteCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const String&);
     55    virtual void addCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const WebCore::Cookie&);
    5556
    5657    // WebCore::PluginStrategy
  • trunk/Source/WebKit2/ChangeLog

    r199118 r199167  
     12016-04-07  Brian Burg  <bburg@apple.com>
     2
     3        CookieJar should support adding synthetic cookies for developer tools
     4        https://bugs.webkit.org/show_bug.cgi?id=156091
     5        <rdar://problem/25581340>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Plumb the new method through the strategy and out to the network process.
     10
     11        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     12        (WebKit::NetworkConnectionToWebProcess::addCookie):
     13        * NetworkProcess/NetworkConnectionToWebProcess.h:
     14        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
     15        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
     16        (WebKit::WebPlatformStrategies::addCookie):
     17        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
     18
    1192016-04-06  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r199043 r199167  
    250250}
    251251
     252void NetworkConnectionToWebProcess::addCookie(SessionID sessionID, const URL& url, const Cookie& cookie)
     253{
     254    WebCore::addCookie(storageSession(sessionID), url, cookie);
     255}
     256
    252257void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, const SandboxExtension::Handle& extensionHandle, const String& contentType)
    253258{
  • trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h

    r199043 r199167  
    8787    void getRawCookies(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
    8888    void deleteCookie(WebCore::SessionID, const WebCore::URL&, const String& cookieName);
     89    void addCookie(WebCore::SessionID, const WebCore::URL&, const WebCore::Cookie&);
    8990
    9091    void registerFileBlobURL(const WebCore::URL&, const String& path, const SandboxExtension::Handle&, const String& contentType);
  • trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in

    r199043 r199167  
    3939    GetRawCookies(WebCore::SessionID sessionID, WebCore::URL firstParty, WebCore::URL url) -> (Vector<WebCore::Cookie> cookies)
    4040    DeleteCookie(WebCore::SessionID sessionID, WebCore::URL url, String cookieName)
     41    AddCookie(WebCore::SessionID sessionID, WebCore::URL url, struct WebCore::Cookie cookie)
    4142
    4243    RegisterFileBlobURL(WebCore::URL url, String path, WebKit::SandboxExtension::Handle extensionHandle, String contentType)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r198177 r199167  
    11/*
    2  * Copyright (C) 2010, 2011, 2012, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011, 2012, 2015, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    156156}
    157157
     158void WebPlatformStrategies::addCookie(const NetworkStorageSession& session, const URL& url, const Cookie& cookie)
     159{
     160    WebProcess::singleton().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::AddCookie(SessionTracker::sessionID(session), url, cookie), 0);
     161}
     162
    158163// PluginStrategy
    159164
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h

    r198177 r199167  
    11/*
    2  * Copyright (C) 2010, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5959    bool getRawCookies(const WebCore::NetworkStorageSession&, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&) override;
    6060    void deleteCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const String&) override;
     61    void addCookie(const WebCore::NetworkStorageSession&, const WebCore::URL&, const WebCore::Cookie&) override;
    6162
    6263    // WebCore::PluginStrategy
Note: See TracChangeset for help on using the changeset viewer.