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

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

Issue 677003002: [ServiceWorker] Introduce the directory restriction of ServiceWorker scope in chromium side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated falken's comment Created 6 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_dispatcher_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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;
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) {
67 DCHECK(document_url.is_valid());
68 DCHECK(pattern.is_valid());
69 DCHECK(script_url.is_valid());
58 return AllOriginsMatch(document_url, pattern, script_url) && 70 return AllOriginsMatch(document_url, pattern, script_url) &&
59 OriginCanAccessServiceWorkers(document_url); 71 OriginCanAccessServiceWorkers(document_url) &&
72 CheckPatternIsUnderTheScriptDirectory(pattern, script_url);
60 } 73 }
61 74
62 bool CanUnregisterServiceWorker(const GURL& document_url, 75 bool CanUnregisterServiceWorker(const GURL& document_url,
63 const GURL& pattern) { 76 const GURL& pattern) {
77 DCHECK(document_url.is_valid());
78 DCHECK(pattern.is_valid());
64 return document_url.GetOrigin() == pattern.GetOrigin() && 79 return document_url.GetOrigin() == pattern.GetOrigin() &&
65 OriginCanAccessServiceWorkers(document_url); 80 OriginCanAccessServiceWorkers(document_url);
66 } 81 }
67 82
68 bool CanGetRegistration(const GURL& document_url, 83 bool CanGetRegistration(const GURL& document_url,
69 const GURL& given_document_url) { 84 const GURL& given_document_url) {
85 DCHECK(document_url.is_valid());
86 DCHECK(given_document_url.is_valid());
70 return document_url.GetOrigin() == given_document_url.GetOrigin() && 87 return document_url.GetOrigin() == given_document_url.GetOrigin() &&
71 OriginCanAccessServiceWorkers(document_url); 88 OriginCanAccessServiceWorkers(document_url);
72 } 89 }
73 90
74 } // namespace 91 } // namespace
75 92
76 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( 93 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
77 int render_process_id, 94 int render_process_id,
78 MessagePortMessageFilter* message_port_message_filter, 95 MessagePortMessageFilter* message_port_message_filter,
79 ResourceContext* resource_context) 96 ResourceContext* resource_context)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 TRACE_EVENT0("ServiceWorker", 246 TRACE_EVENT0("ServiceWorker",
230 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker"); 247 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker");
231 if (!GetContext()) { 248 if (!GetContext()) {
232 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 249 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
233 thread_id, 250 thread_id,
234 request_id, 251 request_id,
235 WebServiceWorkerError::ErrorTypeAbort, 252 WebServiceWorkerError::ErrorTypeAbort,
236 base::ASCIIToUTF16(kShutdownErrorMessage))); 253 base::ASCIIToUTF16(kShutdownErrorMessage)));
237 return; 254 return;
238 } 255 }
256 if (!pattern.is_valid() || !script_url.is_valid()) {
257 BadMessageReceived();
258 return;
259 }
239 260
240 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( 261 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
241 render_process_id_, provider_id); 262 render_process_id_, provider_id);
242 if (!provider_host) { 263 if (!provider_host) {
243 BadMessageReceived(); 264 BadMessageReceived();
244 return; 265 return;
245 } 266 }
246 if (!provider_host->IsContextAlive()) { 267 if (!provider_host->IsContextAlive()) {
247 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 268 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
248 thread_id, 269 thread_id,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 TRACE_EVENT0("ServiceWorker", 313 TRACE_EVENT0("ServiceWorker",
293 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); 314 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
294 if (!GetContext()) { 315 if (!GetContext()) {
295 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 316 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
296 thread_id, 317 thread_id,
297 request_id, 318 request_id,
298 blink::WebServiceWorkerError::ErrorTypeAbort, 319 blink::WebServiceWorkerError::ErrorTypeAbort,
299 base::ASCIIToUTF16(kShutdownErrorMessage))); 320 base::ASCIIToUTF16(kShutdownErrorMessage)));
300 return; 321 return;
301 } 322 }
323 if (!pattern.is_valid()) {
324 BadMessageReceived();
325 return;
326 }
302 327
303 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( 328 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
304 render_process_id_, provider_id); 329 render_process_id_, provider_id);
305 if (!provider_host) { 330 if (!provider_host) {
306 BadMessageReceived(); 331 BadMessageReceived();
307 return; 332 return;
308 } 333 }
309 if (!provider_host->IsContextAlive()) { 334 if (!provider_host->IsContextAlive()) {
310 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 335 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
311 thread_id, 336 thread_id,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 TRACE_EVENT0("ServiceWorker", 376 TRACE_EVENT0("ServiceWorker",
352 "ServiceWorkerDispatcherHost::OnGetRegistration"); 377 "ServiceWorkerDispatcherHost::OnGetRegistration");
353 if (!GetContext()) { 378 if (!GetContext()) {
354 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( 379 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
355 thread_id, 380 thread_id,
356 request_id, 381 request_id,
357 blink::WebServiceWorkerError::ErrorTypeAbort, 382 blink::WebServiceWorkerError::ErrorTypeAbort,
358 base::ASCIIToUTF16(kShutdownErrorMessage))); 383 base::ASCIIToUTF16(kShutdownErrorMessage)));
359 return; 384 return;
360 } 385 }
386 if (!document_url.is_valid()) {
387 BadMessageReceived();
388 return;
389 }
361 390
362 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( 391 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
363 render_process_id_, provider_id); 392 render_process_id_, provider_id);
364 if (!provider_host) { 393 if (!provider_host) {
365 BadMessageReceived(); 394 BadMessageReceived();
366 return; 395 return;
367 } 396 }
368 if (!provider_host->IsContextAlive()) { 397 if (!provider_host->IsContextAlive()) {
369 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( 398 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
370 thread_id, 399 thread_id,
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 status, &error_type, &error_message); 823 status, &error_type, &error_message);
795 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( 824 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
796 thread_id, request_id, error_type, error_message)); 825 thread_id, request_id, error_type, error_message));
797 } 826 }
798 827
799 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 828 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
800 return context_wrapper_->context(); 829 return context_wrapper_->context();
801 } 830 }
802 831
803 } // namespace content 832 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_dispatcher_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698