Changeset 251985 in webkit
- Timestamp:
- Nov 4, 2019 5:31:58 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r251984 r251985 1 2019-11-04 youenn fablet <youenn@apple.com> 2 3 Order of postMessage and fetch events should be preserved when going from client to service worker 4 https://bugs.webkit.org/show_bug.cgi?id=203236 5 6 Reviewed by Chris Dumez. 7 8 * http/wpt/service-workers/service-worker/postMessage-fetch-order-worker.js: Added. 9 * http/wpt/service-workers/service-worker/postMessage-fetch-order.https-expected.txt: Added. 10 * http/wpt/service-workers/service-worker/postMessage-fetch-order.https.html: Added. 11 1 12 2019-11-04 Oriol Brufau <obrufau@igalia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r251977 r251985 1 2019-11-04 youenn fablet <youenn@apple.com> 2 3 Order of postMessage and fetch events should be preserved when going from client to service worker 4 https://bugs.webkit.org/show_bug.cgi?id=203236 5 6 Reviewed by Chris Dumez. 7 8 Now that post message is going through network process, we can make the order predictable. 9 Remove unnecessary task posting when firing events in service worker context and when posting message from a client. 10 Test: http/wpt/service-workers/service-worker/postMessage-fetch-order.https.html 11 12 * workers/service/ServiceWorker.cpp: 13 (WebCore::ServiceWorker::swConnection): 14 (WebCore::ServiceWorker::postMessage): 15 * workers/service/ServiceWorker.h: 16 * workers/service/context/ServiceWorkerThread.cpp: 17 (WebCore::ServiceWorkerThread::postFetchTask): 18 (WebCore::ServiceWorkerThread::fireInstallEvent): 19 (WebCore::ServiceWorkerThread::fireActivateEvent): 20 1 21 2019-11-03 Zalan Bujtas <zalan@apple.com> 2 22 -
trunk/Source/WebCore/workers/service/ServiceWorker.cpp
r251244 r251985 41 41 #include "ServiceWorkerProvider.h" 42 42 #include "ServiceWorkerThread.h" 43 #include "WorkerSWClientConnection.h" 43 44 #include <JavaScriptCore/JSCJSValueInlines.h> 44 45 #include <wtf/IsoMallocInlines.h> … … 94 95 95 96 updatePendingActivityForEventDispatch(); 97 } 98 99 SWClientConnection& ServiceWorker::swConnection() 100 { 101 ASSERT(scriptExecutionContext()); 102 if (is<WorkerGlobalScope>(scriptExecutionContext())) 103 return downcast<WorkerGlobalScope>(scriptExecutionContext())->swClientConnection(); 104 return ServiceWorkerProvider::singleton().serviceWorkerConnection(); 96 105 } 97 106 … … 122 131 } 123 132 124 MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() }; 125 callOnMainThread([destinationIdentifier = identifier(), message = WTFMove(message), sourceIdentifier = WTFMove(sourceIdentifier)]() mutable { 126 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 127 connection.postMessageToServiceWorker(destinationIdentifier, WTFMove(message), sourceIdentifier); 128 }); 133 MessageWithMessagePorts message { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() }; 134 swConnection().postMessageToServiceWorker(identifier(), WTFMove(message), sourceIdentifier); 129 135 return { }; 130 136 } -
trunk/Source/WebCore/workers/service/ServiceWorker.h
r251244 r251985 43 43 44 44 class Frame; 45 class SWClientConnection; 45 46 46 47 class ServiceWorker final : public RefCounted<ServiceWorker>, public EventTargetWithInlineData, public ActiveDOMObject { … … 83 84 bool isAlwaysOnLoggingAllowed() const; 84 85 86 SWClientConnection& swConnection(); 87 85 88 ServiceWorkerData m_data; 86 89 bool m_isStopped { false }; -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
r250104 r251985 99 99 // FIXME: request and options come straigth from IPC so are already isolated. We should be able to take benefit of that. 100 100 runLoop().postTaskForMode([client = WTFMove(client), clientId, request = request.isolatedCopy(), referrer = referrer.isolatedCopy(), options = options.isolatedCopy()] (ScriptExecutionContext& context) mutable { 101 context.postTask([client = WTFMove(client), clientId, request = WTFMove(request), referrer = WTFMove(referrer), options = WTFMove(options)] (ScriptExecutionContext& context) mutable { 102 ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), downcast<ServiceWorkerGlobalScope>(context), clientId, WTFMove(request), WTFMove(referrer), WTFMove(options)); 103 }); 101 ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), downcast<ServiceWorkerGlobalScope>(context), clientId, WTFMove(request), WTFMove(referrer), WTFMove(options)); 104 102 }, WorkerRunLoop::defaultMode()); 105 103 } … … 141 139 void ServiceWorkerThread::fireInstallEvent() 142 140 { 143 ScriptExecutionContext::Task task([jobDataIdentifier = m_data.jobDataIdentifier, serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable { 144 context.postTask([jobDataIdentifier, serviceWorkerIdentifier](ScriptExecutionContext& context) { 145 auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context); 146 auto installEvent = ExtendableEvent::create(eventNames().installEvent, { }, ExtendableEvent::IsTrusted::Yes); 147 serviceWorkerGlobalScope.dispatchEvent(installEvent); 148 149 installEvent->whenAllExtendLifetimePromisesAreSettled([jobDataIdentifier, serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) { 150 bool hasRejectedAnyPromise = false; 151 for (auto& promise : extendLifetimePromises) { 152 if (promise->status() == DOMPromise::Status::Rejected) { 153 hasRejectedAnyPromise = true; 154 break; 155 } 141 runLoop().postTask([jobDataIdentifier = m_data.jobDataIdentifier, serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable { 142 auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context); 143 auto installEvent = ExtendableEvent::create(eventNames().installEvent, { }, ExtendableEvent::IsTrusted::Yes); 144 serviceWorkerGlobalScope.dispatchEvent(installEvent); 145 146 installEvent->whenAllExtendLifetimePromisesAreSettled([jobDataIdentifier, serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) { 147 bool hasRejectedAnyPromise = false; 148 for (auto& promise : extendLifetimePromises) { 149 if (promise->status() == DOMPromise::Status::Rejected) { 150 hasRejectedAnyPromise = true; 151 break; 156 152 } 157 callOnMainThread([jobDataIdentifier, serviceWorkerIdentifier, hasRejectedAnyPromise] () mutable {158 if (auto* connection = SWContextManager::singleton().connection())159 connection->didFinishInstall(jobDataIdentifier, serviceWorkerIdentifier, !hasRejectedAnyPromise);160 });153 } 154 callOnMainThread([jobDataIdentifier, serviceWorkerIdentifier, hasRejectedAnyPromise] () mutable { 155 if (auto* connection = SWContextManager::singleton().connection()) 156 connection->didFinishInstall(jobDataIdentifier, serviceWorkerIdentifier, !hasRejectedAnyPromise); 161 157 }); 162 158 }); 163 159 }); 164 runLoop().postTask(WTFMove(task));165 160 } 166 161 167 162 void ServiceWorkerThread::fireActivateEvent() 168 163 { 169 ScriptExecutionContext::Task task([serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable { 170 context.postTask([serviceWorkerIdentifier](ScriptExecutionContext& context) { 171 auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context); 172 auto activateEvent = ExtendableEvent::create(eventNames().activateEvent, { }, ExtendableEvent::IsTrusted::Yes); 173 serviceWorkerGlobalScope.dispatchEvent(activateEvent); 174 175 activateEvent->whenAllExtendLifetimePromisesAreSettled([serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&&) { 176 callOnMainThread([serviceWorkerIdentifier] () mutable { 177 if (auto* connection = SWContextManager::singleton().connection()) 178 connection->didFinishActivation(serviceWorkerIdentifier); 179 }); 164 runLoop().postTask([serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable { 165 auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context); 166 auto activateEvent = ExtendableEvent::create(eventNames().activateEvent, { }, ExtendableEvent::IsTrusted::Yes); 167 serviceWorkerGlobalScope.dispatchEvent(activateEvent); 168 169 activateEvent->whenAllExtendLifetimePromisesAreSettled([serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&&) { 170 callOnMainThread([serviceWorkerIdentifier] () mutable { 171 if (auto* connection = SWContextManager::singleton().connection()) 172 connection->didFinishActivation(serviceWorkerIdentifier); 180 173 }); 181 174 }); 182 175 }); 183 runLoop().postTask(WTFMove(task));184 176 } 185 177
Note: See TracChangeset
for help on using the changeset viewer.