From db9770f171847662792cc4c03d2c79e1d0a2928e Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Mon, 27 Aug 2012 19:34:30 -0400 Subject: [PATCH] Bug 783562 - blob: protocol wrong Content-Type header. r=sicking --- content/base/src/nsXMLHttpRequest.cpp | 9 ++++++++- modules/libjar/nsJARChannel.cpp | 14 +++++++++++++- modules/libjar/nsJARChannel.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 000798c7e61..4ef4063003f 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -77,6 +77,7 @@ #include "DictionaryHelpers.h" #include "mozilla/Attributes.h" #include "nsIPermissionManager.h" +#include "nsMimeTypes.h" #include "nsWrapperCacheInlines.h" #include "nsStreamListenerWrapper.h" @@ -3087,9 +3088,15 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable& aBody) } // Since we expect XML data, set the type hint accordingly + // if the channel doesn't know any content type. // This means that we always try to parse local files as XML // ignoring return value, as this is not critical - mChannel->SetContentType(NS_LITERAL_CSTRING("application/xml")); + nsCAutoString contentType; + if (NS_FAILED(mChannel->GetContentType(contentType)) || + contentType.IsEmpty() || + contentType.Equals(UNKNOWN_CONTENT_TYPE)) { + mChannel->SetContentType(NS_LITERAL_CSTRING("application/xml")); + } // We're about to send the request. Start our timeout. mRequestSentTime = PR_Now(); diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index dc8ce62008f..6c51d84787d 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -189,7 +189,8 @@ nsJARInputThunk::IsNonBlocking(bool *nonBlocking) nsJARChannel::nsJARChannel() - : mAppURI(nullptr) + : mOpened(false) + , mAppURI(nullptr) , mContentLength(-1) , mLoadFlags(LOAD_NORMAL) , mStatus(NS_OK) @@ -581,7 +582,15 @@ nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo) NS_IMETHODIMP nsJARChannel::GetContentType(nsACString &result) { + // If the Jar file has not been open yet, + // We return application/x-unknown-content-type + if (!mOpened) { + result.Assign(UNKNOWN_CONTENT_TYPE); + return NS_OK; + } + if (mContentType.IsEmpty()) { + // // generate content type and set it // @@ -710,6 +719,8 @@ nsJARChannel::Open(nsIInputStream **stream) if (NS_FAILED(rv)) return rv; NS_ADDREF(*stream = mJarInput); + + mOpened = true; return NS_OK; } @@ -754,6 +765,7 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) if (mLoadGroup) mLoadGroup->AddRequest(this, nullptr); + mOpened = true; return NS_OK; } diff --git a/modules/libjar/nsJARChannel.h b/modules/libjar/nsJARChannel.h index 1526002b30f..a6b048769bb 100644 --- a/modules/libjar/nsJARChannel.h +++ b/modules/libjar/nsJARChannel.h @@ -53,6 +53,8 @@ private: nsCString mSpec; #endif + bool mOpened; + nsCOMPtr mJarURI; nsCOMPtr mOriginalURI; nsCOMPtr mAppURI;