⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249287 in webkit


Ignore:
Timestamp:
Aug 29, 2019, 12:24:46 PM (7 years ago)
Author:
youenn@apple.com
Message:

Skip fetch event dispatching if no fetch event handler is added at script evaluation time
https://bugs.webkit.org/show_bug.cgi?id=201174

Reviewed by Chris Dumez.

Source/WebCore:

At end of worker script evaluation, store whether a fetch event handler is registered.
Send it back to the SWServer that will store it in the corresponding SWServerWorker.

Add support for soft update directly from the registration.
This will trigger a soft-update from the worker context itself.
In theory, this should be started by the job queue but we do not have a way yet to implement this as per spec.

Test: http/wpt/service-workers/skipFetchEvent.https.html

  • workers/DedicatedWorkerThread.h:

(WebCore::DedicatedWorkerThread::start):

  • workers/WorkerMessagingProxy.cpp:

(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):

  • workers/WorkerThread.cpp:

(WebCore::WorkerThread::workerThread):

  • workers/WorkerThread.h:

(WebCore::WorkerThread::finishedEvaluatingScript):

  • workers/service/context/SWContextManager.cpp:

(WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
(WebCore::SWContextManager::startedServiceWorker):
(WebCore::SWContextManager::softUpdate):

  • workers/service/context/SWContextManager.h:
  • workers/service/context/ServiceWorkerThread.cpp:

(WebCore::ServiceWorkerThread::postFetchTask):
(WebCore::ServiceWorkerThread::softUpdate):
(WebCore::ServiceWorkerThread::finishedEvaluatingScript):
(WebCore::ServiceWorkerThread::start):

  • workers/service/context/ServiceWorkerThread.h:

(WebCore::ServiceWorkerThread::doesHandleFetch const):

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

(WebCore::SWServerRegistration::shouldSoftUpdate const):
(WebCore::SWServerRegistration::softUpdate):

  • workers/service/server/SWServerRegistration.h:

(WebCore::SWServerRegistration::isStale const):

  • workers/service/server/SWServerToContextConnection.cpp:

(WebCore::SWServerToContextConnection::generateConnectionIdentifier):
(WebCore::SWServerToContextConnection::SWServerToContextConnection):
(WebCore::SWServerToContextConnection::scriptContextStarted):

  • workers/service/server/SWServerToContextConnection.h:
  • workers/service/server/SWServerWorker.cpp:

(WebCore::SWServerWorker::scriptContextStarted):
(WebCore::SWServerWorker::setState):

  • workers/service/server/SWServerWorker.h:

(WebCore::SWServerWorker::shouldSkipFetchEvent const):

Source/WebKit:

Store whether a fetch event handler is set at script evaluation time.
If not, we skip the fetch event entirely so that the network load can start sooner.
If fetch event is skipped, we trigger soft update, as defined in
https://w3c.github.io/ServiceWorker/#handle-fetch step 16.

  • NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::startFetch):

  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:

(WebKit::WebSWServerToContextConnection::softUpdate):

  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
  • NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
  • WebProcess/Storage/WebSWContextManagerConnection.cpp:

(WebKit::WebSWContextManagerConnection::serviceWorkerStarted):
(WebKit::WebSWContextManagerConnection::serviceWorkerFailedToStart):
(WebKit::WebSWContextManagerConnection::softUpdate):

  • WebProcess/Storage/WebSWContextManagerConnection.h:
  • WebProcess/Storage/WebSWContextManagerConnection.messages.in:

LayoutTests:

  • http/wpt/service-workers/skipFetchEvent-worker.js: Added.

(async.doTest):

  • http/wpt/service-workers/skipFetchEvent.https-expected.txt: Added.
  • http/wpt/service-workers/skipFetchEvent.https.html: Added.
Location:
trunk
Files:
3 added
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249278 r249287  
     12019-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        Skip fetch event dispatching if no fetch event handler is added at script evaluation time
     4        https://bugs.webkit.org/show_bug.cgi?id=201174
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/wpt/service-workers/skipFetchEvent-worker.js: Added.
     9        (async.doTest):
     10        * http/wpt/service-workers/skipFetchEvent.https-expected.txt: Added.
     11        * http/wpt/service-workers/skipFetchEvent.https.html: Added.
     12
    1132019-08-29  Alicia Boya García  <aboya@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r249286 r249287  
     12019-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        Skip fetch event dispatching if no fetch event handler is added at script evaluation time
     4        https://bugs.webkit.org/show_bug.cgi?id=201174
     5
     6        Reviewed by Chris Dumez.
     7
     8        At end of worker script evaluation, store whether a fetch event handler is registered.
     9        Send it back to the SWServer that will store it in the corresponding SWServerWorker.
     10
     11        Add support for soft update directly from the registration.
     12        This will trigger a soft-update from the worker context itself.
     13        In theory, this should be started by the job queue but we do not have a way yet to implement this as per spec.
     14
     15        Test: http/wpt/service-workers/skipFetchEvent.https.html
     16
     17        * workers/DedicatedWorkerThread.h:
     18        (WebCore::DedicatedWorkerThread::start):
     19        * workers/WorkerMessagingProxy.cpp:
     20        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
     21        * workers/WorkerThread.cpp:
     22        (WebCore::WorkerThread::workerThread):
     23        * workers/WorkerThread.h:
     24        (WebCore::WorkerThread::finishedEvaluatingScript):
     25        * workers/service/context/SWContextManager.cpp:
     26        (WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
     27        (WebCore::SWContextManager::startedServiceWorker):
     28        (WebCore::SWContextManager::softUpdate):
     29        * workers/service/context/SWContextManager.h:
     30        * workers/service/context/ServiceWorkerThread.cpp:
     31        (WebCore::ServiceWorkerThread::postFetchTask):
     32        (WebCore::ServiceWorkerThread::softUpdate):
     33        (WebCore::ServiceWorkerThread::finishedEvaluatingScript):
     34        (WebCore::ServiceWorkerThread::start):
     35        * workers/service/context/ServiceWorkerThread.h:
     36        (WebCore::ServiceWorkerThread::doesHandleFetch const):
     37        * workers/service/server/SWServer.h:
     38        * workers/service/server/SWServerRegistration.cpp:
     39        (WebCore::SWServerRegistration::shouldSoftUpdate const):
     40        (WebCore::SWServerRegistration::softUpdate):
     41        * workers/service/server/SWServerRegistration.h:
     42        (WebCore::SWServerRegistration::isStale const):
     43        * workers/service/server/SWServerToContextConnection.cpp:
     44        (WebCore::SWServerToContextConnection::generateConnectionIdentifier):
     45        (WebCore::SWServerToContextConnection::SWServerToContextConnection):
     46        (WebCore::SWServerToContextConnection::scriptContextStarted):
     47        * workers/service/server/SWServerToContextConnection.h:
     48        * workers/service/server/SWServerWorker.cpp:
     49        (WebCore::SWServerWorker::scriptContextStarted):
     50        (WebCore::SWServerWorker::setState):
     51        * workers/service/server/SWServerWorker.h:
     52        (WebCore::SWServerWorker::shouldSkipFetchEvent const):
     53
    1542019-08-29  Keith Rollin  <krollin@apple.com>
    255
  • trunk/Source/WebCore/workers/DedicatedWorkerThread.h

    r235159 r249287  
    4848
    4949    WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
     50    void start() { WorkerThread::start(nullptr); }
    5051
    5152protected:
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp

    r248846 r249287  
    9292
    9393    workerThreadCreated(thread.get());
    94     thread->start(nullptr);
     94    thread->start();
    9595
    9696    m_inspectorProxy->workerStarted(m_scriptExecutionContext.get(), thread.ptr(), scriptURL);
  • trunk/Source/WebCore/workers/WorkerThread.cpp

    r248846 r249287  
    194194    scriptController->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, URL(m_startupData->m_scriptURL)), &exceptionMessage);
    195195
     196    finishedEvaluatingScript();
     197
    196198    callOnMainThread([evaluateCallback = WTFMove(m_evaluateCallback), message = exceptionMessage.isolatedCopy()] {
    197199        if (evaluateCallback)
  • trunk/Source/WebCore/workers/WorkerThread.h

    r241739 r249287  
    6666    static Lock& workerThreadsMutex();
    6767
    68     WEBCORE_EXPORT void start(WTF::Function<void(const String&)>&& evaluateCallback);
    6968    void stop(WTF::Function<void()>&& terminatedCallback);
    7069
     
    105104    SocketProvider* socketProvider();
    106105
     106    void start(Function<void(const String&)>&& evaluateCallback);
     107
    107108private:
    108109    void workerThread();
    109110    virtual bool isServiceWorkerThread() const { return false; }
     111
     112    virtual void finishedEvaluatingScript() { }
    110113
    111114    RefPtr<Thread> m_thread;
  • trunk/Source/WebCore/workers/service/context/SWContextManager.cpp

    r248846 r249287  
    6060    ASSERT_UNUSED(result, result.isNewEntry);
    6161   
    62     threadProxy->thread().start([jobDataIdentifier, serviceWorkerIdentifier](const String& exceptionMessage) {
    63         SWContextManager::singleton().startedServiceWorker(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
     62    threadProxy->thread().start([jobDataIdentifier, serviceWorkerIdentifier](const String& exceptionMessage, bool doesHandleFetch) {
     63        SWContextManager::singleton().startedServiceWorker(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage, doesHandleFetch);
    6464    });
    6565}
    6666
    67 void SWContextManager::startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
     67void SWContextManager::startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage, bool doesHandleFetch)
    6868{
    69     connection()->serviceWorkerStartedWithMessage(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
    7069    if (m_serviceWorkerCreationCallback)
    7170        m_serviceWorkerCreationCallback(serviceWorkerIdentifier.toUInt64());
     71    if (!exceptionMessage.isEmpty()) {
     72        connection()->serviceWorkerFailedToStart(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
     73        return;
     74    }
     75    connection()->serviceWorkerStarted(jobDataIdentifier, serviceWorkerIdentifier, doesHandleFetch);
    7276}
    7377
     
    103107
    104108    serviceWorker->thread().fireActivateEvent();
     109}
     110
     111void SWContextManager::softUpdate(ServiceWorkerIdentifier identifier)
     112{
     113    auto* serviceWorker = m_workerMap.get(identifier);
     114    if (!serviceWorker)
     115        return;
     116
     117    serviceWorker->thread().softUpdate();
    105118}
    106119
  • trunk/Source/WebCore/workers/service/context/SWContextManager.h

    r245299 r249287  
    5151
    5252        virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&&, ServiceWorkerIdentifier source, const String& sourceOrigin) = 0;
    53         virtual void serviceWorkerStartedWithMessage(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage) = 0;
     53        virtual void serviceWorkerStarted(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool doesHandleFetch) = 0;
     54        virtual void serviceWorkerFailedToStart(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& message) = 0;
    5455        virtual void didFinishInstall(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool wasSuccessful) = 0;
    5556        virtual void didFinishActivation(ServiceWorkerIdentifier) = 0;
     
    7576    WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
    7677    WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
     78    WEBCORE_EXPORT void softUpdate(ServiceWorkerIdentifier);
    7779    WEBCORE_EXPORT void terminateWorker(ServiceWorkerIdentifier, Seconds timeout, Function<void()>&&);
    7880
     
    8991    SWContextManager() = default;
    9092
    91     void startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage);
     93    void startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage, bool doesHandleFetch);
    9294    NO_RETURN_DUE_TO_CRASH void serviceWorkerFailedToTerminate(ServiceWorkerIdentifier);
    9395
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp

    r246490 r249287  
    185185}
    186186
     187void ServiceWorkerThread::softUpdate()
     188{
     189    runLoop().postTask([](auto& context) mutable {
     190        auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
     191        serviceWorkerGlobalScope.registration().scheduleSoftUpdate();
     192    });
     193}
     194
     195void ServiceWorkerThread::finishedEvaluatingScript()
     196{
     197    m_doesHandleFetch = workerGlobalScope()->hasEventListeners(eventNames().fetchEvent);
     198}
     199
     200void ServiceWorkerThread::start(Function<void(const String&, bool)>&& callback)
     201{
     202    WorkerThread::start([callback = WTFMove(callback), serviceWorkerIdentifier = this->identifier()](auto& errorMessage) mutable {
     203        bool doesHandleFetch = true;
     204        if (auto* threadProxy = SWContextManager::singleton().workerByID(serviceWorkerIdentifier))
     205            doesHandleFetch = threadProxy->thread().doesHandleFetch();
     206        callback(errorMessage, doesHandleFetch);
     207    });
     208}
     209
    187210} // namespace WebCore
    188211
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h

    r239427 r249287  
    5656    WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
    5757
     58    void start(Function<void(const String&, bool)>&&);
    5859    WEBCORE_EXPORT void postFetchTask(Ref<ServiceWorkerFetch::Client>&&, Optional<ServiceWorkerClientIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&);
    5960    WEBCORE_EXPORT void postMessageToServiceWorker(MessageWithMessagePorts&&, ServiceWorkerOrClientData&& sourceData);
     
    6162    void fireInstallEvent();
    6263    void fireActivateEvent();
     64    void softUpdate();
    6365
    6466    const ServiceWorkerContextData& contextData() const { return m_data; }
    6567
    6668    ServiceWorkerIdentifier identifier() const { return m_data.serviceWorkerIdentifier; }
     69    bool doesHandleFetch() const { return m_doesHandleFetch; }
    6770
    6871protected:
     
    7477
    7578    bool isServiceWorkerThread() const final { return true; }
     79    void finishedEvaluatingScript() final;
    7680
    7781    ServiceWorkerContextData m_data;
    7882    WorkerObjectProxy& m_workerObjectProxy;
     83    bool m_doesHandleFetch { false };
    7984};
    8085
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r247104 r249287  
    131131    WEBCORE_EXPORT void endSuspension();
    132132
    133     SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
     133    WEBCORE_EXPORT SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
    134134    void addRegistration(std::unique_ptr<SWServerRegistration>&&);
    135135    void removeRegistration(const ServiceWorkerRegistrationKey&);
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp

    r248846 r249287  
    351351    //   current time minus registration's last update check time is greater than 86400.
    352352    if (registration->updateViaCache() != ServiceWorkerUpdateViaCache::All
    353         || (newestWorker && registration->lastUpdateTime() && (WallTime::now() - registration->lastUpdateTime()) > 86400_s)) {
     353        || (newestWorker && registration->isStale())) {
    354354        cachePolicy = FetchOptions::Cache::NoCache;
    355355    }
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp

    r240661 r249287  
    363363}
    364364
     365bool SWServerRegistration::shouldSoftUpdate(const FetchOptions& options) const
     366{
     367    if (options.mode == FetchOptions::Mode::Navigate)
     368        return true;
     369
     370    return WebCore::isNonSubresourceRequest(options.destination) && isStale();
     371}
     372
     373// https://w3c.github.io/ServiceWorker/#soft-update
     374void SWServerRegistration::softUpdate()
     375{
     376    auto* worker = getNewestWorker();
     377    if (!worker)
     378        return;
     379
     380    // FIXME: We should schedule an update job.
     381    m_server.runServiceWorkerIfNecessary(worker->identifier(), [serviceWorkerIdentifier = worker->identifier()](auto* contextConnection) {
     382        if (contextConnection)
     383            contextConnection->softUpdate(serviceWorkerIdentifier);
     384    });
     385}
     386
    365387} // namespace WebCore
    366388
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.h

    r237110 r249287  
    6363    void setLastUpdateTime(WallTime);
    6464    WallTime lastUpdateTime() const { return m_lastUpdateTime; }
     65    bool isStale() const { return m_lastUpdateTime && (WallTime::now() - m_lastUpdateTime) > 86400_s; }
    6566
    6667    void setUpdateViaCache(ServiceWorkerUpdateViaCache);
     
    9798    void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
    9899
     100    WEBCORE_EXPORT bool shouldSoftUpdate(const FetchOptions&) const;
     101    WEBCORE_EXPORT void softUpdate();
     102
    99103private:
    100104    void activate();
  • trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp

    r244115 r249287  
    7272}
    7373
    74 void SWServerToContextConnection::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
     74void SWServerToContextConnection::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch)
    7575{
    7676    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
    77         worker->scriptContextStarted(jobDataIdentifier);
     77        worker->scriptContextStarted(jobDataIdentifier, doesHandleFetch);
    7878}
    7979   
  • trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h

    r245299 r249287  
    5757    virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
    5858    virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
     59    virtual void softUpdate(ServiceWorkerIdentifier) = 0;
    5960    virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
    6061    virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0;
     
    6667    // Messages back from the SW host process
    6768    WEBCORE_EXPORT void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, const String& message);
    68     WEBCORE_EXPORT void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier);
     69    WEBCORE_EXPORT void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool doesHandleFetch);
    6970    WEBCORE_EXPORT void didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool wasSuccessful);
    7071    WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier);
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp

    r247705 r249287  
    109109}
    110110
    111 void SWServerWorker::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier)
    112 {
     111void SWServerWorker::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, bool doesHandleFetch)
     112{
     113    m_shouldSkipHandleFetch = !doesHandleFetch;
    113114    ASSERT(m_server);
    114115    if (m_server)
     
    241242    ASSERT(state != State::Running || m_server->getRegistration(m_registrationKey));
    242243    m_state = state;
     244
     245    if (state == State::Running)
     246        m_shouldSkipHandleFetch = false;
    243247}
    244248
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.h

    r247705 r249287  
    8989
    9090    void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, const String& message);
    91     void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&);
     91    void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, bool doesHandleFetch);
    9292    void didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>&, bool wasSuccessful);
    9393    void didFinishActivation();
     
    113113    String userAgent() const;
    114114
     115    bool shouldSkipFetchEvent() const { return m_shouldSkipHandleFetch; }
     116
    115117private:
    116118    SWServerWorker(SWServer&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, String&& referrerPolicy, WorkerType, ServiceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&);
     
    131133    Vector<Function<void(bool)>> m_whenActivatedHandlers;
    132134    HashMap<URL, ServiceWorkerContextData::ImportedScript> m_scriptResourceMap;
     135    bool m_shouldSkipHandleFetch;
    133136};
    134137
  • trunk/Source/WebKit/ChangeLog

    r249286 r249287  
     12019-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        Skip fetch event dispatching if no fetch event handler is added at script evaluation time
     4        https://bugs.webkit.org/show_bug.cgi?id=201174
     5
     6        Reviewed by Chris Dumez.
     7
     8        Store whether a fetch event handler is set at script evaluation time.
     9        If not, we skip the fetch event entirely so that the network load can start sooner.
     10        If fetch event is skipped, we trigger soft update, as defined in
     11        https://w3c.github.io/ServiceWorker/#handle-fetch step 16.
     12
     13        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
     14        (WebKit::WebSWServerConnection::startFetch):
     15        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
     16        (WebKit::WebSWServerToContextConnection::softUpdate):
     17        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
     18        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
     19        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
     20        (WebKit::WebSWContextManagerConnection::serviceWorkerStarted):
     21        (WebKit::WebSWContextManagerConnection::serviceWorkerFailedToStart):
     22        (WebKit::WebSWContextManagerConnection::softUpdate):
     23        * WebProcess/Storage/WebSWContextManagerConnection.h:
     24        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
     25
    1262019-08-29  Keith Rollin  <krollin@apple.com>
    227
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp

    r245796 r249287  
    184184            m_networkProcess->createServerToContextConnection(worker->registrableDomain(), server().sessionID());
    185185
    186         server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = WTFMove(weakThis), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer)](auto* contextConnection) {
     186        server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = WTFMove(weakThis), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer), shouldSkipFetchEvent = worker->shouldSkipFetchEvent()](auto* contextConnection) {
    187187            if (!weakThis)
    188188                return;
     
    198198    };
    199199
     200    if (worker->shouldSkipFetchEvent()) {
     201        m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidNotHandle { }, fetchIdentifier);
     202        auto* registration = server().getRegistration(worker->registrationKey());
     203        if (registration && registration->shouldSoftUpdate(options))
     204            registration->softUpdate();
     205        return;
     206    }
     207
    200208    if (worker->state() == ServiceWorkerState::Activating) {
    201209        worker->whenActivated(WTFMove(runServerWorkerAndStartFetch));
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp

    r245299 r249287  
    7979{
    8080    send(Messages::WebSWContextManagerConnection::FireActivateEvent(serviceWorkerIdentifier));
     81}
     82
     83void WebSWServerToContextConnection::softUpdate(ServiceWorkerIdentifier serviceWorkerIdentifier)
     84{
     85    send(Messages::WebSWContextManagerConnection::SoftUpdate(serviceWorkerIdentifier));
    8186}
    8287
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h

    r245299 r249287  
    8787    void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
    8888    void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
     89    void softUpdate(WebCore::ServiceWorkerIdentifier) final;
    8990    void terminateWorker(WebCore::ServiceWorkerIdentifier) final;
    9091    void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in

    r239427 r249287  
    2727
    2828    ScriptContextFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message);
    29     ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
     29    ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch);
    3030    DidFinishInstall(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful);
    3131    DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier);
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp

    r248846 r249287  
    176176}
    177177
    178 void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
    179 {
    180     if (exceptionMessage.isEmpty())
    181         m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted(jobDataIdentifier, serviceWorkerIdentifier), 0);
    182     else
    183         m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextFailedToStart(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage), 0);
     178void WebSWContextManagerConnection::serviceWorkerStarted(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch)
     179{
     180    m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted { jobDataIdentifier, serviceWorkerIdentifier, doesHandleFetch }, 0);
     181}
     182
     183void WebSWContextManagerConnection::serviceWorkerFailedToStart(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
     184{
     185    m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextFailedToStart { jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage }, 0);
    184186}
    185187
     
    262264}
    263265
     266void WebSWContextManagerConnection::softUpdate(WebCore::ServiceWorkerIdentifier identifier)
     267{
     268    SWContextManager::singleton().softUpdate(identifier);
     269}
     270
    264271void WebSWContextManagerConnection::terminateWorker(ServiceWorkerIdentifier identifier)
    265272{
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

    r245796 r249287  
    7777
    7878    // IPC messages.
    79     void serviceWorkerStartedWithMessage(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
     79    void serviceWorkerStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, bool doesHandleFetch) final;
     80    void serviceWorkerFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
    8081    void installServiceWorker(const WebCore::ServiceWorkerContextData&, PAL::SessionID, String&& userAgent);
    8182    void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer);
     
    8586    void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
    8687    void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
     88    void softUpdate(WebCore::ServiceWorkerIdentifier);
    8789    void terminateWorker(WebCore::ServiceWorkerIdentifier);
    8890    void syncTerminateWorker(WebCore::ServiceWorkerIdentifier, Messages::WebSWContextManagerConnection::SyncTerminateWorker::DelayedReply&&);
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

    r245299 r249287  
    3131    FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
    3232    FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
     33    SoftUpdate(WebCore::ServiceWorkerIdentifier identifier)
    3334    TerminateWorker(WebCore::ServiceWorkerIdentifier identifier)
    3435    SyncTerminateWorker(WebCore::ServiceWorkerIdentifier identifier) -> () Synchronous
Note: See TracChangeset for help on using the changeset viewer.