Changeset 249627 in webkit


Ignore:
Timestamp:
Sep 7, 2019 10:42:51 PM (5 years ago)
Author:
Chris Dumez
Message:

[Service Workers] Drop support for registration resurrection
https://bugs.webkit.org/show_bug.cgi?id=201584

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Re-sync a couple of outdated WPT tests from upstream 820f0f86047e6e.

  • web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https.html:
  • web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt:
  • web-platform-tests/service-workers/service-worker/unregister-then-register.https.html:

Source/WebCore:

Drop support for registration resurrection (Unregistering then quickly re-registering would resurrect
the original registration instead of creating a new one). This behavior is no longer in the
specification (No more "isUninstalling" flag on the registration, and the registration is removed
from the "scope to registration map" right away upon unregistering).

This resurrection behavior was causing a lot of flakiness in the tests so it is likely we will be able
to unskip some tests. This is also what was causing the flakiness that caused Bug 201169 to be rolled
out.

No new tests, updated existing tests.

  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::activeWorkerFromRegistrationID):
(WebCore::SWServer::getRegistration):
(WebCore::SWServer::addRegistration):
(WebCore::SWServer::removeRegistration):
(WebCore::SWServer::getRegistrations):
(WebCore::SWServer::clearAll):
(WebCore::SWServer::clear):
(WebCore::SWServer::terminatePreinstallationWorker):
(WebCore::SWServer::didFinishActivation):
(WebCore::SWServer::claim):
(WebCore::SWServer::addClientServiceWorkerRegistration):
(WebCore::SWServer::removeClientServiceWorkerRegistration):
(WebCore::SWServer::installContextData):
(WebCore::SWServer::runServiceWorker):
(WebCore::SWServer::doRegistrationMatching):
(WebCore::SWServer::registrationFromServiceWorkerIdentifier):
(WebCore::SWServer::registerServiceWorkerClient):
(WebCore::SWServer::unregisterServiceWorkerClient):
(WebCore::SWServer::removeFromScopeToRegistrationMap):
(WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):

  • workers/service/server/SWServer.h:
  • workers/service/server/SWServerJobQueue.cpp:

(WebCore::SWServerJobQueue::runRegisterJob):
(WebCore::SWServerJobQueue::runUnregisterJob):
(WebCore::SWServerJobQueue::runUpdateJob):

  • workers/service/server/SWServerRegistration.cpp:

(WebCore::SWServerRegistration::clear):
(WebCore::SWServerRegistration::handleClientUnload):
(WebCore::SWServerRegistration::isUnregistered const):

  • workers/service/server/SWServerRegistration.h:

(WebCore::SWServerRegistration::scopeURLWithoutFragment const):

  • workers/service/server/SWServerWorker.cpp:

(WebCore::SWServerWorker::SWServerWorker):
(WebCore::m_scriptResourceMap):
(WebCore::SWServerWorker::contextData const):
(WebCore::SWServerWorker::skipWaiting):
(WebCore::SWServerWorker::setHasPendingEvents):
(WebCore::SWServerWorker::setState):
(WebCore::SWServerWorker::registration const):

  • workers/service/server/SWServerWorker.h:
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt

    r224772 r249627  
    22PASS: registration1 should not have a waiting worker
    33PASS: registration1 should have an active worker
    4 PASS: Registration was reused
     4PASS: Registration was not reused
    55
  • trunk/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse.html

    r224772 r249627  
    4141         let registration2 = await navigator.serviceWorker.register("resources/basic-unregister-then-register-again-reuse-worker.js", { });
    4242         if (registration1 === registration2)
    43              log("PASS: Registration was reused");
     43             log("FAIL: Registration was reused");
    4444         else
    45              log("FAIL: Registration was not reused");
     45             log("PASS: Registration was not reused");
    4646    } catch (e) {
    4747        log("FAIL: Got exception " + e);
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r249615 r249627  
     12019-09-07  Chris Dumez  <cdumez@apple.com>
     2
     3        [Service Workers] Drop support for registration resurrection
     4        https://bugs.webkit.org/show_bug.cgi?id=201584
     5
     6        Reviewed by Alex Christensen.
     7
     8        Re-sync a couple of outdated WPT tests from upstream 820f0f86047e6e.
     9
     10        * web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https-expected.txt:
     11        * web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https.html:
     12        * web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt:
     13        * web-platform-tests/service-workers/service-worker/unregister-then-register.https.html:
     14
    1152019-09-07  Ryan Haddad  <ryanhaddad@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https-expected.txt

    r246363 r249627  
    11
    22PASS Registering a new script URL while an unregistered registration is in use
    3 FAIL Registering a new script URL that 404s does not resurrect unregistered registration assert_equals: Document should not be controlled expected null but got object "[object ServiceWorker]"
    4 FAIL Registering a new script URL that fails to install does not resurrect unregistered registration assert_equals: registration.active expected null but got object "[object ServiceWorker]"
     3PASS Registering a new script URL that 404s does not resurrect unregistered registration
     4PASS Registering a new script URL that fails to install does not resurrect unregistered registration
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https.html

    r246363 r249627  
    2323
    2424  assert_equals(
    25     registration.installing.scriptURL,
    26     normalizeURL(newWorkerURL),
     25    registration.installing,
     26    null,
    2727    'before activated registration.installing'
    2828  );
     
    4848  );
    4949  assert_equals(
    50     newRegistration.active.scriptURL,
    51     normalizeURL(worker_url),
     50    newRegistration.active,
     51    null,
    5252    'before activated newRegistration.active'
    5353  );
    5454  iframe.remove();
    5555
    56   await wait_for_state(t, registration.installing, 'activated');
     56  await wait_for_state(t, newRegistration.installing, 'activated');
    5757
    5858  assert_equals(
     
    130130  assert_equals(registration.installing, null, 'registration.installing');
    131131  assert_equals(registration.waiting, null, 'registration.waiting');
    132   assert_equals(registration.active, null, 'registration.active');
     132  assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
     133                'registration.active');
    133134  assert_not_equals(registration, newRegistration, 'New registration is different');
    134135}, 'Registering a new script URL that fails to install does not resurrect unregistered registration');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt

    r246363 r249627  
    11
    22PASS Unregister then register resolves to a new value
    3 FAIL Unregister then register does not resolve to the original value even if the registration is in use. assert_not_equals: Unregister and register should always create a new registration got disallowed value object "[object ServiceWorkerRegistration]"
     3PASS Unregister then register does not resolve to the original value even if the registration is in use.
    44PASS Unregister then register does not affect existing controllee
    5 FAIL Unregister then register does not resurrect the registration assert_equals: Registration is new expected null but got object "[object ServiceWorker]"
     5PASS Unregister then register does not resurrect the registration
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https.html

    r246363 r249627  
    6767          return navigator.serviceWorker.register(worker_url, { scope: scope });
    6868        })
    69       .then(function(registration) {
     69      .then(function(newRegistration) {
    7070          assert_equals(registration.installing, null,
    7171                        'installing version is null');
  • trunk/Source/WebCore/ChangeLog

    r249615 r249627  
     12019-09-07  Chris Dumez  <cdumez@apple.com>
     2
     3        [Service Workers] Drop support for registration resurrection
     4        https://bugs.webkit.org/show_bug.cgi?id=201584
     5
     6        Reviewed by Alex Christensen.
     7
     8        Drop support for registration resurrection (Unregistering then quickly re-registering would resurrect
     9        the original registration instead of creating a new one). This behavior is no longer in the
     10        specification (No more "isUninstalling" flag on the registration, and the registration is removed
     11        from the "scope to registration map" right away upon unregistering).
     12
     13        This resurrection behavior was causing a lot of flakiness in the tests so it is likely we will be able
     14        to unskip some tests. This is also what was causing the flakiness that caused Bug 201169 to be rolled
     15        out.
     16
     17        No new tests, updated existing tests.
     18
     19        * workers/service/server/SWServer.cpp:
     20        (WebCore::SWServer::activeWorkerFromRegistrationID):
     21        (WebCore::SWServer::getRegistration):
     22        (WebCore::SWServer::addRegistration):
     23        (WebCore::SWServer::removeRegistration):
     24        (WebCore::SWServer::getRegistrations):
     25        (WebCore::SWServer::clearAll):
     26        (WebCore::SWServer::clear):
     27        (WebCore::SWServer::terminatePreinstallationWorker):
     28        (WebCore::SWServer::didFinishActivation):
     29        (WebCore::SWServer::claim):
     30        (WebCore::SWServer::addClientServiceWorkerRegistration):
     31        (WebCore::SWServer::removeClientServiceWorkerRegistration):
     32        (WebCore::SWServer::installContextData):
     33        (WebCore::SWServer::runServiceWorker):
     34        (WebCore::SWServer::doRegistrationMatching):
     35        (WebCore::SWServer::registrationFromServiceWorkerIdentifier):
     36        (WebCore::SWServer::registerServiceWorkerClient):
     37        (WebCore::SWServer::unregisterServiceWorkerClient):
     38        (WebCore::SWServer::removeFromScopeToRegistrationMap):
     39        (WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):
     40        * workers/service/server/SWServer.h:
     41        * workers/service/server/SWServerJobQueue.cpp:
     42        (WebCore::SWServerJobQueue::runRegisterJob):
     43        (WebCore::SWServerJobQueue::runUnregisterJob):
     44        (WebCore::SWServerJobQueue::runUpdateJob):
     45        * workers/service/server/SWServerRegistration.cpp:
     46        (WebCore::SWServerRegistration::clear):
     47        (WebCore::SWServerRegistration::handleClientUnload):
     48        (WebCore::SWServerRegistration::isUnregistered const):
     49        * workers/service/server/SWServerRegistration.h:
     50        (WebCore::SWServerRegistration::scopeURLWithoutFragment const):
     51        * workers/service/server/SWServerWorker.cpp:
     52        (WebCore::SWServerWorker::SWServerWorker):
     53        (WebCore::m_scriptResourceMap):
     54        (WebCore::SWServerWorker::contextData const):
     55        (WebCore::SWServerWorker::skipWaiting):
     56        (WebCore::SWServerWorker::setHasPendingEvents):
     57        (WebCore::SWServerWorker::setState):
     58        (WebCore::SWServerWorker::registration const):
     59        * workers/service/server/SWServerWorker.h:
     60
    1612019-09-07  Ryan Haddad  <ryanhaddad@apple.com>
    262
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r248846 r249627  
    112112SWServerWorker* SWServer::activeWorkerFromRegistrationID(ServiceWorkerRegistrationIdentifier identifier)
    113113{
    114     auto* registration = m_registrationsByID.get(identifier);
     114    auto* registration = m_registrations.get(identifier);
    115115    return registration ? registration->activeWorker() : nullptr;
    116116}
     
    118118SWServerRegistration* SWServer::getRegistration(const ServiceWorkerRegistrationKey& registrationKey)
    119119{
    120     return m_registrations.get(registrationKey);
     120    return m_scopeToRegistrationMap.get(registrationKey).get();
    121121}
    122122
     
    143143{
    144144    // Pages should not have been able to make a new registration to this key while the import was still taking place.
    145     ASSERT(!m_registrations.contains(data.registration.key));
     145    ASSERT(!m_scopeToRegistrationMap.contains(data.registration.key));
    146146
    147147    auto registration = makeUnique<SWServerRegistration>(*this, data.registration.key, data.registration.updateViaCache, data.registration.scopeURL, data.scriptURL);
     
    157157void SWServer::addRegistration(std::unique_ptr<SWServerRegistration>&& registration)
    158158{
    159     auto key = registration->key();
    160     auto* registrationPtr = registration.get();
    161     auto addResult1 = m_registrations.add(key, WTFMove(registration));
     159    m_originStore->add(registration->key().topOrigin());
     160    auto registrationID = registration->identifier();
     161    ASSERT(!m_scopeToRegistrationMap.contains(registration->key()));
     162    m_scopeToRegistrationMap.set(registration->key(), makeWeakPtr(*registration));
     163    auto addResult1 = m_registrations.add(registrationID, WTFMove(registration));
    162164    ASSERT_UNUSED(addResult1, addResult1.isNewEntry);
    163 
    164     auto addResult2 = m_registrationsByID.add(registrationPtr->identifier(), registrationPtr);
    165     ASSERT_UNUSED(addResult2, addResult2.isNewEntry);
    166 
    167     m_originStore->add(key.topOrigin());
    168 }
    169 
    170 void SWServer::removeRegistration(const ServiceWorkerRegistrationKey& key)
    171 {
    172     auto topOrigin = key.topOrigin();
    173     auto registration = m_registrations.take(key);
     165}
     166
     167void SWServer::removeRegistration(ServiceWorkerRegistrationIdentifier registrationID)
     168{
     169    auto registration = m_registrations.take(registrationID);
    174170    ASSERT(registration);
    175     bool wasRemoved = m_registrationsByID.remove(registration->identifier());
    176     ASSERT_UNUSED(wasRemoved, wasRemoved);
    177 
    178     m_originStore->remove(topOrigin);
     171   
     172    auto it = m_scopeToRegistrationMap.find(registration->key());
     173    if (it != m_scopeToRegistrationMap.end() && it->value == registration.get())
     174        m_scopeToRegistrationMap.remove(it);
     175
     176    m_originStore->remove(registration->key().topOrigin());
    179177    if (m_registrationStore)
    180         m_registrationStore->removeRegistration(key);
     178        m_registrationStore->removeRegistration(registration->key());
    181179}
    182180
     
    184182{
    185183    Vector<SWServerRegistration*> matchingRegistrations;
    186     for (auto& item : m_registrations) {
    187         if (!item.value->isUninstalling() && item.key.originIsMatching(topOrigin, clientURL))
    188             matchingRegistrations.append(item.value.get());
     184    for (auto& item : m_scopeToRegistrationMap) {
     185        if (item.key.originIsMatching(topOrigin, clientURL)) {
     186            auto* registration = item.value.get();
     187            ASSERT(registration);
     188            if (registration)
     189                matchingRegistrations.append(registration);
     190        }
    189191    }
    190192    // The specification mandates that registrations are returned in the insertion order.
     
    212214    while (!m_registrations.isEmpty())
    213215        m_registrations.begin()->value->clear();
    214     ASSERT(m_registrationsByID.isEmpty());
    215216    m_pendingContextDatas.clear();
    216217    m_originStore->clearAll();
     
    249250
    250251    Vector<SWServerRegistration*> registrationsToRemove;
    251     for (auto& keyAndValue : m_registrations) {
    252         if (keyAndValue.key.relatesToOrigin(securityOrigin))
    253             registrationsToRemove.append(keyAndValue.value.get());
     252    for (auto& registration : m_registrations.values()) {
     253        if (registration->key().relatesToOrigin(securityOrigin))
     254            registrationsToRemove.append(registration.get());
    254255    }
    255256
     
    414415{
    415416    worker.terminate();
    416     auto* registration = getRegistration(worker.registrationKey());
     417    auto* registration = worker.registration();
    417418    if (registration && registration->preInstallationWorker() == &worker)
    418419        registration->setPreInstallationWorker(nullptr);
     
    437438    RELEASE_LOG(ServiceWorker, "%p - SWServer::didFinishActivation: Finished activation for service worker %llu", this, worker.identifier().toUInt64());
    438439
    439     auto* registration = getRegistration(worker.registrationKey());
     440    auto* registration = worker.registration();
    440441    if (!registration)
    441442        return;
     
    495496                return;
    496497            result.iterator->value = registration->identifier();
    497             if (auto* controllingRegistration = m_registrationsByID.get(previousIdentifier))
     498            if (auto* controllingRegistration = m_registrations.get(previousIdentifier))
    498499                controllingRegistration->removeClientUsingRegistration(clientData.identifier);
    499500        }
     
    512513void SWServer::addClientServiceWorkerRegistration(Connection& connection, ServiceWorkerRegistrationIdentifier identifier)
    513514{
    514     auto* registration = m_registrationsByID.get(identifier);
     515    auto* registration = m_registrations.get(identifier);
    515516    if (!registration) {
    516517        LOG_ERROR("Request to add client-side ServiceWorkerRegistration to non-existent server-side registration");
     
    523524void SWServer::removeClientServiceWorkerRegistration(Connection& connection, ServiceWorkerRegistrationIdentifier identifier)
    524525{
    525     if (auto* registration = m_registrationsByID.get(identifier))
     526    if (auto* registration = m_registrations.get(identifier))
    526527        registration->removeClientServiceWorkerRegistration(connection.identifier());
    527528}
     
    574575    }
    575576
    576     auto* registration = m_registrations.get(data.registration.key);
    577     RELEASE_ASSERT(registration);
    578 
     577    auto* registration = m_scopeToRegistrationMap.get(data.registration.key).get();
    579578    auto worker = SWServerWorker::create(*this, *registration, data.scriptURL, data.script, data.contentSecurityPolicy, String { data.referrerPolicy }, data.workerType, data.serviceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript> { data.scriptResourceMap });
    580579
     
    626625        return false;
    627626
    628     // If the registration for a working has been removed then the request to run
     627    // If the registration for a worker has been removed then the request to run
    629628    // the worker is moot.
    630     if (!getRegistration(worker->registrationKey()))
     629    if (!worker->registration())
    631630        return false;
    632631
     
    749748{
    750749    SWServerRegistration* selectedRegistration = nullptr;
    751     for (auto& registration : m_registrations.values()) {
    752         if (!registration->key().isMatching(topOrigin, clientURL))
     750    for (auto& pair : m_scopeToRegistrationMap) {
     751        if (!pair.key.isMatching(topOrigin, clientURL))
    753752            continue;
    754         if (!selectedRegistration || selectedRegistration->key().scopeLength() < registration->key().scopeLength())
    755             selectedRegistration = registration.get();
    756     }
    757 
    758     return (selectedRegistration && !selectedRegistration->isUninstalling()) ? selectedRegistration : nullptr;
     753        if (!selectedRegistration || selectedRegistration->key().scopeLength() < pair.key.scopeLength())
     754            selectedRegistration = pair.value.get();
     755    }
     756
     757    return selectedRegistration;
    759758}
    760759
     
    764763    if (iterator == m_runningOrTerminatingWorkers.end())
    765764        return nullptr;
    766 
    767     return m_registrations.get(iterator->value->registrationKey());
     765    return iterator->value->registration();
    768766}
    769767
     
    795793        return;
    796794
    797     auto* controllingRegistration = m_registrationsByID.get(*controllingServiceWorkerRegistrationIdentifier);
     795    auto* controllingRegistration = m_registrations.get(*controllingServiceWorkerRegistrationIdentifier);
    798796    if (!controllingRegistration || !controllingRegistration->activeWorker())
    799797        return;
     
    851849        return;
    852850
    853     if (auto* registration = m_registrationsByID.get(registrationIterator->value))
     851    if (auto* registration = m_registrations.get(registrationIterator->value))
    854852        registration->removeClientUsingRegistration(clientIdentifier);
    855853
    856854    m_clientToControllingRegistration.remove(registrationIterator);
     855}
     856
     857void SWServer::removeFromScopeToRegistrationMap(const ServiceWorkerRegistrationKey& key)
     858{
     859    m_scopeToRegistrationMap.remove(key);
    857860}
    858861
     
    916919
    917920    HashSet<SecurityOriginData> originsWithRegistrations;
    918     for (auto& key : m_registrations.keys()) {
     921    for (auto& key : m_scopeToRegistrationMap.keys()) {
    919922        originsWithRegistrations.add(key.topOrigin());
    920923        originsWithRegistrations.add(SecurityOriginData { key.scope().protocol().toString(), key.scope().host().toString(), key.scope().port() });
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r249287 r249627  
    133133    WEBCORE_EXPORT SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
    134134    void addRegistration(std::unique_ptr<SWServerRegistration>&&);
    135     void removeRegistration(const ServiceWorkerRegistrationKey&);
     135    void removeRegistration(ServiceWorkerRegistrationIdentifier);
    136136    WEBCORE_EXPORT Vector<ServiceWorkerRegistrationData> getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL);
    137137
     
    194194    void disableServiceWorkerProcessTerminationDelay() { m_shouldDisableServiceWorkerProcessTerminationDelay = true; }
    195195
     196    void removeFromScopeToRegistrationMap(const ServiceWorkerRegistrationKey&);
     197
    196198private:
    197199    void scriptFetchFinished(Connection&, const ServiceWorkerFetchResult&);
     
    222224
    223225    HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>> m_connections;
    224     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerRegistration>> m_registrations;
    225     HashMap<ServiceWorkerRegistrationIdentifier, SWServerRegistration*> m_registrationsByID;
     226    HashMap<ServiceWorkerRegistrationKey, WeakPtr<SWServerRegistration>> m_scopeToRegistrationMap;
     227    HashMap<ServiceWorkerRegistrationIdentifier, std::unique_ptr<SWServerRegistration>> m_registrations;
    226228    HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerJobQueue>> m_jobQueues;
    227229
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp

    r249287 r249627  
    274274    // If registration is not null (in our parlance "empty"), then:
    275275    if (auto* registration = m_server.getRegistration(m_registrationKey)) {
    276         registration->setIsUninstalling(false);
    277276        auto* newestWorker = registration->getNewestWorker();
    278277        if (newestWorker && equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()) && job.registrationOptions.updateViaCache == registration->updateViaCache()) {
     
    307306
    308307    // If registration is null, then:
    309     if (!registration || registration->isUninstalling()) {
     308    if (!registration) {
    310309        // Invoke Resolve Job Promise with job and false.
    311310        m_server.resolveUnregistrationJob(job, m_registrationKey, false);
     
    313312        return;
    314313    }
    315 
    316     // Set registration's uninstalling flag.
    317     registration->setIsUninstalling(true);
     314   
     315    // Remove scope to registration map[job’s scope url].
     316    m_server.removeFromScopeToRegistrationMap(m_registrationKey);
    318317
    319318    // Invoke Resolve Job Promise with job and true.
     
    334333    if (!registration)
    335334        return rejectCurrentJob(ExceptionData { TypeError, "Cannot update a null/nonexistent service worker registration"_s });
    336     if (registration->isUninstalling())
    337         return rejectCurrentJob(ExceptionData { TypeError, "Cannot update a service worker registration that is uninstalling"_s });
    338335
    339336    // Let newestWorker be the result of running Get Newest Worker algorithm passing registration as the argument.
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp

    r249287 r249627  
    260260
    261261    // Remove scope to registration map[scopeString].
    262     m_server.removeRegistration(key());
     262    m_server.removeRegistration(identifier());
    263263}
    264264
     
    334334    if (hasClientsUsingRegistration())
    335335        return;
    336     if (isUninstalling() && tryClear())
     336    if (isUnregistered() && tryClear())
    337337        return;
    338338    tryActivate();
     339}
     340
     341bool SWServerRegistration::isUnregistered() const
     342{
     343    return m_server.getRegistration(key()) != this;
    339344}
    340345
     
    348353    identifiers.add(identifier.contextIdentifier);
    349354    m_server.connection(identifier.serverConnectionIdentifier)->notifyClientsOfControllerChange(identifiers, activeWorker()->data());
    350 }
    351 
    352 void SWServerRegistration::setIsUninstalling(bool value)
    353 {
    354     if (m_uninstalling == value)
    355         return;
    356 
    357     m_uninstalling = value;
    358 
    359     if (!m_uninstalling && activeWorker()) {
    360         // Registration with active worker has been resurrected, we need to check if any ready promises were waiting for this.
    361         m_server.resolveRegistrationReadyRequests(*this);
    362     }
    363355}
    364356
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.h

    r249287 r249627  
    3535#include <wtf/MonotonicTime.h>
    3636#include <wtf/WallTime.h>
     37#include <wtf/WeakPtr.h>
    3738
    3839namespace WebCore {
     
    4647struct ServiceWorkerFetchResult;
    4748
    48 class SWServerRegistration {
     49class SWServerRegistration : public CanMakeWeakPtr<SWServerRegistration> {
    4950    WTF_MAKE_FAST_ALLOCATED;
    5051public:
     
    5758    SWServerWorker* getNewestWorker();
    5859    WEBCORE_EXPORT ServiceWorkerRegistrationData data() const;
    59 
    60     bool isUninstalling() const { return m_uninstalling; }
    61     void setIsUninstalling(bool);
    6260
    6361    void setLastUpdateTime(WallTime);
     
    9593    void tryActivate();
    9694    void didFinishActivation(ServiceWorkerIdentifier);
     95   
     96    bool isUnregistered() const;
    9797
    9898    void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
     
    100100    WEBCORE_EXPORT bool shouldSoftUpdate(const FetchOptions&) const;
    101101    WEBCORE_EXPORT void softUpdate();
     102   
     103    String scopeURLWithoutFragment() const { return m_scopeURL; }
    102104
    103105private:
     
    111113    URL m_scriptURL;
    112114
    113     bool m_uninstalling { false };
    114115    RefPtr<SWServerWorker> m_preInstallationWorker; // Implementation detail, not part of the specification.
    115116    RefPtr<SWServerWorker> m_installingWorker;
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp

    r249287 r249627  
    5252    : m_server(makeWeakPtr(server))
    5353    , m_registrationKey(registration.key())
     54    , m_registration(makeWeakPtr(registration))
    5455    , m_data { identifier, scriptURL, ServiceWorkerState::Redundant, type, registration.identifier() }
    5556    , m_script(script)
     
    6465    ASSERT_UNUSED(result, result.isNewEntry);
    6566
    66     ASSERT(m_server->getRegistration(m_registrationKey));
     67    ASSERT(m_server->getRegistration(m_registrationKey) == &registration);
    6768}
    6869
     
    7778ServiceWorkerContextData SWServerWorker::contextData() const
    7879{
    79     auto* registration = m_server->getRegistration(m_registrationKey);
    80     ASSERT(registration);
    81 
    82     return { WTF::nullopt, registration->data(), m_data.identifier, m_script, m_contentSecurityPolicy, m_referrerPolicy, m_data.scriptURL, m_data.type, m_server->sessionID(), false, m_scriptResourceMap };
     80    ASSERT(m_registration);
     81
     82    return { WTF::nullopt, m_registration->data(), m_data.identifier, m_script, m_contentSecurityPolicy, m_referrerPolicy, m_data.scriptURL, m_data.type, m_server->sessionID(), false, m_scriptResourceMap };
    8383}
    8484
     
    178178    m_isSkipWaitingFlagSet = true;
    179179
    180     auto* registration = m_server->getRegistration(m_registrationKey);
    181     ASSERT(registration || isTerminating());
    182     if (registration)
    183         registration->tryActivate();
     180    ASSERT(m_registration || isTerminating());
     181    if (m_registration)
     182        m_registration->tryActivate();
    184183}
    185184
     
    194193
    195194    // Do tryClear/tryActivate, as per https://w3c.github.io/ServiceWorker/#wait-until-method.
    196     auto* registration = m_server->getRegistration(m_registrationKey);
    197     if (!registration)
    198         return;
    199 
    200     if (registration->isUninstalling() && registration->tryClear())
    201         return;
    202     registration->tryActivate();
     195    if (!m_registration)
     196        return;
     197
     198    if (m_registration->isUnregistered() && m_registration->tryClear())
     199        return;
     200    m_registration->tryActivate();
    203201}
    204202
     
    219217    m_data.state = state;
    220218
    221     auto* registration = m_server->getRegistration(m_registrationKey);
    222     ASSERT(registration || state == ServiceWorkerState::Redundant);
    223     if (registration) {
    224         registration->forEachConnection([&](auto& connection) {
     219    ASSERT(m_registration || state == ServiceWorkerState::Redundant);
     220    if (m_registration) {
     221        m_registration->forEachConnection([&](auto& connection) {
    225222            connection.updateWorkerStateInClient(this->identifier(), state);
    226223        });
     
    240237void SWServerWorker::setState(State state)
    241238{
    242     ASSERT(state != State::Running || m_server->getRegistration(m_registrationKey));
     239    ASSERT(state != State::Running || m_registration);
    243240    m_state = state;
    244241
     
    247244}
    248245
     246SWServerRegistration* SWServerWorker::registration() const
     247{
     248    return m_registration.get();
     249}
     250
    249251} // namespace WebCore
    250252
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.h

    r249287 r249627  
    114114
    115115    bool shouldSkipFetchEvent() const { return m_shouldSkipHandleFetch; }
     116   
     117    SWServerRegistration* registration() const;
    116118
    117119private:
     
    122124    WeakPtr<SWServer> m_server;
    123125    ServiceWorkerRegistrationKey m_registrationKey;
     126    WeakPtr<SWServerRegistration> m_registration;
    124127    ServiceWorkerData m_data;
    125128    String m_script;
Note: See TracChangeset for help on using the changeset viewer.