Changeset 286569 in webkit
- Timestamp:
- Dec 6, 2021, 2:17:05 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 29 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/FileSystem.cpp (modified) (1 diff)
-
Source/WTF/wtf/FileSystem.h (modified) (2 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (modified) (1 diff)
-
Source/WebKit/CMakeLists.txt (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/DerivedSources-input.xcfilelist (modified) (1 diff)
-
Source/WebKit/DerivedSources-output.xcfilelist (modified) (2 diffs)
-
Source/WebKit/DerivedSources.make (modified) (1 diff)
-
Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/NetworkProcess.cpp (modified) (5 diffs)
-
Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (modified) (5 diffs)
-
Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp (modified) (4 diffs)
-
Source/WebKit/NetworkProcess/storage/OriginStorageManager.h (modified) (3 diffs)
-
Source/WebKit/Shared/WebsiteData/WebsiteData.cpp (modified) (1 diff)
-
Source/WebKit/Shared/WebsiteData/WebsiteDataType.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (modified) (1 diff)
-
Source/WebKit/WebKit.xcodeproj/project.pbxproj (modified) (6 diffs)
-
Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp (modified) (2 diffs)
-
Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.messages.in (deleted)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r286565 r286569 1 2021-12-06 Ryan Haddad <ryanhaddad@apple.com> 2 3 REGRESSION (r286507): [macOS] Many file system access layout tests became flaky failures 4 https://bugs.webkit.org/show_bug.cgi?id=233892 5 6 Unreviewed, revert r286507. 7 8 * wtf/FileSystem.cpp: 9 (WTF::FileSystemImpl::readEntireFile): Deleted. 10 (WTF::FileSystemImpl::deleteAllFilesModifiedSince): Deleted. 11 * wtf/FileSystem.h: 12 1 13 2021-12-06 Simon Fraser <simon.fraser@apple.com> 2 14 -
trunk/Source/WTF/wtf/FileSystem.cpp
r286507 r286569 515 515 } 516 516 517 std::optional<Vector<uint8_t>> readEntireFile(PlatformFileHandle handle)518 {519 if (!FileSystem::isHandleValid(handle))520 return std::nullopt;521 522 auto size = FileSystem::fileSize(handle).value_or(0);523 if (!size)524 return std::nullopt;525 526 unsigned bytesToRead;527 if (!WTF::convertSafely(size, bytesToRead))528 return std::nullopt;529 530 Vector<uint8_t> buffer(bytesToRead);531 unsigned totalBytesRead = FileSystem::readFromFile(handle, buffer.data(), buffer.size());532 if (totalBytesRead != bytesToRead)533 return std::nullopt;534 535 return buffer;536 }537 538 void deleteAllFilesModifiedSince(const String& directory, WallTime time)539 {540 // This function may delete directory folder.541 if (time == -WallTime::infinity()) {542 deleteNonEmptyDirectory(directory);543 return;544 }545 546 auto children = listDirectory(directory);547 for (auto& child : children) {548 auto childPath = FileSystem::pathByAppendingComponent(directory, child);549 auto childType = fileType(childPath);550 if (!childType)551 continue;552 553 switch (*childType) {554 case FileType::Regular: {555 if (auto modificationTime = FileSystem::fileModificationTime(childPath); modificationTime && *modificationTime >= time)556 deleteFile(childPath);557 break;558 }559 case FileType::Directory:560 deleteAllFilesModifiedSince(childPath, time);561 deleteEmptyDirectory(childPath);562 break;563 case FileType::SymbolicLink:564 break;565 }566 }567 568 FileSystem::deleteEmptyDirectory(directory);569 }570 571 517 #if HAVE(STD_FILESYSTEM) || HAVE(STD_EXPERIMENTAL_FILESYSTEM) 572 518 -
trunk/Source/WTF/wtf/FileSystem.h
r286507 r286569 109 109 WTF_EXPORT_PRIVATE bool fileExists(const String&); 110 110 WTF_EXPORT_PRIVATE bool deleteFile(const String&); 111 WTF_EXPORT_PRIVATE void deleteAllFilesModifiedSince(const String&, WallTime);112 111 WTF_EXPORT_PRIVATE bool deleteEmptyDirectory(const String&); 113 112 WTF_EXPORT_PRIVATE bool moveFile(const String& oldPath, const String& newPath); … … 148 147 using Salt = std::array<uint8_t, 8>; 149 148 WTF_EXPORT_PRIVATE std::optional<Salt> readOrMakeSalt(const String& path); 150 WTF_EXPORT_PRIVATE std::optional<Vector<uint8_t>> readEntireFile(PlatformFileHandle);151 149 152 150 // Prefix is what the filename should be prefixed with, not the full path. -
trunk/Source/WebCore/ChangeLog
r286568 r286569 1 2021-12-06 Ryan Haddad <ryanhaddad@apple.com> 2 3 REGRESSION (r286507): [macOS] Many file system access layout tests became flaky failures 4 https://bugs.webkit.org/show_bug.cgi?id=233892 5 6 Unreviewed, revert r286507. 7 8 * Modules/filesystemaccess/FileSystemStorageConnection.h: 9 1 10 2021-12-06 Sam Weinig <weinig@apple.com> 2 11 -
trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h
r286507 r286569 28 28 #include "FileSystemHandleIdentifier.h" 29 29 #include "FileSystemSyncAccessHandleIdentifier.h" 30 #include "ProcessQualified.h"31 30 #include "ScriptExecutionContextIdentifier.h" 32 31 #include <wtf/CompletionHandler.h> -
trunk/Source/WebKit/CMakeLists.txt
r286507 r286569 311 311 WebProcess/WebCoreSupport/RemoteWebLockRegistry 312 312 WebProcess/WebCoreSupport/WebBroadcastChannelRegistry 313 WebProcess/WebCoreSupport/WebFileSystemStorageConnection314 313 WebProcess/WebCoreSupport/WebSpeechRecognitionConnection 315 314 -
trunk/Source/WebKit/ChangeLog
r286567 r286569 1 2021-12-06 Ryan Haddad <ryanhaddad@apple.com> 2 3 REGRESSION (r286507): [macOS] Many file system access layout tests became flaky failures 4 https://bugs.webkit.org/show_bug.cgi?id=233892 5 6 Unreviewed, revert r286507. 7 8 * CMakeLists.txt: 9 * DerivedSources-input.xcfilelist: 10 * DerivedSources-output.xcfilelist: 11 * DerivedSources.make: 12 * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: 13 (WebKit::WebResourceLoadStatisticsStore::monitoredDataTypes): 14 * NetworkProcess/NetworkProcess.cpp: 15 (WebKit::NetworkProcess::fetchWebsiteData): 16 (WebKit::NetworkProcess::deleteWebsiteData): 17 (WebKit::NetworkProcess::deleteWebsiteDataForOrigins): 18 (WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains): 19 (WebKit::NetworkProcess::registrableDomainsWithWebsiteData): 20 * NetworkProcess/storage/FileSystemStorageHandle.h: 21 (WebKit::FileSystemStorageHandle::activeSyncAccessHandle const): Deleted. 22 * NetworkProcess/storage/FileSystemStorageManager.cpp: 23 (WebKit::FileSystemStorageManager::~FileSystemStorageManager): 24 (WebKit::FileSystemStorageManager::close): Deleted. 25 * NetworkProcess/storage/FileSystemStorageManager.h: 26 * NetworkProcess/storage/NetworkStorageManager.cpp: 27 (WebKit::originPath): 28 (WebKit::NetworkStorageManager::localOriginStorageManager): 29 (WebKit::readOriginFromFile): Deleted. 30 (WebKit::writeOriginToFileIfNecessary): Deleted. 31 (WebKit::deleteOriginFileIfNecessary): Deleted. 32 (WebKit::originDirectoryPath): Deleted. 33 (WebKit::originFilePath): Deleted. 34 (WebKit::NetworkStorageManager::removeOriginStorageManagerIfPossible): Deleted. 35 (WebKit::toWebsiteDataType): Deleted. 36 (WebKit::NetworkStorageManager::forEachOriginDirectory): Deleted. 37 (WebKit::NetworkStorageManager::fetchDataFromDisk): Deleted. 38 (WebKit::NetworkStorageManager::fetchData): Deleted. 39 (WebKit::NetworkStorageManager::deleteDataOnDisk): Deleted. 40 (WebKit::NetworkStorageManager::deleteData): Deleted. 41 (WebKit::NetworkStorageManager::deleteDataModifiedSince): Deleted. 42 (WebKit::NetworkStorageManager::deleteDataForRegistrableDomains): Deleted. 43 * NetworkProcess/storage/NetworkStorageManager.h: 44 * NetworkProcess/storage/OriginStorageManager.cpp: 45 (WebKit::OriginStorageManager::StorageBucket::typeStoragePath const): 46 (WebKit::OriginStorageManager::StorageBucket::fileSystemStorageManager): 47 (WebKit::OriginStorageManager::OriginStorageManager): 48 (WebKit::OriginStorageManager::StorageBucket::toStorageIdentifier): Deleted. 49 (WebKit::OriginStorageManager::StorageBucket::isActive): Deleted. 50 (WebKit::OriginStorageManager::StorageBucket::deleteData): Deleted. 51 (WebKit::OriginStorageManager::StorageBucket::deleteFileSystemStorageData): Deleted. 52 (WebKit::OriginStorageManager::isActive): Deleted. 53 (WebKit::OriginStorageManager::deleteData): Deleted. 54 * NetworkProcess/storage/OriginStorageManager.h: 55 * Shared/WebsiteData/WebsiteData.cpp: 56 (WebKit::WebsiteData::ownerProcess): 57 * Shared/WebsiteData/WebsiteDataType.h: 58 * UIProcess/API/Cocoa/WKWebsiteDataRecord.mm: 59 (dataTypesToString): 60 * UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h: 61 (WebKit::toWebsiteDataType): 62 (WebKit::toWKWebsiteDataTypes): 63 * UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h: 64 * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: 65 (+[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate]): 66 * WebKit.xcodeproj/project.pbxproj: 67 * WebProcess/Network/NetworkProcessConnection.cpp: 68 (WebKit::NetworkProcessConnection::didReceiveMessage): 69 * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.messages.in: Removed. 70 1 71 2021-12-06 Mark Lam <mark.lam@apple.com> 2 72 -
trunk/Source/WebKit/DerivedSources-input.xcfilelist
r286507 r286569 222 222 $(PROJECT_DIR)/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in 223 223 $(PROJECT_DIR)/WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.messages.in 224 $(PROJECT_DIR)/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.messages.in225 224 $(PROJECT_DIR)/WebProcess/WebCoreSupport/WebSpeechRecognitionConnection.messages.in 226 225 $(PROJECT_DIR)/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in -
trunk/Source/WebKit/DerivedSources-output.xcfilelist
r286535 r286569 1 1 # This file is generated by the generate-xcfilelists script. 2 <<<<<<< HEAD 2 3 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/AudioCaptureSampleManagerMessageReceiver.cpp 3 4 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/AudioCaptureSampleManagerMessagesReplies.h … … 494 495 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebDeviceOrientationUpdateProviderProxyMessages.h 495 496 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebDeviceOrientationUpdateProviderProxyMessagesReplies.h 496 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebFileSystemStorageConnectionMessageReceiver.cpp497 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebFileSystemStorageConnectionMessages.h498 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebFileSystemStorageConnectionMessagesReplies.h499 497 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebFullScreenManagerMessageReceiver.cpp 500 498 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/WebFullScreenManagerMessages.h -
trunk/Source/WebKit/DerivedSources.make
r286507 r286569 223 223 WebProcess/WebCoreSupport/WebBroadcastChannelRegistry \ 224 224 WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider \ 225 WebProcess/WebCoreSupport/WebFileSystemStorageConnection \226 225 WebProcess/WebCoreSupport/WebSpeechRecognitionConnection \ 227 226 WebProcess/Speech/SpeechRecognitionRealtimeMediaSourceManager \ -
trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp
r286507 r286569 75 75 WebsiteDataType::ServiceWorkerRegistrations, 76 76 #endif 77 WebsiteDataType::FileSystem,78 77 })); 79 78 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r286507 r286569 1556 1556 } 1557 1557 #endif 1558 1559 if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {1560 iterator->value->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {1561 callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));1562 });1563 }1564 1558 } 1565 1559 … … 1636 1630 } 1637 1631 #endif 1638 1639 if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end())1640 iterator->value->deleteDataModifiedSince(websiteDataTypes, modifiedSince, [clearTasksHandler] { });1641 1632 } 1642 1633 … … 1745 1736 } 1746 1737 #endif 1747 1748 if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end())1749 iterator->value->deleteData(websiteDataTypes, originDatas, [clearTasksHandler] { });1750 1738 1751 1739 if (auto* networkSession = this->networkSession(sessionID)) { … … 1972 1960 } 1973 1961 1974 if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {1975 iterator->value->deleteDataForRegistrableDomains(websiteDataTypes, domainsToDeleteAllNonCookieWebsiteDataFor, [callbackAggregator](auto deletedDomains) mutable {1976 for (auto domain : deletedDomains)1977 callbackAggregator->m_domains.add(WTFMove(domain));1978 });1979 }1980 1981 1962 auto dataTypesForUIProcess = WebsiteData::filter(websiteDataTypes, WebsiteDataProcessType::UI); 1982 1963 if (!dataTypesForUIProcess.isEmpty() && !domainsToDeleteAllNonCookieWebsiteDataFor.isEmpty()) { … … 2093 2074 callbackAggregator->m_websiteData.entries.appendVector(entries); 2094 2075 }); 2095 });2096 }2097 2098 if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {2099 iterator->value->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {2100 callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));2101 2076 }); 2102 2077 } -
trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h
r286507 r286569 63 63 Expected<AccessHandleInfo, FileSystemStorageError> createSyncAccessHandle(); 64 64 std::optional<FileSystemStorageError> close(WebCore::FileSystemSyncAccessHandleIdentifier); 65 std::optional<WebCore::FileSystemSyncAccessHandleIdentifier> activeSyncAccessHandle() const { return m_activeSyncAccessHandle; }66 65 67 66 private: -
trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp
r286507 r286569 29 29 #include "FileSystemStorageError.h" 30 30 #include "FileSystemStorageHandleRegistry.h" 31 #include "WebFileSystemStorageConnectionMessages.h"32 31 33 32 namespace WebKit { … … 44 43 ASSERT(!RunLoop::isMain()); 45 44 46 close(); 45 for (auto identifier : m_handles.keys()) 46 m_registry.unregisterHandle(identifier); 47 47 } 48 48 … … 150 150 } 151 151 152 void FileSystemStorageManager::close()153 {154 ASSERT(!RunLoop::isMain());155 156 for (auto& [connectionID, identifiers] : m_handlesByConnection) {157 for (auto identifier : identifiers) {158 auto takenHandle = m_handles.take(identifier);159 m_registry.unregisterHandle(identifier);160 161 // Send message to web process to invalidate active sync access handle.162 if (auto accessHandleIdentifier = takenHandle->activeSyncAccessHandle())163 IPC::Connection::send(connectionID, Messages::WebFileSystemStorageConnection::InvalidateAccessHandle(*accessHandleIdentifier), 0);164 }165 }166 167 ASSERT(m_handles.isEmpty());168 m_handlesByConnection.clear();169 m_lockMap.clear();170 }171 172 152 } // namespace WebKit -
trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.h
r286507 r286569 50 50 51 51 private: 52 void close();53 54 52 String m_path; 55 53 FileSystemStorageHandleRegistry& m_registry; -
trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp
r286513 r286569 32 32 #include "NetworkStorageManagerMessages.h" 33 33 #include "OriginStorageManager.h" 34 #include "WebsiteDataType.h"35 34 #include <pal/crypto/CryptoDigest.h> 36 #include <wtf/Scope.h>37 #include <wtf/persistence/PersistentDecoder.h>38 #include <wtf/persistence/PersistentEncoder.h>39 35 #include <wtf/text/Base64.h> 40 36 41 37 namespace WebKit { 42 43 static std::optional<WebCore::ClientOrigin> readOriginFromFile(const String& filePath)44 {45 ASSERT(!RunLoop::isMain());46 47 if (!FileSystem::fileExists(filePath))48 return std::nullopt;49 50 auto originFileHandle = FileSystem::openFile(filePath, FileSystem::FileOpenMode::Read);51 auto closeFile = makeScopeExit([&] {52 FileSystem::closeFile(originFileHandle);53 });54 55 if (!FileSystem::isHandleValid(originFileHandle))56 return std::nullopt;57 58 auto originContent = FileSystem::readEntireFile(originFileHandle);59 if (!originContent)60 return std::nullopt;61 62 WTF::Persistence::Decoder decoder({ originContent->data(), originContent->size() });63 std::optional<WebCore::ClientOrigin> origin;64 decoder >> origin;65 return origin;66 }67 68 static void writeOriginToFileIfNecessary(const String& filePath, const WebCore::ClientOrigin& origin)69 {70 if (FileSystem::fileExists(filePath))71 return;72 73 FileSystem::makeAllDirectories(FileSystem::parentPath(filePath));74 auto originFileHandle = FileSystem::openFile(filePath, FileSystem::FileOpenMode::ReadWrite);75 auto closeFile = makeScopeExit([&] {76 FileSystem::closeFile(originFileHandle);77 });78 79 if (!FileSystem::isHandleValid(originFileHandle)) {80 LOG_ERROR("writeOriginToFileIfNecessary: Failed to open origin file");81 return;82 }83 84 WTF::Persistence::Encoder encoder;85 encoder << origin;86 FileSystem::writeToFile(originFileHandle, encoder.buffer(), encoder.bufferSize());87 }88 89 static void deleteOriginFileIfNecessary(const String& filePath)90 {91 auto parentPath = FileSystem::parentPath(filePath);92 auto children = FileSystem::listDirectory(parentPath);93 if (children.size() == 1)94 FileSystem::deleteFile(filePath);95 }96 38 97 39 Ref<NetworkStorageManager> NetworkStorageManager::create(PAL::SessionID sessionID, const String& path) … … 176 118 } 177 119 178 static String origin DirectoryPath(const String& rootPath, const WebCore::ClientOrigin& origin, FileSystem::Salt salt)120 static String originPath(const String& rootPath, const WebCore::ClientOrigin& origin, FileSystem::Salt salt) 179 121 { 180 122 if (rootPath.isEmpty()) … … 186 128 } 187 129 188 static String originFilePath(const String& directory)189 {190 return FileSystem::pathByAppendingComponent(directory, "origin"_s);191 }192 193 130 OriginStorageManager& NetworkStorageManager::localOriginStorageManager(const WebCore::ClientOrigin& origin) 194 131 { … … 196 133 197 134 return *m_localOriginStorageManagers.ensure(origin, [&] { 198 auto originDirectory = originDirectoryPath(m_path, origin, m_salt); 199 writeOriginToFileIfNecessary(originFilePath(originDirectory), origin); 200 return makeUnique<OriginStorageManager>(WTFMove(originDirectory)); 135 return makeUnique<OriginStorageManager>(originPath(m_path, origin, m_salt)); 201 136 }).iterator->value; 202 }203 204 void NetworkStorageManager::removeOriginStorageManagerIfPossible(const WebCore::ClientOrigin& origin)205 {206 if (auto iterator = m_localOriginStorageManagers.find(origin); iterator != m_localOriginStorageManagers.end()) {207 if (!iterator->value->isActive())208 m_localOriginStorageManagers.remove(iterator);209 }210 137 } 211 138 … … 380 307 } 381 308 382 static std::optional<WebsiteDataType> toWebsiteDataType(const String& storageType)383 {384 if (storageType == "FileSystem")385 return WebsiteDataType::FileSystem;386 387 return std::nullopt;388 }389 390 void NetworkStorageManager::forEachOriginDirectory(const Function<void(const String&)>& apply)391 {392 for (auto& topOrigin : FileSystem::listDirectory(m_path)) {393 auto topOriginDirectory = FileSystem::pathByAppendingComponent(m_path, topOrigin);394 auto openingOrigins = FileSystem::listDirectory(topOriginDirectory);395 if (openingOrigins.isEmpty()) {396 FileSystem::deleteEmptyDirectory(topOriginDirectory);397 continue;398 }399 400 for (auto& openingOrigin : openingOrigins) {401 auto openingOriginDirectory = FileSystem::pathByAppendingComponent(topOriginDirectory, openingOrigin);402 apply(openingOriginDirectory);403 }404 }405 }406 407 Vector<WebsiteData::Entry> NetworkStorageManager::fetchDataFromDisk(OptionSet<WebsiteDataType> targetTypes)408 {409 ASSERT(!RunLoop::isMain());410 411 HashMap<WebCore::SecurityOriginData, OptionSet<WebsiteDataType>> originTypes;412 forEachOriginDirectory([&](auto directory) mutable {413 auto origin = readOriginFromFile(originFilePath(directory));414 if (!origin)415 return;416 417 for (auto& storageType : FileSystem::listDirectory(directory)) {418 if (auto type = toWebsiteDataType(storageType); type && targetTypes.contains(*type)) {419 // Return both top origin and opening origin for this data.420 originTypes.add(origin->clientOrigin, OptionSet<WebsiteDataType> { }).iterator->value.add(*type);421 originTypes.add(origin->topOrigin, OptionSet<WebsiteDataType> { }).iterator->value.add(*type);422 }423 }424 });425 426 Vector<WebsiteData::Entry> entries;427 for (auto [origin, types] : originTypes) {428 for (auto type : types)429 entries.append({ WebsiteData::Entry { origin, type, 0 } });430 }431 432 return entries;433 }434 435 void NetworkStorageManager::fetchData(OptionSet<WebsiteDataType> types, CompletionHandler<void(Vector<WebsiteData::Entry>&&)>&& completionHandler)436 {437 ASSERT(RunLoop::isMain());438 ASSERT(!m_closed);439 440 m_queue->dispatch([this, protectedThis = Ref { *this }, types, completionHandler = WTFMove(completionHandler)]() mutable {441 auto entries = fetchDataFromDisk(types);442 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), entries = crossThreadCopy(WTFMove(entries))]() mutable {443 completionHandler(WTFMove(entries));444 });445 });446 }447 448 Vector<WebCore::ClientOrigin> NetworkStorageManager::deleteDataOnDisk(OptionSet<WebsiteDataType> types, WallTime modifiedSinceTime, const Function<bool(const WebCore::ClientOrigin&)>& filter)449 {450 ASSERT(!RunLoop::isMain());451 452 Vector<WebCore::ClientOrigin> deletedOrigins;453 forEachOriginDirectory([&](auto directory) mutable {454 auto filePath = originFilePath(directory);455 auto origin = readOriginFromFile(filePath);456 if (!origin) {457 // If origin cannot be retrieved, but we are asked to remove data for all origins, remove it.458 RELEASE_LOG_ERROR(Storage, "NetworkStorageManager::deleteDataOnDisk failed to read origin from '%s'", filePath.utf8().data());459 if (filter(WebCore::ClientOrigin { })) {460 FileSystem::deleteAllFilesModifiedSince(directory, modifiedSinceTime);461 FileSystem::deleteEmptyDirectory(directory);462 }463 return;464 }465 466 if (!filter(*origin))467 return;468 469 deletedOrigins.append(*origin);470 localOriginStorageManager(*origin).deleteData(types, modifiedSinceTime);471 removeOriginStorageManagerIfPossible(*origin);472 deleteOriginFileIfNecessary(filePath);473 FileSystem::deleteEmptyDirectory(directory);474 });475 476 return deletedOrigins;477 }478 479 void NetworkStorageManager::deleteData(OptionSet<WebsiteDataType> types, const Vector<WebCore::SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)480 {481 ASSERT(RunLoop::isMain());482 ASSERT(!m_closed);483 484 m_queue->dispatch([this, protectedThis = Ref { *this }, types, origins = crossThreadCopy(origins), completionHandler = WTFMove(completionHandler)]() mutable {485 HashSet<WebCore::SecurityOriginData> originSet;486 originSet.reserveInitialCapacity(origins.size());487 for (auto origin : origins)488 originSet.add(WTFMove(origin));489 490 deleteDataOnDisk(types, -WallTime::infinity(), [&originSet](auto origin) {491 return originSet.contains(origin.topOrigin) || originSet.contains(origin.clientOrigin);492 });493 494 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable {495 completionHandler();496 });497 });498 }499 500 void NetworkStorageManager::deleteDataModifiedSince(OptionSet<WebsiteDataType> types, WallTime modifiedSinceTime, CompletionHandler<void()>&& completionHandler)501 {502 ASSERT(RunLoop::isMain());503 ASSERT(!m_closed);504 505 m_queue->dispatch([this, protectedThis = Ref { *this }, types, modifiedSinceTime, completionHandler = WTFMove(completionHandler)]() mutable {506 deleteDataOnDisk(types, modifiedSinceTime, [](auto&) {507 return true;508 });509 510 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable {511 completionHandler();512 });513 });514 }515 516 void NetworkStorageManager::deleteDataForRegistrableDomains(OptionSet<WebsiteDataType> types, const Vector<WebCore::RegistrableDomain>& domains, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&& completionHandler)517 {518 ASSERT(RunLoop::isMain());519 ASSERT(!m_closed);520 521 m_queue->dispatch([this, protectedThis = Ref { *this }, types, domains = crossThreadCopy(domains), completionHandler = WTFMove(completionHandler)]() mutable {522 auto deletedOrigins = deleteDataOnDisk(types, -WallTime::infinity(), [&domains](auto& origin) {523 auto domain = WebCore::RegistrableDomain::uncheckedCreateFromHost(origin.clientOrigin.host);524 return domains.contains(domain);525 });526 527 HashSet<WebCore::RegistrableDomain> deletedDomains;528 for (auto origin : deletedOrigins) {529 auto domain = WebCore::RegistrableDomain::uncheckedCreateFromHost(origin.clientOrigin.host);530 deletedDomains.add(domain);531 }532 533 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), domains = crossThreadCopy(WTFMove(deletedDomains))]() mutable {534 completionHandler(WTFMove(domains));535 });536 });537 }538 539 309 } // namespace WebKit 540 310 -
trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h
r286507 r286569 29 29 #include "FileSystemStorageError.h" 30 30 #include "OriginStorageManager.h" 31 #include "WebsiteData.h"32 31 #include <WebCore/ClientOrigin.h> 33 32 #include <WebCore/FileSystemHandleIdentifier.h> 34 33 #include <WebCore/FileSystemSyncAccessHandleIdentifier.h> 35 34 #include <pal/SessionID.h> 36 #include <wtf/Forward.h>37 35 38 36 namespace IPC { … … 58 56 void close(); 59 57 void clearStorageForTesting(CompletionHandler<void()>&&); 60 void fetchData(OptionSet<WebsiteDataType>, CompletionHandler<void(Vector<WebsiteData::Entry>&&)>&&);61 void deleteData(OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&&);62 void deleteDataModifiedSince(OptionSet<WebsiteDataType>, WallTime, CompletionHandler<void()>&&);63 void deleteDataForRegistrableDomains(OptionSet<WebsiteDataType>, const Vector<WebCore::RegistrableDomain>&, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&);64 58 65 59 private: … … 67 61 ~NetworkStorageManager(); 68 62 OriginStorageManager& localOriginStorageManager(const WebCore::ClientOrigin&); 69 void removeOriginStorageManagerIfPossible(const WebCore::ClientOrigin&);70 63 FileSystemStorageHandleRegistry& fileSystemStorageHandleRegistry(); 71 72 void forEachOriginDirectory(const Function<void(const String&)>&);73 Vector<WebsiteData::Entry> fetchDataFromDisk(OptionSet<WebsiteDataType>);74 Vector<WebCore::ClientOrigin> deleteDataOnDisk(OptionSet<WebsiteDataType>, WallTime, const Function<bool(const WebCore::ClientOrigin&)>&);75 64 76 65 // IPC::MessageReceiver (implemented by generated code) -
trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp
r286507 r286569 52 52 } 53 53 54 enum class StorageType : uint8_t { 55 FileSystem, 56 }; 57 58 static String toStorageIdentifier(StorageType type) 54 String typeStoragePath(const String& storageIdentifier) const 59 55 { 60 switch (type) { 61 case StorageType::FileSystem: 62 return "FileSystem"_s; 63 default: 64 break; 65 } 66 ASSERT_NOT_REACHED(); 67 return ""_s; 68 } 69 70 String typeStoragePath(StorageType type) const 71 { 72 auto storageIdentifier = toStorageIdentifier(type); 73 if (m_rootPath.isEmpty() || storageIdentifier.isEmpty()) 74 return emptyString(); 75 76 return FileSystem::pathByAppendingComponent(m_rootPath, storageIdentifier); 56 return m_rootPath.isEmpty() ? emptyString() : FileSystem::pathByAppendingComponent(m_rootPath, storageIdentifier); 77 57 } 78 58 … … 80 60 { 81 61 if (!m_fileSystemStorageManager) 82 m_fileSystemStorageManager = makeUnique<FileSystemStorageManager>(typeStoragePath( StorageType::FileSystem), registry);62 m_fileSystemStorageManager = makeUnique<FileSystemStorageManager>(typeStoragePath("FileSystem"), registry); 83 63 84 64 return *m_fileSystemStorageManager; 85 65 } 86 66 87 bool isActive()88 {89 return !!m_fileSystemStorageManager;90 }91 92 void deleteData(OptionSet<WebsiteDataType> types, WallTime modifiedSinceTime)93 {94 if (types.contains(WebsiteDataType::FileSystem))95 deleteFileSystemStorageData(modifiedSinceTime);96 97 FileSystem::deleteNonEmptyDirectory(m_rootPath);98 }99 100 67 private: 101 void deleteFileSystemStorageData(WallTime modifiedSinceTime)102 {103 m_fileSystemStorageManager = nullptr;104 105 auto fileSystemStoragePath = typeStoragePath(StorageType::FileSystem);106 FileSystem::deleteAllFilesModifiedSince(fileSystemStoragePath, modifiedSinceTime);107 }108 109 68 String m_rootPath; 110 69 String m_identifier; … … 116 75 : m_path(WTFMove(path)) 117 76 { 118 ASSERT(!RunLoop::isMain());119 77 } 120 78 … … 146 104 } 147 105 148 bool OriginStorageManager::isActive()149 {150 return defaultBucket().isActive();151 }152 153 void OriginStorageManager::deleteData(OptionSet<WebsiteDataType> types, WallTime modifiedSince)154 {155 ASSERT(!RunLoop::isMain());156 defaultBucket().deleteData(types, modifiedSince);157 }158 159 106 } // namespace WebKit 160 107 -
trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h
r286507 r286569 29 29 #include <wtf/text/WTFString.h> 30 30 31 namespace WebCore {32 struct ClientOrigin;33 }34 35 31 namespace WebKit { 36 32 37 33 class FileSystemStorageHandleRegistry; 38 34 class FileSystemStorageManager; 39 enum class WebsiteDataType : uint32_t;40 35 41 36 class OriginStorageManager { … … 49 44 void persist(); 50 45 FileSystemStorageManager& fileSystemStorageManager(FileSystemStorageHandleRegistry&); 51 bool isActive();52 void deleteData(OptionSet<WebsiteDataType>, WallTime);53 46 54 47 private: … … 56 49 class StorageBucket; 57 50 StorageBucket& defaultBucket(); 58 59 void createOriginFileIfNecessary(const WebCore::ClientOrigin&);60 void deleteOriginFileIfNecessary();61 51 62 52 std::unique_ptr<StorageBucket> m_defaultBucket; -
trunk/Source/WebKit/Shared/WebsiteData/WebsiteData.cpp
r286507 r286569 130 130 return WebsiteDataProcessType::Network; 131 131 #endif 132 case WebsiteDataType::FileSystem:133 return WebsiteDataProcessType::Network;134 132 } 135 133 -
trunk/Source/WebKit/Shared/WebsiteData/WebsiteDataType.h
r286507 r286569 53 53 AlternativeServices = 1 << 18, 54 54 #endif 55 FileSystem = 1 << 19,56 55 }; 57 56 … … 81 80 WebKit::WebsiteDataType::DOMCache, 82 81 WebKit::WebsiteDataType::DeviceIdHashSalt, 83 WebKit::WebsiteDataType::PrivateClickMeasurements ,82 WebKit::WebsiteDataType::PrivateClickMeasurements 84 83 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE) 85 WebKit::WebsiteDataType::AlternativeServices,84 , WebKit::WebsiteDataType::AlternativeServices 86 85 #endif 87 WebKit::WebsiteDataType::FileSystem88 86 >; 89 87 }; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm
r286507 r286569 52 52 NSString * const _WKWebsiteDataTypePrivateClickMeasurements = @"_WKWebsiteDataTypePrivateClickMeasurements"; 53 53 NSString * const _WKWebsiteDataTypeAlternativeServices = @"_WKWebsiteDataTypeAlternativeServices"; 54 NSString * const _WKWebsiteDataTypeFileSystem = @"_WKWebsiteDataTypeFileSystem";55 54 56 55 #if PLATFORM(MAC) … … 112 111 if ([dataTypes containsObject:_WKWebsiteDataTypeAlternativeServices]) 113 112 [array addObject:@"Alternative Services"]; 114 if ([dataTypes containsObject:_WKWebsiteDataTypeFileSystem])115 [array addObject:@"File System"];116 113 117 114 return [array componentsJoinedByString:@", "]; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h
r286507 r286569 78 78 return WebsiteDataType::AlternativeServices; 79 79 #endif 80 if ([websiteDataType isEqualToString:_WKWebsiteDataTypeFileSystem])81 return WebsiteDataType::FileSystem;82 80 return std::nullopt; 83 81 } … … 137 135 [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeAlternativeServices]; 138 136 #endif 139 if (websiteDataTypes.contains(WebsiteDataType::FileSystem))140 [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeFileSystem];141 137 142 138 return wkWebsiteDataTypes; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h
r286507 r286569 38 38 WK_EXTERN NSString * const _WKWebsiteDataTypePrivateClickMeasurements WK_API_AVAILABLE(macos(12.0), ios(15.0)); 39 39 WK_EXTERN NSString * const _WKWebsiteDataTypeAlternativeServices WK_API_AVAILABLE(macos(11.0), ios(14.0)); 40 WK_EXTERN NSString * const _WKWebsiteDataTypeFileSystem WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));41 40 42 41 #if !TARGET_OS_IPHONE -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
r286507 r286569 249 249 _WKWebsiteDataTypeAdClickAttributions, 250 250 _WKWebsiteDataTypePrivateClickMeasurements, 251 _WKWebsiteDataTypeAlternativeServices, 252 _WKWebsiteDataTypeFileSystem 251 _WKWebsiteDataTypeAlternativeServices 253 252 #if !TARGET_OS_IPHONE 254 253 , _WKWebsiteDataTypePlugInData -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r286564 r286569 1505 1505 93D6B7B925534A170058DD3A /* WKSpeechRecognitionPermissionCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D6B7B725534A110058DD3A /* WKSpeechRecognitionPermissionCallback.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1506 1506 93E6A4EE1BC5DD3900F8A0E7 /* _WKHitTestResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E6A4ED1BC5DD3900F8A0E7 /* _WKHitTestResult.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1507 93E799852756FA550074008A /* WebFileSystemStorageConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E799822756FA540074008A /* WebFileSystemStorageConnectionMessageReceiver.cpp */; };1508 93E799872756FAB40074008A /* WebFileSystemStorageConnectionMessagesReplies.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E799832756FA540074008A /* WebFileSystemStorageConnectionMessagesReplies.h */; };1509 93E799882756FAC20074008A /* WebFileSystemStorageConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E799812756FA530074008A /* WebFileSystemStorageConnectionMessages.h */; };1510 1507 93F549B41E3174B7000E7239 /* WKSnapshotConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 93F549B31E3174B7000E7239 /* WKSnapshotConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1511 1508 950F2880252414EA00B74F1C /* WKMouseDeviceObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 950F287E252414E900B74F1C /* WKMouseDeviceObserver.h */; }; … … 5326 5323 93D6B7B825534A120058DD3A /* WKSpeechRecognitionPermissionCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKSpeechRecognitionPermissionCallback.cpp; sourceTree = "<group>"; }; 5327 5324 93E6A4ED1BC5DD3900F8A0E7 /* _WKHitTestResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKHitTestResult.h; sourceTree = "<group>"; }; 5328 93E7997E2756F6700074008A /* WebFileSystemStorageConnection.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebFileSystemStorageConnection.messages.in; sourceTree = "<group>"; };5329 93E799812756FA530074008A /* WebFileSystemStorageConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFileSystemStorageConnectionMessages.h; sourceTree = "<group>"; };5330 93E799822756FA540074008A /* WebFileSystemStorageConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebFileSystemStorageConnectionMessageReceiver.cpp; sourceTree = "<group>"; };5331 93E799832756FA540074008A /* WebFileSystemStorageConnectionMessagesReplies.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFileSystemStorageConnectionMessagesReplies.h; sourceTree = "<group>"; };5332 5325 93F549B31E3174B7000E7239 /* WKSnapshotConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSnapshotConfiguration.h; sourceTree = "<group>"; }; 5333 5326 93F549B51E3174DA000E7239 /* WKSnapshotConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKSnapshotConfiguration.mm; sourceTree = "<group>"; }; … … 10635 10628 9354242B2703BDCB005CA72C /* WebFileSystemStorageConnection.cpp */, 10636 10629 9354242A2703BDCB005CA72C /* WebFileSystemStorageConnection.h */, 10637 93E7997E2756F6700074008A /* WebFileSystemStorageConnection.messages.in */,10638 10630 BC111A58112F4FBB00337BAB /* WebFrameLoaderClient.cpp */, 10639 10631 BC032D6A10F4378D0058C15A /* WebFrameLoaderClient.h */, … … 12113 12105 E3866B042399979C00F88FE9 /* WebDeviceOrientationUpdateProviderProxyMessageReceiver.cpp */, 12114 12106 E3866B052399979C00F88FE9 /* WebDeviceOrientationUpdateProviderProxyMessages.h */, 12115 93E799822756FA540074008A /* WebFileSystemStorageConnectionMessageReceiver.cpp */,12116 93E799812756FA530074008A /* WebFileSystemStorageConnectionMessages.h */,12117 93E799832756FA540074008A /* WebFileSystemStorageConnectionMessagesReplies.h */,12118 12107 CD73BA48131ACD8E00EEDED2 /* WebFullScreenManagerMessageReceiver.cpp */, 12119 12108 CD73BA49131ACD8E00EEDED2 /* WebFullScreenManagerMessages.h */, … … 13362 13351 BC111B5D112F629800337BAB /* WebEventFactory.h in Headers */, 13363 13352 9354242C2703BDCB005CA72C /* WebFileSystemStorageConnection.h in Headers */, 13364 93E799882756FAC20074008A /* WebFileSystemStorageConnectionMessages.h in Headers */,13365 93E799872756FAB40074008A /* WebFileSystemStorageConnectionMessagesReplies.h in Headers */,13366 13353 1A90C1EE1264FD50003E44D4 /* WebFindOptions.h in Headers */, 13367 13354 BCE469541214E6CB000B98EB /* WebFormClient.h in Headers */, … … 15492 15479 E3866B092399A2D500F88FE9 /* WebDeviceOrientationUpdateProviderProxyMessageReceiver.cpp in Sources */, 15493 15480 2D92A789212B6AB100F493FD /* WebEvent.cpp in Sources */, 15494 93E799852756FA550074008A /* WebFileSystemStorageConnectionMessageReceiver.cpp in Sources */,15495 15481 CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */, 15496 15482 CD73BA47131ACC9A00EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp in Sources */, -
trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp
r286507 r286569 38 38 #include "WebCookieJar.h" 39 39 #include "WebCoreArgumentCoders.h" 40 #include "WebFileSystemStorageConnection.h"41 #include "WebFileSystemStorageConnectionMessages.h"42 40 #include "WebFrame.h" 43 41 #include "WebIDBConnectionToServer.h" … … 122 120 return; 123 121 } 124 if (decoder.messageReceiverName() == Messages::WebFileSystemStorageConnection::messageReceiverName()) {125 WebProcess::singleton().fileSystemStorageConnection().didReceiveMessage(connection, decoder);126 return;127 }128 122 129 123 #if USE(LIBWEBRTC) -
trunk/Tools/ChangeLog
r286554 r286569 1 2021-12-06 Ryan Haddad <ryanhaddad@apple.com> 2 3 REGRESSION (r286507): [macOS] Many file system access layout tests became flaky failures 4 https://bugs.webkit.org/show_bug.cgi?id=233892 5 6 Unreviewed, revert r286507. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm: 9 1 10 2021-12-06 Jon Lee <jonlee@apple.com> 2 11 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm
r286507 r286569 30 30 #import "DeprecatedGlobalValues.h" 31 31 #import "PlatformUtilities.h" 32 #import "TestUIDelegate.h"33 32 #import "TestURLSchemeHandler.h" 34 33 #import "TestWKWebView.h" … … 36 35 #import <WebKit/WKWebViewConfigurationPrivate.h> 37 36 #import <WebKit/WKWebViewPrivate.h> 38 #import <WebKit/WKWebsiteDataRecordPrivate.h>39 37 40 38 @interface FileSystemAccessMessageHandler : NSObject <WKScriptMessageHandler> … … 51 49 @end 52 50 53 static NSString * workerFrameString = @"<script> \51 static NSString *mainFrameString = @"<script> \ 54 52 function start() { \ 55 53 var worker = new Worker('worker.js'); \ … … 118 116 119 117 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]); 120 [webView loadHTMLString: workerFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]];118 [webView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]]; 121 119 TestWebKitAPI::Util::run(&receivedScriptMessage); 122 120 receivedScriptMessage = false; … … 129 127 130 128 auto secondWebView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]); 131 [secondWebView loadHTMLString: workerFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]];129 [secondWebView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]]; 132 130 TestWebKitAPI::Util::run(&receivedScriptMessage); 133 131 receivedScriptMessage = false; … … 171 169 172 170 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]); 173 [webView loadHTMLString: workerFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]];171 [webView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"webkit://webkit.org"]]; 174 172 TestWebKitAPI::Util::run(&receivedScriptMessage); 175 173 receivedScriptMessage = false; … … 261 259 } 262 260 263 static NSString *testString = @"<script> \264 async function open(shouldCreateFile) \265 { \266 try { \267 var rootHandle = await navigator.storage.getDirectory(); \268 var fileHandle = await rootHandle.getFileHandle('file-system-access.txt', { 'create' : shouldCreateFile }); \269 window.webkit.messageHandlers.testHandler.postMessage('file is opened'); \270 } catch(err) { \271 window.webkit.messageHandlers.testHandler.postMessage('error: ' + err.name + ' - ' + err.message); \272 } \273 } \274 open(true); \275 </script>";276 277 TEST(FileSystemAccess, FetchAndRemoveData)278 {279 auto handler = adoptNS([[FileSystemAccessMessageHandler alloc] init]);280 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);281 [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];282 auto websiteDataStore = [configuration websiteDataStore];283 auto types = [NSSet setWithObject:_WKWebsiteDataTypeFileSystem];284 285 // Remove existing data.286 done = false;287 [websiteDataStore removeDataOfTypes:types modifiedSince:[NSDate distantPast] completionHandler:^ {288 done = true;289 }];290 TestWebKitAPI::Util::run(&done);291 292 auto preferences = [configuration preferences];293 preferences._fileSystemAccessEnabled = YES;294 preferences._storageAPIEnabled = YES;295 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);296 [webView loadHTMLString:testString baseURL:[NSURL URLWithString:@"https://webkit.org"]];297 TestWebKitAPI::Util::run(&receivedScriptMessage);298 receivedScriptMessage = false;299 EXPECT_WK_STREQ(@"file is opened", [lastScriptMessage body]);300 301 // Fetch data and remove it by origin.302 done = false;303 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {304 EXPECT_EQ(records.count, 1u);305 auto record = [records objectAtIndex:0];306 EXPECT_STREQ("webkit.org", [record.displayName UTF8String]);307 308 // Remove data.309 [websiteDataStore removeDataOfTypes:types forDataRecords:records completionHandler:^{310 done = true;311 }];312 }];313 TestWebKitAPI::Util::run(&done);314 315 // Fetch data after removal.316 done = false;317 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {318 EXPECT_EQ(records.count, 0u);319 done = true;320 }];321 322 // File cannot be opened after data removal.323 [webView evaluateJavaScript:@"open(false)" completionHandler:nil];324 TestWebKitAPI::Util::run(&receivedScriptMessage);325 receivedScriptMessage = false;326 EXPECT_WK_STREQ(@"error: NotFoundError - The object can not be found here.", [lastScriptMessage body]);327 }328 329 TEST(FileSystemAccess, RemoveDataByModificationTime)330 {331 auto handler = adoptNS([[FileSystemAccessMessageHandler alloc] init]);332 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);333 [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];334 auto preferences = [configuration preferences];335 preferences._fileSystemAccessEnabled = YES;336 preferences._storageAPIEnabled = YES;337 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);338 [webView loadHTMLString:testString baseURL:[NSURL URLWithString:@"https://webkit.org"]];339 TestWebKitAPI::Util::run(&receivedScriptMessage);340 receivedScriptMessage = false;341 EXPECT_WK_STREQ(@"file is opened", [lastScriptMessage body]);342 343 auto websiteDataStore = [configuration websiteDataStore];344 auto types = [NSSet setWithObject:_WKWebsiteDataTypeFileSystem];345 done = false;346 __block NSUInteger recordsCount;347 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {348 recordsCount = records.count;349 EXPECT_GT(recordsCount, 0u);350 done = true;351 }];352 TestWebKitAPI::Util::run(&done);353 354 done = false;355 [websiteDataStore removeDataOfTypes:types modifiedSince:[NSDate now] completionHandler:^ {356 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {357 recordsCount = records.count;358 EXPECT_EQ(records.count, recordsCount);359 done = true;360 }];361 }];362 TestWebKitAPI::Util::run(&done);363 364 done = false;365 [websiteDataStore removeDataOfTypes:types modifiedSince:[NSDate distantPast] completionHandler:^ {366 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {367 EXPECT_EQ(records.count, 0u);368 done = true;369 }];370 }];371 TestWebKitAPI::Util::run(&done);372 }373 374 static NSString *mainFrameString = @"<script> \375 function postResult(event) \376 { \377 window.webkit.messageHandlers.testHandler.postMessage(event.data); \378 } \379 addEventListener('message', postResult, false); \380 </script> \381 <iframe src='https://127.0.0.1:9091/'>";382 383 static const char* frameBytes = R"TESTRESOURCE(384 <script>385 function postMessage(message)386 {387 parent.postMessage(message, '*');388 }389 async function open()390 {391 try {392 var rootHandle = await navigator.storage.getDirectory();393 var fileHandle = await rootHandle.getFileHandle('file-system-access.txt', { 'create' : true });394 postMessage('file is opened');395 } catch(err) {396 postMessage('error: ' + err.name + ' - ' + err.message);397 }398 }399 open();400 </script>401 )TESTRESOURCE";402 403 TEST(FileSystemAccess, FetchDataForThirdParty)404 {405 TestWebKitAPI::HTTPServer server({406 { "/", { frameBytes } },407 }, TestWebKitAPI::HTTPServer::Protocol::Https, nullptr, nullptr, 9091);408 409 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);410 auto handler = adoptNS([[FileSystemAccessMessageHandler alloc] init]);411 [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];412 auto preferences = [configuration preferences];413 preferences._fileSystemAccessEnabled = YES;414 preferences._storageAPIEnabled = YES;415 416 auto websiteDataStore = [configuration websiteDataStore];417 auto types = [NSSet setWithObject:_WKWebsiteDataTypeFileSystem];418 done = false;419 [websiteDataStore removeDataOfTypes:types modifiedSince:[NSDate distantPast] completionHandler:^ {420 done = true;421 }];422 TestWebKitAPI::Util::run(&done);423 424 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);425 auto navigationDelegate = adoptNS([TestNavigationDelegate new]);426 [navigationDelegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {427 EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);428 callback(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);429 }];430 [navigationDelegate setDecidePolicyForNavigationAction:[&](WKNavigationAction *action, void (^decisionHandler)(WKNavigationActionPolicy)) {431 decisionHandler(WKNavigationActionPolicyAllow);432 }];433 [webView setNavigationDelegate:navigationDelegate.get()];434 435 [webView loadHTMLString:mainFrameString baseURL:[NSURL URLWithString:@"https://webkit.org"]];436 TestWebKitAPI::Util::run(&receivedScriptMessage);437 receivedScriptMessage = false;438 EXPECT_WK_STREQ(@"file is opened", [lastScriptMessage body]);439 440 done = false;441 [websiteDataStore fetchDataRecordsOfTypes:types completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {442 // Should return both opening origin and top origin.443 EXPECT_EQ(records.count, 2u);444 auto sortFunction = ^(WKWebsiteDataRecord *record1, WKWebsiteDataRecord *record2){445 return [record1.displayName compare:record2.displayName];446 };447 auto sortedRecords = [records sortedArrayUsingComparator:sortFunction];448 EXPECT_WK_STREQ(@"127.0.0.1", [sortedRecords objectAtIndex:0].displayName);449 EXPECT_WK_STREQ(@"webkit.org", [sortedRecords objectAtIndex:1].displayName);450 done = true;451 }];452 TestWebKitAPI::Util::run(&done);453 }454 455 261 #endif // USE(APPLE_INTERNAL_SDK)
Note:
See TracChangeset
for help on using the changeset viewer.