Diff
Modified: trunk/Source/WebCore/ChangeLog (219566 => 219567)
--- trunk/Source/WebCore/ChangeLog 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/ChangeLog 2017-07-17 19:10:06 UTC (rev 219567)
@@ -1,3 +1,46 @@
+2017-07-17 Brady Eidson <beid...@apple.com>
+
+ WKHTTPCookieStore observing only works on the default cookie store.
+ <rdar://problem/33330724> and https://bugs.webkit.org/show_bug.cgi?id=174580
+
+ Reviewed by Sam Weinig.
+
+ Covered by new API tests.
+
+ startObservingCookieChanges and stopObservingCookieChanges are passed a NetworkStorageSession to observe.
+ On Mac/iOS, the passed-in storage session was ignored and the shared cookie storage was assumed.
+ Let's fix that.
+
+ Also, since using NSNotification based observing only works reliably for the shared cookie storage,
+ switch to direct CFHTTPCookieStorageRef observing.
+
+ * WebCore.xcodeproj/project.pbxproj:
+
+ * platform/network/NetworkStorageSession.h:
+
+ * platform/network/cocoa/CookieStorageObserver.h: Added.
+ * platform/network/cocoa/CookieStorageObserver.mm: Added.
+ (WebCore::cookiesChanged):
+ (WebCore::CookieStorageObserver::create):
+ (WebCore::CookieStorageObserver::CookieStorageObserver):
+ (WebCore::CookieStorageObserver::~CookieStorageObserver):
+ (WebCore::CookieStorageObserver::startObserving):
+ (WebCore::CookieStorageObserver::stopObserving):
+ (WebCore::CookieStorageObserver::cookiesDidChange):
+
+ * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+ (WebCore::NetworkStorageSession::cookieStorageObserver):
+
+ * platform/network/mac/CookieStorageMac.mm:
+ (WebCore::startObservingCookieChanges):
+ (WebCore::stopObservingCookieChanges):
+ (-[WebCookieStorageObjCAdapter notifyCookiesChangedOnMainThread]): Deleted.
+ (-[WebCookieStorageObjCAdapter cookiesChangedNotificationHandler:]): Deleted.
+ (-[WebCookieStorageObjCAdapter startListeningForCookieChangeNotificationsWithCallback:]): Deleted.
+ (-[WebCookieStorageObjCAdapter stopListeningForCookieChangeNotifications]): Deleted.
+
+ * platform/spi/cf/CFNetworkSPI.h:
+
2017-07-17 Sam Weinig <s...@webkit.org>
[WebIDL] Rename JSCSSValueCustom.cpp to JSDeprecatedCSSOMValueCustom.cpp to match the underlying class
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (219566 => 219567)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-07-17 19:10:06 UTC (rev 219567)
@@ -2204,6 +2204,8 @@
511EF2CB17F0FD3500E4FA16 /* JSIDBVersionChangeEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 269239911505E1AA009E57FC /* JSIDBVersionChangeEvent.cpp */; };
511EF2D117F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511EF2CE17F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp */; };
511F7D441EB1C39100E47B83 /* SessionID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511F7D431EB1C38900E47B83 /* SessionID.cpp */; };
+ 5120BBAE1F1CE8CE00EFEBF1 /* CookieStorageObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5120BBAC1F1CE77000EFEBF1 /* CookieStorageObserver.mm */; };
+ 5120BBAF1F1CECE700EFEBF1 /* CookieStorageObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 5120BBAD1F1CE77000EFEBF1 /* CookieStorageObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
5126E6BB0A2E3B12005C29FA /* IconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */; };
5126E6BC0A2E3B12005C29FA /* IconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5126E6BA0A2E3B12005C29FA /* IconDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
512BDB4A1C456FF5006494DF /* SQLiteIDBBackingStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 512BDB481C456FAB006494DF /* SQLiteIDBBackingStore.cpp */; };
@@ -9935,6 +9937,8 @@
511EF2CE17F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBObjectStoreCustom.cpp; sourceTree = "<group>"; };
511F7D431EB1C38900E47B83 /* SessionID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionID.cpp; sourceTree = "<group>"; };
511FAEA91BDC989A00B4AFE4 /* ThreadSafeDataBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadSafeDataBuffer.h; sourceTree = "<group>"; };
+ 5120BBAC1F1CE77000EFEBF1 /* CookieStorageObserver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieStorageObserver.mm; sourceTree = "<group>"; };
+ 5120BBAD1F1CE77000EFEBF1 /* CookieStorageObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookieStorageObserver.h; sourceTree = "<group>"; };
5123AF161890A4CA0031CDC9 /* IDBKeyRangeData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBKeyRangeData.cpp; sourceTree = "<group>"; };
5123AF171890A4CA0031CDC9 /* IDBKeyRangeData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBKeyRangeData.h; sourceTree = "<group>"; };
5123AF1C18918AE40031CDC9 /* IDBGetResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBGetResult.h; sourceTree = "<group>"; };
@@ -19823,6 +19827,8 @@
isa = PBXGroup;
children = (
51D1248C1E736456002B2820 /* CookieCocoa.mm */,
+ 5120BBAC1F1CE77000EFEBF1 /* CookieStorageObserver.mm */,
+ 5120BBAD1F1CE77000EFEBF1 /* CookieStorageObserver.h */,
3792917C1987678F00F4B661 /* CredentialCocoa.h */,
3792917B1987678F00F4B661 /* CredentialCocoa.mm */,
5C9B860B1C21E3C600110F36 /* NetworkLoadMetrics.mm */,
@@ -28493,6 +28499,7 @@
1A762C760A074F2600989F5B /* JSXPathExpression.h in Headers */,
1A762C780A074F2600989F5B /* JSXPathNSResolver.h in Headers */,
1A762C7A0A074F2600989F5B /* JSXPathResult.h in Headers */,
+ 5120BBAF1F1CECE700EFEBF1 /* CookieStorageObserver.h in Headers */,
BCEFE1EB0DCA5F6400739219 /* JSXSLTProcessor.h in Headers */,
85031B440A44EFC700F992E0 /* KeyboardEvent.h in Headers */,
1AE00D59182DAC8D00087DD7 /* KeyedCoding.h in Headers */,
@@ -33677,6 +33684,7 @@
078E091317D14CEE00420AA1 /* UserMediaRequest.cpp in Sources */,
7C3B79711908757B00B47A2D /* UserMessageHandler.cpp in Sources */,
7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */,
+ 5120BBAE1F1CE8CE00EFEBF1 /* CookieStorageObserver.mm in Sources */,
7C73FB07191EF417007DE061 /* UserMessageHandlersNamespace.cpp in Sources */,
BCDF317B11F8D683003C5BF8 /* UserTypingGestureIndicator.cpp in Sources */,
55AF14E51EAAC59B0026EEAA /* UTIRegistry.cpp in Sources */,
Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (219566 => 219567)
--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h 2017-07-17 19:10:06 UTC (rev 219567)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -46,6 +46,10 @@
#include <objc/objc.h>
#endif
+#if PLATFORM(COCOA)
+#include "CookieStorageObserver.h"
+#endif
+
namespace WebCore {
class NetworkingContext;
@@ -139,6 +143,14 @@
bool shouldPartitionCookies(const String& topPrivatelyControlledDomain) const;
HashSet<String> m_topPrivatelyControlledDomainsForCookiePartitioning;
#endif
+
+#if PLATFORM(COCOA)
+public:
+ CookieStorageObserver& cookieStorageObserver() const;
+
+private:
+ mutable RefPtr<CookieStorageObserver> m_cookieStorageObserver;
+#endif
};
}
Added: trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h (0 => 219567)
--- trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h (rev 0)
+++ trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.h 2017-07-17 19:10:06 UTC (rev 219567)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#include "CFNetworkSPI.h"
+#include <wtf/Function.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class CookieStorageObserver : public ThreadSafeRefCounted<CookieStorageObserver> {
+public:
+ static RefPtr<CookieStorageObserver> create(CFHTTPCookieStorageRef);
+ CookieStorageObserver(CFHTTPCookieStorageRef);
+ ~CookieStorageObserver();
+
+ void startObserving(WTF::Function<void()>&& callback);
+ void stopObserving();
+
+ void cookiesDidChange();
+
+private:
+ RetainPtr<CFHTTPCookieStorageRef> m_cookieStorage;
+ WTF::Function<void()> m_cookieChangeCallback;
+};
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm (0 => 219567)
--- trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm (rev 0)
+++ trunk/Source/WebCore/platform/network/cocoa/CookieStorageObserver.mm 2017-07-17 19:10:06 UTC (rev 219567)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#import "config.h"
+#import "CookieStorageObserver.h"
+
+#import "NSURLConnectionSPI.h"
+#import <wtf/MainThread.h>
+
+namespace WebCore {
+
+static void cookiesChanged(CFHTTPCookieStorageRef, void* context)
+{
+ ASSERT(!isMainThread());
+ static_cast<CookieStorageObserver*>(context)->cookiesDidChange();
+}
+
+RefPtr<CookieStorageObserver> CookieStorageObserver::create(CFHTTPCookieStorageRef cookieStorage)
+{
+ return adoptRef(new CookieStorageObserver(cookieStorage));
+}
+
+CookieStorageObserver::CookieStorageObserver(CFHTTPCookieStorageRef cookieStorage)
+ : m_cookieStorage(cookieStorage)
+{
+ ASSERT(isMainThread());
+ ASSERT(m_cookieStorage);
+}
+
+CookieStorageObserver::~CookieStorageObserver()
+{
+ ASSERT(isMainThread());
+
+ if (m_cookieChangeCallback)
+ stopObserving();
+}
+
+void CookieStorageObserver::startObserving(WTF::Function<void()>&& callback)
+{
+ ASSERT(isMainThread());
+ ASSERT(!m_cookieChangeCallback);
+ m_cookieChangeCallback = WTFMove(callback);
+
+ CFHTTPCookieStorageAddObserver(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes, cookiesChanged, this);
+ CFHTTPCookieStorageScheduleWithRunLoop(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes);
+}
+
+void CookieStorageObserver::stopObserving()
+{
+ ASSERT(isMainThread());
+ ASSERT(m_cookieChangeCallback);
+ m_cookieChangeCallback = nullptr;
+
+ CFHTTPCookieStorageRemoveObserver(m_cookieStorage.get(), [NSURLConnection resourceLoaderRunLoop], kCFRunLoopCommonModes, cookiesChanged, this);
+}
+
+void CookieStorageObserver::cookiesDidChange()
+{
+ callOnMainThread([protectedThis = makeRef(*this), this] {
+ if (m_cookieChangeCallback)
+ m_cookieChangeCallback();
+ });
+}
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (219566 => 219567)
--- trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm 2017-07-17 19:10:06 UTC (rev 219567)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Apple, Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
#import "CFNetworkSPI.h"
#import "Cookie.h"
+#import "CookieStorageObserver.h"
#import "URL.h"
#import <wtf/BlockObjCExceptions.h>
@@ -90,4 +91,12 @@
return [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:cfCookieStorage.get()] autorelease];
}
+CookieStorageObserver& NetworkStorageSession::cookieStorageObserver() const
+{
+ if (!m_cookieStorageObserver)
+ m_cookieStorageObserver = CookieStorageObserver::create([nsCookieStorage() _cookieStorage]);
+
+ return *m_cookieStorageObserver;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/network/mac/CookieStorageMac.mm (219566 => 219567)
--- trunk/Source/WebCore/platform/network/mac/CookieStorageMac.mm 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/platform/network/mac/CookieStorageMac.mm 2017-07-17 19:10:06 UTC (rev 219567)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,67 +26,19 @@
#import "config.h"
#import "CookieStorage.h"
-#import "WebCoreSystemInterface.h"
-#import <wtf/Function.h>
+#import "CookieStorageObserver.h"
+#import "NetworkStorageSession.h"
-using namespace WebCore;
-
-@interface WebCookieStorageObjCAdapter : NSObject {
- WTF::Function<void ()> m_cookieChangeCallback;
-}
--(void)notifyCookiesChangedOnMainThread;
--(void)cookiesChangedNotificationHandler:(NSNotification *)notification;
--(void)startListeningForCookieChangeNotificationsWithCallback:(WTF::Function<void ()>&&)callback;
--(void)stopListeningForCookieChangeNotifications;
-@end
-
-@implementation WebCookieStorageObjCAdapter
-
--(void)notifyCookiesChangedOnMainThread
-{
- m_cookieChangeCallback();
-}
-
--(void)cookiesChangedNotificationHandler:(NSNotification *)notification
-{
- UNUSED_PARAM(notification);
-
- [self performSelectorOnMainThread:@selector(notifyCookiesChangedOnMainThread) withObject:nil waitUntilDone:FALSE];
-}
-
--(void)startListeningForCookieChangeNotificationsWithCallback:(WTF::Function<void ()>&&)callback
-{
- ASSERT(!m_cookieChangeCallback);
- m_cookieChangeCallback = WTFMove(callback);
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cookiesChangedNotificationHandler:) name:NSHTTPCookieManagerCookiesChangedNotification object:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
-}
-
--(void)stopListeningForCookieChangeNotifications
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self name:NSHTTPCookieManagerCookiesChangedNotification object:nil];
- m_cookieChangeCallback = nullptr;
-}
-
-@end
-
namespace WebCore {
-static WebCookieStorageObjCAdapter *cookieStorageAdapter;
-
-void startObservingCookieChanges(const NetworkStorageSession&, WTF::Function<void ()>&& callback)
+void startObservingCookieChanges(const NetworkStorageSession& storageSession, WTF::Function<void()>&& callback)
{
- if (!cookieStorageAdapter)
- cookieStorageAdapter = [[WebCookieStorageObjCAdapter alloc] init];
- [cookieStorageAdapter startListeningForCookieChangeNotificationsWithCallback:WTFMove(callback)];
+ storageSession.cookieStorageObserver().startObserving(WTFMove(callback));
}
-void stopObservingCookieChanges(const NetworkStorageSession&)
+void stopObservingCookieChanges(const NetworkStorageSession& storageSession)
{
- // cookieStorageAdapter can be nil here, if the WebProcess crashed and was restarted between
- // when startObservingCookieChanges was called, and stopObservingCookieChanges is currently being called.
- if (!cookieStorageAdapter)
- return;
- [cookieStorageAdapter stopListeningForCookieChangeNotifications];
+ storageSession.cookieStorageObserver().stopObserving();
}
}
Modified: trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h (219566 => 219567)
--- trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h 2017-07-17 19:10:06 UTC (rev 219567)
@@ -200,6 +200,10 @@
void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
+typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
+void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
+void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
+
void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
Modified: trunk/Tools/ChangeLog (219566 => 219567)
--- trunk/Tools/ChangeLog 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Tools/ChangeLog 2017-07-17 19:10:06 UTC (rev 219567)
@@ -1,3 +1,15 @@
+2017-07-17 Brady Eidson <beid...@apple.com>
+
+ WKHTTPCookieStore observing only works on the default cookie store.
+ <rdar://problem/33330724> and https://bugs.webkit.org/show_bug.cgi?id=174580
+
+ Reviewed by Sam Weinig.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm:
+ (runTestWithWebsiteDataStore): Refactor the cookie observing test out so it can be
+ called for the default store, a non-persistent store, and a custom store.
+ (TEST):
+
2017-07-16 Sam Weinig <s...@webkit.org>
[Scripts] Fix missing variable warnings from svn-create-patch when there are untracked files
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm (219566 => 219567)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm 2017-07-17 18:30:05 UTC (rev 219566)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm 2017-07-17 19:10:06 UTC (rev 219567)
@@ -30,13 +30,14 @@
#import <WebKit/WKFoundation.h>
#import <WebKit/WKHTTPCookieStore.h>
#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
#import <wtf/RetainPtr.h>
#if WK_API_ENABLED
static bool gotFlag;
-uint64_t observerCallbacks;
-RetainPtr<WKHTTPCookieStore> globalCookieStore;
+static uint64_t observerCallbacks;
+static RetainPtr<WKHTTPCookieStore> globalCookieStore;
@interface CookieObserver : NSObject<WKHTTPCookieStoreObserver>
- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore;
@@ -52,12 +53,18 @@
@end
-TEST(WebKit2, WKHTTPCookieStore)
+static void runTestWithWebsiteDataStore(WKWebsiteDataStore* dataStore)
{
- auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+ observerCallbacks = 0;
+
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ configuration.get().websiteDataStore = dataStore;
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
[webView loadHTMLString:@"Oh hello" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+ [webView _test_waitForDidFinishNavigation];
- [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
+ [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
gotFlag = true;
}];
@@ -64,7 +71,7 @@
TestWebKitAPI::Util::run(&gotFlag);
gotFlag = false;
- globalCookieStore = [WKWebsiteDataStore defaultDataStore].httpCookieStore;
+ globalCookieStore = dataStore.httpCookieStore;
RetainPtr<CookieObserver> observer1 = adoptNS([[CookieObserver alloc] init]);
RetainPtr<CookieObserver> observer2 = adoptNS([[CookieObserver alloc] init]);
[globalCookieStore addObserver:observer1.get()];
@@ -175,8 +182,40 @@
[globalCookieStore removeObserver:observer2.get()];
}
-static RetainPtr<WKHTTPCookieStore> staticCookieStore;
+TEST(WebKit2, WKHTTPCookieStore)
+{
+ runTestWithWebsiteDataStore([WKWebsiteDataStore defaultDataStore]);
+}
+TEST(WebKit2, WKHTTPCookieStoreNonPersistent)
+{
+ RetainPtr<WKWebsiteDataStore> nonPersistentDataStore;
+ @autoreleasepool {
+ nonPersistentDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+ }
+
+ runTestWithWebsiteDataStore(nonPersistentDataStore.get());
+}
+
+TEST(WebKit2, WKHTTPCookieStoreCustom)
+{
+ NSURL *cookieStorageFile = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/CookieStorage/Cookie.File" stringByExpandingTildeInPath] isDirectory:NO];
+ NSURL *idbPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/IndexedDB/" stringByExpandingTildeInPath] isDirectory:YES];
+
+ [[NSFileManager defaultManager] removeItemAtURL:cookieStorageFile error:nil];
+ [[NSFileManager defaultManager] removeItemAtURL:idbPath error:nil];
+
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:cookieStorageFile.path]);
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:idbPath.path]);
+
+ auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+ websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbPath;
+ websiteDataStoreConfiguration.get()._cookieStorageFile = cookieStorageFile;
+
+ auto customDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
+ runTestWithWebsiteDataStore(customDataStore.get());
+}
+
TEST(WebKit2, CookieObserverCrash)
{
RetainPtr<WKWebsiteDataStore> nonPersistentDataStore;
@@ -192,11 +231,11 @@
[webView loadHTMLString:@"Oh hello" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
[webView _test_waitForDidFinishNavigation];
- staticCookieStore = nonPersistentDataStore.get().httpCookieStore;
+ globalCookieStore = nonPersistentDataStore.get().httpCookieStore;
RetainPtr<CookieObserver> observer = adoptNS([[CookieObserver alloc] init]);
- [staticCookieStore addObserver:observer.get()];
+ [globalCookieStore addObserver:observer.get()];
- [staticCookieStore getAllCookies:[](NSArray<NSHTTPCookie *> *) {
+ [globalCookieStore getAllCookies:[](NSArray<NSHTTPCookie *> *) {
gotFlag = true;
}];