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 a60f8bb3e936befb84b226ca651ac1e316f8ea87..f231bb900e69e3474ab1871078495393f139e699 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
@@ -4,11 +4,15 @@ |
#include "content/browser/service_worker/service_worker_dispatcher_host.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "content/browser/service_worker/service_worker_context.h" |
#include "content/common/service_worker_messages.h" |
#include "ipc/ipc_message_macros.h" |
+#include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
#include "url/gurl.h" |
+using WebKit::WebServiceWorkerError; |
+ |
namespace content { |
ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
@@ -18,6 +22,11 @@ ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
+namespace { |
+const char kDomainMismatchErrorMessage[] = |
+ "Scope and scripts do not have the same origin"; |
+} |
+ |
bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
bool* message_was_ok) { |
if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
@@ -48,13 +57,26 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
int32 request_id, |
const GURL& scope, |
const GURL& script_url) { |
- // TODO(alecflett): add a ServiceWorker-specific policy query in |
- // ChildProcessSecurityImpl. See http://crbug.com/311631. |
+ if (!context_->enabled()) { |
+ Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
+ thread_id, |
+ request_id, |
+ WebKit::WebServiceWorkerError::DisabledError, |
+ ASCIIToUTF16("ServiceWorker is disabled"))); |
+ return; |
+ } |
- // TODO(alecflett): Throw an error for origin mismatch, rather than |
- // just returning. |
- if (scope.GetOrigin() != script_url.GetOrigin()) |
+ // TODO(alecflett): This check is insufficient for release. Add a |
+ // ServiceWorker-specific policy query in |
+ // ChildProcessSecurityImpl. See http://crbug.com/311631. |
+ if (scope.GetOrigin() != script_url.GetOrigin()) { |
+ Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
+ thread_id, |
+ request_id, |
+ WebKit::WebServiceWorkerError::SecurityError, |
+ ASCIIToUTF16(kDomainMismatchErrorMessage))); |
return; |
+ } |
Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
thread_id, request_id, NextWorkerId())); |
@@ -63,8 +85,17 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, |
int32 request_id, |
const GURL& scope) { |
- // TODO(alecflett): add a ServiceWorker-specific policy query in |
+ // TODO(alecflett): This check is insufficient for release. Add a |
+ // ServiceWorker-specific policy query in |
// ChildProcessSecurityImpl. See http://crbug.com/311631. |
+ if (!context_->enabled()) { |
+ Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
+ thread_id, |
+ request_id, |
+ WebServiceWorkerError::DisabledError, |
+ ASCIIToUTF16("ServiceWorker is disabled"))); |
+ return; |
+ } |
Send(new ServiceWorkerMsg_ServiceWorkerUnregistered( |
thread_id, request_id)); |