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

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

Issue 273993002: Allow XHR timeout attribute to be overridden after send(), per spec (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 /* 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 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 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)
72 : m_client(client) 72 : m_client(client)
73 , m_document(document) 73 , m_document(document)
74 , m_options(options) 74 , m_options(options)
75 , m_sameOriginRequest(securityOrigin()->canRequest(request.url())) 75 , m_sameOriginRequest(securityOrigin()->canRequest(request.url()))
76 , m_simpleRequest(true) 76 , m_simpleRequest(true)
77 , m_async(blockingBehavior == LoadAsynchronously) 77 , m_async(blockingBehavior == LoadAsynchronously)
78 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) 78 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout)
79 , m_requestStarted(0.0)
79 { 80 {
80 ASSERT(client); 81 ASSERT(client);
81 // 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.
82 ASSERT(m_async || request.httpReferrer().isEmpty()); 83 ASSERT(m_async || request.httpReferrer().isEmpty());
83 84
84 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request 85 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request
85 // create a new one, and copy these headers. 86 // create a new one, and copy these headers.
86 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); 87 const HTTPHeaderMap& headerMap = request.httpHeaderFields();
87 HTTPHeaderMap::const_iterator end = headerMap.end(); 88 HTTPHeaderMap::const_iterator end = headerMap.end();
88 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) { 89 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ResourceRequest preflightRequest = createAccessControlPreflightReque st(*m_actualRequest, securityOrigin()); 132 ResourceRequest preflightRequest = createAccessControlPreflightReque st(*m_actualRequest, securityOrigin());
132 loadRequest(preflightRequest); 133 loadRequest(preflightRequest);
133 } 134 }
134 } 135 }
135 } 136 }
136 137
137 DocumentThreadableLoader::~DocumentThreadableLoader() 138 DocumentThreadableLoader::~DocumentThreadableLoader()
138 { 139 {
139 } 140 }
140 141
142 void DocumentThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds )
143 {
144 if (m_async) {
tyoshino (SeeGerritForStatus) 2014/05/09 08:04:36 if (!m_async) return; ...
145 m_timeoutTimer.stop();
146 // At the time of this method's implementation, it is only ever called b y
147 // XMLHttpRequest, when the timeout attribute is set after sending the
148 // request.
149 //
150 // The XHR request says to resolve the time relative to when the request
151 // was initially sent, however other uses of this method may need to
152 // behave differently, in which case this should be re-arranged somehow.
153 if (timeoutMilliseconds) {
154 double resolvedTime = m_requestStarted + timeoutMilliseconds / 1000. 0;
155 m_timeoutTimer.startOneShotExact(resolvedTime, FROM_HERE);
tyoshino (SeeGerritForStatus) 2014/05/09 08:04:36 any reason you chose to add this new method to Tim
caitp (gmail) 2014/05/09 08:39:49 For IEEE floating point math, you lose accuracy if
156 }
157 }
158 }
159
141 void DocumentThreadableLoader::cancel() 160 void DocumentThreadableLoader::cancel()
142 { 161 {
143 cancelWithError(ResourceError()); 162 cancelWithError(ResourceError());
144 } 163 }
145 164
146 void DocumentThreadableLoader::cancelWithError(const ResourceError& error) 165 void DocumentThreadableLoader::cancelWithError(const ResourceError& error)
147 { 166 {
148 RefPtr<DocumentThreadableLoader> protect(this); 167 RefPtr<DocumentThreadableLoader> protect(this);
149 168
150 // Cancel can re-enter and m_resource might be null here as a result. 169 // Cancel can re-enter and m_resource might be null here as a result.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 m_client->didFailAccessControlCheck(error); 399 m_client->didFailAccessControlCheck(error);
381 } 400 }
382 401
383 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request) 402 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request)
384 { 403 {
385 // Any credential should have been removed from the cross-site requests. 404 // Any credential should have been removed from the cross-site requests.
386 const KURL& requestURL = request.url(); 405 const KURL& requestURL = request.url();
387 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); 406 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty());
388 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); 407 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty());
389 408
409 m_requestStarted = monotonicallyIncreasingTime();
tyoshino (SeeGerritForStatus) 2014/05/09 08:04:36 move this to between L419 and L420 (outside of if-
410
390 ThreadableLoaderOptions options = m_options; 411 ThreadableLoaderOptions options = m_options;
391 if (m_async) { 412 if (m_async) {
392 if (m_actualRequest) { 413 if (m_actualRequest) {
393 options.sniffContent = DoNotSniffContent; 414 options.sniffContent = DoNotSniffContent;
394 options.dataBufferingPolicy = BufferData; 415 options.dataBufferingPolicy = BufferData;
395 } 416 }
396 417
397 if (m_options.timeoutMilliseconds > 0) 418 if (m_options.timeoutMilliseconds > 0)
398 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, FROM_HERE); 419 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, FROM_HERE);
399 420
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 return true; 482 return true;
462 return m_document.contentSecurityPolicy()->allowConnectToSource(url); 483 return m_document.contentSecurityPolicy()->allowConnectToSource(url);
463 } 484 }
464 485
465 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 486 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
466 { 487 {
467 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t.securityOrigin(); 488 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t.securityOrigin();
468 } 489 }
469 490
470 } // namespace WebCore 491 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698