Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "platform/SharedBuffer.h" | 51 #include "platform/SharedBuffer.h" |
| 52 #include "platform/blob/BlobData.h" | 52 #include "platform/blob/BlobData.h" |
| 53 #include "platform/network/HTTPParsers.h" | 53 #include "platform/network/HTTPParsers.h" |
| 54 #include "platform/network/ParsedContentType.h" | 54 #include "platform/network/ParsedContentType.h" |
| 55 #include "platform/network/ResourceError.h" | 55 #include "platform/network/ResourceError.h" |
| 56 #include "platform/network/ResourceRequest.h" | 56 #include "platform/network/ResourceRequest.h" |
| 57 #include "public/platform/WebURLRequest.h" | 57 #include "public/platform/WebURLRequest.h" |
| 58 #include "wtf/ArrayBuffer.h" | 58 #include "wtf/ArrayBuffer.h" |
| 59 #include "wtf/ArrayBufferView.h" | 59 #include "wtf/ArrayBufferView.h" |
| 60 #include "wtf/Assertions.h" | 60 #include "wtf/Assertions.h" |
| 61 #include "wtf/CurrentTime.h" | |
| 61 #include "wtf/RefCountedLeakCounter.h" | 62 #include "wtf/RefCountedLeakCounter.h" |
| 62 #include "wtf/StdLibExtras.h" | 63 #include "wtf/StdLibExtras.h" |
| 63 #include "wtf/text/CString.h" | 64 #include "wtf/text/CString.h" |
| 64 | 65 |
| 65 namespace blink { | 66 namespace blink { |
| 66 | 67 |
| 68 namespace { | |
| 69 | |
| 70 const double progressFireInterval = 0.05; // 0.05s | |
| 71 const int progressFireMinimumSize = 1024 * 1024; // 1MB | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 67 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM LHttpRequest")); | 75 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM LHttpRequest")); |
| 68 | 76 |
| 69 struct XMLHttpRequestStaticData { | 77 struct XMLHttpRequestStaticData { |
| 70 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED; | 78 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED; |
| 71 public: | 79 public: |
| 72 XMLHttpRequestStaticData(); | 80 XMLHttpRequestStaticData(); |
| 73 String m_proxyHeaderPrefix; | 81 String m_proxyHeaderPrefix; |
| 74 String m_secHeaderPrefix; | 82 String m_secHeaderPrefix; |
| 75 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders; | 83 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders; |
| 76 }; | 84 }; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 : ActiveDOMObject(context) | 170 : ActiveDOMObject(context) |
| 163 , m_timeoutMilliseconds(0) | 171 , m_timeoutMilliseconds(0) |
| 164 , m_state(UNSENT) | 172 , m_state(UNSENT) |
| 165 , m_downloadedBlobLength(0) | 173 , m_downloadedBlobLength(0) |
| 166 , m_receivedLength(0) | 174 , m_receivedLength(0) |
| 167 , m_lastSendLineNumber(0) | 175 , m_lastSendLineNumber(0) |
| 168 , m_exceptionCode(0) | 176 , m_exceptionCode(0) |
| 169 , m_progressEventThrottle(this) | 177 , m_progressEventThrottle(this) |
| 170 , m_responseTypeCode(ResponseTypeDefault) | 178 , m_responseTypeCode(ResponseTypeDefault) |
| 171 , m_securityOrigin(securityOrigin) | 179 , m_securityOrigin(securityOrigin) |
| 180 , m_previousProgressFireTime(0) | |
| 181 , m_previousProgressRemainLength(0) | |
| 172 , m_async(true) | 182 , m_async(true) |
| 173 , m_includeCredentials(false) | 183 , m_includeCredentials(false) |
| 174 , m_createdDocument(false) | 184 , m_createdDocument(false) |
| 175 , m_error(false) | 185 , m_error(false) |
| 176 , m_uploadEventsAllowed(true) | 186 , m_uploadEventsAllowed(true) |
| 177 , m_uploadComplete(false) | 187 , m_uploadComplete(false) |
| 178 , m_sameOriginRequest(true) | 188 , m_sameOriginRequest(true) |
| 179 { | 189 { |
| 180 initializeXMLHttpRequestStaticData(); | 190 initializeXMLHttpRequestStaticData(); |
| 181 #ifndef NDEBUG | 191 #ifndef NDEBUG |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 XMLHttpRequestUpload* XMLHttpRequest::upload() | 416 XMLHttpRequestUpload* XMLHttpRequest::upload() |
| 407 { | 417 { |
| 408 if (!m_upload) | 418 if (!m_upload) |
| 409 m_upload = XMLHttpRequestUpload::create(this); | 419 m_upload = XMLHttpRequestUpload::create(this); |
| 410 return m_upload.get(); | 420 return m_upload.get(); |
| 411 } | 421 } |
| 412 | 422 |
| 413 void XMLHttpRequest::trackProgress(int length) | 423 void XMLHttpRequest::trackProgress(int length) |
| 414 { | 424 { |
| 415 m_receivedLength += length; | 425 m_receivedLength += length; |
| 426 double now = monotonicallyIncreasingTime(); | |
| 427 bool shouldFire = | |
| 428 now - m_previousProgressFireTime >= progressFireInterval || m_previousPr ogressRemainLength + length >= progressFireMinimumSize; | |
|
tyoshino (SeeGerritForStatus)
2014/07/29 11:39:37
one line?
yhirano
2014/07/29 12:33:48
Done.
| |
| 429 if (shouldFire) { | |
| 430 m_previousProgressFireTime = now; | |
| 431 m_previousProgressRemainLength = 0; | |
| 432 } else { | |
| 433 m_previousProgressRemainLength += length; | |
| 434 } | |
| 416 | 435 |
| 417 if (m_async) | 436 if (m_async && shouldFire) |
| 418 dispatchProgressEventFromSnapshot(EventTypeNames::progress); | 437 dispatchProgressEventFromSnapshot(EventTypeNames::progress); |
|
tyoshino (SeeGerritForStatus)
2014/07/29 11:39:37
progress events are already throttled. the algorit
yhirano
2014/07/29 12:33:48
Done.
As discussed, we don't have to care about th
| |
| 419 | 438 |
| 420 if (m_state != LOADING) { | 439 if (m_state != LOADING) { |
| 421 changeState(LOADING); | 440 changeState(LOADING); |
| 422 } else { | 441 } else { |
| 423 // Firefox calls readyStateChanged every time it receives data. Do | |
| 424 // the same to align with Firefox. | |
| 425 // | |
| 426 // FIXME: Make our implementation and the spec consistent. This | 442 // FIXME: Make our implementation and the spec consistent. This |
| 427 // behavior was needed when the progress event was not available. | 443 // behavior was needed when the progress event was not available. |
| 428 dispatchReadyStateChangeEvent(); | 444 if (shouldFire) |
| 445 dispatchReadyStateChangeEvent(); | |
| 429 } | 446 } |
| 430 } | 447 } |
| 431 | 448 |
| 432 void XMLHttpRequest::changeState(State newState) | 449 void XMLHttpRequest::changeState(State newState) |
| 433 { | 450 { |
| 434 if (m_state != newState) { | 451 if (m_state != newState) { |
| 435 m_state = newState; | 452 m_state = newState; |
| 436 dispatchReadyStateChangeEvent(); | 453 dispatchReadyStateChangeEvent(); |
| 437 } | 454 } |
| 438 } | 455 } |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 { | 1441 { |
| 1425 visitor->trace(m_responseBlob); | 1442 visitor->trace(m_responseBlob); |
| 1426 visitor->trace(m_responseStream); | 1443 visitor->trace(m_responseStream); |
| 1427 visitor->trace(m_responseDocument); | 1444 visitor->trace(m_responseDocument); |
| 1428 visitor->trace(m_progressEventThrottle); | 1445 visitor->trace(m_progressEventThrottle); |
| 1429 visitor->trace(m_upload); | 1446 visitor->trace(m_upload); |
| 1430 XMLHttpRequestEventTarget::trace(visitor); | 1447 XMLHttpRequestEventTarget::trace(visitor); |
| 1431 } | 1448 } |
| 1432 | 1449 |
| 1433 } // namespace blink | 1450 } // namespace blink |
| OLD | NEW |