Bug 725993 - Remove usage of STORE_ON_DISK flag in XHR code, r=jonas

This commit is contained in:
Michal Novotny 2012-11-27 12:48:15 +01:00
parent de968470dd
commit d5f530148f
4 changed files with 25 additions and 68 deletions

View File

@ -246,24 +246,17 @@ public:
NS_ASSERTION(mFile, "must have file");
}
// Create as a blob
nsDOMFileFile(nsIFile *aFile, const nsAString& aContentType,
nsISupports *aCacheToken)
: nsDOMFile(aContentType, UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false),
mCacheToken(aCacheToken)
{
NS_ASSERTION(mFile, "must have file");
}
// Create as a file with custom name
nsDOMFileFile(nsIFile *aFile, const nsAString& aName)
: nsDOMFile(aName, EmptyString(), UINT64_MAX, UINT64_MAX),
nsDOMFileFile(nsIFile *aFile, const nsAString& aName,
const nsAString& aContentType)
: nsDOMFile(aName, aContentType, UINT64_MAX, UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false)
{
NS_ASSERTION(mFile, "must have file");
// Lazily get the content type and size
mContentType.SetIsVoid(true);
if (aContentType.IsEmpty()) {
// Lazily get the content type and size
mContentType.SetIsVoid(true);
}
}
// Create as a stored file
@ -324,7 +317,7 @@ protected:
const nsAString& aContentType)
: nsDOMFile(aContentType, aOther->mStart + aStart, aLength),
mFile(aOther->mFile), mWholeFile(false),
mStoredFile(aOther->mStoredFile), mCacheToken(aOther->mCacheToken)
mStoredFile(aOther->mStoredFile)
{
NS_ASSERTION(mFile, "must have file");
mImmutable = aOther->mImmutable;
@ -363,7 +356,6 @@ protected:
nsCOMPtr<nsIFile> mFile;
bool mWholeFile;
bool mStoredFile;
nsCOMPtr<nsISupports> mCacheToken;
};
class nsDOMMemoryFile : public nsDOMFile

View File

@ -1077,18 +1077,6 @@ nsXMLHttpRequest::SetResponseType(nsXMLHttpRequest::ResponseTypeEnum aResponseTy
// Set the responseType attribute's value to the given value.
mResponseType = aResponseType;
// If the state is OPENED, SetCacheAsFile would have no effect here
// because the channel hasn't initialized the cache entry yet.
// SetCacheAsFile will be called from OnStartRequest.
// If the state is HEADERS_RECEIVED, however, we need to call
// it immediately because OnStartRequest is already dispatched.
if (mState & XML_HTTP_REQUEST_HEADERS_RECEIVED) {
nsCOMPtr<nsICachingChannel> cc(do_QueryInterface(mChannel));
if (cc) {
cc->SetCacheAsFile(mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB);
}
}
}
/* readonly attribute jsval response; */
@ -1965,37 +1953,22 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request)
{
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsICachingChannel> cc(do_QueryInterface(request));
if (cc) {
cc->GetCacheFile(getter_AddRefs(file));
} else {
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(request);
if (fc) {
fc->GetFile(getter_AddRefs(file));
}
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(request);
if (fc) {
fc->GetFile(getter_AddRefs(file));
}
bool fromFile = false;
if (file) {
nsAutoCString contentType;
mChannel->GetContentType(contentType);
nsCOMPtr<nsISupports> cacheToken;
if (cc) {
cc->GetCacheToken(getter_AddRefs(cacheToken));
// We need to call IsFromCache to determine whether the response is
// fully cached (i.e. whether we can skip reading the response).
cc->IsFromCache(&fromFile);
} else {
// If the response is coming from the local resource, we can skip
// reading the response unconditionally.
fromFile = true;
}
mDOMFile =
new nsDOMFileFile(file, NS_ConvertASCIItoUTF16(contentType), cacheToken);
mBlobSet = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
}
return fromFile;
if (!file)
return false;
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mDOMFile =
new nsDOMFileFile(file, EmptyString(), NS_ConvertASCIItoUTF16(contentType));
mBlobSet = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
return true;
}
NS_IMETHODIMP
@ -2127,14 +2100,6 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
mState &= ~XML_HTTP_REQUEST_MPART_HEADERS;
ChangeState(XML_HTTP_REQUEST_HEADERS_RECEIVED);
if (mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) {
nsCOMPtr<nsICachingChannel> cc(do_QueryInterface(mChannel));
if (cc) {
cc->SetCacheAsFile(true);
}
}
ResetResponse();
if (!mOverrideMimeType.IsEmpty()) {

View File

@ -596,8 +596,7 @@ protected:
// but is also explicitly set in OnStopRequest.
nsCOMPtr<nsIDOMBlob> mResponseBlob;
// Non-null only when we are able to get a os-file representation of the
// response, i.e. when loading from a file, or when the http-stream
// caches into a file or is reading from a cached file.
// response, i.e. when loading from a file.
nsRefPtr<nsDOMFile> mDOMFile;
// We stream data to mBlobSet when response type is "blob" or "moz-blob"
// and mDOMFile is null.

View File

@ -778,7 +778,8 @@ jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
return JSVAL_NULL;
}
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(aFile->mFile, aFile->mPath);
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(aFile->mFile, aFile->mPath,
EmptyString());
return InterfaceToJsval(aWindow, blob, &NS_GET_IID(nsIDOMBlob));
}