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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_); | 89 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
88 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 90 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
89 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); | 91 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); |
92 | |
93 // PlzNavigate | |
94 CHECK_IMPLIES(render_process_id == kVirtualProcessIDForBrowserRequest, | |
95 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
96 switches::kEnableBrowserSideNavigation)); | |
97 | |
90 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 98 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
91 // Actual thread id is set when the service worker context gets started. | 99 // Actual thread id is set when the service worker context gets started. |
92 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 100 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
93 } | 101 } |
94 context_->RegisterProviderHostByClientID(client_uuid_, this); | 102 context_->RegisterProviderHostByClientID(client_uuid_, this); |
95 } | 103 } |
96 | 104 |
97 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 105 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
98 if (context_) | 106 if (context_) |
99 context_->UnregisterProviderHostByClientID(client_uuid_); | 107 context_->UnregisterProviderHostByClientID(client_uuid_); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 517 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
510 int new_process_id, | 518 int new_process_id, |
511 int new_frame_id, | 519 int new_frame_id, |
512 int new_provider_id, | 520 int new_provider_id, |
513 ServiceWorkerProviderType new_provider_type, | 521 ServiceWorkerProviderType new_provider_type, |
514 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 522 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
515 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 523 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
516 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 524 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
517 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); | 525 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); |
518 | 526 |
519 render_process_id_ = new_process_id; | |
520 route_id_ = new_frame_id; | |
521 render_thread_id_ = kDocumentMainThreadId; | 527 render_thread_id_ = kDocumentMainThreadId; |
522 provider_id_ = new_provider_id; | 528 provider_id_ = new_provider_id; |
523 provider_type_ = new_provider_type; | 529 provider_type_ = new_provider_type; |
524 dispatcher_host_ = new_dispatcher_host; | |
525 | 530 |
526 for (const GURL& pattern : associated_patterns_) | 531 FinalizeInitialization(new_process_id, new_frame_id, new_dispatcher_host); |
527 IncreaseProcessReference(pattern); | 532 } |
528 | 533 |
529 for (auto& key_registration : matching_registrations_) | 534 // PlzNavigate |
530 IncreaseProcessReference(key_registration.second->pattern()); | 535 void ServiceWorkerProviderHost::CompleteNavigationInitialized( |
536 int process_id, | |
537 int frame_id, | |
538 ServiceWorkerDispatcherHost* dispatcher_host) { | |
539 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
540 switches::kEnableBrowserSideNavigation)); | |
541 DCHECK_EQ(kVirtualProcessIDForBrowserRequest, render_process_id_); | |
542 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type_); | |
543 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | |
531 | 544 |
532 if (associated_registration_.get()) { | 545 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); |
533 SendAssociateRegistrationMessage(); | 546 DCHECK_NE(MSG_ROUTING_NONE, frame_id); |
nasko
2015/10/02 22:09:45
Routing id or FTN id?
Fabrice (no longer in Chrome)
2015/10/06 17:21:38
Done.
| |
534 if (dispatcher_host_ && associated_registration_->active_version()) { | 547 |
535 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 548 FinalizeInitialization(process_id, frame_id, dispatcher_host); |
536 render_thread_id_, provider_id(), | |
537 GetOrCreateServiceWorkerHandle( | |
538 associated_registration_->active_version()), | |
539 false /* shouldNotifyControllerChange */)); | |
540 } | |
541 } | |
542 } | 549 } |
543 | 550 |
544 void ServiceWorkerProviderHost::SendUpdateFoundMessage( | 551 void ServiceWorkerProviderHost::SendUpdateFoundMessage( |
545 int registration_handle_id) { | 552 int registration_handle_id) { |
546 if (!dispatcher_host_) | 553 if (!dispatcher_host_) |
547 return; // Could be nullptr in some tests. | 554 return; // Could be nullptr in some tests. |
548 | 555 |
549 if (!IsReadyToSendMessages()) { | 556 if (!IsReadyToSendMessages()) { |
550 queued_events_.push_back( | 557 queued_events_.push_back( |
551 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, | 558 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 bool ServiceWorkerProviderHost::IsContextAlive() { | 684 bool ServiceWorkerProviderHost::IsContextAlive() { |
678 return context_ != NULL; | 685 return context_ != NULL; |
679 } | 686 } |
680 | 687 |
681 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 688 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
682 DCHECK(dispatcher_host_); | 689 DCHECK(dispatcher_host_); |
683 DCHECK(IsReadyToSendMessages()); | 690 DCHECK(IsReadyToSendMessages()); |
684 dispatcher_host_->Send(message); | 691 dispatcher_host_->Send(message); |
685 } | 692 } |
686 | 693 |
694 void ServiceWorkerProviderHost::FinalizeInitialization( | |
695 int process_id, | |
696 int frame_id, | |
697 ServiceWorkerDispatcherHost* dispatcher_host) { | |
698 render_process_id_ = process_id; | |
699 route_id_ = frame_id; | |
700 dispatcher_host_ = dispatcher_host; | |
701 | |
702 for (const GURL& pattern : associated_patterns_) | |
703 IncreaseProcessReference(pattern); | |
704 | |
705 for (auto& key_registration : matching_registrations_) | |
706 IncreaseProcessReference(key_registration.second->pattern()); | |
707 | |
708 if (associated_registration_.get()) { | |
709 SendAssociateRegistrationMessage(); | |
710 if (dispatcher_host_ && associated_registration_->active_version()) { | |
711 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | |
712 render_thread_id_, provider_id(), | |
713 GetOrCreateServiceWorkerHandle( | |
714 associated_registration_->active_version()), | |
715 false /* shouldNotifyControllerChange */)); | |
716 } | |
717 } | |
718 } | |
719 | |
687 } // namespace content | 720 } // namespace content |
OLD | NEW |