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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/browser_side_navigation_policy.h" | 31 #include "content/public/common/browser_side_navigation_policy.h" |
32 #include "content/public/common/child_process_host.h" | 32 #include "content/public/common/child_process_host.h" |
33 | 33 |
34 namespace content { | 34 namespace content { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 ServiceWorkerClientInfo FocusOnUIThread(int render_process_id, | 38 ServiceWorkerClientInfo FocusOnUIThread(int render_process_id, |
39 int render_frame_id) { | 39 int render_frame_id, |
| 40 const std::string& client_uuid) { |
40 RenderFrameHostImpl* render_frame_host = | 41 RenderFrameHostImpl* render_frame_host = |
41 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 42 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
42 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 43 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
43 WebContents::FromRenderFrameHost(render_frame_host)); | 44 WebContents::FromRenderFrameHost(render_frame_host)); |
44 | 45 |
45 if (!render_frame_host || !web_contents) | 46 if (!render_frame_host || !web_contents) |
46 return ServiceWorkerClientInfo(); | 47 return ServiceWorkerClientInfo(); |
47 | 48 |
48 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); | 49 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); |
49 | 50 |
50 // Focus the frame in the frame tree node, in case it has changed. | 51 // Focus the frame in the frame tree node, in case it has changed. |
51 frame_tree_node->frame_tree()->SetFocusedFrame( | 52 frame_tree_node->frame_tree()->SetFocusedFrame( |
52 frame_tree_node, render_frame_host->GetSiteInstance()); | 53 frame_tree_node, render_frame_host->GetSiteInstance()); |
53 | 54 |
54 // Focus the frame's view to make sure the frame is now considered as focused. | 55 // Focus the frame's view to make sure the frame is now considered as focused. |
55 render_frame_host->GetView()->Focus(); | 56 render_frame_host->GetView()->Focus(); |
56 | 57 |
57 // Move the web contents to the foreground. | 58 // Move the web contents to the foreground. |
58 web_contents->Activate(); | 59 web_contents->Activate(); |
59 | 60 |
60 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id, | 61 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI( |
61 render_frame_id); | 62 render_process_id, render_frame_id, client_uuid); |
62 } | 63 } |
63 | 64 |
64 // PlzNavigate | 65 // PlzNavigate |
65 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps | 66 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps |
66 // going down. | 67 // going down. |
67 int g_next_navigation_provider_id = -2; | 68 int g_next_navigation_provider_id = -2; |
68 | 69 |
69 } // anonymous namespace | 70 } // anonymous namespace |
70 | 71 |
71 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( | 72 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 Send(new ServiceWorkerMsg_MessageToDocument(params)); | 434 Send(new ServiceWorkerMsg_MessageToDocument(params)); |
434 } | 435 } |
435 | 436 |
436 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) { | 437 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) { |
437 if (provider_type_ != SERVICE_WORKER_PROVIDER_FOR_WINDOW) { | 438 if (provider_type_ != SERVICE_WORKER_PROVIDER_FOR_WINDOW) { |
438 callback.Run(ServiceWorkerClientInfo()); | 439 callback.Run(ServiceWorkerClientInfo()); |
439 return; | 440 return; |
440 } | 441 } |
441 BrowserThread::PostTaskAndReplyWithResult( | 442 BrowserThread::PostTaskAndReplyWithResult( |
442 BrowserThread::UI, FROM_HERE, | 443 BrowserThread::UI, FROM_HERE, |
443 base::Bind(&FocusOnUIThread, render_process_id_, route_id_), callback); | 444 base::Bind(&FocusOnUIThread, render_process_id_, route_id_, client_uuid_), |
| 445 callback); |
444 } | 446 } |
445 | 447 |
446 void ServiceWorkerProviderHost::GetWindowClientInfo( | 448 void ServiceWorkerProviderHost::GetWindowClientInfo( |
447 const GetClientInfoCallback& callback) const { | 449 const GetClientInfoCallback& callback) const { |
448 if (provider_type_ != SERVICE_WORKER_PROVIDER_FOR_WINDOW) { | 450 if (provider_type_ != SERVICE_WORKER_PROVIDER_FOR_WINDOW) { |
449 callback.Run(ServiceWorkerClientInfo()); | 451 callback.Run(ServiceWorkerClientInfo()); |
450 return; | 452 return; |
451 } | 453 } |
452 BrowserThread::PostTaskAndReplyWithResult( | 454 BrowserThread::PostTaskAndReplyWithResult( |
453 BrowserThread::UI, FROM_HERE, | 455 BrowserThread::UI, FROM_HERE, |
454 base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI, | 456 base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI, |
455 render_process_id_, route_id_), | 457 render_process_id_, route_id_, client_uuid_), |
456 callback); | 458 callback); |
457 } | 459 } |
458 | 460 |
459 // static | 461 // static |
460 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI( | 462 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI( |
461 int render_process_id, | 463 int render_process_id, |
462 int render_frame_id) { | 464 int render_frame_id, |
| 465 const std::string& client_uuid) { |
463 RenderFrameHostImpl* render_frame_host = | 466 RenderFrameHostImpl* render_frame_host = |
464 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 467 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
465 if (!render_frame_host) | 468 if (!render_frame_host) |
466 return ServiceWorkerClientInfo(); | 469 return ServiceWorkerClientInfo(); |
467 | 470 |
468 // TODO(mlamouri,michaeln): it is possible to end up collecting information | 471 // TODO(mlamouri,michaeln): it is possible to end up collecting information |
469 // for a frame that is actually being navigated and isn't exactly what we are | 472 // for a frame that is actually being navigated and isn't exactly what we are |
470 // expecting. | 473 // expecting. |
471 return ServiceWorkerClientInfo( | 474 return ServiceWorkerClientInfo( |
472 render_frame_host->GetVisibilityState(), render_frame_host->IsFocused(), | 475 client_uuid, render_frame_host->GetVisibilityState(), |
473 render_frame_host->GetLastCommittedURL(), | 476 render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(), |
474 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED | 477 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED |
475 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, | 478 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, |
476 render_frame_host->frame_tree_node()->last_focus_time(), | 479 render_frame_host->frame_tree_node()->last_focus_time(), |
477 blink::WebServiceWorkerClientTypeWindow); | 480 blink::WebServiceWorkerClientTypeWindow); |
478 } | 481 } |
479 | 482 |
480 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( | 483 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( |
481 const GURL& pattern) { | 484 const GURL& pattern) { |
482 associated_patterns_.push_back(pattern); | 485 associated_patterns_.push_back(pattern); |
483 IncreaseProcessReference(pattern); | 486 IncreaseProcessReference(pattern); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 730 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
728 render_thread_id_, provider_id(), | 731 render_thread_id_, provider_id(), |
729 GetOrCreateServiceWorkerHandle( | 732 GetOrCreateServiceWorkerHandle( |
730 associated_registration_->active_version()), | 733 associated_registration_->active_version()), |
731 false /* shouldNotifyControllerChange */)); | 734 false /* shouldNotifyControllerChange */)); |
732 } | 735 } |
733 } | 736 } |
734 } | 737 } |
735 | 738 |
736 } // namespace content | 739 } // namespace content |
OLD | NEW |