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 "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 return handled; | 112 return handled; |
113 } | 113 } |
114 | 114 |
115 int ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( | 115 int ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( |
116 scoped_ptr<ServiceWorkerHandle> handle) { | 116 scoped_ptr<ServiceWorkerHandle> handle) { |
117 return handles_.Add(handle.release()); | 117 return handles_.Add(handle.release()); |
118 } | 118 } |
119 | 119 |
120 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 120 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
121 int32 thread_id, | 121 int thread_id, |
122 int32 request_id, | 122 int request_id, |
| 123 int provider_id, |
123 const GURL& pattern, | 124 const GURL& pattern, |
124 const GURL& script_url) { | 125 const GURL& script_url) { |
125 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { | 126 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { |
126 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 127 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
127 thread_id, | 128 thread_id, |
128 request_id, | 129 request_id, |
129 WebServiceWorkerError::DisabledError, | 130 WebServiceWorkerError::DisabledError, |
130 base::ASCIIToUTF16(kDisabledErrorMessage))); | 131 base::ASCIIToUTF16(kDisabledErrorMessage))); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 // TODO(alecflett): This check is insufficient for release. Add a | 135 // TODO(alecflett): This check is insufficient for release. Add a |
135 // ServiceWorker-specific policy query in | 136 // ServiceWorker-specific policy query in |
136 // ChildProcessSecurityImpl. See http://crbug.com/311631. | 137 // ChildProcessSecurityImpl. See http://crbug.com/311631. |
137 if (pattern.GetOrigin() != script_url.GetOrigin()) { | 138 if (pattern.GetOrigin() != script_url.GetOrigin()) { |
138 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 139 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
139 thread_id, | 140 thread_id, |
140 request_id, | 141 request_id, |
141 WebServiceWorkerError::SecurityError, | 142 WebServiceWorkerError::SecurityError, |
142 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); | 143 base::ASCIIToUTF16(kDomainMismatchErrorMessage))); |
143 return; | 144 return; |
144 } | 145 } |
145 | 146 |
| 147 ServiceWorkerProviderHost* provider_host = context_->GetProviderHost( |
| 148 render_process_id_, provider_id); |
| 149 if (!provider_host) { |
| 150 BadMessageReceived(); |
| 151 return; |
| 152 } |
| 153 |
146 context_->RegisterServiceWorker( | 154 context_->RegisterServiceWorker( |
147 pattern, | 155 pattern, |
148 script_url, | 156 script_url, |
149 render_process_id_, | 157 render_process_id_, |
| 158 provider_host, |
150 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 159 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
151 this, | 160 this, |
152 thread_id, | 161 thread_id, |
153 request_id)); | 162 request_id)); |
154 } | 163 } |
155 | 164 |
156 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 165 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
157 int32 thread_id, | 166 int thread_id, |
158 int32 request_id, | 167 int request_id, |
| 168 int provider_id, |
159 const GURL& pattern) { | 169 const GURL& pattern) { |
160 // TODO(alecflett): This check is insufficient for release. Add a | 170 // TODO(alecflett): This check is insufficient for release. Add a |
161 // ServiceWorker-specific policy query in | 171 // ServiceWorker-specific policy query in |
162 // ChildProcessSecurityImpl. See http://crbug.com/311631. | 172 // ChildProcessSecurityImpl. See http://crbug.com/311631. |
163 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { | 173 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { |
164 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 174 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
165 thread_id, | 175 thread_id, |
166 request_id, | 176 request_id, |
167 blink::WebServiceWorkerError::DisabledError, | 177 blink::WebServiceWorkerError::DisabledError, |
168 base::ASCIIToUTF16(kDisabledErrorMessage))); | 178 base::ASCIIToUTF16(kDisabledErrorMessage))); |
169 return; | 179 return; |
170 } | 180 } |
171 | 181 |
| 182 ServiceWorkerProviderHost* provider_host = context_->GetProviderHost( |
| 183 render_process_id_, provider_id); |
| 184 if (!provider_host) { |
| 185 BadMessageReceived(); |
| 186 return; |
| 187 } |
| 188 |
172 context_->UnregisterServiceWorker( | 189 context_->UnregisterServiceWorker( |
173 pattern, | 190 pattern, |
174 render_process_id_, | 191 render_process_id_, |
| 192 provider_host, |
175 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, | 193 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, |
176 this, | 194 this, |
177 thread_id, | 195 thread_id, |
178 request_id)); | 196 request_id)); |
179 } | 197 } |
180 | 198 |
181 void ServiceWorkerDispatcherHost::OnPostMessage( | 199 void ServiceWorkerDispatcherHost::OnPostMessage( |
182 int handle_id, | 200 int handle_id, |
183 const base::string16& message, | 201 const base::string16& message, |
184 const std::vector<int>& sent_message_port_ids) { | 202 const std::vector<int>& sent_message_port_ids) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return; | 274 return; |
257 ServiceWorkerProviderHost* provider_host = | 275 ServiceWorkerProviderHost* provider_host = |
258 context_->GetProviderHost(render_process_id_, provider_id); | 276 context_->GetProviderHost(render_process_id_, provider_id); |
259 if (!provider_host || !provider_host->SetHostedVersionId(version_id)) { | 277 if (!provider_host || !provider_host->SetHostedVersionId(version_id)) { |
260 BadMessageReceived(); | 278 BadMessageReceived(); |
261 return; | 279 return; |
262 } | 280 } |
263 } | 281 } |
264 | 282 |
265 void ServiceWorkerDispatcherHost::RegistrationComplete( | 283 void ServiceWorkerDispatcherHost::RegistrationComplete( |
266 int32 thread_id, | 284 int thread_id, |
267 int32 request_id, | 285 int request_id, |
268 ServiceWorkerStatusCode status, | 286 ServiceWorkerStatusCode status, |
269 int64 registration_id, | 287 int64 registration_id, |
270 int64 version_id) { | 288 int64 version_id) { |
271 if (!context_) | 289 if (!context_) |
272 return; | 290 return; |
273 | 291 |
274 if (status != SERVICE_WORKER_OK) { | 292 if (status != SERVICE_WORKER_OK) { |
275 SendRegistrationError(thread_id, request_id, status); | 293 SendRegistrationError(thread_id, request_id, status); |
276 return; | 294 return; |
277 } | 295 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 DVLOG(2) << "[Error] " << error_message << " (" << source_url | 339 DVLOG(2) << "[Error] " << error_message << " (" << source_url |
322 << ":" << line_number << "," << column_number << ")"; | 340 << ":" << line_number << "," << column_number << ")"; |
323 } | 341 } |
324 | 342 |
325 void ServiceWorkerDispatcherHost::OnServiceWorkerObjectDestroyed( | 343 void ServiceWorkerDispatcherHost::OnServiceWorkerObjectDestroyed( |
326 int handle_id) { | 344 int handle_id) { |
327 handles_.Remove(handle_id); | 345 handles_.Remove(handle_id); |
328 } | 346 } |
329 | 347 |
330 void ServiceWorkerDispatcherHost::UnregistrationComplete( | 348 void ServiceWorkerDispatcherHost::UnregistrationComplete( |
331 int32 thread_id, | 349 int thread_id, |
332 int32 request_id, | 350 int request_id, |
333 ServiceWorkerStatusCode status) { | 351 ServiceWorkerStatusCode status) { |
334 if (status != SERVICE_WORKER_OK) { | 352 if (status != SERVICE_WORKER_OK) { |
335 SendRegistrationError(thread_id, request_id, status); | 353 SendRegistrationError(thread_id, request_id, status); |
336 return; | 354 return; |
337 } | 355 } |
338 | 356 |
339 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); | 357 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); |
340 } | 358 } |
341 | 359 |
342 void ServiceWorkerDispatcherHost::SendRegistrationError( | 360 void ServiceWorkerDispatcherHost::SendRegistrationError( |
343 int32 thread_id, | 361 int thread_id, |
344 int32 request_id, | 362 int request_id, |
345 ServiceWorkerStatusCode status) { | 363 ServiceWorkerStatusCode status) { |
346 base::string16 error_message; | 364 base::string16 error_message; |
347 blink::WebServiceWorkerError::ErrorType error_type; | 365 blink::WebServiceWorkerError::ErrorType error_type; |
348 GetServiceWorkerRegistrationStatusResponse( | 366 GetServiceWorkerRegistrationStatusResponse( |
349 status, &error_type, &error_message); | 367 status, &error_type, &error_message); |
350 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 368 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
351 thread_id, request_id, error_type, error_message)); | 369 thread_id, request_id, error_type, error_message)); |
352 } | 370 } |
353 | 371 |
354 } // namespace content | 372 } // namespace content |
OLD | NEW |