Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 52 | 54 |
| 53 // Move the web contents to the foreground. | 55 // Move the web contents to the foreground. |
| 54 web_contents->Activate(); | 56 web_contents->Activate(); |
| 55 | 57 |
| 56 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id, | 58 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id, |
| 57 render_frame_id); | 59 render_frame_id); |
| 58 } | 60 } |
| 59 | 61 |
| 60 } // anonymous namespace | 62 } // anonymous namespace |
| 61 | 63 |
| 64 // PlzNavigate | |
| 65 int ServiceWorkerProviderHost::kVirtualProcessIDForBrowserRequest = -2; | |
| 66 | |
| 67 // PlzNavigate | |
| 68 int ServiceWorkerProviderHost::next_navigation_provider_id_ = -2; | |
| 69 | |
| 70 // PlzNavigate | |
| 71 int ServiceWorkerProviderHost::GetNextNavigationProviderId() { | |
|
michaeln
2015/10/01 01:42:16
please DCHECK_CURRENTLY_ON(BrowserThread::UI), sin
Fabrice (no longer in Chrome)
2015/10/01 18:29:55
I moved it so there should no longer be any confus
| |
| 72 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
|
michaeln
2015/10/01 01:42:16
Does this need to be a runtime check? I don't thin
Fabrice (no longer in Chrome)
2015/10/01 18:29:55
It's called in both cases actually, when initializ
| |
| 73 switches::kEnableBrowserSideNavigation)) { | |
| 74 return next_navigation_provider_id_--; | |
| 75 } | |
| 76 return kInvalidServiceWorkerProviderId; | |
| 77 } | |
| 78 | |
| 62 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( | 79 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
| 63 const GetRegistrationForReadyCallback& callback) | 80 const GetRegistrationForReadyCallback& callback) |
| 64 : callback(callback), | 81 : callback(callback), |
| 65 called(false) { | 82 called(false) { |
| 66 } | 83 } |
| 67 | 84 |
| 68 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { | 85 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { |
| 69 } | 86 } |
| 70 | 87 |
| 71 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 88 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| 72 int render_process_id, | 89 int render_process_id, |
| 73 int route_id, | 90 int route_id, |
| 74 int provider_id, | 91 int provider_id, |
| 75 ServiceWorkerProviderType provider_type, | 92 ServiceWorkerProviderType provider_type, |
| 76 base::WeakPtr<ServiceWorkerContextCore> context, | 93 base::WeakPtr<ServiceWorkerContextCore> context, |
| 77 ServiceWorkerDispatcherHost* dispatcher_host) | 94 ServiceWorkerDispatcherHost* dispatcher_host) |
| 78 : client_uuid_(base::GenerateGUID()), | 95 : client_uuid_(base::GenerateGUID()), |
| 79 render_process_id_(render_process_id), | 96 render_process_id_(render_process_id), |
| 80 route_id_(route_id), | 97 route_id_(route_id), |
| 81 render_thread_id_(kDocumentMainThreadId), | 98 render_thread_id_(kDocumentMainThreadId), |
| 82 provider_id_(provider_id), | 99 provider_id_(provider_id), |
| 83 provider_type_(provider_type), | 100 provider_type_(provider_type), |
| 84 context_(context), | 101 context_(context), |
| 85 dispatcher_host_(dispatcher_host), | 102 dispatcher_host_(dispatcher_host), |
| 86 allow_association_(true) { | 103 allow_association_(true) { |
| 87 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 104 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 88 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 105 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| 89 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); | 106 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_SANDBOXED_FRAME, provider_type_); |
| 107 | |
| 108 // PlzNavigate | |
| 109 CHECK_IMPLIES(render_process_id == kVirtualProcessIDForBrowserRequest, | |
| 110 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 111 switches::kEnableBrowserSideNavigation)); | |
| 112 | |
| 90 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 113 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
| 91 // Actual thread id is set when the service worker context gets started. | 114 // Actual thread id is set when the service worker context gets started. |
| 92 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 115 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| 93 } | 116 } |
| 94 context_->RegisterProviderHostByClientID(client_uuid_, this); | 117 context_->RegisterProviderHostByClientID(client_uuid_, this); |
| 95 } | 118 } |
| 96 | 119 |
| 97 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 120 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| 98 if (context_) | 121 if (context_) |
| 99 context_->UnregisterProviderHostByClientID(client_uuid_); | 122 context_->UnregisterProviderHostByClientID(client_uuid_); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; | 528 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; |
| 506 dispatcher_host_ = nullptr; | 529 dispatcher_host_ = nullptr; |
| 507 } | 530 } |
| 508 | 531 |
| 509 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 532 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
| 510 int new_process_id, | 533 int new_process_id, |
| 511 int new_frame_id, | 534 int new_frame_id, |
| 512 int new_provider_id, | 535 int new_provider_id, |
| 513 ServiceWorkerProviderType new_provider_type, | 536 ServiceWorkerProviderType new_provider_type, |
| 514 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 537 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
| 538 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 539 switches::kEnableBrowserSideNavigation)); | |
|
michaeln
2015/10/01 01:42:16
ah, i didn't notice the ! char!
Ok, thanx for poi
Fabrice (no longer in Chrome)
2015/10/01 18:29:55
I think we should leave a CHECK here as stated abo
michaeln
2015/10/01 23:11:12
If this check is to defend against bad ipc inputs,
Fabrice (no longer in Chrome)
2015/10/02 16:37:34
Looking at the calling stack, this is actually tak
| |
| 515 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 540 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 516 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 541 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
| 517 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); | 542 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); |
| 518 | 543 |
| 519 render_process_id_ = new_process_id; | 544 render_process_id_ = new_process_id; |
| 520 route_id_ = new_frame_id; | 545 route_id_ = new_frame_id; |
| 521 render_thread_id_ = kDocumentMainThreadId; | 546 render_thread_id_ = kDocumentMainThreadId; |
| 522 provider_id_ = new_provider_id; | 547 provider_id_ = new_provider_id; |
| 523 provider_type_ = new_provider_type; | 548 provider_type_ = new_provider_type; |
| 524 dispatcher_host_ = new_dispatcher_host; | 549 dispatcher_host_ = new_dispatcher_host; |
| 525 | 550 |
| 526 for (const GURL& pattern : associated_patterns_) | 551 for (const GURL& pattern : associated_patterns_) |
| 527 IncreaseProcessReference(pattern); | 552 IncreaseProcessReference(pattern); |
| 528 | 553 |
| 529 for (auto& key_registration : matching_registrations_) | 554 for (auto& key_registration : matching_registrations_) |
| 530 IncreaseProcessReference(key_registration.second->pattern()); | 555 IncreaseProcessReference(key_registration.second->pattern()); |
| 531 | 556 |
| 532 if (associated_registration_.get()) { | 557 if (associated_registration_.get()) { |
| 533 SendAssociateRegistrationMessage(); | 558 SendAssociateRegistrationMessage(); |
| 534 if (dispatcher_host_ && associated_registration_->active_version()) { | 559 if (dispatcher_host_ && associated_registration_->active_version()) { |
| 535 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 560 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 536 render_thread_id_, provider_id(), | 561 render_thread_id_, provider_id(), |
| 537 GetOrCreateServiceWorkerHandle( | 562 GetOrCreateServiceWorkerHandle( |
| 538 associated_registration_->active_version()), | 563 associated_registration_->active_version()), |
| 539 false /* shouldNotifyControllerChange */)); | 564 false /* shouldNotifyControllerChange */)); |
| 540 } | 565 } |
| 541 } | 566 } |
| 542 } | 567 } |
| 543 | 568 |
| 569 // PlzNavigate | |
| 570 void ServiceWorkerProviderHost::CompleteNavigationInitialized( | |
| 571 int process_id, | |
| 572 int frame_id, | |
| 573 ServiceWorkerDispatcherHost* dispatcher_host) { | |
| 574 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
|
michaeln
2015/10/01 01:42:16
same question about CHECK vs DCHECK?
Fabrice (no longer in Chrome)
2015/10/01 18:29:55
If we get here, it means the browser received a ne
michaeln
2015/10/01 23:11:11
Please use BadMessageRecieved for that and put the
| |
| 575 switches::kEnableBrowserSideNavigation)); | |
| 576 DCHECK_EQ(kVirtualProcessIDForBrowserRequest, render_process_id_); | |
| 577 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type_); | |
| 578 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | |
| 579 | |
| 580 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); | |
| 581 DCHECK_NE(MSG_ROUTING_NONE, frame_id); | |
| 582 | |
| 583 render_process_id_ = process_id; | |
| 584 route_id_ = frame_id; | |
| 585 dispatcher_host_ = dispatcher_host; | |
| 586 | |
| 587 for (const GURL& pattern : associated_patterns_) | |
|
michaeln
2015/10/01 01:42:16
CompleteCrossSiteTransfer and CompleteNavigationIn
Fabrice (no longer in Chrome)
2015/10/01 18:29:55
Done.
| |
| 588 IncreaseProcessReference(pattern); | |
| 589 | |
| 590 for (auto& key_registration : matching_registrations_) | |
| 591 IncreaseProcessReference(key_registration.second->pattern()); | |
| 592 | |
| 593 if (associated_registration_.get()) { | |
| 594 SendAssociateRegistrationMessage(); | |
| 595 if (dispatcher_host_ && associated_registration_->active_version()) { | |
| 596 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | |
| 597 render_thread_id_, provider_id(), | |
| 598 GetOrCreateServiceWorkerHandle( | |
| 599 associated_registration_->active_version()), | |
| 600 false /* shouldNotifyControllerChange */)); | |
| 601 } | |
| 602 } | |
| 603 } | |
| 604 | |
| 544 void ServiceWorkerProviderHost::SendUpdateFoundMessage( | 605 void ServiceWorkerProviderHost::SendUpdateFoundMessage( |
| 545 int registration_handle_id) { | 606 int registration_handle_id) { |
| 546 if (!dispatcher_host_) | 607 if (!dispatcher_host_) |
| 547 return; // Could be nullptr in some tests. | 608 return; // Could be nullptr in some tests. |
| 548 | 609 |
| 549 if (!IsReadyToSendMessages()) { | 610 if (!IsReadyToSendMessages()) { |
| 550 queued_events_.push_back( | 611 queued_events_.push_back( |
| 551 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, | 612 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, |
| 552 AsWeakPtr(), registration_handle_id)); | 613 AsWeakPtr(), registration_handle_id)); |
| 553 return; | 614 return; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 return context_ != NULL; | 739 return context_ != NULL; |
| 679 } | 740 } |
| 680 | 741 |
| 681 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 742 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
| 682 DCHECK(dispatcher_host_); | 743 DCHECK(dispatcher_host_); |
| 683 DCHECK(IsReadyToSendMessages()); | 744 DCHECK(IsReadyToSendMessages()); |
| 684 dispatcher_host_->Send(message); | 745 dispatcher_host_->Send(message); |
| 685 } | 746 } |
| 686 | 747 |
| 687 } // namespace content | 748 } // namespace content |
| OLD | NEW |