Made contentType a read/write attribute of nsIChannel

This commit is contained in:
rpotts%netscape.com 2000-01-08 06:26:04 +00:00
Родитель 37a760ac57
Коммит 023f2ff6e1
24 изменённых файлов: 202 добавлений и 28 удалений

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

@ -220,6 +220,13 @@ nsCachedChromeChannel::GetContentType(char * *aContentType)
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentType(const char *aContentType)
{
// Do not allow the content-type to be changed.
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -302,6 +302,7 @@ public:
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }

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

@ -232,6 +232,14 @@ nsDateTimeChannel::GetContentType(char* *aContentType) {
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentType(const char *aContentType)
{
//It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -342,6 +342,12 @@ NS_IMETHODIMP nsMsgProtocol::GetContentType(char * *aContentType)
return NS_OK;
}
NS_IMETHODIMP nsMsgProtocol::SetContentType(const char *aContentType)
{
// XXX: Do not allow the content type to be changed (yet)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMsgProtocol::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;

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

@ -323,6 +323,12 @@ NS_IMETHODIMP nsMailtoChannel::GetContentType(char * *aContentType)
return NS_OK;
}
NS_IMETHODIMP nsMailtoChannel::SetContentType(const char *aContentType)
{
// Do not allow the content type to change...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMailtoChannel::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;

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

@ -6399,6 +6399,12 @@ NS_IMETHODIMP nsImapMockChannel::GetContentType(char * *aContentType)
return NS_OK;
}
NS_IMETHODIMP nsImapMockChannel::SetContentType(const char *aContentType)
{
// Do not allow the content-type to change.
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsImapMockChannel::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;

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

@ -418,6 +418,19 @@ nsJARChannel::GetContentType(char* *aContentType)
return rv;
}
NS_IMETHODIMP
nsJARChannel::SetContentType(const char *aContentType)
{
if (mContentType) {
nsCRT::free(mContentType);
}
mContentType = nsCRT::strdup(aContentType);
if (!mContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentLength(PRInt32* aContentLength)
{

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

@ -178,7 +178,7 @@ interface nsIChannel : nsIRequest
* MIME type, wrong document type stored on a server, etc.) and the caller
* most likely wants to verify with the actual data.
*/
readonly attribute string contentType;
attribute string contentType;
/**
* Returns the length of the data assiciated with the channel if available.

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

@ -1087,6 +1087,18 @@ nsFileTransport::GetContentType(char * *aContentType)
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::SetContentType(const char *aContentType)
{
if (mContentType) {
nsCRT::free(mContentType);
}
mContentType = nsCRT::strdup(aContentType);
if (!mContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::GetContentLength(PRInt32 *aContentLength)
{

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

@ -273,6 +273,19 @@ nsInputStreamChannel::GetContentType(char * *aContentType)
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamChannel::SetContentType(const char *aContentType)
{
if (mContentType) {
nsCRT::free(mContentType);
}
mContentType = nsCRT::strdup(aContentType);
if (aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -1804,6 +1804,12 @@ nsSocketTransport::GetContentType(char * *aContentType)
return NS_ERROR_FAILURE; // XXX doesn't make sense for transports
}
NS_IMETHODIMP
nsSocketTransport::SetContentType(const char *aContentType)
{
return NS_ERROR_FAILURE; // XXX doesn't make sense for transports
}
NS_IMETHODIMP
nsSocketTransport::GetContentLength(PRInt32 *aContentLength)
{

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

@ -330,6 +330,15 @@ nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
return mFileTransport->GetContentType(aContentType) ;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::SetContentType(const char *aContentType)
{
if(!mFileTransport)
return NS_ERROR_FAILURE ;
return mFileTransport->SetContentType(aContentType) ;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -455,6 +455,14 @@ nsMemCacheChannel::GetContentType(char* *aContentType)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMemCacheChannel::SetContentType(const char *aContentType)
{
// Not required to be implemented, since it is implemented by cache manager
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMemCacheChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -366,6 +366,13 @@ nsDataChannel::GetContentType(char* *aContentType) {
return NS_OK;
}
NS_IMETHODIMP
nsDataChannel::SetContentType(const char *aContentType)
{
mContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP
nsDataChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -232,6 +232,14 @@ nsDateTimeChannel::GetContentType(char* *aContentType) {
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentType(const char *aContentType)
{
//It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -374,19 +374,28 @@ nsFileChannel::GetContentType(char * *aContentType)
{
nsresult rv = NS_OK;
if (mSpec.IsDirectory()) {
*aContentType = nsCRT::strdup("application/http-index-format");
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
else {
NS_WITH_SERVICE(nsIMIMEService, MIMEService, kMIMEServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
*aContentType = nsnull;
if (mContentType.IsEmpty()) {
if (mSpec.IsDirectory()) {
mContentType = "application/http-index-format";
}
else {
NS_WITH_SERVICE(nsIMIMEService, MIMEService, kMIMEServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = MIMEService->GetTypeFromURI(mURI, aContentType);
if (NS_SUCCEEDED(rv)) return rv;
}
rv = MIMEService->GetTypeFromURI(mURI, aContentType);
if (NS_SUCCEEDED(rv)) {
mContentType = *aContentType;
return rv;
}
}
if (mContentType.IsEmpty()) {
mContentType = UNKNOWN_MIME;
}
}
*aContentType = mContentType.ToNewCString();
*aContentType = nsCRT::strdup(UNKNOWN_MIME);
if (!*aContentType) {
return NS_ERROR_OUT_OF_MEMORY;
} else {
@ -394,6 +403,13 @@ nsFileChannel::GetContentType(char * *aContentType)
}
}
NS_IMETHODIMP
nsFileChannel::SetContentType(const char *aContentType)
{
mContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -33,16 +33,12 @@
#include "nsIURI.h"
#include "nsCOMPtr.h"
#include "nsIFileChannel.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsFileSpec.h"
#include "prlock.h"
#include "nsIEventQueueService.h"
#include "nsIPipe.h"
#include "nsILoadGroup.h"
#include "nsIStreamListener.h"
#include "nsCOMPtr.h"
#include "nsString.h"
class nsFileChannel : public nsIFileChannel,
public nsIStreamListener
@ -86,6 +82,7 @@ protected:
char* mCommand;
nsFileSpec mSpec;
nsCOMPtr<nsIChannel> mFileTransport;
nsCString mContentType;
PRUint32 mLoadAttributes;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsISupports> mOwner;

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

@ -31,7 +31,6 @@ interface nsIEventQueue;
interface nsPIFTPChannel : nsIChannel
{
void SetContentLength(in long aLength);
void SetContentType(in string aContentType);
void Stopped(in nsresult aStatus, in wstring aMsg);
};

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

@ -355,25 +355,35 @@ nsFTPChannel::GetContentType(char* *aContentType) {
if (!aContentType) return NS_ERROR_NULL_POINTER;
if (mContentType.Length()) {
*aContentType = mContentType.ToNewCString();
} else {
*aContentType = nsnull;
if (mContentType.IsEmpty()) {
NS_WITH_SERVICE(nsIMIMEService, MIMEService, kMIMEServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = MIMEService->GetTypeFromURI(mURL, aContentType);
if (NS_SUCCEEDED(rv)) {
mContentType = *aContentType;
} else {
mContentType = UNKNOWN_MIME;
rv = NS_OK;
*aContentType = nsCRT::strdup(UNKNOWN_MIME);
}
}
if (!*aContentType) {
*aContentType = mContentType.ToNewCString();
}
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::GetContentType() returned %s\n", *aContentType));
return rv;
}
NS_IMETHODIMP
nsFTPChannel::SetContentType(const char *aContentType)
{
mContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::GetContentLength(PRInt32 *aContentLength)
@ -448,12 +458,6 @@ nsFTPChannel::SetContentLength(PRInt32 aLength) {
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::SetContentType(const char *aContentType) {
mContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::Stopped(nsresult aStatus, const PRUnichar *aMsg) {
nsresult rv = NS_OK;

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

@ -330,6 +330,25 @@ nsHTTPChannel::GetContentType(char * *aContentType)
return rv;
}
NS_IMETHODIMP
nsHTTPChannel::SetContentType(const char *aContentType)
{
nsresult rv;
if (mResponse) {
rv = mResponse->SetContentType(aContentType);
} else {
//
// Do not allow the content-type to be set until a response has been
// received from the server...
//
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
nsHTTPChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -418,6 +418,19 @@ nsJARChannel::GetContentType(char* *aContentType)
return rv;
}
NS_IMETHODIMP
nsJARChannel::SetContentType(const char *aContentType)
{
if (mContentType) {
nsCRT::free(mContentType);
}
mContentType = nsCRT::strdup(aContentType);
if (!mContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentLength(PRInt32* aContentLength)
{

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

@ -499,6 +499,14 @@ nsResChannel::GetContentType(char * *aContentType)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsResChannel::SetContentType(const char *aContentType)
{
if (mResolvedChannel)
return mResolvedChannel->SetContentType(aContentType);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsResChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -220,6 +220,13 @@ nsCachedChromeChannel::GetContentType(char * *aContentType)
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentType(const char *aContentType)
{
// Do not allow the content-type to be changed.
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -302,6 +302,7 @@ public:
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }