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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
11 #include "content/child/child_thread.h" | 11 #include "content/child/child_thread.h" |
12 #include "content/child/service_worker/service_worker_handle_reference.h" | 12 #include "content/child/service_worker/service_worker_handle_reference.h" |
13 #include "content/child/service_worker/service_worker_provider_context.h" | 13 #include "content/child/service_worker/service_worker_provider_context.h" |
14 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 14 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
15 #include "content/child/service_worker/web_service_worker_impl.h" | 15 #include "content/child/service_worker/web_service_worker_impl.h" |
16 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 16 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
17 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
18 #include "content/child/webmessageportchannel_impl.h" | 18 #include "content/child/webmessageportchannel_impl.h" |
19 #include "content/common/service_worker/service_worker_messages.h" | 19 #include "content/common/service_worker/service_worker_messages.h" |
| 20 #include "content/common/service_worker/service_worker_types.h" |
20 #include "content/public/common/url_utils.h" | 21 #include "content/public/common/url_utils.h" |
21 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" | 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" |
| 24 #include "third_party/WebKit/public/platform/WebString.h" |
23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 25 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
24 | 26 |
25 using blink::WebServiceWorkerError; | 27 using blink::WebServiceWorkerError; |
26 using blink::WebServiceWorkerProvider; | 28 using blink::WebServiceWorkerProvider; |
27 using base::ThreadLocalPointer; | 29 using base::ThreadLocalPointer; |
28 | 30 |
29 namespace content { | 31 namespace content { |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 int provider_id, | 97 int provider_id, |
96 const GURL& pattern, | 98 const GURL& pattern, |
97 const GURL& script_url, | 99 const GURL& script_url, |
98 WebServiceWorkerRegistrationCallbacks* callbacks) { | 100 WebServiceWorkerRegistrationCallbacks* callbacks) { |
99 DCHECK(callbacks); | 101 DCHECK(callbacks); |
100 | 102 |
101 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || | 103 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || |
102 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 104 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
103 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 105 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
104 owned_callbacks(callbacks); | 106 owned_callbacks(callbacks); |
105 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 107 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
106 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 108 error_message += "The provided scriptURL or scope is too long."; |
| 109 scoped_ptr<WebServiceWorkerError> error( |
| 110 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 111 blink::WebString::fromUTF8(error_message))); |
107 callbacks->onError(error.release()); | 112 callbacks->onError(error.release()); |
108 return; | 113 return; |
109 } | 114 } |
110 | 115 |
111 int request_id = pending_registration_callbacks_.Add(callbacks); | 116 int request_id = pending_registration_callbacks_.Add(callbacks); |
112 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 117 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
113 "ServiceWorkerDispatcher::RegisterServiceWorker", | 118 "ServiceWorkerDispatcher::RegisterServiceWorker", |
114 request_id, | 119 request_id, |
115 "Scope", pattern.spec(), | 120 "Scope", pattern.spec(), |
116 "Script URL", script_url.spec()); | 121 "Script URL", script_url.spec()); |
117 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 122 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
118 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 123 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
119 } | 124 } |
120 | 125 |
121 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 126 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
122 int provider_id, | 127 int provider_id, |
123 const GURL& pattern, | 128 const GURL& pattern, |
124 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 129 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
125 DCHECK(callbacks); | 130 DCHECK(callbacks); |
126 | 131 |
127 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 132 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
128 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> | 133 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
129 owned_callbacks(callbacks); | 134 owned_callbacks(callbacks); |
130 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 135 std::string error_message(kServiceWorkerUnregisterErrorPrefix); |
131 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 136 error_message += "The provided scope is too long."; |
| 137 scoped_ptr<WebServiceWorkerError> error( |
| 138 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 139 blink::WebString::fromUTF8(error_message))); |
132 callbacks->onError(error.release()); | 140 callbacks->onError(error.release()); |
133 return; | 141 return; |
134 } | 142 } |
135 | 143 |
136 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 144 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
137 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 145 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
138 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 146 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
139 request_id, | 147 request_id, |
140 "Scope", pattern.spec()); | 148 "Scope", pattern.spec()); |
141 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 149 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
142 CurrentWorkerId(), request_id, provider_id, pattern)); | 150 CurrentWorkerId(), request_id, provider_id, pattern)); |
143 } | 151 } |
144 | 152 |
145 void ServiceWorkerDispatcher::GetRegistration( | 153 void ServiceWorkerDispatcher::GetRegistration( |
146 int provider_id, | 154 int provider_id, |
147 const GURL& document_url, | 155 const GURL& document_url, |
148 WebServiceWorkerRegistrationCallbacks* callbacks) { | 156 WebServiceWorkerRegistrationCallbacks* callbacks) { |
149 DCHECK(callbacks); | 157 DCHECK(callbacks); |
150 | 158 |
151 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 159 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
152 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 160 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
153 owned_callbacks(callbacks); | 161 owned_callbacks(callbacks); |
154 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 162 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
155 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 163 error_message += "The provided documentURL is too long."; |
| 164 scoped_ptr<WebServiceWorkerError> error( |
| 165 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 166 blink::WebString::fromUTF8(error_message))); |
156 callbacks->onError(error.release()); | 167 callbacks->onError(error.release()); |
157 return; | 168 return; |
158 } | 169 } |
159 | 170 |
160 int request_id = pending_get_registration_callbacks_.Add(callbacks); | 171 int request_id = pending_get_registration_callbacks_.Add(callbacks); |
161 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 172 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
162 "ServiceWorkerDispatcher::GetRegistration", | 173 "ServiceWorkerDispatcher::GetRegistration", |
163 request_id, | 174 request_id, |
164 "Document URL", document_url.spec()); | 175 "Document URL", document_url.spec()); |
165 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 176 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 attrs.installing, thread_safe_sender_.get()); | 747 attrs.installing, thread_safe_sender_.get()); |
737 ServiceWorkerHandleReference::Adopt( | 748 ServiceWorkerHandleReference::Adopt( |
738 attrs.waiting, thread_safe_sender_.get()); | 749 attrs.waiting, thread_safe_sender_.get()); |
739 ServiceWorkerHandleReference::Adopt( | 750 ServiceWorkerHandleReference::Adopt( |
740 attrs.active, thread_safe_sender_.get()); | 751 attrs.active, thread_safe_sender_.get()); |
741 } | 752 } |
742 return registration; | 753 return registration; |
743 } | 754 } |
744 | 755 |
745 } // namespace content | 756 } // namespace content |
OLD | NEW |