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 // To throttle readystatechange event fired when readystatechange is not |
| 69 // changed, we don't dispatch the event within 50ms. |
| 70 // As dispatching readystatechange when readystatechange is NOT changed is not |
| 71 // specified, 50ms is not specified, too. |
| 72 // We choose this value because progress event is dispatched every 50ms, but |
| 73 // actually this value doesn't have to equal to the interval. |
| 74 // Note: When readystate is actually changed readystatechange event must be |
| 75 // dispatched no matter how recently dispatched the event was. |
| 76 const double readyStateChangeFireInterval = 0.05; |
| 77 |
67 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM
LHttpRequest")); | 78 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, xmlHttpRequestCounter, ("XM
LHttpRequest")); |
68 | 79 |
69 struct XMLHttpRequestStaticData { | 80 struct XMLHttpRequestStaticData { |
70 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED; | 81 WTF_MAKE_NONCOPYABLE(XMLHttpRequestStaticData); WTF_MAKE_FAST_ALLOCATED; |
71 public: | 82 public: |
72 XMLHttpRequestStaticData(); | 83 XMLHttpRequestStaticData(); |
73 String m_proxyHeaderPrefix; | 84 String m_proxyHeaderPrefix; |
74 String m_secHeaderPrefix; | 85 String m_secHeaderPrefix; |
75 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders; | 86 HashSet<String, CaseFoldingHash> m_forbiddenRequestHeaders; |
76 }; | 87 }; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 : ActiveDOMObject(context) | 173 : ActiveDOMObject(context) |
163 , m_timeoutMilliseconds(0) | 174 , m_timeoutMilliseconds(0) |
164 , m_state(UNSENT) | 175 , m_state(UNSENT) |
165 , m_downloadedBlobLength(0) | 176 , m_downloadedBlobLength(0) |
166 , m_receivedLength(0) | 177 , m_receivedLength(0) |
167 , m_lastSendLineNumber(0) | 178 , m_lastSendLineNumber(0) |
168 , m_exceptionCode(0) | 179 , m_exceptionCode(0) |
169 , m_progressEventThrottle(this) | 180 , m_progressEventThrottle(this) |
170 , m_responseTypeCode(ResponseTypeDefault) | 181 , m_responseTypeCode(ResponseTypeDefault) |
171 , m_securityOrigin(securityOrigin) | 182 , m_securityOrigin(securityOrigin) |
| 183 , m_previousReadyStateChangeFireTime(0) |
172 , m_async(true) | 184 , m_async(true) |
173 , m_includeCredentials(false) | 185 , m_includeCredentials(false) |
174 , m_createdDocument(false) | 186 , m_createdDocument(false) |
175 , m_error(false) | 187 , m_error(false) |
176 , m_uploadEventsAllowed(true) | 188 , m_uploadEventsAllowed(true) |
177 , m_uploadComplete(false) | 189 , m_uploadComplete(false) |
178 , m_sameOriginRequest(true) | 190 , m_sameOriginRequest(true) |
179 { | 191 { |
180 initializeXMLHttpRequestStaticData(); | 192 initializeXMLHttpRequestStaticData(); |
181 #ifndef NDEBUG | 193 #ifndef NDEBUG |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 void XMLHttpRequest::trackProgress(int length) | 425 void XMLHttpRequest::trackProgress(int length) |
414 { | 426 { |
415 m_receivedLength += length; | 427 m_receivedLength += length; |
416 | 428 |
417 if (m_async) | 429 if (m_async) |
418 dispatchProgressEventFromSnapshot(EventTypeNames::progress); | 430 dispatchProgressEventFromSnapshot(EventTypeNames::progress); |
419 | 431 |
420 if (m_state != LOADING) { | 432 if (m_state != LOADING) { |
421 changeState(LOADING); | 433 changeState(LOADING); |
422 } else { | 434 } else { |
423 // Firefox calls readyStateChanged every time it receives data. Do | 435 // FIXME: Make our implementation and the spec consistent. This extra |
424 // the same to align with Firefox. | 436 // invocation of readystatechange event in LOADING state was needed |
425 // | 437 // when the progress event was not available. |
426 // FIXME: Make our implementation and the spec consistent. This | 438 double now = monotonicallyIncreasingTime(); |
427 // behavior was needed when the progress event was not available. | 439 bool shouldFire = now - m_previousReadyStateChangeFireTime >= readyState
ChangeFireInterval; |
428 dispatchReadyStateChangeEvent(); | 440 if (shouldFire) { |
| 441 m_previousReadyStateChangeFireTime = now; |
| 442 dispatchReadyStateChangeEvent(); |
| 443 } |
429 } | 444 } |
430 } | 445 } |
431 | 446 |
432 void XMLHttpRequest::changeState(State newState) | 447 void XMLHttpRequest::changeState(State newState) |
433 { | 448 { |
434 if (m_state != newState) { | 449 if (m_state != newState) { |
435 m_state = newState; | 450 m_state = newState; |
436 dispatchReadyStateChangeEvent(); | 451 dispatchReadyStateChangeEvent(); |
437 } | 452 } |
438 } | 453 } |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 { | 1439 { |
1425 visitor->trace(m_responseBlob); | 1440 visitor->trace(m_responseBlob); |
1426 visitor->trace(m_responseStream); | 1441 visitor->trace(m_responseStream); |
1427 visitor->trace(m_responseDocument); | 1442 visitor->trace(m_responseDocument); |
1428 visitor->trace(m_progressEventThrottle); | 1443 visitor->trace(m_progressEventThrottle); |
1429 visitor->trace(m_upload); | 1444 visitor->trace(m_upload); |
1430 XMLHttpRequestEventTarget::trace(visitor); | 1445 XMLHttpRequestEventTarget::trace(visitor); |
1431 } | 1446 } |
1432 | 1447 |
1433 } // namespace blink | 1448 } // namespace blink |
OLD | NEW |