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 "content/browser/child_process_security_policy_impl.h" | |
7 #include "content/browser/service_worker/service_worker_context.h" | 8 #include "content/browser/service_worker/service_worker_context.h" |
8 #include "content/common/service_worker_messages.h" | 9 #include "content/common/service_worker_messages.h" |
9 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 15 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
16 int render_process_id, | |
15 ServiceWorkerContext* context) | 17 ServiceWorkerContext* context) |
16 : context_(context) {} | 18 : render_process_id_(render_process_id), context_(context) {} |
17 | 19 |
18 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} | 20 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
19 | 21 |
20 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, | 22 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
21 bool* message_was_ok) { | 23 bool* message_was_ok) { |
22 | |
23 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) | 24 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
24 return false; | 25 return false; |
25 | 26 |
26 bool handled = true; | 27 bool handled = true; |
27 IPC_BEGIN_MESSAGE_MAP_EX( | 28 IPC_BEGIN_MESSAGE_MAP_EX( |
28 ServiceWorkerDispatcherHost, message, *message_was_ok) | 29 ServiceWorkerDispatcherHost, message, *message_was_ok) |
29 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 30 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
30 OnRegisterServiceWorker) | 31 OnRegisterServiceWorker) |
31 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 32 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
32 OnUnregisterServiceWorker) | 33 OnUnregisterServiceWorker) |
33 IPC_MESSAGE_UNHANDLED(handled = false) | 34 IPC_MESSAGE_UNHANDLED(handled = false) |
34 IPC_END_MESSAGE_MAP() | 35 IPC_END_MESSAGE_MAP() |
35 | 36 |
36 return handled; | 37 return handled; |
37 } | 38 } |
38 | 39 |
39 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(int32 registry_id, | 40 // TODO(alecflett): Store the service_worker_id keyed by (domain+pattern, |
40 const string16& scope, | 41 // script) so we don't always return a new service worker id. |
41 const GURL& script_url) { | 42 static int32 NextWorkerId() { |
michaeln
2013/10/16 02:03:42
I propose we use int64 bit IDs to identify registe
alecflett
2013/10/23 20:43:17
Done.
| |
42 // TODO(alecflett): Enforce that script_url must have the same | 43 static int32 service_worker_id = 0; |
michaeln
2013/10/16 02:03:42
this todo seems important still
| |
43 // origin as the registering document. | 44 return service_worker_id++; |
44 } | 45 } |
45 | 46 |
46 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 47 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
michaeln
2013/10/16 02:03:42
I think goals for this method at this time are pri
alecflett
2013/10/23 20:43:17
Except for origin mismatch, so adding that now.
| |
47 int32 registry_id, | 48 int32 thread_id, |
48 const string16& scope) {} | 49 int32 request_id, |
50 const GURL& scope, | |
51 const GURL& script_url) { | |
michaeln
2013/10/16 02:03:42
I think there's a requirement that 'scope' and 'sc
alecflett
2013/10/23 20:43:17
Done.
| |
52 // We're using cookie access as a proxy for ServiceWorker | |
53 // registration permission. | |
54 // TODO(alecflett): add a ServiceWorker-specific policy query. | |
55 ChildProcessSecurityPolicyImpl* policy = | |
56 ChildProcessSecurityPolicyImpl::GetInstance(); | |
57 if (!policy->CanAccessCookiesForOrigin(render_process_id_, scope)) | |
michaeln
2013/10/16 02:03:42
I'd actually like to define a policy interface her
alecflett
2013/10/23 20:43:17
Done. Adding a TODO.
| |
58 return; | |
59 if (!policy->CanAccessCookiesForOrigin(render_process_id_, script_url)) | |
60 return; | |
61 | |
62 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | |
63 thread_id, request_id, NextWorkerId())); | |
64 } | |
65 | |
66 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, | |
67 int32 request_id, | |
68 const GURL& scope) { | |
69 // We're using cookie access as a proxy for ServiceWorker | |
70 // registration permission. | |
71 // TODO(alecflett): add a ServiceWorker-specific policy query. | |
72 ChildProcessSecurityPolicyImpl* policy = | |
73 ChildProcessSecurityPolicyImpl::GetInstance(); | |
74 if (!policy->CanAccessCookiesForOrigin(render_process_id_, scope)) | |
75 return; | |
76 | |
77 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( | |
78 thread_id, request_id, NextWorkerId())); | |
michaeln
2013/10/16 02:03:42
I still don't understand the intent of returning t
alecflett
2013/10/23 20:43:17
removed.
| |
79 } | |
49 | 80 |
50 } // namespace content | 81 } // namespace content |
OLD | NEW |