| 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/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "content/common/service_worker/service_worker_messages.h" | 24 #include "content/common/service_worker/service_worker_messages.h" |
| 25 #include "content/common/service_worker/service_worker_types.h" | 25 #include "content/common/service_worker/service_worker_types.h" |
| 26 #include "content/common/service_worker/service_worker_utils.h" | 26 #include "content/common/service_worker/service_worker_utils.h" |
| 27 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
| 28 #include "content/public/common/browser_side_navigation_policy.h" | 28 #include "content/public/common/browser_side_navigation_policy.h" |
| 29 #include "content/public/common/child_process_host.h" | 29 #include "content/public/common/child_process_host.h" |
| 30 #include "content/public/common/content_client.h" | 30 #include "content/public/common/content_client.h" |
| 31 #include "content/public/common/content_features.h" | 31 #include "content/public/common/content_features.h" |
| 32 #include "content/public/common/origin_util.h" | 32 #include "content/public/common/origin_util.h" |
| 33 #include "mojo/public/cpp/bindings/strong_associated_binding.h" | 33 #include "mojo/public/cpp/bindings/strong_associated_binding.h" |
| 34 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 34 #include "net/base/url_util.h" | 35 #include "net/base/url_util.h" |
| 35 #include "storage/browser/blob/blob_storage_context.h" | 36 #include "storage/browser/blob/blob_storage_context.h" |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Provider host for navigation with PlzNavigate or when service worker's | 42 // Provider host for navigation with PlzNavigate or when service worker's |
| 42 // context is created on the browser side. This function provides the next | 43 // context is created on the browser side. This function provides the next |
| 43 // ServiceWorkerProviderHost ID for them, starts at -2 and keeps going down. | 44 // ServiceWorkerProviderHost ID for them, starts at -2 and keeps going down. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 184 } |
| 184 void OnStartLoadingResponseBody( | 185 void OnStartLoadingResponseBody( |
| 185 mojo::ScopedDataPipeConsumerHandle body) override { | 186 mojo::ScopedDataPipeConsumerHandle body) override { |
| 186 forwarding_client_->OnStartLoadingResponseBody(std::move(body)); | 187 forwarding_client_->OnStartLoadingResponseBody(std::move(body)); |
| 187 } | 188 } |
| 188 void OnComplete(const ResourceRequestCompletionStatus& status) override { | 189 void OnComplete(const ResourceRequestCompletionStatus& status) override { |
| 189 forwarding_client_->OnComplete(status); | 190 forwarding_client_->OnComplete(status); |
| 190 } | 191 } |
| 191 | 192 |
| 192 private: | 193 private: |
| 193 mojom::URLLoaderAssociatedPtr network_loader_; | 194 mojom::URLLoaderPtr network_loader_; |
| 194 mojo::Binding<mojom::URLLoaderClient> network_client_binding_; | 195 mojo::Binding<mojom::URLLoaderClient> network_client_binding_; |
| 195 mojom::URLLoaderClientPtr forwarding_client_; | 196 mojom::URLLoaderClientPtr forwarding_client_; |
| 196 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 197 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 197 | 198 |
| 198 DISALLOW_COPY_AND_ASSIGN(ScriptURLLoader); | 199 DISALLOW_COPY_AND_ASSIGN(ScriptURLLoader); |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 // Created per one controller worker for script loading (only during | 202 // Created per one controller worker for script loading (only during |
| 202 // installation, eventually). This is kept alive while | 203 // installation, eventually). This is kept alive while |
| 203 // ServiceWorkerNetworkProvider in the renderer process is alive. | 204 // ServiceWorkerNetworkProvider in the renderer process is alive. |
| 204 // Used only when IsServicificationEnabled is true. | 205 // Used only when IsServicificationEnabled is true. |
| 205 class ScriptURLLoaderFactory : public mojom::URLLoaderFactory { | 206 class ScriptURLLoaderFactory : public mojom::URLLoaderFactory { |
| 206 public: | 207 public: |
| 207 ScriptURLLoaderFactory( | 208 ScriptURLLoaderFactory( |
| 208 base::WeakPtr<ServiceWorkerContextCore> context, | 209 base::WeakPtr<ServiceWorkerContextCore> context, |
| 209 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 210 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 210 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 211 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 211 scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter) | 212 scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter) |
| 212 : context_(context), | 213 : context_(context), |
| 213 provider_host_(provider_host), | 214 provider_host_(provider_host), |
| 214 blob_storage_context_(blob_storage_context), | 215 blob_storage_context_(blob_storage_context), |
| 215 loader_factory_getter_(loader_factory_getter) {} | 216 loader_factory_getter_(loader_factory_getter) {} |
| 216 ~ScriptURLLoaderFactory() override {} | 217 ~ScriptURLLoaderFactory() override {} |
| 217 | 218 |
| 218 // mojom::URLLoaderFactory: | 219 // mojom::URLLoaderFactory: |
| 219 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, | 220 void CreateLoaderAndStart(mojom::URLLoaderRequest request, |
| 220 int32_t routing_id, | 221 int32_t routing_id, |
| 221 int32_t request_id, | 222 int32_t request_id, |
| 222 uint32_t options, | 223 uint32_t options, |
| 223 const ResourceRequest& resource_request, | 224 const ResourceRequest& resource_request, |
| 224 mojom::URLLoaderClientPtr client, | 225 mojom::URLLoaderClientPtr client, |
| 225 const net::MutableNetworkTrafficAnnotationTag& | 226 const net::MutableNetworkTrafficAnnotationTag& |
| 226 traffic_annotation) override { | 227 traffic_annotation) override { |
| 227 if (!ShouldHandleScriptRequest(resource_request)) { | 228 if (!ShouldHandleScriptRequest(resource_request)) { |
| 228 // If the request should not be handled by ScriptURLLoader, just | 229 // If the request should not be handled by ScriptURLLoader, just |
| 229 // fallback to the network. | 230 // fallback to the network. |
| 230 // TODO(kinuko): Record the reason like what we do with netlog in | 231 // TODO(kinuko): Record the reason like what we do with netlog in |
| 231 // ServiceWorkerContextRequestHandler. | 232 // ServiceWorkerContextRequestHandler. |
| 232 loader_factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | 233 loader_factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| 233 std::move(request), routing_id, request_id, options, resource_request, | 234 std::move(request), routing_id, request_id, options, resource_request, |
| 234 std::move(client), traffic_annotation); | 235 std::move(client), traffic_annotation); |
| 235 return; | 236 return; |
| 236 } | 237 } |
| 237 mojo::MakeStrongAssociatedBinding( | 238 mojo::MakeStrongBinding( |
| 238 base::MakeUnique<ScriptURLLoader>( | 239 base::MakeUnique<ScriptURLLoader>( |
| 239 routing_id, request_id, options, resource_request, | 240 routing_id, request_id, options, resource_request, |
| 240 std::move(client), context_, provider_host_, blob_storage_context_, | 241 std::move(client), context_, provider_host_, blob_storage_context_, |
| 241 loader_factory_getter_, traffic_annotation), | 242 loader_factory_getter_, traffic_annotation), |
| 242 std::move(request)); | 243 std::move(request)); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void SyncLoad(int32_t routing_id, | 246 void SyncLoad(int32_t routing_id, |
| 246 int32_t request_id, | 247 int32_t request_id, |
| 247 const ResourceRequest& request, | 248 const ResourceRequest& request, |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 render_thread_id_, provider_id(), | 1113 render_thread_id_, provider_id(), |
| 1113 GetOrCreateServiceWorkerHandle( | 1114 GetOrCreateServiceWorkerHandle( |
| 1114 associated_registration_->active_version()), | 1115 associated_registration_->active_version()), |
| 1115 false /* shouldNotifyControllerChange */, | 1116 false /* shouldNotifyControllerChange */, |
| 1116 associated_registration_->active_version()->used_features())); | 1117 associated_registration_->active_version()->used_features())); |
| 1117 } | 1118 } |
| 1118 } | 1119 } |
| 1119 } | 1120 } |
| 1120 | 1121 |
| 1121 } // namespace content | 1122 } // namespace content |
| OLD | NEW |