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 <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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 ResourceType resource_type) | 51 ResourceType resource_type) |
| 52 : ServiceWorkerRequestHandler(context, | 52 : ServiceWorkerRequestHandler(context, |
| 53 provider_host, | 53 provider_host, |
| 54 blob_storage_context, | 54 blob_storage_context, |
| 55 resource_type) {} | 55 resource_type) {} |
| 56 ~ServiceWorkerURLTrackingRequestHandler() override {} | 56 ~ServiceWorkerURLTrackingRequestHandler() override {} |
| 57 | 57 |
| 58 // Called via custom URLRequestJobFactory. | 58 // Called via custom URLRequestJobFactory. |
| 59 net::URLRequestJob* MaybeCreateJob( | 59 net::URLRequestJob* MaybeCreateJob( |
| 60 net::URLRequest* request, | 60 net::URLRequest* request, |
| 61 net::NetworkDelegate* network_delegate, | 61 net::NetworkDelegate* /* network_delegate */, |
| 62 ResourceContext* resource_context) override { | 62 ResourceContext* /* resource_context */) override { |
|
falken
2017/03/28 06:29:43
You can just omit the names when they don't add ne
shimazu
2017/05/08 08:34:29
Done.
| |
| 63 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); | 63 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); |
| 64 provider_host_->SetDocumentUrl(stripped_url); | 64 provider_host_->SetDocumentUrl(stripped_url); |
| 65 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); | 65 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); |
| 66 return nullptr; | 66 return nullptr; |
| 67 } | 67 } |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler); | 70 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context, | |
| 74 int process_id, | |
| 75 int provider_id) { | |
| 76 TRACE_EVENT0("ServiceWorker", "ServiceWorkerProviderHost::ProviderDestroyed"); | |
|
falken
2017/03/28 06:29:42
Trace event is using the old name.
shimazu
2017/05/08 08:34:28
Done.
| |
| 77 if (!context) | |
| 78 return; | |
| 79 if (!context->GetProviderHost(process_id, provider_id)) { | |
| 80 // PlzNavigate: in some cancellation of navigation cases, it is possible | |
| 81 // for the pre-created host to have been destroyed before being claimed by | |
| 82 // the renderer. The provider is then destroyed in the renderer, and no | |
| 83 // matching host will be found. | |
| 84 CHECK(IsBrowserSideNavigationEnabled() && | |
| 85 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); | |
| 86 return; | |
| 87 } | |
| 88 context->RemoveProviderHost(process_id, provider_id); | |
| 89 } | |
| 90 | |
| 73 } // anonymous namespace | 91 } // anonymous namespace |
| 74 | 92 |
| 75 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( | 93 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
| 76 const GetRegistrationForReadyCallback& callback) | 94 const GetRegistrationForReadyCallback& callback) |
| 77 : callback(callback), | 95 : callback(callback), |
| 78 called(false) { | 96 called(false) { |
| 79 } | 97 } |
| 80 | 98 |
| 81 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { | 99 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { |
| 82 } | 100 } |
| 83 | 101 |
| 84 // static | 102 // static |
| 85 std::unique_ptr<ServiceWorkerProviderHost> | 103 std::unique_ptr<ServiceWorkerProviderHost> |
| 86 ServiceWorkerProviderHost::PreCreateNavigationHost( | 104 ServiceWorkerProviderHost::PreCreateNavigationHost( |
| 87 base::WeakPtr<ServiceWorkerContextCore> context, | 105 base::WeakPtr<ServiceWorkerContextCore> context, |
| 88 bool are_ancestors_secure, | 106 bool are_ancestors_secure, |
| 89 const WebContentsGetter& web_contents_getter) { | 107 const WebContentsGetter& web_contents_getter) { |
| 90 CHECK(IsBrowserSideNavigationEnabled()); | 108 CHECK(IsBrowserSideNavigationEnabled()); |
| 91 // Generate a new browser-assigned id for the host. | 109 // Generate a new browser-assigned id for the host. |
| 92 int provider_id = g_next_navigation_provider_id--; | 110 int provider_id = g_next_navigation_provider_id--; |
| 93 auto host = base::WrapUnique(new ServiceWorkerProviderHost( | 111 auto host = base::WrapUnique(new ServiceWorkerProviderHost( |
| 94 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, | 112 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, |
| 95 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, context, | 113 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, |
| 96 nullptr)); | 114 mojom::ServiceWorkerProviderAssociatedPtrInfo(), |
| 115 mojom::ServiceWorkerProviderHostAssociatedRequest(), context, nullptr)); | |
| 97 host->web_contents_getter_ = web_contents_getter; | 116 host->web_contents_getter_ = web_contents_getter; |
| 98 return host; | 117 return host; |
| 99 } | 118 } |
| 100 | 119 |
| 101 // static | 120 // static |
| 102 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( | 121 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( |
| 103 int process_id, | 122 int process_id, |
| 104 ServiceWorkerProviderHostInfo info, | 123 ServiceWorkerProviderHostInfo info, |
| 105 base::WeakPtr<ServiceWorkerContextCore> context, | 124 base::WeakPtr<ServiceWorkerContextCore> context, |
| 106 ServiceWorkerDispatcherHost* dispatcher_host) { | 125 ServiceWorkerDispatcherHost* dispatcher_host) { |
| 107 return base::WrapUnique(new ServiceWorkerProviderHost( | 126 return base::WrapUnique(new ServiceWorkerProviderHost( |
| 108 process_id, info.route_id, info.provider_id, info.type, | 127 process_id, info.route_id, info.provider_id, info.type, |
| 109 info.is_parent_frame_secure, context, dispatcher_host)); | 128 info.is_parent_frame_secure, std::move(info.client_ptr_info), |
| 129 std::move(info.host_request), context, dispatcher_host)); | |
| 110 } | 130 } |
| 111 | 131 |
| 112 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 132 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| 113 int render_process_id, | 133 int render_process_id, |
| 114 int route_id, | 134 int route_id, |
| 115 int provider_id, | 135 int provider_id, |
| 116 ServiceWorkerProviderType provider_type, | 136 ServiceWorkerProviderType provider_type, |
| 117 bool is_parent_frame_secure, | 137 bool is_parent_frame_secure, |
| 138 mojom::ServiceWorkerProviderAssociatedPtrInfo client_info, | |
| 139 mojom::ServiceWorkerProviderHostAssociatedRequest request, | |
| 118 base::WeakPtr<ServiceWorkerContextCore> context, | 140 base::WeakPtr<ServiceWorkerContextCore> context, |
| 119 ServiceWorkerDispatcherHost* dispatcher_host) | 141 ServiceWorkerDispatcherHost* dispatcher_host) |
| 120 : client_uuid_(base::GenerateGUID()), | 142 : client_uuid_(base::GenerateGUID()), |
| 121 render_process_id_(render_process_id), | 143 render_process_id_(render_process_id), |
| 122 route_id_(route_id), | 144 route_id_(route_id), |
| 123 render_thread_id_(kDocumentMainThreadId), | 145 render_thread_id_(kDocumentMainThreadId), |
| 124 provider_id_(provider_id), | 146 provider_id_(provider_id), |
| 125 provider_type_(provider_type), | 147 provider_type_(provider_type), |
| 126 is_parent_frame_secure_(is_parent_frame_secure), | 148 is_parent_frame_secure_(is_parent_frame_secure), |
| 127 context_(context), | 149 context_(context), |
| 128 dispatcher_host_(dispatcher_host), | 150 dispatcher_host_(dispatcher_host), |
| 129 allow_association_(true) { | 151 allow_association_(true), |
| 152 binding_(this, std::move(request)) { | |
| 130 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 153 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| 131 | 154 |
| 132 // PlzNavigate | 155 // PlzNavigate |
| 133 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 156 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
| 134 IsBrowserSideNavigationEnabled()); | 157 IsBrowserSideNavigationEnabled()); |
| 135 | 158 |
| 136 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 159 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
| 137 // Actual thread id is set when the service worker context gets started. | 160 // Actual thread id is set when the service worker context gets started. |
| 138 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 161 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| 139 } | 162 } |
| 140 context_->RegisterProviderHostByClientID(client_uuid_, this); | 163 context_->RegisterProviderHostByClientID(client_uuid_, this); |
| 164 | |
| 165 // Mojo pile is possible to be null when testing. | |
|
falken
2017/03/28 06:29:43
Can we instead fix the tests?
shimazu
2017/05/08 08:34:28
Yes, I agree with avoiding testing code in product
| |
| 166 if (client_info.is_valid() && binding_.is_bound()) { | |
| 167 client_.Bind(std::move(client_info)); | |
| 168 binding_.set_connection_error_handler(base::Bind( | |
| 169 &RemoveProviderHost, context_, render_process_id, provider_id)); | |
| 170 } | |
| 141 } | 171 } |
| 142 | 172 |
| 143 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 173 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| 144 if (context_) | 174 if (context_) |
| 145 context_->UnregisterProviderHostByClientID(client_uuid_); | 175 context_->UnregisterProviderHostByClientID(client_uuid_); |
| 146 | 176 |
| 147 // Clear docurl so the deferred activation of a waiting worker | 177 // Clear docurl so the deferred activation of a waiting worker |
| 148 // won't associate the new version with a provider being destroyed. | 178 // won't associate the new version with a provider being destroyed. |
| 149 document_url_ = GURL(); | 179 document_url_ = GURL(); |
| 150 if (controlling_version_.get()) | 180 if (controlling_version_.get()) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 177 | 207 |
| 178 std::set<std::string> schemes; | 208 std::set<std::string> schemes; |
| 179 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( | 209 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( |
| 180 &schemes); | 210 &schemes); |
| 181 return schemes.find(document_url().scheme()) != schemes.end(); | 211 return schemes.find(document_url().scheme()) != schemes.end(); |
| 182 } | 212 } |
| 183 | 213 |
| 184 void ServiceWorkerProviderHost::OnVersionAttributesChanged( | 214 void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
| 185 ServiceWorkerRegistration* registration, | 215 ServiceWorkerRegistration* registration, |
| 186 ChangedVersionAttributesMask changed_mask, | 216 ChangedVersionAttributesMask changed_mask, |
| 187 const ServiceWorkerRegistrationInfo& info) { | 217 const ServiceWorkerRegistrationInfo& /* info */) { |
| 188 if (!get_ready_callback_ || get_ready_callback_->called) | 218 if (!get_ready_callback_ || get_ready_callback_->called) |
| 189 return; | 219 return; |
| 190 if (changed_mask.active_changed() && registration->active_version()) { | 220 if (changed_mask.active_changed() && registration->active_version()) { |
| 191 // Wait until the state change so we don't send the get for ready | 221 // Wait until the state change so we don't send the get for ready |
| 192 // registration complete message before set version attributes message. | 222 // registration complete message before set version attributes message. |
| 193 registration->active_version()->RegisterStatusChangeCallback(base::Bind( | 223 registration->active_version()->RegisterStatusChangeCallback(base::Bind( |
| 194 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded, | 224 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded, |
| 195 AsWeakPtr())); | 225 AsWeakPtr())); |
| 196 } | 226 } |
| 197 } | 227 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 std::unique_ptr<ServiceWorkerProviderHost> | 532 std::unique_ptr<ServiceWorkerProviderHost> |
| 503 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | 533 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { |
| 504 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 534 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 505 DCHECK_NE(MSG_ROUTING_NONE, route_id_); | 535 DCHECK_NE(MSG_ROUTING_NONE, route_id_); |
| 506 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | 536 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
| 507 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 537 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| 508 | 538 |
| 509 std::unique_ptr<ServiceWorkerProviderHost> new_provider_host = | 539 std::unique_ptr<ServiceWorkerProviderHost> new_provider_host = |
| 510 base::WrapUnique(new ServiceWorkerProviderHost( | 540 base::WrapUnique(new ServiceWorkerProviderHost( |
| 511 process_id(), frame_id(), provider_id(), provider_type(), | 541 process_id(), frame_id(), provider_id(), provider_type(), |
| 512 is_parent_frame_secure(), context_, dispatcher_host())); | 542 is_parent_frame_secure(), |
| 543 mojom::ServiceWorkerProviderAssociatedPtrInfo(), | |
| 544 mojom::ServiceWorkerProviderHostAssociatedRequest(), context_, | |
| 545 dispatcher_host())); | |
| 513 | 546 |
| 514 for (const GURL& pattern : associated_patterns_) | 547 for (const GURL& pattern : associated_patterns_) |
| 515 DecreaseProcessReference(pattern); | 548 DecreaseProcessReference(pattern); |
| 516 | 549 |
| 517 for (auto& key_registration : matching_registrations_) | 550 for (auto& key_registration : matching_registrations_) |
| 518 DecreaseProcessReference(key_registration.second->pattern()); | 551 DecreaseProcessReference(key_registration.second->pattern()); |
| 519 | 552 |
| 520 if (associated_registration_.get()) { | 553 if (associated_registration_.get()) { |
| 521 if (dispatcher_host_) { | 554 if (dispatcher_host_) { |
| 522 Send(new ServiceWorkerMsg_DisassociateRegistration( | 555 Send(new ServiceWorkerMsg_DisassociateRegistration( |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 render_thread_id_, provider_id(), | 784 render_thread_id_, provider_id(), |
| 752 GetOrCreateServiceWorkerHandle( | 785 GetOrCreateServiceWorkerHandle( |
| 753 associated_registration_->active_version()), | 786 associated_registration_->active_version()), |
| 754 false /* shouldNotifyControllerChange */, | 787 false /* shouldNotifyControllerChange */, |
| 755 associated_registration_->active_version()->used_features())); | 788 associated_registration_->active_version()->used_features())); |
| 756 } | 789 } |
| 757 } | 790 } |
| 758 } | 791 } |
| 759 | 792 |
| 760 } // namespace content | 793 } // namespace content |
| OLD | NEW |