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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // via hasPendingActivity method which returns true if | 87 // via hasPendingActivity method which returns true if |
88 // m_eventDispatchRecursionLevel is positive. | 88 // m_eventDispatchRecursionLevel is positive. |
89 class ScopedEventDispatchProtect final { | 89 class ScopedEventDispatchProtect final { |
90 public: | 90 public: |
91 explicit ScopedEventDispatchProtect(int* level) : m_level(level) | 91 explicit ScopedEventDispatchProtect(int* level) : m_level(level) |
92 { | 92 { |
93 ++*m_level; | 93 ++*m_level; |
94 } | 94 } |
95 ~ScopedEventDispatchProtect() | 95 ~ScopedEventDispatchProtect() |
96 { | 96 { |
97 ASSERT(*m_level > 0); | 97 DCHECK_GT(*m_level, 0); |
98 --*m_level; | 98 --*m_level; |
99 } | 99 } |
100 | 100 |
101 private: | 101 private: |
102 int* const m_level; | 102 int* const m_level; |
103 }; | 103 }; |
104 | 104 |
105 void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) | 105 void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) |
106 { | 106 { |
107 unsigned pos = 0, len = 0; | 107 unsigned pos = 0, len = 0; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 public: | 164 public: |
165 static BlobLoader* create(XMLHttpRequest* xhr, PassRefPtr<BlobDataHandle> ha
ndle) | 165 static BlobLoader* create(XMLHttpRequest* xhr, PassRefPtr<BlobDataHandle> ha
ndle) |
166 { | 166 { |
167 return new BlobLoader(xhr, std::move(handle)); | 167 return new BlobLoader(xhr, std::move(handle)); |
168 } | 168 } |
169 | 169 |
170 // FileReaderLoaderClient functions. | 170 // FileReaderLoaderClient functions. |
171 void didStartLoading() override {} | 171 void didStartLoading() override {} |
172 void didReceiveDataForClient(const char* data, unsigned length) override | 172 void didReceiveDataForClient(const char* data, unsigned length) override |
173 { | 173 { |
174 ASSERT(length <= INT_MAX); | 174 DCHECK_LE(length, static_cast<unsigned>(INT_MAX)); |
175 m_xhr->didReceiveData(data, length); | 175 m_xhr->didReceiveData(data, length); |
176 } | 176 } |
177 void didFinishLoading() override | 177 void didFinishLoading() override |
178 { | 178 { |
179 m_xhr->didFinishLoadingFromBlob(); | 179 m_xhr->didFinishLoadingFromBlob(); |
180 } | 180 } |
181 void didFail(FileError::ErrorCode error) override | 181 void didFail(FileError::ErrorCode error) override |
182 { | 182 { |
183 m_xhr->didFailLoadingFromBlob(); | 183 m_xhr->didFailLoadingFromBlob(); |
184 } | 184 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 , m_responseTextOverflow(false) | 247 , m_responseTextOverflow(false) |
248 { | 248 { |
249 } | 249 } |
250 | 250 |
251 XMLHttpRequest::~XMLHttpRequest() | 251 XMLHttpRequest::~XMLHttpRequest() |
252 { | 252 { |
253 } | 253 } |
254 | 254 |
255 Document* XMLHttpRequest::document() const | 255 Document* XMLHttpRequest::document() const |
256 { | 256 { |
257 ASSERT(getExecutionContext()->isDocument()); | 257 DCHECK(getExecutionContext()->isDocument()); |
258 return toDocument(getExecutionContext()); | 258 return toDocument(getExecutionContext()); |
259 } | 259 } |
260 | 260 |
261 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const | 261 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const |
262 { | 262 { |
263 return m_isolatedWorldSecurityOrigin ? m_isolatedWorldSecurityOrigin.get() :
getExecutionContext()->getSecurityOrigin(); | 263 return m_isolatedWorldSecurityOrigin ? m_isolatedWorldSecurityOrigin.get() :
getExecutionContext()->getSecurityOrigin(); |
264 } | 264 } |
265 | 265 |
266 XMLHttpRequest::State XMLHttpRequest::readyState() const | 266 XMLHttpRequest::State XMLHttpRequest::readyState() const |
267 { | 267 { |
268 return m_state; | 268 return m_state; |
269 } | 269 } |
270 | 270 |
271 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState) | 271 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState) |
272 { | 272 { |
273 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { | 273 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeText) { |
274 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'text' (was '" + responseType(
) + "')."); | 274 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'text' (was '" + responseType(
) + "')."); |
275 return ScriptString(); | 275 return ScriptString(); |
276 } | 276 } |
277 if (m_error || (m_state != kLoading && m_state != kDone)) | 277 if (m_error || (m_state != kLoading && m_state != kDone)) |
278 return ScriptString(); | 278 return ScriptString(); |
279 return m_responseText; | 279 return m_responseText; |
280 } | 280 } |
281 | 281 |
282 ScriptString XMLHttpRequest::responseJSONSource() | 282 ScriptString XMLHttpRequest::responseJSONSource() |
283 { | 283 { |
284 ASSERT(m_responseTypeCode == ResponseTypeJSON); | 284 DCHECK_EQ(m_responseTypeCode, ResponseTypeJSON); |
285 | 285 |
286 if (m_error || m_state != kDone) | 286 if (m_error || m_state != kDone) |
287 return ScriptString(); | 287 return ScriptString(); |
288 return m_responseText; | 288 return m_responseText; |
289 } | 289 } |
290 | 290 |
291 void XMLHttpRequest::initResponseDocument() | 291 void XMLHttpRequest::initResponseDocument() |
292 { | 292 { |
293 // The W3C spec requires the final MIME type to be some valid XML type, or t
ext/html. | 293 // The W3C spec requires the final MIME type to be some valid XML type, or t
ext/html. |
294 // If it is text/html, then the responseType of "document" must have been su
pplied explicitly. | 294 // If it is text/html, then the responseType of "document" must have been su
pplied explicitly. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 m_responseDocument = nullptr; | 332 m_responseDocument = nullptr; |
333 | 333 |
334 m_parsedResponse = true; | 334 m_parsedResponse = true; |
335 } | 335 } |
336 | 336 |
337 return m_responseDocument.get(); | 337 return m_responseDocument.get(); |
338 } | 338 } |
339 | 339 |
340 Blob* XMLHttpRequest::responseBlob() | 340 Blob* XMLHttpRequest::responseBlob() |
341 { | 341 { |
342 ASSERT(m_responseTypeCode == ResponseTypeBlob); | 342 DCHECK_EQ(m_responseTypeCode, ResponseTypeBlob); |
343 | 343 |
344 // We always return null before kDone. | 344 // We always return null before kDone. |
345 if (m_error || m_state != kDone) | 345 if (m_error || m_state != kDone) |
346 return nullptr; | 346 return nullptr; |
347 | 347 |
348 if (!m_responseBlob) { | 348 if (!m_responseBlob) { |
349 if (m_downloadingToFile) { | 349 if (m_downloadingToFile) { |
350 ASSERT(!m_binaryResponseBuilder); | 350 DCHECK(!m_binaryResponseBuilder); |
351 | 351 |
352 // When responseType is set to "blob", we redirect the downloaded | 352 // When responseType is set to "blob", we redirect the downloaded |
353 // data to a file-handle directly in the browser process. We get | 353 // data to a file-handle directly in the browser process. We get |
354 // the file-path from the ResourceResponse directly instead of | 354 // the file-path from the ResourceResponse directly instead of |
355 // copying the bytes between the browser and the renderer. | 355 // copying the bytes between the browser and the renderer. |
356 m_responseBlob = Blob::create(createBlobDataHandleFromResponse()); | 356 m_responseBlob = Blob::create(createBlobDataHandleFromResponse()); |
357 } else { | 357 } else { |
358 std::unique_ptr<BlobData> blobData = BlobData::create(); | 358 std::unique_ptr<BlobData> blobData = BlobData::create(); |
359 size_t size = 0; | 359 size_t size = 0; |
360 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { | 360 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { |
361 size = m_binaryResponseBuilder->size(); | 361 size = m_binaryResponseBuilder->size(); |
362 blobData->appendBytes(m_binaryResponseBuilder->data(), size); | 362 blobData->appendBytes(m_binaryResponseBuilder->data(), size); |
363 blobData->setContentType(finalResponseMIMETypeWithFallback().low
er()); | 363 blobData->setContentType(finalResponseMIMETypeWithFallback().low
er()); |
364 m_binaryResponseBuilder.clear(); | 364 m_binaryResponseBuilder.clear(); |
365 } | 365 } |
366 m_responseBlob = Blob::create(BlobDataHandle::create(std::move(blobD
ata), size)); | 366 m_responseBlob = Blob::create(BlobDataHandle::create(std::move(blobD
ata), size)); |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 return m_responseBlob; | 370 return m_responseBlob; |
371 } | 371 } |
372 | 372 |
373 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() | 373 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() |
374 { | 374 { |
375 ASSERT(m_responseTypeCode == ResponseTypeArrayBuffer); | 375 DCHECK_EQ(m_responseTypeCode, ResponseTypeArrayBuffer); |
376 | 376 |
377 if (m_error || m_state != kDone) | 377 if (m_error || m_state != kDone) |
378 return nullptr; | 378 return nullptr; |
379 | 379 |
380 if (!m_responseArrayBuffer) { | 380 if (!m_responseArrayBuffer) { |
381 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { | 381 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { |
382 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(m_binar
yResponseBuilder->size(), 1); | 382 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(m_binar
yResponseBuilder->size(), 1); |
383 if (!m_binaryResponseBuilder->getAsBytes(buffer->data(), static_cast
<size_t>(buffer->byteLength()))) { | 383 if (!m_binaryResponseBuilder->getAsBytes(buffer->data(), static_cast
<size_t>(buffer->byteLength()))) { |
384 // m_binaryResponseBuilder failed to allocate an ArrayBuffer. | 384 // m_binaryResponseBuilder failed to allocate an ArrayBuffer. |
385 // We need to crash the renderer since there's no way defined in | 385 // We need to crash the renderer since there's no way defined in |
386 // the spec to tell this to the user. | 386 // the spec to tell this to the user. |
387 CRASH(); | 387 CRASH(); |
388 } | 388 } |
389 m_responseArrayBuffer = buffer; | 389 m_responseArrayBuffer = buffer; |
390 m_binaryResponseBuilder.clear(); | 390 m_binaryResponseBuilder.clear(); |
391 } else { | 391 } else { |
392 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); | 392 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 return m_responseArrayBuffer.get(); | 396 return m_responseArrayBuffer.get(); |
397 } | 397 } |
398 | 398 |
399 Stream* XMLHttpRequest::responseLegacyStream() | 399 Stream* XMLHttpRequest::responseLegacyStream() |
400 { | 400 { |
401 ASSERT(m_responseTypeCode == ResponseTypeLegacyStream); | 401 DCHECK_EQ(m_responseTypeCode, ResponseTypeLegacyStream); |
402 | 402 |
403 if (m_error || (m_state != kLoading && m_state != kDone)) | 403 if (m_error || (m_state != kLoading && m_state != kDone)) |
404 return nullptr; | 404 return nullptr; |
405 | 405 |
406 return m_responseLegacyStream; | 406 return m_responseLegacyStream; |
407 } | 407 } |
408 | 408 |
409 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState
) | 409 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState
) |
410 { | 410 { |
411 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 | 411 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 } else if (responseType == "blob") { | 451 } else if (responseType == "blob") { |
452 m_responseTypeCode = ResponseTypeBlob; | 452 m_responseTypeCode = ResponseTypeBlob; |
453 } else if (responseType == "arraybuffer") { | 453 } else if (responseType == "arraybuffer") { |
454 m_responseTypeCode = ResponseTypeArrayBuffer; | 454 m_responseTypeCode = ResponseTypeArrayBuffer; |
455 } else if (responseType == "legacystream") { | 455 } else if (responseType == "legacystream") { |
456 if (RuntimeEnabledFeatures::experimentalStreamEnabled()) | 456 if (RuntimeEnabledFeatures::experimentalStreamEnabled()) |
457 m_responseTypeCode = ResponseTypeLegacyStream; | 457 m_responseTypeCode = ResponseTypeLegacyStream; |
458 else | 458 else |
459 return; | 459 return; |
460 } else { | 460 } else { |
461 ASSERT_NOT_REACHED(); | 461 NOTREACHED(); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 String XMLHttpRequest::responseType() | 465 String XMLHttpRequest::responseType() |
466 { | 466 { |
467 switch (m_responseTypeCode) { | 467 switch (m_responseTypeCode) { |
468 case ResponseTypeDefault: | 468 case ResponseTypeDefault: |
469 return ""; | 469 return ""; |
470 case ResponseTypeText: | 470 case ResponseTypeText: |
471 return "text"; | 471 return "text"; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 if (!document()->processingBeforeUnload()) | 623 if (!document()->processingBeforeUnload()) |
624 Deprecation::countDeprecation(getExecutionContext(), UseCounter::XML
HttpRequestSynchronousInNonWorkerOutsideBeforeUnload); | 624 Deprecation::countDeprecation(getExecutionContext(), UseCounter::XML
HttpRequestSynchronousInNonWorkerOutsideBeforeUnload); |
625 } | 625 } |
626 | 626 |
627 m_method = FetchUtils::normalizeMethod(method); | 627 m_method = FetchUtils::normalizeMethod(method); |
628 | 628 |
629 m_url = url; | 629 m_url = url; |
630 | 630 |
631 m_async = async; | 631 m_async = async; |
632 | 632 |
633 ASSERT(!m_loader); | 633 DCHECK(!m_loader); |
634 | 634 |
635 // Check previous state to avoid dispatching readyState event | 635 // Check previous state to avoid dispatching readyState event |
636 // when calling open several times in a row. | 636 // when calling open several times in a row. |
637 if (previousState != kOpened) | 637 if (previousState != kOpened) |
638 changeState(kOpened); | 638 changeState(kOpened); |
639 else | 639 else |
640 m_state = kOpened; | 640 m_state = kOpened; |
641 } | 641 } |
642 | 642 |
643 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) | 643 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 if (body.isDocument()) { | 688 if (body.isDocument()) { |
689 send(body.getAsDocument(), exceptionState); | 689 send(body.getAsDocument(), exceptionState); |
690 return; | 690 return; |
691 } | 691 } |
692 | 692 |
693 if (body.isFormData()) { | 693 if (body.isFormData()) { |
694 send(body.getAsFormData(), exceptionState); | 694 send(body.getAsFormData(), exceptionState); |
695 return; | 695 return; |
696 } | 696 } |
697 | 697 |
698 ASSERT(body.isString()); | 698 DCHECK(body.isString()); |
699 send(body.getAsString(), exceptionState); | 699 send(body.getAsString(), exceptionState); |
700 } | 700 } |
701 | 701 |
702 bool XMLHttpRequest::areMethodAndURLValidForSend() | 702 bool XMLHttpRequest::areMethodAndURLValidForSend() |
703 { | 703 { |
704 return m_method != HTTPNames::GET && m_method != HTTPNames::HEAD && m_url.pr
otocolIsInHTTPFamily(); | 704 return m_method != HTTPNames::GET && m_method != HTTPNames::HEAD && m_url.pr
otocolIsInHTTPFamily(); |
705 } | 705 } |
706 | 706 |
707 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) | 707 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) |
708 { | 708 { |
709 NETWORK_DVLOG(1) << this << " send() Document " << static_cast<void*>(docume
nt); | 709 NETWORK_DVLOG(1) << this << " send() Document " << static_cast<void*>(docume
nt); |
710 | 710 |
711 ASSERT(document); | 711 DCHECK(document); |
712 | 712 |
713 if (!initSend(exceptionState)) | 713 if (!initSend(exceptionState)) |
714 return; | 714 return; |
715 | 715 |
716 RefPtr<EncodedFormData> httpBody; | 716 RefPtr<EncodedFormData> httpBody; |
717 | 717 |
718 if (areMethodAndURLValidForSend()) { | 718 if (areMethodAndURLValidForSend()) { |
719 // FIXME: Per https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send the | 719 // FIXME: Per https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send the |
720 // Content-Type header and whether to serialize as HTML or XML should | 720 // Content-Type header and whether to serialize as HTML or XML should |
721 // depend on |document->isHTMLDocument()|. | 721 // depend on |document->isHTMLDocument()|. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 | 773 |
774 // FIXME: add support for uploading bundles. | 774 // FIXME: add support for uploading bundles. |
775 httpBody = EncodedFormData::create(); | 775 httpBody = EncodedFormData::create(); |
776 if (body->hasBackingFile()) { | 776 if (body->hasBackingFile()) { |
777 File* file = toFile(body); | 777 File* file = toFile(body); |
778 if (!file->path().isEmpty()) | 778 if (!file->path().isEmpty()) |
779 httpBody->appendFile(file->path()); | 779 httpBody->appendFile(file->path()); |
780 else if (!file->fileSystemURL().isEmpty()) | 780 else if (!file->fileSystemURL().isEmpty()) |
781 httpBody->appendFileSystemURL(file->fileSystemURL()); | 781 httpBody->appendFileSystemURL(file->fileSystemURL()); |
782 else | 782 else |
783 ASSERT_NOT_REACHED(); | 783 NOTREACHED(); |
784 } else { | 784 } else { |
785 httpBody->appendBlob(body->uuid(), body->blobDataHandle()); | 785 httpBody->appendBlob(body->uuid(), body->blobDataHandle()); |
786 } | 786 } |
787 } | 787 } |
788 | 788 |
789 createRequest(httpBody.release(), exceptionState); | 789 createRequest(httpBody.release(), exceptionState); |
790 } | 790 } |
791 | 791 |
792 void XMLHttpRequest::send(FormData* body, ExceptionState& exceptionState) | 792 void XMLHttpRequest::send(FormData* body, ExceptionState& exceptionState) |
793 { | 793 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // Only GET request is supported for blob URL. | 868 // Only GET request is supported for blob URL. |
869 if (m_url.protocolIs("blob") && m_method != HTTPNames::GET) { | 869 if (m_url.protocolIs("blob") && m_method != HTTPNames::GET) { |
870 handleNetworkError(); | 870 handleNetworkError(); |
871 | 871 |
872 if (!m_async) { | 872 if (!m_async) { |
873 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho
d allowed for 'blob:' URLs."); | 873 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho
d allowed for 'blob:' URLs."); |
874 } | 874 } |
875 return; | 875 return; |
876 } | 876 } |
877 | 877 |
878 ASSERT(getExecutionContext()); | 878 DCHECK(getExecutionContext()); |
879 ExecutionContext& executionContext = *this->getExecutionContext(); | 879 ExecutionContext& executionContext = *this->getExecutionContext(); |
880 | 880 |
881 // The presence of upload event listeners forces us to use preflighting beca
use POSTing to an URL that does not | 881 // The presence of upload event listeners forces us to use preflighting beca
use POSTing to an URL that does not |
882 // permit cross origin requests should look exactly like POSTing to an URL t
hat does not respond at all. | 882 // permit cross origin requests should look exactly like POSTing to an URL t
hat does not respond at all. |
883 // Also, only async requests support upload progress events. | 883 // Also, only async requests support upload progress events. |
884 bool uploadEvents = false; | 884 bool uploadEvents = false; |
885 if (m_async) { | 885 if (m_async) { |
886 InspectorInstrumentation::asyncTaskScheduled(&executionContext, "XMLHttp
Request.send", this, true); | 886 InspectorInstrumentation::asyncTaskScheduled(&executionContext, "XMLHttp
Request.send", this, true); |
887 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); | 887 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); |
888 if (httpBody && m_upload) { | 888 if (httpBody && m_upload) { |
(...skipping 14 matching lines...) Expand all Loading... |
903 ResourceRequest request(m_url); | 903 ResourceRequest request(m_url); |
904 request.setHTTPMethod(m_method); | 904 request.setHTTPMethod(m_method); |
905 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); | 905 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); |
906 request.setFetchCredentialsMode(m_includeCredentials ? WebURLRequest::FetchC
redentialsModeInclude : WebURLRequest::FetchCredentialsModeSameOrigin); | 906 request.setFetchCredentialsMode(m_includeCredentials ? WebURLRequest::FetchC
redentialsModeInclude : WebURLRequest::FetchCredentialsModeSameOrigin); |
907 request.setSkipServiceWorker(m_isolatedWorldSecurityOrigin.get() ? WebURLReq
uest::SkipServiceWorker::All : WebURLRequest::SkipServiceWorker::None); | 907 request.setSkipServiceWorker(m_isolatedWorldSecurityOrigin.get() ? WebURLReq
uest::SkipServiceWorker::All : WebURLRequest::SkipServiceWorker::None); |
908 request.setExternalRequestStateFromRequestorAddressSpace(executionContext.se
curityContext().addressSpace()); | 908 request.setExternalRequestStateFromRequestorAddressSpace(executionContext.se
curityContext().addressSpace()); |
909 | 909 |
910 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho
d, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders,
m_includeCredentials); | 910 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho
d, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders,
m_includeCredentials); |
911 | 911 |
912 if (httpBody) { | 912 if (httpBody) { |
913 ASSERT(m_method != HTTPNames::GET); | 913 DCHECK_NE(m_method, HTTPNames::GET); |
914 ASSERT(m_method != HTTPNames::HEAD); | 914 DCHECK_NE(m_method, HTTPNames::HEAD); |
915 request.setHTTPBody(std::move(httpBody)); | 915 request.setHTTPBody(std::move(httpBody)); |
916 } | 916 } |
917 | 917 |
918 if (m_requestHeaders.size() > 0) | 918 if (m_requestHeaders.size() > 0) |
919 request.addHTTPHeaderFields(m_requestHeaders); | 919 request.addHTTPHeaderFields(m_requestHeaders); |
920 | 920 |
921 ThreadableLoaderOptions options; | 921 ThreadableLoaderOptions options; |
922 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; | 922 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; |
923 options.crossOriginRequestPolicy = UseAccessControl; | 923 options.crossOriginRequestPolicy = UseAccessControl; |
924 options.initiator = FetchInitiatorTypeNames::xmlhttprequest; | 924 options.initiator = FetchInitiatorTypeNames::xmlhttprequest; |
(...skipping 14 matching lines...) Expand all Loading... |
939 } | 939 } |
940 | 940 |
941 m_exceptionCode = 0; | 941 m_exceptionCode = 0; |
942 m_error = false; | 942 m_error = false; |
943 | 943 |
944 if (m_async) { | 944 if (m_async) { |
945 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron
ous); | 945 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron
ous); |
946 if (m_upload) | 946 if (m_upload) |
947 request.setReportUploadProgress(true); | 947 request.setReportUploadProgress(true); |
948 | 948 |
949 ASSERT(!m_loader); | 949 DCHECK(!m_loader); |
950 m_loader = ThreadableLoader::create(executionContext, this, options, res
ourceLoaderOptions); | 950 m_loader = ThreadableLoader::create(executionContext, this, options, res
ourceLoaderOptions); |
951 m_loader->start(request); | 951 m_loader->start(request); |
952 | 952 |
953 return; | 953 return; |
954 } | 954 } |
955 | 955 |
956 // Use count for XHR synchronous requests. | 956 // Use count for XHR synchronous requests. |
957 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchronous); | 957 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchronous); |
958 ThreadableLoader::loadResourceSynchronously(executionContext, request, *this
, options, resourceLoaderOptions); | 958 ThreadableLoader::loadResourceSynchronously(executionContext, request, *this
, options, resourceLoaderOptions); |
959 | 959 |
(...skipping 24 matching lines...) Expand all Loading... |
984 // send() call and transition to the DONE state. It's because a sync XHR | 984 // send() call and transition to the DONE state. It's because a sync XHR |
985 // doesn't dispatch any event between them. So, if |m_async| is false, we | 985 // doesn't dispatch any event between them. So, if |m_async| is false, we |
986 // can skip the "request error steps" (defined in the XHR spec) without any | 986 // can skip the "request error steps" (defined in the XHR spec) without any |
987 // state check. | 987 // state check. |
988 // | 988 // |
989 // FIXME: It's possible open() is invoked in internalAbort() and |m_async| | 989 // FIXME: It's possible open() is invoked in internalAbort() and |m_async| |
990 // becomes true by that. We should implement more reliable treatment for | 990 // becomes true by that. We should implement more reliable treatment for |
991 // nested method invocations at some point. | 991 // nested method invocations at some point. |
992 if (m_async) { | 992 if (m_async) { |
993 if ((m_state == kOpened && sendFlag) || m_state == kHeadersReceived || m
_state == kLoading) { | 993 if ((m_state == kOpened && sendFlag) || m_state == kHeadersReceived || m
_state == kLoading) { |
994 ASSERT(!m_loader); | 994 DCHECK(!m_loader); |
995 handleRequestError(0, EventTypeNames::abort, receivedLength, expecte
dLength); | 995 handleRequestError(0, EventTypeNames::abort, receivedLength, expecte
dLength); |
996 } | 996 } |
997 } | 997 } |
998 m_state = kUnsent; | 998 m_state = kUnsent; |
999 } | 999 } |
1000 | 1000 |
1001 void XMLHttpRequest::clearVariablesForLoading() | 1001 void XMLHttpRequest::clearVariablesForLoading() |
1002 { | 1002 { |
1003 if (m_blobLoader) { | 1003 if (m_blobLoader) { |
1004 m_blobLoader->cancel(); | 1004 m_blobLoader->cancel(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect
edLength); | 1131 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect
edLength); |
1132 } | 1132 } |
1133 | 1133 |
1134 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
cString& type, long long receivedLength, long long expectedLength) | 1134 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
cString& type, long long receivedLength, long long expectedLength) |
1135 { | 1135 { |
1136 NETWORK_DVLOG(1) << this << " handleRequestError()"; | 1136 NETWORK_DVLOG(1) << this << " handleRequestError()"; |
1137 | 1137 |
1138 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi
s, m_method, m_url); | 1138 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi
s, m_method, m_url); |
1139 | 1139 |
1140 if (!m_async) { | 1140 if (!m_async) { |
1141 ASSERT(exceptionCode); | 1141 DCHECK(exceptionCode); |
1142 m_state = kDone; | 1142 m_state = kDone; |
1143 m_exceptionCode = exceptionCode; | 1143 m_exceptionCode = exceptionCode; |
1144 return; | 1144 return; |
1145 } | 1145 } |
1146 | 1146 |
1147 // With m_error set, the state change steps are minimal: any pending | 1147 // With m_error set, the state change steps are minimal: any pending |
1148 // progress event is flushed + a readystatechange is dispatched. | 1148 // progress event is flushed + a readystatechange is dispatched. |
1149 // No new progress events dispatched; as required, that happens at | 1149 // No new progress events dispatched; as required, that happens at |
1150 // the end here. | 1150 // the end here. |
1151 ASSERT(m_error); | 1151 DCHECK(m_error); |
1152 changeState(kDone); | 1152 changeState(kDone); |
1153 | 1153 |
1154 if (!m_uploadComplete) { | 1154 if (!m_uploadComplete) { |
1155 m_uploadComplete = true; | 1155 m_uploadComplete = true; |
1156 if (m_upload && m_uploadEventsAllowed) | 1156 if (m_upload && m_uploadEventsAllowed) |
1157 m_upload->handleRequestError(type); | 1157 m_upload->handleRequestError(type); |
1158 } | 1158 } |
1159 | 1159 |
1160 // Note: The below event dispatch may be called while |hasPendingActivity()
== false|, | 1160 // Note: The below event dispatch may be called while |hasPendingActivity()
== false|, |
1161 // when |handleRequestError| is called after |internalAbort()|. | 1161 // when |handleRequestError| is called after |internalAbort()|. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 } | 1403 } |
1404 | 1404 |
1405 void XMLHttpRequest::didFinishLoadingInternal() | 1405 void XMLHttpRequest::didFinishLoadingInternal() |
1406 { | 1406 { |
1407 if (m_responseDocumentParser) { | 1407 if (m_responseDocumentParser) { |
1408 // |DocumentParser::finish()| tells the parser that we have reached end
of the data. | 1408 // |DocumentParser::finish()| tells the parser that we have reached end
of the data. |
1409 // When using |HTMLDocumentParser|, which works asynchronously, we do no
t have the | 1409 // When using |HTMLDocumentParser|, which works asynchronously, we do no
t have the |
1410 // complete document just after the |DocumentParser::finish()| call. | 1410 // complete document just after the |DocumentParser::finish()| call. |
1411 // Wait for the parser to call us back in |notifyParserStopped| to progr
ess state. | 1411 // Wait for the parser to call us back in |notifyParserStopped| to progr
ess state. |
1412 m_responseDocumentParser->finish(); | 1412 m_responseDocumentParser->finish(); |
1413 ASSERT(m_responseDocument); | 1413 DCHECK(m_responseDocument); |
1414 return; | 1414 return; |
1415 } | 1415 } |
1416 | 1416 |
1417 if (m_decoder) { | 1417 if (m_decoder) { |
1418 auto text = m_decoder->flush(); | 1418 auto text = m_decoder->flush(); |
1419 if (!text.isEmpty() && !m_responseTextOverflow) { | 1419 if (!text.isEmpty() && !m_responseTextOverflow) { |
1420 m_responseText = m_responseText.concatenateWith(text); | 1420 m_responseText = m_responseText.concatenateWith(text); |
1421 m_responseTextOverflow = m_responseText.isEmpty(); | 1421 m_responseTextOverflow = m_responseText.isEmpty(); |
1422 } | 1422 } |
1423 } | 1423 } |
(...skipping 18 matching lines...) Expand all Loading... |
1442 NETWORK_DVLOG(1) << this << " didFailLoadingFromBlob()"; | 1442 NETWORK_DVLOG(1) << this << " didFailLoadingFromBlob()"; |
1443 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1443 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
1444 | 1444 |
1445 if (m_error) | 1445 if (m_error) |
1446 return; | 1446 return; |
1447 handleNetworkError(); | 1447 handleNetworkError(); |
1448 } | 1448 } |
1449 | 1449 |
1450 PassRefPtr<BlobDataHandle> XMLHttpRequest::createBlobDataHandleFromResponse() | 1450 PassRefPtr<BlobDataHandle> XMLHttpRequest::createBlobDataHandleFromResponse() |
1451 { | 1451 { |
1452 ASSERT(m_downloadingToFile); | 1452 DCHECK(m_downloadingToFile); |
1453 std::unique_ptr<BlobData> blobData = BlobData::create(); | 1453 std::unique_ptr<BlobData> blobData = BlobData::create(); |
1454 String filePath = m_response.downloadedFilePath(); | 1454 String filePath = m_response.downloadedFilePath(); |
1455 // If we errored out or got no data, we return an empty handle. | 1455 // If we errored out or got no data, we return an empty handle. |
1456 if (!filePath.isEmpty() && m_lengthDownloadedToFile) { | 1456 if (!filePath.isEmpty() && m_lengthDownloadedToFile) { |
1457 blobData->appendFile(filePath, 0, m_lengthDownloadedToFile, invalidFileT
ime()); | 1457 blobData->appendFile(filePath, 0, m_lengthDownloadedToFile, invalidFileT
ime()); |
1458 // FIXME: finalResponseMIMETypeWithFallback() defaults to | 1458 // FIXME: finalResponseMIMETypeWithFallback() defaults to |
1459 // text/xml which may be incorrect. Replace it with | 1459 // text/xml which may be incorrect. Replace it with |
1460 // finalResponseMIMEType() after compatibility investigation. | 1460 // finalResponseMIMEType() after compatibility investigation. |
1461 blobData->setContentType(finalResponseMIMETypeWithFallback().lower()); | 1461 blobData->setContentType(finalResponseMIMETypeWithFallback().lower()); |
1462 } | 1462 } |
1463 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile)
; | 1463 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile)
; |
1464 } | 1464 } |
1465 | 1465 |
1466 void XMLHttpRequest::notifyParserStopped() | 1466 void XMLHttpRequest::notifyParserStopped() |
1467 { | 1467 { |
1468 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1468 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
1469 | 1469 |
1470 // This should only be called when response document is parsed asynchronousl
y. | 1470 // This should only be called when response document is parsed asynchronousl
y. |
1471 ASSERT(m_responseDocumentParser); | 1471 DCHECK(m_responseDocumentParser); |
1472 ASSERT(!m_responseDocumentParser->isParsing()); | 1472 DCHECK(!m_responseDocumentParser->isParsing()); |
1473 ASSERT(!m_responseLegacyStream); | 1473 DCHECK(!m_responseLegacyStream); |
1474 | 1474 |
1475 // Do nothing if we are called from |internalAbort()|. | 1475 // Do nothing if we are called from |internalAbort()|. |
1476 if (m_error) | 1476 if (m_error) |
1477 return; | 1477 return; |
1478 | 1478 |
1479 clearVariablesForLoading(); | 1479 clearVariablesForLoading(); |
1480 | 1480 |
1481 m_responseDocument->implicitClose(); | 1481 m_responseDocument->implicitClose(); |
1482 | 1482 |
1483 if (!m_responseDocument->wellFormed()) | 1483 if (!m_responseDocument->wellFormed()) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 | 1525 |
1526 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) { | 1526 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) { |
1527 m_uploadComplete = true; | 1527 m_uploadComplete = true; |
1528 if (m_uploadEventsAllowed) | 1528 if (m_uploadEventsAllowed) |
1529 m_upload->dispatchEventAndLoadEnd(EventTypeNames::load, true, bytesS
ent, totalBytesToBeSent); | 1529 m_upload->dispatchEventAndLoadEnd(EventTypeNames::load, true, bytesS
ent, totalBytesToBeSent); |
1530 } | 1530 } |
1531 } | 1531 } |
1532 | 1532 |
1533 void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const Resource
Response& response, std::unique_ptr<WebDataConsumerHandle> handle) | 1533 void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const Resource
Response& response, std::unique_ptr<WebDataConsumerHandle> handle) |
1534 { | 1534 { |
1535 ASSERT_UNUSED(handle, !handle); | 1535 ALLOW_UNUSED_LOCAL(handle); |
| 1536 DCHECK(!handle); |
1536 NETWORK_DVLOG(1) << this << " didReceiveResponse(" << identifier << ")"; | 1537 NETWORK_DVLOG(1) << this << " didReceiveResponse(" << identifier << ")"; |
1537 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1538 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
1538 | 1539 |
1539 m_response = response; | 1540 m_response = response; |
1540 if (!m_mimeTypeOverride.isEmpty()) { | 1541 if (!m_mimeTypeOverride.isEmpty()) { |
1541 m_response.setHTTPHeaderField(HTTPNames::Content_Type, m_mimeTypeOverrid
e); | 1542 m_response.setHTTPHeaderField(HTTPNames::Content_Type, m_mimeTypeOverrid
e); |
1542 m_finalResponseCharset = extractCharsetFromMediaType(m_mimeTypeOverride)
; | 1543 m_finalResponseCharset = extractCharsetFromMediaType(m_mimeTypeOverride)
; |
1543 } | 1544 } |
1544 | 1545 |
1545 if (m_finalResponseCharset.isEmpty()) | 1546 if (m_finalResponseCharset.isEmpty()) |
1546 m_finalResponseCharset = response.textEncodingName(); | 1547 m_finalResponseCharset = response.textEncodingName(); |
1547 } | 1548 } |
1548 | 1549 |
1549 void XMLHttpRequest::parseDocumentChunk(const char* data, unsigned len) | 1550 void XMLHttpRequest::parseDocumentChunk(const char* data, unsigned len) |
1550 { | 1551 { |
1551 if (!m_responseDocumentParser) { | 1552 if (!m_responseDocumentParser) { |
1552 ASSERT(!m_responseDocument); | 1553 DCHECK(!m_responseDocument); |
1553 initResponseDocument(); | 1554 initResponseDocument(); |
1554 if (!m_responseDocument) | 1555 if (!m_responseDocument) |
1555 return; | 1556 return; |
1556 | 1557 |
1557 m_responseDocumentParser = m_responseDocument->implicitOpen(AllowAsynchr
onousParsing); | 1558 m_responseDocumentParser = m_responseDocument->implicitOpen(AllowAsynchr
onousParsing); |
1558 m_responseDocumentParser->addClient(this); | 1559 m_responseDocumentParser->addClient(this); |
1559 } | 1560 } |
1560 ASSERT(m_responseDocumentParser); | 1561 DCHECK(m_responseDocumentParser); |
1561 | 1562 |
1562 if (m_responseDocumentParser->needsDecoder()) | 1563 if (m_responseDocumentParser->needsDecoder()) |
1563 m_responseDocumentParser->setDecoder(createDecoder()); | 1564 m_responseDocumentParser->setDecoder(createDecoder()); |
1564 | 1565 |
1565 m_responseDocumentParser->appendBytes(data, len); | 1566 m_responseDocumentParser->appendBytes(data, len); |
1566 } | 1567 } |
1567 | 1568 |
1568 std::unique_ptr<TextResourceDecoder> XMLHttpRequest::createDecoder() const | 1569 std::unique_ptr<TextResourceDecoder> XMLHttpRequest::createDecoder() const |
1569 { | 1570 { |
1570 if (m_responseTypeCode == ResponseTypeJSON) | 1571 if (m_responseTypeCode == ResponseTypeJSON) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 } | 1637 } |
1637 trackProgress(len); | 1638 trackProgress(len); |
1638 } | 1639 } |
1639 | 1640 |
1640 void XMLHttpRequest::didDownloadData(int dataLength) | 1641 void XMLHttpRequest::didDownloadData(int dataLength) |
1641 { | 1642 { |
1642 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1643 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
1643 if (m_error) | 1644 if (m_error) |
1644 return; | 1645 return; |
1645 | 1646 |
1646 ASSERT(m_downloadingToFile); | 1647 DCHECK(m_downloadingToFile); |
1647 | 1648 |
1648 if (m_state < kHeadersReceived) | 1649 if (m_state < kHeadersReceived) |
1649 changeState(kHeadersReceived); | 1650 changeState(kHeadersReceived); |
1650 | 1651 |
1651 if (!dataLength) | 1652 if (!dataLength) |
1652 return; | 1653 return; |
1653 | 1654 |
1654 // readystatechange event handler may do something to put this XHR in error | 1655 // readystatechange event handler may do something to put this XHR in error |
1655 // state. We need to check m_error again here. | 1656 // state. We need to check m_error again here. |
1656 if (m_error) | 1657 if (m_error) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 // |m_loader| is non-null while request is active and ThreadableLoaderClient | 1701 // |m_loader| is non-null while request is active and ThreadableLoaderClient |
1701 // callbacks may be called, and |m_responseDocumentParser| is non-null while | 1702 // callbacks may be called, and |m_responseDocumentParser| is non-null while |
1702 // DocumentParserClient callbacks may be called. | 1703 // DocumentParserClient callbacks may be called. |
1703 if (m_loader || m_responseDocumentParser) | 1704 if (m_loader || m_responseDocumentParser) |
1704 return true; | 1705 return true; |
1705 return m_eventDispatchRecursionLevel > 0; | 1706 return m_eventDispatchRecursionLevel > 0; |
1706 } | 1707 } |
1707 | 1708 |
1708 void XMLHttpRequest::contextDestroyed() | 1709 void XMLHttpRequest::contextDestroyed() |
1709 { | 1710 { |
1710 ASSERT(!m_loader); | 1711 DCHECK(!m_loader); |
1711 ActiveDOMObject::contextDestroyed(); | 1712 ActiveDOMObject::contextDestroyed(); |
1712 } | 1713 } |
1713 | 1714 |
1714 const AtomicString& XMLHttpRequest::interfaceName() const | 1715 const AtomicString& XMLHttpRequest::interfaceName() const |
1715 { | 1716 { |
1716 return EventTargetNames::XMLHttpRequest; | 1717 return EventTargetNames::XMLHttpRequest; |
1717 } | 1718 } |
1718 | 1719 |
1719 ExecutionContext* XMLHttpRequest::getExecutionContext() const | 1720 ExecutionContext* XMLHttpRequest::getExecutionContext() const |
1720 { | 1721 { |
(...skipping 23 matching lines...) Expand all Loading... |
1744 visitor->traceWrappers(m_responseDocument); | 1745 visitor->traceWrappers(m_responseDocument); |
1745 visitor->traceWrappers(m_responseArrayBuffer); | 1746 visitor->traceWrappers(m_responseArrayBuffer); |
1746 } | 1747 } |
1747 | 1748 |
1748 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) | 1749 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) |
1749 { | 1750 { |
1750 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); | 1751 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); |
1751 } | 1752 } |
1752 | 1753 |
1753 } // namespace blink | 1754 } // namespace blink |
OLD | NEW |