Skip to content
Permalink
Browse files
[WK2] Add API to clear service worker registrations
https://bugs.webkit.org/show_bug.cgi?id=178085
<rdar://problem/34866025>

Reviewed by Ryosuke Niwa.

Add API to clear service worker registrations. Although the request to
clear the registration is passed on to the StorageProcess, it is currently
a no-op on StorageProcess side until we actually persist service worker
registrations on disk.

* Shared/WebsiteData/WebsiteDataType.h:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::fetchWebsiteData):
(WebKit::StorageProcess::deleteWebsiteData):
(WebKit::StorageProcess::deleteWebsiteDataForOrigins):
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/API/Cocoa/WKWebsiteDataRecord.h:
* UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
(dataTypesToString):
* UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h:
(WebKit::toWebsiteDataType):
(WebKit::toWKWebsiteDataTypes):
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(+[WKWebsiteDataStore allWebsiteDataTypes]):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::fetchDataAndApply):
(WebKit::WebsiteDataStore::removeData):


Canonical link: https://commits.webkit.org/194400@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223158 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Oct 11, 2017
1 parent 3f61c36 commit ef69b4a0598f28c9532e43b02a04463e2889bac2
Showing 10 changed files with 106 additions and 20 deletions.
@@ -1,3 +1,36 @@
2017-10-10 Chris Dumez <cdumez@apple.com>

[WK2] Add API to clear service worker registrations
https://bugs.webkit.org/show_bug.cgi?id=178085
<rdar://problem/34866025>

Reviewed by Ryosuke Niwa.

Add API to clear service worker registrations. Although the request to
clear the registration is passed on to the StorageProcess, it is currently
a no-op on StorageProcess side until we actually persist service worker
registrations on disk.

* Shared/WebsiteData/WebsiteDataType.h:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::fetchWebsiteData):
(WebKit::StorageProcess::deleteWebsiteData):
(WebKit::StorageProcess::deleteWebsiteDataForOrigins):
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/API/Cocoa/WKWebsiteDataRecord.h:
* UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
(dataTypesToString):
* UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h:
(WebKit::toWebsiteDataType):
(WebKit::toWKWebsiteDataTypes):
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(+[WKWebsiteDataStore allWebsiteDataTypes]):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::fetchDataAndApply):
(WebKit::WebsiteDataStore::removeData):

2017-10-10 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r223130.
@@ -45,6 +45,9 @@ enum class WebsiteDataType {
#endif
ResourceLoadStatistics = 1 << 12,
Credentials = 1 << 13,
#if ENABLE(SERVICE_WORKER)
ServiceWorkerRegistrations = 1 << 14,
#endif
};

};
@@ -183,18 +183,18 @@ void StorageProcess::createStorageToWebProcessConnection()

void StorageProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, uint64_t callbackID)
{
#if ENABLE(INDEXED_DATABASE)
auto completionHandler = [this, callbackID](const WebsiteData& websiteData) {
parentProcessConnection()->send(Messages::StorageProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
};

String path = m_idbDatabasePaths.get(sessionID);
if (path.isEmpty() || !websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
completionHandler({ });
return;
}
#if ENABLE(SERVICE_WORKER)
if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
notImplemented();
#endif

if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
#if ENABLE(INDEXED_DATABASE)
String path = m_idbDatabasePaths.get(sessionID);
if (!path.isEmpty() && websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
// FIXME: Pick the right database store based on the session ID.
postStorageTask(CrossThreadTask([this, completionHandler = WTFMove(completionHandler), path = WTFMove(path)]() mutable {
RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), securityOrigins = indexedDatabaseOrigins(path)] {
@@ -205,40 +205,53 @@ void StorageProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
completionHandler(websiteData);
});
}));
return;
}
#endif

completionHandler({ });
}

void StorageProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
{
#if ENABLE(INDEXED_DATABASE)
auto completionHandler = [this, callbackID]() {
parentProcessConnection()->send(Messages::StorageProcessProxy::DidDeleteWebsiteData(callbackID), 0);
};

if (!websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
completionHandler();
#if ENABLE(SERVICE_WORKER)
if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
notImplemented();
#endif

#if ENABLE(INDEXED_DATABASE)
if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
idbServer(sessionID).closeAndDeleteDatabasesModifiedSince(modifiedSince, WTFMove(completionHandler));
return;
}

idbServer(sessionID).closeAndDeleteDatabasesModifiedSince(modifiedSince, WTFMove(completionHandler));
#endif

completionHandler();
}

void StorageProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<SecurityOriginData>& securityOriginDatas, uint64_t callbackID)
{
#if ENABLE(INDEXED_DATABASE)
auto completionHandler = [this, callbackID]() {
parentProcessConnection()->send(Messages::StorageProcessProxy::DidDeleteWebsiteDataForOrigins(callbackID), 0);
};

#if ENABLE(SERVICE_WORKER)
if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
notImplemented();
#endif

#if ENABLE(INDEXED_DATABASE)
if (!websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
completionHandler();
idbServer(sessionID).closeAndDeleteDatabasesForOrigins(securityOriginDatas, WTFMove(completionHandler));
return;
}

idbServer(sessionID).closeAndDeleteDatabasesForOrigins(securityOriginDatas, WTFMove(completionHandler));
#endif

completionHandler();
}

#if ENABLE(SANDBOX_EXTENSIONS)
@@ -324,3 +324,13 @@ void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStore
OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::IndexedDBDatabases;
WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, std::chrono::system_clock::time_point::min(), [] { });
}

void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef)
{
#if ENABLE(SERVICE_WORKER)
OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::ServiceWorkerRegistrations;
WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, std::chrono::system_clock::time_point::min(), [] { });
#else
UNUSED_PARAM(dataStoreRef);
#endif
}
@@ -71,6 +71,7 @@ typedef void (*WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunctio
WK_EXPORT void WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemoval(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunction callback);
WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef);
WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef);

#ifdef __cplusplus
}
@@ -55,6 +55,9 @@ WK_EXTERN NSString * const WKWebsiteDataTypeWebSQLDatabases WK_API_AVAILABLE(mac
/*! @constant WKWebsiteDataTypeIndexedDBDatabases IndexedDB databases. */
WK_EXTERN NSString * const WKWebsiteDataTypeIndexedDBDatabases WK_API_AVAILABLE(macosx(10.11), ios(9.0));

/*! @constant WKWebsiteDataTypeServiceWorkerRegistrations Service worker registrations. */
WK_EXTERN NSString * const WKWebsiteDataTypeServiceWorkerRegistrations WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

/*! A WKWebsiteDataRecord represents website data, grouped by domain name using the public suffix list. */
WK_CLASS_AVAILABLE(macosx(10.11), ios(9.0))
@interface WKWebsiteDataRecord : NSObject
@@ -40,6 +40,7 @@
NSString * const WKWebsiteDataTypeLocalStorage = @"WKWebsiteDataTypeLocalStorage";
NSString * const WKWebsiteDataTypeWebSQLDatabases = @"WKWebsiteDataTypeWebSQLDatabases";
NSString * const WKWebsiteDataTypeIndexedDBDatabases = @"WKWebsiteDataTypeIndexedDBDatabases";
NSString * const WKWebsiteDataTypeServiceWorkerRegistrations = @"WKWebsiteDataTypeServiceWorkerRegistrations";

NSString * const _WKWebsiteDataTypeMediaKeys = @"_WKWebsiteDataTypeMediaKeys";
NSString * const _WKWebsiteDataTypeHSTSCache = @"_WKWebsiteDataTypeHSTSCache";
@@ -80,6 +81,8 @@ - (void)dealloc
[array addObject:@"Web SQL"];
if ([dataTypes containsObject:WKWebsiteDataTypeIndexedDBDatabases])
[array addObject:@"IndexedDB"];
if ([dataTypes containsObject:WKWebsiteDataTypeServiceWorkerRegistrations])
[array addObject:@"Service Worker Registrations"];
if ([dataTypes containsObject:_WKWebsiteDataTypeHSTSCache])
[array addObject:@"HSTS Cache"];
if ([dataTypes containsObject:_WKWebsiteDataTypeMediaKeys])
@@ -58,6 +58,10 @@ static inline std::optional<WebsiteDataType> toWebsiteDataType(NSString *website
return WebsiteDataType::WebSQLDatabases;
if ([websiteDataType isEqualToString:WKWebsiteDataTypeIndexedDBDatabases])
return WebsiteDataType::IndexedDBDatabases;
#if ENABLE(SERVICE_WORKER)
if ([websiteDataType isEqualToString:WKWebsiteDataTypeServiceWorkerRegistrations])
return WebsiteDataType::ServiceWorkerRegistrations;
#endif
if ([websiteDataType isEqualToString:_WKWebsiteDataTypeHSTSCache])
return WebsiteDataType::HSTSCache;
if ([websiteDataType isEqualToString:_WKWebsiteDataTypeMediaKeys])
@@ -107,6 +111,10 @@ static inline RetainPtr<NSSet> toWKWebsiteDataTypes(OptionSet<WebKit::WebsiteDat
[wkWebsiteDataTypes addObject:WKWebsiteDataTypeWebSQLDatabases];
if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases))
[wkWebsiteDataTypes addObject:WKWebsiteDataTypeIndexedDBDatabases];
#if ENABLE(SERVICE_WORKER)
if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
[wkWebsiteDataTypes addObject:WKWebsiteDataTypeServiceWorkerRegistrations];
#endif
if (websiteDataTypes.contains(WebsiteDataType::HSTSCache))
[wkWebsiteDataTypes addObject:_WKWebsiteDataTypeHSTSCache];
if (websiteDataTypes.contains(WebsiteDataType::MediaKeys))
@@ -95,7 +95,7 @@ + (NSSet *)allWebsiteDataTypes
static dispatch_once_t onceToken;
static NSSet *allWebsiteDataTypes;
dispatch_once(&onceToken, ^{
allWebsiteDataTypes = [[NSSet alloc] initWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeWebSQLDatabases ]];
allWebsiteDataTypes = [[NSSet alloc] initWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeServiceWorkerRegistrations, WKWebsiteDataTypeWebSQLDatabases ]];
});

return allWebsiteDataTypes;
@@ -426,7 +426,11 @@ void WebsiteDataStore::fetchDataAndApply(OptionSet<WebsiteDataType> dataTypes, O
});
}

if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
#if ENABLE(SERVICE_WORKER)
|| dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
#endif
) && isPersistent()) {
for (auto& processPool : processPools()) {
processPool->ensureStorageProcessAndWebsiteDataStore(this);

@@ -720,7 +724,11 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, std::chr
});
}

if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
#if ENABLE(SERVICE_WORKER)
|| dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
#endif
) && isPersistent()) {
for (auto& processPool : processPools()) {
processPool->ensureStorageProcessAndWebsiteDataStore(this);

@@ -999,7 +1007,11 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, const Ve
});
}

if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
#if ENABLE(SERVICE_WORKER)
|| dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
#endif
) && isPersistent()) {
for (auto& processPool : processPools()) {
processPool->ensureStorageProcessAndWebsiteDataStore(this);

0 comments on commit ef69b4a

Please sign in to comment.