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 |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Lesser General Public License for more details. | 16 * Lesser General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Lesser General Public | 18 * You should have received a copy of the GNU Lesser General Public |
19 * License along with this library; if not, write to the Free Software | 19 * License along with this library; if not, write to the Free Software |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301 USA | 21 * Boston, MA 02110-1301 USA |
22 */ | 22 */ |
23 | 23 |
24 #include "core/xmlhttprequest/XMLHttpRequest.h" | 24 #include "core/xmlhttprequest/XMLHttpRequest.h" |
25 | 25 |
26 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringO rFormData.h" | 26 #include <memory> |
27 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringO rFormDataOrURLSearchParams.h" | |
27 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrUSVString.h" | 28 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrUSVString.h" |
28 #include "bindings/core/v8/DOMWrapperWorld.h" | 29 #include "bindings/core/v8/DOMWrapperWorld.h" |
29 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
30 #include "bindings/core/v8/ScriptState.h" | 31 #include "bindings/core/v8/ScriptState.h" |
31 #include "core/dom/DOMArrayBuffer.h" | 32 #include "core/dom/DOMArrayBuffer.h" |
32 #include "core/dom/DOMArrayBufferView.h" | 33 #include "core/dom/DOMArrayBufferView.h" |
33 #include "core/dom/DOMException.h" | 34 #include "core/dom/DOMException.h" |
34 #include "core/dom/DOMImplementation.h" | 35 #include "core/dom/DOMImplementation.h" |
35 #include "core/dom/DOMTypedArray.h" | 36 #include "core/dom/DOMTypedArray.h" |
36 #include "core/dom/DocumentInit.h" | 37 #include "core/dom/DocumentInit.h" |
37 #include "core/dom/DocumentParser.h" | 38 #include "core/dom/DocumentParser.h" |
38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
39 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
41 #include "core/dom/URLSearchParams.h" | |
40 #include "core/dom/XMLDocument.h" | 42 #include "core/dom/XMLDocument.h" |
41 #include "core/editing/serializers/Serialization.h" | 43 #include "core/editing/serializers/Serialization.h" |
42 #include "core/events/Event.h" | 44 #include "core/events/Event.h" |
43 #include "core/events/ProgressEvent.h" | 45 #include "core/events/ProgressEvent.h" |
44 #include "core/fileapi/Blob.h" | 46 #include "core/fileapi/Blob.h" |
45 #include "core/fileapi/File.h" | 47 #include "core/fileapi/File.h" |
46 #include "core/fileapi/FileReaderLoader.h" | 48 #include "core/fileapi/FileReaderLoader.h" |
47 #include "core/fileapi/FileReaderLoaderClient.h" | 49 #include "core/fileapi/FileReaderLoaderClient.h" |
48 #include "core/frame/Deprecation.h" | 50 #include "core/frame/Deprecation.h" |
49 #include "core/frame/Settings.h" | 51 #include "core/frame/Settings.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
74 #include "platform/network/ResourceError.h" | 76 #include "platform/network/ResourceError.h" |
75 #include "platform/network/ResourceRequest.h" | 77 #include "platform/network/ResourceRequest.h" |
76 #include "platform/weborigin/SecurityOrigin.h" | 78 #include "platform/weborigin/SecurityOrigin.h" |
77 #include "platform/weborigin/SecurityPolicy.h" | 79 #include "platform/weborigin/SecurityPolicy.h" |
78 #include "platform/weborigin/Suborigin.h" | 80 #include "platform/weborigin/Suborigin.h" |
79 #include "public/platform/WebURLRequest.h" | 81 #include "public/platform/WebURLRequest.h" |
80 #include "wtf/Assertions.h" | 82 #include "wtf/Assertions.h" |
81 #include "wtf/AutoReset.h" | 83 #include "wtf/AutoReset.h" |
82 #include "wtf/StdLibExtras.h" | 84 #include "wtf/StdLibExtras.h" |
83 #include "wtf/text/CString.h" | 85 #include "wtf/text/CString.h" |
84 #include <memory> | |
85 | 86 |
86 namespace blink { | 87 namespace blink { |
87 | 88 |
88 namespace { | 89 namespace { |
89 | 90 |
90 // This class protects the wrapper of the associated XMLHttpRequest object | 91 // This class protects the wrapper of the associated XMLHttpRequest object |
91 // via hasPendingActivity method which returns true if | 92 // via hasPendingActivity method which returns true if |
92 // m_eventDispatchRecursionLevel is positive. | 93 // m_eventDispatchRecursionLevel is positive. |
93 class ScopedEventDispatchProtect final { | 94 class ScopedEventDispatchProtect final { |
94 public: | 95 public: |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 UseCounter::count(getExecutionContext(), | 698 UseCounter::count(getExecutionContext(), |
698 UseCounter::During_Microtask_SyncXHR); | 699 UseCounter::During_Microtask_SyncXHR); |
699 } | 700 } |
700 } | 701 } |
701 | 702 |
702 m_error = false; | 703 m_error = false; |
703 return true; | 704 return true; |
704 } | 705 } |
705 | 706 |
706 void XMLHttpRequest::send( | 707 void XMLHttpRequest::send( |
707 const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringOrFormData& body, | 708 const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringOrFormDataOrURLSea rchParams& |
709 body, | |
708 ExceptionState& exceptionState) { | 710 ExceptionState& exceptionState) { |
709 InspectorInstrumentation::willSendXMLHttpOrFetchNetworkRequest( | 711 InspectorInstrumentation::willSendXMLHttpOrFetchNetworkRequest( |
710 getExecutionContext(), url()); | 712 getExecutionContext(), url()); |
711 | 713 |
712 if (body.isNull()) { | 714 if (body.isNull()) { |
713 send(String(), exceptionState); | 715 send(String(), exceptionState); |
714 return; | 716 return; |
715 } | 717 } |
716 | 718 |
717 if (body.isArrayBuffer()) { | 719 if (body.isArrayBuffer()) { |
(...skipping 14 matching lines...) Expand all Loading... | |
732 if (body.isDocument()) { | 734 if (body.isDocument()) { |
733 send(body.getAsDocument(), exceptionState); | 735 send(body.getAsDocument(), exceptionState); |
734 return; | 736 return; |
735 } | 737 } |
736 | 738 |
737 if (body.isFormData()) { | 739 if (body.isFormData()) { |
738 send(body.getAsFormData(), exceptionState); | 740 send(body.getAsFormData(), exceptionState); |
739 return; | 741 return; |
740 } | 742 } |
741 | 743 |
744 if (body.isURLSearchParams()) { | |
745 send(body.getAsURLSearchParams(), exceptionState); | |
746 return; | |
747 } | |
748 | |
742 DCHECK(body.isString()); | 749 DCHECK(body.isString()); |
743 send(body.getAsString(), exceptionState); | 750 send(body.getAsString(), exceptionState); |
744 } | 751 } |
745 | 752 |
746 bool XMLHttpRequest::areMethodAndURLValidForSend() { | 753 bool XMLHttpRequest::areMethodAndURLValidForSend() { |
747 return m_method != HTTPNames::GET && m_method != HTTPNames::HEAD && | 754 return m_method != HTTPNames::GET && m_method != HTTPNames::HEAD && |
748 m_url.protocolIsInHTTPFamily(); | 755 m_url.protocolIsInHTTPFamily(); |
749 } | 756 } |
750 | 757 |
751 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) { | 758 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 AtomicString contentType = | 858 AtomicString contentType = |
852 AtomicString("multipart/form-data; boundary=") + | 859 AtomicString("multipart/form-data; boundary=") + |
853 httpBody->boundary().data(); | 860 httpBody->boundary().data(); |
854 setRequestHeaderInternal(HTTPNames::Content_Type, contentType); | 861 setRequestHeaderInternal(HTTPNames::Content_Type, contentType); |
855 } | 862 } |
856 } | 863 } |
857 | 864 |
858 createRequest(std::move(httpBody), exceptionState); | 865 createRequest(std::move(httpBody), exceptionState); |
859 } | 866 } |
860 | 867 |
868 void XMLHttpRequest::send(URLSearchParams* body, | |
869 ExceptionState& exceptionState) { | |
870 NETWORK_DVLOG(1) << this << " send() URLSearchParams " << body; | |
871 | |
872 if (!initSend(exceptionState)) | |
873 return; | |
874 | |
875 RefPtr<EncodedFormData> httpBody; | |
876 | |
877 if (areMethodAndURLValidForSend()) { | |
878 httpBody = body->toEncodedFormData(); | |
879 | |
880 String contentType = getRequestHeader(HTTPNames::Content_Type); | |
881 if (contentType.isEmpty()) { | |
882 setRequestHeaderInternal( | |
883 HTTPNames::Content_Type, | |
884 "application/x-www-form-urlencoded;charset=UTF-8"); | |
885 } else { | |
886 replaceCharsetInMediaType(contentType, "UTF-8"); | |
yhirano
2017/03/01 02:21:00
Can you tell me where this is from?
sof
2017/03/01 07:07:52
Last para of step 4 in https://xhr.spec.whatwg.org
tyoshino (SeeGerritForStatus)
2017/03/01 09:04:58
Can we factor this out? XMLHttpRequest::send(const
sof
2017/03/01 09:49:14
Oh yes, good suggestion; done + added a test.
| |
887 m_requestHeaders.set(HTTPNames::Content_Type, AtomicString(contentType)); | |
888 } | |
889 } | |
890 | |
891 createRequest(std::move(httpBody), exceptionState); | |
892 } | |
893 | |
861 void XMLHttpRequest::send(DOMArrayBuffer* body, | 894 void XMLHttpRequest::send(DOMArrayBuffer* body, |
862 ExceptionState& exceptionState) { | 895 ExceptionState& exceptionState) { |
863 NETWORK_DVLOG(1) << this << " send() ArrayBuffer " << body; | 896 NETWORK_DVLOG(1) << this << " send() ArrayBuffer " << body; |
864 | 897 |
865 sendBytesData(body->data(), body->byteLength(), exceptionState); | 898 sendBytesData(body->data(), body->byteLength(), exceptionState); |
866 } | 899 } |
867 | 900 |
868 void XMLHttpRequest::send(DOMArrayBufferView* body, | 901 void XMLHttpRequest::send(DOMArrayBufferView* body, |
869 ExceptionState& exceptionState) { | 902 ExceptionState& exceptionState) { |
870 NETWORK_DVLOG(1) << this << " send() ArrayBufferView " << body; | 903 NETWORK_DVLOG(1) << this << " send() ArrayBufferView " << body; |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1859 visitor->traceWrappers(m_responseDocument); | 1892 visitor->traceWrappers(m_responseDocument); |
1860 visitor->traceWrappers(m_responseArrayBuffer); | 1893 visitor->traceWrappers(m_responseArrayBuffer); |
1861 XMLHttpRequestEventTarget::traceWrappers(visitor); | 1894 XMLHttpRequestEventTarget::traceWrappers(visitor); |
1862 } | 1895 } |
1863 | 1896 |
1864 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { | 1897 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { |
1865 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); | 1898 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); |
1866 } | 1899 } |
1867 | 1900 |
1868 } // namespace blink | 1901 } // namespace blink |
OLD | NEW |