WebKit Bugzilla
Attachment 357971 Details for
Bug 192951
: navigator.userAgent in service workers does not reflect customUserAgent set by client
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192951-20181221130908.patch (text/plain), 38.36 KB, created by
Chris Dumez
on 2018-12-21 13:09:09 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2018-12-21 13:09:09 PST
Size:
38.36 KB
patch
obsolete
>Subversion Revision: 239472 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 93c5562ada11507e6f083663169e98caa5805bb0..360a7912a992ccc8d92d10acc12bc21f975bbb99 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,43 @@ >+2018-12-21 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent in service workers does not reflect customUserAgent set by client >+ https://bugs.webkit.org/show_bug.cgi?id=192951 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Have WebCore pass the user agent to the Network Process after fetching a service worker >+ script and have the service worker use this user agent when it starts (e.g. for >+ navigator.userAgent). Also have WebCore pass the user agent whenever a fetch is sent >+ to the service worker and have the service worker use that user agent if it is a >+ navigation load. >+ >+ * workers/service/SWClientConnection.cpp: >+ (WebCore::SWClientConnection::failedFetchingScript): >+ * workers/service/ServiceWorkerContainer.cpp: >+ (WebCore::ServiceWorkerContainer::jobFinishedLoadingScript): >+ * workers/service/ServiceWorkerContextData.cpp: >+ (WebCore::ServiceWorkerContextData::isolatedCopy const): >+ * workers/service/ServiceWorkerContextData.h: >+ (WebCore::ServiceWorkerContextData::encode const): >+ (WebCore::ServiceWorkerContextData::decode): >+ * workers/service/ServiceWorkerFetchResult.h: >+ (WebCore::ServiceWorkerFetchResult::encode const): >+ (WebCore::ServiceWorkerFetchResult::decode): >+ * workers/service/server/RegistrationDatabase.cpp: >+ (WebCore::RegistrationDatabase::importRecords): >+ * workers/service/server/SWServer.cpp: >+ (WebCore::SWServer::addRegistrationFromStore): >+ (WebCore::SWServer::updateWorker): >+ (WebCore::SWServer::installContextData): >+ * workers/service/server/SWServer.h: >+ * workers/service/server/SWServerJobQueue.cpp: >+ (WebCore::SWServerJobQueue::scriptFetchFinished): >+ * workers/service/server/SWServerWorker.cpp: >+ (WebCore::SWServerWorker::SWServerWorker): >+ (WebCore::SWServerWorker::contextData const): >+ * workers/service/server/SWServerWorker.h: >+ (WebCore::SWServerWorker::setUserAgent): >+ > 2018-12-20 Youenn Fablet <youenn@apple.com> > > Remove custom constructors of ReadableStreamDefaultReader and ReadableStreamBYOBReader >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 0b9564b726a003a9fe042600310f5721c6c67ca2..81e20ce699731df3fb1765dcbbd62ef61fc5425f 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,22 @@ >+2018-12-21 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent in service workers does not reflect customUserAgent set by client >+ https://bugs.webkit.org/show_bug.cgi?id=192951 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: >+ (WebKit::WebSWServerConnection::startFetch): >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.h: >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in: >+ * WebProcess/Storage/ServiceWorkerClientFetch.cpp: >+ (WebKit::ServiceWorkerClientFetch::start): >+ * WebProcess/Storage/WebSWClientConnection.cpp: >+ (WebKit::WebSWClientConnection::startFetch): >+ * WebProcess/Storage/WebSWClientConnection.h: >+ * WebProcess/Storage/WebSWContextManagerConnection.cpp: >+ (WebKit::WebSWContextManagerConnection::installServiceWorker): >+ > 2018-12-20 Jiewen Tan <jiewen_tan@apple.com> > > [WebAuthN] Add a runtime flag for local authenticator >diff --git a/Source/WebCore/workers/service/SWClientConnection.cpp b/Source/WebCore/workers/service/SWClientConnection.cpp >index 8ed67f67cbfda5af966eff89c5340bbced18f550..ff3eceb73c4918b92a85e91e0117ac5a2b87b4cb 100644 >--- a/Source/WebCore/workers/service/SWClientConnection.cpp >+++ b/Source/WebCore/workers/service/SWClientConnection.cpp >@@ -59,7 +59,7 @@ void SWClientConnection::failedFetchingScript(ServiceWorkerJobIdentifier jobIden > { > ASSERT(isMainThread()); > >- finishFetchingScriptInServer({ { serverConnectionIdentifier(), jobIdentifier }, registrationKey, { }, { }, error }); >+ finishFetchingScriptInServer({ { serverConnectionIdentifier(), jobIdentifier }, registrationKey, { }, { }, error, { } }); > } > > bool SWClientConnection::postTaskForJob(ServiceWorkerJobIdentifier jobIdentifier, IsJobComplete isJobComplete, WTF::Function<void(ServiceWorkerJob&)>&& task) >diff --git a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp b/Source/WebCore/workers/service/ServiceWorkerContainer.cpp >index 1a65873165a760ac5ea30e1d9e09fdd26c5a07af..b62ffe95d907b7250deeb3ba87d929e5a808837b 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp >+++ b/Source/WebCore/workers/service/ServiceWorkerContainer.cpp >@@ -527,8 +527,9 @@ void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, con > > CONTAINER_RELEASE_LOG_IF_ALLOWED("jobFinishedLoadingScript: Successfuly finished fetching script for job %" PRIu64, job.identifier().toUInt64()); > >- callOnMainThread([connection = m_swConnection, jobDataIdentifier = job.data().identifier(), registrationKey = job.data().registrationKey().isolatedCopy(), script = script.isolatedCopy(), contentSecurityPolicy = contentSecurityPolicy.isolatedCopy()] { >- connection->finishFetchingScriptInServer({ jobDataIdentifier, registrationKey, script, contentSecurityPolicy, { } }); >+ String userAgent = scriptExecutionContext() ? scriptExecutionContext()->userAgent(job.data().scriptURL) : String(); >+ callOnMainThread([connection = m_swConnection, jobDataIdentifier = job.data().identifier(), registrationKey = job.data().registrationKey().isolatedCopy(), script = script.isolatedCopy(), userAgent = userAgent.isolatedCopy(), contentSecurityPolicy = contentSecurityPolicy.isolatedCopy()] { >+ connection->finishFetchingScriptInServer({ jobDataIdentifier, registrationKey, script, contentSecurityPolicy, { }, userAgent }); > }); > } > >diff --git a/Source/WebCore/workers/service/ServiceWorkerContextData.cpp b/Source/WebCore/workers/service/ServiceWorkerContextData.cpp >index 2bc4e73c063336878ab3666a9d6993e4db8d2df8..60206777a6d39bc7b9c03be48df5288412da5d79 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerContextData.cpp >+++ b/Source/WebCore/workers/service/ServiceWorkerContextData.cpp >@@ -33,7 +33,7 @@ namespace WebCore { > > ServiceWorkerContextData ServiceWorkerContextData::isolatedCopy() const > { >- return { jobDataIdentifier, registration.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), contentSecurityPolicy.isolatedCopy(), scriptURL.isolatedCopy(), workerType, sessionID, loadedFromDisk, crossThreadCopy(scriptResourceMap) }; >+ return { jobDataIdentifier, registration.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), contentSecurityPolicy.isolatedCopy(), userAgent.isolatedCopy(), scriptURL.isolatedCopy(), workerType, sessionID, loadedFromDisk, crossThreadCopy(scriptResourceMap) }; > } > > } // namespace WebCore >diff --git a/Source/WebCore/workers/service/ServiceWorkerContextData.h b/Source/WebCore/workers/service/ServiceWorkerContextData.h >index 23c4ccf791f3b29608e64fa62bd7c34308da7341..4dfb8175480260a7defd1afe313e0b57744a7e5b 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerContextData.h >+++ b/Source/WebCore/workers/service/ServiceWorkerContextData.h >@@ -75,6 +75,7 @@ struct ServiceWorkerContextData { > ServiceWorkerIdentifier serviceWorkerIdentifier; > String script; > ContentSecurityPolicyResponseHeaders contentSecurityPolicy; >+ String userAgent; > URL scriptURL; > WorkerType workerType; > PAL::SessionID sessionID; >@@ -90,7 +91,7 @@ struct ServiceWorkerContextData { > template<class Encoder> > void ServiceWorkerContextData::encode(Encoder& encoder) const > { >- encoder << jobDataIdentifier << registration << serviceWorkerIdentifier << script << contentSecurityPolicy << scriptURL << workerType << sessionID << loadedFromDisk; >+ encoder << jobDataIdentifier << registration << serviceWorkerIdentifier << script << contentSecurityPolicy << userAgent << scriptURL << workerType << sessionID << loadedFromDisk; > encoder << scriptResourceMap; > } > >@@ -119,6 +120,10 @@ Optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder& dec > if (!decoder.decode(contentSecurityPolicy)) > return WTF::nullopt; > >+ String userAgent; >+ if (!decoder.decode(userAgent)) >+ return WTF::nullopt; >+ > URL scriptURL; > if (!decoder.decode(scriptURL)) > return WTF::nullopt; >@@ -139,7 +144,7 @@ Optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder& dec > if (!decoder.decode(scriptResourceMap)) > return WTF::nullopt; > >- return {{ WTFMove(*jobDataIdentifier), WTFMove(*registration), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(scriptURL), workerType, sessionID, loadedFromDisk, WTFMove(scriptResourceMap) }}; >+ return {{ WTFMove(*jobDataIdentifier), WTFMove(*registration), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(userAgent), WTFMove(scriptURL), workerType, sessionID, loadedFromDisk, WTFMove(scriptResourceMap) }}; > } > > } // namespace WebCore >diff --git a/Source/WebCore/workers/service/ServiceWorkerFetchResult.h b/Source/WebCore/workers/service/ServiceWorkerFetchResult.h >index d390aa9f1b452a66a51d8f24ddfaa868f883312d..46b40a1b652558b5610e73e187acfe3d93de94ec 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerFetchResult.h >+++ b/Source/WebCore/workers/service/ServiceWorkerFetchResult.h >@@ -40,6 +40,7 @@ struct ServiceWorkerFetchResult { > String script; > ContentSecurityPolicyResponseHeaders contentSecurityPolicy; > ResourceError scriptError; >+ String userAgent; > > template<class Encoder> void encode(Encoder&) const; > template<class Decoder> static bool decode(Decoder&, ServiceWorkerFetchResult&); >@@ -48,7 +49,7 @@ struct ServiceWorkerFetchResult { > template<class Encoder> > void ServiceWorkerFetchResult::encode(Encoder& encoder) const > { >- encoder << jobDataIdentifier << registrationKey << script << contentSecurityPolicy << scriptError; >+ encoder << jobDataIdentifier << registrationKey << script << contentSecurityPolicy << scriptError << userAgent; > } > > template<class Decoder> >@@ -71,6 +72,8 @@ bool ServiceWorkerFetchResult::decode(Decoder& decoder, ServiceWorkerFetchResult > return false; > if (!decoder.decode(result.scriptError)) > return false; >+ if (!decoder.decode(result.userAgent)) >+ return false; > > return true; > } >diff --git a/Source/WebCore/workers/service/server/RegistrationDatabase.cpp b/Source/WebCore/workers/service/server/RegistrationDatabase.cpp >index b5c29e9072198713b24429094b18c9eb69ee4f20..18b70ea8bb93f96284ad5376b72afc1101515d72 100644 >--- a/Source/WebCore/workers/service/server/RegistrationDatabase.cpp >+++ b/Source/WebCore/workers/service/server/RegistrationDatabase.cpp >@@ -400,7 +400,7 @@ String RegistrationDatabase::importRecords() > auto registrationIdentifier = generateObjectIdentifier<ServiceWorkerRegistrationIdentifierType>(); > auto serviceWorkerData = ServiceWorkerData { workerIdentifier, scriptURL, ServiceWorkerState::Activated, *workerType, registrationIdentifier }; > auto registration = ServiceWorkerRegistrationData { WTFMove(*key), registrationIdentifier, URL(originURL, scopePath), *updateViaCache, lastUpdateCheckTime, WTF::nullopt, WTF::nullopt, WTFMove(serviceWorkerData) }; >- auto contextData = ServiceWorkerContextData { WTF::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(scriptURL), *workerType, m_sessionID, true, WTFMove(scriptResourceMap) }; >+ auto contextData = ServiceWorkerContextData { WTF::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), { }, WTFMove(scriptURL), *workerType, m_sessionID, true, WTFMove(scriptResourceMap) }; > > callOnMainThread([protectedThis = makeRef(*this), contextData = contextData.isolatedCopy()]() mutable { > protectedThis->addRegistrationToStore(WTFMove(contextData)); >diff --git a/Source/WebCore/workers/service/server/SWServer.cpp b/Source/WebCore/workers/service/server/SWServer.cpp >index bcb197ca2ca7bf75991110137dd09916191346b6..448ed25497ef84b93ffaab540240099315cff5ba 100644 >--- a/Source/WebCore/workers/service/server/SWServer.cpp >+++ b/Source/WebCore/workers/service/server/SWServer.cpp >@@ -132,7 +132,7 @@ void SWServer::addRegistrationFromStore(ServiceWorkerContextData&& data) > auto registrationPtr = registration.get(); > addRegistration(WTFMove(registration)); > >- auto worker = SWServerWorker::create(*this, *registrationPtr, data.scriptURL, data.script, data.contentSecurityPolicy, data.workerType, data.serviceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript> { data.scriptResourceMap }); >+ auto worker = SWServerWorker::create(*this, *registrationPtr, data.scriptURL, data.script, data.contentSecurityPolicy, data.userAgent, data.workerType, data.serviceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript> { data.scriptResourceMap }); > registrationPtr->updateRegistrationState(ServiceWorkerRegistrationState::Active, worker.ptr()); > worker->setState(ServiceWorkerState::Activated); > } >@@ -494,9 +494,9 @@ void SWServer::removeClientServiceWorkerRegistration(Connection& connection, Ser > registration->removeClientServiceWorkerRegistration(connection.identifier()); > } > >-void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, WorkerType type, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap) >+void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& userAgent, WorkerType type, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap) > { >- tryInstallContextData({ jobDataIdentifier, registration.data(), generateObjectIdentifier<ServiceWorkerIdentifierType>(), script, contentSecurityPolicy, url, type, sessionID(), false, WTFMove(scriptResourceMap) }); >+ tryInstallContextData({ jobDataIdentifier, registration.data(), generateObjectIdentifier<ServiceWorkerIdentifierType>(), script, contentSecurityPolicy, userAgent, url, type, sessionID(), false, WTFMove(scriptResourceMap) }); > } > > void SWServer::tryInstallContextData(ServiceWorkerContextData&& data) >@@ -541,7 +541,7 @@ void SWServer::installContextData(const ServiceWorkerContextData& data) > auto* registration = m_registrations.get(data.registration.key); > RELEASE_ASSERT(registration); > >- auto worker = SWServerWorker::create(*this, *registration, data.scriptURL, data.script, data.contentSecurityPolicy, data.workerType, data.serviceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript> { data.scriptResourceMap }); >+ auto worker = SWServerWorker::create(*this, *registration, data.scriptURL, data.script, data.contentSecurityPolicy, data.userAgent, data.workerType, data.serviceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript> { data.scriptResourceMap }); > > auto* connection = worker->contextConnection(); > ASSERT(connection); >diff --git a/Source/WebCore/workers/service/server/SWServer.h b/Source/WebCore/workers/service/server/SWServer.h >index c3910d6be21d12be54f457f6bd201dd57af6854b..a865e6ce803ed4c5359c0f0a697ae704eb27f5d1 100644 >--- a/Source/WebCore/workers/service/server/SWServer.h >+++ b/Source/WebCore/workers/service/server/SWServer.h >@@ -133,7 +133,7 @@ public: > void resolveUnregistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationKey&, bool unregistrationResult); > void startScriptFetch(const ServiceWorkerJobData&, FetchOptions::Cache); > >- void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, WorkerType, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&); >+ void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, const String& userAgent, WorkerType, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&); > void terminateWorker(SWServerWorker&); > void syncTerminateWorker(SWServerWorker&); > void fireInstallEvent(SWServerWorker&); >diff --git a/Source/WebCore/workers/service/server/SWServerJobQueue.cpp b/Source/WebCore/workers/service/server/SWServerJobQueue.cpp >index d8a85b0ad33c4839d92c5b15341a8be1ee02fe89..7313d8866fce49be04f6c8508db3c34b9f812aa8 100644 >--- a/Source/WebCore/workers/service/server/SWServerJobQueue.cpp >+++ b/Source/WebCore/workers/service/server/SWServerJobQueue.cpp >@@ -100,7 +100,7 @@ void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, con > // FIXME: Update all the imported scripts as per spec. For now, we just do as if there is none. > > // FIXME: Support the proper worker type (classic vs module) >- m_server.updateWorker(connection, job.identifier(), *registration, job.scriptURL, result.script, result.contentSecurityPolicy, WorkerType::Classic, { }); >+ m_server.updateWorker(connection, job.identifier(), *registration, job.scriptURL, result.script, result.contentSecurityPolicy, result.userAgent, WorkerType::Classic, { }); > } > > // https://w3c.github.io/ServiceWorker/#update-algorithm >diff --git a/Source/WebCore/workers/service/server/SWServerWorker.cpp b/Source/WebCore/workers/service/server/SWServerWorker.cpp >index c8b68e6b9b8ff2384c00c46eef76f716190e8b69..e28a90c607cf6f00099fcae27116909eb43ea256 100644 >--- a/Source/WebCore/workers/service/server/SWServerWorker.cpp >+++ b/Source/WebCore/workers/service/server/SWServerWorker.cpp >@@ -45,12 +45,13 @@ SWServerWorker* SWServerWorker::existingWorkerForIdentifier(ServiceWorkerIdentif > } > > // FIXME: Use r-value references for script and contentSecurityPolicy >-SWServerWorker::SWServerWorker(SWServer& server, SWServerRegistration& registration, const URL& scriptURL, const String& script, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, WorkerType type, ServiceWorkerIdentifier identifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap) >+SWServerWorker::SWServerWorker(SWServer& server, SWServerRegistration& registration, const URL& scriptURL, const String& script, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& userAgent, WorkerType type, ServiceWorkerIdentifier identifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap) > : m_server(server) > , m_registrationKey(registration.key()) > , m_data { identifier, scriptURL, ServiceWorkerState::Redundant, type, registration.identifier() } > , m_script(script) > , m_contentSecurityPolicy(contentSecurityPolicy) >+ , m_userAgent(userAgent) > , m_scriptResourceMap(WTFMove(scriptResourceMap)) > { > m_data.scriptURL.removeFragmentIdentifier(); >@@ -74,7 +75,7 @@ ServiceWorkerContextData SWServerWorker::contextData() const > auto* registration = m_server.getRegistration(m_registrationKey); > ASSERT(registration); > >- return { WTF::nullopt, registration->data(), m_data.identifier, m_script, m_contentSecurityPolicy, m_data.scriptURL, m_data.type, m_server.sessionID(), false, m_scriptResourceMap }; >+ return { WTF::nullopt, registration->data(), m_data.identifier, m_script, m_contentSecurityPolicy, m_userAgent, m_data.scriptURL, m_data.type, m_server.sessionID(), false, m_scriptResourceMap }; > } > > void SWServerWorker::terminate() >diff --git a/Source/WebCore/workers/service/server/SWServerWorker.h b/Source/WebCore/workers/service/server/SWServerWorker.h >index a31dba714485514f437f3ad40878cb532597244b..08ad18ca3b529c8f5b1255b3649a41350120d28e 100644 >--- a/Source/WebCore/workers/service/server/SWServerWorker.h >+++ b/Source/WebCore/workers/service/server/SWServerWorker.h >@@ -105,13 +105,15 @@ public: > const ServiceWorkerData& data() const { return m_data; } > ServiceWorkerContextData contextData() const; > >+ void setUserAgent(const String& userAgent) { m_userAgent = userAgent; } >+ > const ClientOrigin& origin() const; > WEBCORE_EXPORT const SecurityOriginData& securityOrigin() const; > > WEBCORE_EXPORT SWServerToContextConnection* contextConnection(); > > private: >- SWServerWorker(SWServer&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, WorkerType, ServiceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&); >+ SWServerWorker(SWServer&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, const String& userAgent, WorkerType, ServiceWorkerIdentifier, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&); > > void callWhenActivatedHandler(bool success); > >@@ -120,6 +122,7 @@ private: > ServiceWorkerData m_data; > String m_script; > ContentSecurityPolicyResponseHeaders m_contentSecurityPolicy; >+ String m_userAgent; > bool m_hasPendingEvents { false }; > State m_state { State::NotRunning }; > mutable Optional<ClientOrigin> m_origin; >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >index 97cbf45d8838468ca34a6f17fe43ee462ced42a3..9f45197740ae07d24dc35b7b36ee72fe06bcb4ad 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >@@ -138,7 +138,7 @@ void WebSWServerConnection::cancelFetch(ServiceWorkerRegistrationIdentifier serv > }); > } > >-void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer) >+void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer, String&& userAgent) > { > auto* worker = server().activeWorkerFromRegistrationID(serviceWorkerRegistrationIdentifier); > if (!worker) { >@@ -148,7 +148,7 @@ void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier servi > } > auto serviceWorkerIdentifier = worker->identifier(); > >- auto runServerWorkerAndStartFetch = [weakThis = makeWeakPtr(this), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer)](bool success) mutable { >+ auto runServerWorkerAndStartFetch = [weakThis = makeWeakPtr(this), this, fetchIdentifier, serviceWorkerIdentifier, request = WTFMove(request), options = WTFMove(options), formData = WTFMove(formData), referrer = WTFMove(referrer), userAgent = WTFMove(userAgent)](bool success) mutable { > if (!weakThis) > return; > >@@ -164,6 +164,10 @@ void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier servi > return; > } > >+ // Make sure the service worker's user agent is up-to-date before we attempt to run it. >+ if (options.mode == FetchOptions::Mode::Navigate) >+ worker->setUserAgent(userAgent); >+ > if (!worker->contextConnection()) > NetworkProcess::singleton().createServerToContextConnection(worker->securityOrigin(), server().sessionID()); > >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >index 307da2c9f69c444273353b5432641ce1679522a9..a39fdffbb2729862951cd2c9ded3325fcce0ca37 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >@@ -87,7 +87,7 @@ private: > > void scheduleJobInServer(WebCore::ServiceWorkerJobData&&); > >- void startFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer); >+ void startFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer, String&& userAgent); > void cancelFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier); > > void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL); >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >index 7cbc230a4330e24eae2ed0cab28c88ef94f72338..dda9498cc612343514ba15c9704809a93c049054 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >@@ -29,7 +29,7 @@ messages -> WebSWServerConnection { > AddServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier identifier) > RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier identifier) > >- StartFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer) >+ StartFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer, String userAgent) > CancelFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier) > > PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientIdentifier source) >diff --git a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >index 30f0322facb1aab752c1ac3865af3c24d0adb27f..271587761ba7c5e044a00ac4067ad1ed0f210720 100644 >--- a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >+++ b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >@@ -69,6 +69,7 @@ void ServiceWorkerClientFetch::start() > auto& options = m_loader->options(); > > auto referrer = request.httpReferrer(); >+ auto userAgent = request.httpUserAgent(); > > m_didFail = false; > m_didFinish = false; >@@ -78,7 +79,7 @@ void ServiceWorkerClientFetch::start() > > ASSERT(options.serviceWorkersMode != ServiceWorkersMode::None); > m_serviceWorkerRegistrationIdentifier = options.serviceWorkerRegistrationIdentifier.value(); >- m_connection->startFetch(m_identifier, m_serviceWorkerRegistrationIdentifier, request, options, referrer); >+ m_connection->startFetch(m_identifier, m_serviceWorkerRegistrationIdentifier, request, options, referrer, userAgent); > > m_redirectionStatus = RedirectionStatus::None; > } >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >index 574c920ec30562405bdfbd7a9ee927bd597462cf..27f4501535fb7fb45f008384035b0619abb32878 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >@@ -198,9 +198,9 @@ void WebSWClientConnection::getRegistrations(SecurityOriginData&& topOrigin, con > }); > } > >-void WebSWClientConnection::startFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const WebCore::ResourceRequest& request, const WebCore::FetchOptions& options, const String& referrer) >+void WebSWClientConnection::startFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const WebCore::ResourceRequest& request, const WebCore::FetchOptions& options, const String& referrer, const String& userAgent) > { >- send(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer }); >+ send(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer, userAgent }); > } > > void WebSWClientConnection::cancelFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier) >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >index b92eebff90f9bcd34488da7e4967b9d34989251b..57c5d4a1e6c90a91e2611723bd5da2eae483bd55 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >@@ -61,7 +61,7 @@ public: > void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final; > > bool mayHaveServiceWorkerRegisteredForOrigin(const WebCore::SecurityOriginData&) const final; >- void startFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const String& referrer); >+ void startFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const String& referrer, const String& userAgent); > void cancelFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier); > > void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerData&& source, const String& sourceOrigin); >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >index ef65c42e3b02032413c89a1150958a070fbecd32..14a63ad6e76ac0e5ac9e9b2cc2333475a860f41d 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >@@ -145,13 +145,15 @@ void WebSWContextManagerConnection::installServiceWorker(const ServiceWorkerCont > pageConfiguration.databaseProvider = WebDatabaseProvider::getOrCreate(m_pageGroupID); > #endif > >+ auto effectiveUserAgent = data.userAgent.isNull() ? m_userAgent : data.userAgent; >+ > // FIXME: This method should be moved directly to WebCore::SWContextManager::Connection > // If it weren't for ServiceWorkerFrameLoaderClient's dependence on WebDocumentLoader, this could already happen. >- auto frameLoaderClient = std::make_unique<ServiceWorkerFrameLoaderClient>(*this, sessionID, m_pageID, ++m_previousServiceWorkerID, m_userAgent); >+ auto frameLoaderClient = std::make_unique<ServiceWorkerFrameLoaderClient>(*this, sessionID, m_pageID, ++m_previousServiceWorkerID, effectiveUserAgent); > pageConfiguration.loaderClientForMainFrame = frameLoaderClient.get(); > m_loaders.add(WTFMove(frameLoaderClient)); > >- auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), data, sessionID, String { m_userAgent }, WebProcess::singleton().cacheStorageProvider(), m_storageBlockingPolicy); >+ auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), data, sessionID, WTFMove(effectiveUserAgent), WebProcess::singleton().cacheStorageProvider(), m_storageBlockingPolicy); > SWContextManager::singleton().registerServiceWorkerThreadForInstall(WTFMove(serviceWorkerThreadProxy)); > > LOG(ServiceWorker, "Context process PID: %i created worker thread\n", getCurrentProcessID()); >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 72f62b2b05fb344a2c34f61c61b7db99f3975119..c9a2b28171eeadc3106094d1492743de5e4ac018 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,18 @@ >+2018-12-21 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent in service workers does not reflect customUserAgent set by client >+ https://bugs.webkit.org/show_bug.cgi?id=192951 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add API test coverage. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: >+ (-[SWCustomUserAgentDelegate initWithUserAgent:]): >+ (-[SWCustomUserAgentDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]): >+ (-[SWUserAgentMessageHandler initWithExpectedMessage:]): >+ (-[SWUserAgentMessageHandler userContentController:didReceiveScriptMessage:]): >+ > 2018-12-20 Chris Dumez <cdumez@apple.com> > > Add API test coverage for customUserAgent client setting and service workers >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >index 0ade2f8ae66eae6e3626839f9b2913c460b79a69..e324c29f4aca097e5659761940fe947469e7b30d 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >@@ -514,30 +514,50 @@ TEST(ServiceWorkers, Basic) > } > > @interface SWCustomUserAgentDelegate : NSObject <WKNavigationDelegate> { >+ NSString *_userAgent; > } >+- (instancetype)initWithUserAgent:(NSString *)userAgent; > @end > > @implementation SWCustomUserAgentDelegate > >+- (instancetype)initWithUserAgent:(NSString *)userAgent >+{ >+ self = [super init]; >+ _userAgent = userAgent; >+ return self; >+} >+ > - (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler > { > _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; > if (navigationAction.targetFrame.mainFrame) >- [websitePolicies setCustomUserAgent:@"Foo Custom UserAgent"]; >+ [websitePolicies setCustomUserAgent:_userAgent]; > > decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); > } > > @end > >-@interface SWUserAgentMessageHandler : NSObject <WKScriptMessageHandler> >+@interface SWUserAgentMessageHandler : NSObject <WKScriptMessageHandler> { >+@public >+ NSString *expectedMessage; >+} >+- (instancetype)initWithExpectedMessage:(NSString *)expectedMessage; > @end > > @implementation SWUserAgentMessageHandler >+ >+- (instancetype)initWithExpectedMessage:(NSString *)_expectedMessage >+{ >+ self = [super init]; >+ expectedMessage = _expectedMessage; >+ return self; >+} >+ > - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message > { >- // FIXME: navigator.userAgent currently does not reflect the custom user agent set by the client (https://bugs.webkit.org/show_bug.cgi?id=192951). >- // EXPECT_WK_STREQ(@"Message from worker: Foo Custom UserAgent", [message body]); >+ EXPECT_WK_STREQ(expectedMessage, [message body]); > done = true; > } > @end >@@ -563,7 +583,7 @@ TEST(ServiceWorkers, UserAgentOverride) > > auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); > >- auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] init]); >+ auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Foo Custom UserAgent"]); > [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; > > auto handler = adoptNS([[SWSchemes alloc] init]); >@@ -572,10 +592,10 @@ TEST(ServiceWorkers, UserAgentOverride) > handler->expectedUserAgent = @"Foo Custom UserAgent"; > [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; > >- RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); >+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); > [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"]; > >- auto delegate = adoptNS([[SWCustomUserAgentDelegate alloc] init]); >+ auto delegate = adoptNS([[SWCustomUserAgentDelegate alloc] initWithUserAgent:@"Foo Custom UserAgent"]); > [webView setNavigationDelegate:delegate.get()]; > > NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; >@@ -583,6 +603,36 @@ TEST(ServiceWorkers, UserAgentOverride) > > TestWebKitAPI::Util::run(&done); > done = false; >+ >+ // Restore from disk. >+ webView = nullptr; >+ delegate = nullptr; >+ handler = nullptr; >+ messageHandler = nullptr; >+ configuration = nullptr; >+ >+ configuration = adoptNS([[WKWebViewConfiguration alloc] init]); >+ >+ messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Bar Custom UserAgent"]); >+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; >+ >+ handler = adoptNS([[SWSchemes alloc] init]); >+ handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); >+ handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", userAgentSWBytes }); >+ handler->expectedUserAgent = @"Bar Custom UserAgent"; >+ [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; >+ >+ webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); >+ [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"]; >+ >+ delegate = adoptNS([[SWCustomUserAgentDelegate alloc] initWithUserAgent:@"Bar Custom UserAgent"]); >+ [webView setNavigationDelegate:delegate.get()]; >+ >+ request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; >+ [webView loadRequest:request]; >+ >+ TestWebKitAPI::Util::run(&done); >+ done = false; > } > > TEST(ServiceWorkers, RestoreFromDisk)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192951
:
357857
|
357971
|
357994
|
358012