Bug 474536. Expose the underlying channel's content-disposition on jar: channels. r+sr=bzbarsky

This commit is contained in:
Jason Duell 2009-02-19 15:25:18 -05:00
Родитель 00ef059fae
Коммит 0b10eee40b
9 изменённых файлов: 58 добавлений и 12 удалений

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

@ -46,6 +46,7 @@
#include "nsEscape.h" #include "nsEscape.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsChannelProperties.h"
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
@ -218,6 +219,9 @@ nsJARInputThunk::IsNonBlocking(PRBool *nonBlocking)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// nsJARChannel
//-----------------------------------------------------------------------------
nsJARChannel::nsJARChannel() nsJARChannel::nsJARChannel()
: mContentLength(-1) : mContentLength(-1)
@ -246,18 +250,23 @@ nsJARChannel::~nsJARChannel()
NS_RELEASE(handler); // NULL parameter NS_RELEASE(handler); // NULL parameter
} }
NS_IMPL_ISUPPORTS6(nsJARChannel, NS_IMPL_ISUPPORTS_INHERITED6(nsJARChannel,
nsIRequest, nsHashPropertyBag,
nsIChannel, nsIRequest,
nsIStreamListener, nsIChannel,
nsIRequestObserver, nsIStreamListener,
nsIDownloadObserver, nsIRequestObserver,
nsIJARChannel) nsIDownloadObserver,
nsIJARChannel)
nsresult nsresult
nsJARChannel::Init(nsIURI *uri) nsJARChannel::Init(nsIURI *uri)
{ {
nsresult rv; nsresult rv;
rv = nsHashPropertyBag::Init();
if (NS_FAILED(rv))
return rv;
mJarURI = do_QueryInterface(uri, &rv); mJarURI = do_QueryInterface(uri, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@ -752,6 +761,7 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
} }
if (NS_SUCCEEDED(status) && channel) { if (NS_SUCCEEDED(status) && channel) {
nsCAutoString header;
// Grab the security info from our base channel // Grab the security info from our base channel
channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
@ -760,16 +770,17 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
// We only want to run scripts if the server really intended to // We only want to run scripts if the server really intended to
// send us a JAR file. Check the server-supplied content type for // send us a JAR file. Check the server-supplied content type for
// a JAR type. // a JAR type.
nsCAutoString header;
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"), httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"),
header); header);
nsCAutoString contentType; nsCAutoString contentType;
nsCAutoString charset; nsCAutoString charset;
NS_ParseContentType(header, contentType, charset); NS_ParseContentType(header, contentType, charset);
mIsUnsafe = !contentType.EqualsLiteral("application/java-archive") && mIsUnsafe = !contentType.EqualsLiteral("application/java-archive") &&
!contentType.EqualsLiteral("application/x-jar"); !contentType.EqualsLiteral("application/x-jar");
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Disposition"),
header);
if (NS_SUCCEEDED(rv))
SetPropertyAsACString(NS_CHANNEL_PROP_CONTENT_DISPOSITION, header);
} else { } else {
nsCOMPtr<nsIJARChannel> innerJARChannel(do_QueryInterface(channel)); nsCOMPtr<nsIJARChannel> innerJARChannel(do_QueryInterface(channel));
if (innerJARChannel) { if (innerJARChannel) {
@ -777,6 +788,10 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
innerJARChannel->GetIsUnsafe(&unsafe); innerJARChannel->GetIsUnsafe(&unsafe);
mIsUnsafe = unsafe; mIsUnsafe = unsafe;
} }
// Soon-to-be common way to get Disposition: right now only nsIJARChannel
rv = NS_GetContentDisposition(request, header);
if (NS_SUCCEEDED(rv))
SetPropertyAsACString(NS_CHANNEL_PROP_CONTENT_DISPOSITION, header);
} }
} }

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

@ -47,6 +47,7 @@
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsIDownloader.h" #include "nsIDownloader.h"
#include "nsILoadGroup.h" #include "nsILoadGroup.h"
#include "nsHashPropertyBag.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -60,6 +61,7 @@ class nsJARInputThunk;
class nsJARChannel : public nsIJARChannel class nsJARChannel : public nsIJARChannel
, public nsIDownloadObserver , public nsIDownloadObserver
, public nsIStreamListener , public nsIStreamListener
, public nsHashPropertyBag
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS

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

@ -58,11 +58,21 @@
*/ */
#define NS_CHANNEL_PROP_CONTENT_LENGTH_STR "content-length" #define NS_CHANNEL_PROP_CONTENT_LENGTH_STR "content-length"
/**
* MIME Content-Disposition header of channel.
* Not available before onStartRequest.
* Type: nsACString
*/
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR "content-disposition"
#ifdef IMPL_NS_NET #ifdef IMPL_NS_NET
#define NS_CHANNEL_PROP_CONTENT_LENGTH gNetStrings->kContentLength #define NS_CHANNEL_PROP_CONTENT_LENGTH gNetStrings->kContentLength
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION gNetStrings->kContentDisposition
#else #else
#define NS_CHANNEL_PROP_CONTENT_LENGTH \ #define NS_CHANNEL_PROP_CONTENT_LENGTH \
NS_LITERAL_STRING(NS_CHANNEL_PROP_CONTENT_LENGTH_STR) NS_LITERAL_STRING(NS_CHANNEL_PROP_CONTENT_LENGTH_STR)
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION \
NS_LITERAL_STRING(NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR)
#endif #endif
#endif #endif

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

@ -49,6 +49,7 @@ public:
/** "content-length" */ /** "content-length" */
const nsLiteralString kContentLength; const nsLiteralString kContentLength;
const nsLiteralString kContentDisposition;
}; };
extern NS_HIDDEN_(nsNetStrings*) gNetStrings; extern NS_HIDDEN_(nsNetStrings*) gNetStrings;

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

@ -62,6 +62,7 @@
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsChannelProperties.h"
#include "nsIInputStreamChannel.h" #include "nsIInputStreamChannel.h"
#include "nsITransport.h" #include "nsITransport.h"
#include "nsIStreamTransportService.h" #include "nsIStreamTransportService.h"
@ -194,6 +195,19 @@ NS_NewChannel(nsIChannel **result,
return rv; return rv;
} }
// For now, works only with JARChannel. Future: with all channels that may
// have Content-Disposition header (JAR, nsIHttpChannel, and nsIMultiPartChannel).
inline nsresult
NS_GetContentDisposition(nsIRequest *channel,
nsACString &result)
{
nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(channel));
if (props)
return props->GetPropertyAsACString(NS_CHANNEL_PROP_CONTENT_DISPOSITION,
result);
return NS_ERROR_NOT_AVAILABLE;
}
// Use this function with CAUTION. It creates a stream that blocks when you // Use this function with CAUTION. It creates a stream that blocks when you
// Read() from it and blocking the UI thread is a bad idea. If you don't want // Read() from it and blocking the UI thread is a bad idea. If you don't want
// to implement a full blown asynchronous consumer (via nsIStreamListener) look // to implement a full blown asynchronous consumer (via nsIStreamListener) look

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

@ -41,6 +41,7 @@ NS_HIDDEN_(nsNetStrings*) gNetStrings;
nsNetStrings::nsNetStrings() nsNetStrings::nsNetStrings()
: NS_LITERAL_STRING_INIT(kContentLength, NS_CHANNEL_PROP_CONTENT_LENGTH_STR) : NS_LITERAL_STRING_INIT(kContentLength, NS_CHANNEL_PROP_CONTENT_LENGTH_STR)
: NS_LITERAL_STRING_INIT(kContentDisposition, NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR)
{} {}

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

@ -62,6 +62,7 @@ HTTP_ATOM(Authorization, "Authorization")
HTTP_ATOM(Cache_Control, "Cache-Control") HTTP_ATOM(Cache_Control, "Cache-Control")
HTTP_ATOM(Connection, "Connection") HTTP_ATOM(Connection, "Connection")
HTTP_ATOM(Content_Base, "Content-Base") HTTP_ATOM(Content_Base, "Content-Base")
HTTP_ATOM(Content_Disposition, "Content-Disposition")
HTTP_ATOM(Content_Encoding, "Content-Encoding") HTTP_ATOM(Content_Encoding, "Content-Encoding")
HTTP_ATOM(Content_Language, "Content-Language") HTTP_ATOM(Content_Language, "Content-Language")
HTTP_ATOM(Content_Length, "Content-Length") HTTP_ATOM(Content_Length, "Content-Length")

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

@ -73,4 +73,3 @@ DEFINES += -DNGPREFS
endif endif
endif # WINNT endif # WINNT
DEFINES += -DIMPL_NS_NET

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

@ -65,7 +65,7 @@
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsString.h" #include "nsString.h"
#include "nsNetUtil.h"
#include "nsIDOMWindowInternal.h" #include "nsIDOMWindowInternal.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsDOMError.h" #include "nsDOMError.h"
@ -380,6 +380,9 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports *
if (multipartChannel) if (multipartChannel)
{ {
rv = multipartChannel->GetContentDisposition(disposition); rv = multipartChannel->GetContentDisposition(disposition);
} else {
// Soon-to-be common way to get Disposition: right now only JARChannel
rv = NS_GetContentDisposition(request, disposition);
} }
} }