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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
11 #include "content/browser/service_worker/embedded_worker_registry.h" | 11 #include "content/browser/service_worker/embedded_worker_registry.h" |
12 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
14 #include "content/browser/service_worker/service_worker_handle.h" | 14 #include "content/browser/service_worker/service_worker_handle.h" |
15 #include "content/browser/service_worker/service_worker_registration.h" | 15 #include "content/browser/service_worker/service_worker_registration.h" |
16 #include "content/browser/service_worker/service_worker_utils.h" | 16 #include "content/browser/service_worker/service_worker_utils.h" |
17 #include "content/common/service_worker/embedded_worker_messages.h" | 17 #include "content/common/service_worker/embedded_worker_messages.h" |
18 #include "content/common/service_worker/service_worker_messages.h" | 18 #include "content/common/service_worker/service_worker_messages.h" |
19 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
20 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 20 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 using blink::WebServiceWorkerError; | 23 using blink::WebServiceWorkerError; |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kDisabledErrorMessage[] = | 29 const char kShutdownErrorMessage[] = |
30 "ServiceWorker is disabled"; | 30 "The Service Worker system has shutdown."; |
31 const char kDomainMismatchErrorMessage[] = | 31 const char kDomainMismatchErrorMessage[] = |
32 "Scope and scripts do not have the same origin"; | 32 "Scope and scripts do not have the same origin"; |
33 | 33 |
34 const uint32 kFilteredMessageClasses[] = { | 34 const uint32 kFilteredMessageClasses[] = { |
35 ServiceWorkerMsgStart, | 35 ServiceWorkerMsgStart, |
36 EmbeddedWorkerMsgStart, | 36 EmbeddedWorkerMsgStart, |
37 }; | 37 }; |
38 | 38 |
39 bool CanRegisterServiceWorker(const GURL& document_url, | 39 bool CanRegisterServiceWorker(const GURL& document_url, |
40 const GURL& pattern, | 40 const GURL& pattern, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 int handle_id = handle->handle_id(); | 161 int handle_id = handle->handle_id(); |
162 handles_.AddWithID(handle.release(), handle_id); | 162 handles_.AddWithID(handle.release(), handle_id); |
163 } | 163 } |
164 | 164 |
165 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 165 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
166 int thread_id, | 166 int thread_id, |
167 int request_id, | 167 int request_id, |
168 int provider_id, | 168 int provider_id, |
169 const GURL& pattern, | 169 const GURL& pattern, |
170 const GURL& script_url) { | 170 const GURL& script_url) { |
171 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) { | 171 if (!GetContext()) { |
172 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 172 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
173 thread_id, | 173 thread_id, |
174 request_id, | 174 request_id, |
175 WebServiceWorkerError::ErrorTypeDisabled, | 175 WebServiceWorkerError::ErrorTypeAbort, |
176 base::ASCIIToUTF16(kDisabledErrorMessage))); | 176 base::ASCIIToUTF16(kShutdownErrorMessage))); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 180 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
181 render_process_id_, provider_id); | 181 render_process_id_, provider_id); |
182 if (!provider_host) { | 182 if (!provider_host) { |
183 BadMessageReceived(); | 183 BadMessageReceived(); |
184 return; | 184 return; |
185 } | 185 } |
186 if (!provider_host->IsContextAlive()) { | 186 if (!provider_host->IsContextAlive()) { |
187 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 187 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
188 thread_id, | 188 thread_id, |
189 request_id, | 189 request_id, |
190 WebServiceWorkerError::ErrorTypeDisabled, | 190 WebServiceWorkerError::ErrorTypeAbort, |
191 base::ASCIIToUTF16(kDisabledErrorMessage))); | 191 base::ASCIIToUTF16(kShutdownErrorMessage))); |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 if (!CanRegisterServiceWorker( | 195 if (!CanRegisterServiceWorker( |
196 provider_host->document_url(), pattern, script_url)) { | 196 provider_host->document_url(), pattern, script_url)) { |
197 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 197 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
198 thread_id, | 198 thread_id, |
199 request_id, | 199 request_id, |
200 WebServiceWorkerError::ErrorTypeSecurity, | 200 WebServiceWorkerError::ErrorTypeSecurity, |
201 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); | 201 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); |
202 return; | 202 return; |
203 } | 203 } |
204 GetContext()->RegisterServiceWorker( | 204 GetContext()->RegisterServiceWorker( |
205 pattern, | 205 pattern, |
206 script_url, | 206 script_url, |
207 render_process_id_, | 207 render_process_id_, |
208 provider_host, | 208 provider_host, |
209 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 209 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
210 this, | 210 this, |
211 thread_id, | 211 thread_id, |
212 request_id)); | 212 request_id)); |
213 } | 213 } |
214 | 214 |
215 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 215 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
216 int thread_id, | 216 int thread_id, |
217 int request_id, | 217 int request_id, |
218 int provider_id, | 218 int provider_id, |
219 const GURL& pattern) { | 219 const GURL& pattern) { |
220 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) { | 220 if (!GetContext()) { |
221 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 221 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
222 thread_id, | 222 thread_id, |
223 request_id, | 223 request_id, |
224 blink::WebServiceWorkerError::ErrorTypeDisabled, | 224 blink::WebServiceWorkerError::ErrorTypeAbort, |
225 base::ASCIIToUTF16(kDisabledErrorMessage))); | 225 base::ASCIIToUTF16(kShutdownErrorMessage))); |
226 return; | 226 return; |
227 } | 227 } |
228 | 228 |
229 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 229 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
230 render_process_id_, provider_id); | 230 render_process_id_, provider_id); |
231 if (!provider_host) { | 231 if (!provider_host) { |
232 BadMessageReceived(); | 232 BadMessageReceived(); |
233 return; | 233 return; |
234 } | 234 } |
235 if (!provider_host->IsContextAlive()) { | 235 if (!provider_host->IsContextAlive()) { |
236 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 236 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
237 thread_id, | 237 thread_id, |
238 request_id, | 238 request_id, |
239 blink::WebServiceWorkerError::ErrorTypeDisabled, | 239 blink::WebServiceWorkerError::ErrorTypeAbort, |
240 base::ASCIIToUTF16(kDisabledErrorMessage))); | 240 base::ASCIIToUTF16(kShutdownErrorMessage))); |
241 return; | 241 return; |
242 } | 242 } |
243 | 243 |
244 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { | 244 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { |
245 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 245 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
246 thread_id, | 246 thread_id, |
247 request_id, | 247 request_id, |
248 WebServiceWorkerError::ErrorTypeSecurity, | 248 WebServiceWorkerError::ErrorTypeSecurity, |
249 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); | 249 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 GetContext()->UnregisterServiceWorker( | 253 GetContext()->UnregisterServiceWorker( |
254 pattern, | 254 pattern, |
255 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, | 255 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, |
256 this, | 256 this, |
257 thread_id, | 257 thread_id, |
258 request_id)); | 258 request_id)); |
259 } | 259 } |
260 | 260 |
261 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 261 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
262 int handle_id, | 262 int handle_id, |
263 const base::string16& message, | 263 const base::string16& message, |
264 const std::vector<int>& sent_message_port_ids) { | 264 const std::vector<int>& sent_message_port_ids) { |
265 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) | 265 if (!GetContext()) |
266 return; | 266 return; |
267 | 267 |
268 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 268 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
269 if (!handle) { | 269 if (!handle) { |
270 BadMessageReceived(); | 270 BadMessageReceived(); |
271 return; | 271 return; |
272 } | 272 } |
273 | 273 |
274 std::vector<int> new_routing_ids; | 274 std::vector<int> new_routing_ids; |
275 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( | 275 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 status, &error_type, &error_message); | 452 status, &error_type, &error_message); |
453 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 453 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
454 thread_id, request_id, error_type, error_message)); | 454 thread_id, request_id, error_type, error_message)); |
455 } | 455 } |
456 | 456 |
457 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 457 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
458 return context_wrapper_->context(); | 458 return context_wrapper_->context(); |
459 } | 459 } |
460 | 460 |
461 } // namespace content | 461 } // namespace content |
OLD | NEW |