Bug 178534

Summary: Add initial implementation for serviceWorker.postMessage()
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, buildbot, commit-queue, dbates, esprehn+autocc, ggaren, kangil.han, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar, WebExposed
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://w3c.github.io/ServiceWorker/#service-worker-postmessage
See Also: https://bugs.webkit.org/show_bug.cgi?id=174541
Bug Depends on: 178475, 178491, 178552    
Bug Blocks: 178794    
Attachments:
Description Flags
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Chris Dumez
Reported 2017-10-19 12:32:24 PDT
Add initial implementation for serviceWorker.postMessage(): - https://w3c.github.io/ServiceWorker/#service-worker-postmessage
Attachments
WIP Patch (21.46 KB, patch)
2017-10-19 14:30 PDT, Chris Dumez
no flags
WIP Patch (21.75 KB, patch)
2017-10-19 15:46 PDT, Chris Dumez
no flags
WIP Patch (20.28 KB, patch)
2017-10-23 09:21 PDT, Chris Dumez
no flags
WIP Patch (20.40 KB, patch)
2017-10-23 11:31 PDT, Chris Dumez
no flags
WIP Patch (23.71 KB, patch)
2017-10-23 14:56 PDT, Chris Dumez
no flags
WIP Patch (50.46 KB, patch)
2017-10-23 16:54 PDT, Chris Dumez
no flags
Patch (60.19 KB, patch)
2017-10-23 20:01 PDT, Chris Dumez
no flags
Patch (60.40 KB, patch)
2017-10-23 20:08 PDT, Chris Dumez
no flags
Patch (59.50 KB, patch)
2017-10-23 21:11 PDT, Chris Dumez
no flags
Patch (59.48 KB, patch)
2017-10-23 21:14 PDT, Chris Dumez
no flags
Patch (59.54 KB, patch)
2017-10-23 21:28 PDT, Chris Dumez
no flags
Patch (59.52 KB, patch)
2017-10-24 12:45 PDT, Chris Dumez
no flags
Patch (60.23 KB, patch)
2017-10-24 13:29 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2017-10-19 14:30:05 PDT
Created attachment 324289 [details] WIP Patch
Chris Dumez
Comment 2 2017-10-19 15:46:14 PDT
Created attachment 324303 [details] WIP Patch
Chris Dumez
Comment 3 2017-10-23 09:21:21 PDT
Created attachment 324560 [details] WIP Patch
Chris Dumez
Comment 4 2017-10-23 11:31:06 PDT
Created attachment 324573 [details] WIP Patch
Chris Dumez
Comment 5 2017-10-23 14:56:51 PDT
Created attachment 324594 [details] WIP Patch
Build Bot
Comment 6 2017-10-23 14:59:14 PDT
Attachment 324594 [details] did not pass style-queue: ERROR: Source/WebCore/workers/service/ServiceWorker.h:32: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 1 in 22 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 7 2017-10-23 16:54:51 PDT
Created attachment 324614 [details] WIP Patch
Chris Dumez
Comment 8 2017-10-23 20:01:35 PDT
Chris Dumez
Comment 9 2017-10-23 20:08:26 PDT
Chris Dumez
Comment 10 2017-10-23 21:11:43 PDT
Chris Dumez
Comment 11 2017-10-23 21:14:33 PDT
Chris Dumez
Comment 12 2017-10-23 21:28:46 PDT
Chris Dumez
Comment 13 2017-10-24 12:45:33 PDT
youenn fablet
Comment 14 2017-10-24 12:54:12 PDT
Comment on attachment 324639 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=324639&action=review > Source/WebCore/ChangeLog:18 > + * bindings/js/JSExtendableMessageEvent.cpp: Copied from Source/WebCore/workers/service/ServiceWorker.cpp. Probably added, not copied. > Source/WebCore/bindings/js/JSExtendableMessageEventCustom.cpp:54 > + return result; Is there a way to share some code with JSMessageEvent::data? > Source/WebCore/dom/ScriptExecutionContext.h:114 > + virtual String origin() const = 0; Why not using a SecurityOrigin&/SecurityOrigin*? > Source/WebCore/workers/service/ExtendableMessageEvent.h:57 > + Vector<RefPtr<MessagePort>> ports; Would it be difficult to have a Vector<Ref<MessagePort>> instead? > Source/WebCore/workers/service/ServiceWorker.cpp:68 > + if (!scriptExecutionContext()) I am not sure we can get both a valid ExecState and a null scriptExecutionContext. If so, I would add it as a first check. Can we get a ScriptExecutionContext& as first parameter and get an ExecState from it? Maybe add an ASSERT. > Source/WebCore/workers/service/ServiceWorkerContainer.cpp:84 > + m_controller = ServiceWorker::create(*context, context->selectedServiceWorkerIdentifier()); Can we get a controller whose identifier is not context selectedServiceWorkerIdentifier? > Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:109 > + serviceWorkerGlobalScope.dispatchEvent(ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin)); I guess sourceOrigin might be different from the origin of the service worker, like in the case of data URL iframes. If I am wrong, we might not even need to pass the origin. If the origin cannot be any random origin, maybe we should assert somehow that this is in a restricted set. I probably need to read the spec. > Source/WebCore/workers/service/context/ServiceWorkerThread.h:43 > +using MessagePortChannelArray = Vector<std::unique_ptr<MessagePortChannel>, 1>; Should probably be UniqueRef if possible. > Source/WebCore/workers/service/context/ServiceWorkerThread.h:56 > + WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const String& sourceOrigin); Here as well. > Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp:76 > + auto* workerThread = m_workerThreadMap.get(serviceWorkerIdentifier); Should we protect for a serviceWorkerIdentifier being zero? Even more valid for startFetch above.
Chris Dumez
Comment 15 2017-10-24 13:29:17 PDT
Comment on attachment 324639 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=324639&action=review >> Source/WebCore/bindings/js/JSExtendableMessageEventCustom.cpp:54 >> + return result; > > Is there a way to share some code with JSMessageEvent::data? I'll see what I can do. >> Source/WebCore/dom/ScriptExecutionContext.h:114 >> + virtual String origin() const = 0; > > Why not using a SecurityOrigin&/SecurityOrigin*? This is a pre-existing method on Document / WorkerGlobalScope is is used for the self.origin Web API. This is why it currently returns a String. Also note that I need the origin as a String currently since it is used to populate the messageEvent.source attribute. >> Source/WebCore/workers/service/ExtendableMessageEvent.h:57 >> + Vector<RefPtr<MessagePort>> ports; > > Would it be difficult to have a Vector<Ref<MessagePort>> instead? Yes. This is a long-standing issue with our bindings converters. >> Source/WebCore/workers/service/ServiceWorker.cpp:68 >> + if (!scriptExecutionContext()) > > I am not sure we can get both a valid ExecState and a null scriptExecutionContext. > If so, I would add it as a first check. > > Can we get a ScriptExecutionContext& as first parameter and get an ExecState from it? > Maybe add an ASSERT. Ok. >> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:84 >> + m_controller = ServiceWorker::create(*context, context->selectedServiceWorkerIdentifier()); > > Can we get a controller whose identifier is not context selectedServiceWorkerIdentifier? I think this ways: 1. Register service worker A 2. Access container.controller 3. Register service worker B 4. Access container.controller >> Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:109 >> + serviceWorkerGlobalScope.dispatchEvent(ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin)); > > I guess sourceOrigin might be different from the origin of the service worker, like in the case of data URL iframes. > If I am wrong, we might not even need to pass the origin. > If the origin cannot be any random origin, maybe we should assert somehow that this is in a restricted set. > I probably need to read the spec. No, the source origin is not necessarily the same as the worker's origin. It is the origin of the calling script. >> Source/WebCore/workers/service/context/ServiceWorkerThread.h:43 >> +using MessagePortChannelArray = Vector<std::unique_ptr<MessagePortChannel>, 1>; > > Should probably be UniqueRef if possible. This is a pre-existing WebCore type. I am merely forward declaring. >> Source/WebCore/workers/service/context/ServiceWorkerThread.h:56 >> + WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const String& sourceOrigin); > > Here as well. No, as mentioned in an earlier patch, channels can be null. >> Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp:76 >> + auto* workerThread = m_workerThreadMap.get(serviceWorkerIdentifier); > > Should we protect for a serviceWorkerIdentifier being zero? > Even more valid for startFetch above. It would hit an assertion in HashMap.
Chris Dumez
Comment 16 2017-10-24 13:29:45 PDT
Chris Dumez
Comment 17 2017-10-24 14:22:59 PDT
Comment on attachment 324713 [details] Patch Clearing flags on attachment: 324713 Committed r223922: <https://trac.webkit.org/changeset/223922>
Chris Dumez
Comment 18 2017-10-24 14:23:01 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 19 2017-11-15 13:02:03 PST
Note You need to log in before you can comment on or make changes to this bug.