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

Side by Side Diff: Source/core/xml/XMLHttpRequest.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/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 RefPtr<XMLHttpRequest> xmlHttpRequest(adoptRef(new XMLHttpRequest(context, s ecurityOrigin))); 159 RefPtr<XMLHttpRequest> xmlHttpRequest(adoptRef(new XMLHttpRequest(context, s ecurityOrigin)));
160 xmlHttpRequest->suspendIfNeeded(); 160 xmlHttpRequest->suspendIfNeeded();
161 161
162 return xmlHttpRequest.release(); 162 return xmlHttpRequest.release();
163 } 163 }
164 164
165 XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context, PassRefPtr<Secur ityOrigin> securityOrigin) 165 XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context, PassRefPtr<Secur ityOrigin> securityOrigin)
166 : ActiveDOMObject(context) 166 : ActiveDOMObject(context)
167 , m_async(true) 167 , m_async(true)
168 , m_includeCredentials(false) 168 , m_includeCredentials(false)
169 #if ENABLE(XHR_TIMEOUT)
170 , m_timeoutMilliseconds(0) 169 , m_timeoutMilliseconds(0)
171 #endif
172 , m_state(UNSENT) 170 , m_state(UNSENT)
173 , m_createdDocument(false) 171 , m_createdDocument(false)
174 , m_error(false) 172 , m_error(false)
175 , m_uploadEventsAllowed(true) 173 , m_uploadEventsAllowed(true)
176 , m_uploadComplete(false) 174 , m_uploadComplete(false)
177 , m_sameOriginRequest(true) 175 , m_sameOriginRequest(true)
178 , m_allowCrossOriginRequests(false) 176 , m_allowCrossOriginRequests(false)
179 , m_receivedLength(0) 177 , m_receivedLength(0)
180 , m_lastSendLineNumber(0) 178 , m_lastSendLineNumber(0)
181 , m_exceptionCode(0) 179 , m_exceptionCode(0)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return 0; 304 return 0;
307 305
308 if (!m_responseArrayBuffer.get() && m_binaryResponseBuilder.get() && m_binar yResponseBuilder->size() > 0) { 306 if (!m_responseArrayBuffer.get() && m_binaryResponseBuilder.get() && m_binar yResponseBuilder->size() > 0) {
309 m_responseArrayBuffer = m_binaryResponseBuilder->getAsArrayBuffer(); 307 m_responseArrayBuffer = m_binaryResponseBuilder->getAsArrayBuffer();
310 m_binaryResponseBuilder.clear(); 308 m_binaryResponseBuilder.clear();
311 } 309 }
312 310
313 return m_responseArrayBuffer.get(); 311 return m_responseArrayBuffer.get();
314 } 312 }
315 313
316 #if ENABLE(XHR_TIMEOUT)
317 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionCode& ec) 314 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionCode& ec)
318 { 315 {
319 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156 316 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156
320 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching." 317 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching."
321 if (scriptExecutionContext()->isDocument() && !m_async) { 318 if (scriptExecutionContext()->isDocument() && !m_async) {
322 logConsoleError(scriptExecutionContext(), "XMLHttpRequest.timeout cannot be set for synchronous HTTP(S) requests made from the window context."); 319 logConsoleError(scriptExecutionContext(), "XMLHttpRequest.timeout cannot be set for synchronous HTTP(S) requests made from the window context.");
323 ec = INVALID_ACCESS_ERR; 320 ec = INVALID_ACCESS_ERR;
324 return; 321 return;
325 } 322 }
326 m_timeoutMilliseconds = timeout; 323 m_timeoutMilliseconds = timeout;
327 } 324 }
328 #endif
329 325
330 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionCode& ec) 326 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionCode& ec)
331 { 327 {
332 if (m_state >= LOADING) { 328 if (m_state >= LOADING) {
333 ec = INVALID_STATE_ERR; 329 ec = INVALID_STATE_ERR;
334 return; 330 return;
335 } 331 }
336 332
337 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated 333 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated
338 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. 334 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // Newer functionality is not available to synchronous requests in windo w contexts, as a spec-mandated 486 // Newer functionality is not available to synchronous requests in windo w contexts, as a spec-mandated
491 // attempt to discourage synchronous XHR use. responseType is one such p iece of functionality. 487 // attempt to discourage synchronous XHR use. responseType is one such p iece of functionality.
492 // We'll only disable this functionality for HTTP(S) requests since sync requests for local protocols 488 // We'll only disable this functionality for HTTP(S) requests since sync requests for local protocols
493 // such as file: and data: still make sense to allow. 489 // such as file: and data: still make sense to allow.
494 if (url.protocolIsInHTTPFamily() && m_responseTypeCode != ResponseTypeDe fault) { 490 if (url.protocolIsInHTTPFamily() && m_responseTypeCode != ResponseTypeDe fault) {
495 logConsoleError(scriptExecutionContext(), "Synchronous HTTP(S) reque sts made from the window context cannot have XMLHttpRequest.responseType set."); 491 logConsoleError(scriptExecutionContext(), "Synchronous HTTP(S) reque sts made from the window context cannot have XMLHttpRequest.responseType set.");
496 ec = INVALID_ACCESS_ERR; 492 ec = INVALID_ACCESS_ERR;
497 return; 493 return;
498 } 494 }
499 495
500 #if ENABLE(XHR_TIMEOUT)
501 // Similarly, timeouts are disabled for synchronous requests as well. 496 // Similarly, timeouts are disabled for synchronous requests as well.
502 if (m_timeoutMilliseconds > 0) { 497 if (m_timeoutMilliseconds > 0) {
503 logConsoleError(scriptExecutionContext(), "Synchronous XMLHttpReques ts must not have a timeout value set."); 498 logConsoleError(scriptExecutionContext(), "Synchronous XMLHttpReques ts must not have a timeout value set.");
504 ec = INVALID_ACCESS_ERR; 499 ec = INVALID_ACCESS_ERR;
505 return; 500 return;
506 } 501 }
507 #endif
508 } 502 }
509 503
510 m_method = uppercaseKnownHTTPMethod(method); 504 m_method = uppercaseKnownHTTPMethod(method);
511 505
512 m_url = url; 506 m_url = url;
513 507
514 m_async = async; 508 m_async = async;
515 509
516 ASSERT(!m_loader); 510 ASSERT(!m_loader);
517 511
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ThreadableLoaderOptions options; 737 ThreadableLoaderOptions options;
744 options.sendLoadCallbacks = SendCallbacks; 738 options.sendLoadCallbacks = SendCallbacks;
745 options.sniffContent = DoNotSniffContent; 739 options.sniffContent = DoNotSniffContent;
746 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; 740 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight;
747 options.allowCredentials = (m_sameOriginRequest || m_includeCredentials) ? A llowStoredCredentials : DoNotAllowStoredCredentials; 741 options.allowCredentials = (m_sameOriginRequest || m_includeCredentials) ? A llowStoredCredentials : DoNotAllowStoredCredentials;
748 options.credentialsRequested = m_includeCredentials ? ClientRequestedCredent ials : ClientDidNotRequestCredentials; 742 options.credentialsRequested = m_includeCredentials ? ClientRequestedCredent ials : ClientDidNotRequestCredentials;
749 options.crossOriginRequestPolicy = m_allowCrossOriginRequests ? AllowCrossOr iginRequests : UseAccessControl; 743 options.crossOriginRequestPolicy = m_allowCrossOriginRequests ? AllowCrossOr iginRequests : UseAccessControl;
750 options.securityOrigin = securityOrigin(); 744 options.securityOrigin = securityOrigin();
751 options.initiator = cachedResourceRequestInitiators().xmlhttprequest; 745 options.initiator = cachedResourceRequestInitiators().xmlhttprequest;
752 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(scriptExecutionContext()) ? DoNotEnforceContentSecurityPolicy : Enfo rceConnectSrcDirective; 746 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(scriptExecutionContext()) ? DoNotEnforceContentSecurityPolicy : Enfo rceConnectSrcDirective;
753 747 options.timeoutMilliseconds = m_timeoutMilliseconds;
754 #if ENABLE(XHR_TIMEOUT)
755 if (m_timeoutMilliseconds)
756 request.setTimeoutInterval(m_timeoutMilliseconds / 1000.0);
757 #endif
758 748
759 m_exceptionCode = 0; 749 m_exceptionCode = 0;
760 m_error = false; 750 m_error = false;
761 751
762 if (m_async) { 752 if (m_async) {
763 if (m_upload) 753 if (m_upload)
764 request.setReportUploadProgress(true); 754 request.setReportUploadProgress(true);
765 755
766 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. 756 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page.
767 // This is true while running onunload handlers. 757 // This is true while running onunload handlers.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 // If we are already in an error state, for instance we called abort(), bail out early. 1046 // If we are already in an error state, for instance we called abort(), bail out early.
1057 if (m_error) 1047 if (m_error)
1058 return; 1048 return;
1059 1049
1060 if (error.isCancellation()) { 1050 if (error.isCancellation()) {
1061 m_exceptionCode = ABORT_ERR; 1051 m_exceptionCode = ABORT_ERR;
1062 abortError(); 1052 abortError();
1063 return; 1053 return;
1064 } 1054 }
1065 1055
1066 #if ENABLE(XHR_TIMEOUT)
1067 if (error.isTimeout()) { 1056 if (error.isTimeout()) {
1068 didTimeout(); 1057 didTimeout();
1069 return; 1058 return;
1070 } 1059 }
1071 #endif
1072 1060
1073 // Network failures are already reported to Web Inspector by ResourceLoader. 1061 // Network failures are already reported to Web Inspector by ResourceLoader.
1074 if (error.domain() == errorDomainWebKitInternal) 1062 if (error.domain() == errorDomainWebKitInternal)
1075 logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription()); 1063 logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription());
1076 1064
1077 m_exceptionCode = NETWORK_ERR; 1065 m_exceptionCode = NETWORK_ERR;
1078 networkError(); 1066 networkError();
1079 } 1067 }
1080 1068
1081 void XMLHttpRequest::didFailRedirectCheck() 1069 void XMLHttpRequest::didFailRedirectCheck()
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1173 }
1186 1174
1187 if (m_state != LOADING) 1175 if (m_state != LOADING)
1188 changeState(LOADING); 1176 changeState(LOADING);
1189 else 1177 else
1190 // Firefox calls readyStateChanged every time it receives data, 4449 442 1178 // Firefox calls readyStateChanged every time it receives data, 4449 442
1191 callReadyStateChangeListener(); 1179 callReadyStateChangeListener();
1192 } 1180 }
1193 } 1181 }
1194 1182
1195 #if ENABLE(XHR_TIMEOUT)
1196 void XMLHttpRequest::didTimeout() 1183 void XMLHttpRequest::didTimeout()
1197 { 1184 {
1198 // internalAbort() calls dropProtection(), which may release the last refere nce. 1185 // internalAbort() calls dropProtection(), which may release the last refere nce.
1199 RefPtr<XMLHttpRequest> protect(this); 1186 RefPtr<XMLHttpRequest> protect(this);
1200 internalAbort(); 1187 internalAbort();
1201 1188
1202 clearResponse(); 1189 clearResponse();
1203 clearRequest(); 1190 clearRequest();
1204 1191
1205 m_error = true; 1192 m_error = true;
1206 m_exceptionCode = TIMEOUT_ERR; 1193 m_exceptionCode = TIMEOUT_ERR;
1207 1194
1208 if (!m_async) { 1195 if (!m_async) {
1209 m_state = DONE; 1196 m_state = DONE;
1210 m_exceptionCode = TIMEOUT_ERR; 1197 m_exceptionCode = TIMEOUT_ERR;
1211 return; 1198 return;
1212 } 1199 }
1213 1200
1214 changeState(DONE); 1201 changeState(DONE);
1215 1202
1216 if (!m_uploadComplete) { 1203 if (!m_uploadComplete) {
1217 m_uploadComplete = true; 1204 m_uploadComplete = true;
1218 if (m_upload && m_uploadEventsAllowed) 1205 if (m_upload && m_uploadEventsAllowed)
1219 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().timeoutEvent)); 1206 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(eventNames().timeoutEvent));
1220 } 1207 }
1221 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().timeoutEvent)); 1208 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(eventNames().timeoutEvent));
1222 } 1209 }
1223 #endif
1224 1210
1225 bool XMLHttpRequest::canSuspend() const 1211 bool XMLHttpRequest::canSuspend() const
1226 { 1212 {
1227 return !m_loader; 1213 return !m_loader;
1228 } 1214 }
1229 1215
1230 void XMLHttpRequest::suspend(ReasonForSuspension) 1216 void XMLHttpRequest::suspend(ReasonForSuspension)
1231 { 1217 {
1232 m_progressEventThrottle.suspend(); 1218 m_progressEventThrottle.suspend();
1233 } 1219 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 info.addMember(m_responseDocument, "responseDocument"); 1274 info.addMember(m_responseDocument, "responseDocument");
1289 info.addMember(m_binaryResponseBuilder, "binaryResponseBuilder"); 1275 info.addMember(m_binaryResponseBuilder, "binaryResponseBuilder");
1290 info.addMember(m_responseArrayBuffer, "responseArrayBuffer"); 1276 info.addMember(m_responseArrayBuffer, "responseArrayBuffer");
1291 info.addMember(m_lastSendURL, "lastSendURL"); 1277 info.addMember(m_lastSendURL, "lastSendURL");
1292 info.addMember(m_eventTargetData, "eventTargetData"); 1278 info.addMember(m_eventTargetData, "eventTargetData");
1293 info.addMember(m_progressEventThrottle, "progressEventThrottle"); 1279 info.addMember(m_progressEventThrottle, "progressEventThrottle");
1294 info.addMember(m_securityOrigin, "securityOrigin"); 1280 info.addMember(m_securityOrigin, "securityOrigin");
1295 } 1281 }
1296 1282
1297 } // namespace WebCore 1283 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698