Changeset 226003 in webkit


Ignore:
Timestamp:
Dec 16, 2017 10:54:04 AM (6 years ago)
Author:
beidson@apple.com
Message:

Implement getting ServiceWorker registrations for the WKWebsiteDataStore API
https://bugs.webkit.org/show_bug.cgi?id=180886

Reviewed by Chris Dumez.

Source/WebCore:

No new tests (API test coming soon).

  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::registrationStoreImportComplete):
(WebCore::SWServer::SWServer):
(WebCore::SWServer::getOriginsWithRegistrations):
(WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):

  • workers/service/server/SWServer.h:

Source/WebKit:

  • StorageProcess/StorageProcess.cpp:

(WebKit::StorageProcess::fetchWebsiteData):

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225998 r226003  
     12017-12-16  Brady Eidson  <beidson@apple.com>
     2
     3        Implement getting ServiceWorker registrations for the WKWebsiteDataStore API
     4        https://bugs.webkit.org/show_bug.cgi?id=180886
     5
     6        Reviewed by Chris Dumez.
     7
     8        No new tests (API test coming soon).
     9
     10        * workers/service/server/SWServer.cpp:
     11        (WebCore::SWServer::registrationStoreImportComplete):
     12        (WebCore::SWServer::SWServer):
     13        (WebCore::SWServer::getOriginsWithRegistrations):
     14        (WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):
     15        * workers/service/server/SWServer.h:
     16
    1172017-12-16  Yusuke Suzuki  <utatane.tea@gmail.com>
    218
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r225976 r226003  
    109109void SWServer::registrationStoreImportComplete()
    110110{
     111    ASSERT(!m_importCompleted);
     112    m_importCompleted = true;
    111113    m_originStore->importComplete();
     114    performGetOriginsWithRegistrationsCallbacks();
    112115}
    113116
     
    229232}
    230233
    231     SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, String&& registrationDatabaseDirectory, PAL::SessionID sessionID)
     234SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, String&& registrationDatabaseDirectory, PAL::SessionID sessionID)
    232235    : m_originStore(WTFMove(originStore))
    233236    , m_registrationStore(*this, WTFMove(registrationDatabaseDirectory))
     
    769772}
    770773
     774void SWServer::getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)> callback)
     775{
     776    m_getOriginsWithRegistrationsCallbacks.append(WTFMove(callback));
     777
     778    if (m_importCompleted)
     779        performGetOriginsWithRegistrationsCallbacks();
     780}
     781
     782void SWServer::performGetOriginsWithRegistrationsCallbacks()
     783{
     784    ASSERT(isMainThread());
     785    ASSERT(m_importCompleted);
     786
     787    if (m_getOriginsWithRegistrationsCallbacks.isEmpty())
     788        return;
     789
     790    HashSet<SecurityOriginData> originsWithRegistrations;
     791    for (auto& key : m_registrations.keys()) {
     792        originsWithRegistrations.add(key.topOrigin());
     793        originsWithRegistrations.add(SecurityOriginData { key.scope().protocol().toString(), key.scope().host(), key.scope().port() });
     794    }
     795
     796    auto callbacks = WTFMove(m_getOriginsWithRegistrationsCallbacks);
     797    for (auto& callback : callbacks)
     798        callback(originsWithRegistrations);
     799}
     800
    771801} // namespace WebCore
    772802
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r225992 r226003  
    175175    void registrationStoreImportComplete();
    176176
     177    WEBCORE_EXPORT void getOriginsWithRegistrations(WTF::Function<void(const HashSet<SecurityOriginData>&)>);
     178
    177179private:
    178180    void registerConnection(Connection&);
     
    197199    SWServerRegistration* registrationFromServiceWorkerIdentifier(ServiceWorkerIdentifier);
    198200    void forEachClientForOrigin(const ClientOrigin&, const WTF::Function<void(ServiceWorkerClientData&)>&);
     201
     202    void performGetOriginsWithRegistrationsCallbacks();
    199203
    200204    enum TerminationMode {
     
    232236    HashMap<ServiceWorkerIdentifier, Vector<RunServiceWorkerCallback>> m_serviceWorkerRunRequests;
    233237    PAL::SessionID m_sessionID;
     238    bool m_importCompleted { false };
     239    Vector<WTF::Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
    234240};
    235241
  • trunk/Source/WebKit/ChangeLog

    r225999 r226003  
     12017-12-16  Brady Eidson  <beidson@apple.com>
     2
     3        Implement getting ServiceWorker registrations for the WKWebsiteDataStore API
     4        https://bugs.webkit.org/show_bug.cgi?id=180886
     5
     6        Reviewed by Chris Dumez.
     7
     8        * StorageProcess/StorageProcess.cpp:
     9        (WebKit::StorageProcess::fetchWebsiteData):
     10
    1112017-12-16  Brent Fulgham  <bfulgham@apple.com>
    212
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r225935 r226003  
    266266void StorageProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, uint64_t callbackID)
    267267{
    268     auto completionHandler = [this, callbackID](const WebsiteData& websiteData) {
    269         parentProcessConnection()->send(Messages::StorageProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
    270     };
    271 
    272 #if ENABLE(SERVICE_WORKER)
    273     if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations))
    274         notImplemented();
     268    auto websiteData = std::make_unique<WebsiteData>();
     269    WebsiteData* rawWebsiteData = websiteData.get();
     270    auto callbackAggregator = CallbackAggregator::create([this, websiteData = WTFMove(websiteData), callbackID]() {
     271        parentProcessConnection()->send(Messages::StorageProcessProxy::DidFetchWebsiteData(callbackID, *websiteData), 0);
     272    });
     273
     274    String path;
     275#if ENABLE(SERVICE_WORKER)
     276    path = m_swDatabasePaths.get(sessionID);
     277    if (!path.isEmpty() && websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)) {
     278        swServerForSession(sessionID).getOriginsWithRegistrations([rawWebsiteData, callbackAggregator = callbackAggregator.copyRef()](const HashSet<SecurityOriginData>& origins) mutable {
     279            for (auto& origin : origins)
     280                rawWebsiteData->entries.append({ origin, WebsiteDataType::ServiceWorkerRegistrations, 0 });
     281        });
     282    }
    275283#endif
    276284
    277285#if ENABLE(INDEXED_DATABASE)
    278     String path = m_idbDatabasePaths.get(sessionID);
     286    path = m_idbDatabasePaths.get(sessionID);
    279287    if (!path.isEmpty() && websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
    280288        // FIXME: Pick the right database store based on the session ID.
    281         postStorageTask(CrossThreadTask([this, completionHandler = WTFMove(completionHandler), path = WTFMove(path)]() mutable {
    282             RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), securityOrigins = indexedDatabaseOrigins(path)] {
    283                 WebsiteData websiteData;
     289        postStorageTask(CrossThreadTask([this, callbackAggregator = callbackAggregator.copyRef(), path = WTFMove(path), rawWebsiteData]() mutable {
     290            RunLoop::main().dispatch([callbackAggregator = WTFMove(callbackAggregator), rawWebsiteData, securityOrigins = indexedDatabaseOrigins(path)] {
    284291                for (const auto& securityOrigin : securityOrigins)
    285                     websiteData.entries.append({ securityOrigin, WebsiteDataType::IndexedDBDatabases, 0 });
    286 
    287                 completionHandler(websiteData);
     292                    rawWebsiteData->entries.append({ securityOrigin, WebsiteDataType::IndexedDBDatabases, 0 });
    288293            });
    289294        }));
    290         return;
    291     }
    292 #endif
    293 
    294     completionHandler({ });
     295    }
     296#endif
    295297}
    296298
Note: See TracChangeset for help on using the changeset viewer.