#include "config.h"
#include "CookieJar.h"
#include "CookiesStrategy.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "NetworkingContext.h"
#include "PlatformCookieJar.h"
#include "PlatformStrategies.h"
namespace WebCore {
static NetworkingContext* networkingContext(const Document* document)
{
if (!document)
return 0;
Frame* frame = document->frame();
if (!frame)
return 0;
return frame->loader().networkingContext();
}
#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(SOUP)
inline NetworkStorageSession& storageSession(const Document* document)
{
NetworkingContext* context = networkingContext(document);
return context ? context->storageSession() : NetworkStorageSession::defaultStorageSession();
}
#define LOCAL_SESSION(document) NetworkStorageSession& session = storageSession(document);
#else
#define LOCAL_SESSION(document) NetworkStorageSession session(networkingContext(document));
#endif
String cookies(const Document* document, const URL& url)
{
LOCAL_SESSION(document)
return platformStrategies()->cookiesStrategy()->cookiesForDOM(session, document->firstPartyForCookies(), url);
}
void setCookies(Document* document, const URL& url, const String& cookieString)
{
LOCAL_SESSION(document)
platformStrategies()->cookiesStrategy()->setCookiesFromDOM(session, document->firstPartyForCookies(), url, cookieString);
}
bool cookiesEnabled(const Document* document)
{
LOCAL_SESSION(document)
return platformStrategies()->cookiesStrategy()->cookiesEnabled(session, document->firstPartyForCookies(), document->cookieURL());
}
String cookieRequestHeaderFieldValue(const Document* document, const URL& url)
{
LOCAL_SESSION(document)
return platformStrategies()->cookiesStrategy()->cookieRequestHeaderFieldValue(session, document->firstPartyForCookies(), url);
}
bool getRawCookies(const Document* document, const URL& url, Vector<Cookie>& cookies)
{
LOCAL_SESSION(document)
return platformStrategies()->cookiesStrategy()->getRawCookies(session, document->firstPartyForCookies(), url, cookies);
}
void deleteCookie(const Document* document, const URL& url, const String& cookieName)
{
LOCAL_SESSION(document)
platformStrategies()->cookiesStrategy()->deleteCookie(session, url, cookieName);
}
}