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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
11 #include "content/browser/message_port_service.h" | 11 #include "content/browser/message_port_service.h" |
12 #include "content/browser/service_worker/embedded_worker_registry.h" | 12 #include "content/browser/service_worker/embedded_worker_registry.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
15 #include "content/browser/service_worker/service_worker_handle.h" | 15 #include "content/browser/service_worker/service_worker_handle.h" |
16 #include "content/browser/service_worker/service_worker_registration.h" | 16 #include "content/browser/service_worker/service_worker_registration.h" |
17 #include "content/browser/service_worker/service_worker_registration_handle.h" | 17 #include "content/browser/service_worker/service_worker_registration_handle.h" |
18 #include "content/browser/service_worker/service_worker_utils.h" | 18 #include "content/browser/service_worker/service_worker_utils.h" |
19 #include "content/common/service_worker/embedded_worker_messages.h" | 19 #include "content/common/service_worker/embedded_worker_messages.h" |
20 #include "content/common/service_worker/service_worker_messages.h" | 20 #include "content/common/service_worker/service_worker_messages.h" |
21 #include "content/common/service_worker/service_worker_types.h" | |
21 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
22 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
24 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
25 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 26 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 | 28 |
28 using blink::WebServiceWorkerError; | 29 using blink::WebServiceWorkerError; |
29 | 30 |
30 namespace content { | 31 namespace content { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 250 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
250 int thread_id, | 251 int thread_id, |
251 int request_id, | 252 int request_id, |
252 int provider_id, | 253 int provider_id, |
253 const GURL& pattern, | 254 const GURL& pattern, |
254 const GURL& script_url) { | 255 const GURL& script_url) { |
255 TRACE_EVENT0("ServiceWorker", | 256 TRACE_EVENT0("ServiceWorker", |
256 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker"); | 257 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker"); |
257 if (!GetContext()) { | 258 if (!GetContext()) { |
258 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 259 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
259 thread_id, | 260 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort, |
260 request_id, | 261 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
261 WebServiceWorkerError::ErrorTypeAbort, | 262 base::ASCIIToUTF16(kShutdownErrorMessage))); |
262 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
263 return; | 263 return; |
264 } | 264 } |
265 if (!pattern.is_valid() || !script_url.is_valid()) { | 265 if (!pattern.is_valid() || !script_url.is_valid()) { |
266 BadMessageReceived(); | 266 BadMessageReceived(); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 270 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
271 render_process_id_, provider_id); | 271 render_process_id_, provider_id); |
272 if (!provider_host) { | 272 if (!provider_host) { |
273 BadMessageReceived(); | 273 BadMessageReceived(); |
274 return; | 274 return; |
275 } | 275 } |
276 if (!provider_host->IsContextAlive()) { | 276 if (!provider_host->IsContextAlive()) { |
277 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 277 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
278 thread_id, | 278 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort, |
279 request_id, | 279 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
280 WebServiceWorkerError::ErrorTypeAbort, | 280 base::ASCIIToUTF16(kShutdownErrorMessage))); |
281 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
282 return; | 281 return; |
283 } | 282 } |
284 | 283 |
285 // TODO(ksakamoto): Currently, document_url is empty if the document is in an | 284 // TODO(ksakamoto): Currently, document_url is empty if the document is in an |
286 // IFRAME using frame.contentDocument.write(...). We can remove this check | 285 // IFRAME using frame.contentDocument.write(...). We can remove this check |
287 // once crbug.com/439697 is fixed. | 286 // once crbug.com/439697 is fixed. |
288 if (provider_host->document_url().is_empty()) { | 287 if (provider_host->document_url().is_empty()) { |
289 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 288 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
290 thread_id, | 289 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
291 request_id, | 290 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
292 WebServiceWorkerError::ErrorTypeSecurity, | 291 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); |
293 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | |
294 return; | 292 return; |
295 } | 293 } |
296 | 294 |
297 if (!CanRegisterServiceWorker( | 295 if (!CanRegisterServiceWorker( |
298 provider_host->document_url(), pattern, script_url)) { | 296 provider_host->document_url(), pattern, script_url)) { |
299 BadMessageReceived(); | 297 BadMessageReceived(); |
300 return; | 298 return; |
301 } | 299 } |
302 | 300 |
303 std::string error_message; | 301 std::string error_message; |
304 if (!ServiceWorkerUtils::IsPathRestrictionSatisfied( | 302 if (!ServiceWorkerUtils::IsPathRestrictionSatisfied( |
305 pattern, script_url, &error_message)) { | 303 pattern, script_url, &error_message)) { |
306 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 304 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
307 thread_id, | 305 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
308 request_id, | 306 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
309 WebServiceWorkerError::ErrorTypeSecurity, | 307 base::UTF8ToUTF16(error_message))); |
310 base::UTF8ToUTF16(error_message))); | |
311 return; | 308 return; |
312 } | 309 } |
313 | 310 |
314 if (!GetContentClient()->browser()->AllowServiceWorker( | 311 if (!GetContentClient()->browser()->AllowServiceWorker( |
315 pattern, provider_host->topmost_frame_url(), resource_context_)) { | 312 pattern, provider_host->topmost_frame_url(), resource_context_)) { |
316 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 313 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
317 thread_id, | 314 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, |
318 request_id, | 315 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
319 WebServiceWorkerError::ErrorTypeUnknown, | 316 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
320 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | |
321 return; | 317 return; |
322 } | 318 } |
323 | 319 |
324 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 320 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
325 "ServiceWorkerDispatcherHost::RegisterServiceWorker", | 321 "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
326 request_id, | 322 request_id, |
327 "Pattern", pattern.spec(), | 323 "Pattern", pattern.spec(), |
328 "Script URL", script_url.spec()); | 324 "Script URL", script_url.spec()); |
329 GetContext()->RegisterServiceWorker( | 325 GetContext()->RegisterServiceWorker( |
330 pattern, | 326 pattern, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 | 408 |
413 void ServiceWorkerDispatcherHost::OnGetRegistration( | 409 void ServiceWorkerDispatcherHost::OnGetRegistration( |
414 int thread_id, | 410 int thread_id, |
415 int request_id, | 411 int request_id, |
416 int provider_id, | 412 int provider_id, |
417 const GURL& document_url) { | 413 const GURL& document_url) { |
418 TRACE_EVENT0("ServiceWorker", | 414 TRACE_EVENT0("ServiceWorker", |
419 "ServiceWorkerDispatcherHost::OnGetRegistration"); | 415 "ServiceWorkerDispatcherHost::OnGetRegistration"); |
420 if (!GetContext()) { | 416 if (!GetContext()) { |
421 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 417 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
422 thread_id, | 418 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
423 request_id, | 419 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
424 blink::WebServiceWorkerError::ErrorTypeAbort, | 420 base::ASCIIToUTF16(kShutdownErrorMessage))); |
425 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
426 return; | 421 return; |
427 } | 422 } |
428 if (!document_url.is_valid()) { | 423 if (!document_url.is_valid()) { |
429 BadMessageReceived(); | 424 BadMessageReceived(); |
430 return; | 425 return; |
431 } | 426 } |
432 | 427 |
433 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 428 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
434 render_process_id_, provider_id); | 429 render_process_id_, provider_id); |
435 if (!provider_host) { | 430 if (!provider_host) { |
436 BadMessageReceived(); | 431 BadMessageReceived(); |
437 return; | 432 return; |
438 } | 433 } |
439 if (!provider_host->IsContextAlive()) { | 434 if (!provider_host->IsContextAlive()) { |
440 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 435 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
441 thread_id, | 436 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
442 request_id, | 437 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
443 blink::WebServiceWorkerError::ErrorTypeAbort, | 438 base::ASCIIToUTF16(kShutdownErrorMessage))); |
444 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
445 return; | 439 return; |
446 } | 440 } |
447 | 441 |
448 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. | 442 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. |
449 if (provider_host->document_url().is_empty()) { | 443 if (provider_host->document_url().is_empty()) { |
450 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 444 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
451 thread_id, | 445 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
452 request_id, | 446 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
453 WebServiceWorkerError::ErrorTypeSecurity, | 447 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); |
454 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | |
455 return; | 448 return; |
456 } | 449 } |
457 | 450 |
458 if (!CanGetRegistration(provider_host->document_url(), document_url)) { | 451 if (!CanGetRegistration(provider_host->document_url(), document_url)) { |
459 BadMessageReceived(); | 452 BadMessageReceived(); |
460 return; | 453 return; |
461 } | 454 } |
462 | 455 |
463 if (!GetContentClient()->browser()->AllowServiceWorker( | 456 if (!GetContentClient()->browser()->AllowServiceWorker( |
464 provider_host->document_url(), | 457 provider_host->document_url(), |
465 provider_host->topmost_frame_url(), | 458 provider_host->topmost_frame_url(), |
466 resource_context_)) { | 459 resource_context_)) { |
467 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 460 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
468 thread_id, | 461 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, |
469 request_id, | 462 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
470 WebServiceWorkerError::ErrorTypeUnknown, | 463 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
471 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | |
472 return; | 464 return; |
473 } | 465 } |
474 | 466 |
475 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 467 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
476 if (GetContext()->storage()->IsDisabled()) { | 468 if (GetContext()->storage()->IsDisabled()) { |
477 SendGetRegistrationError(thread_id, request_id, SERVICE_WORKER_ERROR_ABORT); | 469 SendGetRegistrationError(thread_id, request_id, SERVICE_WORKER_ERROR_ABORT); |
478 return; | 470 return; |
479 } | 471 } |
480 | 472 |
481 TRACE_EVENT_ASYNC_BEGIN1( | 473 TRACE_EVENT_ASYNC_BEGIN1( |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 | 852 |
861 void ServiceWorkerDispatcherHost::SendRegistrationError( | 853 void ServiceWorkerDispatcherHost::SendRegistrationError( |
862 int thread_id, | 854 int thread_id, |
863 int request_id, | 855 int request_id, |
864 ServiceWorkerStatusCode status) { | 856 ServiceWorkerStatusCode status) { |
865 base::string16 error_message; | 857 base::string16 error_message; |
866 blink::WebServiceWorkerError::ErrorType error_type; | 858 blink::WebServiceWorkerError::ErrorType error_type; |
867 GetServiceWorkerRegistrationStatusResponse( | 859 GetServiceWorkerRegistrationStatusResponse( |
868 status, &error_type, &error_message); | 860 status, &error_type, &error_message); |
869 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 861 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
870 thread_id, request_id, error_type, error_message)); | 862 thread_id, request_id, error_type, |
863 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + error_message)); | |
dominicc (has gone to gerrit)
2015/01/14 06:16:37
Realize that this is not in your patch, but do you
falken
2015/01/14 07:29:21
That's a good question. I found this post:
https:/
| |
871 } | 864 } |
872 | 865 |
873 void ServiceWorkerDispatcherHost::SendUnregistrationError( | 866 void ServiceWorkerDispatcherHost::SendUnregistrationError( |
874 int thread_id, | 867 int thread_id, |
875 int request_id, | 868 int request_id, |
876 ServiceWorkerStatusCode status) { | 869 ServiceWorkerStatusCode status) { |
877 base::string16 error_message; | 870 base::string16 error_message; |
878 blink::WebServiceWorkerError::ErrorType error_type; | 871 blink::WebServiceWorkerError::ErrorType error_type; |
879 GetServiceWorkerRegistrationStatusResponse( | 872 GetServiceWorkerRegistrationStatusResponse( |
880 status, &error_type, &error_message); | 873 status, &error_type, &error_message); |
881 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 874 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
882 thread_id, request_id, error_type, error_message)); | 875 thread_id, request_id, error_type, |
876 base::ASCIIToUTF16(kServiceWorkerUnregisterErrorPrefix) + error_message)); | |
883 } | 877 } |
884 | 878 |
885 void ServiceWorkerDispatcherHost::SendGetRegistrationError( | 879 void ServiceWorkerDispatcherHost::SendGetRegistrationError( |
886 int thread_id, | 880 int thread_id, |
887 int request_id, | 881 int request_id, |
888 ServiceWorkerStatusCode status) { | 882 ServiceWorkerStatusCode status) { |
889 base::string16 error_message; | 883 base::string16 error_message; |
890 blink::WebServiceWorkerError::ErrorType error_type; | 884 blink::WebServiceWorkerError::ErrorType error_type; |
891 GetServiceWorkerRegistrationStatusResponse( | 885 GetServiceWorkerRegistrationStatusResponse( |
892 status, &error_type, &error_message); | 886 status, &error_type, &error_message); |
893 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 887 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
894 thread_id, request_id, error_type, error_message)); | 888 thread_id, request_id, error_type, |
889 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | |
890 error_message)); | |
895 } | 891 } |
896 | 892 |
897 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 893 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
898 if (!context_wrapper_.get()) | 894 if (!context_wrapper_.get()) |
899 return nullptr; | 895 return nullptr; |
900 return context_wrapper_->context(); | 896 return context_wrapper_->context(); |
901 } | 897 } |
902 | 898 |
903 void ServiceWorkerDispatcherHost::OnTerminateWorker(int handle_id) { | 899 void ServiceWorkerDispatcherHost::OnTerminateWorker(int handle_id) { |
904 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 900 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
(...skipping 11 matching lines...) Expand all Loading... | |
916 handles_.AddWithID(handle.release(), handle_id); | 912 handles_.AddWithID(handle.release(), handle_id); |
917 } | 913 } |
918 | 914 |
919 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( | 915 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( |
920 scoped_ptr<ServiceWorkerRegistrationHandle> handle) { | 916 scoped_ptr<ServiceWorkerRegistrationHandle> handle) { |
921 int handle_id = handle->handle_id(); | 917 int handle_id = handle->handle_id(); |
922 registration_handles_.AddWithID(handle.release(), handle_id); | 918 registration_handles_.AddWithID(handle.release(), handle_id); |
923 } | 919 } |
924 | 920 |
925 } // namespace content | 921 } // namespace content |
OLD | NEW |