Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 26442004: Service worker registration error support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-fix tests Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) : context_(context) {} 20 ServiceWorkerContext* context) : context_(context) {}
17 21
18 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} 22 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {}
19 23
24 namespace {
25 const char kDomainMismatchErrorMessage[] =
26 "Scope and scripts do not have the same origin";
27 }
28
20 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, 29 bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message,
21 bool* message_was_ok) { 30 bool* message_was_ok) {
22 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) 31 if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart)
23 return false; 32 return false;
24 33
25 bool handled = true; 34 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP_EX( 35 IPC_BEGIN_MESSAGE_MAP_EX(
27 ServiceWorkerDispatcherHost, message, *message_was_ok) 36 ServiceWorkerDispatcherHost, message, *message_was_ok)
28 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 37 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
29 OnRegisterServiceWorker) 38 OnRegisterServiceWorker)
(...skipping 10 matching lines...) Expand all
40 static int64 NextWorkerId() { 49 static int64 NextWorkerId() {
41 static int64 service_worker_id = 0; 50 static int64 service_worker_id = 0;
42 return service_worker_id++; 51 return service_worker_id++;
43 } 52 }
44 53
45 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( 54 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
46 int32 thread_id, 55 int32 thread_id,
47 int32 request_id, 56 int32 request_id,
48 const GURL& scope, 57 const GURL& scope,
49 const GURL& script_url) { 58 const GURL& script_url) {
50 // TODO(alecflett): add a ServiceWorker-specific policy query in 59 if (!context_->IsEnabled()) {
60 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
61 thread_id,
62 request_id,
63 WebKit::WebServiceWorkerError::DisabledError,
64 ASCIIToUTF16("ServiceWorker is disabled")));
65 return;
66 }
67
68 // TODO(alecflett): This check is insufficient for release. Add a
69 // ServiceWorker-specific policy query in
51 // ChildProcessSecurityImpl. See http://crbug.com/311631. 70 // ChildProcessSecurityImpl. See http://crbug.com/311631.
52 71 if (scope.GetOrigin() != script_url.GetOrigin()) {
53 // TODO(alecflett): Throw an error for origin mismatch, rather than 72 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
54 // just returning. 73 thread_id,
55 if (scope.GetOrigin() != script_url.GetOrigin()) 74 request_id,
75 WebKit::WebServiceWorkerError::SecurityError,
76 ASCIIToUTF16(kDomainMismatchErrorMessage)));
56 return; 77 return;
78 }
57 79
58 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 80 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
59 thread_id, request_id, NextWorkerId())); 81 thread_id, request_id, NextWorkerId()));
60 } 82 }
61 83
62 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, 84 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id,
63 int32 request_id, 85 int32 request_id,
64 const GURL& scope) { 86 const GURL& scope) {
65 // TODO(alecflett): add a ServiceWorker-specific policy query in 87 // TODO(alecflett): This check is insufficient for release. Add a
88 // ServiceWorker-specific policy query in
66 // ChildProcessSecurityImpl. See http://crbug.com/311631. 89 // ChildProcessSecurityImpl. See http://crbug.com/311631.
90 if (!context_->IsEnabled()) {
91 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
92 thread_id,
93 request_id,
94 WebServiceWorkerError::DisabledError,
95 ASCIIToUTF16("ServiceWorker is disabled")));
96 return;
97 }
67 98
68 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); 99 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
69 } 100 }
70 101
71 } // namespace content 102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698