IndexedDB: closeAndDeleteDatabasesForOrigins should remove all databases for those...
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jul 2018 18:35:50 +0000 (18:35 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jul 2018 18:35:50 +0000 (18:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187631
<rdar://problem/42164227>

Reviewed by Brady Eidson.

Source/WebCore:

When asked to delete database for an origin, we deleted the databases whose mainFrameOrigin
is that origin. Given that the origin may create IndexedDB from subframes, we should delete
databases whose openingOrigin is that origin too.

Covered by modified API test: WebKit.WebsiteDataStoreCustomPaths.

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesForOrigins):

Source/WebKit:

We need to return all origins, both openingOrigin and mainFrameOrigin, of IndexedDB so users
could be better aware of which origins are using databases and decide what they want to
remove.

* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::indexedDatabaseOrigins):
* StorageProcess/StorageProcess.h:

Tools:

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

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

index 5a3dd14..98097e7 100644 (file)
@@ -1,3 +1,20 @@
+2018-07-16  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: closeAndDeleteDatabasesForOrigins should remove all databases for those origins
+        https://bugs.webkit.org/show_bug.cgi?id=187631
+        <rdar://problem/42164227>
+
+        Reviewed by Brady Eidson.
+
+        When asked to delete database for an origin, we deleted the databases whose mainFrameOrigin 
+        is that origin. Given that the origin may create IndexedDB from subframes, we should delete 
+        databases whose openingOrigin is that origin too.
+
+        Covered by modified API test: WebKit.WebsiteDataStoreCustomPaths. 
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesForOrigins):
+
 2018-07-16  Simon Fraser  <simon.fraser@apple.com>
 
         Shrink some font-related classes and enums
index b8e931b..1b99452 100644 (file)
@@ -626,6 +626,11 @@ void IDBServer::performCloseAndDeleteDatabasesForOrigins(const Vector<SecurityOr
         for (const auto& origin : origins) {
             String originPath = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, origin.databaseIdentifier());
             removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
+
+            for (const auto& topOriginPath : FileSystem::listDirectory(m_databaseDirectoryPath, "*")) {
+                originPath = FileSystem::pathByAppendingComponent(topOriginPath, origin.databaseIdentifier());
+                removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
+            }
         }
     }
 
index ba2571c..8b92130 100644 (file)
@@ -1,3 +1,19 @@
+2018-07-16  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: closeAndDeleteDatabasesForOrigins should remove all databases for those origins
+        https://bugs.webkit.org/show_bug.cgi?id=187631
+        <rdar://problem/42164227>
+
+        Reviewed by Brady Eidson.
+
+        We need to return all origins, both openingOrigin and mainFrameOrigin, of IndexedDB so users
+        could be better aware of which origins are using databases and decide what they want to 
+        remove.
+
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::indexedDatabaseOrigins):
+        * StorageProcess/StorageProcess.h:
+
 2018-07-15  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [SOUP] http/tests/misc/bubble-drag-events.html crashes
index 8f6b887..77e3cc1 100644 (file)
@@ -406,17 +406,22 @@ void StorageProcess::accessToTemporaryFileComplete(const String& path)
         extension->revoke();
 }
 
-Vector<WebCore::SecurityOriginData> StorageProcess::indexedDatabaseOrigins(const String& path)
+HashSet<WebCore::SecurityOriginData> StorageProcess::indexedDatabaseOrigins(const String& path)
 {
     if (path.isEmpty())
         return { };
 
-    Vector<WebCore::SecurityOriginData> securityOrigins;
-    for (auto& originPath : FileSystem::listDirectory(path, "*")) {
-        String databaseIdentifier = FileSystem::pathGetFileName(originPath);
-
+    HashSet<WebCore::SecurityOriginData> securityOrigins;
+    for (auto& topOriginPath : FileSystem::listDirectory(path, "*")) {
+        auto databaseIdentifier = FileSystem::pathGetFileName(topOriginPath);
         if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
-            securityOrigins.append(WTFMove(*securityOrigin));
+            securityOrigins.add(WTFMove(*securityOrigin));
+        
+        for (auto& originPath : FileSystem::listDirectory(topOriginPath, "*")) {
+            databaseIdentifier = FileSystem::pathGetFileName(originPath);
+            if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
+                securityOrigins.add(WTFMove(*securityOrigin));
+        }
     }
 
     return securityOrigins;
index aee5100..5fef46c 100644 (file)
@@ -155,7 +155,7 @@ private:
     bool needsServerToContextConnectionForOrigin(const WebCore::SecurityOriginData&) const;
 #endif
 #if ENABLE(INDEXED_DATABASE)
-    Vector<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
+    HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
 #endif
 
     // For execution on work queue thread only
index 42cc068..914314b 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-16  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: closeAndDeleteDatabasesForOrigins should remove all databases for those origins
+        https://bugs.webkit.org/show_bug.cgi?id=187631
+        <rdar://problem/42164227>
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+        (TEST):
+
 2018-07-15  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GLIB] Add API to evaluate code using a given object to store global symbols
index 527649f..62386f3 100644 (file)
@@ -190,10 +190,31 @@ TEST(WebKit, WebsiteDataStoreCustomPaths)
     [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
     [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
     
+    RetainPtr<NSURL> frameIDBPath2 = [[fileIDBPath URLByAppendingPathComponent:@"https_webkit.org_0"] URLByAppendingPathComponent:@"WebsiteDataStoreCustomPaths"];
+    [[NSFileManager defaultManager] createDirectoryAtURL:frameIDBPath2.get() withIntermediateDirectories:YES attributes:nil error:nil];
+    
+    [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
+
+    [dataStore fetchDataRecordsOfTypes:types.get() completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
+        EXPECT_EQ([records count], (unsigned long)3);
+        for (id record in records) {
+            if ([[record displayName] isEqual: @"apple.com"]) {
+                [dataStore removeDataOfTypes:types.get() forDataRecords:[NSArray arrayWithObject:record] completionHandler:^() {
+                    receivedScriptMessage = true;
+                    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:frameIDBPath.get().path]);
+                }];
+            }
+        }
+    }];
     receivedScriptMessage = false;
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+
     [dataStore removeDataOfTypes:types.get() modifiedSince:[NSDate distantPast] completionHandler:[]() {
         receivedScriptMessage = true;
     }];
+    receivedScriptMessage = false;
     TestWebKitAPI::Util::run(&receivedScriptMessage);
 
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fileIDBPath.get().path]);