Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
index c531e915e888504b1396aa27dab35bf4db51b7a3..fb2886b64d7a2f49325fb5d73a7b23a83b4694f3 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
@@ -4,6 +4,7 @@ |
#include "content/browser/service_worker/service_worker_dispatcher_host.h" |
+#include "content/browser/child_process_security_policy_impl.h" |
#include "content/browser/service_worker/service_worker_context.h" |
#include "content/common/service_worker_messages.h" |
#include "ipc/ipc_message_macros.h" |
@@ -12,14 +13,14 @@ |
namespace content { |
ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
+ int render_process_id, |
ServiceWorkerContext* context) |
- : context_(context) {} |
+ : render_process_id_(render_process_id), context_(context) {} |
ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
bool* message_was_ok) { |
- |
if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
return false; |
@@ -36,15 +37,45 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
return handled; |
} |
-void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(int32 registry_id, |
- const string16& scope, |
- const GURL& script_url) { |
- // TODO(alecflett): Enforce that script_url must have the same |
michaeln
2013/10/16 02:03:42
this todo seems important still
|
- // origin as the registering document. |
+// TODO(alecflett): Store the service_worker_id keyed by (domain+pattern, |
+// script) so we don't always return a new service worker id. |
+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.
|
+ static int32 service_worker_id = 0; |
+ return service_worker_id++; |
+} |
+ |
+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.
|
+ int32 thread_id, |
+ int32 request_id, |
+ const GURL& scope, |
+ 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.
|
+ // We're using cookie access as a proxy for ServiceWorker |
+ // registration permission. |
+ // TODO(alecflett): add a ServiceWorker-specific policy query. |
+ ChildProcessSecurityPolicyImpl* policy = |
+ ChildProcessSecurityPolicyImpl::GetInstance(); |
+ 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.
|
+ return; |
+ if (!policy->CanAccessCookiesForOrigin(render_process_id_, script_url)) |
+ return; |
+ |
+ Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
+ thread_id, request_id, NextWorkerId())); |
} |
-void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
- int32 registry_id, |
- const string16& scope) {} |
+void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, |
+ int32 request_id, |
+ const GURL& scope) { |
+ // We're using cookie access as a proxy for ServiceWorker |
+ // registration permission. |
+ // TODO(alecflett): add a ServiceWorker-specific policy query. |
+ ChildProcessSecurityPolicyImpl* policy = |
+ ChildProcessSecurityPolicyImpl::GetInstance(); |
+ if (!policy->CanAccessCookiesForOrigin(render_process_id_, scope)) |
+ return; |
+ |
+ Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( |
+ 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.
|
+} |
} // namespace content |