Skip to content
Permalink
Browse files
Source/WebCore: Part of WebKit2: Need a way to send notifications to …
…client when cookies change

https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Reviewed by Adam Roben.

Add functions on CookieStorage that allow listening for changes in cookies. When
the cookies are changed, they call through to CookiesStrategy::notifyCookiesChanged.

No change in behavior requiring tests.

* platform/CookiesStrategy.h: Added.
(WebCore::CookiesStrategy::~CookiesStrategy):

* platform/PlatformStrategies.h:
(WebCore::PlatformStrategies::cookiesStrategy):
(WebCore::PlatformStrategies::PlatformStrategies):

* platform/network/CookieStorage.h: Add new function declarations.

* platform/network/cf/CookieStorageCFNet.cpp:
(WebCore::notifyCookiesChangedOnMainThread): Call through to CookiesStrategy::notifyCookiesChanged.
(WebCore::notifyCookiesChanged): Call notifyCookiesChangedOnMainThread on the main thread.
(WebCore::beginObservingCookieChanges): Set up cookie observers on the loader run loop.
(WebCore::finishObservingCookieChanges): Remove our cookie observers from the loader run loop.

* platform/network/mac/CookieStorageMac.mm:
(-[CookieStorageObjCAdapter notifyCookiesChangedOnMainThread]): Call through to CookiesStrategy::notifyCookiesChanged.
(-[CookieStorageObjCAdapter cookiesChangedNotificationHandler:]): Call notifyCookiesChangedOnMainThread on
    the main thread.
(-[CookieStorageObjCAdapter registerForCookieChangeNotifications]): Set up the observer for cookie change notifications.
(-[CookieStorageObjCAdapter unregisterForCookieChangeNotifications]): Remove the observer for cookie change notifications.
(WebCore::beginObservingCookieChanges): Create our CookieStorageObjCAdapter, and call registerForCookieChangeNotifications.
(WebCore::finishObservingCookieChanges): Call unregisterForCookieChangeNotifications.

Add new file.
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj: Set role on files we need to include in WebKit to private.

Source/WebKit/mac: Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Reviewed by Adam Roben.

Add stubs for CookiesStrategy on Mac WebKit1.

* WebCoreSupport/WebPlatformStrategies.h:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::createCookiesStrategy):
(WebPlatformStrategies::notifyCookiesChanged):

Source/WebKit/qt: Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Reviewed by Adam Roben.

Add stubs for CookiesStrategy on Qt WebKit1.

* WebCoreSupport/WebPlatformStrategies.cpp:
(WebPlatformStrategies::createCookiesStrategy):
(WebPlatformStrategies::notifyCookiesChanged):
* WebCoreSupport/WebPlatformStrategies.h:

Source/WebKit/win: Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Reviewed by Adam Roben.

Add stubs for CookiesStrategy on Windows WebKit1.

* WebCoreSupport/WebPlatformStrategies.cpp:
(WebPlatformStrategies::createCookiesStrategy):
(WebPlatformStrategies::notifyCookiesChanged):
* WebCoreSupport/WebPlatformStrategies.h:

Source/WebKit2: Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Reviewed by Adam Roben.

* WebProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::dispatchDidModifyCookies): Add a stub with a FIXME to send a
    message to the UI process.

* WebProcess/Cookies/WebCookieManager.h:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::createCookiesStrategy):
(WebKit::WebPlatformStrategies::notifyCookiesChanged): Call WebCookieManager::dispatchDidModifyCookies.
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:



Canonical link: https://commits.webkit.org/70040@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80145 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Brian Weinstein committed Mar 2, 2011
1 parent 398d095 commit 9d675cd89d5be2b70a593fe001574d946bb2c089
Showing 22 changed files with 359 additions and 14 deletions.
@@ -1,3 +1,44 @@
2011-03-01 Brian Weinstein <bweinstein@apple.com>

Reviewed by Adam Roben.

Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Add functions on CookieStorage that allow listening for changes in cookies. When
the cookies are changed, they call through to CookiesStrategy::notifyCookiesChanged.

No change in behavior requiring tests.

* platform/CookiesStrategy.h: Added.
(WebCore::CookiesStrategy::~CookiesStrategy):

* platform/PlatformStrategies.h:
(WebCore::PlatformStrategies::cookiesStrategy):
(WebCore::PlatformStrategies::PlatformStrategies):

* platform/network/CookieStorage.h: Add new function declarations.

* platform/network/cf/CookieStorageCFNet.cpp:
(WebCore::notifyCookiesChangedOnMainThread): Call through to CookiesStrategy::notifyCookiesChanged.
(WebCore::notifyCookiesChanged): Call notifyCookiesChangedOnMainThread on the main thread.
(WebCore::beginObservingCookieChanges): Set up cookie observers on the loader run loop.
(WebCore::finishObservingCookieChanges): Remove our cookie observers from the loader run loop.

* platform/network/mac/CookieStorageMac.mm:
(-[CookieStorageObjCAdapter notifyCookiesChangedOnMainThread]): Call through to CookiesStrategy::notifyCookiesChanged.
(-[CookieStorageObjCAdapter cookiesChangedNotificationHandler:]): Call notifyCookiesChangedOnMainThread on
the main thread.
(-[CookieStorageObjCAdapter registerForCookieChangeNotifications]): Set up the observer for cookie change notifications.
(-[CookieStorageObjCAdapter unregisterForCookieChangeNotifications]): Remove the observer for cookie change notifications.
(WebCore::beginObservingCookieChanges): Create our CookieStorageObjCAdapter, and call registerForCookieChangeNotifications.
(WebCore::finishObservingCookieChanges): Call unregisterForCookieChangeNotifications.

Add new file.
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj: Set role on files we need to include in WebKit to private.

2011-03-02 Sergey Glazunov <serg.glazunov@gmail.com>

Reviewed by Dimitri Glazkov.
@@ -25449,6 +25449,10 @@
RelativePath="..\platform\CookieJar.h"
>
</File>
<File
RelativePath="..\platform\CookiesStrategy.h"
>
</File>
<File
RelativePath="..\platform\CrossThreadCopier.cpp"
>
@@ -805,8 +805,10 @@
3390CA550FFC157B00921962 /* NotificationCenter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3390CA510FFC157B00921962 /* NotificationCenter.cpp */; };
3390CA560FFC157B00921962 /* NotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3390CA520FFC157B00921962 /* NotificationCenter.h */; };
3390CA580FFC157B00921962 /* NotificationContents.h in Headers */ = {isa = PBXBuildFile; fileRef = 3390CA540FFC157B00921962 /* NotificationContents.h */; };
339B5B63131DAA3200F48D02 /* CookiesStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 339B5B62131DAA3200F48D02 /* CookiesStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
33C0CCD4112C5E6200CE057D /* SecureTextInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33C0CCD2112C5E6200CE057D /* SecureTextInput.cpp */; };
33C0CCD5112C5E6200CE057D /* SecureTextInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0CCD3112C5E6200CE057D /* SecureTextInput.h */; };
33D0212D131DB37B004091A8 /* CookieStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = E13F01EA1270E10D00DFBA71 /* CookieStorage.h */; settings = {ATTRIBUTES = (Private, ); }; };
371A67CB11C6C7DB00047B8B /* HyphenationCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 371A67CA11C6C7DB00047B8B /* HyphenationCF.cpp */; };
371F4F400D25B9AF00ECE0D5 /* FontData.h in Headers */ = {isa = PBXBuildFile; fileRef = 371F4F3E0D25B9AF00ECE0D5 /* FontData.h */; settings = {ATTRIBUTES = (Private, ); }; };
371F4F410D25B9AF00ECE0D5 /* FontData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 371F4F3F0D25B9AF00ECE0D5 /* FontData.cpp */; };
@@ -7171,6 +7173,7 @@
3390CA520FFC157B00921962 /* NotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NotificationCenter.h; path = notifications/NotificationCenter.h; sourceTree = "<group>"; };
3390CA530FFC157B00921962 /* NotificationCenter.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = NotificationCenter.idl; path = notifications/NotificationCenter.idl; sourceTree = "<group>"; };
3390CA540FFC157B00921962 /* NotificationContents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NotificationContents.h; path = notifications/NotificationContents.h; sourceTree = "<group>"; };
339B5B62131DAA3200F48D02 /* CookiesStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookiesStrategy.h; sourceTree = "<group>"; };
33C0CCD2112C5E6200CE057D /* SecureTextInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecureTextInput.cpp; sourceTree = "<group>"; };
33C0CCD3112C5E6200CE057D /* SecureTextInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecureTextInput.h; sourceTree = "<group>"; };
371A67CA11C6C7DB00047B8B /* HyphenationCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HyphenationCF.cpp; sourceTree = "<group>"; };
@@ -18284,6 +18287,7 @@
06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */,
D8B6152E1032495100C8554A /* Cookie.h */,
9352088109BD45E900F2038D /* CookieJar.h */,
339B5B62131DAA3200F48D02 /* CookiesStrategy.h */,
2E4346560F546A9900B0F1BA /* CrossThreadCopier.cpp */,
2E4346570F546A9900B0F1BA /* CrossThreadCopier.h */,
E11AF15011B9A1A300805103 /* Cursor.cpp */,
@@ -22492,6 +22496,8 @@
93F199ED08245E59001E9ABC /* XSLTProcessor.h in Headers */,
E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
339B5B63131DAA3200F48D02 /* CookiesStrategy.h in Headers */,
33D0212D131DB37B004091A8 /* CookieStorage.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CookiesStrategy_h
#define CookiesStrategy_h

#if USE(PLATFORM_STRATEGIES)

namespace WebCore {

class CookiesStrategy {
public:
virtual void notifyCookiesChanged() = 0;

protected:
virtual ~CookiesStrategy() { }
};

} // namespace WebCore

#endif // USE(PLATFORM_STRATEGIES)

#endif // CookiesStrategy_h
@@ -30,12 +30,20 @@

namespace WebCore {

class CookiesStrategy;
class PluginStrategy;
class LocalizationStrategy;
class VisitedLinkStrategy;

class PlatformStrategies {
public:
CookiesStrategy* cookiesStrategy()
{
if (!m_cookiesStrategy)
m_cookiesStrategy = createCookiesStrategy();
return m_cookiesStrategy;
}

PluginStrategy* pluginStrategy()
{
if (!m_pluginStrategy)
@@ -59,7 +67,8 @@ class PlatformStrategies {

protected:
PlatformStrategies()
: m_pluginStrategy(0)
: m_cookiesStrategy(0)
, m_pluginStrategy(0)
, m_localizationStrategy(0)
, m_visitedLinkStrategy(0)
{
@@ -70,10 +79,12 @@ class PlatformStrategies {
}

private:
virtual CookiesStrategy* createCookiesStrategy() = 0;
virtual PluginStrategy* createPluginStrategy() = 0;
virtual LocalizationStrategy* createLocalizationStrategy() = 0;
virtual VisitedLinkStrategy* createVisitedLinkStrategy() = 0;

CookiesStrategy* m_cookiesStrategy;
PluginStrategy* m_pluginStrategy;
LocalizationStrategy* m_localizationStrategy;
VisitedLinkStrategy* m_visitedLinkStrategy;
@@ -29,6 +29,8 @@
namespace WebCore {

void setCookieStoragePrivateBrowsingEnabled(bool);
void startObservingCookieChanges();
void stopObservingCookieChanges();

}

@@ -28,11 +28,17 @@

#if USE(CFNETWORK)

#include "LoaderRunLoopCF.h"
#include <CFNetwork/CFHTTPCookiesPriv.h>
#include <WebKitSystemInterface/WebKitSystemInterface.h>
#include <wtf/MainThread.h>
#include <wtf/RetainPtr.h>

#if USE(PLATFORM_STRATEGIES)
#include "CookiesStrategy.h"
#include "PlatformStrategies.h"
#endif

namespace WebCore {

static CFHTTPCookieStorageRef s_cookieStorage;
@@ -70,6 +76,59 @@ void setCookieStoragePrivateBrowsingEnabled(bool enabled)
s_cookieStorage = 0;
}

static void notifyCookiesChangedOnMainThread(void* context)
{
ASSERT(isMainThread());

#if USE(PLATFORM_STRATEGIES)
platformStrategies()->cookiesStrategy()->notifyCookiesChanged();
#endif
}

static void notifyCookiesChanged(CFHTTPCookieStorageRef inStorage, void *context)
{
callOnMainThread(notifyCookiesChangedOnMainThread, 0);
}

static inline CFRunLoopRef cookieStorageObserverRunLoop()
{
// We're using the loader run loop because we need a CFRunLoop to
// call the CFNetwork cookie storage APIs with. Re-using the loader
// run loop is less overhead than starting a new thread to just listen
// for changes in cookies.

// FIXME: The loaderRunLoop function name should be a little more generic.
return loaderRunLoop();
}

void beginObservingCookieChanges()
{
ASSERT(isMainThread());

CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
ASSERT(runLoop);

CFHTTPCookieStorageRef cookieStorage = currentCookieStorage();
ASSERT(cookieStorage);

CFHTTPCookieStorageScheduleWithRunLoop(cookieStorage, runLoop, kCFRunLoopCommonModes);
CFHTTPCookieStorageAddObserver(cookieStorage, runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
}

void finishObservingCookieChanges()
{
ASSERT(isMainThread());

CFRunLoopRef runLoop = cookieStorageObserverRunLoop();
ASSERT(runLoop);

CFHTTPCookieStorageRef cookieStorage = currentCookieStorage();
ASSERT(cookieStorage);

CFHTTPCookieStorageRemoveObserver(cookieStorage, runLoop, kCFRunLoopDefaultMode, notifyCookiesChanged, 0);
CFHTTPCookieStorageUnscheduleFromRunLoop(cookieStorage, runLoop, kCFRunLoopCommonModes);
}

} // namespace WebCore

#endif // USE(CFNETWORK)
@@ -27,6 +27,50 @@
#include "CookieStorage.h"

#import "WebCoreSystemInterface.h"
#import <wtf/RetainPtr.h>
#import <wtf/UnusedParam.h>

#if USE(PLATFORM_STRATEGIES)
#include "CookiesStrategy.h"
#include "PlatformStrategies.h"
#endif

using namespace WebCore;

@interface CookieStorageObjCAdapter : NSObject
-(void)notifyCookiesChangedOnMainThread;
-(void)cookiesChangedNotificationHandler:(NSNotification *)notification;
-(void)startListeningForCookieChangeNotifications;
-(void)stopListeningForCookieChangeNotifications;
@end

@implementation CookieStorageObjCAdapter

-(void)notifyCookiesChangedOnMainThread
{
#if USE(PLATFORM_STRATEGIES)
platformStrategies()->cookiesStrategy()->notifyCookiesChanged();
#endif
}

-(void)cookiesChangedNotificationHandler:(NSNotification *)notification
{
UNUSED_PARAM(notification);

[self performSelectorOnMainThread:@selector(notifyCookiesChangedOnMainThread) withObject:nil waitUntilDone:FALSE];
}

-(void)startListeningForCookieChangeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cookiesChangedNotificationHandler:) name:NSHTTPCookieManagerCookiesChangedNotification object:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
}

-(void)stopListeningForCookieChangeNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSHTTPCookieManagerCookiesChangedNotification object:nil];
}

@end

namespace WebCore {

@@ -35,4 +79,19 @@ void setCookieStoragePrivateBrowsingEnabled(bool enabled)
wkSetCookieStoragePrivateBrowsingEnabled(enabled);
}

static CookieStorageObjCAdapter *cookieStorageAdapter;

void startObservingCookieChanges()
{
if (!cookieStorageAdapter)
cookieStorageAdapter = [[CookieStorageObjCAdapter alloc] init];
[cookieStorageAdapter startListeningForCookieChangeNotifications];
}

void stopObservingCookieChanges()
{
ASSERT(cookieStorageAdapter);
[cookieStorageAdapter stopListeningForCookieChangeNotifications];
}

}
@@ -1,3 +1,18 @@
2011-03-01 Brian Weinstein <bweinstein@apple.com>

Reviewed by Adam Roben.

Part of WebKit2: Need a way to send notifications to client when cookies change
https://bugs.webkit.org/show_bug.cgi?id=55427
<rdar://problem/9056027>

Add stubs for CookiesStrategy on Mac WebKit1.

* WebCoreSupport/WebPlatformStrategies.h:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::createCookiesStrategy):
(WebPlatformStrategies::notifyCookiesChanged):

2011-03-01 Philippe Normand <pnormand@igalia.com>

Reviewed by Eric Carlson.
@@ -26,23 +26,28 @@
#ifndef WebPlatformStrategies_h
#define WebPlatformStrategies_h

#include <WebCore/CookiesStrategy.h>
#include <WebCore/PlatformStrategies.h>
#include <WebCore/PluginStrategy.h>
#include <WebCore/LocalizationStrategy.h>
#include <WebCore/VisitedLinkStrategy.h>

class WebPlatformStrategies : public WebCore::PlatformStrategies, private WebCore::PluginStrategy, private WebCore::LocalizationStrategy, private WebCore::VisitedLinkStrategy {
class WebPlatformStrategies : public WebCore::PlatformStrategies, private WebCore::CookiesStrategy, private WebCore::PluginStrategy, private WebCore::LocalizationStrategy, private WebCore::VisitedLinkStrategy {
public:
static void initialize();

private:
WebPlatformStrategies();

// WebCore::PlatformStrategies
virtual WebCore::CookiesStrategy* createCookiesStrategy();
virtual WebCore::PluginStrategy* createPluginStrategy();
virtual WebCore::LocalizationStrategy* createLocalizationStrategy();
virtual WebCore::VisitedLinkStrategy* createVisitedLinkStrategy();

// WebCore::CookiesStrategy
virtual void notifyCookiesChanged();

// WebCore::PluginStrategy
virtual void refreshPlugins();
virtual void getPluginInfo(const WebCore::Page*, Vector<WebCore::PluginInfo>&);

0 comments on commit 9d675cd

Please sign in to comment.