 Chromium Code Reviews
 Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/loader/WorkerFetchContext.h" | 5 #include "core/loader/WorkerFetchContext.h" | 
| 6 | 6 | 
| 7 #include "core/frame/Deprecation.h" | 7 #include "core/frame/Deprecation.h" | 
| 8 #include "core/frame/UseCounter.h" | 8 #include "core/frame/UseCounter.h" | 
| 9 #include "core/loader/MixedContentChecker.h" | 9 #include "core/loader/MixedContentChecker.h" | 
| 10 #include "core/probe/CoreProbes.h" | |
| 10 #include "core/timing/WorkerGlobalScopePerformance.h" | 11 #include "core/timing/WorkerGlobalScopePerformance.h" | 
| 11 #include "core/workers/WorkerClients.h" | 12 #include "core/workers/WorkerClients.h" | 
| 12 #include "core/workers/WorkerGlobalScope.h" | 13 #include "core/workers/WorkerGlobalScope.h" | 
| 14 #include "platform/RuntimeEnabledFeatures.h" | |
| 13 #include "platform/Supplementable.h" | 15 #include "platform/Supplementable.h" | 
| 14 #include "platform/WebTaskRunner.h" | 16 #include "platform/WebTaskRunner.h" | 
| 15 #include "platform/exported/WrappedResourceRequest.h" | 17 #include "platform/exported/WrappedResourceRequest.h" | 
| 16 #include "platform/loader/fetch/ResourceFetcher.h" | 18 #include "platform/loader/fetch/ResourceFetcher.h" | 
| 17 #include "platform/scheduler/child/web_scheduler.h" | 19 #include "platform/scheduler/child/web_scheduler.h" | 
| 20 #include "platform/weborigin/SecurityPolicy.h" | |
| 18 #include "public/platform/Platform.h" | 21 #include "public/platform/Platform.h" | 
| 19 #include "public/platform/WebMixedContent.h" | 22 #include "public/platform/WebMixedContent.h" | 
| 20 #include "public/platform/WebMixedContentContextType.h" | 23 #include "public/platform/WebMixedContentContextType.h" | 
| 21 #include "public/platform/WebThread.h" | 24 #include "public/platform/WebThread.h" | 
| 22 #include "public/platform/WebURLRequest.h" | 25 #include "public/platform/WebURLRequest.h" | 
| 23 #include "public/platform/WebWorkerFetchContext.h" | 26 #include "public/platform/WebWorkerFetchContext.h" | 
| 24 | 27 | 
| 25 namespace blink { | 28 namespace blink { | 
| 26 | 29 | 
| 27 namespace { | 30 namespace { | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return nullptr; | 118 return nullptr; | 
| 116 } | 119 } | 
| 117 | 120 | 
| 118 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { | 121 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { | 
| 119 // TODO(horo): Implement this. | 122 // TODO(horo): Implement this. | 
| 120 return nullptr; | 123 return nullptr; | 
| 121 } | 124 } | 
| 122 | 125 | 
| 123 bool WorkerFetchContext::ShouldBlockRequestByInspector( | 126 bool WorkerFetchContext::ShouldBlockRequestByInspector( | 
| 124 const ResourceRequest& resource_request) const { | 127 const ResourceRequest& resource_request) const { | 
| 125 // TODO(horo): Implement this. | 128 bool should_block_request = false; | 
| 126 return false; | 129 probe::shouldBlockRequest(worker_global_scope_, resource_request, | 
| 130 &should_block_request); | |
| 131 return should_block_request; | |
| 
kinuko
2017/05/22 06:53:40
I think now this can be implemented in BaseFetchCo
 
horo
2017/05/22 07:32:17
Done.
 | |
| 127 } | 132 } | 
| 128 | 133 | 
| 129 void WorkerFetchContext::DispatchDidBlockRequest( | 134 void WorkerFetchContext::DispatchDidBlockRequest( | 
| 130 const ResourceRequest& resource_request, | 135 const ResourceRequest& resource_request, | 
| 131 const FetchInitiatorInfo& fetch_initiator_info, | 136 const FetchInitiatorInfo& fetch_initiator_info, | 
| 132 ResourceRequestBlockedReason blocked_reason) const { | 137 ResourceRequestBlockedReason blocked_reason) const { | 
| 133 // TODO(horo): Implement this. | 138 probe::didBlockRequest(worker_global_scope_, resource_request, nullptr, | 
| 139 fetch_initiator_info, blocked_reason); | |
| 134 } | 140 } | 
| 135 | 141 | 
| 136 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { | 142 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { | 
| 137 // TODO(horo): Implement this. | 143 // TODO(horo): Implement this. | 
| 138 } | 144 } | 
| 139 | 145 | 
| 140 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { | 146 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { | 
| 141 // TODO(horo): Implement this. | 147 // TODO(horo): Implement this. | 
| 142 return false; | 148 return false; | 
| 143 } | 149 } | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 167 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { | 173 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { | 
| 168 return web_context_->CreateURLLoader(); | 174 return web_context_->CreateURLLoader(); | 
| 169 } | 175 } | 
| 170 | 176 | 
| 171 bool WorkerFetchContext::IsControlledByServiceWorker() const { | 177 bool WorkerFetchContext::IsControlledByServiceWorker() const { | 
| 172 return web_context_->IsControlledByServiceWorker(); | 178 return web_context_->IsControlledByServiceWorker(); | 
| 173 } | 179 } | 
| 174 | 180 | 
| 175 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | 181 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | 
| 176 RedirectType) { | 182 RedirectType) { | 
| 183 String user_agent = worker_global_scope_->UserAgent(); | |
| 184 probe::applyUserAgentOverride(worker_global_scope_, &user_agent); | |
| 185 DCHECK(!user_agent.IsNull()); | |
| 186 request.SetHTTPUserAgent(AtomicString(user_agent)); | |
| 187 | |
| 177 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); | 188 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); | 
| 178 WrappedResourceRequest webreq(request); | 189 WrappedResourceRequest webreq(request); | 
| 179 web_context_->WillSendRequest(webreq); | 190 web_context_->WillSendRequest(webreq); | 
| 180 } | 191 } | 
| 181 | 192 | 
| 182 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { | 193 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { | 
| 183 return loading_task_runner_; | 194 return loading_task_runner_; | 
| 184 } | 195 } | 
| 185 | 196 | 
| 186 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, | 197 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, | 
| 187 FetchResourceType type) { | 198 FetchResourceType type) { | 
| 188 BaseFetchContext::AddAdditionalRequestHeaders(request, type); | 199 BaseFetchContext::AddAdditionalRequestHeaders(request, type); | 
| 189 | 200 | 
| 190 // The remaining modifications are only necessary for HTTP and HTTPS. | 201 // The remaining modifications are only necessary for HTTP and HTTPS. | 
| 191 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) | 202 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) | 
| 192 return; | 203 return; | 
| 193 | 204 | 
| 194 if (web_context_->IsDataSaverEnabled()) | 205 if (web_context_->IsDataSaverEnabled()) | 
| 195 request.SetHTTPHeaderField("Save-Data", "on"); | 206 request.SetHTTPHeaderField("Save-Data", "on"); | 
| 196 } | 207 } | 
| 197 | 208 | 
| 209 void WorkerFetchContext::DispatchWillSendRequest( | |
| 210 unsigned long identifier, | |
| 211 ResourceRequest& request, | |
| 212 const ResourceResponse& redirect_response, | |
| 213 const FetchInitiatorInfo& initiator_info) { | |
| 214 probe::willSendRequest(worker_global_scope_, identifier, nullptr, request, | |
| 215 redirect_response, initiator_info); | |
| 216 } | |
| 217 | |
| 198 void WorkerFetchContext::DispatchDidReceiveResponse( | 218 void WorkerFetchContext::DispatchDidReceiveResponse( | 
| 199 unsigned long identifier, | 219 unsigned long identifier, | 
| 200 const ResourceResponse& response, | 220 const ResourceResponse& response, | 
| 201 WebURLRequest::FrameType frame_type, | 221 WebURLRequest::FrameType frame_type, | 
| 202 WebURLRequest::RequestContext request_context, | 222 WebURLRequest::RequestContext request_context, | 
| 203 Resource* resource, | 223 Resource* resource, | 
| 204 ResourceResponseType) { | 224 ResourceResponseType) { | 
| 205 if (response.HasMajorCertificateErrors()) { | 225 if (response.HasMajorCertificateErrors()) { | 
| 206 WebMixedContentContextType context_type = | 226 WebMixedContentContextType context_type = | 
| 207 WebMixedContent::ContextTypeFromRequestContext( | 227 WebMixedContent::ContextTypeFromRequestContext( | 
| 208 request_context, false /* strictMixedContentCheckingForPlugin */); | 228 request_context, false /* strictMixedContentCheckingForPlugin */); | 
| 209 if (context_type == WebMixedContentContextType::kBlockable) { | 229 if (context_type == WebMixedContentContextType::kBlockable) { | 
| 210 web_context_->DidRunContentWithCertificateErrors(response.Url()); | 230 web_context_->DidRunContentWithCertificateErrors(response.Url()); | 
| 211 } else { | 231 } else { | 
| 212 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); | 232 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); | 
| 213 } | 233 } | 
| 214 } | 234 } | 
| 235 probe::didReceiveResourceResponse(worker_global_scope_, identifier, nullptr, | |
| 236 response, resource); | |
| 237 } | |
| 238 | |
| 239 void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier, | |
| 240 const char* data, | |
| 241 int data_length) { | |
| 242 probe::didReceiveData(worker_global_scope_, identifier, nullptr, data, | |
| 243 data_length); | |
| 244 } | |
| 245 | |
| 246 void WorkerFetchContext::DispatchDidReceiveEncodedData( | |
| 247 unsigned long identifier, | |
| 248 int encoded_data_length) { | |
| 249 probe::didReceiveEncodedDataLength(worker_global_scope_, identifier, | |
| 250 encoded_data_length); | |
| 
kinuko
2017/05/22 06:53:40
ditto
 
horo
2017/05/22 07:32:17
Done.
 
horo
2017/05/22 10:42:39
Ah, BaseFetchContext's |execution_context_| is nul
 | |
| 251 } | |
| 252 | |
| 253 void WorkerFetchContext::DispatchDidFinishLoading(unsigned long identifier, | |
| 254 double finish_time, | |
| 255 int64_t encoded_data_length, | |
| 256 int64_t decoded_body_length) { | |
| 257 probe::didFinishLoading(worker_global_scope_, identifier, nullptr, | |
| 258 finish_time, encoded_data_length, | |
| 259 decoded_body_length); | |
| 260 } | |
| 261 | |
| 262 void WorkerFetchContext::DispatchDidFail(unsigned long identifier, | |
| 263 const ResourceError& error, | |
| 264 int64_t encoded_data_length, | |
| 265 bool is_internal_request) { | |
| 266 probe::didFailLoading(worker_global_scope_, identifier, error); | |
| 215 } | 267 } | 
| 216 | 268 | 
| 217 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { | 269 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { | 
| 218 WorkerGlobalScopePerformance::performance(*worker_global_scope_) | 270 WorkerGlobalScopePerformance::performance(*worker_global_scope_) | 
| 219 ->AddResourceTiming(info); | 271 ->AddResourceTiming(info); | 
| 220 } | 272 } | 
| 221 | 273 | 
| 222 void WorkerFetchContext::PopulateResourceRequest( | 274 void WorkerFetchContext::PopulateResourceRequest( | 
| 223 const KURL& url, | 275 const KURL& url, | 
| 224 Resource::Type type, | 276 Resource::Type type, | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 250 void ProvideWorkerFetchContextToWorker( | 302 void ProvideWorkerFetchContextToWorker( | 
| 251 WorkerClients* clients, | 303 WorkerClients* clients, | 
| 252 std::unique_ptr<WebWorkerFetchContext> web_context) { | 304 std::unique_ptr<WebWorkerFetchContext> web_context) { | 
| 253 DCHECK(clients); | 305 DCHECK(clients); | 
| 254 WorkerFetchContextHolder::ProvideTo( | 306 WorkerFetchContextHolder::ProvideTo( | 
| 255 *clients, WorkerFetchContextHolder::SupplementName(), | 307 *clients, WorkerFetchContextHolder::SupplementName(), | 
| 256 new WorkerFetchContextHolder(std::move(web_context))); | 308 new WorkerFetchContextHolder(std::move(web_context))); | 
| 257 } | 309 } | 
| 258 | 310 | 
| 259 } // namespace blink | 311 } // namespace blink | 
| OLD | NEW |