| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 XMLHttpRequest* xmlHttpRequest = new XMLHttpRequest(context, nullptr); | 201 XMLHttpRequest* xmlHttpRequest = new XMLHttpRequest(context, nullptr); |
| 202 xmlHttpRequest->suspendIfNeeded(); | 202 xmlHttpRequest->suspendIfNeeded(); |
| 203 | 203 |
| 204 return xmlHttpRequest; | 204 return xmlHttpRequest; |
| 205 } | 205 } |
| 206 | 206 |
| 207 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri
gin> isolatedWorldSecurityOrigin) | 207 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri
gin> isolatedWorldSecurityOrigin) |
| 208 : ActiveScriptWrappable(this) | 208 : ActiveScriptWrappable(this) |
| 209 , ActiveDOMObject(context) | 209 , ActiveDOMObject(context) |
| 210 , m_timeoutMilliseconds(0) | 210 , m_timeoutMilliseconds(0) |
| 211 , m_state(UNSENT) | 211 , m_state(kUnsent) |
| 212 , m_lengthDownloadedToFile(0) | 212 , m_lengthDownloadedToFile(0) |
| 213 , m_receivedLength(0) | 213 , m_receivedLength(0) |
| 214 , m_exceptionCode(0) | 214 , m_exceptionCode(0) |
| 215 , m_progressEventThrottle(XMLHttpRequestProgressEventThrottle::create(this)) | 215 , m_progressEventThrottle(XMLHttpRequestProgressEventThrottle::create(this)) |
| 216 , m_responseTypeCode(ResponseTypeDefault) | 216 , m_responseTypeCode(ResponseTypeDefault) |
| 217 , m_isolatedWorldSecurityOrigin(isolatedWorldSecurityOrigin) | 217 , m_isolatedWorldSecurityOrigin(isolatedWorldSecurityOrigin) |
| 218 , m_eventDispatchRecursionLevel(0) | 218 , m_eventDispatchRecursionLevel(0) |
| 219 , m_async(true) | 219 , m_async(true) |
| 220 , m_includeCredentials(false) | 220 , m_includeCredentials(false) |
| 221 , m_parsedResponse(false) | 221 , m_parsedResponse(false) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 247 { | 247 { |
| 248 return m_state; | 248 return m_state; |
| 249 } | 249 } |
| 250 | 250 |
| 251 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState) | 251 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState) |
| 252 { | 252 { |
| 253 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { | 253 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { |
| 254 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'text' (was '" + responseType(
) + "')."); | 254 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'text' (was '" + responseType(
) + "')."); |
| 255 return ScriptString(); | 255 return ScriptString(); |
| 256 } | 256 } |
| 257 if (m_error || (m_state != LOADING && m_state != DONE)) | 257 if (m_error || (m_state != kLoading && m_state != kDone)) |
| 258 return ScriptString(); | 258 return ScriptString(); |
| 259 return m_responseText; | 259 return m_responseText; |
| 260 } | 260 } |
| 261 | 261 |
| 262 ScriptString XMLHttpRequest::responseJSONSource() | 262 ScriptString XMLHttpRequest::responseJSONSource() |
| 263 { | 263 { |
| 264 ASSERT(m_responseTypeCode == ResponseTypeJSON); | 264 ASSERT(m_responseTypeCode == ResponseTypeJSON); |
| 265 | 265 |
| 266 if (m_error || m_state != DONE) | 266 if (m_error || m_state != kDone) |
| 267 return ScriptString(); | 267 return ScriptString(); |
| 268 return m_responseText; | 268 return m_responseText; |
| 269 } | 269 } |
| 270 | 270 |
| 271 void XMLHttpRequest::initResponseDocument() | 271 void XMLHttpRequest::initResponseDocument() |
| 272 { | 272 { |
| 273 // The W3C spec requires the final MIME type to be some valid XML type, or t
ext/html. | 273 // The W3C spec requires the final MIME type to be some valid XML type, or t
ext/html. |
| 274 // If it is text/html, then the responseType of "document" must have been su
pplied explicitly. | 274 // If it is text/html, then the responseType of "document" must have been su
pplied explicitly. |
| 275 bool isHTML = responseIsHTML(); | 275 bool isHTML = responseIsHTML(); |
| 276 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) | 276 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 292 m_responseDocument->setMimeType(finalResponseMIMETypeWithFallback()); | 292 m_responseDocument->setMimeType(finalResponseMIMETypeWithFallback()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) | 295 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) |
| 296 { | 296 { |
| 297 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { | 297 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { |
| 298 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT
ype() + "')."); | 298 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT
ype() + "')."); |
| 299 return nullptr; | 299 return nullptr; |
| 300 } | 300 } |
| 301 | 301 |
| 302 if (m_error || m_state != DONE) | 302 if (m_error || m_state != kDone) |
| 303 return nullptr; | 303 return nullptr; |
| 304 | 304 |
| 305 if (!m_parsedResponse) { | 305 if (!m_parsedResponse) { |
| 306 initResponseDocument(); | 306 initResponseDocument(); |
| 307 if (!m_responseDocument) | 307 if (!m_responseDocument) |
| 308 return nullptr; | 308 return nullptr; |
| 309 | 309 |
| 310 m_responseDocument->setContent(m_responseText.flattenToString()); | 310 m_responseDocument->setContent(m_responseText.flattenToString()); |
| 311 if (!m_responseDocument->wellFormed()) | 311 if (!m_responseDocument->wellFormed()) |
| 312 m_responseDocument = nullptr; | 312 m_responseDocument = nullptr; |
| 313 | 313 |
| 314 m_parsedResponse = true; | 314 m_parsedResponse = true; |
| 315 } | 315 } |
| 316 | 316 |
| 317 return m_responseDocument.get(); | 317 return m_responseDocument.get(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 Blob* XMLHttpRequest::responseBlob() | 320 Blob* XMLHttpRequest::responseBlob() |
| 321 { | 321 { |
| 322 ASSERT(m_responseTypeCode == ResponseTypeBlob); | 322 ASSERT(m_responseTypeCode == ResponseTypeBlob); |
| 323 | 323 |
| 324 // We always return null before DONE. | 324 // We always return null before kDone. |
| 325 if (m_error || m_state != DONE) | 325 if (m_error || m_state != kDone) |
| 326 return nullptr; | 326 return nullptr; |
| 327 | 327 |
| 328 if (!m_responseBlob) { | 328 if (!m_responseBlob) { |
| 329 if (m_downloadingToFile) { | 329 if (m_downloadingToFile) { |
| 330 ASSERT(!m_binaryResponseBuilder); | 330 ASSERT(!m_binaryResponseBuilder); |
| 331 | 331 |
| 332 // When responseType is set to "blob", we redirect the downloaded | 332 // When responseType is set to "blob", we redirect the downloaded |
| 333 // data to a file-handle directly in the browser process. We get | 333 // data to a file-handle directly in the browser process. We get |
| 334 // the file-path from the ResourceResponse directly instead of | 334 // the file-path from the ResourceResponse directly instead of |
| 335 // copying the bytes between the browser and the renderer. | 335 // copying the bytes between the browser and the renderer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 return m_responseBlob; | 350 return m_responseBlob; |
| 351 } | 351 } |
| 352 | 352 |
| 353 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() | 353 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() |
| 354 { | 354 { |
| 355 ASSERT(m_responseTypeCode == ResponseTypeArrayBuffer); | 355 ASSERT(m_responseTypeCode == ResponseTypeArrayBuffer); |
| 356 | 356 |
| 357 if (m_error || m_state != DONE) | 357 if (m_error || m_state != kDone) |
| 358 return nullptr; | 358 return nullptr; |
| 359 | 359 |
| 360 if (!m_responseArrayBuffer) { | 360 if (!m_responseArrayBuffer) { |
| 361 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { | 361 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { |
| 362 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(m_binar
yResponseBuilder->size(), 1); | 362 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(m_binar
yResponseBuilder->size(), 1); |
| 363 if (!m_binaryResponseBuilder->getAsBytes(buffer->data(), static_cast
<size_t>(buffer->byteLength()))) { | 363 if (!m_binaryResponseBuilder->getAsBytes(buffer->data(), static_cast
<size_t>(buffer->byteLength()))) { |
| 364 // m_binaryResponseBuilder failed to allocate an ArrayBuffer. | 364 // m_binaryResponseBuilder failed to allocate an ArrayBuffer. |
| 365 // We need to crash the renderer since there's no way defined in | 365 // We need to crash the renderer since there's no way defined in |
| 366 // the spec to tell this to the user. | 366 // the spec to tell this to the user. |
| 367 CRASH(); | 367 CRASH(); |
| 368 } | 368 } |
| 369 m_responseArrayBuffer = buffer; | 369 m_responseArrayBuffer = buffer; |
| 370 m_binaryResponseBuilder.clear(); | 370 m_binaryResponseBuilder.clear(); |
| 371 } else { | 371 } else { |
| 372 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); | 372 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 return m_responseArrayBuffer.get(); | 376 return m_responseArrayBuffer.get(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 Stream* XMLHttpRequest::responseLegacyStream() | 379 Stream* XMLHttpRequest::responseLegacyStream() |
| 380 { | 380 { |
| 381 ASSERT(m_responseTypeCode == ResponseTypeLegacyStream); | 381 ASSERT(m_responseTypeCode == ResponseTypeLegacyStream); |
| 382 | 382 |
| 383 if (m_error || (m_state != LOADING && m_state != DONE)) | 383 if (m_error || (m_state != kLoading && m_state != kDone)) |
| 384 return nullptr; | 384 return nullptr; |
| 385 | 385 |
| 386 return m_responseLegacyStream; | 386 return m_responseLegacyStream; |
| 387 } | 387 } |
| 388 | 388 |
| 389 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState
) | 389 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState
) |
| 390 { | 390 { |
| 391 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 | 391 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 |
| 392 // 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." | 392 // 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." |
| 393 if (getExecutionContext()->isDocument() && !m_async) { | 393 if (getExecutionContext()->isDocument() && !m_async) { |
| 394 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be
set for synchronous requests made from a document."); | 394 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be
set for synchronous requests made from a document."); |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 | 397 |
| 398 m_timeoutMilliseconds = timeout; | 398 m_timeoutMilliseconds = timeout; |
| 399 | 399 |
| 400 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: | 400 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: |
| 401 // Note: This implies that the timeout attribute can be set while fetching i
s in progress. If | 401 // Note: This implies that the timeout attribute can be set while fetching i
s in progress. If |
| 402 // that occurs it will still be measured relative to the start of fetching. | 402 // that occurs it will still be measured relative to the start of fetching. |
| 403 // | 403 // |
| 404 // The timeout may be overridden after send. | 404 // The timeout may be overridden after send. |
| 405 if (m_loader) | 405 if (m_loader) |
| 406 m_loader->overrideTimeout(timeout); | 406 m_loader->overrideTimeout(timeout); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
exceptionState) | 409 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
exceptionState) |
| 410 { | 410 { |
| 411 if (m_state >= LOADING) { | 411 if (m_state >= kLoading) { |
| 412 exceptionState.throwDOMException(InvalidStateError, "The response type c
annot be set if the object's state is LOADING or DONE."); | 412 exceptionState.throwDOMException(InvalidStateError, "The response type c
annot be set if the object's state is LOADING or DONE."); |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Newer functionality is not available to synchronous requests in window co
ntexts, as a spec-mandated | 416 // Newer functionality is not available to synchronous requests in window co
ntexts, as a spec-mandated |
| 417 // attempt to discourage synchronous XHR use. responseType is one such piece
of functionality. | 417 // attempt to discourage synchronous XHR use. responseType is one such piece
of functionality. |
| 418 if (!m_async && getExecutionContext()->isDocument()) { | 418 if (!m_async && getExecutionContext()->isDocument()) { |
| 419 exceptionState.throwDOMException(InvalidAccessError, "The response type
cannot be changed for synchronous requests made from a document."); | 419 exceptionState.throwDOMException(InvalidAccessError, "The response type
cannot be changed for synchronous requests made from a document."); |
| 420 return; | 420 return; |
| 421 } | 421 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 { | 475 { |
| 476 if (!m_upload) | 476 if (!m_upload) |
| 477 m_upload = XMLHttpRequestUpload::create(this); | 477 m_upload = XMLHttpRequestUpload::create(this); |
| 478 return m_upload.get(); | 478 return m_upload.get(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void XMLHttpRequest::trackProgress(long long length) | 481 void XMLHttpRequest::trackProgress(long long length) |
| 482 { | 482 { |
| 483 m_receivedLength += length; | 483 m_receivedLength += length; |
| 484 | 484 |
| 485 changeState(LOADING); | 485 changeState(kLoading); |
| 486 if (m_async) { | 486 if (m_async) { |
| 487 // readyStateChange event is fired as well. | 487 // readyStateChange event is fired as well. |
| 488 dispatchProgressEventFromSnapshot(EventTypeNames::progress); | 488 dispatchProgressEventFromSnapshot(EventTypeNames::progress); |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 void XMLHttpRequest::changeState(State newState) | 492 void XMLHttpRequest::changeState(State newState) |
| 493 { | 493 { |
| 494 if (m_state != newState) { | 494 if (m_state != newState) { |
| 495 m_state = newState; | 495 m_state = newState; |
| 496 dispatchReadyStateChangeEvent(); | 496 dispatchReadyStateChangeEvent(); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 | 499 |
| 500 void XMLHttpRequest::dispatchReadyStateChangeEvent() | 500 void XMLHttpRequest::dispatchReadyStateChangeEvent() |
| 501 { | 501 { |
| 502 if (!getExecutionContext()) | 502 if (!getExecutionContext()) |
| 503 return; | 503 return; |
| 504 | 504 |
| 505 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 505 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
| 506 if (m_async || (m_state <= OPENED || m_state == DONE)) { | 506 if (m_async || (m_state <= kOpened || m_state == kDone)) { |
| 507 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect
orXhrReadyStateChangeEvent::data(getExecutionContext(), this)); | 507 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect
orXhrReadyStateChangeEvent::data(getExecutionContext(), this)); |
| 508 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt
pRequestProgressEventThrottle::Ignore; | 508 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt
pRequestProgressEventThrottle::Ignore; |
| 509 if (m_state == DONE) { | 509 if (m_state == kDone) { |
| 510 if (m_error) | 510 if (m_error) |
| 511 action = XMLHttpRequestProgressEventThrottle::Clear; | 511 action = XMLHttpRequestProgressEventThrottle::Clear; |
| 512 else | 512 else |
| 513 action = XMLHttpRequestProgressEventThrottle::Flush; | 513 action = XMLHttpRequestProgressEventThrottle::Flush; |
| 514 } | 514 } |
| 515 m_progressEventThrottle->dispatchReadyStateChangeEvent(Event::create(Eve
ntTypeNames::readystatechange), action); | 515 m_progressEventThrottle->dispatchReadyStateChangeEvent(Event::create(Eve
ntTypeNames::readystatechange), action); |
| 516 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up
dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d
ata()); | 516 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up
dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d
ata()); |
| 517 } | 517 } |
| 518 | 518 |
| 519 if (m_state == DONE && !m_error) { | 519 if (m_state == kDone && !m_error) { |
| 520 TRACE_EVENT1("devtools.timeline", "XHRLoad", "data", InspectorXhrLoadEve
nt::data(getExecutionContext(), this)); | 520 TRACE_EVENT1("devtools.timeline", "XHRLoad", "data", InspectorXhrLoadEve
nt::data(getExecutionContext(), this)); |
| 521 dispatchProgressEventFromSnapshot(EventTypeNames::load); | 521 dispatchProgressEventFromSnapshot(EventTypeNames::load); |
| 522 dispatchProgressEventFromSnapshot(EventTypeNames::loadend); | 522 dispatchProgressEventFromSnapshot(EventTypeNames::loadend); |
| 523 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up
dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d
ata()); | 523 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up
dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d
ata()); |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 | 526 |
| 527 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta
te) | 527 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta
te) |
| 528 { | 528 { |
| 529 if (m_state > OPENED || m_loader) { | 529 if (m_state > kOpened || m_loader) { |
| 530 exceptionState.throwDOMException(InvalidStateError, "The value may only
be set if the object's state is UNSENT or OPENED."); | 530 exceptionState.throwDOMException(InvalidStateError, "The value may only
be set if the object's state is UNSENT or OPENED."); |
| 531 return; | 531 return; |
| 532 } | 532 } |
| 533 | 533 |
| 534 m_includeCredentials = value; | 534 m_includeCredentials = value; |
| 535 } | 535 } |
| 536 | 536 |
| 537 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E
xceptionState& exceptionState) | 537 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E
xceptionState& exceptionState) |
| 538 { | 538 { |
| 539 open(method, getExecutionContext()->completeURL(urlString), true, exceptionS
tate); | 539 open(method, getExecutionContext()->completeURL(urlString), true, exceptionS
tate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 551 } | 551 } |
| 552 | 552 |
| 553 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn
c, ExceptionState& exceptionState) | 553 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn
c, ExceptionState& exceptionState) |
| 554 { | 554 { |
| 555 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8
().data(), url.elidedString().utf8().data(), async); | 555 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8
().data(), url.elidedString().utf8().data(), async); |
| 556 | 556 |
| 557 if (!internalAbort()) | 557 if (!internalAbort()) |
| 558 return; | 558 return; |
| 559 | 559 |
| 560 State previousState = m_state; | 560 State previousState = m_state; |
| 561 m_state = UNSENT; | 561 m_state = kUnsent; |
| 562 m_error = false; | 562 m_error = false; |
| 563 m_uploadComplete = false; | 563 m_uploadComplete = false; |
| 564 | 564 |
| 565 if (!isValidHTTPToken(method)) { | 565 if (!isValidHTTPToken(method)) { |
| 566 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a
valid HTTP method."); | 566 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a
valid HTTP method."); |
| 567 return; | 567 return; |
| 568 } | 568 } |
| 569 | 569 |
| 570 if (FetchUtils::isForbiddenMethod(method)) { | 570 if (FetchUtils::isForbiddenMethod(method)) { |
| 571 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup
ported."); | 571 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup
ported."); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 m_method = FetchUtils::normalizeMethod(method); | 608 m_method = FetchUtils::normalizeMethod(method); |
| 609 | 609 |
| 610 m_url = url; | 610 m_url = url; |
| 611 | 611 |
| 612 m_async = async; | 612 m_async = async; |
| 613 | 613 |
| 614 ASSERT(!m_loader); | 614 ASSERT(!m_loader); |
| 615 | 615 |
| 616 // Check previous state to avoid dispatching readyState event | 616 // Check previous state to avoid dispatching readyState event |
| 617 // when calling open several times in a row. | 617 // when calling open several times in a row. |
| 618 if (previousState != OPENED) | 618 if (previousState != kOpened) |
| 619 changeState(OPENED); | 619 changeState(kOpened); |
| 620 else | 620 else |
| 621 m_state = OPENED; | 621 m_state = kOpened; |
| 622 } | 622 } |
| 623 | 623 |
| 624 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) | 624 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) |
| 625 { | 625 { |
| 626 if (!getExecutionContext()) | 626 if (!getExecutionContext()) |
| 627 return false; | 627 return false; |
| 628 | 628 |
| 629 if (m_state != OPENED || m_loader) { | 629 if (m_state != kOpened || m_loader) { |
| 630 exceptionState.throwDOMException(InvalidStateError, "The object's state
must be OPENED."); | 630 exceptionState.throwDOMException(InvalidStateError, "The object's state
must be OPENED."); |
| 631 return false; | 631 return false; |
| 632 } | 632 } |
| 633 | 633 |
| 634 if (!m_async && exceptionState.isolate() && v8::MicrotasksScope::IsRunningMi
crotasks(exceptionState.isolate())) { | 634 if (!m_async && exceptionState.isolate() && v8::MicrotasksScope::IsRunningMi
crotasks(exceptionState.isolate())) { |
| 635 Deprecation::countDeprecation(getExecutionContext(), UseCounter::During_
Microtask_SyncXHR); | 635 Deprecation::countDeprecation(getExecutionContext(), UseCounter::During_
Microtask_SyncXHR); |
| 636 if (RuntimeEnabledFeatures::disableBlockingMethodsDuringMicrotasksEnable
d()) { | 636 if (RuntimeEnabledFeatures::disableBlockingMethodsDuringMicrotasksEnable
d()) { |
| 637 exceptionState.throwDOMException(InvalidAccessError, "Cannot send()
synchronous requests during microtask execution."); | 637 exceptionState.throwDOMException(InvalidAccessError, "Cannot send()
synchronous requests during microtask execution."); |
| 638 return false; | 638 return false; |
| 639 } | 639 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // The script never gets any chance to call abort() on a sync XHR between | 966 // The script never gets any chance to call abort() on a sync XHR between |
| 967 // send() call and transition to the DONE state. It's because a sync XHR | 967 // send() call and transition to the DONE state. It's because a sync XHR |
| 968 // doesn't dispatch any event between them. So, if |m_async| is false, we | 968 // doesn't dispatch any event between them. So, if |m_async| is false, we |
| 969 // can skip the "request error steps" (defined in the XHR spec) without any | 969 // can skip the "request error steps" (defined in the XHR spec) without any |
| 970 // state check. | 970 // state check. |
| 971 // | 971 // |
| 972 // FIXME: It's possible open() is invoked in internalAbort() and |m_async| | 972 // FIXME: It's possible open() is invoked in internalAbort() and |m_async| |
| 973 // becomes true by that. We should implement more reliable treatment for | 973 // becomes true by that. We should implement more reliable treatment for |
| 974 // nested method invocations at some point. | 974 // nested method invocations at some point. |
| 975 if (m_async) { | 975 if (m_async) { |
| 976 if ((m_state == OPENED && sendFlag) || m_state == HEADERS_RECEIVED || m_
state == LOADING) { | 976 if ((m_state == kOpened && sendFlag) || m_state == kHeadersReceived || m
_state == kLoading) { |
| 977 ASSERT(!m_loader); | 977 ASSERT(!m_loader); |
| 978 handleRequestError(0, EventTypeNames::abort, receivedLength, expecte
dLength); | 978 handleRequestError(0, EventTypeNames::abort, receivedLength, expecte
dLength); |
| 979 } | 979 } |
| 980 } | 980 } |
| 981 m_state = UNSENT; | 981 m_state = kUnsent; |
| 982 } | 982 } |
| 983 | 983 |
| 984 void XMLHttpRequest::clearVariablesForLoading() | 984 void XMLHttpRequest::clearVariablesForLoading() |
| 985 { | 985 { |
| 986 if (m_blobLoader) { | 986 if (m_blobLoader) { |
| 987 m_blobLoader->cancel(); | 987 m_blobLoader->cancel(); |
| 988 m_blobLoader = nullptr; | 988 m_blobLoader = nullptr; |
| 989 } | 989 } |
| 990 | 990 |
| 991 m_decoder.reset(); | 991 m_decoder.reset(); |
| 992 | 992 |
| 993 if (m_responseDocumentParser) { | 993 if (m_responseDocumentParser) { |
| 994 m_responseDocumentParser->removeClient(this); | 994 m_responseDocumentParser->removeClient(this); |
| 995 m_responseDocumentParser->detach(); | 995 m_responseDocumentParser->detach(); |
| 996 m_responseDocumentParser = nullptr; | 996 m_responseDocumentParser = nullptr; |
| 997 } | 997 } |
| 998 | 998 |
| 999 m_finalResponseCharset = String(); | 999 m_finalResponseCharset = String(); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 bool XMLHttpRequest::internalAbort() | 1002 bool XMLHttpRequest::internalAbort() |
| 1003 { | 1003 { |
| 1004 m_error = true; | 1004 m_error = true; |
| 1005 | 1005 |
| 1006 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) | 1006 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) |
| 1007 m_responseDocumentParser->stopParsing(); | 1007 m_responseDocumentParser->stopParsing(); |
| 1008 | 1008 |
| 1009 clearVariablesForLoading(); | 1009 clearVariablesForLoading(); |
| 1010 | 1010 |
| 1011 if (m_responseLegacyStream && m_state != DONE) | 1011 if (m_responseLegacyStream && m_state != kDone) |
| 1012 m_responseLegacyStream->abort(); | 1012 m_responseLegacyStream->abort(); |
| 1013 | 1013 |
| 1014 clearResponse(); | 1014 clearResponse(); |
| 1015 clearRequest(); | 1015 clearRequest(); |
| 1016 | 1016 |
| 1017 if (!m_loader) | 1017 if (!m_loader) |
| 1018 return true; | 1018 return true; |
| 1019 | 1019 |
| 1020 // Cancelling the ThreadableLoader m_loader may result in calling | 1020 // Cancelling the ThreadableLoader m_loader may result in calling |
| 1021 // window.onload synchronously. If such an onload handler contains open() | 1021 // window.onload synchronously. If such an onload handler contains open() |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
cString& type, long long receivedLength, long long expectedLength) | 1117 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
cString& type, long long receivedLength, long long expectedLength) |
| 1118 { | 1118 { |
| 1119 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); | 1119 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); |
| 1120 | 1120 |
| 1121 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi
s, m_method, m_url); | 1121 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi
s, m_method, m_url); |
| 1122 | 1122 |
| 1123 if (!m_async) { | 1123 if (!m_async) { |
| 1124 ASSERT(exceptionCode); | 1124 ASSERT(exceptionCode); |
| 1125 m_state = DONE; | 1125 m_state = kDone; |
| 1126 m_exceptionCode = exceptionCode; | 1126 m_exceptionCode = exceptionCode; |
| 1127 return; | 1127 return; |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 // With m_error set, the state change steps are minimal: any pending | 1130 // With m_error set, the state change steps are minimal: any pending |
| 1131 // progress event is flushed + a readystatechange is dispatched. | 1131 // progress event is flushed + a readystatechange is dispatched. |
| 1132 // No new progress events dispatched; as required, that happens at | 1132 // No new progress events dispatched; as required, that happens at |
| 1133 // the end here. | 1133 // the end here. |
| 1134 ASSERT(m_error); | 1134 ASSERT(m_error); |
| 1135 changeState(DONE); | 1135 changeState(kDone); |
| 1136 | 1136 |
| 1137 if (!m_uploadComplete) { | 1137 if (!m_uploadComplete) { |
| 1138 m_uploadComplete = true; | 1138 m_uploadComplete = true; |
| 1139 if (m_upload && m_uploadEventsAllowed) | 1139 if (m_upload && m_uploadEventsAllowed) |
| 1140 m_upload->handleRequestError(type); | 1140 m_upload->handleRequestError(type); |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 // Note: The below event dispatch may be called while |hasPendingActivity()
== false|, | 1143 // Note: The below event dispatch may be called while |hasPendingActivity()
== false|, |
| 1144 // when |handleRequestError| is called after |internalAbort()|. | 1144 // when |handleRequestError| is called after |internalAbort()|. |
| 1145 // This is safe, however, as |this| will be kept alive from a strong ref |Ev
ent::m_target|. | 1145 // This is safe, however, as |this| will be kept alive from a strong ref |Ev
ent::m_target|. |
| 1146 dispatchProgressEvent(EventTypeNames::progress, receivedLength, expectedLeng
th); | 1146 dispatchProgressEvent(EventTypeNames::progress, receivedLength, expectedLeng
th); |
| 1147 dispatchProgressEvent(type, receivedLength, expectedLength); | 1147 dispatchProgressEvent(type, receivedLength, expectedLength); |
| 1148 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, expectedLengt
h); | 1148 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, expectedLengt
h); |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, ExceptionSta
te& exceptionState) | 1151 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, ExceptionSta
te& exceptionState) |
| 1152 { | 1152 { |
| 1153 if (m_state == LOADING || m_state == DONE) { | 1153 if (m_state == kLoading || m_state == kDone) { |
| 1154 exceptionState.throwDOMException(InvalidStateError, "MimeType cannot be
overridden when the state is LOADING or DONE."); | 1154 exceptionState.throwDOMException(InvalidStateError, "MimeType cannot be
overridden when the state is LOADING or DONE."); |
| 1155 return; | 1155 return; |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 m_mimeTypeOverride = mimeType; | 1158 m_mimeTypeOverride = mimeType; |
| 1159 } | 1159 } |
| 1160 | 1160 |
| 1161 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri
ng& value, ExceptionState& exceptionState) | 1161 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri
ng& value, ExceptionState& exceptionState) |
| 1162 { | 1162 { |
| 1163 if (m_state != OPENED || m_loader) { | 1163 if (m_state != kOpened || m_loader) { |
| 1164 exceptionState.throwDOMException(InvalidStateError, "The object's state
must be OPENED."); | 1164 exceptionState.throwDOMException(InvalidStateError, "The object's state
must be OPENED."); |
| 1165 return; | 1165 return; |
| 1166 } | 1166 } |
| 1167 | 1167 |
| 1168 if (!isValidHTTPToken(name)) { | 1168 if (!isValidHTTPToken(name)) { |
| 1169 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v
alid HTTP header field name."); | 1169 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v
alid HTTP header field name."); |
| 1170 return; | 1170 return; |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 if (!isValidHTTPHeaderValue(value)) { | 1173 if (!isValidHTTPHeaderValue(value)) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 headerValueCategoryHistogram.count(headerValueCategory); | 1214 headerValueCategoryHistogram.count(headerValueCategory); |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) c
onst | 1217 const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) c
onst |
| 1218 { | 1218 { |
| 1219 return m_requestHeaders.get(name); | 1219 return m_requestHeaders.get(name); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 String XMLHttpRequest::getAllResponseHeaders() const | 1222 String XMLHttpRequest::getAllResponseHeaders() const |
| 1223 { | 1223 { |
| 1224 if (m_state < HEADERS_RECEIVED || m_error) | 1224 if (m_state < kHeadersReceived || m_error) |
| 1225 return ""; | 1225 return ""; |
| 1226 | 1226 |
| 1227 StringBuilder stringBuilder; | 1227 StringBuilder stringBuilder; |
| 1228 | 1228 |
| 1229 HTTPHeaderSet accessControlExposeHeaderSet; | 1229 HTTPHeaderSet accessControlExposeHeaderSet; |
| 1230 extractCorsExposedHeaderNamesList(m_response, accessControlExposeHeaderSet); | 1230 extractCorsExposedHeaderNamesList(m_response, accessControlExposeHeaderSet); |
| 1231 | 1231 |
| 1232 HTTPHeaderMap::const_iterator end = m_response.httpHeaderFields().end(); | 1232 HTTPHeaderMap::const_iterator end = m_response.httpHeaderFields().end(); |
| 1233 for (HTTPHeaderMap::const_iterator it = m_response.httpHeaderFields().begin(
); it!= end; ++it) { | 1233 for (HTTPHeaderMap::const_iterator it = m_response.httpHeaderFields().begin(
); it!= end; ++it) { |
| 1234 // Hide any headers whose name is a forbidden response-header name. | 1234 // Hide any headers whose name is a forbidden response-header name. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1248 stringBuilder.append(it->value); | 1248 stringBuilder.append(it->value); |
| 1249 stringBuilder.append('\r'); | 1249 stringBuilder.append('\r'); |
| 1250 stringBuilder.append('\n'); | 1250 stringBuilder.append('\n'); |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 return stringBuilder.toString(); | 1253 return stringBuilder.toString(); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name)
const | 1256 const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name)
const |
| 1257 { | 1257 { |
| 1258 if (m_state < HEADERS_RECEIVED || m_error) | 1258 if (m_state < kHeadersReceived || m_error) |
| 1259 return nullAtom; | 1259 return nullAtom; |
| 1260 | 1260 |
| 1261 // See comment in getAllResponseHeaders above. | 1261 // See comment in getAllResponseHeaders above. |
| 1262 if (FetchUtils::isForbiddenResponseHeaderName(name) && !getSecurityOrigin()-
>canLoadLocalResources()) { | 1262 if (FetchUtils::isForbiddenResponseHeaderName(name) && !getSecurityOrigin()-
>canLoadLocalResources()) { |
| 1263 logConsoleError(getExecutionContext(), "Refused to get unsafe header \""
+ name + "\""); | 1263 logConsoleError(getExecutionContext(), "Refused to get unsafe header \""
+ name + "\""); |
| 1264 return nullAtom; | 1264 return nullAtom; |
| 1265 } | 1265 } |
| 1266 | 1266 |
| 1267 HTTPHeaderSet accessControlExposeHeaderSet; | 1267 HTTPHeaderSet accessControlExposeHeaderSet; |
| 1268 extractCorsExposedHeaderNamesList(m_response, accessControlExposeHeaderSet); | 1268 extractCorsExposedHeaderNamesList(m_response, accessControlExposeHeaderSet); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 return DOMImplementation::isXMLMIMEType(finalResponseMIMETypeWithFallback())
; | 1302 return DOMImplementation::isXMLMIMEType(finalResponseMIMETypeWithFallback())
; |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 bool XMLHttpRequest::responseIsHTML() const | 1305 bool XMLHttpRequest::responseIsHTML() const |
| 1306 { | 1306 { |
| 1307 return equalIgnoringCase(finalResponseMIMEType(), "text/html"); | 1307 return equalIgnoringCase(finalResponseMIMEType(), "text/html"); |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 int XMLHttpRequest::status() const | 1310 int XMLHttpRequest::status() const |
| 1311 { | 1311 { |
| 1312 if (m_state == UNSENT || m_state == OPENED || m_error) | 1312 if (m_state == kUnsent || m_state == kOpened || m_error) |
| 1313 return 0; | 1313 return 0; |
| 1314 | 1314 |
| 1315 if (m_response.httpStatusCode()) | 1315 if (m_response.httpStatusCode()) |
| 1316 return m_response.httpStatusCode(); | 1316 return m_response.httpStatusCode(); |
| 1317 | 1317 |
| 1318 return 0; | 1318 return 0; |
| 1319 } | 1319 } |
| 1320 | 1320 |
| 1321 String XMLHttpRequest::statusText() const | 1321 String XMLHttpRequest::statusText() const |
| 1322 { | 1322 { |
| 1323 if (m_state == UNSENT || m_state == OPENED || m_error) | 1323 if (m_state == kUnsent || m_state == kOpened || m_error) |
| 1324 return String(); | 1324 return String(); |
| 1325 | 1325 |
| 1326 if (!m_response.httpStatusText().isNull()) | 1326 if (!m_response.httpStatusText().isNull()) |
| 1327 return m_response.httpStatusText(); | 1327 return m_response.httpStatusText(); |
| 1328 | 1328 |
| 1329 return String(); | 1329 return String(); |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 void XMLHttpRequest::didFail(const ResourceError& error) | 1332 void XMLHttpRequest::didFail(const ResourceError& error) |
| 1333 { | 1333 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1370 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
| 1371 { | 1371 { |
| 1372 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier
); | 1372 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier
); |
| 1373 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1373 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
| 1374 | 1374 |
| 1375 if (m_error) | 1375 if (m_error) |
| 1376 return; | 1376 return; |
| 1377 | 1377 |
| 1378 if (m_state < HEADERS_RECEIVED) | 1378 if (m_state < kHeadersReceived) |
| 1379 changeState(HEADERS_RECEIVED); | 1379 changeState(kHeadersReceived); |
| 1380 | 1380 |
| 1381 if (m_downloadingToFile && m_responseTypeCode != ResponseTypeBlob && m_lengt
hDownloadedToFile) { | 1381 if (m_downloadingToFile && m_responseTypeCode != ResponseTypeBlob && m_lengt
hDownloadedToFile) { |
| 1382 ASSERT(m_state == LOADING); | 1382 DCHECK_EQ(kLoading, m_state); |
| 1383 // In this case, we have sent the request with DownloadToFile true, | 1383 // In this case, we have sent the request with DownloadToFile true, |
| 1384 // but the user changed the response type after that. Hence we need to | 1384 // but the user changed the response type after that. Hence we need to |
| 1385 // read the response data and provide it to this object. | 1385 // read the response data and provide it to this object. |
| 1386 m_blobLoader = BlobLoader::create(this, createBlobDataHandleFromResponse
()); | 1386 m_blobLoader = BlobLoader::create(this, createBlobDataHandleFromResponse
()); |
| 1387 } else { | 1387 } else { |
| 1388 didFinishLoadingInternal(); | 1388 didFinishLoadingInternal(); |
| 1389 } | 1389 } |
| 1390 } | 1390 } |
| 1391 | 1391 |
| 1392 void XMLHttpRequest::didFinishLoadingInternal() | 1392 void XMLHttpRequest::didFinishLoadingInternal() |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 endLoading(); | 1475 endLoading(); |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 void XMLHttpRequest::endLoading() | 1478 void XMLHttpRequest::endLoading() |
| 1479 { | 1479 { |
| 1480 InspectorInstrumentation::didFinishXHRLoading(getExecutionContext(), this, t
his, m_method, m_url); | 1480 InspectorInstrumentation::didFinishXHRLoading(getExecutionContext(), this, t
his, m_method, m_url); |
| 1481 | 1481 |
| 1482 if (m_loader) | 1482 if (m_loader) |
| 1483 m_loader = nullptr; | 1483 m_loader = nullptr; |
| 1484 | 1484 |
| 1485 changeState(DONE); | 1485 changeState(kDone); |
| 1486 | 1486 |
| 1487 if (!getExecutionContext()->isDocument() || !document() || !document()->fram
e() || !document()->frame()->page()) | 1487 if (!getExecutionContext()->isDocument() || !document() || !document()->fram
e() || !document()->frame()->page()) |
| 1488 return; | 1488 return; |
| 1489 | 1489 |
| 1490 if (status() >= 200 && status() < 300) { | 1490 if (status() >= 200 && status() < 300) { |
| 1491 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr
ame()); | 1491 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr
ame()); |
| 1492 } | 1492 } |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) | 1495 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
g totalBytesToBeSent) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 | 1569 |
| 1570 return TextResourceDecoder::create("text/plain", "UTF-8"); | 1570 return TextResourceDecoder::create("text/plain", "UTF-8"); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 void XMLHttpRequest::didReceiveData(const char* data, unsigned len) | 1573 void XMLHttpRequest::didReceiveData(const char* data, unsigned len) |
| 1574 { | 1574 { |
| 1575 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1575 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
| 1576 if (m_error) | 1576 if (m_error) |
| 1577 return; | 1577 return; |
| 1578 | 1578 |
| 1579 if (m_state < HEADERS_RECEIVED) | 1579 if (m_state < kHeadersReceived) |
| 1580 changeState(HEADERS_RECEIVED); | 1580 changeState(kHeadersReceived); |
| 1581 | 1581 |
| 1582 // We need to check for |m_error| again, because |changeState| may trigger | 1582 // We need to check for |m_error| again, because |changeState| may trigger |
| 1583 // readystatechange, and user javascript can cause |abort()|. | 1583 // readystatechange, and user javascript can cause |abort()|. |
| 1584 if (m_error) | 1584 if (m_error) |
| 1585 return; | 1585 return; |
| 1586 | 1586 |
| 1587 if (!len) | 1587 if (!len) |
| 1588 return; | 1588 return; |
| 1589 | 1589 |
| 1590 if (m_responseTypeCode == ResponseTypeDocument && responseIsHTML()) { | 1590 if (m_responseTypeCode == ResponseTypeDocument && responseIsHTML()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1618 } | 1618 } |
| 1619 | 1619 |
| 1620 void XMLHttpRequest::didDownloadData(int dataLength) | 1620 void XMLHttpRequest::didDownloadData(int dataLength) |
| 1621 { | 1621 { |
| 1622 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1622 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
| 1623 if (m_error) | 1623 if (m_error) |
| 1624 return; | 1624 return; |
| 1625 | 1625 |
| 1626 ASSERT(m_downloadingToFile); | 1626 ASSERT(m_downloadingToFile); |
| 1627 | 1627 |
| 1628 if (m_state < HEADERS_RECEIVED) | 1628 if (m_state < kHeadersReceived) |
| 1629 changeState(HEADERS_RECEIVED); | 1629 changeState(kHeadersReceived); |
| 1630 | 1630 |
| 1631 if (!dataLength) | 1631 if (!dataLength) |
| 1632 return; | 1632 return; |
| 1633 | 1633 |
| 1634 // readystatechange event handler may do something to put this XHR in error | 1634 // readystatechange event handler may do something to put this XHR in error |
| 1635 // state. We need to check m_error again here. | 1635 // state. We need to check m_error again here. |
| 1636 if (m_error) | 1636 if (m_error) |
| 1637 return; | 1637 return; |
| 1638 | 1638 |
| 1639 m_lengthDownloadedToFile += dataLength; | 1639 m_lengthDownloadedToFile += dataLength; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 | 1718 |
| 1719 DEFINE_TRACE_WRAPPERS(XMLHttpRequest) | 1719 DEFINE_TRACE_WRAPPERS(XMLHttpRequest) |
| 1720 { | 1720 { |
| 1721 visitor->traceWrappers(m_responseBlob); | 1721 visitor->traceWrappers(m_responseBlob); |
| 1722 visitor->traceWrappers(m_responseLegacyStream); | 1722 visitor->traceWrappers(m_responseLegacyStream); |
| 1723 visitor->traceWrappers(m_responseDocument); | 1723 visitor->traceWrappers(m_responseDocument); |
| 1724 visitor->traceWrappers(m_responseArrayBuffer); | 1724 visitor->traceWrappers(m_responseArrayBuffer); |
| 1725 } | 1725 } |
| 1726 | 1726 |
| 1727 } // namespace blink | 1727 } // namespace blink |
| OLD | NEW |