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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CountFeature, OnCountFeature) | 116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CountFeature, OnCountFeature) |
117 IPC_MESSAGE_UNHANDLED(handled = false) | 117 IPC_MESSAGE_UNHANDLED(handled = false) |
118 IPC_END_MESSAGE_MAP() | 118 IPC_END_MESSAGE_MAP() |
119 DCHECK(handled) << "Unhandled message:" << msg.type(); | 119 DCHECK(handled) << "Unhandled message:" << msg.type(); |
120 } | 120 } |
121 | 121 |
122 void ServiceWorkerDispatcher::RegisterServiceWorker( | 122 void ServiceWorkerDispatcher::RegisterServiceWorker( |
123 int provider_id, | 123 int provider_id, |
124 const GURL& pattern, | 124 const GURL& pattern, |
125 const GURL& script_url, | 125 const GURL& script_url, |
| 126 bool use_cache, |
126 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { | 127 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { |
127 DCHECK(callbacks); | 128 DCHECK(callbacks); |
128 | 129 |
129 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || | 130 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || |
130 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 131 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
131 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 132 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
132 error_message += "The provided scriptURL or scope is too long."; | 133 error_message += "The provided scriptURL or scope is too long."; |
133 callbacks->onError( | 134 callbacks->onError( |
134 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 135 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
135 blink::WebString::fromASCII(error_message))); | 136 blink::WebString::fromASCII(error_message))); |
136 return; | 137 return; |
137 } | 138 } |
138 | 139 |
139 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); | 140 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); |
| 141 ServiceWorkerRegistrationAttributes attrs = { |
| 142 .script_url = script_url, .pattern = pattern, .use_cache = use_cache, |
| 143 }; |
140 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 144 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
141 "ServiceWorkerDispatcher::RegisterServiceWorker", | 145 "ServiceWorkerDispatcher::RegisterServiceWorker", |
142 request_id, | 146 request_id, |
143 "Scope", pattern.spec(), | 147 "Scope", pattern.spec(), |
144 "Script URL", script_url.spec()); | 148 "Script URL", script_url.spec()); |
145 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 149 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
146 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 150 CurrentWorkerId(), request_id, provider_id, attrs)); |
147 } | 151 } |
148 | 152 |
149 void ServiceWorkerDispatcher::UpdateServiceWorker( | 153 void ServiceWorkerDispatcher::UpdateServiceWorker( |
150 int provider_id, | 154 int provider_id, |
151 int64_t registration_id, | 155 int64_t registration_id, |
152 std::unique_ptr<WebServiceWorkerUpdateCallbacks> callbacks) { | 156 std::unique_ptr<WebServiceWorkerUpdateCallbacks> callbacks) { |
153 DCHECK(callbacks); | 157 DCHECK(callbacks); |
154 int request_id = pending_update_callbacks_.Add(std::move(callbacks)); | 158 int request_id = pending_update_callbacks_.Add(std::move(callbacks)); |
155 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( | 159 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( |
156 CurrentWorkerId(), request_id, provider_id, registration_id)); | 160 CurrentWorkerId(), request_id, provider_id, registration_id)); |
(...skipping 22 matching lines...) Expand all Loading... |
179 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 183 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
180 error_message += "The provided documentURL is too long."; | 184 error_message += "The provided documentURL is too long."; |
181 callbacks->onError( | 185 callbacks->onError( |
182 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 186 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
183 blink::WebString::fromASCII(error_message))); | 187 blink::WebString::fromASCII(error_message))); |
184 return; | 188 return; |
185 } | 189 } |
186 | 190 |
187 int request_id = | 191 int request_id = |
188 pending_get_registration_callbacks_.Add(std::move(callbacks)); | 192 pending_get_registration_callbacks_.Add(std::move(callbacks)); |
| 193 |
189 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 194 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
190 "ServiceWorkerDispatcher::GetRegistration", | 195 "ServiceWorkerDispatcher::GetRegistration", |
191 request_id, | 196 request_id, |
192 "Document URL", document_url.spec()); | 197 "Document URL", document_url.spec()); |
193 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 198 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
194 CurrentWorkerId(), request_id, provider_id, document_url)); | 199 CurrentWorkerId(), request_id, provider_id, document_url)); |
195 } | 200 } |
196 | 201 |
197 void ServiceWorkerDispatcher::GetRegistrations( | 202 void ServiceWorkerDispatcher::GetRegistrations( |
198 int provider_id, | 203 int provider_id, |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 return ServiceWorkerRegistrationHandleReference::Adopt( | 927 return ServiceWorkerRegistrationHandleReference::Adopt( |
923 info, thread_safe_sender_.get()); | 928 info, thread_safe_sender_.get()); |
924 } | 929 } |
925 | 930 |
926 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 931 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
927 const ServiceWorkerObjectInfo& info) { | 932 const ServiceWorkerObjectInfo& info) { |
928 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 933 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
929 } | 934 } |
930 | 935 |
931 } // namespace content | 936 } // namespace content |
OLD | NEW |