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

Unified Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 346033003: [XHR] Move bools to end of class declaration for better padding (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« Source/core/xml/XMLHttpRequest.h ('K') | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/XMLHttpRequest.cpp
diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
index 305774dd0cfad72816dff90796dfd41f87cea206..9e7282ed95602c8bc55a2c0a21f24c20092f987b 100644
--- a/Source/core/xml/XMLHttpRequest.cpp
+++ b/Source/core/xml/XMLHttpRequest.cpp
@@ -167,16 +167,10 @@ PassRefPtrWillBeRawPtr<XMLHttpRequest> XMLHttpRequest::create(ExecutionContext*
XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin)
: ActiveDOMObject(context)
- , m_async(true)
- , m_includeCredentials(false)
+ , m_xhrFlags(0)
, m_timeoutMilliseconds(0)
, m_state(UNSENT)
- , m_createdDocument(false)
, m_downloadedBlobLength(0)
- , m_error(false)
- , m_uploadEventsAllowed(true)
- , m_uploadComplete(false)
- , m_sameOriginRequest(true)
, m_receivedLength(0)
, m_lastSendLineNumber(0)
, m_exceptionCode(0)
@@ -185,6 +179,9 @@ XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri
, m_dropProtectionRunner(this, &XMLHttpRequest::dropProtection)
, m_securityOrigin(securityOrigin)
{
+ // Set default values.
+ m_xhrFlags = IsAsync | IsUploadEventsAllowed | IsSameOriginRequest;
Inactive 2014/06/21 00:40:41 Why isn't this done in the initializer list?
maheshkk 2014/06/23 18:32:16 Done.
+
initializeXMLHttpRequestStaticData();
#ifndef NDEBUG
xmlHttpRequestCounter.increment();
@@ -221,7 +218,7 @@ ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState)
exceptionState.throwDOMException(InvalidStateError, "The value is only accessible if the object's 'responseType' is '' or 'text' (was '" + responseType() + "').");
return ScriptString();
}
- if (m_error || (m_state != LOADING && m_state != DONE))
+ if (getFlag(HasError) || (m_state != LOADING && m_state != DONE))
return ScriptString();
return m_responseText;
}
@@ -230,7 +227,7 @@ ScriptString XMLHttpRequest::responseJSONSource()
{
ASSERT(m_responseTypeCode == ResponseTypeJSON);
- if (m_error || m_state != DONE)
+ if (getFlag(HasError) || m_state != DONE)
return ScriptString();
return m_responseText;
}
@@ -242,10 +239,10 @@ Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState)
return 0;
}
- if (m_error || m_state != DONE)
+ if (getFlag(HasError) || m_state != DONE)
return 0;
- if (!m_createdDocument) {
+ if (!getFlag(IsDocumentCreated)) {
AtomicString mimeType = responseMIMEType();
bool isHTML = equalIgnoringCase(mimeType, "text/html");
@@ -269,7 +266,7 @@ Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState)
if (!m_responseDocument->wellFormed())
m_responseDocument = nullptr;
}
- m_createdDocument = true;
+ setFlag(IsDocumentCreated);
}
return m_responseDocument.get();
@@ -281,7 +278,7 @@ Blob* XMLHttpRequest::responseBlob()
ASSERT(!m_binaryResponseBuilder.get());
// We always return null before DONE.
- if (m_error || m_state != DONE)
+ if (getFlag(HasError) || m_state != DONE)
return 0;
if (!m_responseBlob) {
@@ -307,7 +304,7 @@ ArrayBuffer* XMLHttpRequest::responseArrayBuffer()
{
ASSERT(m_responseTypeCode == ResponseTypeArrayBuffer);
- if (m_error || m_state != DONE)
+ if (getFlag(HasError) || m_state != DONE)
return 0;
if (!m_responseArrayBuffer.get()) {
@@ -332,7 +329,7 @@ Stream* XMLHttpRequest::responseStream()
{
ASSERT(m_responseTypeCode == ResponseTypeStream);
- if (m_error || (m_state != LOADING && m_state != DONE))
+ if (getFlag(HasError) || (m_state != LOADING && m_state != DONE))
return 0;
return m_responseStream.get();
@@ -342,7 +339,7 @@ void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionState& exception
{
// FIXME: Need to trigger or update the timeout Timer here, if needed. http://webkit.org/b/98156
// XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while fetching is in progress. If that occurs it will still be measured relative to the start of fetching."
- if (executionContext()->isDocument() && !m_async) {
+ if (executionContext()->isDocument() && !getFlag(IsAsync)) {
exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document.");
return;
}
@@ -358,7 +355,7 @@ void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
// Newer functionality is not available to synchronous requests in window contexts, as a spec-mandated
// attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
- if (!m_async && executionContext()->isDocument()) {
+ if (!getFlag(IsAsync) && executionContext()->isDocument()) {
exceptionState.throwDOMException(InvalidAccessError, "The response type can only be changed for asynchronous HTTP requests made from a document.");
return;
}
@@ -422,7 +419,7 @@ void XMLHttpRequest::trackProgress(int length)
{
m_receivedLength += length;
- if (m_async)
+ if (getFlag(IsAsync))
dispatchProgressEventFromSnapshot(EventTypeNames::progress);
if (m_state != LOADING) {
@@ -452,12 +449,12 @@ void XMLHttpRequest::dispatchReadyStateChangeEvent()
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchXHRReadyStateChangeEvent(executionContext(), this);
- if (m_async || (m_state <= OPENED || m_state == DONE)) {
+ if (getFlag(IsAsync) || (m_state <= OPENED || m_state == DONE)) {
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "XHRReadyStateChange", "data", InspectorXhrReadyStateChangeEvent::data(executionContext(), this));
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
ProgressEventAction flushAction = DoNotFlushProgressEvent;
if (m_state == DONE) {
- if (m_error)
+ if (getFlag(HasError))
flushAction = FlushDeferredProgressEvent;
else
flushAction = FlushProgressEvent;
@@ -467,7 +464,7 @@ void XMLHttpRequest::dispatchReadyStateChangeEvent()
}
InspectorInstrumentation::didDispatchXHRReadyStateChangeEvent(cookie);
- if (m_state == DONE && !m_error) {
+ if (m_state == DONE && !getFlag(HasError)) {
{
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "XHRLoad", "data", InspectorXhrLoadEvent::data(executionContext(), this));
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
@@ -489,10 +486,10 @@ void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta
// FIXME: According to XMLHttpRequest Level 2 we should throw InvalidAccessError exception here.
// However for time being only print warning message to warn web developers.
- if (!m_async)
+ if (!getFlag(IsAsync))
UseCounter::countDeprecation(executionContext(), UseCounter::SyncXHRWithCredentials);
- m_includeCredentials = value;
+ setFlag(value, IsWithCredentials);
}
bool XMLHttpRequest::isAllowedHTTPMethod(const String& method)
@@ -545,8 +542,8 @@ void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn
State previousState = m_state;
m_state = UNSENT;
- m_error = false;
- m_uploadComplete = false;
+ clearFlag(HasError);
+ clearFlag(IsUploadComplete);
// clear stuff from possible previous load
clearResponse();
@@ -594,7 +591,7 @@ void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn
m_url = url;
- m_async = async;
+ setFlag(async, IsAsync);
ASSERT(!m_loader);
@@ -633,7 +630,7 @@ bool XMLHttpRequest::initSend(ExceptionState& exceptionState)
return false;
}
- m_error = false;
+ clearFlag(HasError);
return true;
}
@@ -818,7 +815,7 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
// permit cross origin requests should look exactly like POSTing to an URL that does not respond at all.
// Also, only async requests support upload progress events.
bool uploadEvents = false;
- if (m_async) {
+ if (getFlag(IsAsync)) {
dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
if (httpBody && m_upload) {
uploadEvents = m_upload->hasEventListeners();
@@ -826,11 +823,12 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
}
}
- m_sameOriginRequest = securityOrigin()->canRequest(m_url);
+ setFlag(securityOrigin()->canRequest(m_url), IsSameOriginRequest);
// We also remember whether upload events should be allowed for this request in case the upload listeners are
// added after the request is started.
- m_uploadEventsAllowed = m_sameOriginRequest || uploadEvents || !isSimpleCrossOriginAccessRequest(m_method, m_requestHeaders);
+ setFlag(getFlag(IsSameOriginRequest) || uploadEvents || !isSimpleCrossOriginAccessRequest(m_method, m_requestHeaders),
+ IsUploadEventsAllowed);
ASSERT(executionContext());
ExecutionContext& executionContext = *this->executionContext();
@@ -839,7 +837,7 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
request.setHTTPMethod(m_method);
request.setTargetType(ResourceRequest::TargetIsXHR);
- InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials);
+ InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, getFlag(IsAsync), httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, getFlag(IsWithCredentials));
if (httpBody) {
ASSERT(m_method != "GET");
@@ -858,8 +856,8 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
options.timeoutMilliseconds = m_timeoutMilliseconds;
ResourceLoaderOptions resourceLoaderOptions;
- resourceLoaderOptions.allowCredentials = (m_sameOriginRequest || m_includeCredentials) ? AllowStoredCredentials : DoNotAllowStoredCredentials;
- resourceLoaderOptions.credentialsRequested = m_includeCredentials ? ClientRequestedCredentials : ClientDidNotRequestCredentials;
+ resourceLoaderOptions.allowCredentials = (getFlag(IsSameOriginRequest) || getFlag(IsWithCredentials)) ? AllowStoredCredentials : DoNotAllowStoredCredentials;
+ resourceLoaderOptions.credentialsRequested = getFlag(IsWithCredentials) ? ClientRequestedCredentials : ClientDidNotRequestCredentials;
resourceLoaderOptions.securityOrigin = securityOrigin();
// TODO(tsepez): Specify TreatAsActiveContent per http://crbug.com/305303.
resourceLoaderOptions.mixedContentBlockingTreatment = TreatAsPassiveContent;
@@ -872,9 +870,9 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
}
m_exceptionCode = 0;
- m_error = false;
+ clearFlag(HasError);
- if (m_async) {
+ if (getFlag(IsAsync)) {
if (m_upload)
request.setReportUploadProgress(true);
@@ -896,7 +894,7 @@ void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState
ThreadableLoader::loadResourceSynchronously(executionContext, request, *this, options, resourceLoaderOptions);
}
- if (!m_exceptionCode && m_error)
+ if (!m_exceptionCode && getFlag(HasError))
m_exceptionCode = NetworkError;
if (m_exceptionCode)
exceptionState.throwDOMException(m_exceptionCode, "Failed to load '" + m_url.elidedString() + "'.");
@@ -939,7 +937,7 @@ void XMLHttpRequest::clearVariablesForLoading()
bool XMLHttpRequest::internalAbort(DropProtection async)
{
- m_error = true;
+ setFlag(HasError);
clearVariablesForLoading();
@@ -972,7 +970,7 @@ bool XMLHttpRequest::internalAbort(DropProtection async)
// clearing the error flag, but didn't send(), make sure the error
// flag is still set.
if (!newLoadStarted)
- m_error = true;
+ setFlag(HasError);
if (async == DropProtectionAsync)
dropProtectionSoon();
@@ -992,7 +990,7 @@ void XMLHttpRequest::clearResponse()
m_responseText.clear();
- m_createdDocument = false;
+ clearFlag(IsDocumentCreated);
m_responseDocument = nullptr;
m_responseBlob = nullptr;
@@ -1016,7 +1014,7 @@ void XMLHttpRequest::handleDidFailGeneric()
clearResponse();
clearRequest();
- m_error = true;
+ setFlag(HasError);
}
void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long receivedLength, long long expectedLength)
@@ -1064,21 +1062,21 @@ void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
// The request error steps for event 'type' and exception 'exceptionCode'.
- if (!m_async && exceptionCode) {
+ if (!getFlag(IsAsync) && exceptionCode) {
m_state = DONE;
m_exceptionCode = exceptionCode;
return;
}
- // With m_error set, the state change steps are minimal: any pending
+ // With HasError set, the state change steps are minimal: any pending
// progress event is flushed + a readystatechange is dispatched.
// No new progress events dispatched; as required, that happens at
// the end here.
- ASSERT(m_error);
+ ASSERT(getFlag(HasError));
changeState(DONE);
- if (!m_uploadComplete) {
- m_uploadComplete = true;
- if (m_upload && m_uploadEventsAllowed)
+ if (!getFlag(IsUploadComplete)) {
+ setFlag(IsUploadComplete);
+ if (m_upload && getFlag(IsUploadEventsAllowed))
m_upload->handleRequestError(type);
}
@@ -1142,7 +1140,7 @@ const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) c
String XMLHttpRequest::getAllResponseHeaders() const
{
- if (m_state < HEADERS_RECEIVED || m_error)
+ if (m_state < HEADERS_RECEIVED || getFlag(HasError))
return "";
StringBuilder stringBuilder;
@@ -1160,7 +1158,7 @@ String XMLHttpRequest::getAllResponseHeaders() const
if (isSetCookieHeader(it->key) && !securityOrigin()->canLoadLocalResources())
continue;
- if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(it->key) && !accessControlExposeHeaderSet.contains(it->key))
+ if (!getFlag(IsSameOriginRequest) && !isOnAccessControlResponseHeaderWhitelist(it->key) && !accessControlExposeHeaderSet.contains(it->key))
continue;
stringBuilder.append(it->key);
@@ -1176,7 +1174,7 @@ String XMLHttpRequest::getAllResponseHeaders() const
const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name) const
{
- if (m_state < HEADERS_RECEIVED || m_error)
+ if (m_state < HEADERS_RECEIVED || getFlag(HasError))
return nullAtom;
// See comment in getAllResponseHeaders above.
@@ -1188,7 +1186,7 @@ const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name)
HTTPHeaderSet accessControlExposeHeaderSet;
parseAccessControlExposeHeadersAllowList(m_response.httpHeaderField("Access-Control-Expose-Headers"), accessControlExposeHeaderSet);
- if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(name) && !accessControlExposeHeaderSet.contains(name)) {
+ if (!getFlag(IsSameOriginRequest) && !isOnAccessControlResponseHeaderWhitelist(name) && !accessControlExposeHeaderSet.contains(name)) {
logConsoleError(executionContext(), "Refused to get unsafe header \"" + name + "\"");
return nullAtom;
}
@@ -1217,7 +1215,7 @@ bool XMLHttpRequest::responseIsXML() const
int XMLHttpRequest::status() const
{
- if (m_state == UNSENT || m_state == OPENED || m_error)
+ if (m_state == UNSENT || m_state == OPENED || getFlag(HasError))
return 0;
if (m_response.httpStatusCode())
@@ -1228,7 +1226,7 @@ int XMLHttpRequest::status() const
String XMLHttpRequest::statusText() const
{
- if (m_state == UNSENT || m_state == OPENED || m_error)
+ if (m_state == UNSENT || m_state == OPENED || getFlag(HasError))
return String();
if (!m_response.httpStatusText().isNull())
@@ -1242,7 +1240,7 @@ void XMLHttpRequest::didFail(const ResourceError& error)
WTF_LOG(Network, "XMLHttpRequest %p didFail()", this);
// If we are already in an error state, for instance we called abort(), bail out early.
- if (m_error)
+ if (getFlag(HasError))
return;
if (error.isCancellation()) {
@@ -1273,7 +1271,7 @@ void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
{
WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier);
- if (m_error)
+ if (getFlag(HasError))
return;
if (m_state < HEADERS_RECEIVED)
@@ -1307,12 +1305,12 @@ void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
if (!m_upload)
return;
- if (m_uploadEventsAllowed)
+ if (getFlag(IsUploadEventsAllowed))
m_upload->dispatchProgressEvent(bytesSent, totalBytesToBeSent);
- if (bytesSent == totalBytesToBeSent && !m_uploadComplete) {
- m_uploadComplete = true;
- if (m_uploadEventsAllowed)
+ if (bytesSent == totalBytesToBeSent && !getFlag(IsUploadComplete)) {
+ setFlag(IsUploadComplete);
+ if (getFlag(IsUploadEventsAllowed))
m_upload->dispatchEventAndLoadEnd(EventTypeNames::load, true, bytesSent, totalBytesToBeSent);
}
}
@@ -1335,7 +1333,7 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
{
ASSERT(m_responseTypeCode != ResponseTypeBlob);
- if (m_error)
+ if (getFlag(HasError))
return;
if (m_state < HEADERS_RECEIVED)
@@ -1381,7 +1379,7 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
m_responseStream->addData(data, len);
}
- if (m_error)
+ if (getFlag(HasError))
return;
trackProgress(len);
@@ -1391,7 +1389,7 @@ void XMLHttpRequest::didDownloadData(int dataLength)
{
ASSERT(m_responseTypeCode == ResponseTypeBlob);
- if (m_error)
+ if (getFlag(HasError))
return;
if (m_state < HEADERS_RECEIVED)
@@ -1401,8 +1399,8 @@ void XMLHttpRequest::didDownloadData(int dataLength)
return;
// readystatechange event handler may do something to put this XHR in error
- // state. We need to check m_error again here.
- if (m_error)
+ // state. We need to check HasError again here.
+ if (getFlag(HasError))
return;
m_downloadedBlobLength += dataLength;
« Source/core/xml/XMLHttpRequest.h ('K') | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698