зеркало из https://github.com/mozilla/pjs.git
Bug 474536. Expose the underlying channel's content-disposition on jar: channels. r+sr=bzbarsky
This commit is contained in:
Родитель
00ef059fae
Коммит
0b10eee40b
|
@ -46,6 +46,7 @@
|
|||
#include "nsEscape.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsChannelProperties.h"
|
||||
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIPrincipal.h"
|
||||
|
@ -218,6 +219,9 @@ nsJARInputThunk::IsNonBlocking(PRBool *nonBlocking)
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsJARChannel
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
nsJARChannel::nsJARChannel()
|
||||
: mContentLength(-1)
|
||||
|
@ -246,18 +250,23 @@ nsJARChannel::~nsJARChannel()
|
|||
NS_RELEASE(handler); // NULL parameter
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS6(nsJARChannel,
|
||||
nsIRequest,
|
||||
nsIChannel,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver,
|
||||
nsIDownloadObserver,
|
||||
nsIJARChannel)
|
||||
NS_IMPL_ISUPPORTS_INHERITED6(nsJARChannel,
|
||||
nsHashPropertyBag,
|
||||
nsIRequest,
|
||||
nsIChannel,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver,
|
||||
nsIDownloadObserver,
|
||||
nsIJARChannel)
|
||||
|
||||
nsresult
|
||||
nsJARChannel::Init(nsIURI *uri)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsHashPropertyBag::Init();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mJarURI = do_QueryInterface(uri, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
@ -752,6 +761,7 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(status) && channel) {
|
||||
nsCAutoString header;
|
||||
// Grab the security info from our base channel
|
||||
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
|
||||
// send us a JAR file. Check the server-supplied content type for
|
||||
// a JAR type.
|
||||
nsCAutoString header;
|
||||
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"),
|
||||
header);
|
||||
|
||||
nsCAutoString contentType;
|
||||
nsCAutoString charset;
|
||||
NS_ParseContentType(header, contentType, charset);
|
||||
|
||||
mIsUnsafe = !contentType.EqualsLiteral("application/java-archive") &&
|
||||
!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 {
|
||||
nsCOMPtr<nsIJARChannel> innerJARChannel(do_QueryInterface(channel));
|
||||
if (innerJARChannel) {
|
||||
|
@ -777,6 +788,10 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
|
|||
innerJARChannel->GetIsUnsafe(&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 "nsIDownloader.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsHashPropertyBag.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -60,6 +61,7 @@ class nsJARInputThunk;
|
|||
class nsJARChannel : public nsIJARChannel
|
||||
, public nsIDownloadObserver
|
||||
, public nsIStreamListener
|
||||
, public nsHashPropertyBag
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
|
|
@ -58,11 +58,21 @@
|
|||
*/
|
||||
#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
|
||||
#define NS_CHANNEL_PROP_CONTENT_LENGTH gNetStrings->kContentLength
|
||||
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION gNetStrings->kContentDisposition
|
||||
#else
|
||||
#define NS_CHANNEL_PROP_CONTENT_LENGTH \
|
||||
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
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
|
||||
/** "content-length" */
|
||||
const nsLiteralString kContentLength;
|
||||
const nsLiteralString kContentDisposition;
|
||||
};
|
||||
|
||||
extern NS_HIDDEN_(nsNetStrings*) gNetStrings;
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsChannelProperties.h"
|
||||
#include "nsIInputStreamChannel.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
|
@ -194,6 +195,19 @@ NS_NewChannel(nsIChannel **result,
|
|||
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
|
||||
// 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
|
||||
|
|
|
@ -41,6 +41,7 @@ NS_HIDDEN_(nsNetStrings*) gNetStrings;
|
|||
|
||||
nsNetStrings::nsNetStrings()
|
||||
: 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(Connection, "Connection")
|
||||
HTTP_ATOM(Content_Base, "Content-Base")
|
||||
HTTP_ATOM(Content_Disposition, "Content-Disposition")
|
||||
HTTP_ATOM(Content_Encoding, "Content-Encoding")
|
||||
HTTP_ATOM(Content_Language, "Content-Language")
|
||||
HTTP_ATOM(Content_Length, "Content-Length")
|
||||
|
|
|
@ -73,4 +73,3 @@ DEFINES += -DNGPREFS
|
|||
endif
|
||||
endif # WINNT
|
||||
|
||||
DEFINES += -DIMPL_NS_NET
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsDOMError.h"
|
||||
|
@ -380,6 +380,9 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports *
|
|||
if (multipartChannel)
|
||||
{
|
||||
rv = multipartChannel->GetContentDisposition(disposition);
|
||||
} else {
|
||||
// Soon-to-be common way to get Disposition: right now only JARChannel
|
||||
rv = NS_GetContentDisposition(request, disposition);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче