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/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 "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 }; | 45 }; |
46 | 46 |
47 bool AllOriginsMatch(const GURL& url_a, const GURL& url_b, const GURL& url_c) { | 47 bool AllOriginsMatch(const GURL& url_a, const GURL& url_b, const GURL& url_c) { |
48 return url_a.GetOrigin() == url_b.GetOrigin() && | 48 return url_a.GetOrigin() == url_b.GetOrigin() && |
49 url_a.GetOrigin() == url_c.GetOrigin(); | 49 url_a.GetOrigin() == url_c.GetOrigin(); |
50 } | 50 } |
51 | 51 |
52 // TODO(dominicc): When crbug.com/362214 is fixed use that to be | 52 // TODO(dominicc): When crbug.com/362214 is fixed use that to be |
53 // consistent with Blink's | 53 // consistent with Blink's |
54 // SecurityOrigin::canAccessFeatureRequiringSecureOrigin. | 54 // SecurityOrigin::canAccessFeatureRequiringSecureOrigin. |
55 bool OriginCanAccessServiceWorkers(const GURL& url) { | 55 bool OriginCanAccessServiceWorkers(const GURL& url) { |
nhiroki
2015/02/02 06:14:27
This function is only used for document_url. Proba
kinuko
2015/02/02 07:59:42
Done.
| |
56 return url.SchemeIsSecure() || net::IsLocalhost(url.host()); | 56 return url.SchemeIsHTTPOrHTTPS() && |
57 (url.SchemeIsSecure() || net::IsLocalhost(url.host())); | |
57 } | 58 } |
58 | 59 |
59 bool CanRegisterServiceWorker(const GURL& document_url, | 60 bool CanRegisterServiceWorker(const GURL& document_url, |
60 const GURL& pattern, | 61 const GURL& pattern, |
61 const GURL& script_url) { | 62 const GURL& script_url) { |
62 DCHECK(document_url.is_valid()); | 63 DCHECK(document_url.is_valid()); |
63 DCHECK(pattern.is_valid()); | 64 DCHECK(pattern.is_valid()); |
64 DCHECK(script_url.is_valid()); | 65 DCHECK(script_url.is_valid()); |
65 return AllOriginsMatch(document_url, pattern, script_url) && | 66 return AllOriginsMatch(document_url, pattern, script_url) && |
66 OriginCanAccessServiceWorkers(document_url); | 67 OriginCanAccessServiceWorkers(document_url); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 if (provider_host->document_url().is_empty()) { | 288 if (provider_host->document_url().is_empty()) { |
288 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 289 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
289 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, | 290 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
290 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + | 291 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
291 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | 292 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); |
292 return; | 293 return; |
293 } | 294 } |
294 | 295 |
295 if (!CanRegisterServiceWorker( | 296 if (!CanRegisterServiceWorker( |
296 provider_host->document_url(), pattern, script_url)) { | 297 provider_host->document_url(), pattern, script_url)) { |
297 BadMessageReceived(); | 298 BadMessageReceived(); |
falken
2015/02/02 06:01:23
With the new restriction, it's probably over-aggre
kinuko
2015/02/02 07:59:42
I looked into this deeper, actually we do check if
| |
298 return; | 299 return; |
299 } | 300 } |
300 | 301 |
301 std::string error_message; | 302 std::string error_message; |
302 if (ServiceWorkerUtils::ContainsDisallowedCharacter(pattern, script_url, | 303 if (ServiceWorkerUtils::ContainsDisallowedCharacter(pattern, script_url, |
303 &error_message)) { | 304 &error_message)) { |
304 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 305 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
305 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, | 306 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
306 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + | 307 base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
307 base::UTF8ToUTF16(error_message))); | 308 base::UTF8ToUTF16(error_message))); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 if (provider_host->document_url().is_empty()) { | 373 if (provider_host->document_url().is_empty()) { |
373 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 374 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
374 thread_id, | 375 thread_id, |
375 request_id, | 376 request_id, |
376 WebServiceWorkerError::ErrorTypeSecurity, | 377 WebServiceWorkerError::ErrorTypeSecurity, |
377 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | 378 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); |
378 return; | 379 return; |
379 } | 380 } |
380 | 381 |
381 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { | 382 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) { |
382 BadMessageReceived(); | 383 BadMessageReceived(); |
falken
2015/02/02 06:01:23
Same here
kinuko
2015/02/02 07:59:42
Done.
| |
383 return; | 384 return; |
384 } | 385 } |
385 | 386 |
386 if (!GetContentClient()->browser()->AllowServiceWorker( | 387 if (!GetContentClient()->browser()->AllowServiceWorker( |
387 pattern, provider_host->topmost_frame_url(), resource_context_)) { | 388 pattern, provider_host->topmost_frame_url(), resource_context_)) { |
388 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 389 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
389 thread_id, | 390 thread_id, |
390 request_id, | 391 request_id, |
391 WebServiceWorkerError::ErrorTypeUnknown, | 392 WebServiceWorkerError::ErrorTypeUnknown, |
392 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | 393 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. | 443 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. |
443 if (provider_host->document_url().is_empty()) { | 444 if (provider_host->document_url().is_empty()) { |
444 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 445 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
445 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, | 446 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, |
446 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | 447 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
447 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | 448 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); |
448 return; | 449 return; |
449 } | 450 } |
450 | 451 |
451 if (!CanGetRegistration(provider_host->document_url(), document_url)) { | 452 if (!CanGetRegistration(provider_host->document_url(), document_url)) { |
452 BadMessageReceived(); | 453 BadMessageReceived(); |
falken
2015/02/02 06:01:23
Same here.
kinuko
2015/02/02 07:59:42
I assume this should be fine, as we check the sche
| |
453 return; | 454 return; |
454 } | 455 } |
455 | 456 |
456 if (!GetContentClient()->browser()->AllowServiceWorker( | 457 if (!GetContentClient()->browser()->AllowServiceWorker( |
457 provider_host->document_url(), | 458 provider_host->document_url(), |
458 provider_host->topmost_frame_url(), | 459 provider_host->topmost_frame_url(), |
459 resource_context_)) { | 460 resource_context_)) { |
460 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 461 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
461 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | 462 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, |
462 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | 463 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 939 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
939 if (!handle) { | 940 if (!handle) { |
940 BadMessageReceived(); | 941 BadMessageReceived(); |
941 return; | 942 return; |
942 } | 943 } |
943 handle->version()->StopWorker( | 944 handle->version()->StopWorker( |
944 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 945 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
945 } | 946 } |
946 | 947 |
947 } // namespace content | 948 } // namespace content |
OLD | NEW |