OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); | 172 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); |
173 return; | 173 return; |
174 } | 174 } |
175 | 175 |
176 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 176 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
177 render_process_id_, provider_id); | 177 render_process_id_, provider_id); |
178 if (!provider_host) { | 178 if (!provider_host) { |
179 BadMessageReceived(); | 179 BadMessageReceived(); |
180 return; | 180 return; |
181 } | 181 } |
| 182 if (!provider_host->IsContextAlive()) { |
| 183 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 184 thread_id, |
| 185 request_id, |
| 186 WebServiceWorkerError::ErrorTypeDisabled, |
| 187 base::ASCIIToUTF16(kDisabledErrorMessage))); |
| 188 return; |
| 189 } |
182 | 190 |
183 GetContext()->RegisterServiceWorker( | 191 GetContext()->RegisterServiceWorker( |
184 pattern, | 192 pattern, |
185 script_url, | 193 script_url, |
186 render_process_id_, | 194 render_process_id_, |
187 provider_host, | 195 provider_host, |
188 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 196 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
189 this, | 197 this, |
190 thread_id, | 198 thread_id, |
191 request_id)); | 199 request_id)); |
(...skipping 15 matching lines...) Expand all Loading... |
207 base::ASCIIToUTF16(kDisabledErrorMessage))); | 215 base::ASCIIToUTF16(kDisabledErrorMessage))); |
208 return; | 216 return; |
209 } | 217 } |
210 | 218 |
211 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 219 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
212 render_process_id_, provider_id); | 220 render_process_id_, provider_id); |
213 if (!provider_host) { | 221 if (!provider_host) { |
214 BadMessageReceived(); | 222 BadMessageReceived(); |
215 return; | 223 return; |
216 } | 224 } |
| 225 if (!provider_host->IsContextAlive()) { |
| 226 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 227 thread_id, |
| 228 request_id, |
| 229 blink::WebServiceWorkerError::ErrorTypeDisabled, |
| 230 base::ASCIIToUTF16(kDisabledErrorMessage))); |
| 231 return; |
| 232 } |
217 | 233 |
218 GetContext()->UnregisterServiceWorker( | 234 GetContext()->UnregisterServiceWorker( |
219 pattern, | 235 pattern, |
220 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, | 236 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, |
221 this, | 237 this, |
222 thread_id, | 238 thread_id, |
223 request_id)); | 239 request_id)); |
224 } | 240 } |
225 | 241 |
226 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 242 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 284 } |
269 GetContext()->RemoveProviderHost(render_process_id_, provider_id); | 285 GetContext()->RemoveProviderHost(render_process_id_, provider_id); |
270 } | 286 } |
271 | 287 |
272 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( | 288 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
273 int provider_id, int64 version_id) { | 289 int provider_id, int64 version_id) { |
274 if (!GetContext()) | 290 if (!GetContext()) |
275 return; | 291 return; |
276 ServiceWorkerProviderHost* provider_host = | 292 ServiceWorkerProviderHost* provider_host = |
277 GetContext()->GetProviderHost(render_process_id_, provider_id); | 293 GetContext()->GetProviderHost(render_process_id_, provider_id); |
278 if (!provider_host || !provider_host->SetHostedVersionId(version_id)) { | 294 if (!provider_host) { |
279 BadMessageReceived(); | 295 BadMessageReceived(); |
280 return; | 296 return; |
281 } | 297 } |
| 298 if (!provider_host->IsContextAlive()) |
| 299 return; |
| 300 if (!provider_host->SetHostedVersionId(version_id)) |
| 301 BadMessageReceived(); |
282 } | 302 } |
283 | 303 |
284 void ServiceWorkerDispatcherHost::RegistrationComplete( | 304 void ServiceWorkerDispatcherHost::RegistrationComplete( |
285 int thread_id, | 305 int thread_id, |
286 int request_id, | 306 int request_id, |
287 ServiceWorkerStatusCode status, | 307 ServiceWorkerStatusCode status, |
288 int64 registration_id, | 308 int64 registration_id, |
289 int64 version_id) { | 309 int64 version_id) { |
290 if (!GetContext()) | 310 if (!GetContext()) |
291 return; | 311 return; |
292 | 312 |
293 if (status != SERVICE_WORKER_OK) { | 313 if (status != SERVICE_WORKER_OK) { |
294 SendRegistrationError(thread_id, request_id, status); | 314 SendRegistrationError(thread_id, request_id, status); |
295 return; | 315 return; |
296 } | 316 } |
297 | 317 |
298 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); | 318 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); |
299 DCHECK(version); | 319 DCHECK(version); |
300 DCHECK_EQ(registration_id, version->registration_id()); | 320 DCHECK_EQ(registration_id, version->registration_id()); |
301 scoped_ptr<ServiceWorkerHandle> handle = | 321 scoped_ptr<ServiceWorkerHandle> handle = |
302 ServiceWorkerHandle::Create(GetContext()->AsWeakPtr(), | 322 ServiceWorkerHandle::Create(GetContext()->AsWeakPtr(), |
303 this, thread_id, version); | 323 this, thread_id, version); |
304 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 324 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
305 thread_id, request_id, handle->GetObjectInfo())); | 325 thread_id, request_id, handle->GetObjectInfo())); |
306 RegisterServiceWorkerHandle(handle.Pass()); | 326 RegisterServiceWorkerHandle(handle.Pass()); |
307 } | 327 } |
308 | 328 |
| 329 // TODO(nhiroki): These message handlers that take |embedded_worker_id| as an |
| 330 // input should check if the worker refers to the live context. If the context |
| 331 // was deleted, handle the messege gracefully (http://crbug.com/371675). |
309 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { | 332 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { |
310 if (!GetContext()) | 333 if (!GetContext()) |
311 return; | 334 return; |
312 GetContext()->embedded_worker_registry()->OnWorkerScriptLoaded( | 335 GetContext()->embedded_worker_registry()->OnWorkerScriptLoaded( |
313 render_process_id_, embedded_worker_id); | 336 render_process_id_, embedded_worker_id); |
314 } | 337 } |
315 | 338 |
316 void ServiceWorkerDispatcherHost::OnWorkerScriptLoadFailed( | 339 void ServiceWorkerDispatcherHost::OnWorkerScriptLoadFailed( |
317 int embedded_worker_id) { | 340 int embedded_worker_id) { |
318 if (!GetContext()) | 341 if (!GetContext()) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 status, &error_type, &error_message); | 433 status, &error_type, &error_message); |
411 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 434 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
412 thread_id, request_id, error_type, error_message)); | 435 thread_id, request_id, error_type, error_message)); |
413 } | 436 } |
414 | 437 |
415 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 438 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
416 return context_wrapper_->context(); | 439 return context_wrapper_->context(); |
417 } | 440 } |
418 | 441 |
419 } // namespace content | 442 } // namespace content |
OLD | NEW |