Changeset 221392 in webkit


Ignore:
Timestamp:
Aug 30, 2017 12:40:35 PM (7 years ago)
Author:
beidson@apple.com
Message:

Implement all of "Register" right up until where the script is fetched.
https://bugs.webkit.org/show_bug.cgi?id=176082

Reviewed by Andy Estes.

Source/WebCore:

Test: http/tests/workers/service/basic-register-exceptions.html

This patch implements every detail of the "Register" and "Update" algorithms right up to
where we would actually fetch the service worker script file.

It also includes miscellaneous refactoring and cleanup along the way.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • page/SecurityOrigin.cpp:

(WebCore::shouldTreatAsPotentiallyTrustworthy): Expose in the header for other files to use.

  • page/SecurityOrigin.h:
  • workers/service/ServiceWorkerContainer.cpp:

(WebCore::ServiceWorkerContainer::addRegistration): Add some more exception cases from the spec.
(WebCore::ServiceWorkerContainer::scheduleJob): Use the correct job identifier.
(WebCore::ServiceWorkerContainer::jobFailedWithException):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
(WebCore::ServiceWorkerContainer::jobDidFinish):

  • workers/service/ServiceWorkerContainer.h:
  • workers/service/ServiceWorkerJob.cpp:

(WebCore::ServiceWorkerJob::ServiceWorkerJob):
(WebCore::ServiceWorkerJob::failedWithException): Call through to the client to handle the failure.
(WebCore::ServiceWorkerJob::resolvedWithRegistration): Call through to the client to handle success.

  • workers/service/ServiceWorkerJob.h:

(WebCore::ServiceWorkerJob::promise):
(WebCore::ServiceWorkerJob::identifier const): Deleted. Rely on the identifier from the JobData.

  • workers/service/ServiceWorkerJobClient.h:
  • workers/service/ServiceWorkerJobData.cpp:

(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
(WebCore::ServiceWorkerJobData::isolatedCopy const):

  • workers/service/ServiceWorkerJobData.h:

(WebCore::ServiceWorkerJobData::identifier const):
(WebCore::ServiceWorkerJobData::encode const):
(WebCore::ServiceWorkerJobData::decode):
(WebCore::ServiceWorkerJobData::jobIdentifier const): Deleted.

  • workers/service/ServiceWorkerRegistration.cpp:

(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration): Make this class an ActiveDOMObject

both because it *is* an active DOM object and because we need to get at the ScriptExecutionContext.

  • workers/service/ServiceWorkerRegistration.h:

Add a class to encapsulate everything about a registration for encode/decode/crossthread:

  • workers/service/ServiceWorkerRegistrationData.cpp:

(WebCore::ServiceWorkerRegistrationData::isolatedCopy const):

  • workers/service/ServiceWorkerRegistrationData.h:

(WebCore::ServiceWorkerRegistrationData::encode const):
(WebCore::ServiceWorkerRegistrationData::decode):

  • workers/service/ServiceWorkerRegistrationKey.cpp:

(WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):

  • workers/service/ServiceWorkerRegistrationKey.h:

(WebCore::ServiceWorkerRegistrationKey::encode const):
(WebCore::ServiceWorkerRegistrationKey::decode):

  • workers/service/server/SWClientConnection.cpp:

(WebCore::SWClientConnection::scheduleJob):
(WebCore::SWClientConnection::jobResolvedInServer):

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

(WebCore::SWServer::~SWServer):
(WebCore::SWServer::Connection::scheduleJobInServer):
(WebCore::SWServer::scheduleJob):
(WebCore::SWServer::rejectJob):
(WebCore::SWServer::resolveJob):

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

(WebCore::SWServerRegistration::SWServerRegistration):
(WebCore::SWServerRegistration::startNextJob):
(WebCore::SWServerRegistration::isEmpty):
(WebCore::SWServerRegistration::getNewestWorker): Implement "Get Newest Worker" algorithm.
(WebCore::SWServerRegistration::runRegisterJob): Implement the rest of the "Register" algorithm.
(WebCore::SWServerRegistration::runUpdateJob): Implement every part of "Update" up to where we would fetch.
(WebCore::SWServerRegistration::rejectWithExceptionOnMainThread):
(WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread):
(WebCore::SWServerRegistration::resolveCurrentJob):
(WebCore::SWServerRegistration::data const):
(WebCore::SWServerRegistration::performCurrentJob): Deleted.

  • workers/service/server/SWServerRegistration.h:

(WebCore::SWServerRegistration::identifier const):

Add a stub class to represent "active service workers" in the SWServer:

  • workers/service/server/SWServerWorker.cpp:

(WebCore::SWServerWorker::SWServerWorker):
(WebCore::SWServerWorker::~SWServerWorker):

  • workers/service/server/SWServerWorker.h:

(WebCore::SWServerWorker::scriptURL const):

Source/WebKit:

  • StorageProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::resolveJobInClient):

  • StorageProcess/ServiceWorker/WebSWServerConnection.h:
  • WebProcess/Storage/WebSWClientConnection.messages.in:

LayoutTests:

  • http/tests/workers/service/basic-register-exceptions-expected.txt: Added.
  • http/tests/workers/service/basic-register-exceptions.html: Added.
  • http/tests/workers/service/resources/basic-register-exceptions.js: Added.
Location:
trunk
Files:
3 added
27 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221386 r221392  
     12017-08-30  Brady Eidson  <beidson@apple.com>
     2
     3        Implement all of "Register" right up until where the script is fetched.
     4        https://bugs.webkit.org/show_bug.cgi?id=176082
     5
     6        Reviewed by Andy Estes.
     7
     8        * http/tests/workers/service/basic-register-exceptions-expected.txt: Added.
     9        * http/tests/workers/service/basic-register-exceptions.html: Added.
     10        * http/tests/workers/service/resources/basic-register-exceptions.js: Added.
     11
    1122017-08-22  Matt Rajca  <mrajca@apple.com>
    213
  • trunk/Source/WebCore/CMakeLists.txt

    r221340 r221392  
    30203020    workers/service/ServiceWorkerProvider.cpp
    30213021    workers/service/ServiceWorkerRegistration.cpp
     3022    workers/service/ServiceWorkerRegistrationData.cpp
    30223023    workers/service/ServiceWorkerRegistrationKey.cpp
    30233024    workers/service/ServiceWorkerRegistrationOptions.cpp
     
    30263027    workers/service/server/SWServer.cpp
    30273028    workers/service/server/SWServerRegistration.cpp
     3029    workers/service/server/SWServerWorker.cpp
    30283030
    30293031    xml/DOMParser.cpp
  • trunk/Source/WebCore/ChangeLog

    r221387 r221392  
     12017-08-30  Brady Eidson  <beidson@apple.com>
     2
     3        Implement all of "Register" right up until where the script is fetched.
     4        https://bugs.webkit.org/show_bug.cgi?id=176082
     5
     6        Reviewed by Andy Estes.
     7
     8        Test: http/tests/workers/service/basic-register-exceptions.html
     9
     10        This patch implements every detail of the "Register" and "Update" algorithms right up to
     11        where we would actually fetch the service worker script file.
     12
     13        It also includes miscellaneous refactoring and cleanup along the way.
     14
     15        * CMakeLists.txt:
     16        * WebCore.xcodeproj/project.pbxproj:
     17
     18        * page/SecurityOrigin.cpp:
     19        (WebCore::shouldTreatAsPotentiallyTrustworthy): Expose in the header for other files to use.
     20        * page/SecurityOrigin.h:
     21
     22        * workers/service/ServiceWorkerContainer.cpp:
     23        (WebCore::ServiceWorkerContainer::addRegistration): Add some more exception cases from the spec.
     24        (WebCore::ServiceWorkerContainer::scheduleJob): Use the correct job identifier.
     25        (WebCore::ServiceWorkerContainer::jobFailedWithException):
     26        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
     27        (WebCore::ServiceWorkerContainer::jobDidFinish):
     28        * workers/service/ServiceWorkerContainer.h:
     29
     30        * workers/service/ServiceWorkerJob.cpp:
     31        (WebCore::ServiceWorkerJob::ServiceWorkerJob):
     32        (WebCore::ServiceWorkerJob::failedWithException): Call through to the client to handle the failure.
     33        (WebCore::ServiceWorkerJob::resolvedWithRegistration): Call through to the client to handle success.
     34        * workers/service/ServiceWorkerJob.h:
     35        (WebCore::ServiceWorkerJob::promise):
     36        (WebCore::ServiceWorkerJob::identifier const): Deleted. Rely on the identifier from the JobData.
     37
     38        * workers/service/ServiceWorkerJobClient.h:
     39
     40        * workers/service/ServiceWorkerJobData.cpp:
     41        (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
     42        (WebCore::ServiceWorkerJobData::isolatedCopy const):
     43        * workers/service/ServiceWorkerJobData.h:
     44        (WebCore::ServiceWorkerJobData::identifier const):
     45        (WebCore::ServiceWorkerJobData::encode const):
     46        (WebCore::ServiceWorkerJobData::decode):
     47        (WebCore::ServiceWorkerJobData::jobIdentifier const): Deleted.
     48
     49        * workers/service/ServiceWorkerRegistration.cpp:
     50        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration): Make this class an ActiveDOMObject
     51          both because it *is* an active DOM object and because we need to get at the ScriptExecutionContext.
     52        * workers/service/ServiceWorkerRegistration.h:
     53
     54        Add a class to encapsulate everything about a registration for encode/decode/crossthread:
     55        * workers/service/ServiceWorkerRegistrationData.cpp:
     56        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
     57        * workers/service/ServiceWorkerRegistrationData.h:
     58        (WebCore::ServiceWorkerRegistrationData::encode const):
     59        (WebCore::ServiceWorkerRegistrationData::decode):
     60
     61        * workers/service/ServiceWorkerRegistrationKey.cpp:
     62        (WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
     63        * workers/service/ServiceWorkerRegistrationKey.h:
     64        (WebCore::ServiceWorkerRegistrationKey::encode const):
     65        (WebCore::ServiceWorkerRegistrationKey::decode):
     66
     67        * workers/service/server/SWClientConnection.cpp:
     68        (WebCore::SWClientConnection::scheduleJob):
     69        (WebCore::SWClientConnection::jobResolvedInServer):
     70        * workers/service/server/SWClientConnection.h:
     71
     72        * workers/service/server/SWServer.cpp:
     73        (WebCore::SWServer::~SWServer):
     74        (WebCore::SWServer::Connection::scheduleJobInServer):
     75        (WebCore::SWServer::scheduleJob):
     76        (WebCore::SWServer::rejectJob):
     77        (WebCore::SWServer::resolveJob):
     78        * workers/service/server/SWServer.h:
     79
     80        * workers/service/server/SWServerRegistration.cpp:
     81        (WebCore::SWServerRegistration::SWServerRegistration):
     82        (WebCore::SWServerRegistration::startNextJob):
     83        (WebCore::SWServerRegistration::isEmpty):
     84        (WebCore::SWServerRegistration::getNewestWorker): Implement "Get Newest Worker" algorithm.
     85        (WebCore::SWServerRegistration::runRegisterJob): Implement the rest of the "Register" algorithm.
     86        (WebCore::SWServerRegistration::runUpdateJob): Implement every part of "Update" up to where we would fetch.
     87        (WebCore::SWServerRegistration::rejectWithExceptionOnMainThread):
     88        (WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread):
     89        (WebCore::SWServerRegistration::resolveCurrentJob):
     90        (WebCore::SWServerRegistration::data const):
     91        (WebCore::SWServerRegistration::performCurrentJob): Deleted.
     92        * workers/service/server/SWServerRegistration.h:
     93        (WebCore::SWServerRegistration::identifier const):
     94
     95        Add a stub class to represent "active service workers" in the SWServer:
     96        * workers/service/server/SWServerWorker.cpp:
     97        (WebCore::SWServerWorker::SWServerWorker):
     98        (WebCore::SWServerWorker::~SWServerWorker):
     99        * workers/service/server/SWServerWorker.h:
     100        (WebCore::SWServerWorker::scriptURL const):
     101
    11022017-08-30  Don Olmstead  <don.olmstead@sony.com>
    2103
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r221329 r221392  
    23022302                517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */; };
    23032303                517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2304                517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53431F50C16100DCDC0A /* SWServerWorker.cpp */; };
     2305                517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53421F50C16100DCDC0A /* SWServerWorker.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2306                517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; };
     2307                517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    23042308                517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
    23052309                517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; };
     
    1012310127                517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationKey.h; sourceTree = "<group>"; };
    1012410128                517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationKey.cpp; sourceTree = "<group>"; };
     10129                517A53421F50C16100DCDC0A /* SWServerWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWServerWorker.h; sourceTree = "<group>"; };
     10130                517A53431F50C16100DCDC0A /* SWServerWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServerWorker.cpp; sourceTree = "<group>"; };
     10131                517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationData.cpp; sourceTree = "<group>"; };
     10132                517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationData.h; sourceTree = "<group>"; };
    1012510133                517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; };
    1012610134                517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; };
     
    1875918767                                51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
    1876018768                                51F645941F4A684F00B54DED /* SWServerRegistration.h */,
     18769                                517A53431F50C16100DCDC0A /* SWServerWorker.cpp */,
     18770                                517A53421F50C16100DCDC0A /* SWServerWorker.h */,
    1876118771                        );
    1876218772                        path = server;
     
    1886418874                                51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */,
    1886518875                                51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */,
     18876                                517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */,
     18877                                517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */,
    1886618878                                517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */,
    1886718879                                517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */,
     
    2971029722                                51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */,
    2971129723                                51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */,
     29724                                517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */,
    2971229725                                517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
    2971329726                                51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
     
    3013130144                                517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
    3013230145                                51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
     30146                                517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */,
    3013330147                                E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
    3013430148                                26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
     
    3360133615                                51F175651F3EBC8300C74950 /* ServiceWorkerProvider.cpp in Sources */,
    3360233616                                51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */,
     33617                                517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */,
    3360333618                                517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
    3360433619                                51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
     
    3390833923                                517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
    3390933924                                51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
     33925                                517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */,
    3391033926                                E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
    3391133927                                E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */,
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r221334 r221392  
    124124
    125125// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy (Editor's Draft, 17 November 2016)
    126 static bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
     126bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
    127127{
    128128    if (!url.isValid())
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r221334 r221392  
    235235};
    236236
     237bool shouldTreatAsPotentiallyTrustworthy(const URL&);
     238
    237239// Returns true if the Origin header values serialized from these two origins would be the same.
    238240bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp

    r221198 r221392  
    3030
    3131#include "Exception.h"
     32#include "IDLTypes.h"
    3233#include "JSDOMPromiseDeferred.h"
     34#include "JSServiceWorkerRegistration.h"
    3335#include "NavigatorBase.h"
     36#include "ScopeGuard.h"
    3437#include "ScriptExecutionContext.h"
    3538#include "SecurityOrigin.h"
     
    105108    String path = jobData.scriptURL.path();
    106109    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
    107         promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%%2f' or '%%5c'") });
     110        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'") });
    108111        return;
    109112    }
     
    113116        jobData.scopeURL = context->completeURL(scope);
    114117
     118    if (!jobData.scopeURL.isNull() && !jobData.scopeURL.protocolIsInHTTPFamily()) {
     119        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });
     120        return;
     121    }
     122
     123    path = jobData.scopeURL.path();
     124    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
     125        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'") });
     126        return;
     127    }
     128
    115129    jobData.clientCreationURL = context->url();
    116130    jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
    117131    jobData.type = ServiceWorkerJobType::Register;
    118     jobData.registrationOptions = std::make_unique<RegistrationOptions>(options);
     132    jobData.registrationOptions = options;
    119133
    120134    scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData)));
     
    126140
    127141    ServiceWorkerJob& rawJob = job.get();
    128     auto result = m_jobMap.add(rawJob.identifier(), WTFMove(job));
     142    auto result = m_jobMap.add(rawJob.data().identifier(), WTFMove(job));
    129143    ASSERT_UNUSED(result, result.isNewEntry);
    130144
     
    146160}
    147161
     162void ServiceWorkerContainer::jobFailedWithException(ServiceWorkerJob& job, const Exception& exception)
     163{
     164    job.promise().reject(exception);
     165    jobDidFinish(job);
     166}
     167
     168void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, const ServiceWorkerRegistrationData& data)
     169{
     170    ScopeGuard guard([this, &job] {
     171        jobDidFinish(job);
     172    });
     173
     174    auto* context = scriptExecutionContext();
     175    if (!context) {
     176        LOG_ERROR("ServiceWorkerContainer::jobResolvedWithRegistration called but the containers ScriptExecutionContext is gone");
     177        return;
     178    }
     179
     180    auto registration = ServiceWorkerRegistration::create(*context, data);
     181    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
     182}
     183
    148184void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
    149185{
    150     auto taken = m_jobMap.take(job.identifier());
     186    auto taken = m_jobMap.take(job.data().identifier());
    151187    ASSERT_UNUSED(taken, taken.get() == &job);
    152188}
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h

    r221198 r221392  
    7171private:
    7272    void scheduleJob(Ref<ServiceWorkerJob>&&);
    73     void jobDidFinish(ServiceWorkerJob&) final;
     73
     74    void jobFailedWithException(ServiceWorkerJob&, const Exception&) final;
     75    void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) final;
     76    void jobDidFinish(ServiceWorkerJob&);
     77
    7478    uint64_t connectionIdentifier() final;
    7579
  • trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp

    r221198 r221392  
    3131#include "JSDOMPromiseDeferred.h"
    3232#include "ServiceWorkerJobData.h"
     33#include "ServiceWorkerRegistration.h"
    3334
    3435namespace WebCore {
    35 
    36 static std::atomic<uint64_t> currentIdentifier;
    3736
    3837ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
     
    4039    , m_jobData(WTFMove(jobData))
    4140    , m_promise(WTFMove(promise))
    42     , m_identifier(++currentIdentifier)
    4341{
    4442}
     
    5250{
    5351    ASSERT(currentThread() == m_creationThread);
     52    ASSERT(!m_completed);
    5453
     54    m_completed = true;
     55    m_client->jobFailedWithException(*this, exception);
     56}
     57
     58void ServiceWorkerJob::resolvedWithRegistration(const ServiceWorkerRegistrationData& data)
     59{
     60    ASSERT(currentThread() == m_creationThread);
    5561    ASSERT(!m_completed);
    56     m_promise->reject(exception);
     62
    5763    m_completed = true;
    58 
    59     // Can cause this to be deleted.
    60     m_client->jobDidFinish(*this);
     64    m_client->jobResolvedWithRegistration(*this, data);
    6165}
    6266
  • trunk/Source/WebCore/workers/service/ServiceWorkerJob.h

    r221198 r221392  
    4040class Exception;
    4141enum class ServiceWorkerJobType;
     42struct ServiceWorkerRegistrationData;
    4243
    4344class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {
     
    5051    WEBCORE_EXPORT ~ServiceWorkerJob();
    5152
    52     WEBCORE_EXPORT void failedWithException(const Exception&);
    53 
    54     uint64_t identifier() const { return m_identifier; }
     53    void failedWithException(const Exception&);
     54    void resolvedWithRegistration(const ServiceWorkerRegistrationData&);
    5555
    5656    ServiceWorkerJobData data() const { return m_jobData; }
     57    DeferredPromise& promise() { return m_promise.get(); }
    5758
    5859private:
     
    6465
    6566    bool m_completed { false };
    66     uint64_t m_identifier;
    6767
    6868    Ref<RunLoop> m_runLoop { RunLoop::current() };
  • trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h

    r221198 r221392  
    3030namespace WebCore {
    3131
     32class Exception;
    3233class ServiceWorkerJob;
     34struct ServiceWorkerRegistrationData;
    3335
    3436class ServiceWorkerJobClient {
     
    3638    virtual ~ServiceWorkerJobClient() { };
    3739
    38     virtual void jobDidFinish(ServiceWorkerJob&) = 0;
     40    virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0;
     41    virtual void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) = 0;
     42
    3943    virtual uint64_t connectionIdentifier() = 0;
    4044
  • trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp

    r221198 r221392  
    4848    scopeURL = other.scopeURL;
    4949    type = other.type;
    50 
    51     if (other.registrationOptions)
    52         registrationOptions = std::make_unique<RegistrationOptions>(*other.registrationOptions);
     50    registrationOptions = other.registrationOptions;
    5351}
    5452
     
    6967    result.topOrigin = topOrigin.isolatedCopy();
    7068    result.scopeURL = scopeURL.isolatedCopy();
     69    result.registrationOptions = registrationOptions.isolatedCopy();
    7170
    72     if (registrationOptions)
    73         result.registrationOptions = std::make_unique<RegistrationOptions>(registrationOptions->isolatedCopy());
    7471    return result;
    7572}
  • trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h

    r221198 r221392  
    4242    ServiceWorkerJobData() = default;
    4343
    44     uint64_t jobIdentifier() const { return m_jobIdentifier; }
     44    uint64_t identifier() const { return m_jobIdentifier; }
    4545    uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
    4646
     
    5151    ServiceWorkerJobType type;
    5252
    53     std::unique_ptr<RegistrationOptions> registrationOptions;
     53    RegistrationOptions registrationOptions;
    5454
    5555    ServiceWorkerRegistrationKey registrationKey() const;
     
    7171    switch (type) {
    7272    case ServiceWorkerJobType::Register:
    73         RELEASE_ASSERT(registrationOptions);
    74         encoder << *registrationOptions;
     73        encoder << registrationOptions;
    7574        break;
    7675    }
     
    9796    switch (jobData.type) {
    9897    case ServiceWorkerJobType::Register:
    99         jobData.registrationOptions = std::make_unique<RegistrationOptions>();
    100         if (!decoder.decode(*jobData.registrationOptions))
     98        if (!decoder.decode(jobData.registrationOptions))
    10199            return false;
    102100        break;
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp

    r220623 r221392  
    3030
    3131namespace WebCore {
     32
     33ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& registrationData)
     34    : ActiveDOMObject(&context)
     35    , m_registrationData(registrationData)
     36{
     37    suspendIfNeeded();
     38}
    3239
    3340ServiceWorker* ServiceWorkerRegistration::installing()
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h

    r220623 r221392  
    2828#if ENABLE(SERVICE_WORKER)
    2929
     30#include "ActiveDOMObject.h"
    3031#include "EventTarget.h"
    3132#include "JSDOMPromiseDeferred.h"
     33#include "ServiceWorkerRegistrationData.h"
    3234
    3335namespace WebCore {
    3436
    35 class Frame;
     37class ScriptExecutionContext;
    3638class ServiceWorker;
    3739
    38 class ServiceWorkerRegistration final : public EventTargetWithInlineData {
     40class ServiceWorkerRegistration final : public EventTargetWithInlineData, public ActiveDOMObject {
    3941public:
    4042    enum class UpdateViaCache {
     
    4446    };
    4547
    46     static Ref<ServiceWorkerRegistration> create(Frame& frame) { return adoptRef(*new ServiceWorkerRegistration(frame)); }
     48    static Ref<ServiceWorkerRegistration> create(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& data)
     49    {
     50        return adoptRef(*new ServiceWorkerRegistration(context, data));
     51    }
     52
    4753    virtual ~ServiceWorkerRegistration() = default;
    4854
     
    5864
    5965private:
    60     explicit ServiceWorkerRegistration(Frame&);
     66    ServiceWorkerRegistration(ScriptExecutionContext&, const ServiceWorkerRegistrationData&);
    6167
    6268    virtual EventTargetInterface eventTargetInterface() const;
     
    6470    void refEventTarget() final { ref(); }
    6571    void derefEventTarget() final { deref(); }
     72
     73    const char* activeDOMObjectName() const { return "ServiceWorkerRegistration"; }
     74    bool canSuspendForDocumentSuspension() const { return false; }
     75
     76    ServiceWorkerRegistrationData m_registrationData;
    6677};
    6778
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp

    r221388 r221392  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "ServiceWorkerRegistrationData.h"
    2728
    2829#if ENABLE(SERVICE_WORKER)
     
    3031namespace WebCore {
    3132
    32 class ServiceWorkerJob;
     33ServiceWorkerRegistrationData ServiceWorkerRegistrationData::isolatedCopy() const
     34{
     35    ServiceWorkerRegistrationData result;
     36    result.key = key.isolatedCopy();
     37    result.identifier = identifier;
     38    return result;
     39}
    3340
    34 class ServiceWorkerJobClient {
    35 public:
    36     virtual ~ServiceWorkerJobClient() { };
    37 
    38     virtual void jobDidFinish(ServiceWorkerJob&) = 0;
    39     virtual uint64_t connectionIdentifier() = 0;
    40 
    41     virtual void ref() = 0;
    42     virtual void deref() = 0;
    43 };
    44 
    45 } // namespace WebCore
     41} // namespace WTF
    4642
    4743#endif // ENABLE(SERVICE_WORKER)
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h

    r221388 r221392  
    2424 */
    2525
    26 #include "config.h"
    27 #include "ServiceWorkerRegistrationKey.h"
     26#pragma once
    2827
    2928#if ENABLE(SERVICE_WORKER)
    3029
    31 #include "URLHash.h"
     30#include "ServiceWorkerRegistrationKey.h"
    3231
    3332namespace WebCore {
    3433
    35 ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::emptyKey()
     34struct ServiceWorkerRegistrationData {
     35    ServiceWorkerRegistrationKey key;
     36    uint64_t identifier;
     37
     38    ServiceWorkerRegistrationData isolatedCopy() const;
     39
     40    template<class Encoder> void encode(Encoder&) const;
     41    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationData&);
     42};
     43
     44
     45template<class Encoder>
     46void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
    3647{
    37     return { };
     48    encoder << key << identifier;
    3849}
    3950
    40 unsigned ServiceWorkerRegistrationKey::hash() const
     51template<class Decoder>
     52bool ServiceWorkerRegistrationData::decode(Decoder& decoder, ServiceWorkerRegistrationData& data)
    4153{
    42     unsigned hashes[2];
    43     hashes[0] = URLHash::hash(clientCreationURL);
    44     hashes[1] = SecurityOriginDataHash::hash(topOrigin);
     54    if (!decoder.decode(data.key))
     55        return false;
     56    if (!decoder.decodeEnum(data.identifier))
     57        return false;
    4558
    46     return StringHasher::hashMemory(hashes, sizeof(hashes));
     59    return true;
    4760}
    4861
    49 bool ServiceWorkerRegistrationKey::operator==(const ServiceWorkerRegistrationKey& other) const
    50 {
    51     return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
    52 }
    53 
    54 } // namespace WebCore
     62} // namespace WTF
    5563
    5664#endif // ENABLE(SERVICE_WORKER)
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp

    r221198 r221392  
    5252}
    5353
     54ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::isolatedCopy() const
     55{
     56    ServiceWorkerRegistrationKey result;
     57    result.clientCreationURL = clientCreationURL.isolatedCopy();
     58    result.topOrigin = topOrigin.isolatedCopy();
     59    return result;
     60}
     61
    5462} // namespace WebCore
    5563
  • trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h

    r221198 r221392  
    4141
    4242    bool operator==(const ServiceWorkerRegistrationKey&) const;
     43
     44    ServiceWorkerRegistrationKey isolatedCopy() const;
     45
     46    template<class Encoder> void encode(Encoder&) const;
     47    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationKey&);
    4348};
     49
     50template<class Encoder>
     51void ServiceWorkerRegistrationKey::encode(Encoder& encoder) const
     52{
     53    encoder << clientCreationURL << topOrigin;
     54}
     55
     56template<class Decoder>
     57bool ServiceWorkerRegistrationKey::decode(Decoder& decoder, ServiceWorkerRegistrationKey& key)
     58{
     59    if (!decoder.decode(key.clientCreationURL))
     60        return false;
     61    if (!decoder.decode(key.topOrigin))
     62        return false;
     63
     64    return true;
     65}
    4466
    4567} // namespace WebCore
  • trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp

    r220977 r221392  
    4444void SWClientConnection::scheduleJob(ServiceWorkerJob& job)
    4545{
    46     auto addResult = m_scheduledJobs.add(job.identifier(), &job);
     46    auto addResult = m_scheduledJobs.add(job.data().identifier(), &job);
    4747    ASSERT_UNUSED(addResult, addResult.isNewEntry);
    4848
     
    6161}
    6262
     63void SWClientConnection::jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
     64{
     65    auto job = m_scheduledJobs.take(jobIdentifier);
     66    if (!job) {
     67        LOG_ERROR("Job %" PRIu64 " resolved in server, but was not found", jobIdentifier);
     68        return;
     69    }
     70
     71    job->resolvedWithRegistration(registrationData);
     72}
     73
    6374} // namespace WebCore
    6475
  • trunk/Source/WebCore/workers/service/server/SWClientConnection.h

    r221198 r221392  
    3535
    3636struct ExceptionData;
     37struct ServiceWorkerRegistrationData;
    3738
    3839class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> {
     
    4748protected:
    4849    WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&);
     50    WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&);
    4951
    5052private:
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r221198 r221392  
    5555    RELEASE_ASSERT(m_registrations.isEmpty());
    5656
     57    ASSERT(m_taskQueue.isEmpty());
     58    ASSERT(m_taskReplyQueue.isEmpty());
     59
    5760    // For a SWServer to be cleanly shut down its thread must have finished and gone away.
    5861    // At this stage in development of the feature that actually never happens.
     
    6467void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
    6568{
    66     LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
     69    LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
    6770    ASSERT(identifier() == jobData.connectionIdentifier());
    6871
     
    8386    auto result = m_registrations.add(jobData.registrationKey(), nullptr);
    8487    if (result.isNewEntry)
    85         result.iterator->value = std::make_unique<SWServerRegistration>(*this);
     88        result.iterator->value = std::make_unique<SWServerRegistration>(*this, jobData.registrationKey());
    8689
    8790    ASSERT(result.iterator->value);
     
    9295void SWServer::rejectJob(const ServiceWorkerJobData& jobData, const ExceptionData& exceptionData)
    9396{
    94     LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
     97    LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
    9598    auto* connection = m_connections.get(jobData.connectionIdentifier());
    9699    if (!connection)
    97100        return;
    98101
    99     connection->rejectJobInClient(jobData.jobIdentifier(), exceptionData);
     102    connection->rejectJobInClient(jobData.identifier(), exceptionData);
     103}
     104
     105void SWServer::resolveJob(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationData& registrationData)
     106{
     107    LOG(ServiceWorker, "Resolved ServiceWorker job %" PRIu64 "-%" PRIu64 " in server with registration %" PRIu64, jobData.connectionIdentifier(), jobData.identifier(), registrationData.identifier);
     108    auto* connection = m_connections.get(jobData.connectionIdentifier());
     109    if (!connection)
     110        return;
     111
     112    connection->resolveJobInClient(jobData.identifier(), registrationData);
    100113}
    101114
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r221198 r221392  
    4343class SWServerRegistration;
    4444struct ExceptionData;
     45struct ServiceWorkerRegistrationData;
    4546
    4647class SWServer {
     
    6162    private:
    6263        virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0;
     64        virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0;
    6365
    6466        SWServer& m_server;
     
    7173    void scheduleJob(const ServiceWorkerJobData&);
    7274    void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
    73 
     75    void resolveJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&);
    7476    void postTask(CrossThreadTask&&);
    7577    void postTaskReply(CrossThreadTask&&);
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp

    r221198 r221392  
    3131#include "ExceptionData.h"
    3232#include "SWServer.h"
     33#include "SWServerWorker.h"
     34#include "SecurityOrigin.h"
     35#include "ServiceWorkerRegistrationData.h"
     36#include "WorkerType.h"
    3337
    3438namespace WebCore {
    3539
    36 SWServerRegistration::SWServerRegistration(SWServer& server)
     40static std::atomic<uint64_t> currentIdentifier;
     41
     42SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key)
    3743    : m_jobTimer(*this, &SWServerRegistration::startNextJob)
    3844    , m_server(server)
     45    , m_identifier(++currentIdentifier)
     46    , m_registrationKey(key)
    3947{
    4048}
     
    6674
    6775    m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst().isolatedCopy());
    68     m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::performCurrentJob));
    69 }
    70 
    71 void SWServerRegistration::performCurrentJob()
    72 {
    73     ASSERT(!isMainThread());
    74 
    75     auto exception = ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") };
     76
     77    switch (m_currentJob->type) {
     78    case ServiceWorkerJobType::Register:
     79        m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::runRegisterJob, *m_currentJob));
     80        return;
     81    }
     82
     83    RELEASE_ASSERT_NOT_REACHED();
     84}
     85
     86bool SWServerRegistration::isEmpty()
     87{
     88    ASSERT(!isMainThread());
     89
     90    // Having or not-having an m_updateViaCache flag is currently
     91    // the signal as to whether or not this is an empty (i.e. "new") registration.
     92    // There will be a more explicit signal in the near future.
     93    return !m_updateViaCache;
     94}
     95
     96SWServerWorker* SWServerRegistration::getNewestWorker()
     97{
     98    ASSERT(!isMainThread());
     99    if (m_installingWorker)
     100        return m_installingWorker.get();
     101    if (m_waitingWorker)
     102        return m_waitingWorker.get();
     103
     104    return m_activeWorker.get();
     105}
     106
     107void SWServerRegistration::runRegisterJob(const ServiceWorkerJobData& job)
     108{
     109    ASSERT(!isMainThread());
     110    ASSERT(job.type == ServiceWorkerJobType::Register);
     111
     112    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL))
     113        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") });
     114
     115    // If the origin of job’s script url is not job’s referrer's origin, then:
     116    if (!protocolHostAndPortAreEqual(job.scriptURL, job.clientCreationURL))
     117        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script origin does not match the registering client's origin") });
     118
     119    // If the origin of job’s scope url is not job’s referrer's origin, then:
     120    if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL))
     121        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Scope origin does not match the registering client's origin") });
     122
     123    // If registration is not null (in our parlance "empty"), then:
     124    if (!isEmpty()) {
     125        ASSERT(m_updateViaCache);
     126
     127        m_uninstalling = false;
     128        auto* newestWorker = getNewestWorker();
     129        if (newestWorker && equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()) && job.registrationOptions.updateViaCache == *m_updateViaCache) {
     130            resolveWithRegistrationOnMainThread();
     131            return;
     132        }
     133    } else {
     134        m_scopeURL = job.scopeURL.isolatedCopy();
     135        m_scopeURL.removeFragmentIdentifier();
     136        m_updateViaCache = job.registrationOptions.updateViaCache;
     137    }
     138
     139    runUpdateJob(job);
     140}
     141
     142void SWServerRegistration::runUpdateJob(const ServiceWorkerJobData& job)
     143{
     144    // If registration is null (in our parlance "empty") or registration’s uninstalling flag is set, then:
     145    if (isEmpty())
     146        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a null/nonexistent service worker registration") });
     147    if (m_uninstalling)
     148        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker registration that is uninstalling") });
     149
     150    // If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:
     151    auto* newestWorker = getNewestWorker();
     152    if (newestWorker && !equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()))
     153        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") });
     154
     155    // FIXME: At this point we are ready to actually fetch the script for the worker in the registering context.
     156    // For now we're still hard coding the same rejection we have so far.
     157    rejectWithExceptionOnMainThread(ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") });
     158}
     159
     160void SWServerRegistration::rejectWithExceptionOnMainThread(const ExceptionData& exception)
     161{
     162    ASSERT(!isMainThread());
    76163    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::rejectCurrentJob, exception));
     164}
     165
     166void SWServerRegistration::resolveWithRegistrationOnMainThread()
     167{
     168    ASSERT(!isMainThread());
     169    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentJob, data()));
    77170}
    78171
     
    83176
    84177    m_server.rejectJob(*m_currentJob, exceptionData);
     178
     179    finishCurrentJob();
     180}
     181
     182void SWServerRegistration::resolveCurrentJob(const ServiceWorkerRegistrationData& data)
     183{
     184    ASSERT(isMainThread());
     185    ASSERT(m_currentJob);
     186
     187    m_server.resolveJob(*m_currentJob, data);
    85188
    86189    finishCurrentJob();
     
    99202}
    100203
     204ServiceWorkerRegistrationData SWServerRegistration::data() const
     205{
     206    return { m_registrationKey, m_identifier };
     207}
     208
     209
    101210} // namespace WebCore
    102211
  • trunk/Source/WebCore/workers/service/server/SWServerRegistration.h

    r221198 r221392  
    2929
    3030#include "ServiceWorkerJobData.h"
     31#include "ServiceWorkerRegistrationData.h"
    3132#include "Timer.h"
    3233#include <wtf/Deque.h>
     
    3536
    3637class SWServer;
     38class SWServerWorker;
    3739struct ExceptionData;
    3840
    3941class SWServerRegistration {
    4042public:
    41     explicit SWServerRegistration(SWServer&);
     43    explicit SWServerRegistration(SWServer&, const ServiceWorkerRegistrationKey&);
    4244    SWServerRegistration(const SWServerRegistration&) = delete;
    4345    ~SWServerRegistration();
     
    4547    void enqueueJob(const ServiceWorkerJobData&);
    4648
     49    uint64_t identifier() const { return m_identifier; }
     50    ServiceWorkerRegistrationData data() const;
     51
    4752private:
    4853    void jobTimerFired();
    49     void performCurrentJob();
     54    void startNextJob();
    5055    void rejectCurrentJob(const ExceptionData&);
     56    void resolveCurrentJob(const ServiceWorkerRegistrationData&);
     57    void finishCurrentJob();
    5158
    52     void startNextJob();
    53     void finishCurrentJob();
     59    void runRegisterJob(const ServiceWorkerJobData&);
     60    void runUpdateJob(const ServiceWorkerJobData&);
     61
     62    void rejectWithExceptionOnMainThread(const ExceptionData&);
     63    void resolveWithRegistrationOnMainThread();
     64    bool isEmpty();
     65    SWServerWorker* getNewestWorker();
    5466
    5567    Deque<ServiceWorkerJobData> m_jobQueue;
    5668    std::unique_ptr<ServiceWorkerJobData> m_currentJob;
    5769
     70    bool m_uninstalling { false };
     71    std::unique_ptr<SWServerWorker> m_installingWorker;
     72    std::unique_ptr<SWServerWorker> m_waitingWorker;
     73    std::unique_ptr<SWServerWorker> m_activeWorker;
     74    URL m_scopeURL;
     75    std::optional<ServiceWorkerUpdateViaCache> m_updateViaCache;
     76
    5877    Timer m_jobTimer;
    5978    SWServer& m_server;
     79    uint64_t m_identifier;
     80    ServiceWorkerRegistrationKey m_registrationKey;
    6081};
    6182
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp

    r221388 r221392  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "SWServerWorker.h"
    2728
    2829#if ENABLE(SERVICE_WORKER)
    2930
     31#include <wtf/MainThread.h>
     32
    3033namespace WebCore {
    3134
    32 class ServiceWorkerJob;
     35SWServerWorker::SWServerWorker(const URL& url)
     36    : m_scriptURL(url)
     37{
     38    ASSERT(!isMainThread());
     39}
    3340
    34 class ServiceWorkerJobClient {
    35 public:
    36     virtual ~ServiceWorkerJobClient() { };
    37 
    38     virtual void jobDidFinish(ServiceWorkerJob&) = 0;
    39     virtual uint64_t connectionIdentifier() = 0;
    40 
    41     virtual void ref() = 0;
    42     virtual void deref() = 0;
    43 };
     41SWServerWorker::~SWServerWorker()
     42{
     43    ASSERT(!isMainThread());
     44}
    4445
    4546} // namespace WebCore
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.h

    r221388 r221392  
    2828#if ENABLE(SERVICE_WORKER)
    2929
     30#include "URL.h"
     31
    3032namespace WebCore {
    3133
    32 class ServiceWorkerJob;
     34class SWServerWorker {
     35public:
     36    SWServerWorker(const URL&);
     37    SWServerWorker(const SWServerWorker&) = delete;
     38    ~SWServerWorker();
     39    const URL& scriptURL() const { return m_scriptURL; }
    3340
    34 class ServiceWorkerJobClient {
    35 public:
    36     virtual ~ServiceWorkerJobClient() { };
    37 
    38     virtual void jobDidFinish(ServiceWorkerJob&) = 0;
    39     virtual uint64_t connectionIdentifier() = 0;
    40 
    41     virtual void ref() = 0;
    42     virtual void deref() = 0;
     41private:
     42    URL m_scriptURL;
    4343};
    4444
  • trunk/Source/WebKit/ChangeLog

    r221381 r221392  
     12017-08-30  Brady Eidson  <beidson@apple.com>
     2
     3        Implement all of "Register" right up until where the script is fetched.
     4        https://bugs.webkit.org/show_bug.cgi?id=176082
     5
     6        Reviewed by Andy Estes.
     7
     8        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
     9        (WebKit::WebSWServerConnection::resolveJobInClient):
     10        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
     11        * WebProcess/Storage/WebSWClientConnection.messages.in:
     12
    1132017-08-30  Andy Estes  <aestes@apple.com>
    214
  • trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp

    r221198 r221392  
    6666}
    6767
     68void WebSWServerConnection::resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
     69{
     70    send(Messages::WebSWClientConnection::JobResolvedInServer(jobIdentifier, registrationData));
     71}
     72
    6873} // namespace WebKit
    6974
  • trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h

    r221198 r221392  
    5151    // Implement SWServer::Connection
    5252    void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
     53    void resolveJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final;
    5354
    5455    IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in

    r220977 r221392  
    2626    # When possible, these messages can be implemented directly by WebCore::SWServer::Connection
    2727    JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception)
     28    JobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration)
    2829}
    2930
Note: See TracChangeset for help on using the changeset viewer.