Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp

Issue 2900613002: Support DevTools for off-main-thread-fetch (Closed)
Patch Set: rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dom/TaskRunnerHelper.h" 7 #include "core/dom/TaskRunnerHelper.h"
8 #include "core/frame/Deprecation.h" 8 #include "core/frame/Deprecation.h"
9 #include "core/frame/UseCounter.h" 9 #include "core/frame/UseCounter.h"
10 #include "core/loader/MixedContentChecker.h" 10 #include "core/loader/MixedContentChecker.h"
11 #include "core/probe/CoreProbes.h"
11 #include "core/timing/WorkerGlobalScopePerformance.h" 12 #include "core/timing/WorkerGlobalScopePerformance.h"
12 #include "core/workers/WorkerClients.h" 13 #include "core/workers/WorkerClients.h"
14 #include "core/workers/WorkerGlobalScope.h"
15 #include "platform/RuntimeEnabledFeatures.h"
13 #include "platform/Supplementable.h" 16 #include "platform/Supplementable.h"
14 #include "platform/WebTaskRunner.h" 17 #include "platform/WebTaskRunner.h"
15 #include "platform/exported/WrappedResourceRequest.h" 18 #include "platform/exported/WrappedResourceRequest.h"
16 #include "platform/loader/fetch/ResourceFetcher.h" 19 #include "platform/loader/fetch/ResourceFetcher.h"
20 #include "platform/weborigin/SecurityPolicy.h"
21 #include "public/platform/Platform.h"
17 #include "public/platform/WebMixedContent.h" 22 #include "public/platform/WebMixedContent.h"
18 #include "public/platform/WebMixedContentContextType.h" 23 #include "public/platform/WebMixedContentContextType.h"
19 #include "public/platform/WebURLRequest.h" 24 #include "public/platform/WebURLRequest.h"
20 #include "public/platform/WebWorkerFetchContext.h" 25 #include "public/platform/WebWorkerFetchContext.h"
21 26
22 namespace blink { 27 namespace blink {
23 28
24 namespace { 29 namespace {
25 30
26 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the 31 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return nullptr; 110 return nullptr;
106 } 111 }
107 112
108 SubresourceFilter* WorkerFetchContext::GetSubresourceFilter() const { 113 SubresourceFilter* WorkerFetchContext::GetSubresourceFilter() const {
109 // TODO(horo): Implement this. 114 // TODO(horo): Implement this.
110 return nullptr; 115 return nullptr;
111 } 116 }
112 117
113 bool WorkerFetchContext::ShouldBlockRequestByInspector( 118 bool WorkerFetchContext::ShouldBlockRequestByInspector(
114 const ResourceRequest& resource_request) const { 119 const ResourceRequest& resource_request) const {
115 // TODO(horo): Implement this. 120 bool should_block_request = false;
116 return false; 121 probe::shouldBlockRequest(global_scope_, resource_request,
122 &should_block_request);
123 return should_block_request;
117 } 124 }
118 125
119 void WorkerFetchContext::DispatchDidBlockRequest( 126 void WorkerFetchContext::DispatchDidBlockRequest(
120 const ResourceRequest& resource_request, 127 const ResourceRequest& resource_request,
121 const FetchInitiatorInfo& fetch_initiator_info, 128 const FetchInitiatorInfo& fetch_initiator_info,
122 ResourceRequestBlockedReason blocked_reason) const { 129 ResourceRequestBlockedReason blocked_reason) const {
123 // TODO(horo): Implement this. 130 probe::didBlockRequest(global_scope_, resource_request, nullptr,
131 fetch_initiator_info, blocked_reason);
124 } 132 }
125 133
126 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { 134 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const {
127 // This method was introduced to bypass the page's CSP while running the 135 // This method was introduced to bypass the page's CSP while running the
128 // script from an isolated world (ex: Chrome extensions). But worker threads 136 // script from an isolated world (ex: Chrome extensions). But worker threads
129 // doesn't have any isolated world. So we can just return false. 137 // doesn't have any isolated world. So we can just return false.
130 return false; 138 return false;
131 } 139 }
132 140
133 bool WorkerFetchContext::IsSVGImageChromeClient() const { 141 bool WorkerFetchContext::IsSVGImageChromeClient() const {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return web_context_->CreateURLLoader( 222 return web_context_->CreateURLLoader(
215 wrapped, loading_task_runner_->ToSingleThreadTaskRunner()); 223 wrapped, loading_task_runner_->ToSingleThreadTaskRunner());
216 } 224 }
217 225
218 bool WorkerFetchContext::IsControlledByServiceWorker() const { 226 bool WorkerFetchContext::IsControlledByServiceWorker() const {
219 return web_context_->IsControlledByServiceWorker(); 227 return web_context_->IsControlledByServiceWorker();
220 } 228 }
221 229
222 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, 230 void WorkerFetchContext::PrepareRequest(ResourceRequest& request,
223 RedirectType) { 231 RedirectType) {
232 String user_agent = global_scope_->UserAgent();
233 probe::applyUserAgentOverride(global_scope_, &user_agent);
234 DCHECK(!user_agent.IsNull());
235 request.SetHTTPUserAgent(AtomicString(user_agent));
236
224 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); 237 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo);
225 WrappedResourceRequest webreq(request); 238 WrappedResourceRequest webreq(request);
226 web_context_->WillSendRequest(webreq); 239 web_context_->WillSendRequest(webreq);
227 } 240 }
228 241
229 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, 242 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request,
230 FetchResourceType type) { 243 FetchResourceType type) {
231 BaseFetchContext::AddAdditionalRequestHeaders(request, type); 244 BaseFetchContext::AddAdditionalRequestHeaders(request, type);
232 245
233 // The remaining modifications are only necessary for HTTP and HTTPS. 246 // The remaining modifications are only necessary for HTTP and HTTPS.
234 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) 247 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily())
235 return; 248 return;
236 249
237 if (web_context_->IsDataSaverEnabled()) 250 if (web_context_->IsDataSaverEnabled())
238 request.SetHTTPHeaderField("Save-Data", "on"); 251 request.SetHTTPHeaderField("Save-Data", "on");
239 } 252 }
240 253
254 void WorkerFetchContext::DispatchWillSendRequest(
255 unsigned long identifier,
256 ResourceRequest& request,
257 const ResourceResponse& redirect_response,
258 const FetchInitiatorInfo& initiator_info) {
259 probe::willSendRequest(global_scope_, identifier, nullptr, request,
260 redirect_response, initiator_info);
261 }
262
241 void WorkerFetchContext::DispatchDidReceiveResponse( 263 void WorkerFetchContext::DispatchDidReceiveResponse(
242 unsigned long identifier, 264 unsigned long identifier,
243 const ResourceResponse& response, 265 const ResourceResponse& response,
244 WebURLRequest::FrameType frame_type, 266 WebURLRequest::FrameType frame_type,
245 WebURLRequest::RequestContext request_context, 267 WebURLRequest::RequestContext request_context,
246 Resource* resource, 268 Resource* resource,
247 ResourceResponseType) { 269 ResourceResponseType) {
248 if (response.HasMajorCertificateErrors()) { 270 if (response.HasMajorCertificateErrors()) {
249 WebMixedContentContextType context_type = 271 WebMixedContentContextType context_type =
250 WebMixedContent::ContextTypeFromRequestContext( 272 WebMixedContent::ContextTypeFromRequestContext(
251 request_context, false /* strictMixedContentCheckingForPlugin */); 273 request_context, false /* strictMixedContentCheckingForPlugin */);
252 if (context_type == WebMixedContentContextType::kBlockable) { 274 if (context_type == WebMixedContentContextType::kBlockable) {
253 web_context_->DidRunContentWithCertificateErrors(response.Url()); 275 web_context_->DidRunContentWithCertificateErrors(response.Url());
254 } else { 276 } else {
255 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); 277 web_context_->DidDisplayContentWithCertificateErrors(response.Url());
256 } 278 }
257 } 279 }
280 probe::didReceiveResourceResponse(global_scope_, identifier, nullptr,
281 response, resource);
282 }
283
284 void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier,
285 const char* data,
286 int data_length) {
287 probe::didReceiveData(global_scope_, identifier, nullptr, data, data_length);
288 }
289
290 void WorkerFetchContext::DispatchDidReceiveEncodedData(
291 unsigned long identifier,
292 int encoded_data_length) {
293 probe::didReceiveEncodedDataLength(global_scope_, identifier,
294 encoded_data_length);
295 }
296
297 void WorkerFetchContext::DispatchDidFinishLoading(unsigned long identifier,
298 double finish_time,
299 int64_t encoded_data_length,
300 int64_t decoded_body_length) {
301 probe::didFinishLoading(global_scope_, identifier, nullptr, finish_time,
302 encoded_data_length, decoded_body_length);
303 }
304
305 void WorkerFetchContext::DispatchDidFail(unsigned long identifier,
306 const ResourceError& error,
307 int64_t encoded_data_length,
308 bool is_internal_request) {
309 probe::didFailLoading(global_scope_, identifier, error);
258 } 310 }
259 311
260 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { 312 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) {
261 // TODO(nhiroki): Add ResourceTiming API support once it's spec'ed for 313 // TODO(nhiroki): Add ResourceTiming API support once it's spec'ed for
262 // worklets. 314 // worklets.
263 if (global_scope_->IsWorkletGlobalScope()) 315 if (global_scope_->IsWorkletGlobalScope())
264 return; 316 return;
265 WorkerGlobalScopePerformance::performance(*ToWorkerGlobalScope(global_scope_)) 317 WorkerGlobalScopePerformance::performance(*ToWorkerGlobalScope(global_scope_))
266 ->AddResourceTiming(info); 318 ->AddResourceTiming(info);
267 } 319 }
(...skipping 26 matching lines...) Expand all
294 void ProvideWorkerFetchContextToWorker( 346 void ProvideWorkerFetchContextToWorker(
295 WorkerClients* clients, 347 WorkerClients* clients,
296 std::unique_ptr<WebWorkerFetchContext> web_context) { 348 std::unique_ptr<WebWorkerFetchContext> web_context) {
297 DCHECK(clients); 349 DCHECK(clients);
298 WorkerFetchContextHolder::ProvideTo( 350 WorkerFetchContextHolder::ProvideTo(
299 *clients, WorkerFetchContextHolder::SupplementName(), 351 *clients, WorkerFetchContextHolder::SupplementName(),
300 new WorkerFetchContextHolder(std::move(web_context))); 352 new WorkerFetchContextHolder(std::move(web_context)));
301 } 353 }
302 354
303 } // namespace blink 355 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/WorkerFetchContext.h ('k') | third_party/WebKit/Source/core/probe/CoreProbes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698