CookieStorageCFNet.cpp [plain text]
#include "config.h"
#include "CookieStorage.h"
#include "NetworkStorageSession.h"
#include <wtf/MainThread.h>
#if PLATFORM(COCOA)
#include "WebCoreSystemInterface.h"
#elif PLATFORM(WIN)
#include "LoaderRunLoopCF.h"
#include <CFNetwork/CFHTTPCookiesPriv.h>
#include <WebKitSystemInterface/WebKitSystemInterface.h>
#endif
namespace WebCore {
#if PLATFORM(WIN)
static CookieChangeCallbackPtr cookieChangeCallback;
static void notifyCookiesChangedOnMainThread(void*)
{
ASSERT(isMainThread());
cookieChangeCallback();
}
static void notifyCookiesChanged(CFHTTPCookieStorageRef, void *)
{
callOnMainThread(notifyCookiesChangedOnMainThread, 0);
}
static inline CFRunLoopRef cookieStorageObserverRunLoop()
{
return loaderRunLoop();
}
void startObservingCookieChanges(CookieChangeCallbackPtr callback)
{
ASSERT(isMainThread());
ASSERT(!cookieChangeCallback);
cookieChangeCallback = callback;
CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
ASSERT(runLoop);
RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage();
ASSERT(cookieStorage);
CFHTTPCookieStorageScheduleWithRunLoop(cookieStorage.get(), runLoop, kCFRunLoopCommonModes);
CFHTTPCookieStorageAddObserver(cookieStorage.get(), runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
}
void stopObservingCookieChanges()
{
ASSERT(isMainThread());
cookieChangeCallback = 0;
CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
ASSERT(runLoop);
RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage();
ASSERT(cookieStorage);
CFHTTPCookieStorageRemoveObserver(cookieStorage.get(), runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
CFHTTPCookieStorageUnscheduleFromRunLoop(cookieStorage.get(), runLoop, kCFRunLoopCommonModes);
}
#endif // PLATFORM(WIN)
}