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_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Focus the frame in the frame tree node, in case it has changed. | 47 // Focus the frame in the frame tree node, in case it has changed. |
48 frame_tree_node->frame_tree()->SetFocusedFrame(frame_tree_node); | 48 frame_tree_node->frame_tree()->SetFocusedFrame(frame_tree_node); |
49 | 49 |
50 // Focus the frame's view to make sure the frame is now considered as focused. | 50 // Focus the frame's view to make sure the frame is now considered as focused. |
51 render_frame_host->GetView()->Focus(); | 51 render_frame_host->GetView()->Focus(); |
52 | 52 |
53 // Move the web contents to the foreground. | 53 // Move the web contents to the foreground. |
54 web_contents->Activate(); | 54 web_contents->Activate(); |
55 | 55 |
56 return ServiceWorkerProviderHost::GetClientInfoOnUI( | 56 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id, |
57 render_process_id, render_frame_id); | 57 render_frame_id); |
58 } | 58 } |
59 | 59 |
60 } // anonymous namespace | 60 } // anonymous namespace |
61 | 61 |
62 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( | 62 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
63 const GetRegistrationForReadyCallback& callback) | 63 const GetRegistrationForReadyCallback& callback) |
64 : callback(callback), | 64 : callback(callback), |
65 called(false) { | 65 called(false) { |
66 } | 66 } |
67 | 67 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (previous_version.get()) | 175 if (previous_version.get()) |
176 previous_version->RemoveControllee(this); | 176 previous_version->RemoveControllee(this); |
177 | 177 |
178 if (!dispatcher_host_) | 178 if (!dispatcher_host_) |
179 return; // Could be NULL in some tests. | 179 return; // Could be NULL in some tests. |
180 | 180 |
181 bool should_notify_controllerchange = | 181 bool should_notify_controllerchange = |
182 is_claiming_ || (previous_version && version && version->skip_waiting()); | 182 is_claiming_ || (previous_version && version && version->skip_waiting()); |
183 | 183 |
184 // SetController message should be sent only for controllees. | 184 // SetController message should be sent only for controllees. |
185 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, provider_type_); | 185 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); |
186 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 186 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
187 render_thread_id_, provider_id(), | 187 render_thread_id_, provider_id(), |
188 CreateAndRegisterServiceWorkerHandle(version), | 188 CreateAndRegisterServiceWorkerHandle(version), |
189 should_notify_controllerchange)); | 189 should_notify_controllerchange)); |
190 } | 190 } |
191 | 191 |
192 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 192 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
193 if (!context_) | 193 if (!context_) |
194 return true; // System is shutting down. | 194 return true; // System is shutting down. |
195 if (active_version()) | 195 if (active_version()) |
196 return false; // Unexpected bad message. | 196 return false; // Unexpected bad message. |
197 | 197 |
198 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); | 198 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); |
199 if (!live_version) | 199 if (!live_version) |
200 return true; // Was deleted before it got started. | 200 return true; // Was deleted before it got started. |
201 | 201 |
202 ServiceWorkerVersionInfo info = live_version->GetInfo(); | 202 ServiceWorkerVersionInfo info = live_version->GetInfo(); |
203 if (info.running_status != ServiceWorkerVersion::STARTING || | 203 if (info.running_status != ServiceWorkerVersion::STARTING || |
204 info.process_id != render_process_id_) { | 204 info.process_id != render_process_id_) { |
205 // If we aren't trying to start this version in our process | 205 // If we aren't trying to start this version in our process |
206 // something is amiss. | 206 // something is amiss. |
207 return false; | 207 return false; |
208 } | 208 } |
209 | 209 |
210 running_hosted_version_ = live_version; | 210 running_hosted_version_ = live_version; |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
| 214 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type() |
| 215 const { |
| 216 switch (provider_type_) { |
| 217 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: |
| 218 return blink::WebServiceWorkerClientTypeWindow; |
| 219 case SERVICE_WORKER_PROVIDER_FOR_WORKER: |
| 220 return blink::WebServiceWorkerClientTypeWorker; |
| 221 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: |
| 222 return blink::WebServiceWorkerClientTypeSharedWorker; |
| 223 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: |
| 224 case SERVICE_WORKER_PROVIDER_UNKNOWN: |
| 225 NOTREACHED() << provider_type_; |
| 226 } |
| 227 NOTREACHED() << provider_type_; |
| 228 return blink::WebServiceWorkerClientTypeWindow; |
| 229 } |
| 230 |
214 void ServiceWorkerProviderHost::AssociateRegistration( | 231 void ServiceWorkerProviderHost::AssociateRegistration( |
215 ServiceWorkerRegistration* registration) { | 232 ServiceWorkerRegistration* registration) { |
216 DCHECK(CanAssociateRegistration(registration)); | 233 DCHECK(CanAssociateRegistration(registration)); |
217 associated_registration_ = registration; | 234 associated_registration_ = registration; |
218 AddMatchingRegistration(registration); | 235 AddMatchingRegistration(registration); |
219 SendAssociateRegistrationMessage(); | 236 SendAssociateRegistrationMessage(); |
220 SetControllerVersionAttribute(registration->active_version()); | 237 SetControllerVersionAttribute(registration->active_version()); |
221 } | 238 } |
222 | 239 |
223 void ServiceWorkerProviderHost::DisassociateRegistration() { | 240 void ServiceWorkerProviderHost::DisassociateRegistration() { |
224 queued_events_.clear(); | 241 queued_events_.clear(); |
225 if (!associated_registration_.get()) | 242 if (!associated_registration_.get()) |
226 return; | 243 return; |
227 associated_registration_ = NULL; | 244 associated_registration_ = NULL; |
228 SetControllerVersionAttribute(NULL); | 245 SetControllerVersionAttribute(NULL); |
229 | 246 |
230 if (!dispatcher_host_) | 247 if (!dispatcher_host_) |
231 return; | 248 return; |
232 | 249 |
233 // Disassociation message should be sent only for controllees. | 250 // Disassociation message should be sent only for controllees. |
234 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, provider_type_); | 251 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); |
235 Send(new ServiceWorkerMsg_DisassociateRegistration( | 252 Send(new ServiceWorkerMsg_DisassociateRegistration( |
236 render_thread_id_, provider_id())); | 253 render_thread_id_, provider_id())); |
237 } | 254 } |
238 | 255 |
239 void ServiceWorkerProviderHost::AddMatchingRegistration( | 256 void ServiceWorkerProviderHost::AddMatchingRegistration( |
240 ServiceWorkerRegistration* registration) { | 257 ServiceWorkerRegistration* registration) { |
241 DCHECK(ServiceWorkerUtils::ScopeMatches( | 258 DCHECK(ServiceWorkerUtils::ScopeMatches( |
242 registration->pattern(), document_url_)); | 259 registration->pattern(), document_url_)); |
243 size_t key = registration->pattern().spec().size(); | 260 size_t key = registration->pattern().spec().size(); |
244 if (ContainsKey(matching_registrations_, key)) | 261 if (ContainsKey(matching_registrations_, key)) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 364 |
348 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) { | 365 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) { |
349 BrowserThread::PostTaskAndReplyWithResult( | 366 BrowserThread::PostTaskAndReplyWithResult( |
350 BrowserThread::UI, FROM_HERE, | 367 BrowserThread::UI, FROM_HERE, |
351 base::Bind(&FocusOnUIThread, | 368 base::Bind(&FocusOnUIThread, |
352 render_process_id_, | 369 render_process_id_, |
353 render_frame_id_), | 370 render_frame_id_), |
354 callback); | 371 callback); |
355 } | 372 } |
356 | 373 |
357 void ServiceWorkerProviderHost::GetClientInfo( | 374 void ServiceWorkerProviderHost::GetWindowClientInfo( |
358 const GetClientInfoCallback& callback) const { | 375 const GetClientInfoCallback& callback) const { |
359 BrowserThread::PostTaskAndReplyWithResult( | 376 BrowserThread::PostTaskAndReplyWithResult( |
360 BrowserThread::UI, FROM_HERE, | 377 BrowserThread::UI, FROM_HERE, |
361 base::Bind(&ServiceWorkerProviderHost::GetClientInfoOnUI, | 378 base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI, |
362 render_process_id_, | 379 render_process_id_, render_frame_id_), |
363 render_frame_id_), | |
364 callback); | 380 callback); |
365 } | 381 } |
366 | 382 |
367 // static | 383 // static |
368 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetClientInfoOnUI( | 384 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI( |
369 int render_process_id, int render_frame_id) { | 385 int render_process_id, |
| 386 int render_frame_id) { |
370 RenderFrameHostImpl* render_frame_host = | 387 RenderFrameHostImpl* render_frame_host = |
371 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 388 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
372 if (!render_frame_host) | 389 if (!render_frame_host) |
373 return ServiceWorkerClientInfo(); | 390 return ServiceWorkerClientInfo(); |
374 | 391 |
375 // TODO(mlamouri,michaeln): it is possible to end up collecting information | 392 // TODO(mlamouri,michaeln): it is possible to end up collecting information |
376 // for a frame that is actually being navigated and isn't exactly what we are | 393 // for a frame that is actually being navigated and isn't exactly what we are |
377 // expecting. | 394 // expecting. |
378 return ServiceWorkerClientInfo( | 395 return ServiceWorkerClientInfo( |
379 render_frame_host->GetVisibilityState(), | 396 render_frame_host->GetVisibilityState(), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 578 |
562 ServiceWorkerVersionAttributes attrs; | 579 ServiceWorkerVersionAttributes attrs; |
563 attrs.installing = CreateAndRegisterServiceWorkerHandle( | 580 attrs.installing = CreateAndRegisterServiceWorkerHandle( |
564 associated_registration_->installing_version()); | 581 associated_registration_->installing_version()); |
565 attrs.waiting = CreateAndRegisterServiceWorkerHandle( | 582 attrs.waiting = CreateAndRegisterServiceWorkerHandle( |
566 associated_registration_->waiting_version()); | 583 associated_registration_->waiting_version()); |
567 attrs.active = CreateAndRegisterServiceWorkerHandle( | 584 attrs.active = CreateAndRegisterServiceWorkerHandle( |
568 associated_registration_->active_version()); | 585 associated_registration_->active_version()); |
569 | 586 |
570 // Association message should be sent only for controllees. | 587 // Association message should be sent only for controllees. |
571 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, provider_type_); | 588 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); |
572 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 589 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
573 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); | 590 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
574 } | 591 } |
575 | 592 |
576 void ServiceWorkerProviderHost::IncreaseProcessReference( | 593 void ServiceWorkerProviderHost::IncreaseProcessReference( |
577 const GURL& pattern) { | 594 const GURL& pattern) { |
578 if (context_ && context_->process_manager()) { | 595 if (context_ && context_->process_manager()) { |
579 context_->process_manager()->AddProcessReferenceToPattern( | 596 context_->process_manager()->AddProcessReferenceToPattern( |
580 pattern, render_process_id_); | 597 pattern, render_process_id_); |
581 } | 598 } |
(...skipping 29 matching lines...) Expand all Loading... |
611 return context_ != NULL; | 628 return context_ != NULL; |
612 } | 629 } |
613 | 630 |
614 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 631 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
615 DCHECK(dispatcher_host_); | 632 DCHECK(dispatcher_host_); |
616 DCHECK(IsReadyToSendMessages()); | 633 DCHECK(IsReadyToSendMessages()); |
617 dispatcher_host_->Send(message); | 634 dispatcher_host_->Send(message); |
618 } | 635 } |
619 | 636 |
620 } // namespace content | 637 } // namespace content |
OLD | NEW |