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" |
28 | 29 |
29 using blink::WebServiceWorkerError; | 30 using blink::WebServiceWorkerError; |
30 using blink::WebServiceWorkerProvider; | 31 using blink::WebServiceWorkerProvider; |
31 using base::ThreadLocalPointer; | 32 using base::ThreadLocalPointer; |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 base::LazyInstance<ThreadLocalPointer<void>>::Leaky g_dispatcher_tls = | 38 base::LazyInstance<ThreadLocalPointer<void>>::Leaky g_dispatcher_tls = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 DCHECK(handled) << "Unhandled message:" << msg.type(); | 104 DCHECK(handled) << "Unhandled message:" << msg.type(); |
104 } | 105 } |
105 | 106 |
106 void ServiceWorkerDispatcher::RegisterServiceWorker( | 107 void ServiceWorkerDispatcher::RegisterServiceWorker( |
107 int provider_id, | 108 int provider_id, |
108 const GURL& pattern, | 109 const GURL& pattern, |
109 const GURL& script_url, | 110 const GURL& script_url, |
110 WebServiceWorkerRegistrationCallbacks* callbacks) { | 111 WebServiceWorkerRegistrationCallbacks* callbacks) { |
111 DCHECK(callbacks); | 112 DCHECK(callbacks); |
112 | 113 |
113 if (pattern.possibly_invalid_spec().size() > kMaxURLChars || | 114 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || |
114 script_url.possibly_invalid_spec().size() > kMaxURLChars) { | 115 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
115 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 116 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
116 owned_callbacks(callbacks); | 117 owned_callbacks(callbacks); |
117 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 118 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
118 error_message += "The provided scriptURL or scope is too long."; | 119 error_message += "The provided scriptURL or scope is too long."; |
119 callbacks->onError( | 120 callbacks->onError( |
120 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 121 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
121 blink::WebString::fromUTF8(error_message))); | 122 blink::WebString::fromUTF8(error_message))); |
122 return; | 123 return; |
123 } | 124 } |
124 | 125 |
(...skipping 29 matching lines...) Expand all Loading... |
154 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 155 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
155 CurrentWorkerId(), request_id, provider_id, registration_id)); | 156 CurrentWorkerId(), request_id, provider_id, registration_id)); |
156 } | 157 } |
157 | 158 |
158 void ServiceWorkerDispatcher::GetRegistration( | 159 void ServiceWorkerDispatcher::GetRegistration( |
159 int provider_id, | 160 int provider_id, |
160 const GURL& document_url, | 161 const GURL& document_url, |
161 WebServiceWorkerGetRegistrationCallbacks* callbacks) { | 162 WebServiceWorkerGetRegistrationCallbacks* callbacks) { |
162 DCHECK(callbacks); | 163 DCHECK(callbacks); |
163 | 164 |
164 if (document_url.possibly_invalid_spec().size() > kMaxURLChars) { | 165 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
165 scoped_ptr<WebServiceWorkerGetRegistrationCallbacks> owned_callbacks( | 166 scoped_ptr<WebServiceWorkerGetRegistrationCallbacks> owned_callbacks( |
166 callbacks); | 167 callbacks); |
167 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 168 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
168 error_message += "The provided documentURL is too long."; | 169 error_message += "The provided documentURL is too long."; |
169 callbacks->onError( | 170 callbacks->onError( |
170 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 171 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
171 blink::WebString::fromUTF8(error_message))); | 172 blink::WebString::fromUTF8(error_message))); |
172 return; | 173 return; |
173 } | 174 } |
174 | 175 |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 return ServiceWorkerRegistrationHandleReference::Adopt( | 770 return ServiceWorkerRegistrationHandleReference::Adopt( |
770 info, thread_safe_sender_.get()); | 771 info, thread_safe_sender_.get()); |
771 } | 772 } |
772 | 773 |
773 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 774 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
774 const ServiceWorkerObjectInfo& info) { | 775 const ServiceWorkerObjectInfo& info) { |
775 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 776 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
776 } | 777 } |
777 | 778 |
778 } // namespace content | 779 } // namespace content |
OLD | NEW |