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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 | 84 |
85 // static | 85 // static |
86 std::unique_ptr<ServiceWorkerProviderHost> | 86 std::unique_ptr<ServiceWorkerProviderHost> |
87 ServiceWorkerProviderHost::PreCreateNavigationHost( | 87 ServiceWorkerProviderHost::PreCreateNavigationHost( |
88 base::WeakPtr<ServiceWorkerContextCore> context, | 88 base::WeakPtr<ServiceWorkerContextCore> context, |
89 bool are_ancestors_secure, | 89 bool are_ancestors_secure, |
90 const WebContentsGetter& web_contents_getter) { | 90 const WebContentsGetter& web_contents_getter) { |
91 CHECK(IsBrowserSideNavigationEnabled()); | 91 CHECK(IsBrowserSideNavigationEnabled()); |
92 // Generate a new browser-assigned id for the host. | 92 // Generate a new browser-assigned id for the host. |
93 int provider_id = g_next_navigation_provider_id--; | 93 int provider_id = g_next_navigation_provider_id--; |
94 auto host = base::MakeUnique<ServiceWorkerProviderHost>( | 94 auto host = base::WrapUnique(new ServiceWorkerProviderHost( |
dcheng
2017/02/14 08:47:46
In general, base::WrapUnique(new T(...)) should be
shimazu
2017/02/15 02:24:18
That's because the constructor is private:
https:/
dcheng
2017/02/15 04:29:35
Ah oops. Thanks for pointing that out.
| |
95 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, | 95 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, |
96 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 96 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, context, |
97 are_ancestors_secure ? FrameSecurityLevel::SECURE | 97 nullptr)); |
98 : FrameSecurityLevel::INSECURE, | |
99 context, nullptr); | |
100 host->web_contents_getter_ = web_contents_getter; | 98 host->web_contents_getter_ = web_contents_getter; |
101 return host; | 99 return host; |
102 } | 100 } |
103 | 101 |
102 // static | |
103 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( | |
104 int process_id, | |
105 ServiceWorkerProviderHostInfo info, | |
106 base::WeakPtr<ServiceWorkerContextCore> context, | |
107 ServiceWorkerDispatcherHost* dispatcher_host) { | |
108 return base::WrapUnique(new ServiceWorkerProviderHost( | |
109 process_id, info.route_id, info.provider_id, info.type, | |
110 info.is_parent_frame_secure, context, dispatcher_host)); | |
111 } | |
112 | |
104 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 113 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
105 int render_process_id, | 114 int render_process_id, |
106 int route_id, | 115 int route_id, |
107 int provider_id, | 116 int provider_id, |
108 ServiceWorkerProviderType provider_type, | 117 ServiceWorkerProviderType provider_type, |
109 FrameSecurityLevel parent_frame_security_level, | 118 bool is_parent_frame_secure, |
110 base::WeakPtr<ServiceWorkerContextCore> context, | 119 base::WeakPtr<ServiceWorkerContextCore> context, |
111 ServiceWorkerDispatcherHost* dispatcher_host) | 120 ServiceWorkerDispatcherHost* dispatcher_host) |
112 : client_uuid_(base::GenerateGUID()), | 121 : client_uuid_(base::GenerateGUID()), |
113 render_process_id_(render_process_id), | 122 render_process_id_(render_process_id), |
114 route_id_(route_id), | 123 route_id_(route_id), |
115 render_thread_id_(kDocumentMainThreadId), | 124 render_thread_id_(kDocumentMainThreadId), |
116 provider_id_(provider_id), | 125 provider_id_(provider_id), |
117 provider_type_(provider_type), | 126 provider_type_(provider_type), |
118 parent_frame_security_level_(parent_frame_security_level), | 127 is_parent_frame_secure_(is_parent_frame_secure), |
119 context_(context), | 128 context_(context), |
120 dispatcher_host_(dispatcher_host), | 129 dispatcher_host_(dispatcher_host), |
121 allow_association_(true) { | 130 allow_association_(true) { |
122 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 131 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
123 | 132 |
124 // PlzNavigate | 133 // PlzNavigate |
125 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 134 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
126 IsBrowserSideNavigationEnabled()); | 135 IsBrowserSideNavigationEnabled()); |
127 | 136 |
128 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 137 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 488 |
480 bool ServiceWorkerProviderHost::GetRegistrationForReady( | 489 bool ServiceWorkerProviderHost::GetRegistrationForReady( |
481 const GetRegistrationForReadyCallback& callback) { | 490 const GetRegistrationForReadyCallback& callback) { |
482 if (get_ready_callback_) | 491 if (get_ready_callback_) |
483 return false; | 492 return false; |
484 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); | 493 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); |
485 ReturnRegistrationForReadyIfNeeded(); | 494 ReturnRegistrationForReadyIfNeeded(); |
486 return true; | 495 return true; |
487 } | 496 } |
488 | 497 |
489 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | 498 std::unique_ptr<ServiceWorkerProviderHost> |
499 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | |
490 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 500 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
491 DCHECK_NE(MSG_ROUTING_NONE, route_id_); | 501 DCHECK_NE(MSG_ROUTING_NONE, route_id_); |
492 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | 502 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
493 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 503 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
494 | 504 |
505 std::unique_ptr<ServiceWorkerProviderHost> new_provider_host = | |
506 base::WrapUnique(new ServiceWorkerProviderHost( | |
507 process_id(), frame_id(), provider_id(), provider_type(), | |
508 is_parent_frame_secure(), context_, dispatcher_host())); | |
509 | |
495 for (const GURL& pattern : associated_patterns_) | 510 for (const GURL& pattern : associated_patterns_) |
496 DecreaseProcessReference(pattern); | 511 DecreaseProcessReference(pattern); |
497 | 512 |
498 for (auto& key_registration : matching_registrations_) | 513 for (auto& key_registration : matching_registrations_) |
499 DecreaseProcessReference(key_registration.second->pattern()); | 514 DecreaseProcessReference(key_registration.second->pattern()); |
500 | 515 |
501 if (associated_registration_.get()) { | 516 if (associated_registration_.get()) { |
502 if (dispatcher_host_) { | 517 if (dispatcher_host_) { |
503 Send(new ServiceWorkerMsg_DisassociateRegistration( | 518 Send(new ServiceWorkerMsg_DisassociateRegistration( |
504 render_thread_id_, provider_id())); | 519 render_thread_id_, provider_id())); |
505 } | 520 } |
506 } | 521 } |
507 | 522 |
508 render_process_id_ = ChildProcessHost::kInvalidUniqueID; | 523 render_process_id_ = ChildProcessHost::kInvalidUniqueID; |
509 route_id_ = MSG_ROUTING_NONE; | 524 route_id_ = MSG_ROUTING_NONE; |
510 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 525 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
511 provider_id_ = kInvalidServiceWorkerProviderId; | 526 provider_id_ = kInvalidServiceWorkerProviderId; |
512 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; | 527 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; |
513 dispatcher_host_ = nullptr; | 528 dispatcher_host_ = nullptr; |
529 return new_provider_host; | |
514 } | 530 } |
515 | 531 |
516 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 532 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
517 int new_process_id, | 533 int new_process_id, |
518 int new_frame_id, | 534 int new_frame_id, |
519 int new_provider_id, | 535 int new_provider_id, |
520 ServiceWorkerProviderType new_provider_type, | 536 ServiceWorkerProviderType new_provider_type, |
521 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 537 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
522 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 538 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
523 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 539 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 746 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
731 render_thread_id_, provider_id(), | 747 render_thread_id_, provider_id(), |
732 GetOrCreateServiceWorkerHandle( | 748 GetOrCreateServiceWorkerHandle( |
733 associated_registration_->active_version()), | 749 associated_registration_->active_version()), |
734 false /* shouldNotifyControllerChange */)); | 750 false /* shouldNotifyControllerChange */)); |
735 } | 751 } |
736 } | 752 } |
737 } | 753 } |
738 | 754 |
739 } // namespace content | 755 } // namespace content |
OLD | NEW |