| 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 "base/strings/utf_string_conversions.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" |
| 11 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| 10 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 11 | 13 |
| 14 using WebKit::WebServiceWorkerError; |
| 15 |
| 12 namespace content { | 16 namespace content { |
| 13 | 17 |
| 14 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 18 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| 15 int render_process_id, | 19 int render_process_id, |
| 16 ServiceWorkerContext* context) | 20 ServiceWorkerContext* context) |
| 17 : render_process_id_(render_process_id), context_(context) {} | 21 : render_process_id_(render_process_id), context_(context) {} |
| 18 | 22 |
| 19 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} | 23 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
| 20 | 24 |
| 25 namespace { |
| 26 const char kDomainMismatchErrorMessage[] = |
| 27 "Scope and scripts do not have the same origin"; |
| 28 } |
| 29 |
| 21 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, | 30 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 22 bool* message_was_ok) { | 31 bool* message_was_ok) { |
| 23 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) | 32 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
| 24 return false; | 33 return false; |
| 25 | 34 |
| 26 bool handled = true; | 35 bool handled = true; |
| 27 IPC_BEGIN_MESSAGE_MAP_EX( | 36 IPC_BEGIN_MESSAGE_MAP_EX( |
| 28 ServiceWorkerDispatcherHost, message, *message_was_ok) | 37 ServiceWorkerDispatcherHost, message, *message_was_ok) |
| 29 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 38 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| 30 OnRegisterServiceWorker) | 39 OnRegisterServiceWorker) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 static int64 NextWorkerId() { | 50 static int64 NextWorkerId() { |
| 42 static int64 service_worker_id = 0; | 51 static int64 service_worker_id = 0; |
| 43 return service_worker_id++; | 52 return service_worker_id++; |
| 44 } | 53 } |
| 45 | 54 |
| 46 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 55 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| 47 int32 thread_id, | 56 int32 thread_id, |
| 48 int32 request_id, | 57 int32 request_id, |
| 49 const GURL& scope, | 58 const GURL& scope, |
| 50 const GURL& script_url) { | 59 const GURL& script_url) { |
| 51 // TODO(alecflett): add a ServiceWorker-specific policy query in | 60 if (!context_->enabled()) { |
| 61 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 62 thread_id, |
| 63 request_id, |
| 64 WebKit::WebServiceWorkerError::DisabledError, |
| 65 ASCIIToUTF16("ServiceWorker is disabled"))); |
| 66 return; |
| 67 } |
| 68 |
| 69 // TODO(alecflett): This check is insufficient for release. Add a |
| 70 // ServiceWorker-specific policy query in |
| 52 // ChildProcessSecurityImpl. See http://crbug.com/311631. | 71 // ChildProcessSecurityImpl. See http://crbug.com/311631. |
| 53 | 72 if (scope.GetOrigin() != script_url.GetOrigin()) { |
| 54 // TODO(alecflett): Throw an error for origin mismatch, rather than | 73 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 55 // just returning. | 74 thread_id, |
| 56 if (scope.GetOrigin() != script_url.GetOrigin()) | 75 request_id, |
| 76 WebKit::WebServiceWorkerError::SecurityError, |
| 77 ASCIIToUTF16(kDomainMismatchErrorMessage))); |
| 57 return; | 78 return; |
| 79 } |
| 58 | 80 |
| 59 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 81 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| 60 thread_id, request_id, NextWorkerId())); | 82 thread_id, request_id, NextWorkerId())); |
| 61 } | 83 } |
| 62 | 84 |
| 63 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, | 85 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, |
| 64 int32 request_id, | 86 int32 request_id, |
| 65 const GURL& scope) { | 87 const GURL& scope) { |
| 66 // TODO(alecflett): add a ServiceWorker-specific policy query in | 88 // TODO(alecflett): This check is insufficient for release. Add a |
| 89 // ServiceWorker-specific policy query in |
| 67 // ChildProcessSecurityImpl. See http://crbug.com/311631. | 90 // ChildProcessSecurityImpl. See http://crbug.com/311631. |
| 91 if (!context_->enabled()) { |
| 92 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 93 thread_id, |
| 94 request_id, |
| 95 WebServiceWorkerError::DisabledError, |
| 96 ASCIIToUTF16("ServiceWorker is disabled"))); |
| 97 return; |
| 98 } |
| 68 | 99 |
| 69 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( | 100 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( |
| 70 thread_id, request_id)); | 101 thread_id, request_id)); |
| 71 } | 102 } |
| 72 | 103 |
| 73 } // namespace content | 104 } // namespace content |
| OLD | NEW |