| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { | 121 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { |
| 119 // This method was introduced to check the parent frame's security context | 122 // This method was introduced to check the parent frame's security context |
| 120 // while loading iframe document resources. So this method is not suitable for | 123 // while loading iframe document resources. So this method is not suitable for |
| 121 // workers. | 124 // workers. |
| 122 NOTREACHED(); | 125 NOTREACHED(); |
| 123 return nullptr; | 126 return nullptr; |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool WorkerFetchContext::ShouldBlockRequestByInspector( | 129 bool WorkerFetchContext::ShouldBlockRequestByInspector( |
| 127 const ResourceRequest& resource_request) const { | 130 const ResourceRequest& resource_request) const { |
| 128 // TODO(horo): Implement this. | 131 bool should_block_request = false; |
| 129 return false; | 132 probe::shouldBlockRequest(worker_global_scope_, resource_request, |
| 133 &should_block_request); |
| 134 return should_block_request; |
| 130 } | 135 } |
| 131 | 136 |
| 132 void WorkerFetchContext::DispatchDidBlockRequest( | 137 void WorkerFetchContext::DispatchDidBlockRequest( |
| 133 const ResourceRequest& resource_request, | 138 const ResourceRequest& resource_request, |
| 134 const FetchInitiatorInfo& fetch_initiator_info, | 139 const FetchInitiatorInfo& fetch_initiator_info, |
| 135 ResourceRequestBlockedReason blocked_reason) const { | 140 ResourceRequestBlockedReason blocked_reason) const { |
| 136 // TODO(horo): Implement this. | 141 probe::didBlockRequest(worker_global_scope_, resource_request, nullptr, |
| 142 fetch_initiator_info, blocked_reason); |
| 137 } | 143 } |
| 138 | 144 |
| 139 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { | 145 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { |
| 140 // Threre is no way to load local files from worker thread. | 146 // Threre is no way to load local files from worker thread. |
| 141 NOTREACHED(); | 147 NOTREACHED(); |
| 142 } | 148 } |
| 143 | 149 |
| 144 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { | 150 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { |
| 145 // This method was introduced to bypass the page's CSP while running the | 151 // This method was introduced to bypass the page's CSP while running the |
| 146 // script from an isolated world (ex: Chrome extensions). But worker threads | 152 // script from an isolated world (ex: Chrome extensions). But worker threads |
| (...skipping 26 matching lines...) Expand all Loading... |
| 173 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { | 179 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { |
| 174 return web_context_->CreateURLLoader(); | 180 return web_context_->CreateURLLoader(); |
| 175 } | 181 } |
| 176 | 182 |
| 177 bool WorkerFetchContext::IsControlledByServiceWorker() const { | 183 bool WorkerFetchContext::IsControlledByServiceWorker() const { |
| 178 return web_context_->IsControlledByServiceWorker(); | 184 return web_context_->IsControlledByServiceWorker(); |
| 179 } | 185 } |
| 180 | 186 |
| 181 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | 187 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, |
| 182 RedirectType) { | 188 RedirectType) { |
| 189 String user_agent = worker_global_scope_->UserAgent(); |
| 190 probe::applyUserAgentOverride(worker_global_scope_, &user_agent); |
| 191 DCHECK(!user_agent.IsNull()); |
| 192 request.SetHTTPUserAgent(AtomicString(user_agent)); |
| 193 |
| 183 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); | 194 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); |
| 184 WrappedResourceRequest webreq(request); | 195 WrappedResourceRequest webreq(request); |
| 185 web_context_->WillSendRequest(webreq); | 196 web_context_->WillSendRequest(webreq); |
| 186 } | 197 } |
| 187 | 198 |
| 188 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { | 199 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { |
| 189 return loading_task_runner_; | 200 return loading_task_runner_; |
| 190 } | 201 } |
| 191 | 202 |
| 192 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, | 203 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, |
| 193 FetchResourceType type) { | 204 FetchResourceType type) { |
| 194 BaseFetchContext::AddAdditionalRequestHeaders(request, type); | 205 BaseFetchContext::AddAdditionalRequestHeaders(request, type); |
| 195 | 206 |
| 196 // The remaining modifications are only necessary for HTTP and HTTPS. | 207 // The remaining modifications are only necessary for HTTP and HTTPS. |
| 197 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) | 208 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) |
| 198 return; | 209 return; |
| 199 | 210 |
| 200 if (web_context_->IsDataSaverEnabled()) | 211 if (web_context_->IsDataSaverEnabled()) |
| 201 request.SetHTTPHeaderField("Save-Data", "on"); | 212 request.SetHTTPHeaderField("Save-Data", "on"); |
| 202 } | 213 } |
| 203 | 214 |
| 215 void WorkerFetchContext::DispatchWillSendRequest( |
| 216 unsigned long identifier, |
| 217 ResourceRequest& request, |
| 218 const ResourceResponse& redirect_response, |
| 219 const FetchInitiatorInfo& initiator_info) { |
| 220 probe::willSendRequest(worker_global_scope_, identifier, nullptr, request, |
| 221 redirect_response, initiator_info); |
| 222 } |
| 223 |
| 204 void WorkerFetchContext::DispatchDidReceiveResponse( | 224 void WorkerFetchContext::DispatchDidReceiveResponse( |
| 205 unsigned long identifier, | 225 unsigned long identifier, |
| 206 const ResourceResponse& response, | 226 const ResourceResponse& response, |
| 207 WebURLRequest::FrameType frame_type, | 227 WebURLRequest::FrameType frame_type, |
| 208 WebURLRequest::RequestContext request_context, | 228 WebURLRequest::RequestContext request_context, |
| 209 Resource* resource, | 229 Resource* resource, |
| 210 ResourceResponseType) { | 230 ResourceResponseType) { |
| 211 if (response.HasMajorCertificateErrors()) { | 231 if (response.HasMajorCertificateErrors()) { |
| 212 WebMixedContentContextType context_type = | 232 WebMixedContentContextType context_type = |
| 213 WebMixedContent::ContextTypeFromRequestContext( | 233 WebMixedContent::ContextTypeFromRequestContext( |
| 214 request_context, false /* strictMixedContentCheckingForPlugin */); | 234 request_context, false /* strictMixedContentCheckingForPlugin */); |
| 215 if (context_type == WebMixedContentContextType::kBlockable) { | 235 if (context_type == WebMixedContentContextType::kBlockable) { |
| 216 web_context_->DidRunContentWithCertificateErrors(response.Url()); | 236 web_context_->DidRunContentWithCertificateErrors(response.Url()); |
| 217 } else { | 237 } else { |
| 218 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); | 238 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); |
| 219 } | 239 } |
| 220 } | 240 } |
| 241 probe::didReceiveResourceResponse(worker_global_scope_, identifier, nullptr, |
| 242 response, resource); |
| 243 } |
| 244 |
| 245 void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier, |
| 246 const char* data, |
| 247 int data_length) { |
| 248 probe::didReceiveData(worker_global_scope_, identifier, nullptr, data, |
| 249 data_length); |
| 250 } |
| 251 |
| 252 void WorkerFetchContext::DispatchDidReceiveEncodedData( |
| 253 unsigned long identifier, |
| 254 int encoded_data_length) { |
| 255 probe::didReceiveEncodedDataLength(worker_global_scope_, identifier, |
| 256 encoded_data_length); |
| 257 } |
| 258 |
| 259 void WorkerFetchContext::DispatchDidFinishLoading(unsigned long identifier, |
| 260 double finish_time, |
| 261 int64_t encoded_data_length, |
| 262 int64_t decoded_body_length) { |
| 263 probe::didFinishLoading(worker_global_scope_, identifier, nullptr, |
| 264 finish_time, encoded_data_length, |
| 265 decoded_body_length); |
| 266 } |
| 267 |
| 268 void WorkerFetchContext::DispatchDidFail(unsigned long identifier, |
| 269 const ResourceError& error, |
| 270 int64_t encoded_data_length, |
| 271 bool is_internal_request) { |
| 272 probe::didFailLoading(worker_global_scope_, identifier, error); |
| 221 } | 273 } |
| 222 | 274 |
| 223 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { | 275 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { |
| 224 WorkerGlobalScopePerformance::performance(*worker_global_scope_) | 276 WorkerGlobalScopePerformance::performance(*worker_global_scope_) |
| 225 ->AddResourceTiming(info); | 277 ->AddResourceTiming(info); |
| 226 } | 278 } |
| 227 | 279 |
| 228 void WorkerFetchContext::PopulateResourceRequest( | 280 void WorkerFetchContext::PopulateResourceRequest( |
| 229 const KURL& url, | 281 const KURL& url, |
| 230 Resource::Type type, | 282 Resource::Type type, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 256 void ProvideWorkerFetchContextToWorker( | 308 void ProvideWorkerFetchContextToWorker( |
| 257 WorkerClients* clients, | 309 WorkerClients* clients, |
| 258 std::unique_ptr<WebWorkerFetchContext> web_context) { | 310 std::unique_ptr<WebWorkerFetchContext> web_context) { |
| 259 DCHECK(clients); | 311 DCHECK(clients); |
| 260 WorkerFetchContextHolder::ProvideTo( | 312 WorkerFetchContextHolder::ProvideTo( |
| 261 *clients, WorkerFetchContextHolder::SupplementName(), | 313 *clients, WorkerFetchContextHolder::SupplementName(), |
| 262 new WorkerFetchContextHolder(std::move(web_context))); | 314 new WorkerFetchContextHolder(std::move(web_context))); |
| 263 } | 315 } |
| 264 | 316 |
| 265 } // namespace blink | 317 } // namespace blink |
| OLD | NEW |