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/command_line.h" |
7 #include "base/guid.h" | 8 #include "base/guid.h" |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
10 #include "content/browser/frame_host/frame_tree.h" | 11 #include "content/browser/frame_host/frame_tree.h" |
11 #include "content/browser/frame_host/frame_tree_node.h" | 12 #include "content/browser/frame_host/frame_tree_node.h" |
12 #include "content/browser/frame_host/render_frame_host_impl.h" | 13 #include "content/browser/frame_host/render_frame_host_impl.h" |
13 #include "content/browser/message_port_message_filter.h" | 14 #include "content/browser/message_port_message_filter.h" |
14 #include "content/browser/service_worker/service_worker_context_core.h" | 15 #include "content/browser/service_worker/service_worker_context_core.h" |
15 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 16 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
16 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" | 17 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
17 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 18 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
18 #include "content/browser/service_worker/service_worker_handle.h" | 19 #include "content/browser/service_worker/service_worker_handle.h" |
19 #include "content/browser/service_worker/service_worker_registration_handle.h" | 20 #include "content/browser/service_worker/service_worker_registration_handle.h" |
20 #include "content/browser/service_worker/service_worker_version.h" | 21 #include "content/browser/service_worker/service_worker_version.h" |
21 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
22 #include "content/common/resource_request_body.h" | 23 #include "content/common/resource_request_body.h" |
23 #include "content/common/service_worker/service_worker_messages.h" | 24 #include "content/common/service_worker/service_worker_messages.h" |
24 #include "content/common/service_worker/service_worker_types.h" | 25 #include "content/common/service_worker/service_worker_types.h" |
25 #include "content/common/service_worker/service_worker_utils.h" | 26 #include "content/common/service_worker/service_worker_utils.h" |
26 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
27 #include "content/public/browser/render_widget_host_view.h" | 28 #include "content/public/browser/render_widget_host_view.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/common/child_process_host.h" | 30 #include "content/public/common/child_process_host.h" |
| 31 #include "content/public/common/content_switches.h" |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 ServiceWorkerClientInfo FocusOnUIThread(int render_process_id, | 37 ServiceWorkerClientInfo FocusOnUIThread(int render_process_id, |
36 int render_frame_id) { | 38 int render_frame_id) { |
37 RenderFrameHostImpl* render_frame_host = | 39 RenderFrameHostImpl* render_frame_host = |
38 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 40 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
39 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 41 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 ServiceWorkerDispatcherHost* dispatcher_host) | 79 ServiceWorkerDispatcherHost* dispatcher_host) |
78 : client_uuid_(base::GenerateGUID()), | 80 : client_uuid_(base::GenerateGUID()), |
79 render_process_id_(render_process_id), | 81 render_process_id_(render_process_id), |
80 route_id_(route_id), | 82 route_id_(route_id), |
81 render_thread_id_(kDocumentMainThreadId), | 83 render_thread_id_(kDocumentMainThreadId), |
82 provider_id_(provider_id), | 84 provider_id_(provider_id), |
83 provider_type_(provider_type), | 85 provider_type_(provider_type), |
84 context_(context), | 86 context_(context), |
85 dispatcher_host_(dispatcher_host), | 87 dispatcher_host_(dispatcher_host), |
86 allow_association_(true) { | 88 allow_association_(true) { |
87 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | |
88 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 89 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
89 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); | 90 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); |
| 91 |
| 92 // PlzNavigate |
| 93 CHECK_IMPLIES(render_process_id == ChildProcessHost::kInvalidUniqueID, |
| 94 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 95 switches::kEnableBrowserSideNavigation)); |
| 96 |
90 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 97 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
91 // Actual thread id is set when the service worker context gets started. | 98 // Actual thread id is set when the service worker context gets started. |
92 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 99 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
93 } | 100 } |
94 context_->RegisterProviderHostByClientID(client_uuid_, this); | 101 context_->RegisterProviderHostByClientID(client_uuid_, this); |
95 } | 102 } |
96 | 103 |
97 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 104 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
98 if (context_) | 105 if (context_) |
99 context_->UnregisterProviderHostByClientID(client_uuid_); | 106 context_->UnregisterProviderHostByClientID(client_uuid_); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 516 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
510 int new_process_id, | 517 int new_process_id, |
511 int new_frame_id, | 518 int new_frame_id, |
512 int new_provider_id, | 519 int new_provider_id, |
513 ServiceWorkerProviderType new_provider_type, | 520 ServiceWorkerProviderType new_provider_type, |
514 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 521 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
515 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 522 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
516 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 523 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
517 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); | 524 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); |
518 | 525 |
519 render_process_id_ = new_process_id; | |
520 route_id_ = new_frame_id; | |
521 render_thread_id_ = kDocumentMainThreadId; | 526 render_thread_id_ = kDocumentMainThreadId; |
522 provider_id_ = new_provider_id; | 527 provider_id_ = new_provider_id; |
523 provider_type_ = new_provider_type; | 528 provider_type_ = new_provider_type; |
524 dispatcher_host_ = new_dispatcher_host; | |
525 | 529 |
526 for (const GURL& pattern : associated_patterns_) | 530 FinalizeInitialization(new_process_id, new_frame_id, new_dispatcher_host); |
527 IncreaseProcessReference(pattern); | 531 } |
528 | 532 |
529 for (auto& key_registration : matching_registrations_) | 533 // PlzNavigate |
530 IncreaseProcessReference(key_registration.second->pattern()); | 534 void ServiceWorkerProviderHost::CompleteNavigationInitialized( |
| 535 int process_id, |
| 536 int frame_routing_id, |
| 537 ServiceWorkerDispatcherHost* dispatcher_host) { |
| 538 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 539 switches::kEnableBrowserSideNavigation)); |
| 540 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 541 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type_); |
| 542 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
531 | 543 |
532 if (associated_registration_.get()) { | 544 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); |
533 SendAssociateRegistrationMessage(); | 545 DCHECK_NE(MSG_ROUTING_NONE, frame_routing_id); |
534 if (dispatcher_host_ && associated_registration_->active_version()) { | 546 |
535 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 547 FinalizeInitialization(process_id, frame_routing_id, dispatcher_host); |
536 render_thread_id_, provider_id(), | |
537 GetOrCreateServiceWorkerHandle( | |
538 associated_registration_->active_version()), | |
539 false /* shouldNotifyControllerChange */)); | |
540 } | |
541 } | |
542 } | 548 } |
543 | 549 |
544 void ServiceWorkerProviderHost::SendUpdateFoundMessage( | 550 void ServiceWorkerProviderHost::SendUpdateFoundMessage( |
545 int registration_handle_id) { | 551 int registration_handle_id) { |
546 if (!dispatcher_host_) | 552 if (!dispatcher_host_) |
547 return; // Could be nullptr in some tests. | 553 return; // Could be nullptr in some tests. |
548 | 554 |
549 if (!IsReadyToSendMessages()) { | 555 if (!IsReadyToSendMessages()) { |
550 queued_events_.push_back( | 556 queued_events_.push_back( |
551 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, | 557 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 bool ServiceWorkerProviderHost::IsContextAlive() { | 683 bool ServiceWorkerProviderHost::IsContextAlive() { |
678 return context_ != NULL; | 684 return context_ != NULL; |
679 } | 685 } |
680 | 686 |
681 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 687 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
682 DCHECK(dispatcher_host_); | 688 DCHECK(dispatcher_host_); |
683 DCHECK(IsReadyToSendMessages()); | 689 DCHECK(IsReadyToSendMessages()); |
684 dispatcher_host_->Send(message); | 690 dispatcher_host_->Send(message); |
685 } | 691 } |
686 | 692 |
| 693 void ServiceWorkerProviderHost::FinalizeInitialization( |
| 694 int process_id, |
| 695 int frame_routing_id, |
| 696 ServiceWorkerDispatcherHost* dispatcher_host) { |
| 697 render_process_id_ = process_id; |
| 698 route_id_ = frame_routing_id; |
| 699 dispatcher_host_ = dispatcher_host; |
| 700 |
| 701 for (const GURL& pattern : associated_patterns_) |
| 702 IncreaseProcessReference(pattern); |
| 703 |
| 704 for (auto& key_registration : matching_registrations_) |
| 705 IncreaseProcessReference(key_registration.second->pattern()); |
| 706 |
| 707 if (associated_registration_.get()) { |
| 708 SendAssociateRegistrationMessage(); |
| 709 if (dispatcher_host_ && associated_registration_->active_version()) { |
| 710 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 711 render_thread_id_, provider_id(), |
| 712 GetOrCreateServiceWorkerHandle( |
| 713 associated_registration_->active_version()), |
| 714 false /* shouldNotifyControllerChange */)); |
| 715 } |
| 716 } |
| 717 } |
| 718 |
687 } // namespace content | 719 } // namespace content |
OLD | NEW |