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" |
michaeln
2014/10/02 20:32:51
This class covers the script accessible reg/unreg/
falken
2014/10/03 08:30:42
Right, I'll try to handle that in a next patch. Th
| |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
11 #include "content/browser/message_port_service.h" | 11 #include "content/browser/message_port_service.h" |
12 #include "content/browser/service_worker/embedded_worker_registry.h" | 12 #include "content/browser/service_worker/embedded_worker_registry.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
15 #include "content/browser/service_worker/service_worker_handle.h" | 15 #include "content/browser/service_worker/service_worker_handle.h" |
16 #include "content/browser/service_worker/service_worker_registration.h" | 16 #include "content/browser/service_worker/service_worker_registration.h" |
17 #include "content/browser/service_worker/service_worker_registration_handle.h" | 17 #include "content/browser/service_worker/service_worker_registration_handle.h" |
18 #include "content/browser/service_worker/service_worker_utils.h" | 18 #include "content/browser/service_worker/service_worker_utils.h" |
19 #include "content/common/service_worker/embedded_worker_messages.h" | 19 #include "content/common/service_worker/embedded_worker_messages.h" |
20 #include "content/common/service_worker/service_worker_messages.h" | 20 #include "content/common/service_worker/service_worker_messages.h" |
21 #include "content/public/browser/content_browser_client.h" | |
22 #include "content/public/common/content_client.h" | |
21 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 24 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
24 | 26 |
25 using blink::WebServiceWorkerError; | 27 using blink::WebServiceWorkerError; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 const char kShutdownErrorMessage[] = | 33 const char kShutdownErrorMessage[] = |
32 "The Service Worker system has shutdown."; | 34 "The Service Worker system has shutdown."; |
35 const char kDisabledErrorMessage[] = "The browser has disabled Service Worker."; | |
33 | 36 |
34 const uint32 kFilteredMessageClasses[] = { | 37 const uint32 kFilteredMessageClasses[] = { |
35 ServiceWorkerMsgStart, | 38 ServiceWorkerMsgStart, |
36 EmbeddedWorkerMsgStart, | 39 EmbeddedWorkerMsgStart, |
37 }; | 40 }; |
38 | 41 |
39 // TODO(dominicc): When crbug.com/362214 is fixed, make | 42 // TODO(dominicc): When crbug.com/362214 is fixed, make |
40 // Can(R|Unr)egisterServiceWorker also check that these are secure | 43 // Can(R|Unr)egisterServiceWorker also check that these are secure |
41 // origins to defend against compromised renderers. | 44 // origins to defend against compromised renderers. |
42 bool CanRegisterServiceWorker(const GURL& document_url, | 45 bool CanRegisterServiceWorker(const GURL& document_url, |
43 const GURL& pattern, | 46 const GURL& pattern, |
44 const GURL& script_url) { | 47 const GURL& script_url) { |
45 // TODO: Respect Chrome's content settings, if we add a setting for | |
46 // controlling whether Service Worker is allowed. | |
falken
2014/10/02 09:51:42
Doing the check here would kill the renderer if th
michaeln
2014/10/02 20:32:51
i remember when these methods were originally adde
falken
2014/10/03 08:30:42
Acknowledged. Now it's doing a bit more, checking
| |
47 return document_url.GetOrigin() == pattern.GetOrigin() && | 48 return document_url.GetOrigin() == pattern.GetOrigin() && |
48 document_url.GetOrigin() == script_url.GetOrigin(); | 49 document_url.GetOrigin() == script_url.GetOrigin(); |
49 } | 50 } |
50 | 51 |
51 bool CanUnregisterServiceWorker(const GURL& document_url, | 52 bool CanUnregisterServiceWorker(const GURL& document_url, |
52 const GURL& pattern) { | 53 const GURL& pattern) { |
53 // TODO: Respect Chrome's content settings, if we add a setting for | |
54 // controlling whether Service Worker is allowed. | |
55 return document_url.GetOrigin() == pattern.GetOrigin(); | 54 return document_url.GetOrigin() == pattern.GetOrigin(); |
56 } | 55 } |
57 | 56 |
58 bool CanGetRegistration(const GURL& document_url, | 57 bool CanGetRegistration(const GURL& document_url, |
59 const GURL& given_document_url) { | 58 const GURL& given_document_url) { |
60 // TODO: Respect Chrome's content settings, if we add a setting for | |
61 // controlling whether Service Worker is allowed. | |
falken
2014/10/02 09:51:42
Even if cookies are blocked/service worker is disa
michaeln
2014/10/02 20:32:51
That's not consistent with how cookies or other th
falken
2014/10/03 08:30:42
OK, makes sense. Done.
| |
62 return document_url.GetOrigin() == given_document_url.GetOrigin(); | 59 return document_url.GetOrigin() == given_document_url.GetOrigin(); |
63 } | 60 } |
64 | 61 |
65 } // namespace | 62 } // namespace |
66 | 63 |
67 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 64 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
68 int render_process_id, | 65 int render_process_id, |
69 MessagePortMessageFilter* message_port_message_filter) | 66 MessagePortMessageFilter* message_port_message_filter, |
67 ResourceContext* resource_context) | |
70 : BrowserMessageFilter(kFilteredMessageClasses, | 68 : BrowserMessageFilter(kFilteredMessageClasses, |
71 arraysize(kFilteredMessageClasses)), | 69 arraysize(kFilteredMessageClasses)), |
72 render_process_id_(render_process_id), | 70 render_process_id_(render_process_id), |
73 message_port_message_filter_(message_port_message_filter), | 71 message_port_message_filter_(message_port_message_filter), |
72 resource_context_(resource_context), | |
74 channel_ready_(false) { | 73 channel_ready_(false) { |
75 } | 74 } |
76 | 75 |
77 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { | 76 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { |
78 if (GetContext()) { | 77 if (GetContext()) { |
79 GetContext()->RemoveAllProviderHostsForProcess(render_process_id_); | 78 GetContext()->RemoveAllProviderHostsForProcess(render_process_id_); |
80 GetContext()->embedded_worker_registry()->RemoveChildProcessSender( | 79 GetContext()->embedded_worker_registry()->RemoveChildProcessSender( |
81 render_process_id_); | 80 render_process_id_); |
82 } | 81 } |
83 } | 82 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 WebServiceWorkerError::ErrorTypeAbort, | 238 WebServiceWorkerError::ErrorTypeAbort, |
240 base::ASCIIToUTF16(kShutdownErrorMessage))); | 239 base::ASCIIToUTF16(kShutdownErrorMessage))); |
241 return; | 240 return; |
242 } | 241 } |
243 | 242 |
244 if (!CanRegisterServiceWorker( | 243 if (!CanRegisterServiceWorker( |
245 provider_host->document_url(), pattern, script_url)) { | 244 provider_host->document_url(), pattern, script_url)) { |
246 BadMessageReceived(); | 245 BadMessageReceived(); |
247 return; | 246 return; |
248 } | 247 } |
248 | |
249 if (!GetContentClient()->browser()->AllowServiceWorker( | |
250 pattern, provider_host->document_url(), resource_context_)) { | |
251 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | |
252 thread_id, | |
253 request_id, | |
254 WebServiceWorkerError::ErrorTypeDisabled, | |
255 base::ASCIIToUTF16(kDisabledErrorMessage))); | |
256 return; | |
257 } | |
258 | |
249 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 259 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
250 "ServiceWorkerDispatcherHost::RegisterServiceWorker", | 260 "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
251 request_id, | 261 request_id, |
252 "Pattern", pattern.spec(), | 262 "Pattern", pattern.spec(), |
253 "Script URL", script_url.spec()); | 263 "Script URL", script_url.spec()); |
254 GetContext()->RegisterServiceWorker( | 264 GetContext()->RegisterServiceWorker( |
255 pattern, | 265 pattern, |
256 script_url, | 266 script_url, |
257 provider_host, | 267 provider_host, |
258 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 268 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 blink::WebServiceWorkerError::ErrorTypeAbort, | 301 blink::WebServiceWorkerError::ErrorTypeAbort, |
292 base::ASCIIToUTF16(kShutdownErrorMessage))); | 302 base::ASCIIToUTF16(kShutdownErrorMessage))); |
293 return; | 303 return; |
294 } | 304 } |
295 | 305 |
296 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { | 306 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { |
297 BadMessageReceived(); | 307 BadMessageReceived(); |
298 return; | 308 return; |
299 } | 309 } |
300 | 310 |
311 if (!GetContentClient()->browser()->AllowServiceWorker( | |
312 pattern, provider_host->document_url(), resource_context_)) { | |
313 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | |
314 thread_id, | |
315 request_id, | |
316 WebServiceWorkerError::ErrorTypeDisabled, | |
317 base::ASCIIToUTF16(kDisabledErrorMessage))); | |
318 return; | |
319 } | |
320 | |
301 TRACE_EVENT_ASYNC_BEGIN1( | 321 TRACE_EVENT_ASYNC_BEGIN1( |
302 "ServiceWorker", | 322 "ServiceWorker", |
303 "ServiceWorkerDispatcherHost::UnregisterServiceWorker", | 323 "ServiceWorkerDispatcherHost::UnregisterServiceWorker", |
304 request_id, | 324 request_id, |
305 "Pattern", pattern.spec()); | 325 "Pattern", pattern.spec()); |
306 GetContext()->UnregisterServiceWorker( | 326 GetContext()->UnregisterServiceWorker( |
307 pattern, | 327 pattern, |
308 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, | 328 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, |
309 this, | 329 this, |
310 thread_id, | 330 thread_id, |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 status, &error_type, &error_message); | 770 status, &error_type, &error_message); |
751 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 771 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
752 thread_id, request_id, error_type, error_message)); | 772 thread_id, request_id, error_type, error_message)); |
753 } | 773 } |
754 | 774 |
755 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 775 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
756 return context_wrapper_->context(); | 776 return context_wrapper_->context(); |
757 } | 777 } |
758 | 778 |
759 } // namespace content | 779 } // namespace content |
OLD | NEW |