Skip to content

Commit

Permalink
Backed out changeset c5ac0cb25238 (bug 1491504) for FetchConsumer.cpp…
Browse files Browse the repository at this point in the history
… build bustages CLOSED TREE
  • Loading branch information
SV-ACiure committed Oct 5, 2018
1 parent 2294c78 commit 47efccb
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 172 deletions.
15 changes: 0 additions & 15 deletions dom/fetch/Fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,21 +1252,6 @@ template
void
FetchBody<Response>::SetMimeType();

template <class Derived>
const nsACString&
FetchBody<Derived>::BodyBlobURISpec() const
{
return DerivedClass()->BodyBlobURISpec();
}

template
const nsACString&
FetchBody<Request>::BodyBlobURISpec() const;

template
const nsACString&
FetchBody<Response>::BodyBlobURISpec() const;

template <class Derived>
const nsAString&
FetchBody<Derived>::BodyLocalPath() const
Expand Down
3 changes: 0 additions & 3 deletions dom/fetch/Fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ class FetchBody : public FetchStreamHolder
JS::MutableHandle<JSObject*> aBodyOut,
ErrorResult& aRv);

const nsACString&
BodyBlobURISpec() const;

const nsAString&
BodyLocalPath() const;

Expand Down
22 changes: 3 additions & 19 deletions dom/fetch/FetchConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ FetchBodyConsumer<Derived>::FetchBodyConsumer(nsIEventTarget* aMainThreadEventTa
#endif
, mBodyStream(aBodyStream)
, mBlobStorageType(MutableBlobStorage::eOnlyInMemory)
, mBodyBlobURISpec(aBody ? aBody->BodyBlobURISpec() : VoidCString())
, mBodyLocalPath(aBody ? aBody->BodyLocalPath() : VoidString())
, mGlobal(aGlobalObject)
, mConsumeType(aType)
Expand Down Expand Up @@ -598,26 +597,11 @@ FetchBodyConsumer<Derived>::BeginConsumeBodyMainThread(ThreadSafeWorkerRef* aWor
return;
}

// If we're trying to consume a blob, and the request was for a local
// file, then generate and return a File blob.
if (mConsumeType == CONSUME_BLOB) {
nsresult rv;

// If we're trying to consume a blob, and the request was for a blob URI,
// then just consume that URI's blob instance.
if (!mBodyBlobURISpec.IsEmpty()) {
RefPtr<BlobImpl> blobImpl;
rv = NS_GetBlobForBlobURISpec(mBodyBlobURISpec, getter_AddRefs(blobImpl));
if (NS_WARN_IF(NS_FAILED(rv)) || !blobImpl) {
return;
}
autoReject.DontFail();
ContinueConsumeBlobBody(blobImpl);
return;
}

// If we're trying to consume a blob, and the request was for a local
// file, then generate and return a File blob.
nsCOMPtr<nsIFile> file;
rv = GetBodyLocalFile(getter_AddRefs(file));
nsresult rv = GetBodyLocalFile(getter_AddRefs(file));
if (!NS_WARN_IF(NS_FAILED(rv)) && file) {
ChromeFilePropertyBag bag;
bag.mType = NS_ConvertUTF8toUTF16(mBodyMimeType);
Expand Down
1 change: 0 additions & 1 deletion dom/fetch/FetchConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class FetchBodyConsumer final : public nsIObserver
MutableBlobStorage::MutableBlobStorageType mBlobStorageType;
nsCString mBodyMimeType;

nsCString mBodyBlobURISpec;
nsString mBodyLocalPath;

nsCOMPtr<nsIGlobalObject> mGlobal;
Expand Down
33 changes: 0 additions & 33 deletions dom/fetch/FetchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,6 @@ namespace dom {

namespace {

void
GetBlobURISpecFromChannel(nsIRequest* aRequest, nsCString& aBlobURISpec)
{
MOZ_ASSERT(aRequest);

aBlobURISpec.SetIsVoid(true);

nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
if (!channel) {
return;
}

nsCOMPtr<nsIURI> uri;
nsresult rv = channel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) {
return;
}

if (!dom::IsBlobURI(uri)) {
return;
}

uri->GetSpec(aBlobURISpec);
}

bool
ShouldCheckSRI(const InternalRequest* const aRequest,
const InternalResponse* const aResponse)
Expand Down Expand Up @@ -987,14 +962,6 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
file->GetPath(path);
response->SetBodyLocalPath(path);
}
} else {
// If the request is a blob URI, then remember that URI so that we
// can later just use that blob instance instead of cloning it.
nsCString blobURISpec;
GetBlobURISpecFromChannel(aRequest, blobURISpec);
if (!blobURISpec.IsVoid()) {
response->SetBodyBlobURISpec(blobURISpec);
}
}

response->InitChannelInfo(channel);
Expand Down
13 changes: 0 additions & 13 deletions dom/fetch/InternalRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,6 @@ class InternalRequest final
}
}

void
SetBodyBlobURISpec(nsACString& aBlobURISpec)
{
mBodyBlobURISpec = aBlobURISpec;
}

const nsACString&
BodyBlobURISpec() const
{
return mBodyBlobURISpec;
}

void
SetBodyLocalPath(nsAString& aLocalPath)
{
Expand Down Expand Up @@ -620,7 +608,6 @@ class InternalRequest final
// mURLList: a list of one or more fetch URLs
nsTArray<nsCString> mURLList;
RefPtr<InternalHeaders> mHeaders;
nsCString mBodyBlobURISpec;
nsString mBodyLocalPath;
nsCOMPtr<nsIInputStream> mBodyStream;
int64_t mBodyLength;
Expand Down
16 changes: 0 additions & 16 deletions dom/fetch/InternalResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,6 @@ class InternalResponse final
GetUnfilteredBody(aStream, aBodySize);
}

void
SetBodyBlobURISpec(nsACString& aBlobURISpec)
{
mBodyBlobURISpec = aBlobURISpec;
}

const nsACString&
BodyBlobURISpec() const
{
if (mWrappedResponse) {
return mWrappedResponse->BodyBlobURISpec();
}
return mBodyBlobURISpec;
}

void
SetBodyLocalPath(nsAString& aLocalPath)
{
Expand Down Expand Up @@ -403,7 +388,6 @@ class InternalResponse final
const nsCString mStatusText;
RefPtr<InternalHeaders> mHeaders;
nsCOMPtr<nsIInputStream> mBody;
nsCString mBodyBlobURISpec;
nsString mBodyLocalPath;
int64_t mBodySize;
// It's used to passed to the CacheResponse to generate padding size. Once, we
Expand Down
8 changes: 0 additions & 8 deletions dom/fetch/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ class Request final : public nsISupports
mRequest->SetBody(aStream, aBodyLength);
}

using FetchBody::BodyBlobURISpec;

const nsACString&
BodyBlobURISpec() const
{
return mRequest->BodyBlobURISpec();
}

using FetchBody::BodyLocalPath;

const nsAString&
Expand Down
8 changes: 0 additions & 8 deletions dom/fetch/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ class Response final : public nsISupports

using FetchBody::GetBody;

using FetchBody::BodyBlobURISpec;

const nsACString&
BodyBlobURISpec() const
{
return mInternalResponse->BodyBlobURISpec();
}

using FetchBody::BodyLocalPath;

const nsAString&
Expand Down
62 changes: 6 additions & 56 deletions dom/xhr/XMLHttpRequestMainThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/BlobURLProtocolHandler.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/DOMString.h"
#include "mozilla/dom/File.h"
Expand Down Expand Up @@ -1186,13 +1185,11 @@ XMLHttpRequestMainThread::GetResponseHeader(const nsACString& header,

// Even non-http channels supply content type and content length.
// Remember we don't leak header information from denied cross-site
// requests. However, we handle file: and blob: URLs for blob response
// types by canceling them with a specific error, so we have to allow
// them to pass through this check.
// requests.
nsresult status;
if (!mChannel ||
NS_FAILED(mChannel->GetStatus(&status)) ||
(NS_FAILED(status) && status != NS_ERROR_FILE_ALREADY_EXISTS)) {
NS_FAILED(status)) {
return;
}

Expand Down Expand Up @@ -1658,32 +1655,6 @@ XMLHttpRequestMainThread::StreamReaderFunc(nsIInputStream* in,

namespace {

void
GetBlobURIFromChannel(nsIRequest* aRequest, nsIURI** aURI)
{
MOZ_ASSERT(aRequest);
MOZ_ASSERT(aURI);

*aURI = nullptr;

nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
if (!channel) {
return;
}

nsCOMPtr<nsIURI> uri;
nsresult rv = channel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) {
return;
}

if (!dom::IsBlobURI(uri)) {
return;
}

uri.forget(aURI);
}

nsresult
GetLocalFileFromChannel(nsIRequest* aRequest, nsIFile** aFile)
{
Expand Down Expand Up @@ -1800,29 +1771,14 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest *request,

nsresult rv;

nsCOMPtr<nsIFile> localFile;
if (mResponseType == XMLHttpRequestResponseType::Blob) {
nsCOMPtr<nsIFile> localFile;
nsCOMPtr<nsIURI> blobURI;
GetBlobURIFromChannel(request, getter_AddRefs(blobURI));
if (blobURI) {
RefPtr<BlobImpl> blobImpl;
rv = NS_GetBlobForBlobURI(blobURI, getter_AddRefs(blobImpl));
if (NS_SUCCEEDED(rv)) {
if (blobImpl) {
mResponseBlob = Blob::Create(GetOwner(), blobImpl);
}
if (!mResponseBlob) {
rv = NS_ERROR_FILE_NOT_FOUND;
}
}
} else {
rv = GetLocalFileFromChannel(request, getter_AddRefs(localFile));
}
rv = GetLocalFileFromChannel(request, getter_AddRefs(localFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

if (mResponseBlob || localFile) {
if (localFile) {
mBlobStorage = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");

Expand Down Expand Up @@ -2185,18 +2141,12 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
return NS_OK;
}

// If we were just reading a blob URL, we're already done
if (status == NS_ERROR_FILE_ALREADY_EXISTS && mResponseBlob) {
ChangeStateToDone();
return NS_OK;
}

bool waitingForBlobCreation = false;

// If we have this error, we have to deal with a file: URL + responseType =
// blob. We have this error because we canceled the channel. The status will
// be set to NS_OK.
if (!mResponseBlob && status == NS_ERROR_FILE_ALREADY_EXISTS &&
if (status == NS_ERROR_FILE_ALREADY_EXISTS &&
mResponseType == XMLHttpRequestResponseType::Blob) {
nsCOMPtr<nsIFile> file;
nsresult rv = GetLocalFileFromChannel(request, getter_AddRefs(file));
Expand Down

0 comments on commit 47efccb

Please sign in to comment.