Changeset 221461 in webkit
- Timestamp:
- Aug 31, 2017 5:12:52 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 24 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r221456 r221461 1 2017-08-31 Brady Eidson <beidson@apple.com> 2 3 Add (entirely incorrect) fetching of ServiceWorker scripts. 4 https://bugs.webkit.org/show_bug.cgi?id=176179 5 6 Reviewed by Andy Estes. 7 8 * http/tests/workers/service/basic-register-expected.txt: 9 * http/tests/workers/service/resources/basic-register.js: 10 * http/tests/workers/service/resources/registration-task-queue-scheduling-1.js: 11 1 12 2017-08-31 Antti Koivisto <antti@apple.com> 2 13 -
trunk/LayoutTests/http/tests/workers/service/basic-register-expected.txt
r220539 r221461 1 CONSOLE MESSAGE: line 11: Registration failed with error: UnknownError: serviceWorker job scheduling is not yet implemented 1 CONSOLE MESSAGE: line 10: Registration failed with error: UnknownError: Script URL http://127.0.0.1:8000/workers/service/resources/empty-worker.js fetched with 41 bytes, but we're not using the result yet 2 CONSOLE MESSAGE: line 21: Registration failed with error: UnknownError: Script URL http://127.0.0.1:8000/workers/service/resources/empty-worker-doesnt-exist.js fetch resulted in error: ServiceWorker script network fetch failed with HTTP status code 404 2 3 -
trunk/LayoutTests/http/tests/workers/service/resources/basic-register.js
r220924 r221461 5 5 6 6 navigator.serviceWorker.register("resources/empty-worker.js", { }) 7 .then(function(r) { 8 console.log("Registered!"); 9 }, function(e) { 10 console.log("Registration failed with error: " + e); 11 }) 12 .catch(function(e) { 13 console.log("Exception registering: " + e); 14 }); 15 16 navigator.serviceWorker.register("resources/empty-worker-doesnt-exist.js", { }) 7 17 .then(function(r) { 8 18 console.log("Registered!"); -
trunk/LayoutTests/http/tests/workers/service/resources/registration-task-queue-scheduling-1.js
r221198 r221461 49 49 done(); 50 50 }, function(e) { 51 if (e+"" != "UnknownError: serviceWorker job scheduling is not yet implemented") {52 alert("Unexpected error received from server ");51 if (e+"" != "UnknownError: Script URL http://127.0.0.1:8000/workers/service/resources/empty-worker.js fetched with 41 bytes, but we're not using the result yet") { 52 alert("Unexpected error received from server: " + e); 53 53 finishSWTest(); 54 54 } -
trunk/Source/WebCore/ChangeLog
r221459 r221461 1 2017-08-31 Brady Eidson <beidson@apple.com> 2 3 Add (entirely incorrect) fetching of ServiceWorker scripts. 4 https://bugs.webkit.org/show_bug.cgi?id=176179 5 6 Reviewed by Andy Estes. 7 8 No new tests (Covered by changes to existing tests). 9 10 When the Storage process is running the "Update" algorithm and a ServiceWorker script file needs to be fetched, this patch: 11 - Messages back to the WebContent process that started the register/update job 12 - Executes a FetchLoad in that script context for the script 13 - Sends the results back to the Storage process 14 15 We don't do anything with the results yet. 16 17 Soon. 18 19 * WebCore.xcodeproj/project.pbxproj: 20 21 * workers/service/ServiceWorkerContainer.cpp: 22 (WebCore::ServiceWorkerContainer::startScriptFetchForJob): 23 (WebCore::ServiceWorkerContainer::jobFinishedLoadingScript): 24 (WebCore::ServiceWorkerContainer::jobFailedLoadingScript): 25 * workers/service/ServiceWorkerContainer.h: 26 27 * workers/service/ServiceWorkerFetchResult.h: Copied from Source/WebCore/workers/service/server/SWClientConnection.h. 28 (WebCore::ServiceWorkerFetchResult::encode const): 29 (WebCore::ServiceWorkerFetchResult::decode): 30 31 * workers/service/ServiceWorkerJob.cpp: 32 (WebCore::ServiceWorkerJob::startScriptFetch): 33 (WebCore::ServiceWorkerJob::fetchScriptWithContext): 34 (WebCore::ServiceWorkerJob::didReceiveResponse): 35 (WebCore::ServiceWorkerJob::didReceiveData): 36 (WebCore::ServiceWorkerJob::didSucceed): 37 (WebCore::ServiceWorkerJob::didFail): 38 * workers/service/ServiceWorkerJob.h: 39 40 * workers/service/ServiceWorkerJobClient.h: 41 42 * workers/service/server/SWClientConnection.cpp: 43 (WebCore::SWClientConnection::finishedFetchingScript): 44 (WebCore::SWClientConnection::failedFetchingScript): 45 (WebCore::SWClientConnection::startScriptFetchForServer): 46 * workers/service/server/SWClientConnection.h: 47 48 * workers/service/server/SWServer.cpp: 49 (WebCore::SWServer::Connection::finishFetchingScriptInServer): 50 (WebCore::SWServer::startScriptFetch): 51 (WebCore::SWServer::scriptFetchFinished): 52 * workers/service/server/SWServer.h: 53 54 * workers/service/server/SWServerRegistration.cpp: 55 (WebCore::SWServerRegistration::scriptFetchFinished): 56 (WebCore::SWServerRegistration::runUpdateJob): 57 (WebCore::SWServerRegistration::startScriptFetchFromMainThread): 58 (WebCore::SWServerRegistration::startScriptFetchForCurrentJob): 59 * workers/service/server/SWServerRegistration.h: 60 1 61 2017-08-31 Daniel Bates <dabates@apple.com> 2 62 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r221441 r221461 2306 2306 517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; }; 2307 2307 517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2308 517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B61C89912600A7E715 /* FetchLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2309 517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2310 517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 41CF8BE51D46222000707DC9 /* FetchBodyConsumer.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2311 517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2308 2312 517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; }; 2309 2313 517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; }; … … 10132 10136 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationData.cpp; sourceTree = "<group>"; }; 10133 10137 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationData.h; sourceTree = "<group>"; }; 10138 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerFetchResult.h; sourceTree = "<group>"; }; 10134 10139 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; }; 10135 10140 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; }; … … 18863 18868 51F175571F3EBC0C00C74950 /* ServiceWorkerContainer.h */, 18864 18869 51F175561F3EBC0C00C74950 /* ServiceWorkerContainer.idl */, 18870 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */, 18865 18871 51F175551F3EBC0C00C74950 /* ServiceWorkerGlobalScope.cpp */, 18866 18872 51F175541F3EBC0C00C74950 /* ServiceWorkerGlobalScope.h */, … … 26822 26828 7C6522F51E00A51700677F22 /* ApplePayPaymentPass.h in Headers */, 26823 26829 7C6579E01E0079F900E3A27A /* ApplePayPaymentRequest.h in Headers */, 26830 517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */, 26824 26831 1A8A64591D19FCFC00D0E00F /* ApplePaySession.h in Headers */, 26825 26832 1A58E8651D19D4EB00C0EA73 /* ApplePaySessionPaymentRequest.h in Headers */, … … 27790 27797 977B3867122883E900B81FF8 /* HTMLDocumentParser.h in Headers */, 27791 27798 93F198E608245E59001E9ABC /* HTMLElement.h in Headers */, 27799 517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */, 27792 27800 A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */, 27793 27801 977B37241228721700B81FF8 /* HTMLElementStack.h in Headers */, … … 28941 28949 37C738EF1EDBD71B003F2B0B /* MathMLUnknownElement.h in Headers */, 28942 28950 439046EA12DA25E812AF80AC /* MathOperator.h in Headers */, 28951 517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */, 28943 28952 49D5DC2C0F423A73008F20FD /* Matrix3DTransformOperation.h in Headers */, 28944 28953 49E911C70EF86D47009D0CAF /* MatrixTransformOperation.h in Headers */, … … 29103 29112 A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */, 29104 29113 628D214C12131ED10055DCFC /* NetworkingContext.h in Headers */, 29114 517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */, 29105 29115 8A81BF8511DCFD9000DA2B98 /* NetworkLoadMetrics.h in Headers */, 29106 29116 59C27F07138D28CF0079B7E2 /* NetworkResourcesData.h in Headers */, -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp
r221392 r221461 33 33 #include "JSDOMPromiseDeferred.h" 34 34 #include "JSServiceWorkerRegistration.h" 35 #include "Logging.h" 35 36 #include "NavigatorBase.h" 37 #include "ResourceError.h" 36 38 #include "ScopeGuard.h" 37 39 #include "ScriptExecutionContext.h" … … 182 184 } 183 185 186 void ServiceWorkerContainer::startScriptFetchForJob(ServiceWorkerJob& job) 187 { 188 LOG(ServiceWorker, "SeviceWorkerContainer %p starting script fetch for job %" PRIu64, this, job.data().identifier()); 189 190 auto* context = scriptExecutionContext(); 191 if (!context) { 192 LOG_ERROR("ServiceWorkerContainer::jobResolvedWithRegistration called but the container's ScriptExecutionContext is gone"); 193 m_swConnection->failedFetchingScript(job, { errorDomainWebKitInternal, 0, job.data().scriptURL, ASCIILiteral("Attempt to fetch service worker script with no ScriptExecutionContext") }); 194 jobDidFinish(job); 195 return; 196 } 197 198 job.fetchScriptWithContext(*context); 199 } 200 201 void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, Ref<SharedBuffer>&& data) 202 { 203 LOG(ServiceWorker, "SeviceWorkerContainer %p finished fetching script for job %" PRIu64, this, job.data().identifier()); 204 205 m_swConnection->finishedFetchingScript(job, data.get()); 206 } 207 208 void ServiceWorkerContainer::jobFailedLoadingScript(ServiceWorkerJob& job, const ResourceError& error) 209 { 210 LOG(ServiceWorker, "SeviceWorkerContainer %p failed fetching script for job %" PRIu64, this, job.data().identifier()); 211 212 m_swConnection->failedFetchingScript(job, error); 213 } 214 184 215 void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job) 185 216 { -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h
r221392 r221461 74 74 void jobFailedWithException(ServiceWorkerJob&, const Exception&) final; 75 75 void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) final; 76 void startScriptFetchForJob(ServiceWorkerJob&) final; 77 void jobFinishedLoadingScript(ServiceWorkerJob&, Ref<SharedBuffer>&&) final; 78 void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&) final; 79 76 80 void jobDidFinish(ServiceWorkerJob&); 77 81 -
trunk/Source/WebCore/workers/service/ServiceWorkerFetchResult.h
r221460 r221461 28 28 #if ENABLE(SERVICE_WORKER) 29 29 30 #include " ServiceWorkerJob.h"31 #include <wtf/HashMap.h>32 #include <wtf/ ThreadSafeRefCounted.h>30 #include "ResourceError.h" 31 #include "ServiceWorkerRegistrationKey.h" 32 #include <wtf/Vector.h> 33 33 34 34 namespace WebCore { 35 35 36 struct ExceptionData; 37 struct ServiceWorkerRegistrationData; 36 struct ServiceWorkerFetchResult { 37 uint64_t jobIdentifier; 38 uint64_t connectionIdentifier; 39 ServiceWorkerRegistrationKey registrationKey; 40 Vector<uint8_t> scriptData; 41 ResourceError scriptError; 38 42 39 class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> { 40 public: 41 WEBCORE_EXPORT SWClientConnection(); 42 WEBCORE_EXPORT virtual ~SWClientConnection(); 43 template<class Encoder> void encode(Encoder&) const; 44 template<class Decoder> static bool decode(Decoder&, ServiceWorkerFetchResult&); 45 }; 43 46 44 void scheduleJob(ServiceWorkerJob&); 47 template<class Encoder> 48 void ServiceWorkerFetchResult::encode(Encoder& encoder) const 49 { 50 encoder << jobIdentifier << connectionIdentifier << registrationKey << scriptData << scriptError; 51 } 45 52 46 virtual uint64_t identifier() const = 0; 53 template<class Decoder> 54 bool ServiceWorkerFetchResult::decode(Decoder& decoder, ServiceWorkerFetchResult& result) 55 { 56 if (!decoder.decode(result.jobIdentifier)) 57 return false; 58 if (!decoder.decode(result.connectionIdentifier)) 59 return false; 60 if (!decoder.decode(result.registrationKey)) 61 return false; 62 if (!decoder.decode(result.scriptData)) 63 return false; 64 if (!decoder.decode(result.scriptError)) 65 return false; 47 66 48 protected: 49 WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&); 50 WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&); 51 52 private: 53 virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0; 54 55 HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_scheduledJobs; 56 }; 67 return true; 68 } 57 69 58 70 } // namespace WebCore -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp
r221392 r221461 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "FetchHeaders.h" 32 #include "FetchLoader.h" 33 #include "FetchRequest.h" 31 34 #include "JSDOMPromiseDeferred.h" 35 #include "ResourceError.h" 36 #include "ResourceResponse.h" 32 37 #include "ServiceWorkerJobData.h" 33 38 #include "ServiceWorkerRegistration.h" … … 65 70 } 66 71 72 void ServiceWorkerJob::startScriptFetch() 73 { 74 ASSERT(currentThread() == m_creationThread); 75 ASSERT(!m_completed); 76 77 m_client->startScriptFetchForJob(*this); 78 } 79 80 void ServiceWorkerJob::fetchScriptWithContext(ScriptExecutionContext& context) 81 { 82 ASSERT(currentThread() == m_creationThread); 83 ASSERT(!m_completed); 84 85 m_fetchLoader = std::make_unique<FetchLoader>(*this, nullptr); 86 87 // FIXME: This Fetch request is set up incorrectly and without proper care. 88 // The ServiceWorkers spec specifics many details to apply here. 89 90 auto fetchHeaders = FetchHeaders::create(); 91 auto referrer = m_jobData.clientCreationURL.string(); 92 auto fetchRequest = FetchRequest::create(context, std::nullopt, WTFMove(fetchHeaders), { m_jobData.scriptURL }, { }, WTFMove(referrer)); 93 94 m_fetchLoader->start(context, fetchRequest); 95 } 96 97 void ServiceWorkerJob::didReceiveResponse(const ResourceResponse& response) 98 { 99 ASSERT(currentThread() == m_creationThread); 100 ASSERT(!m_completed); 101 ASSERT(m_fetchLoader); 102 ASSERT(!m_scriptData); 103 104 m_lastResponse = response; 105 106 if (response.httpStatusCode() < 200 || response.httpStatusCode() > 399) { 107 auto message = makeString(ASCIILiteral("ServiceWorker script network fetch failed with HTTP status code "), String::number(response.httpStatusCode())); 108 didFail({ errorDomainWebKitInternal, 0, m_lastResponse.url(), message }); 109 } 110 } 111 112 void ServiceWorkerJob::didReceiveData(const char* data, size_t size) 113 { 114 ASSERT(currentThread() == m_creationThread); 115 ASSERT(!m_completed); 116 ASSERT(m_fetchLoader); 117 118 if (!m_scriptData) 119 m_scriptData = SharedBuffer::create(); 120 121 m_scriptData->get().append(data, size); 122 } 123 124 void ServiceWorkerJob::didSucceed() 125 { 126 ASSERT(currentThread() == m_creationThread); 127 ASSERT(!m_completed); 128 ASSERT(m_fetchLoader); 129 130 if (!m_scriptData) 131 m_scriptData = SharedBuffer::create(); 132 m_client->jobFinishedLoadingScript(*this, WTFMove(*m_scriptData)); 133 m_fetchLoader = nullptr; 134 } 135 136 void ServiceWorkerJob::didFail(const ResourceError& error) 137 { 138 ASSERT(currentThread() == m_creationThread); 139 ASSERT(!m_completed); 140 ASSERT(m_fetchLoader); 141 142 m_client->jobFailedLoadingScript(*this, error); 143 m_fetchLoader = nullptr; 144 } 145 67 146 } // namespace WebCore 68 147 -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.h
r221392 r221461 28 28 #if ENABLE(SERVICE_WORKER) 29 29 30 #include "FetchLoader.h" 31 #include "FetchLoaderClient.h" 32 #include "ResourceResponse.h" 30 33 #include "ServiceWorkerJobClient.h" 31 34 #include "ServiceWorkerJobData.h" … … 39 42 class DeferredPromise; 40 43 class Exception; 44 class ScriptExecutionContext; 41 45 enum class ServiceWorkerJobType; 42 46 struct ServiceWorkerRegistrationData; 43 47 44 class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {48 class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob>, public FetchLoaderClient { 45 49 public: 46 50 static Ref<ServiceWorkerJob> create(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData) … … 53 57 void failedWithException(const Exception&); 54 58 void resolvedWithRegistration(const ServiceWorkerRegistrationData&); 59 void startScriptFetch(); 55 60 56 61 ServiceWorkerJobData data() const { return m_jobData; } 57 62 DeferredPromise& promise() { return m_promise.get(); } 58 63 64 void fetchScriptWithContext(ScriptExecutionContext&); 65 59 66 private: 60 67 ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&); 68 69 // FetchLoaderClient 70 void didReceiveResponse(const ResourceResponse&) final; 71 void didReceiveData(const char*, size_t) final; 72 void didSucceed() final; 73 void didFail(const ResourceError&) final; 61 74 62 75 Ref<ServiceWorkerJobClient> m_client; … … 67 80 68 81 Ref<RunLoop> m_runLoop { RunLoop::current() }; 82 std::unique_ptr<FetchLoader> m_fetchLoader; 83 ResourceResponse m_lastResponse; 84 std::optional<Ref<SharedBuffer>> m_scriptData; 69 85 70 86 #if !ASSERT_DISABLED -
trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h
r221392 r221461 31 31 32 32 class Exception; 33 class ResourceError; 33 34 class ServiceWorkerJob; 35 class SharedBuffer; 34 36 struct ServiceWorkerRegistrationData; 35 37 … … 40 42 virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0; 41 43 virtual void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) = 0; 44 virtual void startScriptFetchForJob(ServiceWorkerJob&) = 0; 45 virtual void jobFinishedLoadingScript(ServiceWorkerJob&, Ref<SharedBuffer>&&) = 0; 46 virtual void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&) = 0; 42 47 43 48 virtual uint64_t connectionIdentifier() = 0; -
trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp
r221392 r221461 30 30 31 31 #include "ExceptionData.h" 32 #include "ServiceWorkerFetchResult.h" 32 33 #include "ServiceWorkerJobData.h" 33 34 … … 48 49 49 50 scheduleJobInServer(job.data()); 51 } 52 53 void SWClientConnection::finishedFetchingScript(ServiceWorkerJob& job, SharedBuffer& data) 54 { 55 ASSERT(m_scheduledJobs.get(job.data().identifier()) == &job); 56 57 Vector<uint8_t> vector; 58 vector.append(reinterpret_cast<const uint8_t *>(data.data()), data.size()); 59 finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), vector, { } }); 60 } 61 62 void SWClientConnection::failedFetchingScript(ServiceWorkerJob& job, const ResourceError& error) 63 { 64 ASSERT(m_scheduledJobs.get(job.data().identifier()) == &job); 65 66 finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), { }, error }); 50 67 } 51 68 … … 72 89 } 73 90 91 void SWClientConnection::startScriptFetchForServer(uint64_t jobIdentifier) 92 { 93 auto job = m_scheduledJobs.get(jobIdentifier); 94 if (!job) { 95 LOG_ERROR("Job %" PRIu64 " instructed to start fetch from server, but job was not found", jobIdentifier); 96 97 // FIXME: Should message back to the server here to signal failure to fetch, 98 // but we currently need the registration key to do so, and don't have it here. 99 // In the future we'll refactor to have a global, cross-process job identifier that can be used to overcome this. 100 101 return; 102 } 103 104 job->startScriptFetch(); 105 } 106 74 107 } // namespace WebCore 75 108 -
trunk/Source/WebCore/workers/service/server/SWClientConnection.h
r221392 r221461 34 34 namespace WebCore { 35 35 36 class ResourceError; 37 class SharedBuffer; 36 38 struct ExceptionData; 39 struct ServiceWorkerFetchResult; 37 40 struct ServiceWorkerRegistrationData; 38 41 … … 43 46 44 47 void scheduleJob(ServiceWorkerJob&); 48 void finishedFetchingScript(ServiceWorkerJob&, SharedBuffer&); 49 void failedFetchingScript(ServiceWorkerJob&, const ResourceError&); 45 50 46 51 virtual uint64_t identifier() const = 0; … … 49 54 WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&); 50 55 WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&); 56 WEBCORE_EXPORT void startScriptFetchForServer(uint64_t jobIdentifier); 51 57 52 58 private: 53 59 virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0; 60 virtual void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) = 0; 54 61 55 62 HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_scheduledJobs; -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r221399 r221461 33 33 #include "Logging.h" 34 34 #include "SWServerRegistration.h" 35 #include "ServiceWorkerFetchResult.h" 35 36 #include "ServiceWorkerJobData.h" 36 37 #include <wtf/text/WTFString.h> … … 73 74 } 74 75 76 void SWServer::Connection::finishFetchingScriptInServer(const ServiceWorkerFetchResult& result) 77 { 78 m_server.scriptFetchFinished(result); 79 } 80 75 81 SWServer::SWServer() 76 82 { … … 111 117 112 118 connection->resolveJobInClient(jobData.identifier(), registrationData); 119 } 120 121 void SWServer::startScriptFetch(const ServiceWorkerJobData& jobData) 122 { 123 LOG(ServiceWorker, "Server issuing startScriptFetch for current job %" PRIu64 "-%" PRIu64 " in client", jobData.connectionIdentifier(), jobData.identifier()); 124 auto* connection = m_connections.get(jobData.connectionIdentifier()); 125 if (!connection) 126 return; 127 128 connection->startScriptFetchInClient(jobData.identifier()); 129 } 130 131 void SWServer::scriptFetchFinished(const ServiceWorkerFetchResult& result) 132 { 133 LOG(ServiceWorker, "Server handling scriptFetchFinished for current job %" PRIu64 "-%" PRIu64 " in client", result.connectionIdentifier, result.jobIdentifier); 134 135 ASSERT(m_connections.contains(result.connectionIdentifier)); 136 137 auto registration = m_registrations.get(result.registrationKey); 138 if (!registration) 139 return; 140 141 registration->scriptFetchFinished(result); 113 142 } 114 143 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r221399 r221461 44 44 class SWServerRegistration; 45 45 struct ExceptionData; 46 struct ServiceWorkerFetchResult; 46 47 struct ServiceWorkerRegistrationData; 47 48 … … 58 59 59 60 WEBCORE_EXPORT void scheduleJobInServer(const ServiceWorkerJobData&); 61 WEBCORE_EXPORT void finishFetchingScriptInServer(const ServiceWorkerFetchResult&); 60 62 61 63 private: 62 64 virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0; 63 65 virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0; 66 virtual void startScriptFetchInClient(uint64_t jobIdentifier) = 0; 64 67 65 68 SWServer& m_server; … … 72 75 void rejectJob(const ServiceWorkerJobData&, const ExceptionData&); 73 76 void resolveJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&); 77 void startScriptFetch(const ServiceWorkerJobData&); 78 74 79 void postTask(CrossThreadTask&&); 75 80 void postTaskReply(CrossThreadTask&&); … … 81 86 void taskThreadEntryPoint(); 82 87 void handleTaskRepliesOnMainThread(); 88 89 void scriptFetchFinished(const ServiceWorkerFetchResult&); 83 90 84 91 HashMap<uint64_t, Connection*> m_connections; -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp
r221399 r221461 33 33 #include "SWServerWorker.h" 34 34 #include "SecurityOrigin.h" 35 #include "ServiceWorkerFetchResult.h" 35 36 #include "ServiceWorkerRegistrationData.h" 36 37 #include "WorkerType.h" … … 62 63 if (!m_jobTimer.isActive()) 63 64 m_jobTimer.startOneShot(0_s); 65 } 66 67 void SWServerRegistration::scriptFetchFinished(const ServiceWorkerFetchResult& result) 68 { 69 ASSERT(m_currentJob && m_currentJob->identifier() == result.jobIdentifier); 70 71 // FIXME: We fetched the script contents but don't do anything with them yet. 72 // These errors are for testing the current state of the feature. 73 74 String message; 75 if (result.scriptError.isNull()) 76 message = makeString("Script URL ", m_currentJob->scriptURL.string(), " fetched with ", String::number(result.scriptData.size()), " bytes, but we're not using the result yet"); 77 else 78 message = makeString("Script URL ", m_currentJob->scriptURL.string(), " fetch resulted in error: ", result.scriptError.localizedDescription()); 79 80 rejectCurrentJob(ExceptionData { UnknownError, message }); 64 81 } 65 82 … … 150 167 return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") }); 151 168 152 // FIXME: At this point we are ready to actually fetch the script for the worker in the registering context. 153 // For now we're still hard coding the same rejection we have so far. 154 rejectWithExceptionOnMainThread(ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") }); 169 startScriptFetchFromMainThread(); 155 170 } 156 171 … … 167 182 } 168 183 184 void SWServerRegistration::startScriptFetchFromMainThread() 185 { 186 ASSERT(!isMainThread()); 187 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::startScriptFetchForCurrentJob)); 188 } 189 169 190 void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData) 170 191 { … … 185 206 186 207 finishCurrentJob(); 208 } 209 210 void SWServerRegistration::startScriptFetchForCurrentJob() 211 { 212 ASSERT(isMainThread()); 213 ASSERT(m_currentJob); 214 215 m_server.startScriptFetch(*m_currentJob); 187 216 } 188 217 -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.h
r221399 r221461 39 39 class SWServerWorker; 40 40 struct ExceptionData; 41 struct ServiceWorkerFetchResult; 41 42 42 43 class SWServerRegistration : public ThreadSafeIdentified<SWServerRegistration> { … … 47 48 48 49 void enqueueJob(const ServiceWorkerJobData&); 50 void scriptFetchFinished(const ServiceWorkerFetchResult&); 49 51 50 52 ServiceWorkerRegistrationData data() const; … … 55 57 void rejectCurrentJob(const ExceptionData&); 56 58 void resolveCurrentJob(const ServiceWorkerRegistrationData&); 59 void startScriptFetchForCurrentJob(); 57 60 void finishCurrentJob(); 58 61 … … 62 65 void rejectWithExceptionOnMainThread(const ExceptionData&); 63 66 void resolveWithRegistrationOnMainThread(); 67 void startScriptFetchFromMainThread(); 64 68 bool isEmpty(); 65 69 SWServerWorker* getNewestWorker(); -
trunk/Source/WebKit/ChangeLog
r221457 r221461 1 2017-08-31 Brady Eidson <beidson@apple.com> 2 3 Add (entirely incorrect) fetching of ServiceWorker scripts. 4 https://bugs.webkit.org/show_bug.cgi?id=176179 5 6 Reviewed by Andy Estes. 7 8 * StorageProcess/ServiceWorker/WebSWServerConnection.cpp: 9 (WebKit::WebSWServerConnection::startScriptFetchInClient): 10 * StorageProcess/ServiceWorker/WebSWServerConnection.h: 11 * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in: 12 13 * WebProcess/Storage/WebSWClientConnection.cpp: 14 (WebKit::WebSWClientConnection::finishFetchingScriptInServer): 15 * WebProcess/Storage/WebSWClientConnection.h: 16 * WebProcess/Storage/WebSWClientConnection.messages.in: 17 1 18 2017-08-31 Megan Gardner <megan_gardner@apple.com> 2 19 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
r221392 r221461 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "DataReference.h" 31 32 #include "Logging.h" 32 33 #include "StorageToWebProcessConnectionMessages.h" … … 71 72 } 72 73 74 void WebSWServerConnection::startScriptFetchInClient(uint64_t jobIdentifier) 75 { 76 send(Messages::WebSWClientConnection::StartScriptFetchForServer(jobIdentifier)); 77 } 78 73 79 } // namespace WebKit 74 80 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
r221392 r221461 52 52 void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final; 53 53 void resolveJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final; 54 void startScriptFetchInClient(uint64_t jobIdentifier) final; 54 55 55 56 IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); } -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in
r220977 r221461 26 26 # When possible, these messages can be implemented directly by WebCore::SWClientConnection 27 27 ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData) 28 FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result) 28 29 } 29 30 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
r220977 r221461 31 31 #include "Logging.h" 32 32 #include "StorageToWebProcessConnectionMessages.h" 33 #include "WebCoreArgumentCoders.h" 33 34 #include "WebSWServerConnectionMessages.h" 35 #include <WebCore/ServiceWorkerFetchResult.h> 34 36 #include <WebCore/ServiceWorkerJobData.h> 35 37 … … 57 59 } 58 60 61 void WebSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerFetchResult& result) 62 { 63 send(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result)); 64 } 65 59 66 } // namespace WebKit 60 67 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
r221198 r221461 49 49 50 50 void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final; 51 void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final; 51 52 52 53 void disconnectedFromWebProcess(); -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in
r221392 r221461 27 27 JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception) 28 28 JobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration) 29 StartScriptFetchForServer(uint64_t jobIdentifier) 29 30 } 30 31
Note: See TracChangeset
for help on using the changeset viewer.