Commit 18d41ecd authored by tyoshino@chromium.org's avatar tyoshino@chromium.org

Remove m_requestEntityBody from XMLHttpRequest

We don't have to hold the FormData instance to be used by createRequest()
as a class member. It's instantiated right before createRequest() call.
We can just allocate it on stack.

BUG=none
R=ricea,tkent

Review URL: https://codereview.chromium.org/314283005

git-svn-id: svn://svn.chromium.org/blink/trunk@175776 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 56974e50
...@@ -657,6 +657,8 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) ...@@ -657,6 +657,8 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
if (!initSend(exceptionState)) if (!initSend(exceptionState))
return; return;
RefPtr<FormData> httpBody;
if (areMethodAndURLValidForSend()) { if (areMethodAndURLValidForSend()) {
if (getRequestHeader("Content-Type").isEmpty()) { if (getRequestHeader("Content-Type").isEmpty()) {
// FIXME: this should include the charset used for encoding. // FIXME: this should include the charset used for encoding.
...@@ -668,12 +670,12 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) ...@@ -668,12 +670,12 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
String body = createMarkup(document); String body = createMarkup(document);
// FIXME: This should use value of document.inputEncoding to determine the encoding to use. // FIXME: This should use value of document.inputEncoding to determine the encoding to use.
m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables)); httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
if (m_upload) if (m_upload)
m_requestEntityBody->setAlwaysStream(true); httpBody->setAlwaysStream(true);
} }
createRequest(exceptionState); createRequest(httpBody.release(), exceptionState);
} }
void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
...@@ -683,6 +685,8 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) ...@@ -683,6 +685,8 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
if (!initSend(exceptionState)) if (!initSend(exceptionState))
return; return;
RefPtr<FormData> httpBody;
if (!body.isNull() && areMethodAndURLValidForSend()) { if (!body.isNull() && areMethodAndURLValidForSend()) {
String contentType = getRequestHeader("Content-Type"); String contentType = getRequestHeader("Content-Type");
if (contentType.isEmpty()) { if (contentType.isEmpty()) {
...@@ -692,12 +696,12 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) ...@@ -692,12 +696,12 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
m_requestHeaders.set("Content-Type", AtomicString(contentType)); m_requestHeaders.set("Content-Type", AtomicString(contentType));
} }
m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables)); httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
if (m_upload) if (m_upload)
m_requestEntityBody->setAlwaysStream(true); httpBody->setAlwaysStream(true);
} }
createRequest(exceptionState); createRequest(httpBody.release(), exceptionState);
} }
void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
...@@ -707,6 +711,8 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) ...@@ -707,6 +711,8 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
if (!initSend(exceptionState)) if (!initSend(exceptionState))
return; return;
RefPtr<FormData> httpBody;
if (areMethodAndURLValidForSend()) { if (areMethodAndURLValidForSend()) {
if (getRequestHeader("Content-Type").isEmpty()) { if (getRequestHeader("Content-Type").isEmpty()) {
const String& blobType = body->type(); const String& blobType = body->type();
...@@ -719,21 +725,21 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) ...@@ -719,21 +725,21 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
} }
// FIXME: add support for uploading bundles. // FIXME: add support for uploading bundles.
m_requestEntityBody = FormData::create(); httpBody = FormData::create();
if (body->hasBackingFile()) { if (body->hasBackingFile()) {
File* file = toFile(body); File* file = toFile(body);
if (!file->path().isEmpty()) if (!file->path().isEmpty())
m_requestEntityBody->appendFile(file->path()); httpBody->appendFile(file->path());
else if (!file->fileSystemURL().isEmpty()) else if (!file->fileSystemURL().isEmpty())
m_requestEntityBody->appendFileSystemURL(file->fileSystemURL()); httpBody->appendFileSystemURL(file->fileSystemURL());
else else
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} else { } else {
m_requestEntityBody->appendBlob(body->uuid(), body->blobDataHandle()); httpBody->appendBlob(body->uuid(), body->blobDataHandle());
} }
} }
createRequest(exceptionState); createRequest(httpBody.release(), exceptionState);
} }
void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState)
...@@ -743,16 +749,18 @@ void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) ...@@ -743,16 +749,18 @@ void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState)
if (!initSend(exceptionState)) if (!initSend(exceptionState))
return; return;
RefPtr<FormData> httpBody;
if (areMethodAndURLValidForSend()) { if (areMethodAndURLValidForSend()) {
m_requestEntityBody = body->createMultiPartFormData(body->encoding()); httpBody = body->createMultiPartFormData(body->encoding());
if (getRequestHeader("Content-Type").isEmpty()) { if (getRequestHeader("Content-Type").isEmpty()) {
AtomicString contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + m_requestEntityBody->boundary().data(); AtomicString contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data();
setRequestHeaderInternal("Content-Type", contentType); setRequestHeaderInternal("Content-Type", contentType);
} }
} }
createRequest(exceptionState); createRequest(httpBody.release(), exceptionState);
} }
void XMLHttpRequest::send(ArrayBuffer* body, ExceptionState& exceptionState) void XMLHttpRequest::send(ArrayBuffer* body, ExceptionState& exceptionState)
...@@ -781,23 +789,24 @@ void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta ...@@ -781,23 +789,24 @@ void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta
if (!initSend(exceptionState)) if (!initSend(exceptionState))
return; return;
RefPtr<FormData> httpBody;
if (areMethodAndURLValidForSend()) { if (areMethodAndURLValidForSend()) {
m_requestEntityBody = FormData::create(data, length); httpBody = FormData::create(data, length);
if (m_upload) if (m_upload)
m_requestEntityBody->setAlwaysStream(true); httpBody->setAlwaysStream(true);
} }
createRequest(exceptionState); createRequest(httpBody.release(), exceptionState);
} }
void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, ExceptionState& exceptionState) void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, ExceptionState& exceptionState)
{ {
m_requestEntityBody = formData ? formData->deepCopy() : nullptr; createRequest(formData ? formData->deepCopy() : nullptr, exceptionState);
createRequest(exceptionState);
m_exceptionCode = exceptionState.code(); m_exceptionCode = exceptionState.code();
} }
void XMLHttpRequest::createRequest(ExceptionState& exceptionState) void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState& exceptionState)
{ {
// Only GET request is supported for blob URL. // Only GET request is supported for blob URL.
if (m_url.protocolIs("blob") && m_method != "GET") { if (m_url.protocolIs("blob") && m_method != "GET") {
...@@ -811,7 +820,7 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState) ...@@ -811,7 +820,7 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState)
bool uploadEvents = false; bool uploadEvents = false;
if (m_async) { if (m_async) {
dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
if (m_requestEntityBody && m_upload) { if (httpBody && m_upload) {
uploadEvents = m_upload->hasEventListeners(); uploadEvents = m_upload->hasEventListeners();
m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::loadstart)); m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::loadstart));
} }
...@@ -830,12 +839,12 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState) ...@@ -830,12 +839,12 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState)
request.setHTTPMethod(m_method); request.setHTTPMethod(m_method);
request.setTargetType(ResourceRequest::TargetIsXHR); request.setTargetType(ResourceRequest::TargetIsXHR);
InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials); InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials);
if (m_requestEntityBody) { if (httpBody) {
ASSERT(m_method != "GET"); ASSERT(m_method != "GET");
ASSERT(m_method != "HEAD"); ASSERT(m_method != "HEAD");
request.setHTTPBody(m_requestEntityBody.release()); request.setHTTPBody(httpBody);
} }
if (m_requestHeaders.size() > 0) if (m_requestHeaders.size() > 0)
...@@ -998,7 +1007,6 @@ void XMLHttpRequest::clearResponse() ...@@ -998,7 +1007,6 @@ void XMLHttpRequest::clearResponse()
void XMLHttpRequest::clearRequest() void XMLHttpRequest::clearRequest()
{ {
m_requestHeaders.clear(); m_requestHeaders.clear();
m_requestEntityBody = nullptr;
} }
void XMLHttpRequest::handleDidFailGeneric() void XMLHttpRequest::handleDidFailGeneric()
......
...@@ -191,7 +191,7 @@ private: ...@@ -191,7 +191,7 @@ private:
void clearResponse(); void clearResponse();
void clearRequest(); void clearRequest();
void createRequest(ExceptionState&); void createRequest(PassRefPtr<FormData>, ExceptionState&);
// Dispatches a response ProgressEvent. // Dispatches a response ProgressEvent.
void dispatchProgressEvent(const AtomicString&, long long, long long); void dispatchProgressEvent(const AtomicString&, long long, long long);
...@@ -215,7 +215,6 @@ private: ...@@ -215,7 +215,6 @@ private:
KURL m_url; KURL m_url;
AtomicString m_method; AtomicString m_method;
HTTPHeaderMap m_requestHeaders; HTTPHeaderMap m_requestHeaders;
RefPtr<FormData> m_requestEntityBody;
AtomicString m_mimeTypeOverride; AtomicString m_mimeTypeOverride;
bool m_async; bool m_async;
bool m_includeCredentials; bool m_includeCredentials;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment