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

Side by Side Diff: Source/core/loader/DocumentThreadableLoader.cpp

Issue 14246006: Implementing timeout support for XHR (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@timeoutResourceHandle
Patch Set: Timeout support in DocumentThreadableLoader (speculative bot failure fix) Created 7 years, 6 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
« no previous file with comments | « Source/core/loader/DocumentThreadableLoader.h ('k') | Source/core/loader/ThreadableLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
6 * met: 7 * met:
7 * 8 *
8 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return loader.release(); 68 return loader.release();
68 } 69 }
69 70
70 DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options) 71 DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options)
71 : m_client(client) 72 : m_client(client)
72 , m_document(document) 73 , m_document(document)
73 , m_options(options) 74 , m_options(options)
74 , m_sameOriginRequest(securityOrigin()->canRequest(request.url())) 75 , m_sameOriginRequest(securityOrigin()->canRequest(request.url()))
75 , m_simpleRequest(true) 76 , m_simpleRequest(true)
76 , m_async(blockingBehavior == LoadAsynchronously) 77 , m_async(blockingBehavior == LoadAsynchronously)
78 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout)
77 { 79 {
78 ASSERT(document); 80 ASSERT(document);
79 ASSERT(client); 81 ASSERT(client);
80 // Setting an outgoing referer is only supported in the async code path. 82 // Setting an outgoing referer is only supported in the async code path.
81 ASSERT(m_async || request.httpReferrer().isEmpty()); 83 ASSERT(m_async || request.httpReferrer().isEmpty());
82 84
83 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { 85 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
84 loadRequest(request, DoSecurityCheck); 86 loadRequest(request, DoSecurityCheck);
85 return; 87 return;
86 } 88 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 136 }
135 137
136 DocumentThreadableLoader::~DocumentThreadableLoader() 138 DocumentThreadableLoader::~DocumentThreadableLoader()
137 { 139 {
138 if (m_resource) 140 if (m_resource)
139 m_resource->removeClient(this); 141 m_resource->removeClient(this);
140 } 142 }
141 143
142 void DocumentThreadableLoader::cancel() 144 void DocumentThreadableLoader::cancel()
143 { 145 {
146 cancelWithError(ResourceError());
147 }
148
149 void DocumentThreadableLoader::cancelWithError(const ResourceError& error)
150 {
144 RefPtr<DocumentThreadableLoader> protect(this); 151 RefPtr<DocumentThreadableLoader> protect(this);
145 152
146 // Cancel can re-enter and m_resource might be null here as a result. 153 // Cancel can re-enter and m_resource might be null here as a result.
147 if (m_client && m_resource) { 154 if (m_client && m_resource) {
148 // FIXME: This error is sent to the client in didFail(), so it should no t be an internal one. Use FrameLoaderClient::cancelledError() instead. 155 ResourceError errorForCallback = error;
149 ResourceError error(errorDomainWebKitInternal, 0, m_resource->url().stri ng(), "Load cancelled"); 156 if (errorForCallback.isNull()) {
150 error.setIsCancellation(true); 157 // FIXME: This error is sent to the client in didFail(), so it shoul d not be an internal one. Use FrameLoaderClient::cancelledError() instead.
151 didFail(m_resource->identifier(), error); 158 errorForCallback = ResourceError(errorDomainWebKitInternal, 0, m_res ource->url().string(), "Load cancelled");
159 errorForCallback.setIsCancellation(true);
160 }
161 didFail(m_resource->identifier(), errorForCallback);
152 } 162 }
153 clearResource(); 163 clearResource();
154 m_client = 0; 164 m_client = 0;
155 } 165 }
156 166
157 void DocumentThreadableLoader::setDefersLoading(bool value) 167 void DocumentThreadableLoader::setDefersLoading(bool value)
158 { 168 {
159 if (m_resource) 169 if (m_resource)
160 m_resource->setDefersLoading(value); 170 m_resource->setDefersLoading(value);
161 } 171 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return; 322 return;
313 } 323 }
314 324
315 m_client->didReceiveData(data, dataLength); 325 m_client->didReceiveData(data, dataLength);
316 } 326 }
317 327
318 void DocumentThreadableLoader::notifyFinished(CachedResource* resource) 328 void DocumentThreadableLoader::notifyFinished(CachedResource* resource)
319 { 329 {
320 ASSERT(m_client); 330 ASSERT(m_client);
321 ASSERT_UNUSED(resource, resource == m_resource); 331 ASSERT_UNUSED(resource, resource == m_resource);
332
333 m_timeoutTimer.stop();
322 334
323 if (m_resource->errorOccurred()) 335 if (m_resource->errorOccurred())
324 didFail(m_resource->identifier(), m_resource->resourceError()); 336 didFail(m_resource->identifier(), m_resource->resourceError());
325 else 337 else
326 didFinishLoading(m_resource->identifier(), m_resource->loadFinishTime()) ; 338 didFinishLoading(m_resource->identifier(), m_resource->loadFinishTime()) ;
327 } 339 }
328 340
329 void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime) 341 void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime)
330 { 342 {
331 if (m_actualRequest) { 343 if (m_actualRequest) {
332 InspectorInstrumentation::didFinishLoading(m_document->frame(), identifi er, m_document->frame()->loader()->documentLoader(), finishTime); 344 InspectorInstrumentation::didFinishLoading(m_document->frame(), identifi er, m_document->frame()->loader()->documentLoader(), finishTime);
333 ASSERT(!m_sameOriginRequest); 345 ASSERT(!m_sameOriginRequest);
334 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); 346 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
335 preflightSuccess(); 347 preflightSuccess();
336 } else 348 } else
337 m_client->didFinishLoading(identifier, finishTime); 349 m_client->didFinishLoading(identifier, finishTime);
338 } 350 }
339 351
340 void DocumentThreadableLoader::didFail(unsigned long identifier, const ResourceE rror& error) 352 void DocumentThreadableLoader::didFail(unsigned long identifier, const ResourceE rror& error)
341 { 353 {
342 if (m_actualRequest) 354 if (m_actualRequest)
343 InspectorInstrumentation::didFailLoading(m_document->frame(), identifier , m_document->frame()->loader()->documentLoader(), error); 355 InspectorInstrumentation::didFailLoading(m_document->frame(), identifier , m_document->frame()->loader()->documentLoader(), error);
344 356
345 m_client->didFail(error); 357 m_client->didFail(error);
346 } 358 }
347 359
360 void DocumentThreadableLoader::didTimeout(Timer<DocumentThreadableLoader>* timer )
361 {
362 ASSERT_UNUSED(timer, timer == &m_timeoutTimer);
363
364 // Using values from net/base/net_error_list.h ERR_TIMED_OUT,
365 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable.
366 static const int timeoutError = -7;
367 ResourceError error("net", timeoutError, m_resource->url(), String());
368 error.setIsTimeout(true);
369 cancelWithError(error);
370 }
371
348 void DocumentThreadableLoader::preflightSuccess() 372 void DocumentThreadableLoader::preflightSuccess()
349 { 373 {
350 OwnPtr<ResourceRequest> actualRequest; 374 OwnPtr<ResourceRequest> actualRequest;
351 actualRequest.swap(m_actualRequest); 375 actualRequest.swap(m_actualRequest);
352 376
353 actualRequest->setHTTPOrigin(securityOrigin()->toString()); 377 actualRequest->setHTTPOrigin(securityOrigin()->toString());
354 378
355 clearResource(); 379 clearResource();
356 380
357 // It should be ok to skip the security check since we already asked about t he preflight request. 381 // It should be ok to skip the security check since we already asked about t he preflight request.
(...skipping 21 matching lines...) Expand all
379 ThreadableLoaderOptions options = m_options; 403 ThreadableLoaderOptions options = m_options;
380 options.crossOriginCredentialPolicy = DoNotAskClientForCrossOriginCreden tials; 404 options.crossOriginCredentialPolicy = DoNotAskClientForCrossOriginCreden tials;
381 if (m_actualRequest) { 405 if (m_actualRequest) {
382 // Don't sniff content or send load callbacks for the preflight requ est. 406 // Don't sniff content or send load callbacks for the preflight requ est.
383 options.sendLoadCallbacks = DoNotSendCallbacks; 407 options.sendLoadCallbacks = DoNotSendCallbacks;
384 options.sniffContent = DoNotSniffContent; 408 options.sniffContent = DoNotSniffContent;
385 // Keep buffering the data for the preflight request. 409 // Keep buffering the data for the preflight request.
386 options.dataBufferingPolicy = BufferData; 410 options.dataBufferingPolicy = BufferData;
387 } 411 }
388 412
413 if (m_options.timeoutMilliseconds > 0)
414 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0);
415
389 CachedResourceRequest newRequest(request, m_options.initiator, options); 416 CachedResourceRequest newRequest(request, m_options.initiator, options);
390 ASSERT(!m_resource); 417 ASSERT(!m_resource);
391 m_resource = m_document->cachedResourceLoader()->requestRawResource(newR equest); 418 m_resource = m_document->cachedResourceLoader()->requestRawResource(newR equest);
392 if (m_resource) { 419 if (m_resource) {
393 if (m_resource->loader()) { 420 if (m_resource->loader()) {
394 unsigned long identifier = m_resource->identifier(); 421 unsigned long identifier = m_resource->identifier();
395 InspectorInstrumentation::documentThreadableLoaderStartedLoading ForClient(m_document, identifier, m_client); 422 InspectorInstrumentation::documentThreadableLoaderStartedLoading ForClient(m_document, identifier, m_client);
396 } 423 }
397 m_resource->addClient(this); 424 m_resource->addClient(this);
398 } 425 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 return true; 480 return true;
454 return m_document->contentSecurityPolicy()->allowConnectToSource(url); 481 return m_document->contentSecurityPolicy()->allowConnectToSource(url);
455 } 482 }
456 483
457 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 484 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
458 { 485 {
459 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); 486 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin();
460 } 487 }
461 488
462 } // namespace WebCore 489 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentThreadableLoader.h ('k') | Source/core/loader/ThreadableLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698