Changeset 223964 in webkit
- Timestamp:
- Oct 25, 2017 11:28:54 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223962 r223964 1 2017-10-25 Chris Dumez <cdumez@apple.com> 2 3 Add support for unregistering a service worker 4 https://bugs.webkit.org/show_bug.cgi?id=178735 5 6 Reviewed by Brady Eidson. 7 8 Add layout test coverage. 9 10 * http/tests/workers/service/basic-unregister.https-expected.txt: Added. 11 * http/tests/workers/service/basic-unregister.https.html: Added. 12 * http/tests/workers/service/resources/basic-unregister.js: Added. 13 1 14 2017-10-25 Andy Estes <aestes@apple.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r223963 r223964 1 2017-10-25 Chris Dumez <cdumez@apple.com> 2 3 Add support for unregistering a service worker 4 https://bugs.webkit.org/show_bug.cgi?id=178735 5 6 Reviewed by Brady Eidson. 7 8 Add support for unregistering a service worker: 9 - https://w3c.github.io/ServiceWorker/#navigator-service-worker-unregister 10 11 Test: http/tests/workers/service/basic-unregister.https.html 12 13 * workers/service/ServiceWorkerContainer.cpp: 14 (WebCore::ServiceWorkerContainer::addRegistration): 15 (WebCore::ServiceWorkerContainer::removeRegistration): 16 (WebCore::ServiceWorkerContainer::jobResolvedWithUnregistrationResult): 17 * workers/service/ServiceWorkerContainer.h: 18 * workers/service/ServiceWorkerJob.cpp: 19 (WebCore::ServiceWorkerJob::resolvedWithUnregistrationResult): 20 * workers/service/ServiceWorkerJob.h: 21 * workers/service/ServiceWorkerJobClient.h: 22 * workers/service/ServiceWorkerJobData.h: 23 (WebCore::ServiceWorkerJobData::encode const): 24 (WebCore::ServiceWorkerJobData::decode): 25 * workers/service/ServiceWorkerJobType.h: 26 * workers/service/ServiceWorkerRegistration.cpp: 27 (WebCore::containerForScriptExecutionContext): 28 (WebCore::ServiceWorkerRegistration::unregister): 29 * workers/service/server/SWClientConnection.cpp: 30 (WebCore::SWClientConnection::registrationJobResolvedInServer): 31 (WebCore::SWClientConnection::unregistrationJobResolvedInServer): 32 * workers/service/server/SWClientConnection.h: 33 * workers/service/server/SWServer.cpp: 34 (WebCore::SWServer::resolveRegistationJob): 35 (WebCore::SWServer::resolveUnregistrationJob): 36 * workers/service/server/SWServer.h: 37 * workers/service/server/SWServerRegistration.cpp: 38 (WebCore::SWServerRegistration::scriptContextStarted): 39 (WebCore::SWServerRegistration::startNextJob): 40 (WebCore::SWServerRegistration::runUnregisterJob): 41 (WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread): 42 (WebCore::SWServerRegistration::resolveWithUnregistrationResultOnMainThread): 43 (WebCore::SWServerRegistration::resolveCurrentRegistrationJob): 44 (WebCore::SWServerRegistration::resolveCurrentUnregistrationJob): 45 * workers/service/server/SWServerRegistration.h: 46 1 47 2017-10-25 Simon Fraser <simon.fraser@apple.com> 2 48 -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp
r223922 r223964 91 91 if (!context || !context->sessionID().isValid()) { 92 92 ASSERT_NOT_REACHED(); 93 return; 94 } 95 96 if (!m_swConnection) 97 m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context->sessionID()); 93 promise->reject(Exception(InvalidStateError)); 94 return; 95 } 98 96 99 97 if (relativeScriptURL.isEmpty()) { … … 101 99 return; 102 100 } 101 102 if (!m_swConnection) 103 m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(scriptExecutionContext()->sessionID()); 103 104 104 105 ServiceWorkerJobData jobData(m_swConnection->identifier()); … … 145 146 } 146 147 148 void ServiceWorkerContainer::removeRegistration(const URL& scopeURL, Ref<DeferredPromise>&& promise) 149 { 150 auto* context = scriptExecutionContext(); 151 if (!context || !context->sessionID().isValid()) { 152 ASSERT_NOT_REACHED(); 153 promise->reject(Exception(InvalidStateError)); 154 return; 155 } 156 157 if (!m_swConnection) { 158 ASSERT_NOT_REACHED(); 159 promise->reject(Exception(InvalidStateError)); 160 return; 161 } 162 163 ServiceWorkerJobData jobData(m_swConnection->identifier()); 164 jobData.clientCreationURL = context->url(); 165 jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin()); 166 jobData.type = ServiceWorkerJobType::Unregister; 167 jobData.scopeURL = scopeURL; 168 169 scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData))); 170 } 171 147 172 void ServiceWorkerContainer::scheduleJob(Ref<ServiceWorkerJob>&& job) 148 173 { … … 193 218 auto registration = ServiceWorkerRegistration::create(*context, WTFMove(data)); 194 219 job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get()); 220 } 221 222 void ServiceWorkerContainer::jobResolvedWithUnregistrationResult(ServiceWorkerJob& job, bool unregistrationResult) 223 { 224 ScopeGuard guard([this, &job] { 225 jobDidFinish(job); 226 }); 227 228 auto* context = scriptExecutionContext(); 229 if (!context) { 230 LOG_ERROR("ServiceWorkerContainer::jobResolvedWithUnregistrationResult called but the containers ScriptExecutionContext is gone"); 231 return; 232 } 233 234 // FIXME: Implement proper selection of service workers. 235 if (unregistrationResult) 236 context->setSelectedServiceWorkerIdentifier(0); 237 238 job.promise().resolve<IDLBoolean>(unregistrationResult); 195 239 } 196 240 -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h
r223922 r223964 61 61 62 62 void addRegistration(const String& scriptURL, const RegistrationOptions&, Ref<DeferredPromise>&&); 63 void removeRegistration(const URL& scopeURL, Ref<DeferredPromise>&&); 63 64 void getRegistration(const String& url, Ref<DeferredPromise>&&); 64 65 void getRegistrations(Ref<DeferredPromise>&&); … … 74 75 void jobFailedWithException(ServiceWorkerJob&, const Exception&) final; 75 76 void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&) final; 77 void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) final; 76 78 void startScriptFetchForJob(ServiceWorkerJob&) final; 77 79 void jobFinishedLoadingScript(ServiceWorkerJob&, const String&) final; -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp
r223652 r223964 67 67 } 68 68 69 void ServiceWorkerJob::resolvedWithUnregistrationResult(bool unregistrationResult) 70 { 71 ASSERT(currentThread() == m_creationThread); 72 ASSERT(!m_completed); 73 74 m_completed = true; 75 m_client->jobResolvedWithUnregistrationResult(*this, unregistrationResult); 76 } 77 69 78 void ServiceWorkerJob::startScriptFetch() 70 79 { -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.h
r223944 r223964 57 57 void failedWithException(const Exception&); 58 58 void resolvedWithRegistration(ServiceWorkerRegistrationData&&); 59 void resolvedWithUnregistrationResult(bool); 59 60 void startScriptFetch(); 60 61 -
trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h
r223728 r223964 42 42 virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0; 43 43 virtual void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&) = 0; 44 virtual void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) = 0; 44 45 virtual void startScriptFetchForJob(ServiceWorkerJob&) = 0; 45 46 virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const String&) = 0; -
trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h
r222233 r223964 74 74 encoder << registrationOptions; 75 75 break; 76 case ServiceWorkerJobType::Unregister: 77 break; 76 78 } 77 79 } … … 111 113 return std::nullopt; 112 114 break; 115 case ServiceWorkerJobType::Unregister: 116 break; 113 117 } 114 118 -
trunk/Source/WebCore/workers/service/ServiceWorkerJobType.h
r220924 r223964 32 32 enum class ServiceWorkerJobType { 33 33 Register, 34 Unregister, 34 35 }; 35 36 -
trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp
r223652 r223964 28 28 29 29 #if ENABLE(SERVICE_WORKER) 30 #include "DOMWindow.h" 31 #include "Document.h" 32 #include "Navigator.h" 33 #include "ServiceWorkerContainer.h" 34 #include "WorkerGlobalScope.h" 35 #include "WorkerNavigator.h" 30 36 31 37 namespace WebCore { 38 39 static ServiceWorkerContainer* containerForScriptExecutionContext(ScriptExecutionContext& context) 40 { 41 NavigatorBase* navigator = nullptr; 42 if (is<Document>(context)) { 43 if (auto* window = downcast<Document>(context).domWindow()) 44 navigator = window->navigator(); 45 } else 46 navigator = &downcast<WorkerGlobalScope>(context).navigator(); 47 48 return navigator ? navigator->serviceWorker() : nullptr; 49 } 32 50 33 51 ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, ServiceWorkerRegistrationData&& registrationData) … … 70 88 void ServiceWorkerRegistration::unregister(Ref<DeferredPromise>&& promise) 71 89 { 72 promise->reject(Exception(NotSupportedError, ASCIILiteral("ServiceWorkerRegistration::unregister not yet implemented"))); 90 auto* context = scriptExecutionContext(); 91 if (!context) { 92 ASSERT_NOT_REACHED(); 93 promise->reject(Exception(InvalidStateError)); 94 return; 95 } 96 97 auto* container = containerForScriptExecutionContext(*context); 98 if (!container) { 99 promise->reject(Exception(InvalidStateError)); 100 return; 101 } 102 103 container->removeRegistration(m_registrationData.scopeURL, WTFMove(promise)); 73 104 } 74 105 -
trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp
r223728 r223964 72 72 } 73 73 74 void SWClientConnection:: jobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&& registrationData)74 void SWClientConnection::registrationJobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&& registrationData) 75 75 { 76 76 auto job = m_scheduledJobs.take(jobIdentifier); … … 81 81 82 82 job->resolvedWithRegistration(WTFMove(registrationData)); 83 } 84 85 void SWClientConnection::unregistrationJobResolvedInServer(uint64_t jobIdentifier, bool unregistrationResult) 86 { 87 auto job = m_scheduledJobs.take(jobIdentifier); 88 if (!job) { 89 LOG_ERROR("Job %" PRIu64 " resolved in server, but was not found", jobIdentifier); 90 return; 91 } 92 93 job->resolvedWithUnregistrationResult(unregistrationResult); 83 94 } 84 95 -
trunk/Source/WebCore/workers/service/server/SWClientConnection.h
r223922 r223964 57 57 protected: 58 58 WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&); 59 WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&&); 59 WEBCORE_EXPORT void registrationJobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&&); 60 WEBCORE_EXPORT void unregistrationJobResolvedInServer(uint64_t jobIdentifier, bool unregistrationResult); 60 61 WEBCORE_EXPORT void startScriptFetchForServer(uint64_t jobIdentifier); 61 62 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r223608 r223964 122 122 } 123 123 124 void SWServer::resolve Job(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationData& registrationData)124 void SWServer::resolveRegistrationJob(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationData& registrationData) 125 125 { 126 126 LOG(ServiceWorker, "Resolved ServiceWorker job %" PRIu64 "-%" PRIu64 " in server with registration %" PRIu64, jobData.connectionIdentifier(), jobData.identifier(), registrationData.identifier); … … 129 129 return; 130 130 131 connection->resolveJobInClient(jobData.identifier(), registrationData); 131 connection->resolveRegistrationJobInClient(jobData.identifier(), registrationData); 132 } 133 134 void SWServer::resolveUnregistrationJob(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationKey& registrationKey, bool unregistrationResult) 135 { 136 auto* connection = m_connections.get(jobData.connectionIdentifier()); 137 if (!connection) 138 return; 139 140 connection->resolveUnregistrationJobInClient(jobData.identifier(), registrationKey, unregistrationResult); 132 141 } 133 142 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r223608 r223964 68 68 // Messages to the client WebProcess 69 69 virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0; 70 virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0; 70 virtual void resolveRegistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0; 71 virtual void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationKey&, bool registrationResult) = 0; 71 72 virtual void startScriptFetchInClient(uint64_t jobIdentifier) = 0; 72 73 … … 82 83 void scheduleJob(const ServiceWorkerJobData&); 83 84 void rejectJob(const ServiceWorkerJobData&, const ExceptionData&); 84 void resolveJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&); 85 void resolveRegistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&); 86 void resolveUnregistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationKey&, bool unregistrationResult); 85 87 void startScriptFetch(const ServiceWorkerJobData&); 86 88 -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp
r223652 r223964 98 98 { 99 99 UNUSED_PARAM(workerID); 100 resolveCurrent Job(ServiceWorkerRegistrationData { m_registrationKey, identifier, m_scopeURL, m_updateViaCache.value_or(ServiceWorkerUpdateViaCache::Imports) });100 resolveCurrentRegistrationJob(ServiceWorkerRegistrationData { m_registrationKey, identifier, m_scopeURL, m_updateViaCache.value_or(ServiceWorkerUpdateViaCache::Imports) }); 101 101 } 102 102 … … 112 112 case ServiceWorkerJobType::Register: 113 113 m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::runRegisterJob, *m_currentJob)); 114 return; 115 case ServiceWorkerJobType::Unregister: 116 m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::runUnregisterJob, *m_currentJob)); 114 117 return; 115 118 } … … 174 177 } 175 178 179 void SWServerRegistration::runUnregisterJob(const ServiceWorkerJobData& job) 180 { 181 // If the origin of job’s scope url is not job's client's origin, then: 182 if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL)) 183 return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Origin of scope URL does not match the client's origin") }); 184 185 // Let registration be the result of running "Get Registration" algorithm passing job’s scope url as the argument. 186 // If registration is null, then: 187 if (isEmpty() || m_uninstalling) { 188 // Invoke Resolve Job Promise with job and false. 189 resolveWithUnregistrationResultOnMainThread(false); 190 return; 191 } 192 193 // Set registration’s uninstalling flag. 194 m_uninstalling = true; 195 196 // Invoke Resolve Job Promise with job and true. 197 resolveWithUnregistrationResultOnMainThread(true); 198 199 // FIXME: Invoke Try Clear Registration with registration. 200 } 201 176 202 void SWServerRegistration::runUpdateJob(const ServiceWorkerJobData& job) 177 203 { … … 199 225 { 200 226 ASSERT(!isMainThread()); 201 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentJob, data())); 227 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentRegistrationJob, data())); 228 } 229 230 void SWServerRegistration::resolveWithUnregistrationResultOnMainThread(bool unregistrationResult) 231 { 232 ASSERT(!isMainThread()); 233 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentUnregistrationJob, unregistrationResult)); 202 234 } 203 235 … … 218 250 } 219 251 220 void SWServerRegistration::resolveCurrentJob(const ServiceWorkerRegistrationData& data) 221 { 222 ASSERT(isMainThread()); 223 ASSERT(m_currentJob); 224 225 m_server.resolveJob(*m_currentJob, data); 252 void SWServerRegistration::resolveCurrentRegistrationJob(const ServiceWorkerRegistrationData& data) 253 { 254 ASSERT(isMainThread()); 255 ASSERT(m_currentJob); 256 ASSERT(m_currentJob->type == ServiceWorkerJobType::Register); 257 258 m_server.resolveRegistrationJob(*m_currentJob, data); 259 260 finishCurrentJob(); 261 } 262 263 void SWServerRegistration::resolveCurrentUnregistrationJob(bool unregistrationResult) 264 { 265 ASSERT(isMainThread()); 266 ASSERT(m_currentJob); 267 ASSERT(m_currentJob->type == ServiceWorkerJobType::Unregister); 268 269 m_server.resolveUnregistrationJob(*m_currentJob, m_registrationKey, unregistrationResult); 226 270 227 271 finishCurrentJob(); -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.h
r223608 r223964 59 59 void startNextJob(); 60 60 void rejectCurrentJob(const ExceptionData&); 61 void resolveCurrentJob(const ServiceWorkerRegistrationData&); 61 void resolveCurrentRegistrationJob(const ServiceWorkerRegistrationData&); 62 void resolveCurrentUnregistrationJob(bool unregistrationResult); 62 63 void startScriptFetchForCurrentJob(); 63 64 void finishCurrentJob(); 64 65 65 66 void runRegisterJob(const ServiceWorkerJobData&); 67 void runUnregisterJob(const ServiceWorkerJobData&); 66 68 void runUpdateJob(const ServiceWorkerJobData&); 67 69 68 70 void rejectWithExceptionOnMainThread(const ExceptionData&); 69 71 void resolveWithRegistrationOnMainThread(); 72 void resolveWithUnregistrationResultOnMainThread(bool); 70 73 void startScriptFetchFromMainThread(); 71 74 bool isEmpty(); -
trunk/Source/WebKit/ChangeLog
r223958 r223964 1 2017-10-25 Chris Dumez <cdumez@apple.com> 2 3 Add support for unregistering a service worker 4 https://bugs.webkit.org/show_bug.cgi?id=178735 5 6 Reviewed by Brady Eidson. 7 8 Add support for unregistering a service worker: 9 - https://w3c.github.io/ServiceWorker/#navigator-service-worker-unregister 10 11 * StorageProcess/ServiceWorker/WebSWServerConnection.cpp: 12 (WebKit::WebSWServerConnection::resolveRegistrationJobInClient): 13 (WebKit::WebSWServerConnection::resolveUnregistrationJobInClient): 14 * StorageProcess/ServiceWorker/WebSWServerConnection.h: 15 * WebProcess/Storage/WebSWClientConnection.messages.in: 16 1 17 2017-10-25 Chris Dumez <cdumez@apple.com> 2 18 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
r223922 r223964 76 76 } 77 77 78 void WebSWServerConnection::resolve JobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)78 void WebSWServerConnection::resolveRegistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData) 79 79 { 80 80 auto origin = registrationData.key.topOrigin.securityOrigin(); 81 81 StorageProcess::singleton().ensureSWOriginStoreForSession(m_sessionID).add(origin); 82 send(Messages::WebSWClientConnection::JobResolvedInServer(jobIdentifier, registrationData)); 82 send(Messages::WebSWClientConnection::RegistrationJobResolvedInServer(jobIdentifier, registrationData)); 83 } 84 85 void WebSWServerConnection::resolveUnregistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationKey& registrationKey, bool unregistrationResult) 86 { 87 auto origin = registrationKey.topOrigin.securityOrigin(); 88 if (auto* store = StorageProcess::singleton().swOriginStoreForSession(m_sessionID)) 89 store->remove(origin); 90 send(Messages::WebSWClientConnection::UnregistrationJobResolvedInServer(jobIdentifier, unregistrationResult)); 83 91 } 84 92 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
r223922 r223964 61 61 // Implement SWServer::Connection (Messages to the client WebProcess) 62 62 void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final; 63 void resolveJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final; 63 void resolveRegistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final; 64 void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, bool unregistrationResult) final; 64 65 void startScriptFetchInClient(uint64_t jobIdentifier) final; 65 66 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in
r223608 r223964 26 26 # When possible, these messages can be implemented directly by WebCore::SWServer::Connection 27 27 JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception) 28 JobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration) 28 RegistrationJobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration) 29 UnregistrationJobResolvedInServer(uint64_t identifier, bool unregistrationResult) 29 30 StartScriptFetchForServer(uint64_t jobIdentifier) 30 31
Note: See TracChangeset
for help on using the changeset viewer.