IndexedDB: database file of subframe cannot be removed
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 19:14:32 +0000 (19:14 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jul 2018 19:14:32 +0000 (19:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187564

Reviewed by Youenn Fablet.

Source/WebCore:

For IndexedDB, if openingOrigin is different from mainFrameOrigin, there will be another
layer in the database file path.
IDBServer should delete database files recursively to make sure all files are removed.

Covered by modified test: WebKit.WebsiteDataStoreCustomPaths.

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

Tools:

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

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3 [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

index 2ef7581..7f45388 100644 (file)
@@ -1,3 +1,19 @@
+2018-07-12  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: database file of subframe cannot be removed
+        https://bugs.webkit.org/show_bug.cgi?id=187564
+
+        Reviewed by Youenn Fablet.
+
+        For IndexedDB, if openingOrigin is different from mainFrameOrigin, there will be another 
+        layer in the database file path. 
+        IDBServer should delete database files recursively to make sure all files are removed.
+
+        Covered by modified test: WebKit.WebsiteDataStoreCustomPaths.
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::removeAllDatabasesForOriginPath):
+
 2018-07-12  Per Arne Vollan  <pvollan@apple.com>
 
         Add compile guard for enabling NSRunLoop in the WebContent process.
index afe575d..b8e931b 100644 (file)
@@ -543,11 +543,14 @@ void IDBServer::closeAndDeleteDatabasesForOrigins(const Vector<SecurityOriginDat
 
 static void removeAllDatabasesForOriginPath(const String& originPath, WallTime modifiedSince)
 {
+    LOG(IndexedDB, "removeAllDatabasesForOriginPath with originPath %s", originPath.utf8().data());
     Vector<String> databasePaths = FileSystem::listDirectory(originPath, "*");
 
     for (auto& databasePath : databasePaths) {
-        String databaseFile = FileSystem::pathByAppendingComponent(databasePath, "IndexedDB.sqlite3");
+        if (FileSystem::fileIsDirectory(databasePath, FileSystem::ShouldFollowSymbolicLinks::No))
+            removeAllDatabasesForOriginPath(databasePath, modifiedSince);
 
+        String databaseFile = FileSystem::pathByAppendingComponent(databasePath, "IndexedDB.sqlite3");
         if (modifiedSince > -WallTime::infinity() && FileSystem::fileExists(databaseFile)) {
             auto modificationTime = FileSystem::getFileModificationTime(databaseFile);
             if (!modificationTime)
index 1b0d864..3f6908f 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-12  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: database file of subframe cannot be removed
+        https://bugs.webkit.org/show_bug.cgi?id=187564
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+        (TEST):
+
 2018-07-12  Timothy Hatcher  <timothy@apple.com>
 
         Make WebKit.LinkColorWithSystemAppearance work across system versions.
index dcac971..7b8c17e 100644 (file)
                9329AA291DE3F81E003ABD07 /* TextBreakIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */; };
                932AE53D1D371047005DFFAF /* focus-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93575C551D30366E000D604D /* focus-inputs.html */; };
                933D631D1FCB76200032ECD6 /* Hasher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933D631B1FCB76180032ECD6 /* Hasher.cpp */; };
+               935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */; };
+               935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */; };
+               935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */; };
                9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
                93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93625D261CD973AF006DC1F1 /* large-video-without-audio.html */; };
                936F72801CD7D9EC0068A0FB /* large-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */; };
                                F41AB9A51EF4696B0083FA08 /* image-and-textarea.html in Copy Resources */,
                                F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
                                F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
+                               935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */,
+                               935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */,
+                               935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */,
                                51A587851D2739E3004BA9AF /* IndexedDBDatabaseProcessKill-1.html in Copy Resources */,
                                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */,
                                51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */,
                9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextBreakIterator.cpp; sourceTree = "<group>"; };
                9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DidNotHandleKeyDown.cpp; sourceTree = "<group>"; };
                933D631B1FCB76180032ECD6 /* Hasher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Hasher.cpp; sourceTree = "<group>"; };
+               934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDB.sqlite3-wal"; sourceTree = "<group>"; };
+               934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDB.sqlite3-shm"; sourceTree = "<group>"; };
+               934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = IndexedDB.sqlite3; sourceTree = "<group>"; };
                93575C551D30366E000D604D /* focus-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "focus-inputs.html"; sourceTree = "<group>"; };
                9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
                93625D261CD973AF006DC1F1 /* large-video-without-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-without-audio.html"; sourceTree = "<group>"; };
                                F41AB9931EF4692C0083FA08 /* image-and-textarea.html */,
                                F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
                                F45B63FA1F197F33009D38B9 /* image-map.html */,
+                               934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */,
+                               934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */,
+                               934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */,
                                51A587821D272EB5004BA9AF /* IndexedDBDatabaseProcessKill-1.html */,
                                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */,
                                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3 b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3
new file mode 100644 (file)
index 0000000..bf99cb8
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3 differ
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm
new file mode 100644 (file)
index 0000000..5767970
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm differ
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal
new file mode 100644 (file)
index 0000000..c823f9c
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal differ
index a8f0847..2a4b446 100644 (file)
@@ -178,6 +178,18 @@ TEST(WebKit, WebsiteDataStoreCustomPaths)
     RetainPtr<WKWebsiteDataStore> dataStore = [[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()];
     RetainPtr<NSSet> types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
 
+    // Subframe of different origins may also create IndexedDB files.
+    RetainPtr<NSURL> url1 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3" subdirectory:@"TestWebKitAPI.resources"];
+    RetainPtr<NSURL> url2 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3-shm" subdirectory:@"TestWebKitAPI.resources"];
+    RetainPtr<NSURL> url3 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3-wal" subdirectory:@"TestWebKitAPI.resources"];
+    
+    RetainPtr<NSURL> frameIDBPath = [[fileIDBPath URLByAppendingPathComponent:@"https_apple.com_0"] URLByAppendingPathComponent:@"WebsiteDataStoreCustomPaths"];
+    [[NSFileManager defaultManager] createDirectoryAtURL:frameIDBPath.get() withIntermediateDirectories:YES attributes:nil error:nil];
+    
+    [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
+    [[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];
+    
     receivedScriptMessage = false;
     [dataStore removeDataOfTypes:types.get() modifiedSince:[NSDate distantPast] completionHandler:[]() {
         receivedScriptMessage = true;