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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 if (ServiceWorkerUtils::ContainsDisallowedCharacter(pattern, script_url, | 340 if (ServiceWorkerUtils::ContainsDisallowedCharacter(pattern, script_url, |
341 &error_message)) { | 341 &error_message)) { |
342 bad_message::ReceivedBadMessage(this, bad_message::SWDH_REGISTER_CANNOT); | 342 bad_message::ReceivedBadMessage(this, bad_message::SWDH_REGISTER_CANNOT); |
343 return; | 343 return; |
344 } | 344 } |
345 | 345 |
346 if (!GetContentClient()->browser()->AllowServiceWorker( | 346 if (!GetContentClient()->browser()->AllowServiceWorker( |
347 pattern, provider_host->topmost_frame_url(), resource_context_, | 347 pattern, provider_host->topmost_frame_url(), resource_context_, |
348 render_process_id_, provider_host->frame_id())) { | 348 render_process_id_, provider_host->frame_id())) { |
349 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 349 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
350 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 350 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
351 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + | 351 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
352 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 352 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
353 return; | 353 return; |
354 } | 354 } |
355 | 355 |
356 TRACE_EVENT_ASYNC_BEGIN2( | 356 TRACE_EVENT_ASYNC_BEGIN2( |
357 "ServiceWorker", "ServiceWorkerDispatcherHost::RegisterServiceWorker", | 357 "ServiceWorker", "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
358 request_id, "Scope", pattern.spec(), "Script URL", script_url.spec()); | 358 request_id, "Scope", pattern.spec(), "Script URL", script_url.spec()); |
359 GetContext()->RegisterServiceWorker( | 359 GetContext()->RegisterServiceWorker( |
360 pattern, | 360 pattern, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (!CanUpdateServiceWorker(provider_host->document_url(), | 418 if (!CanUpdateServiceWorker(provider_host->document_url(), |
419 registration->pattern())) { | 419 registration->pattern())) { |
420 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); | 420 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); |
421 return; | 421 return; |
422 } | 422 } |
423 | 423 |
424 if (!GetContentClient()->browser()->AllowServiceWorker( | 424 if (!GetContentClient()->browser()->AllowServiceWorker( |
425 registration->pattern(), provider_host->topmost_frame_url(), | 425 registration->pattern(), provider_host->topmost_frame_url(), |
426 resource_context_, render_process_id_, provider_host->frame_id())) { | 426 resource_context_, render_process_id_, provider_host->frame_id())) { |
427 Send(new ServiceWorkerMsg_ServiceWorkerUpdateError( | 427 Send(new ServiceWorkerMsg_ServiceWorkerUpdateError( |
428 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 428 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
429 base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) + | 429 base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) + |
430 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 430 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 if (!registration->GetNewestVersion()) { | 434 if (!registration->GetNewestVersion()) { |
435 // This can happen if update() is called during initial script evaluation. | 435 // This can happen if update() is called during initial script evaluation. |
436 // Abort the following steps according to the spec. | 436 // Abort the following steps according to the spec. |
437 Send(new ServiceWorkerMsg_ServiceWorkerUpdateError( | 437 Send(new ServiceWorkerMsg_ServiceWorkerUpdateError( |
438 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, | 438 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 base::debug::ScopedCrashKey scope_url_key( | 505 base::debug::ScopedCrashKey scope_url_key( |
506 "swdh_unregister_cannot_scope_url", registration->pattern().spec()); | 506 "swdh_unregister_cannot_scope_url", registration->pattern().spec()); |
507 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT); | 507 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT); |
508 return; | 508 return; |
509 } | 509 } |
510 | 510 |
511 if (!GetContentClient()->browser()->AllowServiceWorker( | 511 if (!GetContentClient()->browser()->AllowServiceWorker( |
512 registration->pattern(), provider_host->topmost_frame_url(), | 512 registration->pattern(), provider_host->topmost_frame_url(), |
513 resource_context_, render_process_id_, provider_host->frame_id())) { | 513 resource_context_, render_process_id_, provider_host->frame_id())) { |
514 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 514 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
515 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 515 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
516 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 516 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
517 return; | 517 return; |
518 } | 518 } |
519 | 519 |
520 TRACE_EVENT_ASYNC_BEGIN1( | 520 TRACE_EVENT_ASYNC_BEGIN1( |
521 "ServiceWorker", "ServiceWorkerDispatcherHost::UnregisterServiceWorker", | 521 "ServiceWorker", "ServiceWorkerDispatcherHost::UnregisterServiceWorker", |
522 request_id, "Scope", registration->pattern().spec()); | 522 request_id, "Scope", registration->pattern().spec()); |
523 GetContext()->UnregisterServiceWorker( | 523 GetContext()->UnregisterServiceWorker( |
524 registration->pattern(), | 524 registration->pattern(), |
525 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, this, | 525 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, this, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 "swdh_get_registration_cannot_document_url", document_url.spec()); | 581 "swdh_get_registration_cannot_document_url", document_url.spec()); |
582 bad_message::ReceivedBadMessage(this, | 582 bad_message::ReceivedBadMessage(this, |
583 bad_message::SWDH_GET_REGISTRATION_CANNOT); | 583 bad_message::SWDH_GET_REGISTRATION_CANNOT); |
584 return; | 584 return; |
585 } | 585 } |
586 | 586 |
587 if (!GetContentClient()->browser()->AllowServiceWorker( | 587 if (!GetContentClient()->browser()->AllowServiceWorker( |
588 provider_host->document_url(), provider_host->topmost_frame_url(), | 588 provider_host->document_url(), provider_host->topmost_frame_url(), |
589 resource_context_, render_process_id_, provider_host->frame_id())) { | 589 resource_context_, render_process_id_, provider_host->frame_id())) { |
590 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 590 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
591 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 591 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
592 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | 592 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
593 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 593 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
594 return; | 594 return; |
595 } | 595 } |
596 | 596 |
597 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 597 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
598 "ServiceWorkerDispatcherHost::GetRegistration", | 598 "ServiceWorkerDispatcherHost::GetRegistration", |
599 request_id, "Document URL", document_url.spec()); | 599 request_id, "Document URL", document_url.spec()); |
600 GetContext()->storage()->FindRegistrationForDocument( | 600 GetContext()->storage()->FindRegistrationForDocument( |
601 document_url, | 601 document_url, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 if (!OriginCanAccessServiceWorkers(provider_host->document_url())) { | 648 if (!OriginCanAccessServiceWorkers(provider_host->document_url())) { |
649 bad_message::ReceivedBadMessage( | 649 bad_message::ReceivedBadMessage( |
650 this, bad_message::SWDH_GET_REGISTRATIONS_INVALID_ORIGIN); | 650 this, bad_message::SWDH_GET_REGISTRATIONS_INVALID_ORIGIN); |
651 return; | 651 return; |
652 } | 652 } |
653 | 653 |
654 if (!GetContentClient()->browser()->AllowServiceWorker( | 654 if (!GetContentClient()->browser()->AllowServiceWorker( |
655 provider_host->document_url(), provider_host->topmost_frame_url(), | 655 provider_host->document_url(), provider_host->topmost_frame_url(), |
656 resource_context_, render_process_id_, provider_host->frame_id())) { | 656 resource_context_, render_process_id_, provider_host->frame_id())) { |
657 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | 657 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( |
658 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 658 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
659 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + | 659 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + |
660 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 660 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
661 return; | 661 return; |
662 } | 662 } |
663 | 663 |
664 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 664 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
665 "ServiceWorkerDispatcherHost::GetRegistrations", | 665 "ServiceWorkerDispatcherHost::GetRegistrations", |
666 request_id); | 666 request_id); |
667 GetContext()->storage()->GetRegistrationsForOrigin( | 667 GetContext()->storage()->GetRegistrationsForOrigin( |
668 provider_host->document_url().GetOrigin(), | 668 provider_host->document_url().GetOrigin(), |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 if (!handle) { | 1455 if (!handle) { |
1456 bad_message::ReceivedBadMessage(this, | 1456 bad_message::ReceivedBadMessage(this, |
1457 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1457 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
1458 return; | 1458 return; |
1459 } | 1459 } |
1460 handle->version()->StopWorker( | 1460 handle->version()->StopWorker( |
1461 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1461 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1462 } | 1462 } |
1463 | 1463 |
1464 } // namespace content | 1464 } // namespace content |
OLD | NEW |