When setting a custom cookie storage location on a WKWebsiteDataStore, cookies aren...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Jul 2017 21:37:54 +0000 (21:37 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Jul 2017 21:37:54 +0000 (21:37 +0000)
<rdar://problem/32410662> and https://bugs.webkit.org/show_bug.cgi?id=174035

Reviewed by Alex Christensen.

Source/WebKit2:

* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _terminateNetworkProcess]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::ensureNetworkProcess): Take an optional WebsiteDataStore. If one is passed in,
  send it to either the existing or new network process.
* UIProcess/WebProcessPool.h:

* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters): Resolve paths first.

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::fetchDataAndApply):
(WebKit::WebsiteDataStore::removeData):

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219052 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebProcessPool.h
Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm

index fe5f9e0..8db18d8 100644 (file)
@@ -1,3 +1,26 @@
+2017-07-01  Brady Eidson  <beidson@apple.com>
+
+        When setting a custom cookie storage location on a WKWebsiteDataStore, cookies aren't actually removed.
+        <rdar://problem/32410662> and https://bugs.webkit.org/show_bug.cgi?id=174035
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _terminateNetworkProcess]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::ensureNetworkProcess): Take an optional WebsiteDataStore. If one is passed in,
+          send it to either the existing or new network process.
+        * UIProcess/WebProcessPool.h:
+        
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters): Resolve paths first.
+
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::fetchDataAndApply):
+        (WebKit::WebsiteDataStore::removeData):
+
 2017-07-01  Ryosuke Niwa  <rniwa@webkit.org>
 
         Frame.h doesn't need to include FrameLoader.h, IntRect.h, and NavigationScheduler.h
index e93a463..a836464 100644 (file)
@@ -389,6 +389,11 @@ static NSDictionary *policiesHashMapToDictionary(const HashMap<String, HashMap<S
     _processPool->terminateDatabaseProcess();
 }
 
+- (void)_terminateNetworkProcess
+{
+    _processPool->terminateNetworkProcess();
+}
+
 - (void)_syncNetworkProcessCookies
 {
     _processPool->syncNetworkProcessCookies();
index 36a6c27..f22b22b 100644 (file)
@@ -73,6 +73,7 @@
 
 // Test only. Should be called only while no web content processes are running.
 - (void)_terminateDatabaseProcess;
+- (void)_terminateNetworkProcess;
 
 // Test only.
 - (size_t)_webProcessCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
index a213441..3c3063d 100644 (file)
@@ -415,10 +415,13 @@ void WebProcessPool::textCheckerStateChanged()
     sendToAllProcesses(Messages::WebProcess::SetTextCheckerState(TextChecker::state()));
 }
 
-NetworkProcessProxy& WebProcessPool::ensureNetworkProcess()
+NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore)
 {
-    if (m_networkProcess)
+    if (m_networkProcess) {
+        if (withWebsiteDataStore)
+            m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
         return *m_networkProcess;
+    }
 
     m_networkProcess = NetworkProcessProxy::create(*this);
 
@@ -481,6 +484,9 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess()
             process->reinstateNetworkProcessAssertionState(*m_networkProcess);
     }
 
+    if (withWebsiteDataStore)
+        m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
+
     return *m_networkProcess;
 }
 
index e611fab..74c3341 100644 (file)
@@ -313,7 +313,7 @@ public:
     void setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary&, double time);
 
     // Network Process Management
-    NetworkProcessProxy& ensureNetworkProcess();
+    NetworkProcessProxy& ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore = nullptr);
     NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); }
     void networkProcessCrashed(NetworkProcessProxy*);
 
index 624a2f1..84b7744 100644 (file)
@@ -51,8 +51,9 @@ static Vector<WebsiteDataStore*>& dataStoresWithStorageManagers()
 
 WebsiteDataStoreParameters WebsiteDataStore::parameters()
 {
-    WebsiteDataStoreParameters parameters;
+    resolveDirectoriesIfNecessary();
 
+    WebsiteDataStoreParameters parameters;
     parameters.sessionID = m_sessionID;
 
     auto cookieFile = resolvedCookieStorageFile();
index f20546b..16845f6 100644 (file)
@@ -328,7 +328,7 @@ void WebsiteDataStore::fetchDataAndApply(OptionSet<WebsiteDataType> dataTypes, O
                 break;
 
             case ProcessAccessType::Launch:
-                processPool->ensureNetworkProcess();
+                processPool->ensureNetworkProcess(this);
                 break;
 
             case ProcessAccessType::None:
@@ -647,7 +647,7 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, std::chr
                 break;
 
             case ProcessAccessType::Launch:
-                processPool->ensureNetworkProcess();
+                processPool->ensureNetworkProcess(this);
                 break;
 
             case ProcessAccessType::None:
@@ -896,7 +896,7 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, const Ve
                 break;
 
             case ProcessAccessType::Launch:
-                processPool->ensureNetworkProcess();
+                processPool->ensureNetworkProcess(this);
                 break;
 
             case ProcessAccessType::None:
index 66fc34b..0284e74 100644 (file)
@@ -1,3 +1,12 @@
+2017-07-01  Brady Eidson  <beidson@apple.com>
+
+        When setting a custom cookie storage location on a WKWebsiteDataStore, cookies aren't actually removed.
+        <rdar://problem/32410662> and https://bugs.webkit.org/show_bug.cgi?id=174035
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsiteDataStoreCustomPaths.mm:
+
 2017-07-01  Dan Bernstein  <mitz@apple.com>
 
         [macOS] Remove code only needed when building for OS X Yosemite
index 127d9f9..69428a2 100644 (file)
@@ -170,6 +170,42 @@ TEST(WebKit2, WebsiteDataStoreCustomPaths)
     TestWebKitAPI::Util::run(&receivedScriptMessage);
 
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fileIDBPath.get().path]);
+
+    // Now, with brand new WKWebsiteDataStores pointing at the same custom cookie storage location,
+    // in newly fired up NetworkProcesses, verify that the fetch and delete APIs work as expected.
+
+    [processPool _terminateNetworkProcess];
+    auto newCustomDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
+
+    [newCustomDataStore fetchDataRecordsOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeCookies, nil] completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
+        EXPECT_GT([records count], (unsigned long)0);
+        receivedScriptMessage = true;
+    }];
+
+    receivedScriptMessage = false;
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+    [processPool _terminateNetworkProcess];
+    newCustomDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
+
+    [newCustomDataStore removeDataOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeCookies, nil] modifiedSince:[NSDate distantPast] completionHandler:^ {
+        receivedScriptMessage = true;
+    }];
+
+    receivedScriptMessage = false;
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+    // This time, reuse the same network process but still do a new websitedatastore, to make sure even an existing network process
+    // gets the new datastore.
+    newCustomDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
+
+    [newCustomDataStore fetchDataRecordsOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeCookies, nil] completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
+        EXPECT_EQ([records count], (unsigned long)0);
+        receivedScriptMessage = true;
+    }];
+
+    receivedScriptMessage = false;
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
 }
 
 #endif