Bug 1306235 - XHR should set lengthComputable only if total value is set, r==smaug

This commit is contained in:
Andrea Marchesini 2016-10-06 16:13:08 +02:00
Родитель d5f9a8fa71
Коммит 9d453d6ef0
2 изменённых файлов: 17 добавлений и 12 удалений

Просмотреть файл

@ -179,7 +179,7 @@ XMLHttpRequestMainThread::XMLHttpRequestMainThread()
mProgressTimerIsActive(false),
mIsHtml(false),
mWarnAboutSyncHtml(false),
mLoadTotal(0),
mLoadTotal(-1),
mIsSystem(false),
mIsAnon(false),
mFirstStartRequestSeen(false),
@ -1048,9 +1048,9 @@ XMLHttpRequestMainThread::CloseRequestWithError(const ProgressEventType aType)
if (!mFlagSyncLooping) {
if (mUpload && !mUploadComplete) {
mUploadComplete = true;
DispatchProgressEvent(mUpload, aType, 0, 0);
DispatchProgressEvent(mUpload, aType, 0, -1);
}
DispatchProgressEvent(this, aType, 0, 0);
DispatchProgressEvent(this, aType, 0, -1);
}
}
@ -1324,7 +1324,7 @@ XMLHttpRequestMainThread::DispatchProgressEvent(DOMEventTargetHelper* aTarget,
return;
}
aLoaded = 0;
aTotal = 0;
aTotal = -1;
}
if (aType == ProgressEventType::progress) {
@ -1334,7 +1334,7 @@ XMLHttpRequestMainThread::DispatchProgressEvent(DOMEventTargetHelper* aTarget,
ProgressEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mLengthComputable = aTotal != 0; // XHR spec step 6.1
init.mLengthComputable = aTotal != -1; // XHR spec step 6.1
init.mLoaded = aLoaded;
init.mTotal = (aTotal == -1) ? 0 : aTotal;
@ -2207,7 +2207,11 @@ XMLHttpRequestMainThread::ChangeStateToDone()
mTimeoutTimer->Cancel();
}
mLoadTotal = mLoadTransferred;
if (mLoadTransferred) {
mLoadTotal = mLoadTransferred;
} else {
mLoadTotal = -1;
}
// Per spec, fire the last download progress event, if any,
// before readystatechange=4/done. (Note that 0-sized responses
@ -2225,7 +2229,7 @@ XMLHttpRequestMainThread::ChangeStateToDone()
// Per spec, if we failed in the upload phase, fire a final error
// and loadend events for the upload after readystatechange=4/done.
if (!mFlagSynchronous && mUpload && !mUploadComplete) {
DispatchProgressEvent(mUpload, ProgressEventType::error, 0, 0);
DispatchProgressEvent(mUpload, ProgressEventType::error, 0, -1);
}
// Per spec, fire download's load/error and loadend events after
@ -2234,7 +2238,7 @@ XMLHttpRequestMainThread::ChangeStateToDone()
mErrorLoad ? ProgressEventType::error :
ProgressEventType::load,
mErrorLoad ? 0 : mLoadTransferred,
mErrorLoad ? 0 : mLoadTotal);
mErrorLoad ? -1 : mLoadTotal);
if (mErrorLoad) {
// By nulling out channel here we make it so that Send() can test
@ -2827,7 +2831,7 @@ XMLHttpRequestMainThread::SendInternal(const RequestBodyBase* aBody)
// By default we don't have any upload, so mark upload complete.
mUploadComplete = true;
mErrorLoad = false;
mLoadTotal = 0;
mLoadTotal = -1;
nsCOMPtr<nsIInputStream> uploadStream;
nsAutoCString uploadContentType;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
@ -2964,7 +2968,7 @@ XMLHttpRequestMainThread::SendInternal(const RequestBodyBase* aBody)
StartProgressEventTimer();
}
// Dispatch loadstart events
DispatchProgressEvent(this, ProgressEventType::loadstart, 0, 0);
DispatchProgressEvent(this, ProgressEventType::loadstart, 0, -1);
if (mUpload && !mUploadComplete) {
DispatchProgressEvent(mUpload, ProgressEventType::loadstart,
0, mUploadTotal);
@ -3324,8 +3328,9 @@ XMLHttpRequestMainThread::OnProgress(nsIRequest *aRequest, nsISupports *aContext
StartProgressEventTimer();
}
} else {
mLoadTotal = lengthComputable ? aProgressMax : 0;
mLoadTotal = lengthComputable ? aProgressMax : -1;
mLoadTransferred = aProgress;
// OnDataAvailable() handles mProgressSinceLastProgressEvent
// for the download phase.
}

Просмотреть файл

@ -717,7 +717,7 @@ protected:
bool mIsHtml;
bool mWarnAboutMultipartHtml;
bool mWarnAboutSyncHtml;
int64_t mLoadTotal; // 0 if not known.
int64_t mLoadTotal; // -1 if not known.
// Amount of script-exposed (i.e. after undoing gzip compresion) data
// received.
uint64_t mDataAvailable;