Move IDB storage in private browsing mode to NetworkProcess
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 23:08:27 +0000 (23:08 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 23:08:27 +0000 (23:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195602

Reviewed by Brady Eidson.

Source/WebKit:

Covered by existing IDB tests and added API test.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::createIDBServer):
Make sure that path is empty for private sessions.
This will make IDB use a memory backing store.
* WebProcess/Databases/WebDatabaseProvider.cpp:
(WebKit::WebDatabaseProvider::idbConnectionToServerForSession):
Use NetworkProcess IDB server instead of InProcessIDBServer.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm:
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/WebProcess/Databases/WebDatabaseProvider.cpp
Source/WebKit/WebProcess/Databases/WebDatabaseProvider.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm

index c14d6a1..a0b1b7f 100644 (file)
@@ -1,3 +1,20 @@
+2019-03-14  Youenn Fablet  <youenn@apple.com>
+
+        Move IDB storage in private browsing mode to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=195602
+
+        Reviewed by Brady Eidson.
+
+        Covered by existing IDB tests and added API test.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::createIDBServer):
+        Make sure that path is empty for private sessions.
+        This will make IDB use a memory backing store.
+        * WebProcess/Databases/WebDatabaseProvider.cpp:
+        (WebKit::WebDatabaseProvider::idbConnectionToServerForSession):
+        Use NetworkProcess IDB server instead of InProcessIDBServer.
+
 2019-03-14  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         REGRESSION (r242801): [iOS] preventDefault() on touchstart in a subframe does not prevent focusing the subframe
index 17598ef..48f0f3b 100644 (file)
@@ -2052,10 +2052,11 @@ void NetworkProcess::didSyncAllCookies()
 #if ENABLE(INDEXED_DATABASE)
 Ref<IDBServer::IDBServer> NetworkProcess::createIDBServer(PAL::SessionID sessionID)
 {
-    auto path = m_idbDatabasePaths.get(sessionID);
-    // There should already be a registered path for this PAL::SessionID.
-    // If there's not, then where did this PAL::SessionID come from?
-    ASSERT(!path.isEmpty());
+    String path;
+    if (!sessionID.isEphemeral()) {
+        ASSERT(m_idbDatabasePaths.contains(sessionID));
+        path = m_idbDatabasePaths.get(sessionID);
+    }
 
     auto server = IDBServer::IDBServer::create(sessionID, path, *this, [this, weakThis = makeWeakPtr(this)](PAL::SessionID sessionID, const auto& origin) -> StorageQuotaManager* {
         if (!weakThis)
index 1c9de65..1728dcd 100644 (file)
@@ -69,14 +69,6 @@ WebDatabaseProvider::~WebDatabaseProvider()
 #if ENABLE(INDEXED_DATABASE)
 WebCore::IDBClient::IDBConnectionToServer& WebDatabaseProvider::idbConnectionToServerForSession(const PAL::SessionID& sessionID)
 {
-    if (sessionID.isEphemeral()) {
-        auto result = m_idbEphemeralConnectionMap.add(sessionID.sessionID(), nullptr);
-        if (result.isNewEntry)
-            result.iterator->value = WebCore::InProcessIDBServer::create(sessionID);
-
-        return result.iterator->value->connectionToServer();
-    }
-
     return WebProcess::singleton().ensureNetworkProcessConnection().idbConnectionToServerForSession(sessionID).coreConnectionToServer();
 }
 #endif
index f9daaf1..d4e7f1c 100644 (file)
@@ -44,10 +44,6 @@ public:
 private:
     explicit WebDatabaseProvider(uint64_t identifier);
 
-#if ENABLE(INDEXED_DATABASE)
-    HashMap<uint64_t, RefPtr<WebCore::InProcessIDBServer>> m_idbEphemeralConnectionMap;
-#endif
-
     const uint64_t m_identifier;
 };
 
index 3e61d6e..7de7626 100644 (file)
@@ -1,3 +1,13 @@
+2019-03-14  Youenn Fablet  <youenn@apple.com>
+
+        Move IDB storage in private browsing mode to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=195602
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm:
+        (TEST):
+
 2019-03-14  Aakash Jain  <aakash_jain@apple.com>
 
         [ews-build] Make descriptionDone messages more readable
index 9058a84..f4880a1 100644 (file)
@@ -31,6 +31,7 @@
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserStyleSheet.h>
 #import <wtf/RetainPtr.h>
@@ -92,6 +93,50 @@ TEST(IndexedDB, IndexedDBPersistence)
     EXPECT_WK_STREQ(@"2 TestObjectStore", string3.get());
 }
 
+TEST(IndexedDB, IndexedDBPersistencePrivate)
+{
+    RetainPtr<IndexedDBMessageHandler> handler = adoptNS([[IndexedDBMessageHandler alloc] init]);
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+    auto ephemeralStore = [WKWebsiteDataStore nonPersistentDataStore];
+    configuration.get().websiteDataStore = ephemeralStore;
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBPersistence-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr<NSString> string1 = (NSString *)[lastScriptMessage body];
+
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr<NSString> string2 = (NSString *)[lastScriptMessage body];
+
+    auto webViewPid1 = [webView _webProcessIdentifier];
+    // Ditch this web view (ditching its web process)
+    webView = nil;
+
+    // Make a new web view to finish the test
+    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBPersistence-2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+    receivedScriptMessage = false;
+    RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
+
+    auto webViewPid2 = [webView _webProcessIdentifier];
+    EXPECT_NE(webViewPid1, webViewPid2);
+
+    EXPECT_WK_STREQ(@"UpgradeNeeded", string1.get());
+    EXPECT_WK_STREQ(@"Success", string2.get());
+    EXPECT_WK_STREQ(@"2 TestObjectStore", string3.get());
+}
+
 TEST(IndexedDB, IndexedDBDataRemoval)
 {
     auto websiteDataTypes = adoptNS([[NSSet alloc] initWithArray:@[WKWebsiteDataTypeIndexedDBDatabases]]);