Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> | 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> |
| 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> | 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> |
| 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. |
| 6 * Copyright (C) 2012 Intel Corporation | 6 * Copyright (C) 2012 Intel Corporation |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 | 650 |
| 651 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) | 651 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) |
| 652 { | 652 { |
| 653 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document); | 653 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document); |
| 654 | 654 |
| 655 ASSERT(document); | 655 ASSERT(document); |
| 656 | 656 |
| 657 if (!initSend(exceptionState)) | 657 if (!initSend(exceptionState)) |
| 658 return; | 658 return; |
| 659 | 659 |
| 660 RefPtr<FormData> httpBody; | |
| 661 | |
| 660 if (areMethodAndURLValidForSend()) { | 662 if (areMethodAndURLValidForSend()) { |
| 661 if (getRequestHeader("Content-Type").isEmpty()) { | 663 if (getRequestHeader("Content-Type").isEmpty()) { |
| 662 // FIXME: this should include the charset used for encoding. | 664 // FIXME: this should include the charset used for encoding. |
| 663 setRequestHeaderInternal("Content-Type", "application/xml"); | 665 setRequestHeaderInternal("Content-Type", "application/xml"); |
| 664 } | 666 } |
| 665 | 667 |
| 666 // FIXME: According to XMLHttpRequest Level 2, this should use the Docum ent.innerHTML algorithm | 668 // FIXME: According to XMLHttpRequest Level 2, this should use the Docum ent.innerHTML algorithm |
| 667 // from the HTML5 specification to serialize the document. | 669 // from the HTML5 specification to serialize the document. |
| 668 String body = createMarkup(document); | 670 String body = createMarkup(document); |
| 669 | 671 |
| 670 // FIXME: This should use value of document.inputEncoding to determine t he encoding to use. | 672 // FIXME: This should use value of document.inputEncoding to determine t he encoding to use. |
| 671 m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF:: EntitiesForUnencodables)); | 673 httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesFor Unencodables)); |
| 672 if (m_upload) | 674 if (m_upload) |
| 673 m_requestEntityBody->setAlwaysStream(true); | 675 httpBody->setAlwaysStream(true); |
| 674 } | 676 } |
| 675 | 677 |
| 676 createRequest(exceptionState); | 678 createRequest(httpBody.release(), exceptionState); |
| 677 } | 679 } |
| 678 | 680 |
| 679 void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) | 681 void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) |
| 680 { | 682 { |
| 681 WTF_LOG(Network, "XMLHttpRequest %p send() String '%s'", this, body.utf8().d ata()); | 683 WTF_LOG(Network, "XMLHttpRequest %p send() String '%s'", this, body.utf8().d ata()); |
| 682 | 684 |
| 683 if (!initSend(exceptionState)) | 685 if (!initSend(exceptionState)) |
| 684 return; | 686 return; |
| 685 | 687 |
| 688 RefPtr<FormData> httpBody; | |
| 689 | |
| 686 if (!body.isNull() && areMethodAndURLValidForSend()) { | 690 if (!body.isNull() && areMethodAndURLValidForSend()) { |
| 687 String contentType = getRequestHeader("Content-Type"); | 691 String contentType = getRequestHeader("Content-Type"); |
| 688 if (contentType.isEmpty()) { | 692 if (contentType.isEmpty()) { |
| 689 setRequestHeaderInternal("Content-Type", "text/plain;charset=UTF-8") ; | 693 setRequestHeaderInternal("Content-Type", "text/plain;charset=UTF-8") ; |
| 690 } else { | 694 } else { |
| 691 replaceCharsetInMediaType(contentType, "UTF-8"); | 695 replaceCharsetInMediaType(contentType, "UTF-8"); |
| 692 m_requestHeaders.set("Content-Type", AtomicString(contentType)); | 696 m_requestHeaders.set("Content-Type", AtomicString(contentType)); |
| 693 } | 697 } |
| 694 | 698 |
| 695 m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF:: EntitiesForUnencodables)); | 699 httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesFor Unencodables)); |
| 696 if (m_upload) | 700 if (m_upload) |
| 697 m_requestEntityBody->setAlwaysStream(true); | 701 httpBody->setAlwaysStream(true); |
| 698 } | 702 } |
| 699 | 703 |
| 700 createRequest(exceptionState); | 704 createRequest(httpBody.release(), exceptionState); |
| 701 } | 705 } |
| 702 | 706 |
| 703 void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) | 707 void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) |
| 704 { | 708 { |
| 705 WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().ut f8().data()); | 709 WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().ut f8().data()); |
| 706 | 710 |
| 707 if (!initSend(exceptionState)) | 711 if (!initSend(exceptionState)) |
| 708 return; | 712 return; |
| 709 | 713 |
| 714 RefPtr<FormData> httpBody; | |
| 715 | |
| 710 if (areMethodAndURLValidForSend()) { | 716 if (areMethodAndURLValidForSend()) { |
| 711 if (getRequestHeader("Content-Type").isEmpty()) { | 717 if (getRequestHeader("Content-Type").isEmpty()) { |
| 712 const String& blobType = body->type(); | 718 const String& blobType = body->type(); |
| 713 if (!blobType.isEmpty() && isValidContentType(blobType)) | 719 if (!blobType.isEmpty() && isValidContentType(blobType)) |
| 714 setRequestHeaderInternal("Content-Type", AtomicString(blobType)) ; | 720 setRequestHeaderInternal("Content-Type", AtomicString(blobType)) ; |
| 715 else { | 721 else { |
| 716 // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. | 722 // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. |
| 717 setRequestHeaderInternal("Content-Type", ""); | 723 setRequestHeaderInternal("Content-Type", ""); |
| 718 } | 724 } |
| 719 } | 725 } |
| 720 | 726 |
| 721 // FIXME: add support for uploading bundles. | 727 // FIXME: add support for uploading bundles. |
| 722 m_requestEntityBody = FormData::create(); | 728 httpBody = FormData::create(); |
| 723 if (body->hasBackingFile()) { | 729 if (body->hasBackingFile()) { |
| 724 File* file = toFile(body); | 730 File* file = toFile(body); |
| 725 if (!file->path().isEmpty()) | 731 if (!file->path().isEmpty()) |
| 726 m_requestEntityBody->appendFile(file->path()); | 732 httpBody->appendFile(file->path()); |
| 727 else if (!file->fileSystemURL().isEmpty()) | 733 else if (!file->fileSystemURL().isEmpty()) |
| 728 m_requestEntityBody->appendFileSystemURL(file->fileSystemURL()); | 734 httpBody->appendFileSystemURL(file->fileSystemURL()); |
| 729 else | 735 else |
| 730 ASSERT_NOT_REACHED(); | 736 ASSERT_NOT_REACHED(); |
| 731 } else { | 737 } else { |
| 732 m_requestEntityBody->appendBlob(body->uuid(), body->blobDataHandle() ); | 738 httpBody->appendBlob(body->uuid(), body->blobDataHandle()); |
| 733 } | 739 } |
| 734 } | 740 } |
| 735 | 741 |
| 736 createRequest(exceptionState); | 742 createRequest(httpBody.release(), exceptionState); |
| 737 } | 743 } |
| 738 | 744 |
| 739 void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) | 745 void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) |
| 740 { | 746 { |
| 741 WTF_LOG(Network, "XMLHttpRequest %p send() DOMFormData %p", this, body); | 747 WTF_LOG(Network, "XMLHttpRequest %p send() DOMFormData %p", this, body); |
| 742 | 748 |
| 743 if (!initSend(exceptionState)) | 749 if (!initSend(exceptionState)) |
| 744 return; | 750 return; |
| 745 | 751 |
| 752 RefPtr<FormData> httpBody; | |
| 753 | |
| 746 if (areMethodAndURLValidForSend()) { | 754 if (areMethodAndURLValidForSend()) { |
| 747 m_requestEntityBody = body->createMultiPartFormData(body->encoding()); | 755 httpBody = body->createMultiPartFormData(body->encoding()); |
| 748 | 756 |
| 749 if (getRequestHeader("Content-Type").isEmpty()) { | 757 if (getRequestHeader("Content-Type").isEmpty()) { |
| 750 AtomicString contentType = AtomicString("multipart/form-data; bounda ry=", AtomicString::ConstructFromLiteral) + m_requestEntityBody->boundary().data (); | 758 AtomicString contentType = AtomicString("multipart/form-data; bounda ry=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data(); |
| 751 setRequestHeaderInternal("Content-Type", contentType); | 759 setRequestHeaderInternal("Content-Type", contentType); |
| 752 } | 760 } |
| 753 } | 761 } |
| 754 | 762 |
| 755 createRequest(exceptionState); | 763 createRequest(httpBody.release(), exceptionState); |
| 756 } | 764 } |
| 757 | 765 |
| 758 void XMLHttpRequest::send(ArrayBuffer* body, ExceptionState& exceptionState) | 766 void XMLHttpRequest::send(ArrayBuffer* body, ExceptionState& exceptionState) |
| 759 { | 767 { |
| 760 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBuffer %p", this, body); | 768 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBuffer %p", this, body); |
| 761 | 769 |
| 762 String consoleMessage("ArrayBuffer is deprecated in XMLHttpRequest.send(). U se ArrayBufferView instead."); | 770 String consoleMessage("ArrayBuffer is deprecated in XMLHttpRequest.send(). U se ArrayBufferView instead."); |
| 763 executionContext()->addConsoleMessage(JSMessageSource, WarningMessageLevel, consoleMessage); | 771 executionContext()->addConsoleMessage(JSMessageSource, WarningMessageLevel, consoleMessage); |
| 764 | 772 |
| 765 blink::Platform::current()->histogramEnumeration("WebCore.XHR.send.ArrayBuff erOrView", XMLHttpRequestSendArrayBuffer, XMLHttpRequestSendArrayBufferOrViewMax ); | 773 blink::Platform::current()->histogramEnumeration("WebCore.XHR.send.ArrayBuff erOrView", XMLHttpRequestSendArrayBuffer, XMLHttpRequestSendArrayBufferOrViewMax ); |
| 766 | 774 |
| 767 sendBytesData(body->data(), body->byteLength(), exceptionState); | 775 sendBytesData(body->data(), body->byteLength(), exceptionState); |
| 768 } | 776 } |
| 769 | 777 |
| 770 void XMLHttpRequest::send(ArrayBufferView* body, ExceptionState& exceptionState) | 778 void XMLHttpRequest::send(ArrayBufferView* body, ExceptionState& exceptionState) |
| 771 { | 779 { |
| 772 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBufferView %p", this, body); | 780 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBufferView %p", this, body); |
| 773 | 781 |
| 774 blink::Platform::current()->histogramEnumeration("WebCore.XHR.send.ArrayBuff erOrView", XMLHttpRequestSendArrayBufferView, XMLHttpRequestSendArrayBufferOrVie wMax); | 782 blink::Platform::current()->histogramEnumeration("WebCore.XHR.send.ArrayBuff erOrView", XMLHttpRequestSendArrayBufferView, XMLHttpRequestSendArrayBufferOrVie wMax); |
| 775 | 783 |
| 776 sendBytesData(body->baseAddress(), body->byteLength(), exceptionState); | 784 sendBytesData(body->baseAddress(), body->byteLength(), exceptionState); |
| 777 } | 785 } |
| 778 | 786 |
| 779 void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta te& exceptionState) | 787 void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta te& exceptionState) |
| 780 { | 788 { |
| 781 if (!initSend(exceptionState)) | 789 if (!initSend(exceptionState)) |
| 782 return; | 790 return; |
| 783 | 791 |
| 792 RefPtr<FormData> httpBody; | |
| 793 | |
| 784 if (areMethodAndURLValidForSend()) { | 794 if (areMethodAndURLValidForSend()) { |
| 785 m_requestEntityBody = FormData::create(data, length); | 795 httpBody = FormData::create(data, length); |
| 786 if (m_upload) | 796 if (m_upload) |
| 787 m_requestEntityBody->setAlwaysStream(true); | 797 httpBody->setAlwaysStream(true); |
| 788 } | 798 } |
| 789 | 799 |
| 790 createRequest(exceptionState); | 800 createRequest(httpBody.release(), exceptionState); |
| 791 } | 801 } |
| 792 | 802 |
| 793 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) | 803 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) |
| 794 { | 804 { |
| 795 m_requestEntityBody = formData ? formData->deepCopy() : nullptr; | 805 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState); |
| 796 createRequest(exceptionState); | |
| 797 m_exceptionCode = exceptionState.code(); | 806 m_exceptionCode = exceptionState.code(); |
| 798 } | 807 } |
| 799 | 808 |
| 800 void XMLHttpRequest::createRequest(ExceptionState& exceptionState) | 809 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState) |
| 801 { | 810 { |
| 802 // Only GET request is supported for blob URL. | 811 // Only GET request is supported for blob URL. |
| 803 if (m_url.protocolIs("blob") && m_method != "GET") { | 812 if (m_url.protocolIs("blob") && m_method != "GET") { |
| 804 exceptionState.throwDOMException(NetworkError, "'GET' is the only method allowed for 'blob:' URLs."); | 813 exceptionState.throwDOMException(NetworkError, "'GET' is the only method allowed for 'blob:' URLs."); |
| 805 return; | 814 return; |
| 806 } | 815 } |
| 807 | 816 |
| 808 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not | 817 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not |
| 809 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. | 818 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. |
| 810 // Also, only async requests support upload progress events. | 819 // Also, only async requests support upload progress events. |
| 811 bool uploadEvents = false; | 820 bool uploadEvents = false; |
| 812 if (m_async) { | 821 if (m_async) { |
| 813 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); | 822 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); |
| 814 if (m_requestEntityBody && m_upload) { | 823 if (httpBody.get() && m_upload) { |
|
tkent
2014/06/09 04:39:05
nit: |.get()| is unnecessary.
tyoshino (SeeGerritForStatus)
2014/06/09 04:52:30
Done.
| |
| 815 uploadEvents = m_upload->hasEventListeners(); | 824 uploadEvents = m_upload->hasEventListeners(); |
| 816 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTyp eNames::loadstart)); | 825 m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTyp eNames::loadstart)); |
| 817 } | 826 } |
| 818 } | 827 } |
| 819 | 828 |
| 820 m_sameOriginRequest = securityOrigin()->canRequest(m_url); | 829 m_sameOriginRequest = securityOrigin()->canRequest(m_url); |
| 821 | 830 |
| 822 // We also remember whether upload events should be allowed for this request in case the upload listeners are | 831 // We also remember whether upload events should be allowed for this request in case the upload listeners are |
| 823 // added after the request is started. | 832 // added after the request is started. |
| 824 m_uploadEventsAllowed = m_sameOriginRequest || uploadEvents || !isSimpleCros sOriginAccessRequest(m_method, m_requestHeaders); | 833 m_uploadEventsAllowed = m_sameOriginRequest || uploadEvents || !isSimpleCros sOriginAccessRequest(m_method, m_requestHeaders); |
| 825 | 834 |
| 826 ASSERT(executionContext()); | 835 ASSERT(executionContext()); |
| 827 ExecutionContext& executionContext = *this->executionContext(); | 836 ExecutionContext& executionContext = *this->executionContext(); |
| 828 | 837 |
| 829 ResourceRequest request(m_url); | 838 ResourceRequest request(m_url); |
| 830 request.setHTTPMethod(m_method); | 839 request.setHTTPMethod(m_method); |
| 831 request.setTargetType(ResourceRequest::TargetIsXHR); | 840 request.setTargetType(ResourceRequest::TargetIsXHR); |
| 832 | 841 |
| 833 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho d, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : nullp tr, m_requestHeaders, m_includeCredentials); | 842 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho d, m_url, m_async, httpBody.get() ? httpBody->deepCopy() : nullptr, m_requestHea ders, m_includeCredentials); |
|
tkent
2014/06/09 04:39:05
nit: |.get()| is unnecessary.
tyoshino (SeeGerritForStatus)
2014/06/09 04:52:30
Done.
| |
| 834 | 843 |
| 835 if (m_requestEntityBody) { | 844 if (httpBody.get()) { |
|
tkent
2014/06/09 04:39:05
Ditto.
tyoshino (SeeGerritForStatus)
2014/06/09 04:52:30
Done.
| |
| 836 ASSERT(m_method != "GET"); | 845 ASSERT(m_method != "GET"); |
| 837 ASSERT(m_method != "HEAD"); | 846 ASSERT(m_method != "HEAD"); |
| 838 request.setHTTPBody(m_requestEntityBody.release()); | 847 request.setHTTPBody(httpBody); |
| 839 } | 848 } |
| 840 | 849 |
| 841 if (m_requestHeaders.size() > 0) | 850 if (m_requestHeaders.size() > 0) |
| 842 request.addHTTPHeaderFields(m_requestHeaders); | 851 request.addHTTPHeaderFields(m_requestHeaders); |
| 843 | 852 |
| 844 ThreadableLoaderOptions options; | 853 ThreadableLoaderOptions options; |
| 845 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; | 854 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; |
| 846 options.crossOriginRequestPolicy = UseAccessControl; | 855 options.crossOriginRequestPolicy = UseAccessControl; |
| 847 options.initiator = FetchInitiatorTypeNames::xmlhttprequest; | 856 options.initiator = FetchInitiatorTypeNames::xmlhttprequest; |
| 848 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(&executionContext) ? DoNotEnforceContentSecurityPolicy : EnforceConn ectSrcDirective; | 857 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(&executionContext) ? DoNotEnforceContentSecurityPolicy : EnforceConn ectSrcDirective; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 | 1000 |
| 992 // These variables may referred by the response accessors. So, we can clear | 1001 // These variables may referred by the response accessors. So, we can clear |
| 993 // this only when we clear the response holder variables above. | 1002 // this only when we clear the response holder variables above. |
| 994 m_binaryResponseBuilder.clear(); | 1003 m_binaryResponseBuilder.clear(); |
| 995 m_responseArrayBuffer.clear(); | 1004 m_responseArrayBuffer.clear(); |
| 996 } | 1005 } |
| 997 | 1006 |
| 998 void XMLHttpRequest::clearRequest() | 1007 void XMLHttpRequest::clearRequest() |
| 999 { | 1008 { |
| 1000 m_requestHeaders.clear(); | 1009 m_requestHeaders.clear(); |
| 1001 m_requestEntityBody = nullptr; | |
| 1002 } | 1010 } |
| 1003 | 1011 |
| 1004 void XMLHttpRequest::handleDidFailGeneric() | 1012 void XMLHttpRequest::handleDidFailGeneric() |
| 1005 { | 1013 { |
| 1006 clearResponse(); | 1014 clearResponse(); |
| 1007 clearRequest(); | 1015 clearRequest(); |
| 1008 | 1016 |
| 1009 m_error = true; | 1017 m_error = true; |
| 1010 } | 1018 } |
| 1011 | 1019 |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1450 { | 1458 { |
| 1451 visitor->trace(m_responseBlob); | 1459 visitor->trace(m_responseBlob); |
| 1452 visitor->trace(m_responseStream); | 1460 visitor->trace(m_responseStream); |
| 1453 visitor->trace(m_responseDocument); | 1461 visitor->trace(m_responseDocument); |
| 1454 visitor->trace(m_progressEventThrottle); | 1462 visitor->trace(m_progressEventThrottle); |
| 1455 visitor->trace(m_upload); | 1463 visitor->trace(m_upload); |
| 1456 XMLHttpRequestEventTarget::trace(visitor); | 1464 XMLHttpRequestEventTarget::trace(visitor); |
| 1457 } | 1465 } |
| 1458 | 1466 |
| 1459 } // namespace WebCore | 1467 } // namespace WebCore |
| OLD | NEW |