Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Rebased/Fixed unittests when BrowserSideNavigation is enabled Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ResourceType resource_type) 54 ResourceType resource_type)
55 : ServiceWorkerRequestHandler(context, 55 : ServiceWorkerRequestHandler(context,
56 provider_host, 56 provider_host,
57 blob_storage_context, 57 blob_storage_context,
58 resource_type) {} 58 resource_type) {}
59 ~ServiceWorkerURLTrackingRequestHandler() override {} 59 ~ServiceWorkerURLTrackingRequestHandler() override {}
60 60
61 // Called via custom URLRequestJobFactory. 61 // Called via custom URLRequestJobFactory.
62 net::URLRequestJob* MaybeCreateJob( 62 net::URLRequestJob* MaybeCreateJob(
63 net::URLRequest* request, 63 net::URLRequest* request,
64 net::NetworkDelegate* network_delegate, 64 net::NetworkDelegate* /* network_delegate */,
65 ResourceContext* resource_context) override { 65 ResourceContext* /* resource_context */) override {
66 // |provider_host_| may have been deleted when the request is resumed. 66 // |provider_host_| may have been deleted when the request is resumed.
67 if (!provider_host_) 67 if (!provider_host_)
68 return nullptr; 68 return nullptr;
69 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); 69 const GURL stripped_url = net::SimplifyUrlForRequest(request->url());
70 provider_host_->SetDocumentUrl(stripped_url); 70 provider_host_->SetDocumentUrl(stripped_url);
71 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); 71 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies());
72 return nullptr; 72 return nullptr;
73 } 73 }
74 74
75 private: 75 private:
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler); 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler);
77 }; 77 };
78 78
79 void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context,
80 int process_id,
81 int provider_id) {
82 TRACE_EVENT0("ServiceWorker",
83 "ServiceWorkerProviderHost::RemoveProviderHost");
84 if (!context)
85 return;
86 if (!context->GetProviderHost(process_id, provider_id)) {
87 // PlzNavigate: in some cancellation of navigation cases, it is possible
88 // for the pre-created host to have been destroyed before being claimed by
89 // the renderer. The provider is then destroyed in the renderer, and no
90 // matching host will be found.
91 CHECK(IsBrowserSideNavigationEnabled() &&
92 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id));
93 return;
94 }
95 context->RemoveProviderHost(process_id, provider_id);
96 }
97
79 } // anonymous namespace 98 } // anonymous namespace
80 99
81 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( 100 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback(
82 const GetRegistrationForReadyCallback& callback) 101 const GetRegistrationForReadyCallback& callback)
83 : callback(callback), 102 : callback(callback),
84 called(false) { 103 called(false) {
85 } 104 }
86 105
87 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { 106 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() {
88 } 107 }
89 108
90 // static 109 // static
91 std::unique_ptr<ServiceWorkerProviderHost> 110 std::unique_ptr<ServiceWorkerProviderHost>
92 ServiceWorkerProviderHost::PreCreateNavigationHost( 111 ServiceWorkerProviderHost::PreCreateNavigationHost(
93 base::WeakPtr<ServiceWorkerContextCore> context, 112 base::WeakPtr<ServiceWorkerContextCore> context,
94 bool are_ancestors_secure, 113 bool are_ancestors_secure,
95 const WebContentsGetter& web_contents_getter) { 114 const WebContentsGetter& web_contents_getter) {
96 CHECK(IsBrowserSideNavigationEnabled()); 115 CHECK(IsBrowserSideNavigationEnabled());
97 // Generate a new browser-assigned id for the host. 116 // Generate a new browser-assigned id for the host.
98 int provider_id = g_next_navigation_provider_id--; 117 int provider_id = g_next_navigation_provider_id--;
99 auto host = base::WrapUnique(new ServiceWorkerProviderHost( 118 auto host = base::WrapUnique(new ServiceWorkerProviderHost(
100 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, 119 ChildProcessHost::kInvalidUniqueID,
101 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, context, 120 ServiceWorkerProviderHostInfo(provider_id, MSG_ROUTING_NONE,
102 nullptr)); 121 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
122 are_ancestors_secure),
123 context, nullptr));
103 host->web_contents_getter_ = web_contents_getter; 124 host->web_contents_getter_ = web_contents_getter;
104 return host; 125 return host;
105 } 126 }
106 127
107 // static 128 // static
108 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( 129 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create(
109 int process_id, 130 int process_id,
110 ServiceWorkerProviderHostInfo info, 131 ServiceWorkerProviderHostInfo info,
111 base::WeakPtr<ServiceWorkerContextCore> context, 132 base::WeakPtr<ServiceWorkerContextCore> context,
112 ServiceWorkerDispatcherHost* dispatcher_host) { 133 ServiceWorkerDispatcherHost* dispatcher_host) {
113 return base::WrapUnique(new ServiceWorkerProviderHost( 134 return base::WrapUnique(new ServiceWorkerProviderHost(
114 process_id, info.route_id, info.provider_id, info.type, 135 process_id, std::move(info), context, dispatcher_host));
115 info.is_parent_frame_secure, context, dispatcher_host));
116 } 136 }
117 137
118 void ServiceWorkerProviderHost::BindWorkerFetchContext( 138 void ServiceWorkerProviderHost::BindWorkerFetchContext(
119 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) { 139 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) {
120 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch)); 140 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch));
121 mojom::ServiceWorkerWorkerClientAssociatedPtr client; 141 mojom::ServiceWorkerWorkerClientAssociatedPtr client;
122 client.Bind(std::move(client_ptr_info)); 142 client.Bind(std::move(client_ptr_info));
123 client.set_connection_error_handler( 143 client.set_connection_error_handler(
124 base::Bind(&ServiceWorkerProviderHost::UnregisterWorkerFetchContext, 144 base::Bind(&ServiceWorkerProviderHost::UnregisterWorkerFetchContext,
125 base::Unretained(this), client.get())); 145 base::Unretained(this), client.get()));
126 146
127 if (controlling_version_) 147 if (controlling_version_)
128 client->SetControllerServiceWorker(controlling_version_->version_id()); 148 client->SetControllerServiceWorker(controlling_version_->version_id());
129 149
130 auto result = worker_clients_.insert( 150 auto result = worker_clients_.insert(
131 std::make_pair<mojom::ServiceWorkerWorkerClient*, 151 std::make_pair<mojom::ServiceWorkerWorkerClient*,
132 mojom::ServiceWorkerWorkerClientAssociatedPtr>( 152 mojom::ServiceWorkerWorkerClientAssociatedPtr>(
133 client.get(), std::move(client))); 153 client.get(), std::move(client)));
134 DCHECK(result.second); 154 DCHECK(result.second);
135 } 155 }
136 156
137 void ServiceWorkerProviderHost::UnregisterWorkerFetchContext( 157 void ServiceWorkerProviderHost::UnregisterWorkerFetchContext(
138 mojom::ServiceWorkerWorkerClient* client) { 158 mojom::ServiceWorkerWorkerClient* client) {
139 DCHECK(worker_clients_.count(client)); 159 DCHECK(worker_clients_.count(client));
140 worker_clients_.erase(client); 160 worker_clients_.erase(client);
141 } 161 }
142 162
143 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 163 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
144 int render_process_id, 164 int render_process_id,
145 int route_id, 165 ServiceWorkerProviderHostInfo info,
146 int provider_id,
147 ServiceWorkerProviderType provider_type,
148 bool is_parent_frame_secure,
149 base::WeakPtr<ServiceWorkerContextCore> context, 166 base::WeakPtr<ServiceWorkerContextCore> context,
150 ServiceWorkerDispatcherHost* dispatcher_host) 167 ServiceWorkerDispatcherHost* dispatcher_host)
151 : client_uuid_(base::GenerateGUID()), 168 : client_uuid_(base::GenerateGUID()),
152 render_process_id_(render_process_id), 169 render_process_id_(render_process_id),
153 route_id_(route_id),
154 render_thread_id_(kDocumentMainThreadId), 170 render_thread_id_(kDocumentMainThreadId),
155 provider_id_(provider_id), 171 info_(std::move(info)),
156 provider_type_(provider_type),
157 is_parent_frame_secure_(is_parent_frame_secure),
158 context_(context), 172 context_(context),
159 dispatcher_host_(dispatcher_host), 173 dispatcher_host_(dispatcher_host),
160 allow_association_(true) { 174 allow_association_(true),
161 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 175 binding_(this) {
176 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
162 177
163 // PlzNavigate 178 // PlzNavigate
164 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || 179 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
165 IsBrowserSideNavigationEnabled()); 180 IsBrowserSideNavigationEnabled());
166 181
167 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { 182 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
168 // Actual thread id is set when the service worker context gets started. 183 // Actual thread id is set when the service worker context gets started.
169 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 184 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
170 } 185 }
171 context_->RegisterProviderHostByClientID(client_uuid_, this); 186 context_->RegisterProviderHostByClientID(client_uuid_, this);
187
188 // PlzNavigate
189 // |client_| and |binding_| will be bound on CompleteNavigationInitialized.
190 if (IsBrowserSideNavigationEnabled()) {
191 DCHECK(!info.client_ptr_info.is_valid() && !info.host_request.is_pending());
192 return;
193 }
194
195 client_.Bind(std::move(info_.client_ptr_info));
196 binding_.Bind(std::move(info_.host_request));
197 binding_.set_connection_error_handler(base::Bind(
198 &RemoveProviderHost, context_, render_process_id, info_.provider_id));
172 } 199 }
173 200
174 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 201 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
175 if (context_) 202 if (context_)
176 context_->UnregisterProviderHostByClientID(client_uuid_); 203 context_->UnregisterProviderHostByClientID(client_uuid_);
177 204
178 // Clear docurl so the deferred activation of a waiting worker 205 // Clear docurl so the deferred activation of a waiting worker
179 // won't associate the new version with a provider being destroyed. 206 // won't associate the new version with a provider being destroyed.
180 document_url_ = GURL(); 207 document_url_ = GURL();
181 if (controlling_version_.get()) 208 if (controlling_version_.get())
182 controlling_version_->RemoveControllee(this); 209 controlling_version_->RemoveControllee(this);
183 210
184 RemoveAllMatchingRegistrations(); 211 RemoveAllMatchingRegistrations();
185 212
186 for (const GURL& pattern : associated_patterns_) 213 for (const GURL& pattern : associated_patterns_)
187 DecreaseProcessReference(pattern); 214 DecreaseProcessReference(pattern);
188 } 215 }
189 216
190 int ServiceWorkerProviderHost::frame_id() const { 217 int ServiceWorkerProviderHost::frame_id() const {
191 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) 218 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_WINDOW)
192 return route_id_; 219 return info_.route_id;
193 return MSG_ROUTING_NONE; 220 return MSG_ROUTING_NONE;
194 } 221 }
195 222
196 bool ServiceWorkerProviderHost::IsContextSecureForServiceWorker() const { 223 bool ServiceWorkerProviderHost::IsContextSecureForServiceWorker() const {
197 // |document_url_| may be empty if loading has not begun, or 224 // |document_url_| may be empty if loading has not begun, or
198 // ServiceWorkerRequestHandler didn't handle the load (because e.g. another 225 // ServiceWorkerRequestHandler didn't handle the load (because e.g. another
199 // handler did first, or the initial request URL was such that 226 // handler did first, or the initial request URL was such that
200 // OriginCanAccessServiceWorkers returned false). 227 // OriginCanAccessServiceWorkers returned false).
201 if (!document_url_.is_valid()) 228 if (!document_url_.is_valid())
202 return false; 229 return false;
203 if (!OriginCanAccessServiceWorkers(document_url_)) 230 if (!OriginCanAccessServiceWorkers(document_url_))
204 return false; 231 return false;
205 232
206 if (is_parent_frame_secure()) 233 if (is_parent_frame_secure())
207 return true; 234 return true;
208 235
209 std::set<std::string> schemes; 236 std::set<std::string> schemes;
210 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( 237 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist(
211 &schemes); 238 &schemes);
212 return schemes.find(document_url().scheme()) != schemes.end(); 239 return schemes.find(document_url().scheme()) != schemes.end();
213 } 240 }
214 241
215 void ServiceWorkerProviderHost::OnVersionAttributesChanged( 242 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
216 ServiceWorkerRegistration* registration, 243 ServiceWorkerRegistration* registration,
217 ChangedVersionAttributesMask changed_mask, 244 ChangedVersionAttributesMask changed_mask,
218 const ServiceWorkerRegistrationInfo& info) { 245 const ServiceWorkerRegistrationInfo& /* info */) {
219 if (!get_ready_callback_ || get_ready_callback_->called) 246 if (!get_ready_callback_ || get_ready_callback_->called)
220 return; 247 return;
221 if (changed_mask.active_changed() && registration->active_version()) { 248 if (changed_mask.active_changed() && registration->active_version()) {
222 // Wait until the state change so we don't send the get for ready 249 // Wait until the state change so we don't send the get for ready
223 // registration complete message before set version attributes message. 250 // registration complete message before set version attributes message.
224 registration->active_version()->RegisterStatusChangeCallback(base::Bind( 251 registration->active_version()->RegisterStatusChangeCallback(base::Bind(
225 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded, 252 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded,
226 AsWeakPtr())); 253 AsWeakPtr()));
227 } 254 }
228 } 255 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 324
298 void ServiceWorkerProviderHost::SetHostedVersion( 325 void ServiceWorkerProviderHost::SetHostedVersion(
299 ServiceWorkerVersion* version) { 326 ServiceWorkerVersion* version) {
300 DCHECK(!IsProviderForClient()); 327 DCHECK(!IsProviderForClient());
301 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, version->running_status()); 328 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, version->running_status());
302 DCHECK_EQ(render_process_id_, version->embedded_worker()->process_id()); 329 DCHECK_EQ(render_process_id_, version->embedded_worker()->process_id());
303 running_hosted_version_ = version; 330 running_hosted_version_ = version;
304 } 331 }
305 332
306 bool ServiceWorkerProviderHost::IsProviderForClient() const { 333 bool ServiceWorkerProviderHost::IsProviderForClient() const {
307 switch (provider_type_) { 334 switch (info_.type) {
308 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: 335 case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
309 case SERVICE_WORKER_PROVIDER_FOR_WORKER: 336 case SERVICE_WORKER_PROVIDER_FOR_WORKER:
310 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: 337 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
311 return true; 338 return true;
312 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: 339 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER:
313 return false; 340 return false;
314 case SERVICE_WORKER_PROVIDER_UNKNOWN: 341 case SERVICE_WORKER_PROVIDER_UNKNOWN:
315 NOTREACHED() << provider_type_; 342 NOTREACHED() << info_.type;
316 } 343 }
317 NOTREACHED() << provider_type_; 344 NOTREACHED() << info_.type;
318 return false; 345 return false;
319 } 346 }
320 347
321 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type() 348 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type()
322 const { 349 const {
323 switch (provider_type_) { 350 switch (info_.type) {
324 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: 351 case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
325 return blink::kWebServiceWorkerClientTypeWindow; 352 return blink::kWebServiceWorkerClientTypeWindow;
326 case SERVICE_WORKER_PROVIDER_FOR_WORKER: 353 case SERVICE_WORKER_PROVIDER_FOR_WORKER:
327 return blink::kWebServiceWorkerClientTypeWorker; 354 return blink::kWebServiceWorkerClientTypeWorker;
328 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: 355 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
329 return blink::kWebServiceWorkerClientTypeSharedWorker; 356 return blink::kWebServiceWorkerClientTypeSharedWorker;
330 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: 357 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER:
331 case SERVICE_WORKER_PROVIDER_UNKNOWN: 358 case SERVICE_WORKER_PROVIDER_UNKNOWN:
332 NOTREACHED() << provider_type_; 359 NOTREACHED() << info_.type;
333 } 360 }
334 NOTREACHED() << provider_type_; 361 NOTREACHED() << info_.type;
335 return blink::kWebServiceWorkerClientTypeWindow; 362 return blink::kWebServiceWorkerClientTypeWindow;
336 } 363 }
337 364
338 void ServiceWorkerProviderHost::AssociateRegistration( 365 void ServiceWorkerProviderHost::AssociateRegistration(
339 ServiceWorkerRegistration* registration, 366 ServiceWorkerRegistration* registration,
340 bool notify_controllerchange) { 367 bool notify_controllerchange) {
341 CHECK(IsContextSecureForServiceWorker()); 368 CHECK(IsContextSecureForServiceWorker());
342 DCHECK(CanAssociateRegistration(registration)); 369 DCHECK(CanAssociateRegistration(registration));
343 associated_registration_ = registration; 370 associated_registration_ = registration;
344 AddMatchingRegistration(registration); 371 AddMatchingRegistration(registration);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (get_ready_callback_) 557 if (get_ready_callback_)
531 return false; 558 return false;
532 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); 559 get_ready_callback_.reset(new OneShotGetReadyCallback(callback));
533 ReturnRegistrationForReadyIfNeeded(); 560 ReturnRegistrationForReadyIfNeeded();
534 return true; 561 return true;
535 } 562 }
536 563
537 std::unique_ptr<ServiceWorkerProviderHost> 564 std::unique_ptr<ServiceWorkerProviderHost>
538 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 565 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
539 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 566 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
540 DCHECK_NE(MSG_ROUTING_NONE, route_id_); 567 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id);
541 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 568 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
542 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 569 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
543 570
544 std::unique_ptr<ServiceWorkerProviderHost> new_provider_host = 571 std::unique_ptr<ServiceWorkerProviderHost> replacement =
545 base::WrapUnique(new ServiceWorkerProviderHost( 572 base::WrapUnique(new ServiceWorkerProviderHost(
546 process_id(), frame_id(), provider_id(), provider_type(), 573 process_id(),
547 is_parent_frame_secure(), context_, dispatcher_host())); 574 ServiceWorkerProviderHostInfo(std::move(info_), binding_.Unbind(),
575 client_.PassInterface()),
576 context_, dispatcher_host()));
548 577
549 for (const GURL& pattern : associated_patterns_) 578 for (const GURL& pattern : associated_patterns_)
550 DecreaseProcessReference(pattern); 579 DecreaseProcessReference(pattern);
551 580
552 for (auto& key_registration : matching_registrations_) 581 for (auto& key_registration : matching_registrations_)
553 DecreaseProcessReference(key_registration.second->pattern()); 582 DecreaseProcessReference(key_registration.second->pattern());
554 583
555 if (associated_registration_.get()) { 584 if (associated_registration_.get()) {
556 if (dispatcher_host_) { 585 if (dispatcher_host_) {
557 Send(new ServiceWorkerMsg_DisassociateRegistration( 586 Send(new ServiceWorkerMsg_DisassociateRegistration(
558 render_thread_id_, provider_id())); 587 render_thread_id_, provider_id()));
559 } 588 }
560 } 589 }
561 590
562 render_process_id_ = ChildProcessHost::kInvalidUniqueID; 591 render_process_id_ = ChildProcessHost::kInvalidUniqueID;
563 route_id_ = MSG_ROUTING_NONE;
564 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 592 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
565 provider_id_ = kInvalidServiceWorkerProviderId;
566 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN;
567 dispatcher_host_ = nullptr; 593 dispatcher_host_ = nullptr;
568 return new_provider_host; 594 return replacement;
569 } 595 }
570 596
571 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( 597 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
572 int new_process_id, 598 ServiceWorkerProviderHost* provisional_host) {
573 int new_frame_id,
574 int new_provider_id,
575 ServiceWorkerProviderType new_provider_type,
576 ServiceWorkerDispatcherHost* new_dispatcher_host) {
577 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 599 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
578 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); 600 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id());
579 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); 601 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id());
580 602
581 render_thread_id_ = kDocumentMainThreadId; 603 render_thread_id_ = kDocumentMainThreadId;
582 provider_id_ = new_provider_id; 604 info_.provider_id = provisional_host->provider_id();
583 provider_type_ = new_provider_type; 605 info_.type = provisional_host->provider_type();
584 606
585 FinalizeInitialization(new_process_id, new_frame_id, new_dispatcher_host); 607 // Take the connection over from the provisional host.
608 DCHECK(!client_.is_bound());
609 DCHECK(!binding_.is_bound());
610 client_.Bind(provisional_host->client_.PassInterface());
611 binding_.Bind(provisional_host->binding_.Unbind());
612 binding_.set_connection_error_handler(
613 base::Bind(&RemoveProviderHost, context_, provisional_host->process_id(),
614 provisional_host->provider_id()));
615
616 FinalizeInitialization(provisional_host->process_id(),
617 provisional_host->frame_id(),
618 provisional_host->dispatcher_host());
586 } 619 }
587 620
588 // PlzNavigate 621 // PlzNavigate
589 void ServiceWorkerProviderHost::CompleteNavigationInitialized( 622 void ServiceWorkerProviderHost::CompleteNavigationInitialized(
590 int process_id, 623 int process_id,
591 int frame_routing_id, 624 ServiceWorkerProviderHostInfo info,
592 ServiceWorkerDispatcherHost* dispatcher_host) { 625 ServiceWorkerDispatcherHost* dispatcher_host) {
593 CHECK(IsBrowserSideNavigationEnabled()); 626 CHECK(IsBrowserSideNavigationEnabled());
594 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 627 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
595 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type_); 628 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type);
596 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 629 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
597 630
598 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); 631 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id);
599 DCHECK_NE(MSG_ROUTING_NONE, frame_routing_id); 632 DCHECK_EQ(info_.provider_id, info.provider_id);
633 DCHECK_NE(MSG_ROUTING_NONE, info.route_id);
600 634
601 FinalizeInitialization(process_id, frame_routing_id, dispatcher_host); 635 // Connect with the provider on the renderer.
636 DCHECK(!client_.is_bound());
637 DCHECK(!binding_.is_bound());
638 client_.Bind(std::move(info.client_ptr_info));
639 binding_.Bind(std::move(info.host_request));
640 binding_.set_connection_error_handler(
641 base::Bind(&RemoveProviderHost, context_, process_id, provider_id()));
642
643 FinalizeInitialization(process_id, info.route_id, dispatcher_host);
602 } 644 }
603 645
604 void ServiceWorkerProviderHost::SendUpdateFoundMessage( 646 void ServiceWorkerProviderHost::SendUpdateFoundMessage(
605 int registration_handle_id) { 647 int registration_handle_id) {
606 if (!dispatcher_host_) 648 if (!dispatcher_host_)
607 return; // Could be nullptr in some tests. 649 return; // Could be nullptr in some tests.
608 650
609 if (!IsReadyToSendMessages()) { 651 if (!IsReadyToSendMessages()) {
610 queued_events_.push_back( 652 queued_events_.push_back(
611 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, 653 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 DCHECK(dispatcher_host_); 805 DCHECK(dispatcher_host_);
764 DCHECK(IsReadyToSendMessages()); 806 DCHECK(IsReadyToSendMessages());
765 dispatcher_host_->Send(message); 807 dispatcher_host_->Send(message);
766 } 808 }
767 809
768 void ServiceWorkerProviderHost::FinalizeInitialization( 810 void ServiceWorkerProviderHost::FinalizeInitialization(
769 int process_id, 811 int process_id,
770 int frame_routing_id, 812 int frame_routing_id,
771 ServiceWorkerDispatcherHost* dispatcher_host) { 813 ServiceWorkerDispatcherHost* dispatcher_host) {
772 render_process_id_ = process_id; 814 render_process_id_ = process_id;
773 route_id_ = frame_routing_id; 815 info_.route_id = frame_routing_id;
774 dispatcher_host_ = dispatcher_host; 816 dispatcher_host_ = dispatcher_host;
775 817
776 for (const GURL& pattern : associated_patterns_) 818 for (const GURL& pattern : associated_patterns_)
777 IncreaseProcessReference(pattern); 819 IncreaseProcessReference(pattern);
778 820
779 for (auto& key_registration : matching_registrations_) 821 for (auto& key_registration : matching_registrations_)
780 IncreaseProcessReference(key_registration.second->pattern()); 822 IncreaseProcessReference(key_registration.second->pattern());
781 823
782 if (associated_registration_.get()) { 824 if (associated_registration_.get()) {
783 SendAssociateRegistrationMessage(); 825 SendAssociateRegistrationMessage();
784 if (dispatcher_host_ && associated_registration_->active_version()) { 826 if (dispatcher_host_ && associated_registration_->active_version()) {
785 Send(new ServiceWorkerMsg_SetControllerServiceWorker( 827 Send(new ServiceWorkerMsg_SetControllerServiceWorker(
786 render_thread_id_, provider_id(), 828 render_thread_id_, provider_id(),
787 GetOrCreateServiceWorkerHandle( 829 GetOrCreateServiceWorkerHandle(
788 associated_registration_->active_version()), 830 associated_registration_->active_version()),
789 false /* shouldNotifyControllerChange */, 831 false /* shouldNotifyControllerChange */,
790 associated_registration_->active_version()->used_features())); 832 associated_registration_->active_version()->used_features()));
791 } 833 }
792 } 834 }
793 } 835 }
794 836
795 } // namespace content 837 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698