| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // process, to have been destroyed before being claimed by the renderer. The | 93 // process, to have been destroyed before being claimed by the renderer. The |
| 94 // provider is then destroyed in the renderer, and no matching host will be | 94 // provider is then destroyed in the renderer, and no matching host will be |
| 95 // found. | 95 // found. |
| 96 DCHECK(IsBrowserSideNavigationEnabled() && | 96 DCHECK(IsBrowserSideNavigationEnabled() && |
| 97 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); | 97 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 context->RemoveProviderHost(process_id, provider_id); | 100 context->RemoveProviderHost(process_id, provider_id); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Wraps associated request for another associated request. | |
| 104 class AssociatedURLLoaderRelay final : public mojom::URLLoader { | |
| 105 public: | |
| 106 static void CreateLoaderAndStart( | |
| 107 mojom::URLLoaderFactory* factory, | |
| 108 mojom::URLLoaderAssociatedRequest request, | |
| 109 int routing_id, | |
| 110 int request_id, | |
| 111 uint32_t options, | |
| 112 const ResourceRequest& resource_request, | |
| 113 mojom::URLLoaderClientPtr client, | |
| 114 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { | |
| 115 mojom::URLLoaderAssociatedPtr associated_ptr; | |
| 116 mojom::URLLoaderAssociatedRequest associated_request = | |
| 117 mojo::MakeRequest(&associated_ptr); | |
| 118 factory->CreateLoaderAndStart(std::move(associated_request), routing_id, | |
| 119 request_id, options, resource_request, | |
| 120 std::move(client), traffic_annotation); | |
| 121 mojo::MakeStrongAssociatedBinding( | |
| 122 base::MakeUnique<AssociatedURLLoaderRelay>(std::move(associated_ptr)), | |
| 123 std::move(request)); | |
| 124 } | |
| 125 | |
| 126 explicit AssociatedURLLoaderRelay( | |
| 127 mojom::URLLoaderAssociatedPtr associated_ptr) | |
| 128 : associated_ptr_(std::move(associated_ptr)) {} | |
| 129 ~AssociatedURLLoaderRelay() override {} | |
| 130 void FollowRedirect() override { associated_ptr_->FollowRedirect(); } | |
| 131 void SetPriority(net::RequestPriority priority, | |
| 132 int intra_priority_value) override { | |
| 133 associated_ptr_->SetPriority(priority, intra_priority_value); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 mojom::URLLoaderAssociatedPtr associated_ptr_; | |
| 138 DISALLOW_COPY_AND_ASSIGN(AssociatedURLLoaderRelay); | |
| 139 }; | |
| 140 | |
| 141 // Used by a Service Worker for script loading only during the installation | 103 // Used by a Service Worker for script loading only during the installation |
| 142 // time. For now this is just a proxy loader for the network loader. | 104 // time. For now this is just a proxy loader for the network loader. |
| 143 // Eventually this should replace the existing URLRequestJob-based request | 105 // Eventually this should replace the existing URLRequestJob-based request |
| 144 // interception for script loading, namely ServiceWorkerWriteToCacheJob. | 106 // interception for script loading, namely ServiceWorkerWriteToCacheJob. |
| 145 // TODO(kinuko): Implement this. | 107 // TODO(kinuko): Implement this. |
| 146 class ScriptURLLoader : public mojom::URLLoader, public mojom::URLLoaderClient { | 108 class ScriptURLLoader : public mojom::URLLoader, public mojom::URLLoaderClient { |
| 147 public: | 109 public: |
| 148 ScriptURLLoader( | 110 ScriptURLLoader( |
| 149 int32_t routing_id, | 111 int32_t routing_id, |
| 150 int32_t request_id, | 112 int32_t request_id, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, | 219 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
| 258 int32_t routing_id, | 220 int32_t routing_id, |
| 259 int32_t request_id, | 221 int32_t request_id, |
| 260 uint32_t options, | 222 uint32_t options, |
| 261 const ResourceRequest& resource_request, | 223 const ResourceRequest& resource_request, |
| 262 mojom::URLLoaderClientPtr client, | 224 mojom::URLLoaderClientPtr client, |
| 263 const net::MutableNetworkTrafficAnnotationTag& | 225 const net::MutableNetworkTrafficAnnotationTag& |
| 264 traffic_annotation) override { | 226 traffic_annotation) override { |
| 265 if (!ShouldHandleScriptRequest(resource_request)) { | 227 if (!ShouldHandleScriptRequest(resource_request)) { |
| 266 // If the request should not be handled by ScriptURLLoader, just | 228 // If the request should not be handled by ScriptURLLoader, just |
| 267 // fallback to the network. This needs a relaying as we use different | 229 // fallback to the network. |
| 268 // associated message pipes. | |
| 269 // TODO(kinuko): Record the reason like what we do with netlog in | 230 // TODO(kinuko): Record the reason like what we do with netlog in |
| 270 // ServiceWorkerContextRequestHandler. | 231 // ServiceWorkerContextRequestHandler. |
| 271 AssociatedURLLoaderRelay::CreateLoaderAndStart( | 232 loader_factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| 272 loader_factory_getter_->GetNetworkFactory()->get(), | |
| 273 std::move(request), routing_id, request_id, options, resource_request, | 233 std::move(request), routing_id, request_id, options, resource_request, |
| 274 std::move(client), traffic_annotation); | 234 std::move(client), traffic_annotation); |
| 275 return; | 235 return; |
| 276 } | 236 } |
| 277 mojo::MakeStrongAssociatedBinding( | 237 mojo::MakeStrongAssociatedBinding( |
| 278 base::MakeUnique<ScriptURLLoader>( | 238 base::MakeUnique<ScriptURLLoader>( |
| 279 routing_id, request_id, options, resource_request, | 239 routing_id, request_id, options, resource_request, |
| 280 std::move(client), context_, provider_host_, blob_storage_context_, | 240 std::move(client), context_, provider_host_, blob_storage_context_, |
| 281 loader_factory_getter_, traffic_annotation), | 241 loader_factory_getter_, traffic_annotation), |
| 282 std::move(request)); | 242 std::move(request)); |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 render_thread_id_, provider_id(), | 1112 render_thread_id_, provider_id(), |
| 1153 GetOrCreateServiceWorkerHandle( | 1113 GetOrCreateServiceWorkerHandle( |
| 1154 associated_registration_->active_version()), | 1114 associated_registration_->active_version()), |
| 1155 false /* shouldNotifyControllerChange */, | 1115 false /* shouldNotifyControllerChange */, |
| 1156 associated_registration_->active_version()->used_features())); | 1116 associated_registration_->active_version()->used_features())); |
| 1157 } | 1117 } |
| 1158 } | 1118 } |
| 1159 } | 1119 } |
| 1160 | 1120 |
| 1161 } // namespace content | 1121 } // namespace content |
| OLD | NEW |