Chromium Code Reviews| 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/service_worker/service_worker_context.h" | 7 #include "content/browser/service_worker/service_worker_context.h" |
| 8 #include "content/common/service_worker_messages.h" | 8 #include "content/common/service_worker_messages.h" |
| 9 #include "ipc/ipc_message_macros.h" | 9 #include "ipc/ipc_message_macros.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 14 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| 15 int render_process_id, | |
| 15 ServiceWorkerContext* context) | 16 ServiceWorkerContext* context) |
| 16 : context_(context) {} | 17 : render_process_id_(render_process_id), context_(context) {} |
| 17 | 18 |
| 18 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} | 19 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
| 19 | 20 |
| 20 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, | 21 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 21 bool* message_was_ok) { | 22 bool* message_was_ok) { |
| 22 | |
| 23 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) | 23 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
| 24 return false; | 24 return false; |
| 25 | 25 |
| 26 bool handled = true; | 26 bool handled = true; |
| 27 IPC_BEGIN_MESSAGE_MAP_EX( | 27 IPC_BEGIN_MESSAGE_MAP_EX( |
| 28 ServiceWorkerDispatcherHost, message, *message_was_ok) | 28 ServiceWorkerDispatcherHost, message, *message_was_ok) |
| 29 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 29 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| 30 OnRegisterServiceWorker) | 30 OnRegisterServiceWorker) |
| 31 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 31 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| 32 OnUnregisterServiceWorker) | 32 OnUnregisterServiceWorker) |
| 33 IPC_MESSAGE_UNHANDLED(handled = false) | 33 IPC_MESSAGE_UNHANDLED(handled = false) |
| 34 IPC_END_MESSAGE_MAP() | 34 IPC_END_MESSAGE_MAP() |
| 35 | 35 |
| 36 return handled; | 36 return handled; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(int32 registry_id, | 39 // TODO(alecflett): Store the service_worker_id keyed by (domain+pattern, |
| 40 const string16& scope, | 40 // script) so we don't always return a new service worker id. |
| 41 const GURL& script_url) { | 41 static int64 NextWorkerId() { |
| 42 // TODO(alecflett): Enforce that script_url must have the same | 42 static int64 service_worker_id = 0; |
| 43 // origin as the registering document. | 43 return service_worker_id++; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 46 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| 47 int32 registry_id, | 47 int32 thread_id, |
| 48 const string16& scope) {} | 48 int32 request_id, |
| 49 const GURL& scope, | |
| 50 const GURL& script_url) { | |
| 51 // TODO(alecflett): add a ServiceWorker-specific policy query in | |
|
Tom Sepez
2013/10/24 23:25:52
Please file a follow-up bug for this and link it h
alecflett
2013/10/25 18:22:50
Done.
| |
| 52 // ChildProcessSecurityImpl. | |
| 53 | |
| 54 // TODO(alecflett): Throw an error for origin mismatch, rather than | |
| 55 // just returning. | |
| 56 if (scope.GetOrigin() != script_url.GetOrigin()) | |
| 57 return; | |
| 58 | |
| 59 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | |
| 60 thread_id, request_id, NextWorkerId())); | |
| 61 } | |
| 62 | |
| 63 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, | |
| 64 int32 request_id, | |
| 65 const GURL& scope) { | |
| 66 // TODO(alecflett): add a ServiceWorker-specific policy query in | |
| 67 // ChildProcessSecurityImpl. | |
| 68 | |
| 69 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( | |
| 70 thread_id, request_id)); | |
| 71 } | |
| 49 | 72 |
| 50 } // namespace content | 73 } // namespace content |
| OLD | NEW |