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

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

Issue 339973003: Remove --enable-service-worker flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/message_port_message_filter.h" 9 #include "content/browser/message_port_message_filter.h"
10 #include "content/browser/message_port_service.h" 10 #include "content/browser/message_port_service.h"
11 #include "content/browser/service_worker/embedded_worker_registry.h" 11 #include "content/browser/service_worker/embedded_worker_registry.h"
12 #include "content/browser/service_worker/service_worker_context_core.h" 12 #include "content/browser/service_worker/service_worker_context_core.h"
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" 13 #include "content/browser/service_worker/service_worker_context_wrapper.h"
14 #include "content/browser/service_worker/service_worker_handle.h" 14 #include "content/browser/service_worker/service_worker_handle.h"
15 #include "content/browser/service_worker/service_worker_registration.h" 15 #include "content/browser/service_worker/service_worker_registration.h"
16 #include "content/browser/service_worker/service_worker_utils.h" 16 #include "content/browser/service_worker/service_worker_utils.h"
17 #include "content/common/service_worker/embedded_worker_messages.h" 17 #include "content/common/service_worker/embedded_worker_messages.h"
18 #include "content/common/service_worker/service_worker_messages.h" 18 #include "content/common/service_worker/service_worker_messages.h"
19 #include "ipc/ipc_message_macros.h" 19 #include "ipc/ipc_message_macros.h"
20 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" 20 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 using blink::WebServiceWorkerError; 23 using blink::WebServiceWorkerError;
24 24
25 namespace content { 25 namespace content {
26 26
27 namespace { 27 namespace {
28 28
29 const char kDisabledErrorMessage[] = 29 const char kShutdownErrorMessage[] =
30 "ServiceWorker is disabled"; 30 "The Service Worker system has shutdown.";
31 const char kDomainMismatchErrorMessage[] = 31 const char kDomainMismatchErrorMessage[] =
32 "Scope and scripts do not have the same origin"; 32 "Scope and scripts do not have the same origin";
33 33
34 const uint32 kFilteredMessageClasses[] = { 34 const uint32 kFilteredMessageClasses[] = {
35 ServiceWorkerMsgStart, 35 ServiceWorkerMsgStart,
36 EmbeddedWorkerMsgStart, 36 EmbeddedWorkerMsgStart,
37 }; 37 };
38 38
39 bool CanRegisterServiceWorker(const GURL& document_url, 39 bool CanRegisterServiceWorker(const GURL& document_url,
40 const GURL& pattern, 40 const GURL& pattern,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 int handle_id = handle->handle_id(); 157 int handle_id = handle->handle_id();
158 handles_.AddWithID(handle.release(), handle_id); 158 handles_.AddWithID(handle.release(), handle_id);
159 } 159 }
160 160
161 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( 161 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
162 int thread_id, 162 int thread_id,
163 int request_id, 163 int request_id,
164 int provider_id, 164 int provider_id,
165 const GURL& pattern, 165 const GURL& pattern,
166 const GURL& script_url) { 166 const GURL& script_url) {
167 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) { 167 if (!GetContext()) {
168 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 168 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
169 thread_id, 169 thread_id,
170 request_id, 170 request_id,
171 WebServiceWorkerError::ErrorTypeDisabled, 171 WebServiceWorkerError::ErrorTypeAbort,
172 base::ASCIIToUTF16(kDisabledErrorMessage))); 172 base::ASCIIToUTF16(kShutdownErrorMessage)));
173 return; 173 return;
174 } 174 }
175 175
176 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( 176 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
177 render_process_id_, provider_id); 177 render_process_id_, provider_id);
178 if (!provider_host) { 178 if (!provider_host) {
179 BadMessageReceived(); 179 BadMessageReceived();
180 return; 180 return;
181 } 181 }
182 if (!provider_host->IsContextAlive()) { 182 if (!provider_host->IsContextAlive()) {
183 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 183 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
184 thread_id, 184 thread_id,
185 request_id, 185 request_id,
186 WebServiceWorkerError::ErrorTypeDisabled, 186 WebServiceWorkerError::ErrorTypeAbort,
187 base::ASCIIToUTF16(kDisabledErrorMessage))); 187 base::ASCIIToUTF16(kShutdownErrorMessage)));
188 return; 188 return;
189 } 189 }
190 190
191 if (!CanRegisterServiceWorker( 191 if (!CanRegisterServiceWorker(
192 provider_host->document_url(), pattern, script_url)) { 192 provider_host->document_url(), pattern, script_url)) {
193 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 193 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
194 thread_id, 194 thread_id,
195 request_id, 195 request_id,
196 WebServiceWorkerError::ErrorTypeSecurity, 196 WebServiceWorkerError::ErrorTypeSecurity,
197 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); 197 base::ASCIIToUTF16(kDomainMismatchErrorMessage)));
198 return; 198 return;
199 } 199 }
200 GetContext()->RegisterServiceWorker( 200 GetContext()->RegisterServiceWorker(
201 pattern, 201 pattern,
202 script_url, 202 script_url,
203 render_process_id_, 203 render_process_id_,
204 provider_host, 204 provider_host,
205 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, 205 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete,
206 this, 206 this,
207 thread_id, 207 thread_id,
208 request_id)); 208 request_id));
209 } 209 }
210 210
211 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( 211 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
212 int thread_id, 212 int thread_id,
213 int request_id, 213 int request_id,
214 int provider_id, 214 int provider_id,
215 const GURL& pattern) { 215 const GURL& pattern) {
216 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) { 216 if (!GetContext()) {
217 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 217 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
218 thread_id, 218 thread_id,
219 request_id, 219 request_id,
220 blink::WebServiceWorkerError::ErrorTypeDisabled, 220 blink::WebServiceWorkerError::ErrorTypeAbort,
221 base::ASCIIToUTF16(kDisabledErrorMessage))); 221 base::ASCIIToUTF16(kShutdownErrorMessage)));
222 return; 222 return;
223 } 223 }
224 224
225 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( 225 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
226 render_process_id_, provider_id); 226 render_process_id_, provider_id);
227 if (!provider_host) { 227 if (!provider_host) {
228 BadMessageReceived(); 228 BadMessageReceived();
229 return; 229 return;
230 } 230 }
231 if (!provider_host->IsContextAlive()) { 231 if (!provider_host->IsContextAlive()) {
232 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 232 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
233 thread_id, 233 thread_id,
234 request_id, 234 request_id,
235 blink::WebServiceWorkerError::ErrorTypeDisabled, 235 blink::WebServiceWorkerError::ErrorTypeAbort,
236 base::ASCIIToUTF16(kDisabledErrorMessage))); 236 base::ASCIIToUTF16(kShutdownErrorMessage)));
237 return; 237 return;
238 } 238 }
239 239
240 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { 240 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) {
241 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 241 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
242 thread_id, 242 thread_id,
243 request_id, 243 request_id,
244 WebServiceWorkerError::ErrorTypeSecurity, 244 WebServiceWorkerError::ErrorTypeSecurity,
245 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); 245 base::ASCIIToUTF16(kDomainMismatchErrorMessage)));
246 return; 246 return;
247 } 247 }
248 248
249 GetContext()->UnregisterServiceWorker( 249 GetContext()->UnregisterServiceWorker(
250 pattern, 250 pattern,
251 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, 251 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
252 this, 252 this,
253 thread_id, 253 thread_id,
254 request_id)); 254 request_id));
255 } 255 }
256 256
257 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( 257 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
258 int handle_id, 258 int handle_id,
259 const base::string16& message, 259 const base::string16& message,
260 const std::vector<int>& sent_message_port_ids) { 260 const std::vector<int>& sent_message_port_ids) {
261 if (!GetContext() || !ServiceWorkerUtils::IsFeatureEnabled()) 261 if (!GetContext())
262 return; 262 return;
263 263
264 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 264 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
265 if (!handle) { 265 if (!handle) {
266 BadMessageReceived(); 266 BadMessageReceived();
267 return; 267 return;
268 } 268 }
269 269
270 std::vector<int> new_routing_ids; 270 std::vector<int> new_routing_ids;
271 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( 271 message_port_message_filter_->UpdateMessagePortsWithNewRoutes(
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 status, &error_type, &error_message); 448 status, &error_type, &error_message);
449 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 449 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
450 thread_id, request_id, error_type, error_message)); 450 thread_id, request_id, error_type, error_message));
451 } 451 }
452 452
453 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 453 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
454 return context_wrapper_->context(); 454 return context_wrapper_->context();
455 } 455 }
456 456
457 } // namespace content 457 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698