Bug 1591579 - XHR-MainThread exposes a set of methods to retrieve response values for workers, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D50920

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-10-31 10:27:11 +00:00
Родитель d7261d6930
Коммит cff9f77d8c
2 изменённых файлов: 46 добавлений и 2 удалений

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

@ -619,8 +619,9 @@ nsresult XMLHttpRequestMainThread::CreateResponseParsedJSON(JSContext* aCx) {
}
nsAutoString string;
if (!mResponseText.GetAsString(string)) {
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = GetResponseTextForJSON(string);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// The Unicode converter has already zapped the BOM if there was one
@ -745,6 +746,45 @@ void XMLHttpRequestMainThread::GetResponse(
aResponse.setNull();
}
already_AddRefed<BlobImpl> XMLHttpRequestMainThread::GetResponseBlobImpl() {
MOZ_DIAGNOSTIC_ASSERT(mForWorker);
MOZ_DIAGNOSTIC_ASSERT(mResponseType == XMLHttpRequestResponseType::Blob);
if (mState != XMLHttpRequest_Binding::DONE) {
return nullptr;
}
RefPtr<BlobImpl> blobImpl = mResponseBlobImpl;
return blobImpl.forget();
}
already_AddRefed<ArrayBufferBuilder>
XMLHttpRequestMainThread::GetResponseArrayBufferBuilder() {
MOZ_DIAGNOSTIC_ASSERT(mForWorker);
MOZ_DIAGNOSTIC_ASSERT(mResponseType ==
XMLHttpRequestResponseType::Arraybuffer);
if (mState != XMLHttpRequest_Binding::DONE) {
return nullptr;
}
RefPtr<ArrayBufferBuilder> builder = mArrayBufferBuilder;
return builder.forget();
}
nsresult XMLHttpRequestMainThread::GetResponseTextForJSON(nsAString& aString) {
if (mState != XMLHttpRequest_Binding::DONE) {
aString.SetIsVoid(true);
return NS_OK;
}
if (!mResponseText.GetAsString(aString)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
bool XMLHttpRequestMainThread::IsCrossSiteCORSRequest() const {
if (!mChannel) {
return false;

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

@ -386,6 +386,10 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
virtual void GetResponseText(DOMString& aResponseText,
ErrorResult& aRv) override;
// GetResponse* for workers:
already_AddRefed<BlobImpl> GetResponseBlobImpl();
already_AddRefed<ArrayBufferBuilder> GetResponseArrayBufferBuilder();
nsresult GetResponseTextForJSON(nsAString& aString);
void GetResponseText(XMLHttpRequestStringSnapshot& aSnapshot,
ErrorResult& aRv);