Skip to content

Commit 66903c8

Browse files
WebSWClientConnection should do IPC to StorageProcess if its WebSWOriginTable is not yet initialized
https://bugs.webkit.org/show_bug.cgi?id=179668 Patch by Youenn Fablet <[email protected]> on 2017-11-14 Reviewed by Chris Dumez. Source/WebCore: Covered by existing updated tests. Removing hasServiceWorkerRegisteredForOrigin and using hasServiceWorkerRegistration instead. The former is only checking the shared map which might not be initialized at the time the function is called. The latter is going to the StorageProcess if the map is not yet initialized. * testing/Internals.cpp: (WebCore::Internals::hasServiceWorkerRegisteredForOrigin): Deleted. * testing/Internals.h: * testing/Internals.idl: * workers/service/server/SWClientConnection.h: Source/WebKit: There may be cases where the origin table is not initialized and we would think there is no service worker registration. In such a case, we should go to the StorageProcess. StorageProcess is now sending an IPC message back to each registered SW connection so that WebProcess will know whether its map is correctly initialized or not. Renaming hasServiceWorkerRegisteredForOrigin in mayHaveServiceWorkerRegisteredForOrigin. * WebProcess/Storage/WebSWClientConnection.cpp: (WebKit::WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin const): (WebKit::WebSWClientConnection::matchRegistration): (WebKit::WebSWClientConnection::hasServiceWorkerRegisteredForOrigin const): Deleted. * WebProcess/Storage/WebSWClientConnection.h: * WebProcess/Storage/WebSWOriginTable.h: (WebKit::WebSWOriginTable::isInitialized const): * WebProcess/Storage/WebServiceWorkerProvider.cpp: (WebKit::shouldHandleFetch): LayoutTests: Updated tests to use hasServiceWorkerRegistration instead of hasServiceWorkerRegisteredForOrigin. Since the latter is trying to match a registration and compares scopes, we need the scopes to be set right on the tests. * http/tests/workers/service/basic-unregister.https-expected.txt: * http/tests/workers/service/resources/basic-register.js: * http/tests/workers/service/resources/basic-unregister.js: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@224832 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent f577e5b commit 66903c8

17 files changed

+92
-35
lines changed

LayoutTests/ChangeLog

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2017-11-14 Youenn Fablet <[email protected]>
2+
3+
WebSWClientConnection should do IPC to StorageProcess if its WebSWOriginTable is not yet initialized
4+
https://bugs.webkit.org/show_bug.cgi?id=179668
5+
6+
Reviewed by Chris Dumez.
7+
8+
Updated tests to use hasServiceWorkerRegistration instead of hasServiceWorkerRegisteredForOrigin.
9+
Since the latter is trying to match a registration and compares scopes, we need the scopes to be set right on the tests.
10+
11+
* http/tests/workers/service/basic-unregister.https-expected.txt:
12+
* http/tests/workers/service/resources/basic-register.js:
13+
* http/tests/workers/service/resources/basic-unregister.js:
14+
115
2017-11-14 Ms2ger <[email protected]>
216

317
Add some bug numbers for failing XHR tests

LayoutTests/http/tests/workers/service/basic-unregister.https-expected.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PASS: There is initially no service worker registered for the origin
2-
PASS: registration scope is https://127.0.0.1:8443/workers/service/
2+
PASS: registration scope is https://127.0.0.1:8443/
33
PASS: There is a service worker registered for the origin
44
PASS: Unregistration was successful
55
PASS: There is no service worker registered for the origin

LayoutTests/http/tests/workers/service/resources/basic-register.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ function done()
55

66
async function test()
77
{
8-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
8+
if (!await internals.hasServiceWorkerRegistration(self.origin))
99
log("PASS: No service worker is initially registered for this origin");
1010
else
1111
log("FAIL: A service worker is initially registered for this origin");
1212

1313
testRunner.setPrivateBrowsingEnabled(true);
1414

15-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
15+
if (!await internals.hasServiceWorkerRegistration(self.origin))
1616
log("PASS: No service worker is initially registered for this origin in private session");
1717
else
1818
log("FAIL: A service worker is initially registered for this origin in private session");
@@ -32,14 +32,14 @@ async function test()
3232
else
3333
log("FAIL: registration object's updateViaCache is invalid, got: " + r.updateViaCache);
3434

35-
if (internals.hasServiceWorkerRegisteredForOrigin(self.origin))
35+
if (await internals.hasServiceWorkerRegistration("/test"))
3636
log("PASS: A service worker is now registered for this origin");
3737
else
3838
log("FAIL: No service worker is registered for this origin");
3939

4040
testRunner.setPrivateBrowsingEnabled(true);
4141

42-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
42+
if (!await internals.hasServiceWorkerRegistration("/test"))
4343
log("PASS: No service worker is registered for this origin in private session");
4444
else
4545
log("FAIL: A service worker is registered for this origin in private session");

LayoutTests/http/tests/workers/service/resources/basic-unregister.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ function done()
66
async function test()
77
{
88
try {
9-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
9+
if (!await internals.hasServiceWorkerRegistration(self.origin))
1010
log("PASS: There is initially no service worker registered for the origin");
1111
else
1212
log("FAIL: There is initially a service worker registered for the origin");
1313

14-
let registration = await navigator.serviceWorker.register("resources/basic-fetch-worker.js", { });
15-
if (registration.scope === "https://127.0.0.1:8443/%3Cspan%20class="x x-first x-last">workers/service/")
14+
let registration = await navigator.serviceWorker.register("resources/basic-fetch-worker.js", { scope: "/" });
15+
if (registration.scope === "https://127.0.0.1:8443/")
1616
log("PASS: registration scope is " + registration.scope);
1717
else
1818
log("FAIL: registration scope is " + registration.scope);
1919

20-
if (internals.hasServiceWorkerRegisteredForOrigin(self.origin))
20+
if (await internals.hasServiceWorkerRegistration(self.origin))
2121
log("PASS: There is a service worker registered for the origin");
2222
else
2323
log("FAIL: There is no service worker registered for the origin");
@@ -28,7 +28,7 @@ async function test()
2828
else
2929
log("FAIL: Unregistration failed");
3030

31-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
31+
if (!await internals.hasServiceWorkerRegistration(self.origin))
3232
log("PASS: There is no service worker registered for the origin");
3333
else
3434
log("FAIL: There is a service worker registered for the origin");
@@ -39,7 +39,7 @@ async function test()
3939
else
4040
log("FAIL: Unregistration succeeded unexpectedly");
4141

42-
if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
42+
if (!await internals.hasServiceWorkerRegistration(self.origin))
4343
log("PASS: There is no service worker registered for the origin");
4444
else
4545
log("FAIL: There is a service worker registered for the origin");
@@ -50,7 +50,7 @@ async function test()
5050
else
5151
log("FAIL: registration scope is " + registration.scope);
5252

53-
if (internals.hasServiceWorkerRegisteredForOrigin(self.origin))
53+
if (await internals.hasServiceWorkerRegistration("/workers/service/resources/test"))
5454
log("PASS: There is a service worker registered for the origin");
5555
else
5656
log("FAIL: There is no service worker registered for the origin");

Source/WebCore/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2017-11-14 Youenn Fablet <[email protected]>
2+
3+
WebSWClientConnection should do IPC to StorageProcess if its WebSWOriginTable is not yet initialized
4+
https://bugs.webkit.org/show_bug.cgi?id=179668
5+
6+
Reviewed by Chris Dumez.
7+
8+
Covered by existing updated tests.
9+
10+
Removing hasServiceWorkerRegisteredForOrigin and using hasServiceWorkerRegistration instead.
11+
The former is only checking the shared map which might not be initialized at the time the function is called.
12+
The latter is going to the StorageProcess if the map is not yet initialized.
13+
14+
* testing/Internals.cpp:
15+
(WebCore::Internals::hasServiceWorkerRegisteredForOrigin): Deleted.
16+
* testing/Internals.h:
17+
* testing/Internals.idl:
18+
* workers/service/server/SWClientConnection.h:
19+
120
2017-11-14 Joseph Pecoraro <[email protected]>
221

322
Web Inspector: Add a ServiceWorker domain to get information about an inspected ServiceWorker

Source/WebCore/testing/Internals.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -4232,19 +4232,6 @@ void Internals::setConsoleMessageListener(RefPtr<StringCallback>&& listener)
42324232
contextDocument()->setConsoleMessageListener(WTFMove(listener));
42334233
}
42344234

4235-
bool Internals::hasServiceWorkerRegisteredForOrigin(const String& origin)
4236-
{
4237-
#if ENABLE(SERVICE_WORKER)
4238-
if (!contextDocument())
4239-
return false;
4240-
4241-
return ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(contextDocument()->sessionID()).hasServiceWorkerRegisteredForOrigin(SecurityOrigin::createFromString(origin));
4242-
#else
4243-
UNUSED_PARAM(origin);
4244-
return false;
4245-
#endif
4246-
}
4247-
42484235
void Internals::setResponseSizeWithPadding(FetchResponse& response, uint64_t size)
42494236
{
42504237
response.setBodySizeWithPadding(size);

Source/WebCore/testing/Internals.h

-2
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,6 @@ class Internals final : public RefCounted<Internals>, private ContextDestructio
625625
void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
626626
#endif
627627

628-
bool hasServiceWorkerRegisteredForOrigin(const String&);
629-
630628
#if ENABLE(APPLE_PAY)
631629
MockPaymentCoordinator& mockPaymentCoordinator() const;
632630
#endif

Source/WebCore/testing/Internals.idl

-2
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,6 @@ enum EventThrottlingBehavior {
568568
[Conditional=SERVICE_WORKER, CallWith=ScriptExecutionContext] FetchEvent createBeingDispatchedFetchEvent();
569569
[Conditional=SERVICE_WORKER] Promise<boolean> hasServiceWorkerRegistration(DOMString scopeURL);
570570

571-
boolean hasServiceWorkerRegisteredForOrigin(DOMString origin);
572-
573571
[EnabledAtRuntime=WebAnimations] DOMString timelineDescription(AnimationTimeline timeline);
574572
[EnabledAtRuntime=WebAnimations] void pauseTimeline(AnimationTimeline timeline);
575573
[EnabledAtRuntime=WebAnimations] void setTimelineCurrentTime(AnimationTimeline timeline, double currentTime);

Source/WebCore/workers/service/server/SWClientConnection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> {
6666

6767
virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
6868
virtual uint64_t identifier() const = 0;
69-
virtual bool hasServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
69+
virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
7070

7171
protected:
7272
WEBCORE_EXPORT SWClientConnection();

Source/WebKit/ChangeLog

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2017-11-14 Youenn Fablet <[email protected]>
2+
3+
WebSWClientConnection should do IPC to StorageProcess if its WebSWOriginTable is not yet initialized
4+
https://bugs.webkit.org/show_bug.cgi?id=179668
5+
6+
Reviewed by Chris Dumez.
7+
8+
There may be cases where the origin table is not initialized and we would think there is no service worker registration.
9+
In such a case, we should go to the StorageProcess.
10+
StorageProcess is now sending an IPC message back to each registered SW connection so that WebProcess will know whether its map
11+
is correctly initialized or not.
12+
13+
Renaming hasServiceWorkerRegisteredForOrigin in mayHaveServiceWorkerRegisteredForOrigin.
14+
15+
* WebProcess/Storage/WebSWClientConnection.cpp:
16+
(WebKit::WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin const):
17+
(WebKit::WebSWClientConnection::matchRegistration):
18+
(WebKit::WebSWClientConnection::hasServiceWorkerRegisteredForOrigin const): Deleted.
19+
* WebProcess/Storage/WebSWClientConnection.h:
20+
* WebProcess/Storage/WebSWOriginTable.h:
21+
(WebKit::WebSWOriginTable::isInitialized const):
22+
* WebProcess/Storage/WebServiceWorkerProvider.cpp:
23+
(WebKit::shouldHandleFetch):
24+
125
2017-11-14 Brent Fulgham <[email protected]>
226

327
Consolidate sysctl-read rules in WebProcess sandbox

Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ void WebSWOriginStore::registerSWServerConnection(WebSWServerConnection& connect
6262
{
6363
m_webSWServerConnections.add(&connection);
6464

65-
if (m_store.isEmpty())
65+
if (m_store.isEmpty()) {
66+
connection.send(Messages::WebSWClientConnection::InitializeSWOriginTableAsEmpty());
6667
return;
68+
}
6769

6870
sendStoreHandle(connection);
6971
}

Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerReg
9494
send(Messages::WebSWServerConnection::DidResolveRegistrationPromise(key));
9595
}
9696

97-
bool WebSWClientConnection::hasServiceWorkerRegisteredForOrigin(const SecurityOrigin& origin) const
97+
bool WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin& origin) const
9898
{
99+
if (!m_swOriginTable->isInitialized())
100+
return true;
101+
99102
return m_swOriginTable->contains(origin);
100103
}
101104

@@ -104,6 +107,11 @@ void WebSWClientConnection::setSWOriginTableSharedMemory(const SharedMemory::Han
104107
m_swOriginTable->setSharedMemory(handle);
105108
}
106109

110+
void WebSWClientConnection::initializeSWOriginTableAsEmpty()
111+
{
112+
m_swOriginTable->initializeAsEmpty();
113+
}
114+
107115
void WebSWClientConnection::didMatchRegistration(uint64_t matchingRequest, std::optional<ServiceWorkerRegistrationData>&& result)
108116
{
109117
if (auto completionHandler = m_ongoingMatchRegistrationTasks.take(matchingRequest))
@@ -112,7 +120,7 @@ void WebSWClientConnection::didMatchRegistration(uint64_t matchingRequest, std::
112120

113121
void WebSWClientConnection::matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
114122
{
115-
if (!hasServiceWorkerRegisteredForOrigin(topOrigin)) {
123+
if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
116124
callback(std::nullopt);
117125
return;
118126
}

Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class WebSWClientConnection : public WebCore::SWClientConnection, public IPC::Me
6060
void disconnectedFromWebProcess();
6161
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
6262

63-
bool hasServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
63+
bool mayHaveServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
6464
Ref<ServiceWorkerClientFetch> startFetch(WebServiceWorkerProvider&, Ref<WebCore::ResourceLoader>&&, uint64_t identifier, ServiceWorkerClientFetch::Callback&&);
6565

6666
void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerData&& source, const String& sourceOrigin);
@@ -81,6 +81,7 @@ class WebSWClientConnection : public WebCore::SWClientConnection, public IPC::Me
8181
uint64_t messageSenderDestinationID() final { return m_identifier; }
8282

8383
void setSWOriginTableSharedMemory(const SharedMemory::Handle&);
84+
void initializeSWOriginTableAsEmpty();
8485

8586
PAL::SessionID m_sessionID;
8687
uint64_t m_identifier;

Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ messages -> WebSWClientConnection {
3232
UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum WebCore::ServiceWorkerState state)
3333
FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier identifier)
3434

35+
InitializeSWOriginTableAsEmpty()
3536
SetSWOriginTableSharedMemory(WebKit::SharedMemory::Handle handle)
3637
PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
3738

Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ bool WebSWOriginTable::contains(const SecurityOrigin& origin) const
4444

4545
void WebSWOriginTable::setSharedMemory(const SharedMemory::Handle& handle)
4646
{
47+
m_isInitialized = true;
48+
4749
auto sharedMemory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
4850
if (!sharedMemory)
4951
return;

Source/WebKit/WebProcess/Storage/WebSWOriginTable.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ class WebSWOriginTable {
4040
public:
4141
WebSWOriginTable() = default;
4242

43+
bool isInitialized() const { return m_isInitialized; }
4344
bool contains(const WebCore::SecurityOrigin&) const;
4445
void setSharedMemory(const SharedMemory::Handle&);
46+
void initializeAsEmpty() { m_isInitialized = true; }
4547

4648
private:
4749
SharedStringHashTableReadOnly m_serviceWorkerOriginTable;
50+
bool m_isInitialized { false };
4851
};
4952

5053
} // namespace WebKit

Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static inline bool shouldHandleFetch(const WebSWClientConnection& connection, Ca
7474
if (!resource)
7575
return false;
7676

77-
return connection.hasServiceWorkerRegisteredForOrigin(*resource->origin());
77+
return connection.mayHaveServiceWorkerRegisteredForOrigin(*resource->origin());
7878
}
7979

8080
void WebServiceWorkerProvider::handleFetch(ResourceLoader& loader, CachedResource* resource, PAL::SessionID sessionID, ServiceWorkerClientFetch::Callback&& callback)

0 commit comments

Comments
 (0)