This commit is contained in:
Dan Witte 2010-08-30 13:20:38 -07:00
Родитель 6e68061138
Коммит 363355fc1c
28 изменённых файлов: 116 добавлений и 126 удалений

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

@ -6720,11 +6720,14 @@ nsDocument::RetrieveRelevantHeaders(nsIChannel *aChannel)
}
}
} else {
nsCAutoString contentDisp;
rv = aChannel->GetContentDisposition(contentDisp);
if (NS_SUCCEEDED(rv) && !contentDisp.IsEmpty()) {
SetHeaderData(nsGkAtoms::headerContentDisposition,
NS_ConvertASCIItoUTF16(contentDisp));
nsCOMPtr<nsIMultiPartChannel> partChannel = do_QueryInterface(aChannel);
if (partChannel) {
nsCAutoString contentDisp;
rv = partChannel->GetContentDisposition(contentDisp);
if (NS_SUCCEEDED(rv) && !contentDisp.IsEmpty()) {
SetHeaderData(nsGkAtoms::headerContentDisposition,
NS_ConvertASCIItoUTF16(contentDisp));
}
}
}
}

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

@ -2407,7 +2407,6 @@ NOT_IMPLEMENTED_IF_FUNC_1(GetContentType, nsACString &value)
NOT_IMPLEMENTED_IF_FUNC_1(SetContentType, const nsACString &value)
NOT_IMPLEMENTED_IF_FUNC_1(GetContentCharset, nsACString &value)
NOT_IMPLEMENTED_IF_FUNC_1(SetContentCharset, const nsACString &value)
NOT_IMPLEMENTED_IF_FUNC_1(GetContentDisposition, nsACString &value)
NOT_IMPLEMENTED_IF_FUNC_1(GetContentLength, PRInt64 *value)
NOT_IMPLEMENTED_IF_FUNC_1(SetContentLength, PRInt64 value)
NOT_IMPLEMENTED_IF_FUNC_1(Open, nsIInputStream **_retval)

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

@ -264,13 +264,6 @@ nsWyciwygChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWyciwygChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsWyciwygChannel::GetContentLength(PRInt64 *aContentLength)
{

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

@ -1011,12 +1011,6 @@ nsJSChannel::SetContentCharset(const nsACString &aContentCharset)
return mStreamChannel->SetContentCharset(aContentCharset);
}
NS_IMETHODIMP
nsJSChannel::GetContentDisposition(nsACString &aContentDisposition)
{
return mStreamChannel->GetContentDisposition(aContentDisposition);
}
NS_IMETHODIMP
nsJSChannel::GetContentLength(PRInt64 *aContentLength)
{

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

@ -631,13 +631,6 @@ nsJARChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentDisposition(nsACString &result)
{
result = mContentDisposition;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentLength(PRInt64 *result)
{
@ -778,6 +771,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));
@ -786,7 +780,6 @@ 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;
@ -797,6 +790,10 @@ nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
mIsUnsafe = !(contentType.Equals(channelContentType) &&
(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) {
@ -804,9 +801,11 @@ 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);
}
channel->GetContentDisposition(mContentDisposition);
}
if (NS_SUCCEEDED(status) && mIsUnsafe) {

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

@ -96,7 +96,6 @@ private:
nsCOMPtr<nsISupports> mListenerContext;
nsCString mContentType;
nsCString mContentCharset;
nsCString mContentDisposition;
PRInt64 mContentLength;
PRUint32 mLoadFlags;
nsresult mStatus;

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

@ -407,13 +407,6 @@ nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsIconChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt64 *aContentLength)
{
*aContentLength = mContentLength;

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

@ -399,13 +399,6 @@ nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsIconChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt64 *aContentLength)
{
*aContentLength = mContentLength;

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

@ -636,13 +636,6 @@ nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsIconChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt64 *aContentLength)
{
*aContentLength = mContentLength;

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

@ -693,13 +693,6 @@ nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsIconChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt64 *aContentLength)
{
*aContentLength = mContentLength;

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

@ -988,10 +988,11 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
/* NS_WARNING if the content type from the channel isn't the same if the sniffing */
#endif
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
if (mContentType.IsEmpty()) {
LOG_SCOPE(gImgLog, "imgRequest::OnDataAvailable |sniffing of mimetype failed|");
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
rv = NS_ERROR_FAILURE;
if (chan) {
rv = chan->GetContentType(mContentType);
@ -1031,8 +1032,14 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
/* set our content disposition as a property */
nsCAutoString disposition;
if (chan) {
chan->GetContentDisposition(disposition);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
if (httpChannel) {
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"), disposition);
} else {
nsCOMPtr<nsIMultiPartChannel> multiPartChannel(do_QueryInterface(aRequest));
if (multiPartChannel) {
multiPartChannel->GetContentDisposition(disposition);
}
}
if (!disposition.IsEmpty()) {
nsCOMPtr<nsISupportsCString> contentDisposition(do_CreateInstance("@mozilla.org/supports-cstring;1"));
@ -1092,7 +1099,6 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
if (imageType == imgIContainer::TYPE_RASTER) {
/* Use content-length as a size hint for http channels. */
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
if (httpChannel) {
PRInt64 contentLength;
rv = httpChannel->GetContentLength(&contentLength);

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

@ -50,6 +50,13 @@
*/
/**
* MIME Content-Disposition header of channel.
* Not available before onStartRequest.
* Type: nsACString
*/
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR "content-disposition"
/**
* Exists to allow content policy mechanism to function properly during channel
* redirects. Contains security contextual information about the load.
@ -58,8 +65,11 @@
#define NS_CHANNEL_PROP_CHANNEL_POLICY_STR "channel-policy"
#ifdef IMPL_NS_NET
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION gNetStrings->kContentDisposition
#define NS_CHANNEL_PROP_CHANNEL_POLICY gNetStrings->kChannelPolicy
#else
#define NS_CHANNEL_PROP_CONTENT_DISPOSITION \
NS_LITERAL_STRING(NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR)
#define NS_CHANNEL_PROP_CHANNEL_POLICY \
NS_LITERAL_STRING(NS_CHANNEL_PROP_CHANNEL_POLICY_STR)
#endif

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

@ -56,7 +56,7 @@ interface nsIStreamListener;
*
* This interface must be used only from the XPCOM main thread.
*/
[scriptable, uuid(3906f857-3d79-4716-be55-ed2455d666f4)]
[scriptable, uuid(e0bb5c49-c54e-4efb-8f0d-6a7edd926fab)]
interface nsIChannel : nsIRequest
{
/**
@ -157,13 +157,6 @@ interface nsIChannel : nsIRequest
*/
attribute PRInt64 contentLength;
/**
* Access to the Content-Disposition header if available and if applicable.
* This allows getting the preferred handling method, preferred filename,
* etc. See RFC 2183.
*/
readonly attribute ACString contentDisposition;
/**
* Synchronously open the channel.
*

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

@ -45,7 +45,7 @@ interface nsIChannel;
* associated with a MultiPartChannel.
*/
[scriptable, uuid(51698f28-c975-4bce-a951-25130cda0113)]
[scriptable, uuid(ba78db7b-b88c-4b76-baf9-3c2296a585ae)]
interface nsIMultiPartChannel : nsISupports
{
/**
@ -53,6 +53,13 @@ interface nsIMultiPartChannel : nsISupports
*/
readonly attribute nsIChannel baseChannel;
/**
* Access to the Content-Disposition header field of this part of
* a multipart message. This allows getting the preferred
* handling method, preferred filename, etc. See RFC 2183.
*/
attribute ACString contentDisposition;
/**
* Attribute guaranteed to be different for different parts of
* the same multipart document.

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

@ -47,6 +47,7 @@ class nsNetStrings {
public:
nsNetStrings();
const nsLiteralString kContentDisposition;
const nsLiteralString kChannelPolicy;
};

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

@ -238,6 +238,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

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

@ -503,13 +503,6 @@ nsBaseChannel::SetContentCharset(const nsACString &aContentCharset)
return NS_OK;
}
NS_IMETHODIMP
nsBaseChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition = mContentDisposition;
return NS_OK;
}
NS_IMETHODIMP
nsBaseChannel::GetContentLength(PRInt64 *aContentLength)
{

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

@ -290,7 +290,6 @@ private:
nsCOMPtr<nsIChannel> mRedirectChannel;
nsCString mContentType;
nsCString mContentCharset;
nsCString mContentDisposition;
PRInt64 mContentLength;
PRUint32 mLoadFlags;
nsresult mStatus;

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

@ -40,7 +40,8 @@
NS_HIDDEN_(nsNetStrings*) gNetStrings;
nsNetStrings::nsNetStrings()
: NS_LITERAL_STRING_INIT(kChannelPolicy, NS_CHANNEL_PROP_CHANNEL_POLICY_STR)
: NS_LITERAL_STRING_INIT(kContentDisposition, NS_CHANNEL_PROP_CONTENT_DISPOSITION_STR),
NS_LITERAL_STRING_INIT(kChannelPolicy, NS_CHANNEL_PROP_CHANNEL_POLICY_STR)
{}

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

@ -358,18 +358,6 @@ HttpBaseChannel::SetContentCharset(const nsACString& aContentCharset)
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetContentDisposition(nsACString& aContentDisposition)
{
aContentDisposition.Truncate();
if (!mResponseHead)
return NS_ERROR_NOT_AVAILABLE;
mResponseHead->GetHeader(nsHttp::Content_Disposition, aContentDisposition);
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetContentLength(PRInt64 *aContentLength)
{

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

@ -129,7 +129,6 @@ public:
NS_IMETHOD SetContentType(const nsACString& aContentType);
NS_IMETHOD GetContentCharset(nsACString& aContentCharset);
NS_IMETHOD SetContentCharset(const nsACString& aContentCharset);
NS_IMETHOD GetContentDisposition(nsACString& aContentDisposition);
NS_IMETHOD GetContentLength(PRInt64 *aContentLength);
NS_IMETHOD SetContentLength(PRInt64 aContentLength);
NS_IMETHOD Open(nsIInputStream **aResult);

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

@ -369,14 +369,6 @@ nsViewSourceChannel::SetContentCharset(const nsACString &aContentCharset)
return mChannel->SetContentCharset(aContentCharset);
}
NS_IMETHODIMP
nsViewSourceChannel::GetContentDisposition(nsACString &aContentDisposition)
{
NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
return mChannel->GetContentDisposition(aContentDisposition);
}
NS_IMETHODIMP
nsViewSourceChannel::GetContentLength(PRInt64 *aContentLength)
{

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

@ -344,6 +344,13 @@ nsPartChannel::GetContentDisposition(nsACString &aContentDisposition)
return NS_OK;
}
NS_IMETHODIMP
nsPartChannel::SetContentDisposition(const nsACString &aContentDisposition)
{
mContentDisposition = aContentDisposition;
return NS_OK;
}
NS_IMETHODIMP
nsPartChannel::GetPartID(PRUint32 *aPartID)
{
@ -793,7 +800,8 @@ nsMultiMixedConv::SendStart(nsIChannel *aChannel) {
rv = mPartChannel->SetContentLength(mContentLength);
if (NS_FAILED(rv)) return rv;
mPartChannel->SetContentDisposition(mContentDisposition);
rv = mPartChannel->SetContentDisposition(mContentDisposition);
if (NS_FAILED(rv)) return rv;
nsLoadFlags loadFlags = 0;
mPartChannel->GetLoadFlags(&loadFlags);

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

@ -77,11 +77,6 @@ public:
PRUint32 aOffset, PRUint32 aLen);
nsresult SendOnStopRequest(nsISupports* aContext, nsresult aStatus);
void SetContentDisposition(const nsACString& aDisposition)
{
mContentDisposition = aDisposition;
}
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL

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

@ -386,9 +386,26 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports *
// future, because the user has specified external handling for the MIME
// type.
PRBool forceExternalHandling = PR_FALSE;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
nsCAutoString disposition;
rv = aChannel->GetContentDisposition(disposition);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
nsCOMPtr<nsIURI> uri;
if (httpChannel)
{
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"),
disposition);
httpChannel->GetURI(getter_AddRefs(uri));
}
else
{
nsCOMPtr<nsIMultiPartChannel> multipartChannel(do_QueryInterface(request));
if (multipartChannel)
{
rv = multipartChannel->GetContentDisposition(disposition);
} else {
// Soon-to-be common way to get Disposition: right now only JARChannel
rv = NS_GetContentDisposition(request, disposition);
}
}
LOG((" Disposition header: '%s'", disposition.get()));
@ -398,9 +415,6 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports *
if (NS_SUCCEEDED(rv))
{
nsCAutoString fallbackCharset;
nsCOMPtr<nsIURI> uri;
if (httpChannel)
httpChannel->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetOriginCharset(fallbackCharset);
nsAutoString dispToken;

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

@ -295,13 +295,6 @@ ExternalHelperAppParent::SetContentCharset(const nsACString& aContentCharset)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetContentDisposition(nsACString& aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetContentLength(PRInt64 *aContentLength)
{

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

@ -222,6 +222,31 @@ static nsresult UnescapeFragment(const nsACString& aFragment, nsIURI* aURI,
return rv;
}
/** Gets the content-disposition header from a channel, using nsIHttpChannel
* or nsIMultipartChannel if available
* @param aChannel The channel to extract the disposition header from
* @param aDisposition Reference to a string where the header is to be stored
*/
static void ExtractDisposition(nsIChannel* aChannel, nsACString& aDisposition)
{
aDisposition.Truncate();
// First see whether this is an http channel
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
if (httpChannel)
{
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"), aDisposition);
}
if (aDisposition.IsEmpty())
{
nsCOMPtr<nsIMultiPartChannel> multipartChannel(do_QueryInterface(aChannel));
if (multipartChannel)
{
multipartChannel->GetContentDisposition(aDisposition);
}
}
}
/** Extracts the filename out of a content-disposition header
* @param aFilename [out] The filename. Can be empty on error.
* @param aDisposition Value of a Content-Disposition header
@ -289,7 +314,7 @@ static PRBool GetFilenameAndExtensionFromChannel(nsIChannel* aChannel,
* permission... otherwise just use our temp file
*/
nsCAutoString disp;
aChannel->GetContentDisposition(disp);
ExtractDisposition(aChannel, disp);
PRBool handleExternally = PR_FALSE;
nsCOMPtr<nsIURI> uri;
nsresult rv;

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

@ -247,12 +247,6 @@ NS_IMETHODIMP nsExtProtocolChannel::SetContentCharset(const nsACString &aContent
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsExtProtocolChannel::GetContentDisposition(nsACString &aContentDisposition)
{
aContentDisposition.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsExtProtocolChannel::GetContentLength(PRInt64 * aContentLength)
{
*aContentLength = -1;