Service worker registrations restored from disk may not be reused when the JS calls...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 19:13:24 +0000 (19:13 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 19:13:24 +0000 (19:13 +0000)
commit89b52171c7212921630fffd281a245b88df8bb58
treeff2a28cc7c4e675c105dfc00227ad2a846980f14
parentb6159fd57da4ab42eb96af295378b6b38e6837ca
Service worker registrations restored from disk may not be reused when the JS calls register() again
https://bugs.webkit.org/show_bug.cgi?id=181810
<rdar://problem/36591711>

Reviewed by Youenn Fablet.

Source/WebCore:

The issue was that when restoring a registration from disk, we would not set its active worker right
away. We only set it later in installContextData(). installContextData() is only called after we’ve
launched the service worker process and established a connection to it.

However, we would start processing jobs (such as registrations) before we’ve established the connection
to the service worker process. SWServerJobQueue::runRegisterJob(), in order to reuse an existing
registration checks the registration’s active worker has the right script URL. The issue was that when
this code would execute, we may not have set the registration’s active service worker yet, in which case,
we would update the existing registration instead of reusing it as-is.

To address the issue, we now delay the processing of jobs until the connection to the service worker
process has been established and we've installed all pending contexts via installContextData().

Changed is covered by new API test.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::scheduleJobInServer):
(WebCore::SWServer::scheduleJob):
(WebCore::SWServer::serverToContextConnectionCreated):
* workers/service/server/SWServer.h:

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
(-[SWMessageHandlerForRestoreFromDiskTest initWithExpectedMessage:]):
(-[SWMessageHandlerForRestoreFromDiskTest userContentController:didReceiveScriptMessage:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227220 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm