Changeset 223158 in webkit


Ignore:
Timestamp:
Oct 10, 2017 5:01:28 PM (7 years ago)
Author:
Chris Dumez
Message:

[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):

Location:
trunk/Source/WebKit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r223150 r223158  
     12017-10-10  Chris Dumez  <cdumez@apple.com>
     2
     3        [WK2] Add API to clear service worker registrations
     4        https://bugs.webkit.org/show_bug.cgi?id=178085
     5        <rdar://problem/34866025>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add API to clear service worker registrations. Although the request to
     10        clear the registration is passed on to the StorageProcess, it is currently
     11        a no-op on StorageProcess side until we actually persist service worker
     12        registrations on disk.
     13
     14        * Shared/WebsiteData/WebsiteDataType.h:
     15        * StorageProcess/StorageProcess.cpp:
     16        (WebKit::StorageProcess::fetchWebsiteData):
     17        (WebKit::StorageProcess::deleteWebsiteData):
     18        (WebKit::StorageProcess::deleteWebsiteDataForOrigins):
     19        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     20        (WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations):
     21        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     22        * UIProcess/API/Cocoa/WKWebsiteDataRecord.h:
     23        * UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
     24        (dataTypesToString):
     25        * UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h:
     26        (WebKit::toWebsiteDataType):
     27        (WebKit::toWKWebsiteDataTypes):
     28        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     29        (+[WKWebsiteDataStore allWebsiteDataTypes]):
     30        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     31        (WebKit::WebsiteDataStore::fetchDataAndApply):
     32        (WebKit::WebsiteDataStore::removeData):
     33
    1342017-10-10  Commit Queue  <commit-queue@webkit.org>
    235
  • trunk/Source/WebKit/Shared/WebsiteData/WebsiteDataType.h

    r219904 r223158  
    4646    ResourceLoadStatistics = 1 << 12,
    4747    Credentials = 1 << 13,
     48#if ENABLE(SERVICE_WORKER)
     49    ServiceWorkerRegistrations = 1 << 14,
     50#endif
    4851};
    4952
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r223141 r223158  
    184184void StorageProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, uint64_t callbackID)
    185185{
    186 #if ENABLE(INDEXED_DATABASE)
    187186    auto completionHandler = [this, callbackID](const WebsiteData& websiteData) {
    188187        parentProcessConnection()->send(Messages::StorageProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
    189188    };
    190189
     190#if ENABLE(SERVICE_WORKER)
     191    if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
     192        notImplemented();
     193#endif
     194
     195#if ENABLE(INDEXED_DATABASE)
    191196    String path = m_idbDatabasePaths.get(sessionID);
    192     if (path.isEmpty() || !websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
    193         completionHandler({ });
    194         return;
    195     }
    196 
    197     if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
     197    if (!path.isEmpty() && websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
    198198        // FIXME: Pick the right database store based on the session ID.
    199199        postStorageTask(CrossThreadTask([this, completionHandler = WTFMove(completionHandler), path = WTFMove(path)]() mutable {
     
    206206            });
    207207        }));
    208     }
    209 #endif
     208        return;
     209    }
     210#endif
     211
     212    completionHandler({ });
    210213}
    211214
    212215void StorageProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
    213216{
    214 #if ENABLE(INDEXED_DATABASE)
    215217    auto completionHandler = [this, callbackID]() {
    216218        parentProcessConnection()->send(Messages::StorageProcessProxy::DidDeleteWebsiteData(callbackID), 0);
    217219    };
    218220
    219     if (!websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
    220         completionHandler();
    221         return;
    222     }
    223 
    224     idbServer(sessionID).closeAndDeleteDatabasesModifiedSince(modifiedSince, WTFMove(completionHandler));
    225 #endif
     221#if ENABLE(SERVICE_WORKER)
     222    if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
     223        notImplemented();
     224#endif
     225
     226#if ENABLE(INDEXED_DATABASE)
     227    if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
     228        idbServer(sessionID).closeAndDeleteDatabasesModifiedSince(modifiedSince, WTFMove(completionHandler));
     229        return;
     230    }
     231#endif
     232
     233    completionHandler();
    226234}
    227235
    228236void StorageProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<SecurityOriginData>& securityOriginDatas, uint64_t callbackID)
    229237{
    230 #if ENABLE(INDEXED_DATABASE)
    231238    auto completionHandler = [this, callbackID]() {
    232239        parentProcessConnection()->send(Messages::StorageProcessProxy::DidDeleteWebsiteDataForOrigins(callbackID), 0);
    233240    };
    234241
     242#if ENABLE(SERVICE_WORKER)
     243    if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
     244        notImplemented();
     245#endif
     246
     247#if ENABLE(INDEXED_DATABASE)
    235248    if (!websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
    236         completionHandler();
    237         return;
    238     }
    239 
    240     idbServer(sessionID).closeAndDeleteDatabasesForOrigins(securityOriginDatas, WTFMove(completionHandler));
    241 #endif
     249        idbServer(sessionID).closeAndDeleteDatabasesForOrigins(securityOriginDatas, WTFMove(completionHandler));
     250        return;
     251    }
     252#endif
     253
     254    completionHandler();
    242255}
    243256
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r222962 r223158  
    325325    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, std::chrono::system_clock::time_point::min(), [] { });
    326326}
     327
     328void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef)
     329{
     330#if ENABLE(SERVICE_WORKER)
     331    OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::ServiceWorkerRegistrations;
     332    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, std::chrono::system_clock::time_point::min(), [] { });
     333#else
     334    UNUSED_PARAM(dataStoreRef);
     335#endif
     336}
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r222962 r223158  
    7272WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef);
    7373WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
     74WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef);
    7475
    7576#ifdef __cplusplus
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.h

    r202789 r223158  
    5656WK_EXTERN NSString * const WKWebsiteDataTypeIndexedDBDatabases WK_API_AVAILABLE(macosx(10.11), ios(9.0));
    5757
     58/*! @constant WKWebsiteDataTypeServiceWorkerRegistrations Service worker registrations. */
     59WK_EXTERN NSString * const WKWebsiteDataTypeServiceWorkerRegistrations WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     60
    5861/*! A WKWebsiteDataRecord represents website data, grouped by domain name using the public suffix list. */
    5962WK_CLASS_AVAILABLE(macosx(10.11), ios(9.0))
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm

    r217886 r223158  
    4141NSString * const WKWebsiteDataTypeWebSQLDatabases = @"WKWebsiteDataTypeWebSQLDatabases";
    4242NSString * const WKWebsiteDataTypeIndexedDBDatabases = @"WKWebsiteDataTypeIndexedDBDatabases";
     43NSString * const WKWebsiteDataTypeServiceWorkerRegistrations = @"WKWebsiteDataTypeServiceWorkerRegistrations";
    4344
    4445NSString * const _WKWebsiteDataTypeMediaKeys = @"_WKWebsiteDataTypeMediaKeys";
     
    8182    if ([dataTypes containsObject:WKWebsiteDataTypeIndexedDBDatabases])
    8283        [array addObject:@"IndexedDB"];
     84    if ([dataTypes containsObject:WKWebsiteDataTypeServiceWorkerRegistrations])
     85        [array addObject:@"Service Worker Registrations"];
    8386    if ([dataTypes containsObject:_WKWebsiteDataTypeHSTSCache])
    8487        [array addObject:@"HSTS Cache"];
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h

    r218011 r223158  
    5959    if ([websiteDataType isEqualToString:WKWebsiteDataTypeIndexedDBDatabases])
    6060        return WebsiteDataType::IndexedDBDatabases;
     61#if ENABLE(SERVICE_WORKER)
     62    if ([websiteDataType isEqualToString:WKWebsiteDataTypeServiceWorkerRegistrations])
     63        return WebsiteDataType::ServiceWorkerRegistrations;
     64#endif
    6165    if ([websiteDataType isEqualToString:_WKWebsiteDataTypeHSTSCache])
    6266        return WebsiteDataType::HSTSCache;
     
    108112    if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases))
    109113        [wkWebsiteDataTypes addObject:WKWebsiteDataTypeIndexedDBDatabases];
     114#if ENABLE(SERVICE_WORKER)
     115    if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
     116        [wkWebsiteDataTypes addObject:WKWebsiteDataTypeServiceWorkerRegistrations];
     117#endif
    110118    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache))
    111119        [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeHSTSCache];
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r222396 r223158  
    9696    static NSSet *allWebsiteDataTypes;
    9797    dispatch_once(&onceToken, ^{
    98         allWebsiteDataTypes = [[NSSet alloc] initWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeWebSQLDatabases ]];
     98        allWebsiteDataTypes = [[NSSet alloc] initWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeServiceWorkerRegistrations, WKWebsiteDataTypeWebSQLDatabases ]];
    9999    });
    100100
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r222941 r223158  
    427427    }
    428428
    429     if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
     429    if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
     430#if ENABLE(SERVICE_WORKER)
     431        || dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
     432#endif
     433        ) && isPersistent()) {
    430434        for (auto& processPool : processPools()) {
    431435            processPool->ensureStorageProcessAndWebsiteDataStore(this);
     
    721725    }
    722726
    723     if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
     727    if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
     728#if ENABLE(SERVICE_WORKER)
     729        || dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
     730#endif
     731        ) && isPersistent()) {
    724732        for (auto& processPool : processPools()) {
    725733            processPool->ensureStorageProcessAndWebsiteDataStore(this);
     
    10001008    }
    10011009
    1002     if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && isPersistent()) {
     1010    if ((dataTypes.contains(WebsiteDataType::IndexedDBDatabases)
     1011#if ENABLE(SERVICE_WORKER)
     1012        || dataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)
     1013#endif
     1014        ) && isPersistent()) {
    10031015        for (auto& processPool : processPools()) {
    10041016            processPool->ensureStorageProcessAndWebsiteDataStore(this);
Note: See TracChangeset for help on using the changeset viewer.