Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 1311923004: Rename FormData/FormDataBuilder to EncodedFormData/FormDataEncoder respectively. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: update comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.h ('k') | Source/modules/fetch/BodyStreamBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 699
700 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) 700 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
701 { 701 {
702 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document); 702 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document);
703 703
704 ASSERT(document); 704 ASSERT(document);
705 705
706 if (!initSend(exceptionState)) 706 if (!initSend(exceptionState))
707 return; 707 return;
708 708
709 RefPtr<FormData> httpBody; 709 RefPtr<EncodedFormData> httpBody;
710 710
711 if (areMethodAndURLValidForSend()) { 711 if (areMethodAndURLValidForSend()) {
712 // FIXME: Per https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send the 712 // FIXME: Per https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send the
713 // Content-Type header and whether to serialize as HTML or XML should 713 // Content-Type header and whether to serialize as HTML or XML should
714 // depend on |document->isHTMLDocument()|. 714 // depend on |document->isHTMLDocument()|.
715 if (getRequestHeader("Content-Type").isEmpty()) 715 if (getRequestHeader("Content-Type").isEmpty())
716 setRequestHeaderInternal("Content-Type", "application/xml;charset=UT F-8"); 716 setRequestHeaderInternal("Content-Type", "application/xml;charset=UT F-8");
717 717
718 String body = createMarkup(document); 718 String body = createMarkup(document);
719 719
720 httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesFor Unencodables)); 720 httpBody = EncodedFormData::create(UTF8Encoding().encode(body, WTF::Enti tiesForUnencodables));
721 } 721 }
722 722
723 createRequest(httpBody.release(), exceptionState); 723 createRequest(httpBody.release(), exceptionState);
724 } 724 }
725 725
726 void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) 726 void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
727 { 727 {
728 WTF_LOG(Network, "XMLHttpRequest %p send() String '%s'", this, body.utf8().d ata()); 728 WTF_LOG(Network, "XMLHttpRequest %p send() String '%s'", this, body.utf8().d ata());
729 729
730 if (!initSend(exceptionState)) 730 if (!initSend(exceptionState))
731 return; 731 return;
732 732
733 RefPtr<FormData> httpBody; 733 RefPtr<EncodedFormData> httpBody;
734 734
735 if (!body.isNull() && areMethodAndURLValidForSend()) { 735 if (!body.isNull() && areMethodAndURLValidForSend()) {
736 String contentType = getRequestHeader("Content-Type"); 736 String contentType = getRequestHeader("Content-Type");
737 if (contentType.isEmpty()) { 737 if (contentType.isEmpty()) {
738 setRequestHeaderInternal("Content-Type", "text/plain;charset=UTF-8") ; 738 setRequestHeaderInternal("Content-Type", "text/plain;charset=UTF-8") ;
739 } else { 739 } else {
740 replaceCharsetInMediaType(contentType, "UTF-8"); 740 replaceCharsetInMediaType(contentType, "UTF-8");
741 m_requestHeaders.set("Content-Type", AtomicString(contentType)); 741 m_requestHeaders.set("Content-Type", AtomicString(contentType));
742 } 742 }
743 743
744 httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesFor Unencodables)); 744 httpBody = EncodedFormData::create(UTF8Encoding().encode(body, WTF::Enti tiesForUnencodables));
745 } 745 }
746 746
747 createRequest(httpBody.release(), exceptionState); 747 createRequest(httpBody.release(), exceptionState);
748 } 748 }
749 749
750 void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) 750 void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
751 { 751 {
752 WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().ut f8().data()); 752 WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().ut f8().data());
753 753
754 if (!initSend(exceptionState)) 754 if (!initSend(exceptionState))
755 return; 755 return;
756 756
757 RefPtr<FormData> httpBody; 757 RefPtr<EncodedFormData> httpBody;
758 758
759 if (areMethodAndURLValidForSend()) { 759 if (areMethodAndURLValidForSend()) {
760 if (getRequestHeader("Content-Type").isEmpty()) { 760 if (getRequestHeader("Content-Type").isEmpty()) {
761 const String& blobType = body->type(); 761 const String& blobType = body->type();
762 if (!blobType.isEmpty() && isValidContentType(blobType)) { 762 if (!blobType.isEmpty() && isValidContentType(blobType)) {
763 setRequestHeaderInternal("Content-Type", AtomicString(blobType)) ; 763 setRequestHeaderInternal("Content-Type", AtomicString(blobType)) ;
764 } 764 }
765 } 765 }
766 766
767 // FIXME: add support for uploading bundles. 767 // FIXME: add support for uploading bundles.
768 httpBody = FormData::create(); 768 httpBody = EncodedFormData::create();
769 if (body->hasBackingFile()) { 769 if (body->hasBackingFile()) {
770 File* file = toFile(body); 770 File* file = toFile(body);
771 if (!file->path().isEmpty()) 771 if (!file->path().isEmpty())
772 httpBody->appendFile(file->path()); 772 httpBody->appendFile(file->path());
773 else if (!file->fileSystemURL().isEmpty()) 773 else if (!file->fileSystemURL().isEmpty())
774 httpBody->appendFileSystemURL(file->fileSystemURL()); 774 httpBody->appendFileSystemURL(file->fileSystemURL());
775 else 775 else
776 ASSERT_NOT_REACHED(); 776 ASSERT_NOT_REACHED();
777 } else { 777 } else {
778 httpBody->appendBlob(body->uuid(), body->blobDataHandle()); 778 httpBody->appendBlob(body->uuid(), body->blobDataHandle());
779 } 779 }
780 } 780 }
781 781
782 createRequest(httpBody.release(), exceptionState); 782 createRequest(httpBody.release(), exceptionState);
783 } 783 }
784 784
785 void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) 785 void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState)
786 { 786 {
787 WTF_LOG(Network, "XMLHttpRequest %p send() DOMFormData %p", this, body); 787 WTF_LOG(Network, "XMLHttpRequest %p send() DOMFormData %p", this, body);
788 788
789 if (!initSend(exceptionState)) 789 if (!initSend(exceptionState))
790 return; 790 return;
791 791
792 RefPtr<FormData> httpBody; 792 RefPtr<EncodedFormData> httpBody;
793 793
794 if (areMethodAndURLValidForSend()) { 794 if (areMethodAndURLValidForSend()) {
795 httpBody = body->createMultiPartFormData(); 795 httpBody = body->createMultiPartFormData();
796 796
797 if (getRequestHeader("Content-Type").isEmpty()) { 797 if (getRequestHeader("Content-Type").isEmpty()) {
798 AtomicString contentType = AtomicString("multipart/form-data; bounda ry=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data(); 798 AtomicString contentType = AtomicString("multipart/form-data; bounda ry=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data();
799 setRequestHeaderInternal("Content-Type", contentType); 799 setRequestHeaderInternal("Content-Type", contentType);
800 } 800 }
801 } 801 }
802 802
(...skipping 12 matching lines...) Expand all
815 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBufferView %p", this, body); 815 WTF_LOG(Network, "XMLHttpRequest %p send() ArrayBufferView %p", this, body);
816 816
817 sendBytesData(body->baseAddress(), body->byteLength(), exceptionState); 817 sendBytesData(body->baseAddress(), body->byteLength(), exceptionState);
818 } 818 }
819 819
820 void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta te& exceptionState) 820 void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta te& exceptionState)
821 { 821 {
822 if (!initSend(exceptionState)) 822 if (!initSend(exceptionState))
823 return; 823 return;
824 824
825 RefPtr<FormData> httpBody; 825 RefPtr<EncodedFormData> httpBody;
826 826
827 if (areMethodAndURLValidForSend()) { 827 if (areMethodAndURLValidForSend()) {
828 httpBody = FormData::create(data, length); 828 httpBody = EncodedFormData::create(data, length);
829 } 829 }
830 830
831 createRequest(httpBody.release(), exceptionState); 831 createRequest(httpBody.release(), exceptionState);
832 } 832 }
833 833
834 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) 834 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<EncodedFormData> formD ata, ExceptionState& exceptionState)
835 { 835 {
836 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState); 836 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState);
837 m_exceptionCode = exceptionState.code(); 837 m_exceptionCode = exceptionState.code();
838 } 838 }
839 839
840 void XMLHttpRequest::throwForLoadFailureIfNeeded(ExceptionState& exceptionState, const String& reason) 840 void XMLHttpRequest::throwForLoadFailureIfNeeded(ExceptionState& exceptionState, const String& reason)
841 { 841 {
842 if (m_error && !m_exceptionCode) 842 if (m_error && !m_exceptionCode)
843 m_exceptionCode = NetworkError; 843 m_exceptionCode = NetworkError;
844 844
845 if (!m_exceptionCode) 845 if (!m_exceptionCode)
846 return; 846 return;
847 847
848 String message = "Failed to load '" + m_url.elidedString() + "'"; 848 String message = "Failed to load '" + m_url.elidedString() + "'";
849 if (reason.isNull()) { 849 if (reason.isNull()) {
850 message.append("."); 850 message.append(".");
851 } else { 851 } else {
852 message.append(": "); 852 message.append(": ");
853 message.append(reason); 853 message.append(reason);
854 } 854 }
855 855
856 exceptionState.throwDOMException(m_exceptionCode, message); 856 exceptionState.throwDOMException(m_exceptionCode, message);
857 } 857 }
858 858
859 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState) 859 void XMLHttpRequest::createRequest(PassRefPtr<EncodedFormData> httpBody, Excepti onState& exceptionState)
860 { 860 {
861 // Only GET request is supported for blob URL. 861 // Only GET request is supported for blob URL.
862 if (m_url.protocolIs("blob") && m_method != "GET") { 862 if (m_url.protocolIs("blob") && m_method != "GET") {
863 handleNetworkError(); 863 handleNetworkError();
864 864
865 if (!m_async) { 865 if (!m_async) {
866 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs."); 866 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs.");
867 } 867 }
868 return; 868 return;
869 } 869 }
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 visitor->trace(m_responseDocumentParser); 1697 visitor->trace(m_responseDocumentParser);
1698 visitor->trace(m_progressEventThrottle); 1698 visitor->trace(m_progressEventThrottle);
1699 visitor->trace(m_upload); 1699 visitor->trace(m_upload);
1700 visitor->trace(m_blobLoader); 1700 visitor->trace(m_blobLoader);
1701 XMLHttpRequestEventTarget::trace(visitor); 1701 XMLHttpRequestEventTarget::trace(visitor);
1702 DocumentParserClient::trace(visitor); 1702 DocumentParserClient::trace(visitor);
1703 ActiveDOMObject::trace(visitor); 1703 ActiveDOMObject::trace(visitor);
1704 } 1704 }
1705 1705
1706 } // namespace blink 1706 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.h ('k') | Source/modules/fetch/BodyStreamBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698