Changeset 222980 in webkit
- Timestamp:
- Oct 6, 2017 9:20:04 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 29 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r222979 r222980 1 2017-10-06 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-exceptions-expected.txt: 9 * http/tests/workers/service/basic-register-expected.txt: 10 * http/tests/workers/service/resources/basic-register-exceptions.js: 11 * http/tests/workers/service/resources/basic-register.js: 12 * http/tests/workers/service/resources/registration-task-queue-scheduling-1.js: 13 1 14 2017-10-06 Ryan Haddad <ryanhaddad@apple.com> 2 15 -
trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt
r221392 r222980 1 CONSOLE MESSAGE: line 10: Registration failed with error: TypeError: serviceWorker.register() cannot be called with an empty script URL 2 CONSOLE MESSAGE: line 20: Registration failed with error: TypeError: serviceWorker.register() must be called with a valid relative script URL 3 CONSOLE MESSAGE: line 30: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS 4 CONSOLE MESSAGE: line 40: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c' 5 CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS 6 CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c' 7 CONSOLE MESSAGE: line 70: Registration failed with error: SecurityError: Script origin does not match the registering client's origin 8 CONSOLE MESSAGE: line 81: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin 1 CONSOLE MESSAGE: line 20: Registration failed with error: TypeError: serviceWorker.register() cannot be called with an empty script URL 2 CONSOLE MESSAGE: line 30: Registration failed with error: TypeError: serviceWorker.register() must be called with a valid relative script URL 3 CONSOLE MESSAGE: line 40: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS 4 CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c' 5 CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS 6 CONSOLE MESSAGE: line 70: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c' 7 CONSOLE MESSAGE: line 10: Registration failed with error: UnknownError: Script URL http://127.0.0.1:8000/workers/service/image-mime-type.php fetched with 0 characters, but we're not using the result yet 8 CONSOLE MESSAGE: line 80: Registration failed with error: SecurityError: Script origin does not match the registering client's origin 9 CONSOLE MESSAGE: line 91: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin 9 10 -
trunk/LayoutTests/http/tests/workers/service/basic-register-expected.txt
r221699 r222980 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 characters, 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 fetched with 0 characters, but we're not using the result yet 2 3 -
trunk/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js
r221392 r222980 3 3 finishSWTest(); 4 4 } 5 6 navigator.serviceWorker.register("image-mime-type.php", { }) 7 .then(function(r) { 8 console.log("Registered! (unexpectedly)"); 9 }, function(e) { 10 console.log("Registration failed with error: " + e); 11 }) 12 .catch(function(e) { 13 console.log("Exception registering: " + e); 14 }); 5 15 6 16 navigator.serviceWorker.register("", { }) -
trunk/LayoutTests/http/tests/workers/service/resources/basic-register.js
r221699 r222980 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
r221699 r222980 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 characters, 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
r222975 r222980 1 2017-10-06 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/WorkerScriptLoader.cpp: 22 (WebCore::WorkerScriptLoader::didFail): 23 * workers/WorkerScriptLoader.h: 24 (WebCore::WorkerScriptLoader::error const): 25 26 * workers/WorkerScriptLoaderClient.h: 27 (WebCore::WorkerScriptLoaderClient::~WorkerScriptLoaderClient): 28 (WebCore::WorkerScriptLoaderClient::didReceiveResponse): Deleted. 29 (WebCore::WorkerScriptLoaderClient::notifyFinished): Deleted. 30 31 * workers/service/ServiceWorkerContainer.cpp: 32 (WebCore::ServiceWorkerContainer::startScriptFetchForJob): 33 (WebCore::ServiceWorkerContainer::jobFinishedLoadingScript): 34 (WebCore::ServiceWorkerContainer::jobFailedLoadingScript): 35 * workers/service/ServiceWorkerContainer.h: 36 37 * workers/service/ServiceWorkerFetchResult.h: Copied from Source/WebCore/workers/service/server/SWClientConnection.h. 38 (WebCore::ServiceWorkerFetchResult::encode const): 39 (WebCore::ServiceWorkerFetchResult::decode): 40 41 * workers/service/ServiceWorkerJob.cpp: 42 (WebCore::ServiceWorkerJob::startScriptFetch): 43 (WebCore::ServiceWorkerJob::fetchScriptWithContext): 44 (WebCore::ServiceWorkerJob::didReceiveResponse): 45 (WebCore::ServiceWorkerJob::notifyFinished): 46 * workers/service/ServiceWorkerJob.h: 47 * workers/service/ServiceWorkerJobClient.h: 48 49 * workers/service/server/SWClientConnection.cpp: 50 (WebCore::SWClientConnection::finishedFetchingScript): 51 (WebCore::SWClientConnection::failedFetchingScript): 52 (WebCore::SWClientConnection::startScriptFetchForServer): 53 * workers/service/server/SWClientConnection.h: 54 55 * workers/service/server/SWServer.cpp: 56 (WebCore::SWServer::Connection::finishFetchingScriptInServer): 57 (WebCore::SWServer::startScriptFetch): 58 (WebCore::SWServer::scriptFetchFinished): 59 * workers/service/server/SWServer.h: 60 61 * workers/service/server/SWServerRegistration.cpp: 62 (WebCore::SWServerRegistration::scriptFetchFinished): 63 (WebCore::SWServerRegistration::runUpdateJob): 64 (WebCore::SWServerRegistration::startScriptFetchFromMainThread): 65 (WebCore::SWServerRegistration::startScriptFetchForCurrentJob): 66 * workers/service/server/SWServerRegistration.h: 67 1 68 2017-10-06 Zan Dobersek <zdobersek@igalia.com> 2 69 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r222946 r222980 1321 1321 2E94F43C119207DA00B7F75D /* JSFileReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E94F43A119207DA00B7F75D /* JSFileReader.h */; }; 1322 1322 2E9B5D8F1B66A94E008C6A24 /* WheelEventDeltaFilterMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E9B5D8E1B66A94E008C6A24 /* WheelEventDeltaFilterMac.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1323 2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EA768030FE7126400AB9C8A /* WorkerScriptLoaderClient.h */; };1323 2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EA768030FE7126400AB9C8A /* WorkerScriptLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1324 1324 2EB4BCD2121F03E300EC4885 /* BlobResourceHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EB4BCD0121F03E300EC4885 /* BlobResourceHandle.cpp */; }; 1325 1325 2EB4BCD3121F03E300EC4885 /* BlobResourceHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EB4BCD1121F03E300EC4885 /* BlobResourceHandle.h */; }; … … 2344 2344 517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; }; 2345 2345 517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2346 517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B61C89912600A7E715 /* FetchLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2347 517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2348 517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 41CF8BE51D46222000707DC9 /* FetchBodyConsumer.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2349 517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2346 2350 517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; }; 2347 2351 517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; }; … … 4703 4707 A7D20F63107F406900A80392 /* JSWebGLActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F61107F406900A80392 /* JSWebGLActiveInfo.h */; }; 4704 4708 A7D20F6D107F438B00A80392 /* WebGLActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F6B107F438B00A80392 /* WebGLActiveInfo.h */; }; 4705 A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */; };4709 A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4706 4710 A7D6B34A0F61104500B79FD1 /* WorkerScriptLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */; }; 4707 4711 A7DBF8DD1276919C006B6008 /* TextCheckingHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7DBF8DB1276919C006B6008 /* TextCheckingHelper.cpp */; }; … … 10260 10264 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationData.cpp; sourceTree = "<group>"; }; 10261 10265 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationData.h; sourceTree = "<group>"; }; 10266 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerFetchResult.h; sourceTree = "<group>"; }; 10262 10267 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; }; 10263 10268 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; }; … … 19173 19178 51F175571F3EBC0C00C74950 /* ServiceWorkerContainer.h */, 19174 19179 51F175561F3EBC0C00C74950 /* ServiceWorkerContainer.idl */, 19180 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */, 19175 19181 51F175551F3EBC0C00C74950 /* ServiceWorkerGlobalScope.cpp */, 19176 19182 51F175541F3EBC0C00C74950 /* ServiceWorkerGlobalScope.h */, … … 28146 28152 977B3867122883E900B81FF8 /* HTMLDocumentParser.h in Headers */, 28147 28153 93F198E608245E59001E9ABC /* HTMLElement.h in Headers */, 28154 517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */, 28148 28155 A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */, 28149 28156 977B37241228721700B81FF8 /* HTMLElementStack.h in Headers */, … … 29322 29329 37C738EF1EDBD71B003F2B0B /* MathMLUnknownElement.h in Headers */, 29323 29330 439046EA12DA25E812AF80AC /* MathOperator.h in Headers */, 29331 517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */, 29324 29332 49D5DC2C0F423A73008F20FD /* Matrix3DTransformOperation.h in Headers */, 29325 29333 49E911C70EF86D47009D0CAF /* MatrixTransformOperation.h in Headers */, … … 29477 29485 A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */, 29478 29486 628D214C12131ED10055DCFC /* NetworkingContext.h in Headers */, 29487 517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */, 29479 29488 8A81BF8511DCFD9000DA2B98 /* NetworkLoadMetrics.h in Headers */, 29480 29489 59C27F07138D28CF0079B7E2 /* NetworkResourcesData.h in Headers */, -
trunk/Source/WebCore/workers/WorkerScriptLoader.cpp
r219276 r222980 165 165 } 166 166 167 void WorkerScriptLoader::didFail(const ResourceError& )167 void WorkerScriptLoader::didFail(const ResourceError& error) 168 168 { 169 m_error = error; 169 170 notifyError(); 170 171 } -
trunk/Source/WebCore/workers/WorkerScriptLoader.h
r212993 r222980 27 27 #pragma once 28 28 29 #include " URL.h"29 #include "ResourceError.h" 30 30 #include "ResourceRequest.h" 31 31 #include "ThreadableLoader.h" 32 32 #include "ThreadableLoaderClient.h" 33 #include "URL.h" 33 34 #include <memory> 34 35 #include <wtf/FastMalloc.h> … … 39 40 namespace WebCore { 40 41 41 42 43 44 42 class ResourceResponse; 43 class ScriptExecutionContext; 44 class TextResourceDecoder; 45 class WorkerScriptLoaderClient; 45 46 46 47 48 49 50 51 52 47 class WorkerScriptLoader : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient { 48 WTF_MAKE_FAST_ALLOCATED; 49 public: 50 static Ref<WorkerScriptLoader> create() 51 { 52 return adoptRef(*new WorkerScriptLoader); 53 } 53 54 54 55 55 void loadSynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier); 56 void loadAsynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier, WorkerScriptLoaderClient*); 56 57 57 58 void notifyError(); 58 59 59 String script(); 60 const URL& url() const { return m_url; } 61 const URL& responseURL() const; 62 bool failed() const { return m_failed; } 63 unsigned long identifier() const { return m_identifier; } 60 String script(); 61 const URL& url() const { return m_url; } 62 const URL& responseURL() const; 63 bool failed() const { return m_failed; } 64 unsigned long identifier() const { return m_identifier; } 65 const ResourceError& error() const { return m_error; } 64 66 65 66 67 68 67 void didReceiveResponse(unsigned long identifier, const ResourceResponse&) override; 68 void didReceiveData(const char* data, int dataLength) override; 69 void didFinishLoading(unsigned long identifier) override; 70 void didFail(const ResourceError&) override; 69 71 70 71 72 private: 73 friend class WTF::RefCounted<WorkerScriptLoader>; 72 74 73 74 75 WorkerScriptLoader(); 76 ~WorkerScriptLoader(); 75 77 76 77 78 std::unique_ptr<ResourceRequest> createResourceRequest(const String& initiatorIdentifier); 79 void notifyFinished(); 78 80 79 WorkerScriptLoaderClient* m_client { nullptr }; 80 RefPtr<ThreadableLoader> m_threadableLoader; 81 String m_responseEncoding; 82 RefPtr<TextResourceDecoder> m_decoder; 83 StringBuilder m_script; 84 URL m_url; 85 URL m_responseURL; 86 unsigned long m_identifier { 0 }; 87 bool m_failed { false }; 88 bool m_finishing { false }; 89 }; 81 WorkerScriptLoaderClient* m_client { nullptr }; 82 RefPtr<ThreadableLoader> m_threadableLoader; 83 String m_responseEncoding; 84 RefPtr<TextResourceDecoder> m_decoder; 85 StringBuilder m_script; 86 URL m_url; 87 URL m_responseURL; 88 unsigned long m_identifier { 0 }; 89 bool m_failed { false }; 90 bool m_finishing { false }; 91 ResourceError m_error; 92 }; 90 93 91 94 } // namespace WebCore -
trunk/Source/WebCore/workers/WorkerScriptLoaderClient.h
r207546 r222980 29 29 namespace WebCore { 30 30 31 31 class ResourceResponse; 32 32 33 class WorkerScriptLoaderClient { 34 public: 35 virtual void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse&) { } 33 class WorkerScriptLoaderClient { 34 public: 35 virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&) = 0; 36 virtual void notifyFinished() = 0; 36 37 37 // FIXME: notifyFinished() is not currently guaranteed to be invoked if used from worker context and the worker shuts down in the middle of an operation. 38 // This will cause leaks when we support nested workers. 39 virtual void notifyFinished() { } 40 41 protected: 42 virtual ~WorkerScriptLoaderClient() { } 43 }; 38 protected: 39 virtual ~WorkerScriptLoaderClient() { } 40 }; 44 41 45 42 } // namespace WebCore -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp
r221699 r222980 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, const String& script) 202 { 203 LOG(ServiceWorker, "SeviceWorkerContainer %p finished fetching script for job %" PRIu64, this, job.data().identifier()); 204 205 m_swConnection->finishedFetchingScript(job, script); 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
r221699 r222980 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&, const String&) final; 78 void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&) final; 79 76 80 void jobDidFinish(ServiceWorkerJob&); 77 81 -
trunk/Source/WebCore/workers/service/ServiceWorkerFetchResult.h
r222979 r222980 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" 33 32 34 33 namespace WebCore { 35 34 36 struct ExceptionData; 37 struct ServiceWorkerRegistrationData; 35 struct ServiceWorkerFetchResult { 36 uint64_t jobIdentifier; 37 uint64_t connectionIdentifier; 38 ServiceWorkerRegistrationKey registrationKey; 39 String script; 40 ResourceError scriptError; 38 41 39 class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> { 40 public: 41 WEBCORE_EXPORT SWClientConnection(); 42 WEBCORE_EXPORT virtual ~SWClientConnection(); 42 template<class Encoder> void encode(Encoder&) const; 43 template<class Decoder> static bool decode(Decoder&, ServiceWorkerFetchResult&); 44 }; 43 45 44 void scheduleJob(ServiceWorkerJob&); 46 template<class Encoder> 47 void ServiceWorkerFetchResult::encode(Encoder& encoder) const 48 { 49 encoder << jobIdentifier << connectionIdentifier << registrationKey << script << scriptError; 50 } 45 51 46 virtual uint64_t identifier() const = 0; 52 template<class Decoder> 53 bool ServiceWorkerFetchResult::decode(Decoder& decoder, ServiceWorkerFetchResult& result) 54 { 55 if (!decoder.decode(result.jobIdentifier)) 56 return false; 57 if (!decoder.decode(result.connectionIdentifier)) 58 return false; 59 60 auto registrationKey = ServiceWorkerRegistrationKey::decode(decoder); 61 if (!registrationKey) 62 return false; 63 std::swap(*registrationKey, result.registrationKey); 47 64 48 protected: 49 WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&); 50 WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&); 65 if (!decoder.decode(result.script)) 66 return false; 67 if (!decoder.decode(result.scriptError)) 68 return false; 51 69 52 private: 53 virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0; 54 55 HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_scheduledJobs; 56 }; 70 return true; 71 } 57 72 58 73 } // namespace WebCore -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp
r221699 r222980 30 30 31 31 #include "JSDOMPromiseDeferred.h" 32 #include "ResourceError.h" 33 #include "ResourceResponse.h" 32 34 #include "ServiceWorkerJobData.h" 33 35 #include "ServiceWorkerRegistration.h" … … 65 67 } 66 68 69 void ServiceWorkerJob::startScriptFetch() 70 { 71 ASSERT(currentThread() == m_creationThread); 72 ASSERT(!m_completed); 73 74 m_client->startScriptFetchForJob(*this); 75 } 76 77 void ServiceWorkerJob::fetchScriptWithContext(ScriptExecutionContext& context) 78 { 79 ASSERT(currentThread() == m_creationThread); 80 ASSERT(!m_completed); 81 82 // FIXME: WorkerScriptLoader is the wrong loader class to use here, but there's nothing else better right now. 83 m_scriptLoader = WorkerScriptLoader::create(); 84 m_scriptLoader->loadAsynchronously(&context, m_jobData.scriptURL, FetchOptions::Mode::SameOrigin, ContentSecurityPolicyEnforcement::DoNotEnforce, "serviceWorkerScriptLoad:", this); 85 } 86 87 void ServiceWorkerJob::didReceiveResponse(unsigned long, const ResourceResponse& response) 88 { 89 ASSERT(currentThread() == m_creationThread); 90 ASSERT(!m_completed); 91 ASSERT(m_scriptLoader); 92 93 m_lastResponse = response; 94 } 95 96 void ServiceWorkerJob::notifyFinished() 97 { 98 ASSERT(currentThread() == m_creationThread); 99 ASSERT(m_scriptLoader); 100 101 if (!m_scriptLoader->failed()) 102 m_client->jobFinishedLoadingScript(*this, m_scriptLoader->script()); 103 else 104 m_client->jobFailedLoadingScript(*this, m_scriptLoader->error()); 105 106 m_scriptLoader = nullptr; 107 } 108 67 109 } // namespace WebCore 68 110 -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.h
r221699 r222980 28 28 #if ENABLE(SERVICE_WORKER) 29 29 30 #include "ResourceResponse.h" 30 31 #include "ServiceWorkerJobClient.h" 31 32 #include "ServiceWorkerJobData.h" 33 #include "WorkerScriptLoader.h" 34 #include "WorkerScriptLoaderClient.h" 32 35 #include <wtf/RefPtr.h> 33 36 #include <wtf/RunLoop.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 WorkerScriptLoaderClient { 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 // WorkerScriptLoaderClient 70 void didReceiveResponse(unsigned long identifier, const ResourceResponse&) final; 71 void notifyFinished() final; 61 72 62 73 Ref<ServiceWorkerJobClient> m_client; … … 67 78 68 79 Ref<RunLoop> m_runLoop { RunLoop::current() }; 80 RefPtr<WorkerScriptLoader> m_scriptLoader; 81 ResourceResponse m_lastResponse; 69 82 70 83 #if !ASSERT_DISABLED -
trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h
r221699 r222980 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&, const String&) = 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
r221699 r222980 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, const String& script) 54 { 55 ASSERT(m_scheduledJobs.get(job.data().identifier()) == &job); 56 57 finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), script, { } }); 58 } 59 60 void SWClientConnection::failedFetchingScript(ServiceWorkerJob& job, const ResourceError& error) 61 { 62 ASSERT(m_scheduledJobs.get(job.data().identifier()) == &job); 63 64 finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), { }, error }); 50 65 } 51 66 … … 72 87 } 73 88 89 void SWClientConnection::startScriptFetchForServer(uint64_t jobIdentifier) 90 { 91 auto job = m_scheduledJobs.get(jobIdentifier); 92 if (!job) { 93 LOG_ERROR("Job %" PRIu64 " instructed to start fetch from server, but job was not found", jobIdentifier); 94 95 // FIXME: Should message back to the server here to signal failure to fetch, 96 // but we currently need the registration key to do so, and don't have it here. 97 // In the future we'll refactor to have a global, cross-process job identifier that can be used to overcome this. 98 99 return; 100 } 101 102 job->startScriptFetch(); 103 } 104 74 105 } // namespace WebCore 75 106 -
trunk/Source/WebCore/workers/service/server/SWClientConnection.h
r221699 r222980 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&, const String&); 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
r221699 r222980 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
r221699 r222980 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
r221699 r222980 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.script.length()), " characters, 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
r221699 r222980 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
r222967 r222980 1 2017-10-06 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-10-05 Carlos Garcia Campos <cgarcia@igalia.com> 2 19 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
r221699 r222980 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
r221699 r222980 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
r221699 r222980 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
r221699 r222980 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
r221699 r222980 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
r221699 r222980 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.