Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) | |
| 145 return; | |
| 146 m_timeoutTimer.stop(); | |
| 147 // At the time of this method's implementation, it is only ever called by | |
| 148 // XMLHttpRequest, when the timeout attribute is set after sending the | |
| 149 // request. | |
| 150 // | |
| 151 // The XHR request says to resolve the time relative to when the request | |
| 152 // was initially sent, however other uses of this method may need to | |
| 153 // behave differently, in which case this should be re-arranged somehow. | |
| 154 if (timeoutMilliseconds) { | |
| 155 double elapsedTime = monotonicallyIncreasingTime() - m_requestStarted; | |
| 156 double nextFire = timeoutMilliseconds / 1000.0; | |
| 157 double resolvedTime = nextFire > elapsedTime ? nextFire - elapsedTime : 0.0; | |
| 158 m_timeoutTimer.startOneShot(resolvedTime, FROM_HERE); | |
|
tyoshino (SeeGerritForStatus)
2014/05/15 09:15:43
We should start the timer only when there's active
caitp (gmail)
2014/05/15 11:51:03
What about just `m_requestStarted > 0.0` ? It gets
tyoshino (SeeGerritForStatus)
2014/05/15 12:33:42
Sounds fine as far as well commented.
| |
| 159 } | |
| 160 } | |
| 161 | |
| 141 void DocumentThreadableLoader::cancel() | 162 void DocumentThreadableLoader::cancel() |
| 142 { | 163 { |
| 143 cancelWithError(ResourceError()); | 164 cancelWithError(ResourceError()); |
| 144 } | 165 } |
| 145 | 166 |
| 146 void DocumentThreadableLoader::cancelWithError(const ResourceError& error) | 167 void DocumentThreadableLoader::cancelWithError(const ResourceError& error) |
| 147 { | 168 { |
| 148 RefPtr<DocumentThreadableLoader> protect(this); | 169 RefPtr<DocumentThreadableLoader> protect(this); |
| 149 | 170 |
| 150 // Cancel can re-enter and m_resource might be null here as a result. | 171 // Cancel can re-enter and m_resource might be null here as a result. |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 | 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); |
| 420 m_requestStarted = monotonicallyIncreasingTime(); | |
| 399 | 421 |
| 400 FetchRequest newRequest(request, m_options.initiator, options); | 422 FetchRequest newRequest(request, m_options.initiator, options); |
| 401 ASSERT(!resource()); | 423 ASSERT(!resource()); |
| 402 if (request.targetType() == ResourceRequest::TargetIsMedia) | 424 if (request.targetType() == ResourceRequest::TargetIsMedia) |
| 403 setResource(m_document.fetcher()->fetchMedia(newRequest)); | 425 setResource(m_document.fetcher()->fetchMedia(newRequest)); |
| 404 else | 426 else |
| 405 setResource(m_document.fetcher()->fetchRawResource(newRequest)); | 427 setResource(m_document.fetcher()->fetchRawResource(newRequest)); |
| 406 if (resource() && resource()->loader()) { | 428 if (resource() && resource()->loader()) { |
| 407 unsigned long identifier = resource()->identifier(); | 429 unsigned long identifier = resource()->identifier(); |
| 408 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(&m_document, identifier, m_client); | 430 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(&m_document, identifier, m_client); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 return true; | 483 return true; |
| 462 return m_document.contentSecurityPolicy()->allowConnectToSource(url); | 484 return m_document.contentSecurityPolicy()->allowConnectToSource(url); |
| 463 } | 485 } |
| 464 | 486 |
| 465 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const | 487 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const |
| 466 { | 488 { |
| 467 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t.securityOrigin(); | 489 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t.securityOrigin(); |
| 468 } | 490 } |
| 469 | 491 |
| 470 } // namespace WebCore | 492 } // namespace WebCore |
| OLD | NEW |