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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
7 #include "content/browser/service_worker/service_worker_context.h"
8 #include "content/common/service_worker_messages.h"
9 #include "ipc/ipc_message_macros.h"
14 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
15 int render_process_id,
16 ServiceWorkerContext* context) : context_(context) {}
18 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {}
20 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message,
21 bool* message_was_ok) {
22 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart)
26 IPC_BEGIN_MESSAGE_MAP_EX(
27 ServiceWorkerDispatcherHost, message, *message_was_ok)
28 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
29 OnRegisterServiceWorker)
30 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
31 OnUnregisterServiceWorker)
32 IPC_MESSAGE_UNHANDLED(handled = false)
38 // TODO(alecflett): Store the service_worker_id keyed by (domain+pattern,
39 // script) so we don't always return a new service worker id.
40 static int64 NextWorkerId() {
41 static int64 service_worker_id = 0;
42 return service_worker_id++;
45 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
49 const GURL& script_url) {
50 // TODO(alecflett): add a ServiceWorker-specific policy query in
51 // ChildProcessSecurityImpl. See http://crbug.com/311631.
53 // TODO(alecflett): Throw an error for origin mismatch, rather than
55 if (scope.GetOrigin() != script_url.GetOrigin())
58 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
59 thread_id, request_id, NextWorkerId()));
62 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id,
65 // TODO(alecflett): add a ServiceWorker-specific policy query in
66 // ChildProcessSecurityImpl. See http://crbug.com/311631.
68 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
71 } // namespace content