Title: [219783] branches/safari-604-branch/Source/WebCore
- Revision
- 219783
- Author
- [email protected]
- Date
- 2017-07-22 23:51:38 -0700 (Sat, 22 Jul 2017)
Log Message
Cherry-pick r219683. rdar://problem/33464463
Modified Paths
Diff
Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (219782 => 219783)
--- branches/safari-604-branch/Source/WebCore/ChangeLog 2017-07-23 06:51:32 UTC (rev 219782)
+++ branches/safari-604-branch/Source/WebCore/ChangeLog 2017-07-23 06:51:38 UTC (rev 219783)
@@ -1,5 +1,42 @@
2017-07-22 Jason Marcell <[email protected]>
+ Cherry-pick r219683. rdar://problem/33464463
+
+ 2017-07-20 Brady Eidson <[email protected]>
+
+ WKHTTPCookieStore API tests fail on High Sierra.
+ <rdar://problem/33410271> and https://bugs.webkit.org/show_bug.cgi?id=174666
+
+ Reviewed by Andy Estes.
+
+ Covered by existing API tests.
+
+ In r219567 I'd moved cookie storage observation off of NSHTTPCookieStorage and NSNotificationCenter
+ to CFHTTPCookieStorage observation callbacks.
+
+ This is because notifications were only sent for the default [NSHTTPCookieStorage sharedHTTPCookieStorage]
+ and not any of the other ones we keep in flight.
+
+ Unfortunately that SPI has been disabled in High Sierra.
+ Fortunately we found a way we can get non-shared NSHTTPCookieStorages to send notifications that works everywhere.
+
+ * platform/network/cocoa/CookieStorageObserver.h:
+ * platform/network/cocoa/CookieStorageObserver.mm:
+ (-[WebCookieObserverAdapter initWithObserver:]):
+ (-[WebCookieObserverAdapter cookiesChangedNotificationHandler:]):
+ (WebCore::CookieStorageObserver::create):
+ (WebCore::CookieStorageObserver::CookieStorageObserver):
+ (WebCore::CookieStorageObserver::~CookieStorageObserver):
+ (WebCore::CookieStorageObserver::startObserving): Use a trick to call some SPI on non-shared NSHTTPCookieStorages
+ to get them to send notifications.
+ (WebCore::CookieStorageObserver::stopObserving):
+ (WebCore::cookiesChanged): Deleted.
+
+ * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+ (WebCore::NetworkStorageSession::cookieStorageObserver):
+
+2017-07-22 Jason Marcell <[email protected]>
+
Cherry-pick r219668. rdar://problem/33462676
2017-07-19 Simon Fraser <[email protected]>
Modified: branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h (219782 => 219783)
--- branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h 2017-07-23 06:51:32 UTC (rev 219782)
+++ branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h 2017-07-23 06:51:38 UTC (rev 219783)
@@ -30,12 +30,15 @@
#include <wtf/RetainPtr.h>
#include <wtf/ThreadSafeRefCounted.h>
+OBJC_CLASS NSHTTPCookieStorage;
+OBJC_CLASS WebCookieObserverAdapter;
+
namespace WebCore {
class CookieStorageObserver : public ThreadSafeRefCounted<CookieStorageObserver> {
public:
- static RefPtr<CookieStorageObserver> create(CFHTTPCookieStorageRef);
- CookieStorageObserver(CFHTTPCookieStorageRef);
+ static RefPtr<CookieStorageObserver> create(NSHTTPCookieStorage *);
+ CookieStorageObserver(NSHTTPCookieStorage *);
~CookieStorageObserver();
void startObserving(WTF::Function<void()>&& callback);
@@ -44,7 +47,9 @@
void cookiesDidChange();
private:
- RetainPtr<CFHTTPCookieStorageRef> m_cookieStorage;
+ RetainPtr<NSHTTPCookieStorage> m_cookieStorage;
+ bool m_hasRegisteredInternalsForNotifications { false };
+ RetainPtr<WebCookieObserverAdapter> m_observerAdapter;
WTF::Function<void()> m_cookieChangeCallback;
};
Modified: branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm (219782 => 219783)
--- branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm 2017-07-23 06:51:32 UTC (rev 219782)
+++ branches/safari-604-branch/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm 2017-07-23 06:51:38 UTC (rev 219783)
@@ -29,20 +29,52 @@
#import "NSURLConnectionSPI.h"
#import <wtf/MainThread.h>
-namespace WebCore {
+@interface WebNSHTTPCookieStorageInternal : NSObject {
+@public
+ id internal;
+}
+@end
-static void cookiesChanged(CFHTTPCookieStorageRef, void* context)
+@implementation WebNSHTTPCookieStorageInternal
+@end
+
+@interface WebCookieObserverAdapter : NSObject {
+ WebCore::CookieStorageObserver* observer;
+}
+- (instancetype)initWithObserver:(WebCore::CookieStorageObserver&)theObserver;
+- (void)cookiesChangedNotificationHandler:(NSNotification *)notification;
+
+@end
+
+@implementation WebCookieObserverAdapter
+
+- (instancetype)initWithObserver:(WebCore::CookieStorageObserver&)theObserver
{
- ASSERT(!isMainThread());
- static_cast<CookieStorageObserver*>(context)->cookiesDidChange();
+ self = [super init];
+ if (!self)
+ return nil;
+
+ observer = &theObserver;
+
+ return self;
}
-RefPtr<CookieStorageObserver> CookieStorageObserver::create(CFHTTPCookieStorageRef cookieStorage)
+- (void)cookiesChangedNotificationHandler:(NSNotification *)notification
{
+ UNUSED_PARAM(notification);
+ observer->cookiesDidChange();
+}
+
+@end
+
+namespace WebCore {
+
+RefPtr<CookieStorageObserver> CookieStorageObserver::create(NSHTTPCookieStorage *cookieStorage)
+{
return adoptRef(new CookieStorageObserver(cookieStorage));
}
-CookieStorageObserver::CookieStorageObserver(CFHTTPCookieStorageRef cookieStorage)
+CookieStorageObserver::CookieStorageObserver(NSHTTPCookieStorage *cookieStorage)
: m_cookieStorage(cookieStorage)
{
ASSERT(isMainThread());
@@ -53,8 +85,10 @@
{
ASSERT(isMainThread());
- if (m_cookieChangeCallback)
+ if (m_cookieChangeCallback) {
+ ASSERT(m_observerAdapter);
stopObserving();
+ }
}
void CookieStorageObserver::startObserving(WTF::Function<void()>&& callback)
@@ -61,10 +95,23 @@
{
ASSERT(isMainThread());
ASSERT(!m_cookieChangeCallback);
+ ASSERT(!m_observerAdapter);
+
m_cookieChangeCallback = WTFMove(callback);
+ m_observerAdapter = adoptNS([[WebCookieObserverAdapter alloc] initWithObserver:*this]);
- CFHTTPCookieStorageAddObserver(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes, cookiesChanged, this);
- CFHTTPCookieStorageScheduleWithRunLoop(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes);
+ if (!m_hasRegisteredInternalsForNotifications) {
+ if (m_cookieStorage.get() != [NSHTTPCookieStorage sharedHTTPCookieStorage]) {
+ auto selector = NSSelectorFromString(@"registerForPostingNotificationsWithContext:");
+ id internalObject = (static_cast<WebNSHTTPCookieStorageInternal *>(m_cookieStorage.get()))->internal;
+ RELEASE_ASSERT([internalObject respondsToSelector:selector]);
+ [internalObject performSelector:selector withObject:m_cookieStorage.get()];
+ }
+
+ m_hasRegisteredInternalsForNotifications = true;
+ }
+
+ [[NSNotificationCenter defaultCenter] addObserver:m_observerAdapter.get() selector:@selector(cookiesChangedNotificationHandler:) name:NSHTTPCookieManagerCookiesChangedNotification object:m_cookieStorage.get()];
}
void CookieStorageObserver::stopObserving()
@@ -71,9 +118,12 @@
{
ASSERT(isMainThread());
ASSERT(m_cookieChangeCallback);
+ ASSERT(m_observerAdapter);
+
+ [[NSNotificationCenter defaultCenter] removeObserver:m_observerAdapter.get() name:NSHTTPCookieManagerCookiesChangedNotification object:nil];
+
m_cookieChangeCallback = nullptr;
-
- CFHTTPCookieStorageRemoveObserver(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes, cookiesChanged, this);
+ m_observerAdapter = nil;
}
void CookieStorageObserver::cookiesDidChange()
Modified: branches/safari-604-branch/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (219782 => 219783)
--- branches/safari-604-branch/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm 2017-07-23 06:51:32 UTC (rev 219782)
+++ branches/safari-604-branch/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm 2017-07-23 06:51:38 UTC (rev 219783)
@@ -94,7 +94,7 @@
CookieStorageObserver& NetworkStorageSession::cookieStorageObserver() const
{
if (!m_cookieStorageObserver)
- m_cookieStorageObserver = CookieStorageObserver::create([nsCookieStorage() _cookieStorage]);
+ m_cookieStorageObserver = CookieStorageObserver::create(nsCookieStorage());
return *m_cookieStorageObserver;
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes