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/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
| 11 #include "content/child/service_worker/service_worker_handle_reference.h" | 11 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 12 #include "content/child/service_worker/service_worker_provider_context.h" | 12 #include "content/child/service_worker/service_worker_provider_context.h" |
| 13 #include "content/child/service_worker/web_service_worker_impl.h" | 13 #include "content/child/service_worker/web_service_worker_impl.h" |
| 14 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
| 15 #include "content/child/webmessageportchannel_impl.h" | 15 #include "content/child/webmessageportchannel_impl.h" |
| 16 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "content/public/common/url_utils.h" | |
| 17 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" |
| 18 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 19 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 19 | 20 |
| 20 using blink::WebServiceWorkerError; | 21 using blink::WebServiceWorkerError; |
| 21 using blink::WebServiceWorkerProvider; | 22 using blink::WebServiceWorkerProvider; |
| 22 using base::ThreadLocalPointer; | 23 using base::ThreadLocalPointer; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | 72 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { |
| 72 return thread_safe_sender_->Send(msg); | 73 return thread_safe_sender_->Send(msg); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void ServiceWorkerDispatcher::RegisterServiceWorker( | 76 void ServiceWorkerDispatcher::RegisterServiceWorker( |
| 76 int provider_id, | 77 int provider_id, |
| 77 const GURL& pattern, | 78 const GURL& pattern, |
| 78 const GURL& script_url, | 79 const GURL& script_url, |
| 79 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { | 80 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { |
| 80 DCHECK(callbacks); | 81 DCHECK(callbacks); |
| 82 | |
| 83 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || | |
| 84 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | |
| 85 scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> | |
| 86 owned_callbacks(callbacks); | |
| 87 scoped_ptr<WebServiceWorkerError> error( | |
|
falken
2014/06/20 03:09:21
extra space here
jsbell
2014/06/20 17:05:25
Done.
| |
| 88 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | |
| 89 "URL too long")); | |
| 90 callbacks->onError(error.release()); | |
| 91 return; | |
| 92 } | |
| 93 | |
| 81 int request_id = pending_callbacks_.Add(callbacks); | 94 int request_id = pending_callbacks_.Add(callbacks); |
| 82 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 95 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| 83 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 96 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
| 84 } | 97 } |
| 85 | 98 |
| 86 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 99 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 87 int provider_id, | 100 int provider_id, |
| 88 const GURL& pattern, | 101 const GURL& pattern, |
| 89 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { | 102 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { |
| 90 DCHECK(callbacks); | 103 DCHECK(callbacks); |
| 104 | |
| 105 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | |
| 106 scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> | |
| 107 owned_callbacks(callbacks); | |
| 108 scoped_ptr<WebServiceWorkerError> error( | |
|
falken
2014/06/20 03:09:21
ditto
jsbell
2014/06/20 17:05:25
Done.
| |
| 109 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | |
| 110 "URL too long")); | |
| 111 callbacks->onError(error.release()); | |
| 112 return; | |
| 113 } | |
| 114 | |
| 91 int request_id = pending_callbacks_.Add(callbacks); | 115 int request_id = pending_callbacks_.Add(callbacks); |
| 92 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 116 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 93 CurrentWorkerId(), request_id, provider_id, pattern)); | 117 CurrentWorkerId(), request_id, provider_id, pattern)); |
| 94 } | 118 } |
| 95 | 119 |
| 96 void ServiceWorkerDispatcher::AddProviderContext( | 120 void ServiceWorkerDispatcher::AddProviderContext( |
| 97 ServiceWorkerProviderContext* provider_context) { | 121 ServiceWorkerProviderContext* provider_context) { |
| 98 DCHECK(provider_context); | 122 DCHECK(provider_context); |
| 99 int provider_id = provider_context->provider_id(); | 123 int provider_id = provider_context->provider_id(); |
| 100 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 124 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 int thread_id, | 232 int thread_id, |
| 209 int request_id, | 233 int request_id, |
| 210 WebServiceWorkerError::ErrorType error_type, | 234 WebServiceWorkerError::ErrorType error_type, |
| 211 const base::string16& message) { | 235 const base::string16& message) { |
| 212 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 236 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
| 213 pending_callbacks_.Lookup(request_id); | 237 pending_callbacks_.Lookup(request_id); |
| 214 DCHECK(callbacks); | 238 DCHECK(callbacks); |
| 215 if (!callbacks) | 239 if (!callbacks) |
| 216 return; | 240 return; |
| 217 | 241 |
| 218 scoped_ptr<WebServiceWorkerError> error( | 242 scoped_ptr<WebServiceWorkerError> error( |
|
jsbell
2014/06/20 17:05:25
And fixed it too (which was what I copy/pasted)
| |
| 219 new WebServiceWorkerError(error_type, message)); | 243 new WebServiceWorkerError(error_type, message)); |
| 220 callbacks->onError(error.release()); | 244 callbacks->onError(error.release()); |
| 221 pending_callbacks_.Remove(request_id); | 245 pending_callbacks_.Remove(request_id); |
| 222 } | 246 } |
| 223 | 247 |
| 224 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 248 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
| 225 int thread_id, | 249 int thread_id, |
| 226 int handle_id, | 250 int handle_id, |
| 227 blink::WebServiceWorkerState state) { | 251 blink::WebServiceWorkerState state) { |
| 228 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 252 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 DCHECK(!ContainsKey(service_workers_, handle_id)); | 337 DCHECK(!ContainsKey(service_workers_, handle_id)); |
| 314 service_workers_[handle_id] = worker; | 338 service_workers_[handle_id] = worker; |
| 315 } | 339 } |
| 316 | 340 |
| 317 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 341 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 318 DCHECK(ContainsKey(service_workers_, handle_id)); | 342 DCHECK(ContainsKey(service_workers_, handle_id)); |
| 319 service_workers_.erase(handle_id); | 343 service_workers_.erase(handle_id); |
| 320 } | 344 } |
| 321 | 345 |
| 322 } // namespace content | 346 } // namespace content |
| OLD | NEW |