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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 called(false) { | 45 called(false) { |
46 } | 46 } |
47 | 47 |
48 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { | 48 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { |
49 } | 49 } |
50 | 50 |
51 // static | 51 // static |
52 std::unique_ptr<ServiceWorkerProviderHost> | 52 std::unique_ptr<ServiceWorkerProviderHost> |
53 ServiceWorkerProviderHost::PreCreateNavigationHost( | 53 ServiceWorkerProviderHost::PreCreateNavigationHost( |
54 base::WeakPtr<ServiceWorkerContextCore> context, | 54 base::WeakPtr<ServiceWorkerContextCore> context, |
| 55 const MojoURLLoaderFactoryGetter& url_loader_factory_getter, |
55 bool are_ancestors_secure) { | 56 bool are_ancestors_secure) { |
56 CHECK(IsBrowserSideNavigationEnabled()); | 57 CHECK(IsBrowserSideNavigationEnabled()); |
57 // Generate a new browser-assigned id for the host. | 58 // Generate a new browser-assigned id for the host. |
58 int provider_id = g_next_navigation_provider_id--; | 59 int provider_id = g_next_navigation_provider_id--; |
59 return std::unique_ptr<ServiceWorkerProviderHost>( | 60 std::unique_ptr<ServiceWorkerProviderHost> host( |
60 new ServiceWorkerProviderHost( | 61 base::MakeUnique<ServiceWorkerProviderHost>( |
61 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, | 62 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, |
62 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 63 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
63 are_ancestors_secure ? FrameSecurityLevel::SECURE | 64 are_ancestors_secure ? FrameSecurityLevel::SECURE |
64 : FrameSecurityLevel::INSECURE, | 65 : FrameSecurityLevel::INSECURE, |
65 context, nullptr)); | 66 context, nullptr)); |
| 67 host->url_loader_factory_getter_ = url_loader_factory_getter; |
| 68 return host; |
66 } | 69 } |
67 | 70 |
68 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 71 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
69 int render_process_id, | 72 int render_process_id, |
70 int route_id, | 73 int route_id, |
71 int provider_id, | 74 int provider_id, |
72 ServiceWorkerProviderType provider_type, | 75 ServiceWorkerProviderType provider_type, |
73 FrameSecurityLevel parent_frame_security_level, | 76 FrameSecurityLevel parent_frame_security_level, |
74 base::WeakPtr<ServiceWorkerContextCore> context, | 77 base::WeakPtr<ServiceWorkerContextCore> context, |
75 ServiceWorkerDispatcherHost* dispatcher_host) | 78 ServiceWorkerDispatcherHost* dispatcher_host) |
76 : client_uuid_(base::GenerateGUID()), | 79 : client_uuid_(base::GenerateGUID()), |
77 render_process_id_(render_process_id), | 80 render_process_id_(render_process_id), |
78 route_id_(route_id), | 81 route_id_(route_id), |
79 render_thread_id_(kDocumentMainThreadId), | 82 render_thread_id_(kDocumentMainThreadId), |
80 provider_id_(provider_id), | 83 provider_id_(provider_id), |
81 provider_type_(provider_type), | 84 provider_type_(provider_type), |
82 parent_frame_security_level_(parent_frame_security_level), | 85 parent_frame_security_level_(parent_frame_security_level), |
83 context_(context), | 86 context_(context), |
84 dispatcher_host_(dispatcher_host), | 87 dispatcher_host_(dispatcher_host), |
85 allow_association_(true) { | 88 allow_association_(true), |
| 89 url_loader_factory_getter_( |
| 90 dispatcher_host_ ? dispatcher_host_->url_loader_factory_getter() |
| 91 : MojoURLLoaderFactoryGetter()) { |
86 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 92 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
87 | 93 |
88 // PlzNavigate | 94 // PlzNavigate |
89 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 95 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
90 IsBrowserSideNavigationEnabled()); | 96 IsBrowserSideNavigationEnabled()); |
91 | 97 |
92 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 98 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
93 // 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. |
94 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 100 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
95 } | 101 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 RequestContextFrameType frame_type, | 340 RequestContextFrameType frame_type, |
335 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 341 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
336 scoped_refptr<ResourceRequestBodyImpl> body) { | 342 scoped_refptr<ResourceRequestBodyImpl> body) { |
337 if (IsHostToRunningServiceWorker()) { | 343 if (IsHostToRunningServiceWorker()) { |
338 return std::unique_ptr<ServiceWorkerRequestHandler>( | 344 return std::unique_ptr<ServiceWorkerRequestHandler>( |
339 new ServiceWorkerContextRequestHandler( | 345 new ServiceWorkerContextRequestHandler( |
340 context_, AsWeakPtr(), blob_storage_context, resource_type)); | 346 context_, AsWeakPtr(), blob_storage_context, resource_type)); |
341 } | 347 } |
342 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || | 348 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || |
343 controlling_version()) { | 349 controlling_version()) { |
344 // |dispatcher_host_| may be null in some unittests. | |
345 return std::unique_ptr<ServiceWorkerRequestHandler>( | 350 return std::unique_ptr<ServiceWorkerRequestHandler>( |
346 new ServiceWorkerControlleeRequestHandler( | 351 new ServiceWorkerControlleeRequestHandler( |
347 context_, AsWeakPtr(), blob_storage_context, request_mode, | 352 context_, AsWeakPtr(), blob_storage_context, request_mode, |
348 credentials_mode, redirect_mode, resource_type, | 353 credentials_mode, redirect_mode, resource_type, |
349 request_context_type, frame_type, body, | 354 request_context_type, frame_type, body, |
350 dispatcher_host_ ? dispatcher_host_->url_loader_factory_getter() | 355 url_loader_factory_getter_)); |
351 : MojoURLLoaderFactoryGetter())); | |
352 } | 356 } |
353 return std::unique_ptr<ServiceWorkerRequestHandler>(); | 357 return std::unique_ptr<ServiceWorkerRequestHandler>(); |
354 } | 358 } |
355 | 359 |
356 ServiceWorkerObjectInfo | 360 ServiceWorkerObjectInfo |
357 ServiceWorkerProviderHost::GetOrCreateServiceWorkerHandle( | 361 ServiceWorkerProviderHost::GetOrCreateServiceWorkerHandle( |
358 ServiceWorkerVersion* version) { | 362 ServiceWorkerVersion* version) { |
359 DCHECK(dispatcher_host_); | 363 DCHECK(dispatcher_host_); |
360 if (!context_ || !version) | 364 if (!context_ || !version) |
361 return ServiceWorkerObjectInfo(); | 365 return ServiceWorkerObjectInfo(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 render_thread_id_, provider_id())); | 455 render_thread_id_, provider_id())); |
452 } | 456 } |
453 } | 457 } |
454 | 458 |
455 render_process_id_ = ChildProcessHost::kInvalidUniqueID; | 459 render_process_id_ = ChildProcessHost::kInvalidUniqueID; |
456 route_id_ = MSG_ROUTING_NONE; | 460 route_id_ = MSG_ROUTING_NONE; |
457 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 461 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
458 provider_id_ = kInvalidServiceWorkerProviderId; | 462 provider_id_ = kInvalidServiceWorkerProviderId; |
459 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; | 463 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; |
460 dispatcher_host_ = nullptr; | 464 dispatcher_host_ = nullptr; |
| 465 url_loader_factory_getter_ = MojoURLLoaderFactoryGetter(); |
461 } | 466 } |
462 | 467 |
463 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 468 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
464 int new_process_id, | 469 int new_process_id, |
465 int new_frame_id, | 470 int new_frame_id, |
466 int new_provider_id, | 471 int new_provider_id, |
467 ServiceWorkerProviderType new_provider_type, | 472 ServiceWorkerProviderType new_provider_type, |
468 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 473 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
469 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 474 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
470 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 475 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 659 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
655 DCHECK(dispatcher_host_); | 660 DCHECK(dispatcher_host_); |
656 DCHECK(IsReadyToSendMessages()); | 661 DCHECK(IsReadyToSendMessages()); |
657 dispatcher_host_->Send(message); | 662 dispatcher_host_->Send(message); |
658 } | 663 } |
659 | 664 |
660 void ServiceWorkerProviderHost::FinalizeInitialization( | 665 void ServiceWorkerProviderHost::FinalizeInitialization( |
661 int process_id, | 666 int process_id, |
662 int frame_routing_id, | 667 int frame_routing_id, |
663 ServiceWorkerDispatcherHost* dispatcher_host) { | 668 ServiceWorkerDispatcherHost* dispatcher_host) { |
| 669 DCHECK(dispatcher_host); |
664 render_process_id_ = process_id; | 670 render_process_id_ = process_id; |
665 route_id_ = frame_routing_id; | 671 route_id_ = frame_routing_id; |
666 dispatcher_host_ = dispatcher_host; | 672 dispatcher_host_ = dispatcher_host; |
| 673 url_loader_factory_getter_ = dispatcher_host_->url_loader_factory_getter(); |
667 | 674 |
668 for (const GURL& pattern : associated_patterns_) | 675 for (const GURL& pattern : associated_patterns_) |
669 IncreaseProcessReference(pattern); | 676 IncreaseProcessReference(pattern); |
670 | 677 |
671 for (auto& key_registration : matching_registrations_) | 678 for (auto& key_registration : matching_registrations_) |
672 IncreaseProcessReference(key_registration.second->pattern()); | 679 IncreaseProcessReference(key_registration.second->pattern()); |
673 | 680 |
674 if (associated_registration_.get()) { | 681 if (associated_registration_.get()) { |
675 SendAssociateRegistrationMessage(); | 682 SendAssociateRegistrationMessage(); |
676 if (dispatcher_host_ && associated_registration_->active_version()) { | 683 if (associated_registration_->active_version()) { |
677 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 684 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
678 render_thread_id_, provider_id(), | 685 render_thread_id_, provider_id(), |
679 GetOrCreateServiceWorkerHandle( | 686 GetOrCreateServiceWorkerHandle( |
680 associated_registration_->active_version()), | 687 associated_registration_->active_version()), |
681 false /* shouldNotifyControllerChange */)); | 688 false /* shouldNotifyControllerChange */)); |
682 } | 689 } |
683 } | 690 } |
684 } | 691 } |
685 | 692 |
686 } // namespace content | 693 } // namespace content |
OLD | NEW |