Diff
Modified: trunk/LayoutTests/ChangeLog (249286 => 249287)
--- trunk/LayoutTests/ChangeLog 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/LayoutTests/ChangeLog 2019-08-29 19:24:46 UTC (rev 249287)
@@ -1,3 +1,15 @@
+2019-08-29 Youenn Fablet <[email protected]>
+
+ Skip fetch event dispatching if no fetch event handler is added at script evaluation time
+ https://bugs.webkit.org/show_bug.cgi?id=201174
+
+ Reviewed by Chris Dumez.
+
+ * http/wpt/service-workers/skipFetchEvent-worker.js: Added.
+ (async.doTest):
+ * http/wpt/service-workers/skipFetchEvent.https-expected.txt: Added.
+ * http/wpt/service-workers/skipFetchEvent.https.html: Added.
+
2019-08-29 Alicia Boya GarcĂa <[email protected]>
[GTK] Unreviewed test gardening
Added: trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent-worker.js (0 => 249287)
--- trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent-worker.js (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent-worker.js 2019-08-29 19:24:46 UTC (rev 249287)
@@ -0,0 +1,18 @@
+async function doTest(event)
+{
+ if (event.data ="" "SET-FETCH") {
+ self.receivedFetch = 0;
+ self.addEventListener("fetch", (event) => {
+ self.receivedFetch++;
+ });
+ event.source.postMessage("OK");
+ return;
+ }
+ if (event.data ="" "GET-FETCH") {
+ event.source.postMessage(self.receivedFetch);
+ return;
+ }
+ event.source.postMessage("KO");
+}
+
+self.addEventListener("message", doTest);
Added: trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https-expected.txt (0 => 249287)
--- trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https-expected.txt 2019-08-29 19:24:46 UTC (rev 249287)
@@ -0,0 +1,6 @@
+
+
+PASS Setup worker
+PASS Setup fetch event after script is run
+PASS Fetch event should be skipped
+
Added: trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https.html (0 => 249287)
--- trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/skipFetchEvent.https.html 2019-08-29 19:24:46 UTC (rev 249287)
@@ -0,0 +1,57 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "test";
+var activeWorker;
+
+promise_test(async (test) => {
+ var registration = await navigator.serviceWorker.register("skipFetchEvent-worker.js", { scope : scope });
+ activeWorker = registration.active;
+ if (activeWorker)
+ return;
+ activeWorker = registration.installing;
+ return new Promise(resolve => {
+ activeWorker.addEventListener('statechange', () => {
+ if (activeWorker.state === "activated")
+ resolve();
+ });
+ });
+}, "Setup worker");
+
+promise_test(async (test) => {
+ var promise = new Promise((resolve, reject) => {
+ navigator.serviceWorker.addEventListener("message", (event) => {
+ resolve(event.data);
+ });
+ });
+
+ activeWorker.postMessage("SET-FETCH");
+ var result = await promise;
+
+ assert_equals(result, "OK");
+}, "Setup fetch event after script is run");
+
+promise_test(async (test) => {
+ var promise = new Promise((resolve, reject) => {
+ navigator.serviceWorker.addEventListener("message", (event) => {
+ resolve(event.data);
+ });
+ });
+
+ const iframe = await with_iframe(scope);
+
+ assert_true(!!iframe.contentWindow.navigator.serviceWorker.controller);
+
+ activeWorker.postMessage("GET-FETCH");
+ var result = await promise;
+
+ assert_equals(result, 0);
+}, "Fetch event should be skipped");
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (249286 => 249287)
--- trunk/Source/WebCore/ChangeLog 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/ChangeLog 2019-08-29 19:24:46 UTC (rev 249287)
@@ -1,3 +1,56 @@
+2019-08-29 Youenn Fablet <[email protected]>
+
+ Skip fetch event dispatching if no fetch event handler is added at script evaluation time
+ https://bugs.webkit.org/show_bug.cgi?id=201174
+
+ Reviewed by Chris Dumez.
+
+ At end of worker script evaluation, store whether a fetch event handler is registered.
+ Send it back to the SWServer that will store it in the corresponding SWServerWorker.
+
+ Add support for soft update directly from the registration.
+ This will trigger a soft-update from the worker context itself.
+ In theory, this should be started by the job queue but we do not have a way yet to implement this as per spec.
+
+ Test: http/wpt/service-workers/skipFetchEvent.https.html
+
+ * workers/DedicatedWorkerThread.h:
+ (WebCore::DedicatedWorkerThread::start):
+ * workers/WorkerMessagingProxy.cpp:
+ (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+ * workers/WorkerThread.cpp:
+ (WebCore::WorkerThread::workerThread):
+ * workers/WorkerThread.h:
+ (WebCore::WorkerThread::finishedEvaluatingScript):
+ * workers/service/context/SWContextManager.cpp:
+ (WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
+ (WebCore::SWContextManager::startedServiceWorker):
+ (WebCore::SWContextManager::softUpdate):
+ * workers/service/context/SWContextManager.h:
+ * workers/service/context/ServiceWorkerThread.cpp:
+ (WebCore::ServiceWorkerThread::postFetchTask):
+ (WebCore::ServiceWorkerThread::softUpdate):
+ (WebCore::ServiceWorkerThread::finishedEvaluatingScript):
+ (WebCore::ServiceWorkerThread::start):
+ * workers/service/context/ServiceWorkerThread.h:
+ (WebCore::ServiceWorkerThread::doesHandleFetch const):
+ * workers/service/server/SWServer.h:
+ * workers/service/server/SWServerRegistration.cpp:
+ (WebCore::SWServerRegistration::shouldSoftUpdate const):
+ (WebCore::SWServerRegistration::softUpdate):
+ * workers/service/server/SWServerRegistration.h:
+ (WebCore::SWServerRegistration::isStale const):
+ * workers/service/server/SWServerToContextConnection.cpp:
+ (WebCore::SWServerToContextConnection::generateConnectionIdentifier):
+ (WebCore::SWServerToContextConnection::SWServerToContextConnection):
+ (WebCore::SWServerToContextConnection::scriptContextStarted):
+ * workers/service/server/SWServerToContextConnection.h:
+ * workers/service/server/SWServerWorker.cpp:
+ (WebCore::SWServerWorker::scriptContextStarted):
+ (WebCore::SWServerWorker::setState):
+ * workers/service/server/SWServerWorker.h:
+ (WebCore::SWServerWorker::shouldSkipFetchEvent const):
+
2019-08-29 Keith Rollin <[email protected]>
Remove support for macOS < 10.13 (part 3)
Modified: trunk/Source/WebCore/workers/DedicatedWorkerThread.h (249286 => 249287)
--- trunk/Source/WebCore/workers/DedicatedWorkerThread.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/DedicatedWorkerThread.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -47,6 +47,7 @@
virtual ~DedicatedWorkerThread();
WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
+ void start() { WorkerThread::start(nullptr); }
protected:
Ref<WorkerGlobalScope> createWorkerGlobalScope(const URL&, Ref<SecurityOrigin>&&, const String& name, const String& identifier, const String& userAgent, bool isOnline, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, PAL::SessionID) override;
Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -91,7 +91,7 @@
auto thread = DedicatedWorkerThread::create(scriptURL, name, identifier, userAgent, isOnline, sourceCode, *this, *this, *this, startMode, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, document.topOrigin(), timeOrigin, proxy, socketProvider, runtimeFlags, sessionID);
workerThreadCreated(thread.get());
- thread->start(nullptr);
+ thread->start();
m_inspectorProxy->workerStarted(m_scriptExecutionContext.get(), thread.ptr(), scriptURL);
}
Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/WorkerThread.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -193,6 +193,8 @@
String exceptionMessage;
scriptController->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, URL(m_startupData->m_scriptURL)), &exceptionMessage);
+ finishedEvaluatingScript();
+
callOnMainThread([evaluateCallback = WTFMove(m_evaluateCallback), message = exceptionMessage.isolatedCopy()] {
if (evaluateCallback)
evaluateCallback(message);
Modified: trunk/Source/WebCore/workers/WorkerThread.h (249286 => 249287)
--- trunk/Source/WebCore/workers/WorkerThread.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/WorkerThread.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -65,7 +65,6 @@
static HashSet<WorkerThread*>& workerThreads(const LockHolder&);
static Lock& workerThreadsMutex();
- WEBCORE_EXPORT void start(WTF::Function<void(const String&)>&& evaluateCallback);
void stop(WTF::Function<void()>&& terminatedCallback);
Thread* thread() const { return m_thread.get(); }
@@ -104,10 +103,14 @@
IDBClient::IDBConnectionProxy* idbConnectionProxy();
SocketProvider* socketProvider();
+ void start(Function<void(const String&)>&& evaluateCallback);
+
private:
void workerThread();
virtual bool isServiceWorkerThread() const { return false; }
+ virtual void finishedEvaluatingScript() { }
+
RefPtr<Thread> m_thread;
String m_identifier;
WorkerRunLoop m_runLoop;
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -59,16 +59,20 @@
auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorkerThreadProxy));
ASSERT_UNUSED(result, result.isNewEntry);
- threadProxy->thread().start([jobDataIdentifier, serviceWorkerIdentifier](const String& exceptionMessage) {
- SWContextManager::singleton().startedServiceWorker(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
+ threadProxy->thread().start([jobDataIdentifier, serviceWorkerIdentifier](const String& exceptionMessage, bool doesHandleFetch) {
+ SWContextManager::singleton().startedServiceWorker(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage, doesHandleFetch);
});
}
-void SWContextManager::startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
+void SWContextManager::startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage, bool doesHandleFetch)
{
- connection()->serviceWorkerStartedWithMessage(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
if (m_serviceWorkerCreationCallback)
m_serviceWorkerCreationCallback(serviceWorkerIdentifier.toUInt64());
+ if (!exceptionMessage.isEmpty()) {
+ connection()->serviceWorkerFailedToStart(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
+ return;
+ }
+ connection()->serviceWorkerStarted(jobDataIdentifier, serviceWorkerIdentifier, doesHandleFetch);
}
ServiceWorkerThreadProxy* SWContextManager::serviceWorkerThreadProxy(ServiceWorkerIdentifier identifier) const
@@ -104,6 +108,15 @@
serviceWorker->thread().fireActivateEvent();
}
+void SWContextManager::softUpdate(ServiceWorkerIdentifier identifier)
+{
+ auto* serviceWorker = m_workerMap.get(identifier);
+ if (!serviceWorker)
+ return;
+
+ serviceWorker->thread().softUpdate();
+}
+
void SWContextManager::terminateWorker(ServiceWorkerIdentifier identifier, Seconds timeout, Function<void()>&& completionHandler)
{
auto serviceWorker = m_workerMap.take(identifier);
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -50,7 +50,8 @@
virtual ~Connection() { }
virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&&, ServiceWorkerIdentifier source, const String& sourceOrigin) = 0;
- virtual void serviceWorkerStartedWithMessage(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage) = 0;
+ virtual void serviceWorkerStarted(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool doesHandleFetch) = 0;
+ virtual void serviceWorkerFailedToStart(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& message) = 0;
virtual void didFinishInstall(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool wasSuccessful) = 0;
virtual void didFinishActivation(ServiceWorkerIdentifier) = 0;
virtual void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool) = 0;
@@ -74,6 +75,7 @@
WEBCORE_EXPORT void postMessageToServiceWorker(ServiceWorkerIdentifier destination, MessageWithMessagePorts&&, ServiceWorkerOrClientData&& sourceData);
WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
+ WEBCORE_EXPORT void softUpdate(ServiceWorkerIdentifier);
WEBCORE_EXPORT void terminateWorker(ServiceWorkerIdentifier, Seconds timeout, Function<void()>&&);
void forEachServiceWorkerThread(const WTF::Function<void(ServiceWorkerThreadProxy&)>&);
@@ -88,7 +90,7 @@
private:
SWContextManager() = default;
- void startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage);
+ void startedServiceWorker(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage, bool doesHandleFetch);
NO_RETURN_DUE_TO_CRASH void serviceWorkerFailedToTerminate(ServiceWorkerIdentifier);
HashMap<ServiceWorkerIdentifier, RefPtr<ServiceWorkerThreadProxy>> m_workerMap;
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -184,6 +184,29 @@
runLoop().postTask(WTFMove(task));
}
+void ServiceWorkerThread::softUpdate()
+{
+ runLoop().postTask([](auto& context) mutable {
+ auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
+ serviceWorkerGlobalScope.registration().scheduleSoftUpdate();
+ });
+}
+
+void ServiceWorkerThread::finishedEvaluatingScript()
+{
+ m_doesHandleFetch = workerGlobalScope()->hasEventListeners(eventNames().fetchEvent);
+}
+
+void ServiceWorkerThread::start(Function<void(const String&, bool)>&& callback)
+{
+ WorkerThread::start([callback = WTFMove(callback), serviceWorkerIdentifier = this->identifier()](auto& errorMessage) mutable {
+ bool doesHandleFetch = true;
+ if (auto* threadProxy = SWContextManager::singleton().workerByID(serviceWorkerIdentifier))
+ doesHandleFetch = threadProxy->thread().doesHandleFetch();
+ callback(errorMessage, doesHandleFetch);
+ });
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -55,15 +55,18 @@
WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
+ void start(Function<void(const String&, bool)>&&);
WEBCORE_EXPORT void postFetchTask(Ref<ServiceWorkerFetch::Client>&&, Optional<ServiceWorkerClientIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&);
WEBCORE_EXPORT void postMessageToServiceWorker(MessageWithMessagePorts&&, ServiceWorkerOrClientData&& sourceData);
void fireInstallEvent();
void fireActivateEvent();
+ void softUpdate();
const ServiceWorkerContextData& contextData() const { return m_data; }
ServiceWorkerIdentifier identifier() const { return m_data.serviceWorkerIdentifier; }
+ bool doesHandleFetch() const { return m_doesHandleFetch; }
protected:
Ref<WorkerGlobalScope> createWorkerGlobalScope(const URL&, Ref<SecurityOrigin>&&, const String& name, const String& identifier, const String& userAgent, bool isOnline, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, PAL::SessionID) final;
@@ -73,9 +76,11 @@
WEBCORE_EXPORT ServiceWorkerThread(const ServiceWorkerContextData&, PAL::SessionID, String&& userAgent, WorkerLoaderProxy&, WorkerDebuggerProxy&, IDBClient::IDBConnectionProxy*, SocketProvider*);
bool isServiceWorkerThread() const final { return true; }
+ void finishedEvaluatingScript() final;
ServiceWorkerContextData m_data;
WorkerObjectProxy& m_workerObjectProxy;
+ bool m_doesHandleFetch { false };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServer.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -130,7 +130,7 @@
WEBCORE_EXPORT void startSuspension(CompletionHandler<void()>&&);
WEBCORE_EXPORT void endSuspension();
- SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
+ WEBCORE_EXPORT SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
void addRegistration(std::unique_ptr<SWServerRegistration>&&);
void removeRegistration(const ServiceWorkerRegistrationKey&);
WEBCORE_EXPORT Vector<ServiceWorkerRegistrationData> getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL);
Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -350,7 +350,7 @@
// - newestWorker is not null, and registration's last update check time is not null and the time difference in seconds calculated by the
// current time minus registration's last update check time is greater than 86400.
if (registration->updateViaCache() != ServiceWorkerUpdateViaCache::All
- || (newestWorker && registration->lastUpdateTime() && (WallTime::now() - registration->lastUpdateTime()) > 86400_s)) {
+ || (newestWorker && registration->isStale())) {
cachePolicy = FetchOptions::Cache::NoCache;
}
m_server.startScriptFetch(job, cachePolicy);
Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -362,6 +362,28 @@
}
}
+bool SWServerRegistration::shouldSoftUpdate(const FetchOptions& options) const
+{
+ if (options.mode == FetchOptions::Mode::Navigate)
+ return true;
+
+ return WebCore::isNonSubresourceRequest(options.destination) && isStale();
+}
+
+// https://w3c.github.io/ServiceWorker/#soft-update
+void SWServerRegistration::softUpdate()
+{
+ auto* worker = getNewestWorker();
+ if (!worker)
+ return;
+
+ // FIXME: We should schedule an update job.
+ m_server.runServiceWorkerIfNecessary(worker->identifier(), [serviceWorkerIdentifier = worker->identifier()](auto* contextConnection) {
+ if (contextConnection)
+ contextConnection->softUpdate(serviceWorkerIdentifier);
+ });
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -62,6 +62,7 @@
void setLastUpdateTime(WallTime);
WallTime lastUpdateTime() const { return m_lastUpdateTime; }
+ bool isStale() const { return m_lastUpdateTime && (WallTime::now() - m_lastUpdateTime) > 86400_s; }
void setUpdateViaCache(ServiceWorkerUpdateViaCache);
ServiceWorkerUpdateViaCache updateViaCache() const { return m_updateViaCache; }
@@ -96,6 +97,9 @@
void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
+ WEBCORE_EXPORT bool shouldSoftUpdate(const FetchOptions&) const;
+ WEBCORE_EXPORT void softUpdate();
+
private:
void activate();
void handleClientUnload();
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -71,10 +71,10 @@
worker->scriptContextFailedToStart(jobDataIdentifier, message);
}
-void SWServerToContextConnection::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServerToContextConnection::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch)
{
if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
- worker->scriptContextStarted(jobDataIdentifier);
+ worker->scriptContextStarted(jobDataIdentifier, doesHandleFetch);
}
void SWServerToContextConnection::didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -56,6 +56,7 @@
virtual void installServiceWorkerContext(const ServiceWorkerContextData&, PAL::SessionID, const String& userAgent) = 0;
virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
+ virtual void softUpdate(ServiceWorkerIdentifier) = 0;
virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0;
virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0;
@@ -65,7 +66,7 @@
// Messages back from the SW host process
WEBCORE_EXPORT void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, const String& message);
- WEBCORE_EXPORT void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier);
+ WEBCORE_EXPORT void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool doesHandleFetch);
WEBCORE_EXPORT void didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool wasSuccessful);
WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier);
WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -108,8 +108,9 @@
m_server->scriptContextFailedToStart(jobDataIdentifier, *this, message);
}
-void SWServerWorker::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier)
+void SWServerWorker::scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, bool doesHandleFetch)
{
+ m_shouldSkipHandleFetch = !doesHandleFetch;
ASSERT(m_server);
if (m_server)
m_server->scriptContextStarted(jobDataIdentifier, *this);
@@ -240,6 +241,9 @@
{
ASSERT(state != State::Running || m_server->getRegistration(m_registrationKey));
m_state = state;
+
+ if (state == State::Running)
+ m_shouldSkipHandleFetch = false;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (249286 => 249287)
--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -88,7 +88,7 @@
void setHasPendingEvents(bool);
void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, const String& message);
- void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&);
+ void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, bool doesHandleFetch);
void didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>&, bool wasSuccessful);
void didFinishActivation();
void contextTerminated();
@@ -112,6 +112,8 @@
WEBCORE_EXPORT SWServerToContextConnection* contextConnection();
String userAgent() const;
+ bool shouldSkipFetchEvent() const { return m_shouldSkipHandleFetch; }
+
private:
SWServerWorker(SWServer&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, String&& referrerPolicy, WorkerType, ServiceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&);
@@ -130,6 +132,7 @@
bool m_isSkipWaitingFlagSet { false };
Vector<Function<void(bool)>> m_whenActivatedHandlers;
HashMap<URL, ServiceWorkerContextData::ImportedScript> m_scriptResourceMap;
+ bool m_shouldSkipHandleFetch;
};
} // namespace WebCore
Modified: trunk/Source/WebKit/ChangeLog (249286 => 249287)
--- trunk/Source/WebKit/ChangeLog 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/ChangeLog 2019-08-29 19:24:46 UTC (rev 249287)
@@ -1,3 +1,28 @@
+2019-08-29 Youenn Fablet <[email protected]>
+
+ Skip fetch event dispatching if no fetch event handler is added at script evaluation time
+ https://bugs.webkit.org/show_bug.cgi?id=201174
+
+ Reviewed by Chris Dumez.
+
+ Store whether a fetch event handler is set at script evaluation time.
+ If not, we skip the fetch event entirely so that the network load can start sooner.
+ If fetch event is skipped, we trigger soft update, as defined in
+ https://w3c.github.io/ServiceWorker/#handle-fetch step 16.
+
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+ (WebKit::WebSWServerConnection::startFetch):
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+ (WebKit::WebSWServerToContextConnection::softUpdate):
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
+ * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+ (WebKit::WebSWContextManagerConnection::serviceWorkerStarted):
+ (WebKit::WebSWContextManagerConnection::serviceWorkerFailedToStart):
+ (WebKit::WebSWContextManagerConnection::softUpdate):
+ * WebProcess/Storage/WebSWContextManagerConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
2019-08-29 Keith Rollin <[email protected]>
Remove support for macOS < 10.13 (part 3)
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (249286 => 249287)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -183,7 +183,7 @@
if (!worker->contextConnection())
m_networkProcess->createServerToContextConnection(worker->registrableDomain(), server().sessionID());
- server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = WTFMove(weakThis), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer)](auto* contextConnection) {
+ server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = WTFMove(weakThis), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer), shouldSkipFetchEvent = worker->shouldSkipFetchEvent()](auto* contextConnection) {
if (!weakThis)
return;
@@ -197,6 +197,14 @@
});
};
+ if (worker->shouldSkipFetchEvent()) {
+ m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidNotHandle { }, fetchIdentifier);
+ auto* registration = server().getRegistration(worker->registrationKey());
+ if (registration && registration->shouldSoftUpdate(options))
+ registration->softUpdate();
+ return;
+ }
+
if (worker->state() == ServiceWorkerState::Activating) {
worker->whenActivated(WTFMove(runServerWorkerAndStartFetch));
return;
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (249286 => 249287)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -80,6 +80,11 @@
send(Messages::WebSWContextManagerConnection::FireActivateEvent(serviceWorkerIdentifier));
}
+void WebSWServerToContextConnection::softUpdate(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+ send(Messages::WebSWContextManagerConnection::SoftUpdate(serviceWorkerIdentifier));
+}
+
void WebSWServerToContextConnection::terminateWorker(ServiceWorkerIdentifier serviceWorkerIdentifier)
{
send(Messages::WebSWContextManagerConnection::TerminateWorker(serviceWorkerIdentifier));
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h (249286 => 249287)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -86,6 +86,7 @@
void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&, PAL::SessionID, const String& userAgent) final;
void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
+ void softUpdate(WebCore::ServiceWorkerIdentifier) final;
void terminateWorker(WebCore::ServiceWorkerIdentifier) final;
void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final;
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in (249286 => 249287)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in 2019-08-29 19:24:46 UTC (rev 249287)
@@ -26,7 +26,7 @@
# When possible, these messages can be implemented directly by WebCore::SWServerToContextConnection
ScriptContextFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message);
- ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
+ ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch);
DidFinishInstall(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful);
DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier);
SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (249286 => 249287)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2019-08-29 19:24:46 UTC (rev 249287)
@@ -175,14 +175,16 @@
ASSERT_UNUSED(result, result);
}
-void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
+void WebSWContextManagerConnection::serviceWorkerStarted(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch)
{
- if (exceptionMessage.isEmpty())
- m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted(jobDataIdentifier, serviceWorkerIdentifier), 0);
- else
- m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextFailedToStart(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage), 0);
+ m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted { jobDataIdentifier, serviceWorkerIdentifier, doesHandleFetch }, 0);
}
+void WebSWContextManagerConnection::serviceWorkerFailedToStart(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
+{
+ m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::ScriptContextFailedToStart { jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage }, 0);
+}
+
static inline bool isValidFetch(const ResourceRequest& request, const FetchOptions& options, const URL& serviceWorkerURL, const String& referrer)
{
// For exotic service workers, do not enforce checks.
@@ -261,6 +263,11 @@
SWContextManager::singleton().fireActivateEvent(identifier);
}
+void WebSWContextManagerConnection::softUpdate(WebCore::ServiceWorkerIdentifier identifier)
+{
+ SWContextManager::singleton().softUpdate(identifier);
+}
+
void WebSWContextManagerConnection::terminateWorker(ServiceWorkerIdentifier identifier)
{
SWContextManager::singleton().terminateWorker(identifier, asyncWorkerTerminationTimeout, nullptr);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (249286 => 249287)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2019-08-29 19:24:46 UTC (rev 249287)
@@ -76,7 +76,8 @@
bool isThrottleable() const final;
// IPC messages.
- void serviceWorkerStartedWithMessage(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
+ void serviceWorkerStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, bool doesHandleFetch) final;
+ void serviceWorkerFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
void installServiceWorker(const WebCore::ServiceWorkerContextData&, PAL::SessionID, String&& userAgent);
void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer);
void cancelFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier);
@@ -84,6 +85,7 @@
void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerOrClientData&& sourceData);
void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
+ void softUpdate(WebCore::ServiceWorkerIdentifier);
void terminateWorker(WebCore::ServiceWorkerIdentifier);
void syncTerminateWorker(WebCore::ServiceWorkerIdentifier, Messages::WebSWContextManagerConnection::SyncTerminateWorker::DelayedReply&&);
void findClientByIdentifierCompleted(uint64_t requestIdentifier, Optional<WebCore::ServiceWorkerClientData>&&, bool hasSecurityError);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (249286 => 249287)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2019-08-29 19:22:22 UTC (rev 249286)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2019-08-29 19:24:46 UTC (rev 249287)
@@ -30,6 +30,7 @@
PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientData sourceData)
FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
+ SoftUpdate(WebCore::ServiceWorkerIdentifier identifier)
TerminateWorker(WebCore::ServiceWorkerIdentifier identifier)
SyncTerminateWorker(WebCore::ServiceWorkerIdentifier identifier) -> () Synchronous
FindClientByIdentifierCompleted(uint64_t clientIdRequestIdentifier, Optional<WebCore::ServiceWorkerClientData> data, bool hasSecurityError)