| 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/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "content/child/service_worker/service_worker_handle_reference.h" | 16 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 17 #include "content/child/service_worker/service_worker_provider_context.h" | 17 #include "content/child/service_worker/service_worker_provider_context.h" |
| 18 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 18 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 19 #include "content/child/service_worker/web_service_worker_impl.h" | 19 #include "content/child/service_worker/web_service_worker_impl.h" |
| 20 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 20 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 21 #include "content/child/thread_safe_sender.h" | 21 #include "content/child/thread_safe_sender.h" |
| 22 #include "content/child/webmessageportchannel_impl.h" | 22 #include "content/child/webmessageportchannel_impl.h" |
| 23 #include "content/common/service_worker/service_worker_messages.h" | 23 #include "content/common/service_worker/service_worker_messages.h" |
| 24 #include "content/common/service_worker/service_worker_types.h" | 24 #include "content/common/service_worker/service_worker_types.h" |
| 25 #include "content/public/common/content_constants.h" | 25 #include "content/public/common/content_constants.h" |
| 26 #include "third_party/WebKit/public/platform/WebString.h" | 26 #include "third_party/WebKit/public/platform/WebString.h" |
| 27 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" | 27 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" |
| 28 #include "url/url_constants.h" | |
| 29 | 28 |
| 30 using blink::WebServiceWorkerError; | 29 using blink::WebServiceWorkerError; |
| 31 using blink::WebServiceWorkerProvider; | 30 using blink::WebServiceWorkerProvider; |
| 32 using base::ThreadLocalPointer; | 31 using base::ThreadLocalPointer; |
| 33 | 32 |
| 34 namespace content { | 33 namespace content { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 base::LazyInstance<ThreadLocalPointer<void>>::Leaky g_dispatcher_tls = | 37 base::LazyInstance<ThreadLocalPointer<void>>::Leaky g_dispatcher_tls = |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 DCHECK(handled) << "Unhandled message:" << msg.type(); | 103 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void ServiceWorkerDispatcher::RegisterServiceWorker( | 106 void ServiceWorkerDispatcher::RegisterServiceWorker( |
| 108 int provider_id, | 107 int provider_id, |
| 109 const GURL& pattern, | 108 const GURL& pattern, |
| 110 const GURL& script_url, | 109 const GURL& script_url, |
| 111 WebServiceWorkerRegistrationCallbacks* callbacks) { | 110 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 112 DCHECK(callbacks); | 111 DCHECK(callbacks); |
| 113 | 112 |
| 114 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || | 113 if (pattern.possibly_invalid_spec().size() > kMaxURLChars || |
| 115 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 114 script_url.possibly_invalid_spec().size() > kMaxURLChars) { |
| 116 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 115 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| 117 owned_callbacks(callbacks); | 116 owned_callbacks(callbacks); |
| 118 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 117 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
| 119 error_message += "The provided scriptURL or scope is too long."; | 118 error_message += "The provided scriptURL or scope is too long."; |
| 120 callbacks->onError( | 119 callbacks->onError( |
| 121 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 120 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 122 blink::WebString::fromUTF8(error_message))); | 121 blink::WebString::fromUTF8(error_message))); |
| 123 return; | 122 return; |
| 124 } | 123 } |
| 125 | 124 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 155 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 154 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 156 CurrentWorkerId(), request_id, provider_id, registration_id)); | 155 CurrentWorkerId(), request_id, provider_id, registration_id)); |
| 157 } | 156 } |
| 158 | 157 |
| 159 void ServiceWorkerDispatcher::GetRegistration( | 158 void ServiceWorkerDispatcher::GetRegistration( |
| 160 int provider_id, | 159 int provider_id, |
| 161 const GURL& document_url, | 160 const GURL& document_url, |
| 162 WebServiceWorkerGetRegistrationCallbacks* callbacks) { | 161 WebServiceWorkerGetRegistrationCallbacks* callbacks) { |
| 163 DCHECK(callbacks); | 162 DCHECK(callbacks); |
| 164 | 163 |
| 165 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 164 if (document_url.possibly_invalid_spec().size() > kMaxURLChars) { |
| 166 scoped_ptr<WebServiceWorkerGetRegistrationCallbacks> owned_callbacks( | 165 scoped_ptr<WebServiceWorkerGetRegistrationCallbacks> owned_callbacks( |
| 167 callbacks); | 166 callbacks); |
| 168 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 167 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
| 169 error_message += "The provided documentURL is too long."; | 168 error_message += "The provided documentURL is too long."; |
| 170 callbacks->onError( | 169 callbacks->onError( |
| 171 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 170 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 172 blink::WebString::fromUTF8(error_message))); | 171 blink::WebString::fromUTF8(error_message))); |
| 173 return; | 172 return; |
| 174 } | 173 } |
| 175 | 174 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 return ServiceWorkerRegistrationHandleReference::Adopt( | 769 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 771 info, thread_safe_sender_.get()); | 770 info, thread_safe_sender_.get()); |
| 772 } | 771 } |
| 773 | 772 |
| 774 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 773 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 775 const ServiceWorkerObjectInfo& info) { | 774 const ServiceWorkerObjectInfo& info) { |
| 776 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 775 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 777 } | 776 } |
| 778 | 777 |
| 779 } // namespace content | 778 } // namespace content |
| OLD | NEW |