| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 17 #include "content/browser/bad_message.h" | 18 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/message_port_message_filter.h" | 19 #include "content/browser/message_port_message_filter.h" |
| 19 #include "content/browser/message_port_service.h" | 20 #include "content/browser/message_port_service.h" |
| 20 #include "content/browser/service_worker/embedded_worker_registry.h" | 21 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 21 #include "content/browser/service_worker/embedded_worker_status.h" | 22 #include "content/browser/service_worker/embedded_worker_status.h" |
| 22 #include "content/browser/service_worker/service_worker_client_utils.h" | 23 #include "content/browser/service_worker/service_worker_client_utils.h" |
| 23 #include "content/browser/service_worker/service_worker_context_core.h" | 24 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // |registration| must be alive because a renderer retains a registration | 475 // |registration| must be alive because a renderer retains a registration |
| 475 // reference at this point. | 476 // reference at this point. |
| 476 bad_message::ReceivedBadMessage( | 477 bad_message::ReceivedBadMessage( |
| 477 this, bad_message::SWDH_UNREGISTER_BAD_REGISTRATION_ID); | 478 this, bad_message::SWDH_UNREGISTER_BAD_REGISTRATION_ID); |
| 478 return; | 479 return; |
| 479 } | 480 } |
| 480 | 481 |
| 481 std::vector<GURL> urls = {provider_host->document_url(), | 482 std::vector<GURL> urls = {provider_host->document_url(), |
| 482 registration->pattern()}; | 483 registration->pattern()}; |
| 483 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { | 484 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { |
| 484 // Temporary debugging for https://crbug.com/619294 | |
| 485 base::debug::ScopedCrashKey host_url_key( | |
| 486 "swdh_unregister_cannot_host_url", | |
| 487 provider_host->document_url().spec()); | |
| 488 base::debug::ScopedCrashKey scope_url_key( | |
| 489 "swdh_unregister_cannot_scope_url", registration->pattern().spec()); | |
| 490 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT); | 485 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT); |
| 491 return; | 486 return; |
| 492 } | 487 } |
| 493 | 488 |
| 494 if (!GetContentClient()->browser()->AllowServiceWorker( | 489 if (!GetContentClient()->browser()->AllowServiceWorker( |
| 495 registration->pattern(), provider_host->topmost_frame_url(), | 490 registration->pattern(), provider_host->topmost_frame_url(), |
| 496 resource_context_, render_process_id_, provider_host->frame_id())) { | 491 resource_context_, render_process_id_, provider_host->frame_id())) { |
| 497 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 492 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
| 498 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, | 493 thread_id, request_id, WebServiceWorkerError::ErrorTypeDisabled, |
| 499 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 494 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 if (!version || version->running_status() != EmbeddedWorkerStatus::STARTING) | 1069 if (!version || version->running_status() != EmbeddedWorkerStatus::STARTING) |
| 1075 return; | 1070 return; |
| 1076 | 1071 |
| 1077 // If the version has a different embedded worker, assume the message is about | 1072 // If the version has a different embedded worker, assume the message is about |
| 1078 // a detached worker and ignore. | 1073 // a detached worker and ignore. |
| 1079 if (version->embedded_worker()->embedded_worker_id() != embedded_worker_id) | 1074 if (version->embedded_worker()->embedded_worker_id() != embedded_worker_id) |
| 1080 return; | 1075 return; |
| 1081 | 1076 |
| 1082 // A process for the worker must be equal to a process for the provider host. | 1077 // A process for the worker must be equal to a process for the provider host. |
| 1083 if (version->embedded_worker()->process_id() != provider_host->process_id()) { | 1078 if (version->embedded_worker()->process_id() != provider_host->process_id()) { |
| 1079 // Temporary debugging for https://crbug.com/668633 |
| 1080 base::debug::ScopedCrashKey scope_worker_pid( |
| 1081 "swdh_set_hosted_version_worker_pid", |
| 1082 base::IntToString(version->embedded_worker()->process_id())); |
| 1083 base::debug::ScopedCrashKey scope_provider_host_pid( |
| 1084 "swdh_set_hosted_version_host_pid", |
| 1085 base::IntToString(provider_host->process_id())); |
| 1084 bad_message::ReceivedBadMessage( | 1086 bad_message::ReceivedBadMessage( |
| 1085 this, bad_message::SWDH_SET_HOSTED_VERSION_PROCESS_MISMATCH); | 1087 this, bad_message::SWDH_SET_HOSTED_VERSION_PROCESS_MISMATCH); |
| 1086 return; | 1088 return; |
| 1087 } | 1089 } |
| 1088 | 1090 |
| 1089 provider_host->SetHostedVersion(version); | 1091 provider_host->SetHostedVersion(version); |
| 1090 | 1092 |
| 1091 // Retrieve the registration associated with |version|. The registration | 1093 // Retrieve the registration associated with |version|. The registration |
| 1092 // must be alive because the version keeps it during starting worker. | 1094 // must be alive because the version keeps it during starting worker. |
| 1093 ServiceWorkerRegistration* registration = | 1095 ServiceWorkerRegistration* registration = |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 if (!handle) { | 1747 if (!handle) { |
| 1746 bad_message::ReceivedBadMessage(this, | 1748 bad_message::ReceivedBadMessage(this, |
| 1747 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1749 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
| 1748 return; | 1750 return; |
| 1749 } | 1751 } |
| 1750 handle->version()->StopWorker( | 1752 handle->version()->StopWorker( |
| 1751 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1753 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1752 } | 1754 } |
| 1753 | 1755 |
| 1754 } // namespace content | 1756 } // namespace content |
| OLD | NEW |