Chromium Code Reviews| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.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 url_a.GetOrigin() == url_c.GetOrigin(); | 45 url_a.GetOrigin() == url_c.GetOrigin(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // TODO(dominicc): When crbug.com/362214 is fixed use that to be | 48 // TODO(dominicc): When crbug.com/362214 is fixed use that to be |
| 49 // consistent with Blink's | 49 // consistent with Blink's |
| 50 // SecurityOrigin::canAccessFeatureRequiringSecureOrigin. | 50 // SecurityOrigin::canAccessFeatureRequiringSecureOrigin. |
| 51 bool OriginCanAccessServiceWorkers(const GURL& url) { | 51 bool OriginCanAccessServiceWorkers(const GURL& url) { |
| 52 return url.SchemeIsSecure() || net::IsLocalhost(url.host()); | 52 return url.SchemeIsSecure() || net::IsLocalhost(url.host()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool CheckPatternIsUnderTheScriptDirectory(const GURL& pattern, | |
| 56 const GURL& script_url) { | |
| 57 size_t slash_pos = script_url.spec().rfind('/'); | |
| 58 if (slash_pos == std::string::npos) | |
| 59 return false; | |
| 60 return pattern.spec().compare( | |
| 61 0, slash_pos + 1, script_url.spec(), 0, slash_pos + 1) == 0; | |
|
falken
2014/10/27 03:54:17
i think this can just be: pattern.spec().compare(0
horo
2014/10/27 09:14:12
No. We need subpos and sublen.
http://www.cplusplu
falken
2014/10/28 00:55:45
Ah, my mistake. I thought if they were the same as
| |
| 62 } | |
| 63 | |
| 55 bool CanRegisterServiceWorker(const GURL& document_url, | 64 bool CanRegisterServiceWorker(const GURL& document_url, |
| 56 const GURL& pattern, | 65 const GURL& pattern, |
| 57 const GURL& script_url) { | 66 const GURL& script_url) { |
|
falken
2014/10/27 03:54:17
Using spec() in this CL reminds me that we should
horo
2014/10/27 09:14:12
Done.
| |
| 58 return AllOriginsMatch(document_url, pattern, script_url) && | 67 return AllOriginsMatch(document_url, pattern, script_url) && |
| 59 OriginCanAccessServiceWorkers(document_url); | 68 OriginCanAccessServiceWorkers(document_url) && |
| 69 CheckPatternIsUnderTheScriptDirectory(pattern, script_url); | |
| 60 } | 70 } |
| 61 | 71 |
| 62 bool CanUnregisterServiceWorker(const GURL& document_url, | 72 bool CanUnregisterServiceWorker(const GURL& document_url, |
| 63 const GURL& pattern) { | 73 const GURL& pattern) { |
|
falken
2014/10/27 03:54:17
Check for validity here too.
horo
2014/10/27 09:14:12
Done.
| |
| 64 return document_url.GetOrigin() == pattern.GetOrigin() && | 74 return document_url.GetOrigin() == pattern.GetOrigin() && |
| 65 OriginCanAccessServiceWorkers(document_url); | 75 OriginCanAccessServiceWorkers(document_url); |
| 66 } | 76 } |
| 67 | 77 |
| 68 bool CanGetRegistration(const GURL& document_url, | 78 bool CanGetRegistration(const GURL& document_url, |
| 69 const GURL& given_document_url) { | 79 const GURL& given_document_url) { |
|
falken
2014/10/27 03:54:17
And here
horo
2014/10/27 09:14:12
Done.
| |
| 70 return document_url.GetOrigin() == given_document_url.GetOrigin() && | 80 return document_url.GetOrigin() == given_document_url.GetOrigin() && |
| 71 OriginCanAccessServiceWorkers(document_url); | 81 OriginCanAccessServiceWorkers(document_url); |
| 72 } | 82 } |
| 73 | 83 |
| 74 } // namespace | 84 } // namespace |
| 75 | 85 |
| 76 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 86 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| 77 int render_process_id, | 87 int render_process_id, |
| 78 MessagePortMessageFilter* message_port_message_filter, | 88 MessagePortMessageFilter* message_port_message_filter, |
| 79 ResourceContext* resource_context) | 89 ResourceContext* resource_context) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 provider_id, | 293 provider_id, |
| 284 request_id)); | 294 request_id)); |
| 285 } | 295 } |
| 286 | 296 |
| 287 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 297 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| 288 int thread_id, | 298 int thread_id, |
| 289 int request_id, | 299 int request_id, |
| 290 int provider_id, | 300 int provider_id, |
| 291 const GURL& pattern) { | 301 const GURL& pattern) { |
| 292 TRACE_EVENT0("ServiceWorker", | 302 TRACE_EVENT0("ServiceWorker", |
| 293 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); | 303 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); |
|
falken
2014/10/27 03:54:17
Here too, let's check for validity.
horo
2014/10/27 09:14:11
Done.
| |
| 294 if (!GetContext()) { | 304 if (!GetContext()) { |
| 295 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 305 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
| 296 thread_id, | 306 thread_id, |
| 297 request_id, | 307 request_id, |
| 298 blink::WebServiceWorkerError::ErrorTypeAbort, | 308 blink::WebServiceWorkerError::ErrorTypeAbort, |
| 299 base::ASCIIToUTF16(kShutdownErrorMessage))); | 309 base::ASCIIToUTF16(kShutdownErrorMessage))); |
| 300 return; | 310 return; |
| 301 } | 311 } |
| 302 | 312 |
| 303 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 313 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 thread_id, | 352 thread_id, |
| 343 request_id)); | 353 request_id)); |
| 344 } | 354 } |
| 345 | 355 |
| 346 void ServiceWorkerDispatcherHost::OnGetRegistration( | 356 void ServiceWorkerDispatcherHost::OnGetRegistration( |
| 347 int thread_id, | 357 int thread_id, |
| 348 int request_id, | 358 int request_id, |
| 349 int provider_id, | 359 int provider_id, |
| 350 const GURL& document_url) { | 360 const GURL& document_url) { |
| 351 TRACE_EVENT0("ServiceWorker", | 361 TRACE_EVENT0("ServiceWorker", |
| 352 "ServiceWorkerDispatcherHost::OnGetRegistration"); | 362 "ServiceWorkerDispatcherHost::OnGetRegistration"); |
|
falken
2014/10/27 03:54:17
And here.
horo
2014/10/27 09:14:12
Done.
| |
| 353 if (!GetContext()) { | 363 if (!GetContext()) { |
| 354 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 364 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| 355 thread_id, | 365 thread_id, |
| 356 request_id, | 366 request_id, |
| 357 blink::WebServiceWorkerError::ErrorTypeAbort, | 367 blink::WebServiceWorkerError::ErrorTypeAbort, |
| 358 base::ASCIIToUTF16(kShutdownErrorMessage))); | 368 base::ASCIIToUTF16(kShutdownErrorMessage))); |
| 359 return; | 369 return; |
| 360 } | 370 } |
| 361 | 371 |
| 362 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( | 372 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 status, &error_type, &error_message); | 804 status, &error_type, &error_message); |
| 795 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 805 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| 796 thread_id, request_id, error_type, error_message)); | 806 thread_id, request_id, error_type, error_message)); |
| 797 } | 807 } |
| 798 | 808 |
| 799 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 809 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
| 800 return context_wrapper_->context(); | 810 return context_wrapper_->context(); |
| 801 } | 811 } |
| 802 | 812 |
| 803 } // namespace content | 813 } // namespace content |
| OLD | NEW |