b=128508 "freeze nsIChannel nsIRequest" r=gagan, sr=rpotts, a=asa

This commit is contained in:
darin%netscape.com 2002-03-20 22:50:33 +00:00
Родитель 93114688c3
Коммит 819ce1f98f
171 изменённых файлов: 1872 добавлений и 2120 удалений

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

@ -137,7 +137,7 @@ public:
NS_DECL_ISUPPORTS
// nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetName(nsACString &result) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
NS_IMETHOD GetStatus(nsresult *status) { *status = mStatus; return NS_OK; }
NS_IMETHOD Cancel(nsresult status) { mStatus = status; return NS_OK; }
@ -342,20 +342,35 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentType(char * *aContentType)
nsCachedChromeChannel::GetContentType(nsACString &aContentType)
{
*aContentType = nsCRT::strdup("mozilla.application/cached-xul");
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aContentType = NS_LITERAL_CSTRING("mozilla.application/cached-xul");
return NS_OK;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentType(const char *aContentType)
nsCachedChromeChannel::SetContentType(const nsACString &aContentType)
{
// Do not allow the content-type to be changed.
NS_NOTREACHED("don't do that");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentCharset(const nsACString &aContentCharset)
{
// Do not allow the content charset to be changed.
NS_NOTREACHED("don't do that");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -756,9 +756,10 @@ nsDocument::StartDocumentLoad(const char* aCommand,
if (aReset)
rv = Reset(aChannel, aLoadGroup);
nsXPIDLCString contentType;
if (NS_SUCCEEDED(aChannel->GetContentType(getter_Copies(contentType)))) {
nsXPIDLCString::const_iterator start, end, semicolon;
nsCAutoString contentType;
if (NS_SUCCEEDED(aChannel->GetContentType(contentType))) {
// XXX this is only necessary for viewsource:
nsACString::const_iterator start, end, semicolon;
contentType.BeginReading(start);
contentType.EndReading(end);
semicolon = start;
@ -769,10 +770,10 @@ nsDocument::StartDocumentLoad(const char* aCommand,
PRBool have_contentLanguage = PR_FALSE;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsXPIDLCString contentLanguage;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Content-Language",
getter_Copies(contentLanguage)))) {
mContentLanguage.AssignWithConversion(contentLanguage);
nsCAutoString contentLanguage;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Language"),
contentLanguage))) {
CopyASCIItoUCS2(contentLanguage, mContentLanguage); // XXX what's wrong w/ ASCII?
have_contentLanguage = PR_TRUE;
}
}

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

@ -2747,7 +2747,7 @@ nsRange::CreateContextualFragment(const nsAReadableString& aFragment,
}
if (NS_SUCCEEDED(result)) {
nsAutoString contentType;
nsCAutoString contentType;
nsIHTMLFragmentContentSink* sink;
result = NS_NewHTMLFragmentContentSink(&sink);
@ -2755,11 +2755,13 @@ nsRange::CreateContextualFragment(const nsAReadableString& aFragment,
parser->SetContentSink(sink);
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(document));
if (domnsDocument) {
domnsDocument->GetContentType(contentType);
nsAutoString buf;
domnsDocument->GetContentType(buf);
CopyUCS2toASCII(buf, contentType);
}
else {
// Who're we kidding. This only works for html.
contentType.Assign(NS_LITERAL_STRING("text/html"));
contentType = NS_LITERAL_CSTRING("text/html");
}
// If there's no JS or system JS running,

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

@ -637,7 +637,6 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
if (stringLen) {
nsAutoString characterSet, preferred;
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
nsCOMPtr<nsIHttpChannel> httpChannel;
nsCOMPtr<nsIChannel> channel;
nsCOMPtr<nsIRequest> req;
@ -646,14 +645,12 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_FAILED(rv)) return rv;
channel = do_QueryInterface(req);
httpChannel = do_QueryInterface(channel);
if (httpChannel) {
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (channel) {
nsCAutoString charsetVal;
rv = channel->GetContentCharset(charsetVal);
if (NS_SUCCEEDED(rv)) {
characterSet = NS_ConvertASCIItoUCS2(charsetheader);
characterSet = NS_ConvertASCIItoUCS2(charsetVal);
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {

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

@ -188,7 +188,7 @@ nsContentDLF::CreateInstance(const char* aCommand,
// where <orig_type> can be text/html, text/xml etc.
//
nsCAutoString strContentType; strContentType.Append(aContentType);
nsCAutoString strContentType(aContentType);
PRInt32 idx = strContentType.Find("; x-view-type=view-source", PR_TRUE, 0, -1);
if(idx != -1)
{ // Found "; x-view-type=view-source" param in content type.
@ -211,7 +211,7 @@ nsContentDLF::CreateInstance(const char* aCommand,
// It's a view-source. Reset channel's content type to the original
// type so as not to choke the parser when it asks the channel
// for the content type during the parse phase
aChannel->SetContentType(aContentType);
aChannel->SetContentType(nsDependentCString(aContentType));
aContentType=gHTMLTypes[0];
}

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

@ -65,10 +65,10 @@ nsContentHTTPStartup::Observe( nsISupports *aSubject,
nsCOMPtr<nsIHttpProtocolHandler> http(do_QueryInterface(aSubject));
if (NS_FAILED(rv)) return rv;
rv = http->SetProduct(PRODUCT_NAME);
rv = http->SetProduct(NS_LITERAL_CSTRING(PRODUCT_NAME));
if (NS_FAILED(rv)) return rv;
rv = http->SetProductSub((char*) PRODUCT_VERSION);
rv = http->SetProductSub(NS_LITERAL_CSTRING(PRODUCT_VERSION));
if (NS_FAILED(rv)) return rv;
return NS_OK;

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

@ -519,8 +519,8 @@ public:
NS_DECL_ISUPPORTS
// nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) {
*result = ToNewUnicode(NS_LITERAL_STRING("about:layout-dummy-request"));
NS_IMETHOD GetName(nsACString &result) {
result = NS_LITERAL_CSTRING("about:layout-dummy-request");
return NS_OK;
}
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@ -528,6 +528,10 @@ public:
NS_IMETHOD Cancel(nsresult status);
NS_IMETHOD Suspend(void) { return NS_OK; }
NS_IMETHOD Resume(void) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
// nsIChannel
NS_IMETHOD GetOriginalURI(nsIURI* *aOriginalURI) { *aOriginalURI = gURI; NS_ADDREF(*aOriginalURI); return NS_OK; }
@ -536,17 +540,15 @@ public:
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentType(nsACString &aContentType) { aContentType.Truncate(); return NS_OK; }
NS_IMETHOD SetContentType(const nsACString &aContentType) { return NS_OK; }
NS_IMETHOD GetContentCharset(nsACString &aContentCharset) { aContentCharset.Truncate(); return NS_OK; }
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
@ -4660,18 +4662,13 @@ HTMLContentSink::ProcessHTTPHeaders(nsIChannel* aChannel) {
if (httpchannel) {
const char *const headers[]={"link","default-style","content-base",0}; // add more http headers if you need
const char *const *name=headers;
nsXPIDLCString tmp;
nsCAutoString tmp;
while(*name) {
httpchannel->GetResponseHeader(*name, getter_Copies(tmp));
if(tmp.get()) {
nsAutoString value;
value.AssignWithConversion(tmp);
rv = httpchannel->GetResponseHeader(nsDependentCString(*name), tmp);
if (NS_SUCCEEDED(rv) && !tmp.IsEmpty()) {
nsCOMPtr<nsIAtom> key(dont_AddRef(NS_NewAtom(*name)));
ProcessHeaderData(key,value);
}
else {
rv=NS_ERROR_OUT_OF_MEMORY;
ProcessHeaderData(key,NS_ConvertASCIItoUCS2(tmp));
}
name++;
}//while
@ -4703,7 +4700,7 @@ HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aVa
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mWebShell);
if (reefer) {
rv = reefer->SetupRefreshURIFromHeader(baseURI, aValue);
rv = reefer->SetupRefreshURIFromHeader(baseURI, NS_ConvertUCS2toUTF8(aValue));
if (NS_FAILED(rv)) return rv;
}
} // END refresh
@ -4759,8 +4756,8 @@ HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aVa
const PRUnichar *header = 0;
(void)aHeader->GetUnicode(&header);
(void)httpChannel->SetResponseHeader(
NS_ConvertUCS2toUTF8(header).get(),
NS_ConvertUCS2toUTF8(aValue).get());
NS_ConvertUCS2toUTF8(header),
NS_ConvertUCS2toUTF8(aValue));
}
}
}
@ -5368,15 +5365,10 @@ HTMLContentSink::AddDummyParserRequest(void)
}
if (loadGroup) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mDummyParserRequest);
if (channel) {
rv = channel->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyParserRequest, nsnull);
if (NS_FAILED(rv)) return rv;
} else {
return NS_ERROR_FAILURE;
}
rv = mDummyParserRequest->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyParserRequest, nsnull);
if (NS_FAILED(rv)) return rv;
}
return rv;

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

@ -685,24 +685,24 @@ nsHTMLDocument::TryWeakDocTypeDefault(PRInt32& aCharsetSource,
}
PRBool
nsHTMLDocument::TryHttpHeaderCharset(nsIHttpChannel *aHttpChannel,
PRInt32& aCharsetSource,
nsAString& aCharset)
nsHTMLDocument::TryChannelCharset(nsIChannel *aChannel,
PRInt32& aCharsetSource,
nsAString& aCharset)
{
if(kCharsetFromHTTPHeader <= aCharsetSource)
if(kCharsetFromChannel <= aCharsetSource)
return PR_TRUE;
if (aHttpChannel) {
nsXPIDLCString charsetheader;
nsresult rv = aHttpChannel->GetCharset(getter_Copies(charsetheader));
if (aChannel) {
nsCAutoString charsetVal;
nsresult rv = aChannel->GetContentCharset(charsetVal);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_CreateInstance(kCharsetAliasCID, &rv));
if(calias) {
if (calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
if(NS_SUCCEEDED(rv)) {
aCharset = preferred;
aCharsetSource = kCharsetFromHTTPHeader;
aCharsetSource = kCharsetFromChannel;
return PR_TRUE;
}
}
@ -819,26 +819,22 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsXPIDLCString lastModHeader;
rv = httpChannel->GetResponseHeader("last-modified",
getter_Copies(lastModHeader));
nsCAutoString lastModHeader;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"),
lastModHeader);
if (NS_SUCCEEDED(rv)) {
lastModified.AssignWithConversion(NS_STATIC_CAST(const char*,
lastModHeader));
CopyASCIItoUCS2(lastModHeader, lastModified);
SetLastModified(lastModified);
}
nsXPIDLCString referrerHeader;
nsCAutoString referrerHeader;
// The misspelled key 'referer' is as per the HTTP spec
rv = httpChannel->GetRequestHeader("referer",
getter_Copies(referrerHeader));
rv = httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"),
referrerHeader);
if (NS_SUCCEEDED(rv)) {
nsAutoString referrer;
referrer.AssignWithConversion(referrerHeader);
SetReferrer(referrer);
SetReferrer(NS_ConvertASCIItoUCS2(referrerHeader));
}
mHttpChannel = httpChannel;
@ -966,10 +962,10 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (! TryUserForcedCharset(muCV, dcInfo, charsetSource, charset)) {
TryHintCharset(muCV, charsetSource, charset);
TryParentCharset(dcInfo, charsetSource, charset);
if (TryHttpHeaderCharset(httpChannel, charsetSource, charset)) {
// Use the header's charset.
if (TryChannelCharset(aChannel, charsetSource, charset)) {
// Use the channel's charset (e.g., charset from HTTP "Content-Type" header).
}
else if (nsCRT::strcasecmp("about", scheme.get()) && // don't try to access bookmarks for about:blank
else if (!scheme.Equals(NS_LITERAL_CSTRING("about")) && // don't try to access bookmarks for about:blank
TryBookmarkCharset(&urlSpec, charsetSource, charset)) {
// Use the bookmark's charset.
}
@ -2458,7 +2454,7 @@ nsHTMLDocument::Close()
mWriteLevel++;
result = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_STRING("text/html"), PR_FALSE,
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
PR_TRUE);
mWriteLevel--;
mIsWriting = 0;
@ -2521,9 +2517,9 @@ nsHTMLDocument::WriteCommon(const nsAReadableString& aText,
}
rv = mParser->Parse(text ,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_STRING("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
mWriteLevel--;

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

@ -68,7 +68,6 @@ class nsIURI;
class nsIMarkupDocumentViewer;
class nsIDocumentCharsetInfo;
class nsICacheEntryDescriptor;
class nsIHttpChannel;
class nsHTMLDocument : public nsMarkupDocument,
public nsIHTMLDocument,
@ -269,9 +268,9 @@ protected:
nsAString& aCharset);
static PRBool TryWeakDocTypeDefault(PRInt32& aCharsetSource,
nsAString& aCharset);
static PRBool TryHttpHeaderCharset(nsIHttpChannel *aHttpChannel,
PRInt32& aCharsetSource,
nsAString& aCharset);
static PRBool TryChannelCharset(nsIChannel *aChannel,
PRInt32& aCharsetSource,
nsAString& aCharset);
static PRBool TryUserDefaultCharset(nsIMarkupDocumentViewer* aMarkupDV,
PRInt32& aCharsetSource,
nsAString& aCharset);

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

@ -92,13 +92,9 @@ nsWyciwygChannel::GetInterface(const nsIID &aIID, void **aResult)
///////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsWyciwygChannel::GetName(PRUnichar**aName)
nsWyciwygChannel::GetName(nsACString &aName)
{
NS_ENSURE_ARG_POINTER(aName);
nsCAutoString spec;
mURI->GetSpec(spec);
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(spec));
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return mURI->GetSpec(aName);
}
NS_IMETHODIMP
@ -275,15 +271,27 @@ nsWyciwygChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
}
NS_IMETHODIMP
nsWyciwygChannel::GetContentType(char* *aContentType)
nsWyciwygChannel::GetContentType(nsACString &aContentType)
{
NS_ENSURE_ARG_POINTER(aContentType);
*aContentType = nsCRT::strdup(wyciwyg_TYPE);
aContentType = NS_LITERAL_CSTRING(wyciwyg_TYPE);
return NS_OK;
}
NS_IMETHODIMP
nsWyciwygChannel::SetContentType(const char *aContentType)
nsWyciwygChannel::SetContentType(const nsACString &aContentType)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWyciwygChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsWyciwygChannel::SetContentCharset(const nsACString &aContentCharset)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -620,20 +620,19 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
if (aString && aStringLen>0) {
nsCOMPtr<nsIRequest> request;
aLoader->GetRequest(getter_AddRefs(request));
nsXPIDLCString contentType;
nsCAutoString contentType;
if (! (mLoader->mNavQuirkMode)) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(getter_Copies(contentType));
channel->GetContentType(contentType);
}
}
if (mLoader->mNavQuirkMode ||
contentType.Equals(NS_LITERAL_CSTRING("text/css"),
nsCaseInsensitiveCStringComparator()) ||
contentType.Equals(NS_LITERAL_CSTRING("text/css")) ||
contentType.IsEmpty()) {
/*
* First determine the charset (if one is indicated)
* 1) Check HTTP charset
* 1) Check nsIChannel::contentCharset
* 2) Check @charset rules
* 3) Check "charset" attribute of the <LINK> or <?xml-stylesheet?>
*
@ -641,16 +640,16 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
* default (document charset or ISO-8859-1 if we have no document
* charset)
*/
nsAutoString strHTTPCharset;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
if (httpChannel) {
nsXPIDLCString httpCharset;
httpChannel->GetCharset(getter_Copies(httpCharset));
CopyASCIItoUCS2(httpCharset, strHTTPCharset);
nsAutoString strChannelCharset;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
CopyASCIItoUCS2(charsetVal, strChannelCharset);
}
result = NS_ERROR_NOT_AVAILABLE;
if (! strHTTPCharset.IsEmpty()) {
result = mLoader->SetCharset(strHTTPCharset);
if (! strChannelCharset.IsEmpty()) {
result = mLoader->SetCharset(strChannelCharset);
}
if (NS_FAILED(result)) {
// We have no charset or the HTTP charset is not recognized.

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

@ -783,7 +783,7 @@ nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aV
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mWebShell);
if (reefer) {
rv = reefer->SetupRefreshURIFromHeader(baseURI, aValue);
rv = reefer->SetupRefreshURIFromHeader(baseURI, NS_ConvertUCS2toUTF8(aValue));
if (NS_FAILED(rv)) return rv;
}
} // END refresh

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

@ -433,23 +433,22 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
aContentType = nsnull;
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if(httpChannel) {
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
{ // check channel's charset...
nsCAutoString charsetVal;
rv = aChannel->GetContentCharset(charsetVal);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && (nsnull != calias) ) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
if(NS_SUCCEEDED(rv)){
charset = preferred;
charsetSource = kCharsetFromHTTPHeader;
charsetSource = kCharsetFromChannel;
}
}
}
} //end of checking http channel
} //end of checking channel's charset
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);

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

@ -326,7 +326,7 @@ public:
NS_DECL_ISUPPORTS
// nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) {
NS_IMETHOD GetName(nsACString &result) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@ -334,6 +334,10 @@ public:
NS_IMETHOD Cancel(nsresult status) { return NS_OK; }
NS_IMETHOD Suspend(void) { return NS_OK; }
NS_IMETHOD Resume(void) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
// nsIChannel
NS_IMETHOD GetOriginalURI(nsIURI* *aOriginalURI) { *aOriginalURI = gURI; NS_ADDREF(*aOriginalURI); return NS_OK; }
@ -342,17 +346,15 @@ public:
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentType(nsACString &aContentType) { aContentType.Truncate(); return NS_OK; }
NS_IMETHOD SetContentType(const nsACString &aContentType) { return NS_OK; }
NS_IMETHOD GetContentCharset(nsACString &aContentCharset) { aContentCharset.Truncate(); return NS_OK; }
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
@ -736,11 +738,10 @@ nsXULDocument::StartDocumentLoad(const char* aCommand,
// StartDocumentLoad() before the channel's content type has been
// detected.
nsXPIDLCString contentType;
aChannel->GetContentType(getter_Copies(contentType));
nsCAutoString contentType;
aChannel->GetContentType(contentType);
if (contentType &&
PL_strcmp(contentType, "mozilla.application/cached-xul") == 0) {
if (contentType.Equals(NS_LITERAL_CSTRING("mozilla.application/cached-xul"))) {
// Look in the chrome cache: we've got this puppy loaded
// already.
nsCOMPtr<nsIXULPrototypeDocument> proto;
@ -5582,8 +5583,7 @@ nsXULDocument::PrepareToWalk()
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
if (group) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mPlaceHolderRequest);
rv = channel->SetLoadGroup(group);
rv = mPlaceHolderRequest->SetLoadGroup(group);
if (NS_FAILED(rv)) return rv;
rv = group->AddRequest(mPlaceHolderRequest, nsnull);
if (NS_FAILED(rv)) return rv;

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

@ -154,13 +154,12 @@ nsLDAPChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
// nsIRequest methods
NS_IMETHODIMP
nsLDAPChannel::GetName(PRUnichar* *result)
nsLDAPChannel::GetName(nsACString &result)
{
nsCAutoString name;
if (mURI)
mURI->GetSpec(name);
*result = ToNewUnicode(NS_ConvertUTF8toUCS2(name));
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return mURI->GetSpec(result);
result.Truncate();
return NS_OK;
}
NS_IMETHODIMP
@ -312,27 +311,33 @@ nsLDAPChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
// most likely wants to verify with the actual data.
//
NS_IMETHODIMP
nsLDAPChannel::GetContentType(char* *aContentType)
nsLDAPChannel::GetContentType(nsACString &aContentType)
{
if (!aContentType) {
return NS_ERROR_ILLEGAL_VALUE;
}
*aContentType = nsCRT::strdup(TEXT_PLAIN);
if (!*aContentType) {
return NS_ERROR_OUT_OF_MEMORY;
} else {
return NS_OK;
}
aContentType = NS_LITERAL_CSTRING(TEXT_PLAIN);
return NS_OK;
}
NS_IMETHODIMP
nsLDAPChannel::SetContentType(const char *contenttype)
nsLDAPChannel::SetContentType(const nsACString &aContentType)
{
NS_NOTYETIMPLEMENTED("nsLDAPChannel::SetContentType");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsLDAPChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsLDAPChannel::SetContentCharset(const nsACString &aContentCharset)
{
NS_NOTYETIMPLEMENTED("nsLDAPChannel::SetContentCharset");
return NS_ERROR_NOT_IMPLEMENTED;
}
// getter and setter for contentLength attribute:
//
// Returns the length of the data associated with the channel if available.

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

@ -697,7 +697,9 @@ nsDocShell::LoadStream(nsIInputStream * aStream, nsIURI * aURI,
// build up a channel for this stream.
nsCOMPtr<nsIChannel> channel;
NS_ENSURE_SUCCESS(NS_NewInputStreamChannel
(getter_AddRefs(channel), uri, aStream, aContentType,
(getter_AddRefs(channel), uri, aStream,
nsDependentCString(aContentType),
NS_LITERAL_CSTRING(""),
aContentLen), NS_ERROR_FAILURE);
nsCOMPtr<nsIURILoader>
@ -3332,7 +3334,7 @@ nsDocShell::RefreshURI(nsIURI * aURI, PRInt32 aDelay, PRBool aRepeat, PRBool aMe
nsresult
nsDocShell::SetupRefreshURIFromHeader(nsIURI * aBaseURI,
const nsAReadableString & aHeader)
const nsACString & aHeader)
{
// Refresh headers are parsed with the following format in mind
// <META HTTP-EQUIV=REFRESH CONTENT="5; URL=http://uri">
@ -3373,10 +3375,10 @@ nsDocShell::SetupRefreshURIFromHeader(nsIURI * aBaseURI,
// when done, seconds is 0 or the given number of seconds
// uriAttrib is empty or the URI specified
nsAutoString uriAttrib;
nsCAutoString uriAttrib;
PRInt32 seconds = 0;
nsReadingIterator < PRUnichar > iter, tokenStart, doneIterating;
nsACString::const_iterator iter, tokenStart, doneIterating;
aHeader.BeginReading(iter);
aHeader.EndReading(doneIterating);
@ -3511,13 +3513,12 @@ NS_IMETHODIMP nsDocShell::SetupRefreshURI(nsIChannel * aChannel)
if (NS_SUCCEEDED(rv)) {
SetReferrerURI(referrer);
nsXPIDLCString refreshHeader;
rv = httpChannel->GetResponseHeader("refresh",
getter_Copies(refreshHeader));
nsCAutoString refreshHeader;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("refresh"),
refreshHeader);
if (refreshHeader)
rv = SetupRefreshURIFromHeader(mCurrentURI,
NS_ConvertUTF8toUCS2(refreshHeader));
if (!refreshHeader.IsEmpty())
rv = SetupRefreshURIFromHeader(mCurrentURI, refreshHeader);
}
}
return rv;
@ -4899,7 +4900,7 @@ nsDocShell::AddHeadersToChannel(nsIInputStream * aHeadersData,
// FINALLY: we can set the header!
//
rv = aChannel->SetRequestHeader(headerName.get(), headerValue.get());
rv = aChannel->SetRequestHeader(headerName, headerValue);
if (NS_FAILED(rv)) {
return NS_ERROR_NULL_POINTER;
}

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

@ -4989,10 +4989,9 @@ NavigatorImpl::GetUserAgent(nsAWritableString& aUserAgent)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *ua = nsnull;
res = service->GetUserAgent(&ua);
aUserAgent = NS_ConvertASCIItoUCS2(ua);
Recycle(ua);
nsCAutoString ua;
res = service->GetUserAgent(ua);
CopyASCIItoUCS2(ua, aUserAgent);
}
return res;
@ -5005,10 +5004,9 @@ NavigatorImpl::GetAppCodeName(nsAWritableString& aAppCodeName)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *appName = nsnull;
res = service->GetAppName(&appName);
aAppCodeName = NS_ConvertASCIItoUCS2(appName);
Recycle(appName);
nsCAutoString appName;
res = service->GetAppName(appName);
CopyASCIItoUCS2(appName, aAppCodeName);
}
return res;
@ -5021,26 +5019,23 @@ NavigatorImpl::GetAppVersion(nsAWritableString& aAppVersion)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *str = nsnull;
res = service->GetAppVersion(&str);
aAppVersion = NS_ConvertASCIItoUCS2(str);
Recycle(str);
nsCAutoString str;
res = service->GetAppVersion(str);
CopyASCIItoUCS2(str, aAppVersion);
aAppVersion.Append(NS_LITERAL_STRING(" ("));
res = service->GetPlatform(&str);
res = service->GetPlatform(str);
if (NS_FAILED(res))
return res;
aAppVersion += NS_ConvertASCIItoUCS2(str);
Recycle(str);
aAppVersion.Append(NS_LITERAL_STRING("; "));
res = service->GetLanguage(&str);
res = service->GetLanguage(str);
if (NS_FAILED(res))
return res;
aAppVersion += NS_ConvertASCIItoUCS2(str);
Recycle(str);
aAppVersion.Append(PRUnichar(')'));
}
@ -5062,10 +5057,9 @@ NavigatorImpl::GetLanguage(nsAWritableString& aLanguage)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *lang = nsnull;
res = service->GetLanguage(&lang);
aLanguage = NS_ConvertASCIItoUCS2(lang);
Recycle(lang);
nsCAutoString lang;
res = service->GetLanguage(lang);
CopyASCIItoUCS2(lang, aLanguage);
}
return res;
@ -5091,10 +5085,9 @@ NavigatorImpl::GetPlatform(nsAWritableString& aPlatform)
// XXX Communicator uses compiled-in build-time string defines
// to indicate the platform it was compiled *for*, not what it is
// currently running *on* which is what this does.
char *plat = nsnull;
res = service->GetOscpu(&plat);
aPlatform = NS_ConvertASCIItoUCS2(plat);
Recycle(plat);
nsCAutoString plat;
res = service->GetOscpu(plat);
CopyASCIItoUCS2(plat, aPlatform);
#endif
}
@ -5108,10 +5101,9 @@ NavigatorImpl::GetOscpu(nsAWritableString& aOSCPU)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *oscpu = nsnull;
res = service->GetOscpu(&oscpu);
aOSCPU = NS_ConvertASCIItoUCS2(oscpu);
Recycle(oscpu);
nsCAutoString oscpu;
res = service->GetOscpu(oscpu);
CopyASCIItoUCS2(oscpu, aOSCPU);
}
return res;
@ -5124,10 +5116,9 @@ NavigatorImpl::GetVendor(nsAWritableString& aVendor)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *vendor = nsnull;
res = service->GetVendor(&vendor);
aVendor = NS_ConvertASCIItoUCS2(vendor);
Recycle(vendor);
nsCAutoString vendor;
res = service->GetVendor(vendor);
CopyASCIItoUCS2(vendor, aVendor);
}
return res;
@ -5141,10 +5132,9 @@ NavigatorImpl::GetVendorSub(nsAWritableString& aVendorSub)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *vendor = nsnull;
res = service->GetVendorSub(&vendor);
aVendorSub = NS_ConvertASCIItoUCS2(vendor);
Recycle(vendor);
nsCAutoString vendor;
res = service->GetVendorSub(vendor);
CopyASCIItoUCS2(vendor, aVendorSub);
}
return res;
@ -5157,10 +5147,9 @@ NavigatorImpl::GetProduct(nsAWritableString& aProduct)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *product = nsnull;
res = service->GetProduct(&product);
aProduct = NS_ConvertASCIItoUCS2(product);
Recycle(product);
nsCAutoString product;
res = service->GetProduct(product);
CopyASCIItoUCS2(product, aProduct);
}
return res;
@ -5173,10 +5162,9 @@ NavigatorImpl::GetProductSub(nsAWritableString& aProductSub)
nsCOMPtr<nsIHttpProtocolHandler>
service(do_GetService(kHTTPHandlerCID, &res));
if (NS_SUCCEEDED(res) && service) {
char *productSub = nsnull;
res = service->GetProductSub(&productSub);
aProductSub = NS_ConvertASCIItoUCS2(productSub);
Recycle(productSub);
nsCAutoString productSub;
res = service->GetProductSub(productSub);
CopyASCIItoUCS2(productSub, aProductSub);
}
return res;

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

@ -335,7 +335,13 @@ nsresult nsJSThunk::BringUpConsole()
// nsIStreamIO implementation...
//
NS_IMETHODIMP
nsJSThunk::Open(PRInt32 *contentLength)
nsJSThunk::Open()
{
return NS_OK;
}
NS_IMETHODIMP
nsJSThunk::GetContentType(nsACString &aContentType)
{
//
// At this point the script has already been evaluated...
@ -343,20 +349,22 @@ nsJSThunk::Open(PRInt32 *contentLength)
//
// If the resultant script evaluation actually does return a value, we
// treat it as html.
*contentLength = mLength;
//
aContentType = NS_LITERAL_CSTRING("text/html");
return NS_OK;
}
NS_IMETHODIMP
nsJSThunk::GetContentType(char * *aContentType)
NS_IMETHODIMP
nsJSThunk::GetContentCharset(nsACString &aContentCharset)
{
*aContentType = nsCRT::strdup("text/html");
if (*aContentType == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsJSThunk::GetContentLength(PRInt32 *result)
{
*result = mLength;
return NS_OK;
}
@ -398,15 +406,9 @@ nsJSThunk::GetOutputStream(nsIOutputStream* *aOutputStream)
}
NS_IMETHODIMP
nsJSThunk::GetName(char* *aName)
nsJSThunk::GetName(nsACString &aName)
{
nsCAutoString buf;
nsresult rv = mURI->GetSpec(buf);
if (NS_FAILED(rv)) return rv;
*aName = ToNewCString(buf);
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return mURI->GetSpec(aName);
}
@ -494,7 +496,7 @@ NS_INTERFACE_MAP_END
//
NS_IMETHODIMP
nsJSChannel::GetName(PRUnichar * *aResult)
nsJSChannel::GetName(nsACString &aResult)
{
return mStreamChannel->GetName(aResult);
}
@ -675,17 +677,29 @@ nsJSChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
}
NS_IMETHODIMP
nsJSChannel::GetContentType(char * *aContentType)
nsJSChannel::GetContentType(nsACString &aContentType)
{
return mStreamChannel->GetContentType(aContentType);
}
NS_IMETHODIMP
nsJSChannel::SetContentType(const char *aContentType)
nsJSChannel::SetContentType(const nsACString &aContentType)
{
return mStreamChannel->SetContentType(aContentType);
}
NS_IMETHODIMP
nsJSChannel::GetContentCharset(nsACString &aContentCharset)
{
return mStreamChannel->GetContentCharset(aContentCharset);
}
NS_IMETHODIMP
nsJSChannel::SetContentCharset(const nsACString &aContentCharset)
{
return mStreamChannel->SetContentCharset(aContentCharset);
}
NS_IMETHODIMP
nsJSChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -4580,14 +4580,14 @@ nsEditorShell::OnSecurityChange(nsIWebProgress *aWebProgress,
nsresult nsEditorShell::StartPageLoad(nsIChannel *aChannel)
{
nsXPIDLCString contentType;
aChannel->GetContentType(getter_Copies(contentType));
nsCAutoString contentType;
aChannel->GetContentType(contentType);
// save the original MIME type; we'll use it later
if (contentType.get())
if (!contentType.IsEmpty())
mContentMIMEType.Assign(contentType);
if (nsCRT::strcmp(contentType, "text/html") == 0)
if (contentType.Equals(NS_LITERAL_CSTRING("text/html")))
{
// fine, do nothing
mContentTypeKnown = PR_TRUE;
@ -4595,11 +4595,11 @@ nsresult nsEditorShell::StartPageLoad(nsIChannel *aChannel)
else
{
PRBool canBeText;
IsSupportedTextType(contentType, &canBeText);
IsSupportedTextType(contentType.get(), &canBeText);
if (canBeText)
{
// set the mime type to text/plain so that it renders as text
aChannel->SetContentType("text/plain");
aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
mContentTypeKnown = PR_TRUE;
}
else
@ -4669,10 +4669,10 @@ nsresult nsEditorShell::EndPageLoad(nsIDOMWindow *aDOMWindow,
// if we didn't get the content-type at the start of the load, get it now
if (!mContentTypeKnown)
{
nsXPIDLCString contentType;
aChannel->GetContentType(getter_Copies(contentType));
nsCAutoString contentType;
aChannel->GetContentType(contentType);
if (contentType.get())
if (!contentType.IsEmpty())
mContentMIMEType.Assign(contentType);
}
}

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

@ -117,7 +117,8 @@ EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
// create a new input stream channel
rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), uri,
NS_STATIC_CAST(nsIInputStream *, this),
aContentType,
nsDependentCString(aContentType),
NS_LITERAL_CSTRING(""),
1024); /* len */
if (NS_FAILED(rv))
return rv;

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

@ -700,8 +700,8 @@ NS_IMETHODIMP nsWebBrowserPersist::OnDataAvailable(
if ((channelContentLength - (aOffset + aLength)) == 0)
{
// we're done with this pass; see if we need to do upload
nsXPIDLCString contentType;
channel->GetContentType(getter_Copies(contentType));
nsCAutoString contentType;
channel->GetContentType(contentType);
// if we don't have the right type of output stream then it's a local file
nsCOMPtr<nsIStorageStream> storStream(do_QueryInterface(data->mStream));
if (storStream)
@ -1455,17 +1455,20 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
NS_ENSURE_TRUE(mMIMEService, NS_ERROR_FAILURE);
}
nsXPIDLCString contentType;
nsCAutoString contentType;
// Get the content type from the channel
aChannel->GetContentType(getter_Copies(contentType));
aChannel->GetContentType(contentType);
// Get the content type from the MIME service
if (contentType.Length() == 0)
{
nsCOMPtr<nsIURI> uri;
aChannel->GetOriginalURI(getter_AddRefs(uri));
rv = mMIMEService->GetTypeFromURI(uri, getter_Copies(contentType));
nsXPIDLCString mimeType;
rv = mMIMEService->GetTypeFromURI(uri, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
contentType = mimeType;
}
// Append the extension onto the file

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

@ -47,7 +47,8 @@
#include "nsCookie.h"
#include "nsIURL.h"
#include "nsCRT.h"
#include "nsXPIDLString.h"
#include "nsLiteralString.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsINetModuleMgr.h"
#include "nsILoadGroup.h"
@ -179,12 +180,12 @@ nsCookieHTTPNotify::OnModifyRequest(nsIHttpChannel *aHttpChannel)
if (NS_FAILED(rv)) return rv;
// Clear any existing Cookie request header
rv = aHttpChannel->SetRequestHeader("Cookie", nsnull);
rv = aHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cookie"), NS_LITERAL_CSTRING(""));
if (NS_FAILED(rv)) return rv;
// Set the cookie into the request headers
if (cookie && *cookie)
rv = aHttpChannel->SetRequestHeader("Cookie", cookie);
rv = aHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cookie"), nsDependentCString(cookie));
nsMemory::Free((void *)cookie);
return rv;
@ -198,10 +199,10 @@ nsCookieHTTPNotify::OnExamineResponse(nsIHttpChannel *aHttpChannel)
NS_ENSURE_ARG_POINTER(aHttpChannel);
// Get the Cookie header
nsXPIDLCString cookieHeader;
rv = aHttpChannel->GetResponseHeader("Set-Cookie", getter_Copies(cookieHeader));
nsCAutoString cookieHeader;
rv = aHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Set-Cookie"), cookieHeader);
if (NS_FAILED(rv)) return rv;
if (!cookieHeader) return NS_OK; // not an error, there's just no header.
if (cookieHeader.IsEmpty()) return NS_OK; // not an error, there's just no header.
// Get the url
nsCOMPtr<nsIURI> pURL;
@ -235,8 +236,8 @@ nsCookieHTTPNotify::OnExamineResponse(nsIHttpChannel *aHttpChannel)
pInterfaces->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(pPrompter));
// Get the expires
nsXPIDLCString dateHeader;
rv = aHttpChannel->GetResponseHeader("Date", getter_Copies(dateHeader));
nsCAutoString dateHeader;
rv = aHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Date"), dateHeader);
// NS_ERROR_NOT_AVAILABLE is not a fatal error, other errors are
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) return rv;
@ -245,7 +246,7 @@ nsCookieHTTPNotify::OnExamineResponse(nsIHttpChannel *aHttpChannel)
if (NS_FAILED(rv)) return rv;
// Save the cookie
rv = mCookieService->SetCookieStringFromHttp(pURL, pFirstURL, pPrompter, cookieHeader, dateHeader, aHttpChannel);
rv = mCookieService->SetCookieStringFromHttp(pURL, pFirstURL, pPrompter, cookieHeader.get(), dateHeader.get(), aHttpChannel);
return rv;
}

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

@ -102,7 +102,7 @@ nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult
// nsIRequest methods:
NS_IMETHODIMP
nsDateTimeChannel::GetName(PRUnichar* *result)
nsDateTimeChannel::GetName(nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -243,22 +243,34 @@ nsDateTimeChannel::SetLoadFlags(PRUint32 aLoadFlags)
#define DATETIME_TYPE "text/plain"
NS_IMETHODIMP
nsDateTimeChannel::GetContentType(char* *aContentType) {
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup(DATETIME_TYPE);
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
nsDateTimeChannel::GetContentType(nsACString &aContentType)
{
aContentType = NS_LITERAL_CSTRING(DATETIME_TYPE);
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentType(const char *aContentType)
nsDateTimeChannel::SetContentType(const nsACString &aContentType)
{
//It doesn't make sense to set the content-type on this type
// It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentCharset(const nsACString &aContentCharset)
{
NS_NOTREACHED("nsDateTimeChannel::SetContentCharset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -113,7 +113,7 @@ nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
// nsIRequest methods:
NS_IMETHODIMP
nsFingerChannel::GetName(PRUnichar* *result)
nsFingerChannel::GetName(nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -251,22 +251,34 @@ nsFingerChannel::SetLoadFlags(PRUint32 aLoadFlags)
#define FINGER_TYPE TEXT_HTML
NS_IMETHODIMP
nsFingerChannel::GetContentType(char* *aContentType) {
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup(FINGER_TYPE);
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
nsFingerChannel::GetContentType(nsACString &aContentType)
{
aContentType = NS_LITERAL_CSTRING(FINGER_TYPE);
return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::SetContentType(const char *aContentType)
nsFingerChannel::SetContentType(const nsACString &aContentType)
{
//It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsFingerChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::SetContentCharset(const nsACString &aContentCharset)
{
NS_NOTREACHED("nsFingerChannel::SetContentCharset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFingerChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -62,7 +62,7 @@ inBitmapChannel::Init(nsIURI* uri)
// nsIRequest
NS_IMETHODIMP
inBitmapChannel::GetName(PRUnichar* *result)
inBitmapChannel::GetName(nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -196,17 +196,24 @@ NS_IMETHODIMP inBitmapChannel::SetLoadFlags(PRUint32 aLoadAttributes)
return NS_OK;
}
NS_IMETHODIMP inBitmapChannel::GetContentType(char* *aContentType)
NS_IMETHODIMP inBitmapChannel::GetContentType(nsACString &aContentType)
{
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup("image/inspector-bitmap");
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
aContentType = NS_LITERAL_CSTRING("image/inspector-bitmap");
return NS_OK;
}
NS_IMETHODIMP
inBitmapChannel::SetContentType(const char *aContentType)
NS_IMETHODIMP inBitmapChannel::SetContentType(const nsACString &aContentType)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP inBitmapChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP inBitmapChannel::SetContentCharset(const nsACString &aContentCharset)
{
return NS_ERROR_FAILURE;
}

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

@ -126,10 +126,10 @@ nsP3PService::ProcessResponseHeader(nsIHttpChannel* aHttpChannel)
nsresult result = NS_OK;
nsXPIDLCString p3pHeader;
aHttpChannel->GetResponseHeader("P3P",getter_Copies(p3pHeader));
nsCAutoString p3pHeader;
aHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("P3P"), p3pHeader);
if (p3pHeader) {
if (!p3pHeader.IsEmpty()) {
nsCOMPtr<nsIURI> uri;
aHttpChannel->GetURI(getter_AddRefs(uri));
@ -139,10 +139,10 @@ nsP3PService::ProcessResponseHeader(nsIHttpChannel* aHttpChannel)
NS_ENSURE_TRUE(mCompactPolicy,NS_ERROR_OUT_OF_MEMORY);
}
nsXPIDLCString spec;
nsCAutoString spec;
uri->GetSpec(spec);
result = mCompactPolicy->OnHeaderAvailable(p3pHeader,spec);
result = mCompactPolicy->OnHeaderAvailable(p3pHeader.get(), spec.get());
}
}

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

@ -570,7 +570,7 @@ void txMozillaXMLOutput::processHTTPEquiv(nsIAtom* aHeader, nsAReadableString& a
// For now we only handle "refresh". There's a longer list in
// HTMLContentSink::ProcessHeaderData
if (aHeader == txHTMLAtoms::refresh)
mRefreshString.Assign(aValue);
CopyUCS2toASCII(aValue, mRefreshString);
}
void txMozillaXMLOutput::wrapChildren(nsIDOMNode* aCurrentNode,

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

@ -174,7 +174,7 @@ private:
nsCOMPtr<nsIDOMNode> mNonAddedNode;
PRInt32 mStyleSheetCount;
nsAutoString mRefreshString;
nsCString mRefreshString;
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager;

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

@ -119,7 +119,7 @@ NS_IMPL_ISUPPORTS2(nsDOMParserChannel,
nsIRequest)
/* boolean isPending (); */
NS_IMETHODIMP nsDOMParserChannel::GetName(PRUnichar* *result)
NS_IMETHODIMP nsDOMParserChannel::GetName(nsACString &result)
{
NS_NOTREACHED("nsDOMParserChannel::GetName");
return NS_ERROR_NOT_IMPLEMENTED;
@ -188,20 +188,29 @@ NS_IMETHODIMP nsDOMParserChannel::GetURI(nsIURI * *aURI)
return NS_OK;
}
/* attribute string contentType; */
NS_IMETHODIMP nsDOMParserChannel::GetContentType(char * *aContentType)
/* attribute ACString contentType; */
NS_IMETHODIMP nsDOMParserChannel::GetContentType(nsACString &aContentType)
{
NS_ENSURE_ARG_POINTER(aContentType);
*aContentType = ToNewCString(mContentType);
aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP nsDOMParserChannel::SetContentType(const char * aContentType)
NS_IMETHODIMP nsDOMParserChannel::SetContentType(const nsACString &aContentType)
{
NS_ENSURE_ARG(aContentType);
mContentType.Assign(aContentType);
mContentType = aContentType;
return NS_OK;
}
/* attribute ACString contentCharset; */
NS_IMETHODIMP nsDOMParserChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsDOMParserChannel::SetContentCharset(const nsACString &aContentCharset)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long contentLength; */
NS_IMETHODIMP nsDOMParserChannel::GetContentLength(PRInt32 *aContentLength)
{

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

@ -48,6 +48,7 @@
#include "nsIPrivateDOMImplementation.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsPrintfCString.h"
#include "nsIURI.h"
#include "nsILoadGroup.h"
#include "nsNetUtil.h"
@ -335,18 +336,15 @@ nsXMLHttpRequest::DetectCharset(nsAWritableString& aCharset)
{
aCharset.Truncate();
nsresult rv;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel,&rv));
if(httpChannel) {
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
if(NS_SUCCEEDED(rv)) {
aCharset.Assign(preferred);
}
nsCAutoString charsetVal;
rv = mChannel->GetContentCharset(charsetVal);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
if(NS_SUCCEEDED(rv)) {
aCharset.Assign(preferred);
}
}
}
@ -479,10 +477,15 @@ nsXMLHttpRequest::GetStatusText(char * *aStatusText)
NS_ENSURE_ARG_POINTER(aStatusText);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (httpChannel) {
return httpChannel->GetResponseStatusText(aStatusText);
}
*aStatusText = nsnull;
if (httpChannel) {
nsCAutoString text;
nsresult rv = httpChannel->GetResponseStatusText(text);
if (NS_FAILED(rv)) return rv;
*aStatusText = ToNewCString(text);
return *aStatusText ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
@ -535,8 +538,13 @@ nsXMLHttpRequest::GetResponseHeader(const char *header, char **_retval)
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
*_retval = nsnull;
if (httpChannel)
return httpChannel->GetResponseHeader(header, _retval);
if (httpChannel) {
nsCAutoString buf;
nsresult rv = httpChannel->GetResponseHeader(nsDependentCString(header), buf);
if (NS_FAILED(rv)) return rv;
*_retval = ToNewCString(buf);
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
@ -584,7 +592,7 @@ nsXMLHttpRequest::OpenRequest(const char *method,
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (httpChannel) {
rv = httpChannel->SetRequestMethod(method);
rv = httpChannel->SetRequestMethod(nsDependentCString(method));
}
ChangeState(XML_HTTP_REQUEST_OPENED);
@ -719,14 +727,13 @@ nsXMLHttpRequest::GetStreamForWString(const PRUnichar* aStr,
}
// If no content type header was set by the client, we set it to text/xml.
nsXPIDLCString header;
if( NS_OK != httpChannel->GetRequestHeader("Content-Type", getter_Copies(header)) )
httpChannel->SetRequestHeader("Content-Type", "text/xml" );
nsCAutoString header;
if( NS_FAILED(httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), header)) )
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"),
NS_LITERAL_CSTRING("text/xml") );
// set the content length header
char charLengthBuf [32];
PR_snprintf(charLengthBuf, sizeof(charLengthBuf), "%d", charLength);
httpChannel->SetRequestHeader("Content-Length", charLengthBuf );
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), nsPrintfCString("%d", charLength) );
// Shove in the trailing and leading CRLF
postData[0] = nsCRT::CR;
@ -822,7 +829,7 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
request->GetStatus(&status);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel && NS_SUCCEEDED(status)) {
channel->SetContentType(mOverrideMimeType.get());
channel->SetContentType(mOverrideMimeType);
}
}
return mXMLParserStreamListener->OnStartRequest(request,ctxt);
@ -975,14 +982,14 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
}
// Ignore argument if method is GET, there is no point in trying to upload anything
nsXPIDLCString method;
nsCAutoString method;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (httpChannel) {
httpChannel->GetRequestMethod(getter_Copies(method)); // If GET, method name will be uppercase
httpChannel->GetRequestMethod(method); // If GET, method name will be uppercase
}
if (aBody && httpChannel && nsCRT::strcmp("GET", method.get()) != 0) {
if (aBody && httpChannel && !method.Equals(NS_LITERAL_CSTRING("GET"))) {
nsXPIDLString serial;
nsCOMPtr<nsIInputStream> postDataStream;
@ -1204,7 +1211,8 @@ nsXMLHttpRequest::SetRequestHeader(const char *header, const char *value)
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (httpChannel)
return httpChannel->SetRequestHeader(header, value);
return httpChannel->SetRequestHeader(nsDependentCString(header),
nsDependentCString(value));
return NS_OK;
}
@ -1385,7 +1393,7 @@ nsXMLHttpRequest::ChangeState(nsXMLHttpRequestState aState, PRBool aBroadcast)
NS_IMPL_ISUPPORTS1(nsXMLHttpRequest::nsHeaderVisitor, nsIHttpHeaderVisitor)
NS_IMETHODIMP nsXMLHttpRequest::
nsHeaderVisitor::VisitHeader(const char *header, const char *value)
nsHeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value)
{
mHeaders.Append(header);
mHeaders.Append(": ");

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

@ -209,7 +209,9 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindowInternal* aDOMWindow,
result = NS_NewInputStreamChannel(getter_AddRefs(mChannel),
uri,
inputStream,
contentType, contentLength);
nsDependentCString(contentType),
NS_LITERAL_CSTRING(""),
contentLength);
if (NS_FAILED(result))
return result;

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

@ -104,7 +104,7 @@ enum eParserDocType {
#define kCharsetFromAutoDetection 7
#define kCharsetFromMetaTag 8
#define kCharsetFromByteOrderMark 9
#define kCharsetFromHTTPHeader 10
#define kCharsetFromChannel 10
#define kCharsetFromParentForced 11
#define kCharsetFromUserForced 12
#define kCharsetFromOtherComponent 13
@ -230,8 +230,8 @@ class nsIParser : public nsISupports {
virtual PRBool IsComplete() =0;
virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0;
virtual nsresult Parse(nsIInputStream& aStream, const nsAReadableString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0;
virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0;
virtual nsresult Parse(nsIInputStream& aStream, const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0;
virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsACString& aMimeType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0;
virtual nsresult Terminate(void) = 0;
@ -239,7 +239,7 @@ class nsIParser : public nsISupports {
void* aKey,
nsVoidArray& aTagStack,
PRUint32 anInsertPos,
const nsAReadableString& aContentType,
const nsACString& aContentType,
nsDTDMode aMode=eDTDMode_autodetect) = 0;
/**

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

@ -327,19 +327,19 @@ CNavDTD::CanParse(CParserContext& aParserContext,
eAutoDetectResult result=eUnknownDetect;
if(aParserContext.mParserCommand != eViewSource) {
if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kHTMLTextContentType)) {
if(PR_TRUE==aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType))) {
result=ePrimaryDetect;
}
else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) {
else if(PR_TRUE==aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kPlainTextContentType))) {
result=ePrimaryDetect;
}
else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kTextCSSContentType)) {
else if(PR_TRUE==aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kTextCSSContentType))) {
result=ePrimaryDetect;
}
else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kApplicationJSContentType)) {
else if(PR_TRUE==aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kApplicationJSContentType))) {
result=ePrimaryDetect;
}
else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kTextJSContentType)) {
else if(PR_TRUE==aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kTextJSContentType))) {
result=ePrimaryDetect;
}
else {
@ -348,7 +348,7 @@ CNavDTD::CanParse(CParserContext& aParserContext,
if(BufferContainsHTML(aBuffer,theBufHasXML)){
result = eValidDetect ;
if(0==aParserContext.mMimeType.Length()) {
aParserContext.SetMimeType(NS_ConvertASCIItoUCS2(kHTMLTextContentType, sizeof(kHTMLTextContentType)));
aParserContext.SetMimeType(NS_LITERAL_CSTRING(kHTMLTextContentType));
if(!theBufHasXML) {
switch(aParserContext.mDTDMode) {
case eDTDMode_strict:

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

@ -352,7 +352,7 @@ protected:
nsString mFilename;
nsString mScratch; //used for various purposes; non-persistent
nsAutoString mMimeType; //ok as an autostring; these are short.
nsCString mMimeType;
nsNodeAllocator mNodeAllocator;
nsDTDMode mDTDMode;

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

@ -294,7 +294,7 @@ COtherDTD::CanParse(CParserContext& aParserContext, const nsString& aBuffer,
if(BufferContainsHTML(aBuffer,theBufHasXML)){
result = eValidDetect ;
if(0==aParserContext.mMimeType.Length()) {
aParserContext.SetMimeType(NS_ConvertASCIItoUCS2(kHTMLTextContentType));
aParserContext.SetMimeType(NS_LITERAL_CSTRING(kHTMLTextContentType));
if(!theBufHasXML) {
switch(aParserContext.mDTDMode) {
case eDTDMode_strict:

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

@ -142,18 +142,18 @@ CParserContext::~CParserContext(){
* Set's the mimetype for this context
* @update rickg 03.18.2000
*/
void CParserContext::SetMimeType(nsAReadableString& aMimeType){
void CParserContext::SetMimeType(const nsACString& aMimeType){
mMimeType.Assign(aMimeType);
mDocType=ePlainText;
if(mMimeType.EqualsWithConversion(kHTMLTextContentType))
if(mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType)))
mDocType=eHTML_Strict;
else if (mMimeType.EqualsWithConversion(kXMLTextContentType) ||
mMimeType.EqualsWithConversion(kXMLApplicationContentType) ||
mMimeType.EqualsWithConversion(kXHTMLApplicationContentType) ||
mMimeType.EqualsWithConversion(kXULTextContentType) ||
mMimeType.EqualsWithConversion(kRDFTextContentType) ||
mMimeType.EqualsWithConversion(kXIFTextContentType))
else if (mMimeType.Equals(NS_LITERAL_CSTRING(kXMLTextContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXMLApplicationContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXHTMLApplicationContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXULTextContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kRDFTextContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXIFTextContentType)))
mDocType=eXML;
}

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

@ -77,7 +77,7 @@ public:
CParserContext( const CParserContext& aContext);
~CParserContext();
void SetMimeType(nsAReadableString& aMimeType);
void SetMimeType(const nsACString& aMimeType);
nsCOMPtr<nsIRequest> mRequest; // provided by necko to differnciate different input streams
// why is mRequest strongly referenced? see bug 102376.
@ -88,7 +88,7 @@ public:
CParserContext* mPrevContext;
nsScanner* mScanner;
nsAutoString mMimeType;
nsCString mMimeType;
nsDTDMode mDTDMode;
eParserDocType mDocType;

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

@ -812,7 +812,7 @@ nsExpatDriver::CanParse(CParserContext& aParserContext,
else {
if (0 == aParserContext.mMimeType.Length() &&
kNotFound != aBuffer.Find("<?xml ")) {
aParserContext.SetMimeType(NS_LITERAL_STRING(kXMLTextContentType));
aParserContext.SetMimeType(NS_LITERAL_CSTRING(kXMLTextContentType));
result=eValidDetect;
}
}

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

@ -1083,9 +1083,9 @@ static
void DetermineParseMode(nsString& aBuffer,
nsDTDMode& aParseMode,
eParserDocType& aDocType,
const nsString& aMimeType)
const nsACString& aMimeType)
{
if (aMimeType.EqualsWithConversion(kHTMLTextContentType)) {
if (aMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType))) {
// For XML (XHTML) documents served as text/html, we will use strict
// mode. XML declarations must be the first thing in the document,
// and must be lowercase. (XXX What about a byte order mark?)
@ -1096,10 +1096,10 @@ void DetermineParseMode(nsString& aBuffer,
} else {
DetermineHTMLParseMode(aBuffer, aParseMode, aDocType);
}
} else if (aMimeType.EqualsWithConversion(kPlainTextContentType) ||
aMimeType.EqualsWithConversion(kTextCSSContentType) ||
aMimeType.EqualsWithConversion(kApplicationJSContentType) ||
aMimeType.EqualsWithConversion(kTextJSContentType)) {
} else if (aMimeType.Equals(NS_LITERAL_CSTRING(kPlainTextContentType)) ||
aMimeType.Equals(NS_LITERAL_CSTRING(kTextCSSContentType)) ||
aMimeType.Equals(NS_LITERAL_CSTRING(kApplicationJSContentType)) ||
aMimeType.Equals(NS_LITERAL_CSTRING(kTextJSContentType))) {
aDocType = ePlainText;
aParseMode = eDTDMode_quirks;
} else { // Some form of XML
@ -1484,7 +1484,7 @@ nsresult nsParser::Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aVeri
* @param aStream is the i/o source
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(nsIInputStream& aStream,const nsAReadableString& aMimeType,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode){
nsresult nsParser::Parse(nsIInputStream& aStream,const nsACString& aMimeType,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode){
if (aVerifyEnabled) {
mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION;
@ -1532,7 +1532,7 @@ nsresult nsParser::Parse(nsIInputStream& aStream,const nsAReadableString& aMimeT
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(const nsAReadableString& aSourceBuffer, void* aKey,
const nsAReadableString& aMimeType,
const nsACString& aMimeType,
PRBool aVerifyEnabled, PRBool aLastCall,
nsDTDMode aMode){
@ -1645,7 +1645,7 @@ nsresult nsParser::ParseFragment(const nsAReadableString& aSourceBuffer,
void* aKey,
nsVoidArray& aTagStack,
PRUint32 anInsertPos,
const nsAReadableString& aMimeType,
const nsACString& aMimeType,
nsDTDMode aMode){
nsresult result = NS_OK;
@ -1918,18 +1918,17 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) {
mParserContext->mRequest = request;
nsresult rv;
char* contentType = nsnull;
nsCAutoString contentType;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
NS_ASSERTION(channel, "parser needs a channel to find a dtd");
rv = channel->GetContentType(&contentType);
rv = channel->GetContentType(contentType);
if (NS_SUCCEEDED(rv))
{
mParserContext->SetMimeType( NS_ConvertASCIItoUCS2(contentType) );
nsCRT::free(contentType);
mParserContext->SetMimeType(contentType);
}
else
NS_ASSERTION(contentType, "parser needs a content type to find a dtd");
NS_NOTREACHED("parser needs a content type to find a dtd");
#ifdef rickgdebug
gOutFile= new fstream("c:/temp/out.file",ios::trunc);
@ -2128,7 +2127,7 @@ nsParser::DetectMetaTag(const char* aBytes,
// XXX Only look inside HTML documents for now. For XML
// documents we should be looking inside the XMLDecl.
if (!mParserContext->mMimeType.Equals(NS_ConvertASCIItoUCS2(kHTMLTextContentType))) {
if (!mParserContext->mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType))) {
return PR_FALSE;
}
@ -2411,7 +2410,7 @@ nsresult nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext,
//If you're here, then OnDataAvailable() never got called.
//Prior to necko, we never dealt with this case, but the problem may have existed.
//What we'll do (for now at least) is construct a blank HTML document.
if (!mParserContext->mMimeType.EqualsWithConversion(kPlainTextContentType))
if (!mParserContext->mMimeType.Equals(NS_LITERAL_CSTRING(kPlainTextContentType)))
{
temp.Assign(NS_LITERAL_STRING("<html><body></body></html>"));
}

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

@ -204,7 +204,7 @@ class nsParser : public nsIParser,
* @param aStream is the i/o source
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(nsIInputStream& aStream,const nsAReadableString& aMimeType,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect);
virtual nsresult Parse(nsIInputStream& aStream,const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect);
/**
* @update gess5/11/98
@ -212,13 +212,13 @@ class nsParser : public nsIParser,
* @param appendTokens tells us whether we should insert tokens inline, or append them.
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsAReadableString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect);
virtual nsresult Parse(const nsAReadableString& aSourceBuffer,void* aKey,const nsACString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect);
virtual nsresult ParseFragment(const nsAReadableString& aSourceBuffer,
void* aKey,
nsVoidArray& aTagStack,
PRUint32 anInsertPos,
const nsAReadableString& aContentType,
const nsACString& aContentType,
nsDTDMode aMode=eDTDMode_autodetect);

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

@ -103,7 +103,7 @@ protected:
nsDTDMode mDTDMode;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
eParserDocType mDocType;
nsAutoString mMimeType;
nsCString mMimeType;
PRInt32 mErrorCount;
PRInt32 mTagCount;

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

@ -170,9 +170,7 @@ HTML2text(nsString& inString, nsString& inType, nsString& outType,
parser->RegisterDTD(dtd);
char* inTypeStr = ToNewCString(inType);
rv = parser->Parse(inString, 0, NS_ConvertASCIItoUCS2(inTypeStr), PR_FALSE, PR_TRUE);
delete[] inTypeStr;
rv = parser->Parse(inString, 0, NS_LossyConvertUCS2toASCII(inType), PR_FALSE, PR_TRUE);
if (NS_FAILED(rv))
{
printf("Parse() failed! 0x%x\n", rv);

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

@ -65,12 +65,10 @@ NS_IMETHODIMP nsObserverBase::NotifyWebShell(nsISupports* aWebShell,
if (NS_SUCCEEDED(res)) {
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel,&res));
if (NS_SUCCEEDED(res)) {
nsXPIDLCString method;
httpChannel->GetRequestMethod(getter_Copies(method));
if (method) {
if (!PL_strcasecmp(method, "POST")) {
return NS_OK;
}
nsCAutoString method;
httpChannel->GetRequestMethod(method);
if (method.Equals(NS_LITERAL_CSTRING("POST"), nsCaseInsensitiveCStringComparator())) {
return NS_OK;
}
}
}

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

@ -723,8 +723,8 @@ public:
NS_DECL_ISUPPORTS
// nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) {
*result = ToNewUnicode(NS_LITERAL_STRING("about:layout-dummy-request"));
NS_IMETHOD GetName(nsACString &result) {
result = NS_LITERAL_CSTRING("about:layout-dummy-request");
return NS_OK;
}
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@ -732,6 +732,10 @@ public:
NS_IMETHOD Cancel(nsresult status);
NS_IMETHOD Suspend(void) { return NS_OK; }
NS_IMETHOD Resume(void) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
// nsIChannel
NS_IMETHOD GetOriginalURI(nsIURI* *aOriginalURI) { *aOriginalURI = gURI; NS_ADDREF(*aOriginalURI); return NS_OK; }
@ -740,20 +744,17 @@ public:
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentType(nsACString &aContentType) { aContentType.Truncate(); return NS_OK; }
NS_IMETHOD SetContentType(const nsACString &aContentType) { return NS_OK; }
NS_IMETHOD GetContentCharset(nsACString &aContentCharset) { aContentCharset.Truncate(); return NS_OK; }
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
};
PRInt32 DummyLayoutRequest::gRefCnt;
@ -6575,8 +6576,7 @@ PresShell::AddDummyLayoutRequest(void)
}
if (loadGroup) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mDummyLayoutRequest);
rv = channel->SetLoadGroup(loadGroup);
rv = mDummyLayoutRequest->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyLayoutRequest, nsnull);
if (NS_FAILED(rv)) return rv;

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

@ -188,7 +188,7 @@ nsContentDLF::CreateInstance(const char* aCommand,
// where <orig_type> can be text/html, text/xml etc.
//
nsCAutoString strContentType; strContentType.Append(aContentType);
nsCAutoString strContentType(aContentType);
PRInt32 idx = strContentType.Find("; x-view-type=view-source", PR_TRUE, 0, -1);
if(idx != -1)
{ // Found "; x-view-type=view-source" param in content type.
@ -211,7 +211,7 @@ nsContentDLF::CreateInstance(const char* aCommand,
// It's a view-source. Reset channel's content type to the original
// type so as not to choke the parser when it asks the channel
// for the content type during the parse phase
aChannel->SetContentType(aContentType);
aChannel->SetContentType(nsDependentCString(aContentType));
aContentType=gHTMLTypes[0];
}

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

@ -65,10 +65,10 @@ nsContentHTTPStartup::Observe( nsISupports *aSubject,
nsCOMPtr<nsIHttpProtocolHandler> http(do_QueryInterface(aSubject));
if (NS_FAILED(rv)) return rv;
rv = http->SetProduct(PRODUCT_NAME);
rv = http->SetProduct(NS_LITERAL_CSTRING(PRODUCT_NAME));
if (NS_FAILED(rv)) return rv;
rv = http->SetProductSub((char*) PRODUCT_VERSION);
rv = http->SetProductSub(NS_LITERAL_CSTRING(PRODUCT_VERSION));
if (NS_FAILED(rv)) return rv;
return NS_OK;

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

@ -723,8 +723,8 @@ public:
NS_DECL_ISUPPORTS
// nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) {
*result = ToNewUnicode(NS_LITERAL_STRING("about:layout-dummy-request"));
NS_IMETHOD GetName(nsACString &result) {
result = NS_LITERAL_CSTRING("about:layout-dummy-request");
return NS_OK;
}
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@ -732,6 +732,10 @@ public:
NS_IMETHOD Cancel(nsresult status);
NS_IMETHOD Suspend(void) { return NS_OK; }
NS_IMETHOD Resume(void) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
// nsIChannel
NS_IMETHOD GetOriginalURI(nsIURI* *aOriginalURI) { *aOriginalURI = gURI; NS_ADDREF(*aOriginalURI); return NS_OK; }
@ -740,20 +744,17 @@ public:
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentType(nsACString &aContentType) { aContentType.Truncate(); return NS_OK; }
NS_IMETHOD SetContentType(const nsACString &aContentType) { return NS_OK; }
NS_IMETHOD GetContentCharset(nsACString &aContentCharset) { aContentCharset.Truncate(); return NS_OK; }
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
};
PRInt32 DummyLayoutRequest::gRefCnt;
@ -6575,8 +6576,7 @@ PresShell::AddDummyLayoutRequest(void)
}
if (loadGroup) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mDummyLayoutRequest);
rv = channel->SetLoadGroup(loadGroup);
rv = mDummyLayoutRequest->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyLayoutRequest, nsnull);
if (NS_FAILED(rv)) return rv;

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

@ -620,20 +620,19 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
if (aString && aStringLen>0) {
nsCOMPtr<nsIRequest> request;
aLoader->GetRequest(getter_AddRefs(request));
nsXPIDLCString contentType;
nsCAutoString contentType;
if (! (mLoader->mNavQuirkMode)) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(getter_Copies(contentType));
channel->GetContentType(contentType);
}
}
if (mLoader->mNavQuirkMode ||
contentType.Equals(NS_LITERAL_CSTRING("text/css"),
nsCaseInsensitiveCStringComparator()) ||
contentType.Equals(NS_LITERAL_CSTRING("text/css")) ||
contentType.IsEmpty()) {
/*
* First determine the charset (if one is indicated)
* 1) Check HTTP charset
* 1) Check nsIChannel::contentCharset
* 2) Check @charset rules
* 3) Check "charset" attribute of the <LINK> or <?xml-stylesheet?>
*
@ -641,16 +640,16 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
* default (document charset or ISO-8859-1 if we have no document
* charset)
*/
nsAutoString strHTTPCharset;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
if (httpChannel) {
nsXPIDLCString httpCharset;
httpChannel->GetCharset(getter_Copies(httpCharset));
CopyASCIItoUCS2(httpCharset, strHTTPCharset);
nsAutoString strChannelCharset;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
CopyASCIItoUCS2(charsetVal, strChannelCharset);
}
result = NS_ERROR_NOT_AVAILABLE;
if (! strHTTPCharset.IsEmpty()) {
result = mLoader->SetCharset(strHTTPCharset);
if (! strChannelCharset.IsEmpty()) {
result = mLoader->SetCharset(strChannelCharset);
}
if (NS_FAILED(result)) {
// We have no charset or the HTTP charset is not recognized.

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

@ -109,8 +109,6 @@ nsAbSyncPostEngine::nsAbSyncPostEngine()
// Init member variables...
mTotalWritten = 0;
mStillRunning = PR_TRUE;
mContentType = nsnull;
mCharset = nsnull;
mListenerArray = nsnull;
mListenerArrayCount = 0;
@ -130,8 +128,6 @@ nsAbSyncPostEngine::nsAbSyncPostEngine()
nsAbSyncPostEngine::~nsAbSyncPostEngine()
{
mStillRunning = PR_FALSE;
PR_FREEIF(mContentType);
PR_FREEIF(mCharset);
PR_FREEIF(mSyncProtocolRequest);
PR_FREEIF(mSyncProtocolRequestPrefix);
@ -449,23 +445,18 @@ nsAbSyncPostEngine::OnStopRequest(nsIRequest *request, nsISupports * /* ctxt */,
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel)
{
char *contentType = nsnull;
char *charset = nsnull;
nsCAutoString contentType;
nsCAutoString charset;
if (NS_SUCCEEDED(channel->GetContentType(&contentType)) && contentType)
if (NS_SUCCEEDED(channel->GetContentType(contentType)) &&
!contentType.Equals(NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE)))
{
if (PL_strcasecmp(contentType, UNKNOWN_CONTENT_TYPE))
{
mContentType = contentType;
}
mContentType = contentType;
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
if (httpChannel)
if (NS_SUCCEEDED(channel->GetContentCharset(charset)) && !charset.IsEmpty())
{
if (NS_SUCCEEDED(httpChannel->GetCharset(&charset)) && charset)
{
mCharset = charset;
}
mCharset = charset;
}
}

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

@ -1,135 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsAbSyncPostEngine_h_
#define nsAbSyncPostEngine_h_
#include "nsCOMPtr.h"
#include "nsIInputStream.h"
#include "nsIStreamListener.h"
#include "nsFileStream.h"
#include "nsIAbSyncPostEngine.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsCURILoader.h"
#include "nsIURIContentListener.h"
#include "nsIURI.h"
#include "nsIAbSyncMojo.h"
#include "nsIChannel.h"
//
// Callback declarations for URL completion
//
// For completion of send/message creation operations...
//
typedef nsresult (*nsPostCompletionCallback ) (nsresult aStatus,
const char *aContentType,
const char *aCharset,
PRInt32 totalSize, const PRUnichar* aMsg,
void *tagData);
class nsAbSyncPostEngine : public nsIAbSyncPostEngine, public nsIStreamListener, public nsIURIContentListener, public nsIInterfaceRequestor {
public:
nsAbSyncPostEngine();
virtual ~nsAbSyncPostEngine();
/* this macro defines QueryInterface, AddRef and Release for this class */
NS_DECL_ISUPPORTS
NS_DECL_NSIABSYNCPOSTENGINE
//
// This is the output stream where the stream converter will write processed data after
// conversion.
//
NS_IMETHOD StillRunning(PRBool *running);
NS_IMETHOD FireURLRequest(nsIURI *aURL, const char *postData);
NS_IMETHOD KickTheSyncOperation();
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
// Methods for nsIStreamListener
NS_DECL_NSISTREAMLISTENER
// Methods for nsIStreamObserver
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
PRInt32 mPostEngineState;
PRInt32 mTransactionID;
private:
// Handy methods for listeners...
nsresult DeleteListeners();
nsresult NotifyListenersOnStartAuthOperation(void);
nsresult NotifyListenersOnStopAuthOperation(nsresult aStatus, const char *aCookie);
nsresult NotifyListenersOnStartSending(PRInt32 aTransactionID, PRUint32 aMsgSize);
nsresult NotifyListenersOnProgress(PRInt32 aTransactionID, PRUint32 aProgress, PRUint32 aProgressMax);
nsresult NotifyListenersOnStatus(PRInt32 aTransactionID, PRUnichar *aMsg);
nsresult NotifyListenersOnStopSending(PRInt32 aTransactionID, nsresult aStatus,
char *aProtocolResponse);
PRBool mStillRunning; // Are we still running?
PRInt32 mTotalWritten; // Size counter variable
nsString mProtocolResponse; // Protocol response
char *mContentType; // The content type retrieved from the server
char *mCharset; // The charset retrieved from the server
nsCOMPtr<nsISupports> mLoadCookie; // load cookie used by the uri loader when we post the url
char *mCookie;
char *mUser;
char *mAuthSpec;
PRInt32 mMessageSize; // Size of POST request...
nsIAbSyncPostListener **mListenerArray;
PRInt32 mListenerArrayCount;
// Since we need to do authentication a bit differently, do it here!
PRBool mAuthenticationRunning;
nsCOMPtr<nsIAbSyncMojo> mSyncMojo;
nsCOMPtr<nsIChannel> mChannel;
char *mSyncProtocolRequest;
char *mSyncProtocolRequestPrefix;
char *mMojoSyncSpec;
PRInt32 mMojoSyncPort;
};
#endif /* nsAbSyncPostEngine_h_ */

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

@ -133,7 +133,10 @@ nsAddbookProtocolHandler::GenerateXMLOutputChannel( nsString &aOutput,
rv = NS_NewCStringInputStream(getter_AddRefs(inStr), utf8String);
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/xml", utf8String.Length());
rv = NS_NewInputStreamChannel(&channel, aURI, inStr,
NS_LITERAL_CSTRING("text/xml"),
NS_LITERAL_CSTRING(""),
utf8String.Length());
NS_ENSURE_SUCCESS(rv, rv);
*_retval = channel;

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

@ -186,8 +186,7 @@ ConvertBufToPlainText(nsString &aConBuf)
parser->SetContentSink(sink);
nsAutoString mimeStr(NS_LITERAL_STRING("text/html").get());
parser->Parse(aConBuf, 0, mimeStr, PR_FALSE, PR_TRUE);
parser->Parse(aConBuf, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE);
//
// Now if we get here, we need to get from ASCII text to
@ -990,9 +989,10 @@ nsMessenger::SaveAs(const char* url, PRBool asFile, nsIMsgIdentity* identity, ns
aListener->m_channel = nsnull;
rv = NS_NewInputStreamChannel(getter_AddRefs(aListener->m_channel),
aURL,
nsnull, // inputStream
nsnull, // contentType
-1); // contentLength
nsnull, // inputStream
NS_LITERAL_CSTRING(""), // contentType
NS_LITERAL_CSTRING(""), // contentCharset
-1); // contentLength
if (NS_FAILED(rv)) goto done;
aListener->m_outputFormat.AssignWithConversion(saveAsFileType == 1 ? TEXT_HTML : TEXT_PLAIN);

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

@ -524,7 +524,7 @@ NS_IMETHODIMP nsMsgProtocol::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK; // don't fail when trying to set this
}
NS_IMETHODIMP nsMsgProtocol::GetContentType(char * *aContentType)
NS_IMETHODIMP nsMsgProtocol::GetContentType(nsACString &aContentType)
{
// as url dispatching matures, we'll be intelligent and actually start
// opening the url before specifying the content type. This will allow
@ -532,18 +532,30 @@ NS_IMETHODIMP nsMsgProtocol::GetContentType(char * *aContentType)
// a part in the message that has a content type that is not message/rfc822
if (m_ContentType.IsEmpty())
*aContentType = nsCRT::strdup("message/rfc822");
aContentType = NS_LITERAL_CSTRING("message/rfc822");
else
*aContentType = ToNewCString(m_ContentType);
aContentType = m_ContentType;
return NS_OK;
}
NS_IMETHODIMP nsMsgProtocol::SetContentType(const char *aContentType)
NS_IMETHODIMP nsMsgProtocol::SetContentType(const nsACString &aContentType)
{
m_ContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP nsMsgProtocol::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsMsgProtocol::SetContentCharset(const nsACString &aContentCharset)
{
NS_NOTREACHED("nsMsgProtocol::SetContentCharset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgProtocol::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;
@ -556,7 +568,7 @@ NS_IMETHODIMP nsMsgProtocol::GetSecurityInfo(nsISupports * *aSecurityInfo)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgProtocol::GetName(PRUnichar * *aName)
NS_IMETHODIMP nsMsgProtocol::GetName(nsACString &aName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -439,10 +439,10 @@ RRT_HEADER:
do_GetService(kHTTPHandlerCID, &rv);
if (NS_SUCCEEDED(rv) && pHTTPHandler)
{
nsXPIDLCString userAgentString;
pHTTPHandler->GetUserAgent(getter_Copies(userAgentString));
nsCAutoString userAgentString;
pHTTPHandler->GetUserAgent(userAgentString);
if (userAgentString)
if (!userAgentString.IsEmpty())
{
// PUSH_STRING ("X-Mailer: "); // To be more standards compliant
PUSH_STRING ("User-Agent: ");
@ -1909,8 +1909,7 @@ ConvertBufToPlainText(nsString &aConBuf, PRBool formatflowed /* = PR_FALSE */)
parser->SetContentSink(sink);
nsAutoString contentType; contentType = NS_LITERAL_STRING("text/html");
parser->Parse(aConBuf, 0, contentType, PR_FALSE, PR_TRUE);
parser->Parse(aConBuf, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE);
//
// Now if we get here, we need to get from ASCII text to
// UTF-8 format or there is a problem downstream...

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

@ -179,7 +179,8 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType
}
nsCOMPtr<nsIChannel> dummyChannel;
rv = NS_NewInputStreamChannel(getter_AddRefs(dummyChannel), aURL, nsnull, nsnull, -1);
rv = NS_NewInputStreamChannel(getter_AddRefs(dummyChannel), aURL, nsnull,
NS_LITERAL_CSTRING(""), NS_LITERAL_CSTRING(""), -1);
if (NS_FAILED(mimeParser->AsyncConvertData(nsnull, nsnull, nsnull, dummyChannel)))
{
Release();

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

@ -412,13 +412,25 @@ NS_IMETHODIMP nsMailtoChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP nsMailtoChannel::GetContentType(char * *aContentType)
NS_IMETHODIMP nsMailtoChannel::GetContentType(nsACString &aContentType)
{
*aContentType = nsCRT::strdup("x-application-mailto");
aContentType = NS_LITERAL_CSTRING("x-application-mailto");
return NS_OK;
}
NS_IMETHODIMP nsMailtoChannel::SetContentType(const char *aContentType)
NS_IMETHODIMP nsMailtoChannel::SetContentType(const nsACString &aContentType)
{
// Do not allow the content type to change...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMailtoChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsMailtoChannel::SetContentCharset(const nsACString &aContentCharset)
{
// Do not allow the content type to change...
return NS_ERROR_FAILURE;
@ -460,7 +472,7 @@ NS_IMETHODIMP nsMailtoChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
////////////////////////////////////////////////////////////////////////////////
/* readonly attribute wstring name; */
NS_IMETHODIMP nsMailtoChannel::GetName(PRUnichar * *aName)
NS_IMETHODIMP nsMailtoChannel::GetName(nsACString &aName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -494,32 +494,22 @@ NS_IMETHODIMP nsURLFetcherStreamConsumer::OnStopRequest(nsIRequest *aRequest, ns
return NS_ERROR_FAILURE;
// Check the content type!
char *contentType = nsnull;
char *charset = nsnull;
nsCAutoString contentType;
nsCAutoString charset;
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(aRequest);
if(!aChannel) return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(aChannel->GetContentType(&contentType)) && contentType)
if (PL_strcasecmp(contentType, UNKNOWN_CONTENT_TYPE) != 0)
{
mURLFetcher->mContentType.Adopt(contentType);
contentType = 0;
}
if (NS_SUCCEEDED(aChannel->GetContentType(contentType)) &&
!contentType.Equals(NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE)))
{
mURLFetcher->mContentType = contentType;
}
if (contentType)
nsCRT::free(contentType);
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel)
if (NS_SUCCEEDED(httpChannel->GetCharset(&charset)) && charset)
{
mURLFetcher->mCharset.Adopt(charset);
charset = 0;
}
if (charset)
nsCRT::free(charset);
if (NS_SUCCEEDED(aChannel->GetContentCharset(charset)) && !charset.IsEmpty())
{
mURLFetcher->mCharset = charset;
}
return NS_OK;
}

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

@ -7524,7 +7524,7 @@ NS_IMETHODIMP nsImapMockChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK; // don't fail when trying to set this
}
NS_IMETHODIMP nsImapMockChannel::GetContentType(char * *aContentType)
NS_IMETHODIMP nsImapMockChannel::GetContentType(nsACString &aContentType)
{
if (m_ContentType.IsEmpty())
{
@ -7538,21 +7538,33 @@ NS_IMETHODIMP nsImapMockChannel::GetContentType(char * *aContentType)
}
}
if (imapAction == nsIImapUrl::nsImapSelectFolder)
*aContentType = nsCRT::strdup("x-application-imapfolder");
aContentType = NS_LITERAL_CSTRING("x-application-imapfolder");
else
*aContentType = nsCRT::strdup("message/rfc822");
aContentType = NS_LITERAL_CSTRING("message/rfc822");
}
else
*aContentType = ToNewCString(m_ContentType);
aContentType = m_ContentType;
return NS_OK;
}
NS_IMETHODIMP nsImapMockChannel::SetContentType(const char *aContentType)
NS_IMETHODIMP nsImapMockChannel::SetContentType(const nsACString &aContentType)
{
m_ContentType = aContentType;
return NS_OK;
}
NS_IMETHODIMP nsImapMockChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP nsImapMockChannel::SetContentCharset(const nsACString &aContentCharset)
{
NS_NOTREACHED("nsImapMockChannel::SetContentCharset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsImapMockChannel::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;
@ -7595,7 +7607,7 @@ NS_IMETHODIMP nsImapMockChannel::SetSecurityInfo(nsISupports *aSecurityInfo)
// From nsIRequest
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsImapMockChannel::GetName(PRUnichar* *result)
NS_IMETHODIMP nsImapMockChannel::GetName(nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -158,8 +158,11 @@ nsresult nsMailboxProtocol::OpenFileSocketForReuse(nsIURI * aURL, PRUint32 aStar
LL_L2UI( length, fileSize );
// probably should pass in the file size instead of aReadCount
rv = fts->CreateTransportFromStream("mailbox", m_multipleMsgMoveCopyStream,
"", length, PR_FALSE, getter_AddRefs(m_transport));
rv = fts->CreateTransportFromStream(NS_LITERAL_CSTRING("mailbox"),
m_multipleMsgMoveCopyStream,
NS_LITERAL_CSTRING(""),
NS_LITERAL_CSTRING(""),
length, PR_FALSE, getter_AddRefs(m_transport));
m_socketIsOpen = PR_FALSE;
return rv;

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

@ -558,15 +558,15 @@ nsMimeBaseEmitter::UpdateCharacterSet(const char *aCharset)
(PL_strcasecmp(aCharset, "ISO-8859-1")) &&
(PL_strcasecmp(aCharset, "UTF-8")) )
{
char *contentType = nsnull;
nsCAutoString contentType;
if (NS_SUCCEEDED(mChannel->GetContentType(&contentType)) && contentType)
if (NS_SUCCEEDED(mChannel->GetContentType(contentType)) && !contentType.IsEmpty())
{
char *cPtr = (char *) PL_strcasestr(contentType, "charset=");
char *cPtr = (char *) PL_strcasestr(contentType.get(), "charset=");
if (cPtr)
{
char *ptr = contentType;
char *ptr = (char *) contentType.get();
while (*ptr)
{
if ( (*ptr == ' ') || (*ptr == ';') )
@ -582,14 +582,9 @@ nsMimeBaseEmitter::UpdateCharacterSet(const char *aCharset)
}
}
char *newContentType = (char *) PR_smprintf("%s; charset=%s", contentType, aCharset);
if (newContentType)
{
mChannel->SetContentType(newContentType);
PR_FREEIF(newContentType);
}
PR_FREEIF(contentType);
// have to recompute strlen since contentType could have an embedded null byte
mChannel->SetContentType(nsDependentCString(contentType.get()));
mChannel->SetContentCharset(nsDependentCString(aCharset));
}
}

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

@ -166,7 +166,7 @@ MimeInlineImage_parse_begin (MimeObject *obj)
mime_stream_data *msd = (mime_stream_data *) (obj->options->stream_closure);
if ( (msd) && (msd->channel) )
{
msd->channel->SetContentType(obj->content_type);
msd->channel->SetContentType(nsDependentCString(obj->content_type));
}
}

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

@ -1975,11 +1975,11 @@ ResetChannelCharset(MimeObject *obj)
char *ct = MimeHeaders_get (obj->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
if ( (ct) && (msd) && (msd->channel) )
{
char *ptr = PL_strstr(ct, "charset=");
char *ptr = strstr(ct, "charset=");
if (ptr)
{
// First, setup the channel!
msd->channel->SetContentType(ct);
msd->channel->SetContentType(nsDependentCString(ct));
// Second, if this is a Save As operation, then we need to convert
// to override the output charset!

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

@ -42,7 +42,6 @@ interface nsISimpleEnumerator;
[scriptable, uuid(c7e410d1-85f2-11d3-9f63-006008a6efe9)]
interface nsIJARChannel : nsIChannel
{
/**
* Enumerates all the entries in the JAR (the root URI).
* ARGUMENTS:
@ -50,5 +49,4 @@ interface nsIJARChannel : nsIChannel
* or null to enumerate the whole thing.
*/
nsISimpleEnumerator EnumerateEntries(in string aRoot);
};

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

@ -64,7 +64,6 @@ PRLogModuleInfo* gJarProtocolLog = nsnull;
nsJARChannel::nsJARChannel()
: mLoadFlags(LOAD_NORMAL)
, mContentType(nsnull)
, mContentLength(-1)
, mStatus(NS_OK)
#ifdef DEBUG
@ -86,8 +85,6 @@ nsJARChannel::nsJARChannel()
nsJARChannel::~nsJARChannel()
{
if (mContentType)
nsCRT::free(mContentType);
NS_IF_RELEASE(mJARProtocolHandler);
}
@ -133,14 +130,9 @@ nsJARChannel::Init(nsJARProtocolHandler* aHandler, nsIURI* uri)
// nsIRequest methods
NS_IMETHODIMP
nsJARChannel::GetName(PRUnichar* *result)
nsJARChannel::GetName(nsACString &result)
{
nsresult rv;
nsCAutoString urlStr;
rv = mURI->GetSpec(urlStr);
if (NS_FAILED(rv)) return rv;
*result = ToNewUnicode(NS_ConvertUTF8toUCS2(urlStr));
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return mURI->GetSpec(result);
}
NS_IMETHODIMP
@ -240,7 +232,7 @@ nsJARChannel::OpenJARElement()
{
nsresult rv;
nsAutoCMonitor mon(this);
rv = Open((PRInt32*) nsnull); // is there a better way.... where is my C++ book?!
rv = Open();
if (NS_SUCCEEDED(rv))
rv = GetInputStream(getter_AddRefs(mSynchronousInputStream));
mon.Notify(); // wake up nsIChannel::Open
@ -388,10 +380,10 @@ nsJARChannel::SetLoadFlags(PRUint32 aLoadFlags)
}
NS_IMETHODIMP
nsJARChannel::GetContentType(char* *aContentType)
nsJARChannel::GetContentType(nsACString &aContentType)
{
nsresult rv = NS_OK;
if (mContentType == nsnull) {
if (mContentType.IsEmpty()) {
if (mJAREntry.IsEmpty())
return NS_ERROR_NOT_AVAILABLE;
const char *ext = nsnull, *fileName = mJAREntry.get();
@ -405,46 +397,61 @@ nsJARChannel::GetContentType(char* *aContentType)
if (ext) {
nsIMIMEService* mimeServ = mJARProtocolHandler->GetCachedMimeService();
if (mimeServ) {
rv = mimeServ->GetTypeFromExtension(ext, &mContentType);
nsXPIDLCString mimeType;
rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
mContentType = mimeType;
}
}
else
rv = NS_ERROR_NOT_AVAILABLE;
if (NS_FAILED(rv)) {
mContentType = strdup(UNKNOWN_CONTENT_TYPE);
if (mContentType == nsnull)
rv = NS_ERROR_OUT_OF_MEMORY;
else
rv = NS_OK;
mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv)) {
*aContentType = strdup(mContentType);
if (*aContentType == nsnull)
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_SUCCEEDED(rv))
aContentType = mContentType;
else
aContentType.Truncate();
return rv;
}
NS_IMETHODIMP
nsJARChannel::SetContentType(const char *aContentType)
nsJARChannel::SetContentType(const nsACString &aContentType)
{
if (mContentType) {
nsCRT::free(mContentType);
}
mContentType = aContentType;
return NS_OK;
}
mContentType = nsCRT::strdup(aContentType);
if (!mContentType) return NS_ERROR_OUT_OF_MEMORY;
NS_IMETHODIMP
nsJARChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset = mContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::SetContentCharset(const nsACString &aContentCharset)
{
mContentCharset = aContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentLength(PRInt32* aContentLength)
{
if (mContentLength == -1)
return NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(aContentLength);
if (mContentLength == -1) {
nsresult rv;
nsCOMPtr<nsIZipEntry> entry;
rv = mJAR->GetEntry(mJAREntry.get(), getter_AddRefs(entry));
if (NS_FAILED(rv)) return rv;
rv = entry->GetRealSize((PRUint32*)&mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentLength = mContentLength;
return NS_OK;
}
@ -646,12 +653,15 @@ nsJARChannel::EnsureZipReader()
}
NS_IMETHODIMP
nsJARChannel::Open(PRInt32 *contentLength)
nsJARChannel::Open()
{
nsresult rv;
rv = EnsureZipReader();
if (NS_FAILED(rv)) return rv;
return EnsureZipReader();
}
/*
NS_IMETHODIMP
nsJARChannel::GetContentLength(PRInt32 *length)
{
nsCOMPtr<nsIZipEntry> entry;
rv = mJAR->GetEntry(mJAREntry.get(), getter_AddRefs(entry));
if (NS_FAILED(rv)) return rv;
@ -663,6 +673,7 @@ nsJARChannel::Open(PRInt32 *contentLength)
return rv;
}
*/
NS_IMETHODIMP
nsJARChannel::Close(nsresult status)

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

@ -88,7 +88,7 @@ public:
// NS_DECL_NSISTREAMIO and nsIChannel both define (attribute string contentType)
NS_IMETHOD Open(PRInt32 *contentLength);
NS_IMETHOD Open();
NS_IMETHOD Close(nsresult status);
NS_IMETHOD GetInputStream(nsIInputStream * *aInputStream);
NS_IMETHOD GetOutputStream(nsIOutputStream * *aOutputStream);
@ -121,7 +121,8 @@ protected:
nsCOMPtr<nsISupports> mUserContext;
nsCOMPtr<nsIStreamListener> mUserListener;
char* mContentType;
nsCString mContentType;
nsCString mContentCharset;
PRInt32 mContentLength;
nsCOMPtr<nsIURI> mJARBaseURI;
nsCString mJAREntry;

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

@ -72,7 +72,7 @@ nsresult nsIconChannel::Init(nsIURI* uri)
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP nsIconChannel::GetName(PRUnichar* *result)
NS_IMETHODIMP nsIconChannel::GetName(nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -434,19 +434,30 @@ NS_IMETHODIMP nsIconChannel::SetLoadFlags(PRUint32 aLoadAttributes)
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentType(char* *aContentType)
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType)
{
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup("image/icon");
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
aContentType = NS_LITERAL_CSTRING("image/icon");
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::SetContentType(const char *aContentType)
nsIconChannel::SetContentType(const nsACString &aContentType)
{
//It doesn't make sense to set the content-type on this type
// It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsIconChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
{
// It doesn't make sense to set the content-charset on this type
// of channel...
return NS_ERROR_FAILURE;
}

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

@ -555,10 +555,10 @@ NS_IMETHODIMP ProxyListener::OnStartRequest(nsIRequest *aRequest, nsISupports *c
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
if (channel) {
nsXPIDLCString contentType;
nsresult rv = channel->GetContentType(getter_Copies(contentType));
nsCAutoString contentType;
nsresult rv = channel->GetContentType(contentType);
if (contentType.get()) {
if (!contentType.IsEmpty()) {
/* If multipart/x-mixed-replace content, we'll insert a MIME decoder
in the pipeline to handle the content and pass it along to our
original listener.

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

@ -59,7 +59,7 @@ imgRequest::imgRequest() :
mObservers(0),
mLoading(PR_FALSE), mProcessing(PR_FALSE),
mImageStatus(imgIRequest::STATUS_NONE), mState(0),
mContentType(nsnull), mCacheId(0), mValidator(nsnull), mIsMultiPartChannel(PR_FALSE)
mCacheId(0), mValidator(nsnull), mIsMultiPartChannel(PR_FALSE)
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
@ -68,8 +68,6 @@ imgRequest::imgRequest() :
imgRequest::~imgRequest()
{
/* destructor code */
if (mContentType)
nsCRT::free(mContentType);
}
nsresult imgRequest::Init(nsIChannel *aChannel,
@ -547,9 +545,10 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
mChannel = do_QueryInterface(aRequest);
}
nsXPIDLCString mContentType;
mChannel->GetContentType(getter_Copies(mContentType));
if (PL_strcasecmp("multipart/x-mixed-replace", mContentType.get()) == 0)
nsCAutoString contentType;
mChannel->GetContentType(contentType);
if (contentType.Equals(NS_LITERAL_CSTRING("multipart/x-mixed-replace"),
nsCaseInsensitiveCStringComparator()))
mIsMultiPartChannel = PR_TRUE;
/* set our state variables to their initial values. */
@ -685,15 +684,14 @@ 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
if (!mContentType) {
if (mContentType.IsEmpty()) {
LOG_SCOPE(gImgLog, "imgRequest::OnDataAvailable |sniffing of mimetype failed|");
nsXPIDLCString contentType;
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
nsresult rv = NS_ERROR_FAILURE;
if (chan) {
rv = chan->GetContentType(getter_Copies(contentType));
rv = chan->GetContentType(mContentType);
}
if (NS_FAILED(rv)) {
@ -707,14 +705,11 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
}
LOG_MSG(gImgLog, "imgRequest::OnDataAvailable", "Got content type from the channel");
mContentType = nsCRT::strdup(contentType.get());
}
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "content type", mContentType);
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "content type", mContentType.get());
nsCAutoString conid("@mozilla.org/image/decoder;2?type=");
conid += mContentType;
nsCAutoString conid(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;2?type=") + mContentType);
mDecoder = do_CreateInstance(conid.get());
@ -786,13 +781,10 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
{
/* Is it a GIF? */
if (mContentType) {
nsCRT::free(mContentType);
mContentType = nsnull;
}
mContentType.Truncate();
if (len >= 4 && !nsCRT::strncmp(buf, "GIF8", 4)) {
mContentType = nsCRT::strndup("image/gif", 9);
mContentType = NS_LITERAL_CSTRING("image/gif");
return;
}
@ -802,7 +794,7 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
(unsigned char)buf[2]==0x4E &&
(unsigned char)buf[3]==0x47))
{
mContentType = nsCRT::strndup("image/png", 9);
mContentType = NS_LITERAL_CSTRING("image/png");
return;
}
@ -818,7 +810,7 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
((unsigned char)buf[1])==0xD8 &&
((unsigned char)buf[2])==0xFF)
{
mContentType = nsCRT::strndup("image/jpeg", 10);
mContentType = NS_LITERAL_CSTRING("image/jpeg");
return;
}
@ -831,18 +823,18 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
((unsigned char) buf[1])==0x47 &&
((unsigned char) buf[4])==0x00 )
{
mContentType = nsCRT::strndup("image/x-jg", 10);
mContentType = NS_LITERAL_CSTRING("image/x-jg");
return;
}
if (len >= 2 && !nsCRT::strncmp(buf, "BM", 2)) {
mContentType = nsCRT::strndup("image/bmp", 9);
mContentType = NS_LITERAL_CSTRING("image/bmp");
return;
}
// ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
if (len >= 4 && !memcmp(buf, "\000\000\001\000", 4)) {
mContentType = nsCRT::strndup("image/x-icon", 12);
mContentType = NS_LITERAL_CSTRING("image/x-icon");
return;
}
@ -851,7 +843,7 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
(unsigned char)buf[2]==0x4E &&
(unsigned char)buf[3]==0x47))
{
mContentType = nsCRT::strndup("video/x-mng", 11);
mContentType = NS_LITERAL_CSTRING("video/x-mng");
return;
}
@ -860,7 +852,7 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len)
(unsigned char)buf[2]==0x4E &&
(unsigned char)buf[3]==0x47))
{
mContentType = nsCRT::strndup("image/x-jng", 11);
mContentType = NS_LITERAL_CSTRING("image/x-jng");
return;
}

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

@ -94,7 +94,7 @@ private:
nsresult GetURI(nsIURI **aURI);
void RemoveFromCache();
inline const char *GetMimeType() const {
return mContentType;
return mContentType.get();
}
public:
@ -118,7 +118,7 @@ private:
PRUint32 mImageStatus;
PRUint32 mState;
char *mContentType;
nsCString mContentType;
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry; /* we hold on to this to this so long as we have observers */

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

@ -141,18 +141,16 @@ nsresult imgRequestProxy::ChangeOwner(imgRequest *aNewOwner)
/** nsIRequest / imgIRequest methods **/
/* readonly attribute wstring name; */
NS_IMETHODIMP imgRequestProxy::GetName(PRUnichar * *aName)
NS_IMETHODIMP imgRequestProxy::GetName(nsACString &aName)
{
nsCAutoString name;
aName.Truncate();
if (mOwner) {
nsCOMPtr<nsIURI> uri;
mOwner->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetSpec(name);
uri->GetSpec(aName);
}
*aName = ToNewUnicode(NS_ConvertUTF8toUCS2(name));
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
/* boolean isPending (); */
@ -358,9 +356,9 @@ void imgRequestProxy::OnStopDecode(nsresult status, const PRUnichar *statusArg)
void imgRequestProxy::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{
#ifdef PR_LOGGING
nsXPIDLString name;
GetName(getter_Copies(name));
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStartRequest", "name", NS_ConvertUCS2toUTF8(name).get());
nsCAutoString name;
GetName(name);
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStartRequest", "name", name.get());
#endif
if (!mIsInLoadGroup && mLoadGroup) {
@ -377,9 +375,9 @@ void imgRequestProxy::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsre
return;
#ifdef PR_LOGGING
nsXPIDLString name;
GetName(getter_Copies(name));
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStopRequest", "name", NS_ConvertUCS2toUTF8(name).get());
nsCAutoString name;
GetName(name);
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStopRequest", "name", name.get());
#endif
/* calling RemoveRequest may cause the document to finish loading,

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

@ -1163,7 +1163,7 @@ public:
SetPluginStreamListenerPeer(nsPluginStreamListenerPeer * aPluginStreamListenerPeer);
void
MakeByteRangeString(nsByteRange* aRangeList, char** string, PRInt32 *numRequests);
MakeByteRangeString(nsByteRange* aRangeList, nsACString &string, PRInt32 *numRequests);
void
SetLocalCachedFile(const char* path);
@ -1390,9 +1390,9 @@ nsPluginStreamInfo::GetURL(const char** result)
////////////////////////////////////////////////////////////////////////
void
nsPluginStreamInfo::MakeByteRangeString(nsByteRange* aRangeList, char** rangeRequest, PRInt32 *numRequests)
nsPluginStreamInfo::MakeByteRangeString(nsByteRange* aRangeList, nsACString &rangeRequest, PRInt32 *numRequests)
{
*rangeRequest = nsnull;
rangeRequest.Truncate();
*numRequests = 0;
//the string should look like this: bytes=500-700,601-999
if(!aRangeList)
@ -1420,7 +1420,7 @@ nsPluginStreamInfo::MakeByteRangeString(nsByteRange* aRangeList, char** rangeReq
// get rid of possible trailing comma
string.Trim(",", PR_FALSE);
*rangeRequest = ToNewCString(string);
rangeRequest = string;
*numRequests = requestCnt;
return;
}
@ -1446,17 +1446,15 @@ nsPluginStreamInfo::RequestRead(nsByteRange* rangeList)
if(!httpChannel)
return NS_ERROR_FAILURE;
char *rangeString;
nsCAutoString rangeString;
PRInt32 numRequests;
MakeByteRangeString(rangeList, &rangeString, &numRequests);
MakeByteRangeString(rangeList, rangeString, &numRequests);
if(!rangeString)
if(rangeString.IsEmpty())
return NS_ERROR_FAILURE;
httpChannel->SetRequestHeader("Range", rangeString);
nsMemory::Free(rangeString);
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString);
// instruct old stream listener to cancel the request on the next
// attempt to write.
@ -1967,9 +1965,9 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
// Now we look for a content-encoding header. If we find one,
// we can't use the cache as a file
nsXPIDLCString contentEncoding;
rv = httpChannel->GetResponseHeader("Content-Encoding",
getter_Copies(contentEncoding));
nsCAutoString contentEncoding;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Encoding"),
contentEncoding);
if (NS_SUCCEEDED(rv) &&
!contentEncoding.Equals("identity",
nsCaseInsensitiveCStringComparator())) {
@ -1990,15 +1988,15 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
NS_WARNING("No Cache Aval. Some plugins wont work OR we don't have a URL");
}
char* aContentType = nsnull;
rv = channel->GetContentType(&aContentType);
nsCAutoString aContentType;
rv = channel->GetContentType(aContentType);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> aURL;
rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
if (nsnull != aContentType)
mPluginStreamInfo->SetContentType(aContentType);
if (!aContentType.IsEmpty())
mPluginStreamInfo->SetContentType(aContentType.get());
#ifdef PLUGIN_LOGGING
nsCAutoString urlSpec;
@ -2006,7 +2004,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NOISY,
("nsPluginStreamListenerPeer::OnStartRequest this=%p request=%p mime=%s, url=%s\n",
this, request, aContentType, urlSpec.get()));
this, request, aContentType.get(), urlSpec.get()));
PR_LogFlush();
#endif
@ -2020,7 +2018,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
// which is called by InstantiateEmbededPlugin()
// NOTE: we don't want to try again if we didn't get the MIME type this time
if ((nsnull == mInstance) && (nsnull != mOwner) && (nsnull != aContentType))
if ((nsnull == mInstance) && (nsnull != mOwner) && (!aContentType.IsEmpty()))
{
mOwner->GetInstance(mInstance);
mOwner->GetWindow(window);
@ -2031,9 +2029,9 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
nsPluginMode mode;
mOwner->GetMode(&mode);
if (mode == nsPluginMode_Embedded)
rv = mHost->InstantiateEmbededPlugin(aContentType, aURL, mOwner);
rv = mHost->InstantiateEmbededPlugin(aContentType.get(), aURL, mOwner);
else
rv = mHost->SetUpPluginInstance(aContentType, aURL, mOwner);
rv = mHost->SetUpPluginInstance(aContentType.get(), aURL, mOwner);
if (NS_OK == rv)
{
@ -2054,8 +2052,6 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo
}
}
nsCRT::free(aContentType);
//
// Set up the stream listener...
//
@ -2334,13 +2330,13 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
mPluginStreamInfo->SetURL(urlString.get());
// Set the content type to ensure we don't pass null to the plugin
nsXPIDLCString aContentType;
rv = channel->GetContentType(getter_Copies(aContentType));
nsCAutoString aContentType;
rv = channel->GetContentType(aContentType);
if (NS_FAILED(rv))
return rv;
if (aContentType)
mPluginStreamInfo->SetContentType(aContentType);
if (!aContentType.IsEmpty())
mPluginStreamInfo->SetContentType(aContentType.get());
// set error status if stream failed so we notify the plugin
if (mRequestFailed)
@ -2415,10 +2411,10 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
mPluginStreamInfo->GetLength(&length);
if ((length != -1) && httpChannel)
{
nsXPIDLCString range;
if(NS_SUCCEEDED(httpChannel->GetResponseHeader("accept-ranges", getter_Copies(range))))
nsCAutoString range;
if(NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("accept-ranges"), range)))
{
if (0 == PL_strcasecmp(range.get(), "bytes"))
if (range.Equals(NS_LITERAL_CSTRING("bytes"), nsCaseInsensitiveCStringComparator()))
bSeekable = PR_TRUE;
}
}
@ -2428,18 +2424,17 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
// get Last-Modified header for plugin info
if (httpChannel)
{
char * lastModified = nsnull;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader("last-modified", &lastModified)) &&
lastModified)
nsCAutoString lastModified;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"), lastModified)) &&
!lastModified.IsEmpty())
{
PRTime time64;
PR_ParseTimeString(lastModified, PR_TRUE, &time64); //convert string time to interger time
PR_ParseTimeString(lastModified.get(), PR_TRUE, &time64); //convert string time to interger time
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
double fpTime;
LL_L2D(fpTime, time64);
mPluginStreamInfo->SetLastModified((PRUint32)(fpTime * 1e-6 + 0.5));
nsCRT::free(lastModified);
}
}
@ -2489,13 +2484,14 @@ nsPluginStreamListenerPeer::GetLoadGroup()
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsPluginStreamListenerPeer::VisitHeader(const char *header, const char *value)
nsPluginStreamListenerPeer::VisitHeader(const nsACString &header, const nsACString &value)
{
nsCOMPtr<nsIHTTPHeaderListener> listener = do_QueryInterface(mPStreamListener);
if (!listener)
return NS_ERROR_FAILURE;
return listener->NewResponseHeader(header, value);
return listener->NewResponseHeader(PromiseFlatCString(header).get(),
PromiseFlatCString(value).get());
}
@ -2777,14 +2773,14 @@ nsresult nsPluginHostImpl::UserAgent(const char **retstring)
if (NS_FAILED(res))
return res;
nsXPIDLCString uaString;
res = http->GetUserAgent(getter_Copies(uaString));
nsCAutoString uaString;
res = http->GetUserAgent(uaString);
if (NS_SUCCEEDED(res))
{
if(NS_RETURN_UASTRING_SIZE > PL_strlen(uaString))
if(NS_RETURN_UASTRING_SIZE > uaString.Length())
{
PL_strcpy(resultString, uaString);
PL_strcpy(resultString, uaString.get());
*retstring = resultString;
}
else
@ -5713,7 +5709,7 @@ nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData,
// FINALLY: we can set the header!
//
rv =aChannel->SetRequestHeader(headerName.get(), headerValue.get());
rv =aChannel->SetRequestHeader(headerName, headerValue);
if (NS_FAILED(rv)) {
rv = NS_ERROR_NULL_POINTER;
return rv;

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

@ -344,10 +344,9 @@ PluginViewerImpl::StartLoad(nsIRequest* request, nsIStreamListener*& aResult)
NS_ADDREF(mChannel);
#ifdef DEBUG
char* contentType;
channel->GetContentType(&contentType);
printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType);
nsCRT::free(contentType);
nsCAutoString contentType;
channel->GetContentType(contentType);
printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType.get());
#endif
aResult = nsnull;
@ -415,14 +414,12 @@ PluginViewerImpl::CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const
if (NS_FAILED(rv)) return rv;
NS_ConvertUTF8toUCS2 str(spec);
char* ct;
nsCAutoString ct;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
channel->GetContentType(&ct);
channel->GetContentType(ct);
if (NS_FAILED(rv)) return rv;
rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner);
delete[] ct;
rv = aHost->InstantiateFullPagePlugin(ct.get(), str, aResult, mOwner);
}
return rv;
@ -976,14 +973,7 @@ NS_IMETHODIMP
PluginListener::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{
nsresult rv;
char* contentType = nsnull;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
rv = channel->GetContentType(&contentType);
if (NS_FAILED(rv)) {
return rv;
}
rv = mViewer->StartLoad(request, mNextStream);
if (NS_FAILED(rv)) {

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

@ -72,6 +72,10 @@
#define NS_ERROR_UNKNOWN_PROTOCOL \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 18)
// There is no content available (when nsIChannel::asyncOpen is called)
#define NS_ERROR_NO_CONTENT \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 17)
#define NS_ERROR_PORT_ACCESS_NOT_ALLOWED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 19)

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

@ -43,96 +43,109 @@ interface nsIInputStream;
interface nsIStreamListener;
/**
* The nsIChannel interface allows the user to construct GET requests for
* specific protocols, and manage them in a uniform way. Once a channel
* is created (via nsIIOService::NewChannel), parameters for that request
* may be set by using the channel attributes, or by QI'ing to a subclass
* of nsIChannel for protocol-specific parameters. Then the actual request
* can be issued via Open or AsyncOpen.
* The nsIChannel interface allows clients to construct "GET" requests for
* specific protocols, and manage them in a uniform way. Once a channel is
* created (via nsIIOService::newChannel), parameters for that request may
* be set by using the channel attributes, or by QI'ing to a subclass of
* nsIChannel for protocol-specific parameters. Then, the URI can be fetched
* by calling nsIChannel::open or nsIChannel::asyncOpen.
*
* After a request has been completed, the channel is still valid for
* accessing protocol-specific results. For example, QI'ing to nsIHTTPChannel
* allows response headers to be retrieved for the http transaction.
* After a request has been completed, the channel is still valid for accessing
* protocol-specific results. For example, QI'ing to nsIHttpChannel allows
* response headers to be retrieved for the corresponding http transaction.
*
* @status UNDER_REVIEW
*/
[scriptable, uuid(1788e79e-f947-11d3-8cda-0060b0fc14a3)]
interface nsIChannel : nsIRequest
{
/**
* Returns the original URL used to construct the channel.
* This is used in the case of a redirect or URI "resolution" (e.g.
* resolving a resource: URI to a file: URI) so that the original
* pre-redirect URI can still be obtained.
* The original URI used to construct the channel. This is used in the case
* of a redirect or URI "resolution" (e.g. resolving a resource: URI to a
* file: URI) so that the original pre-redirect URI can still be obtained.
*
* Note that this is distinctly different from the http referrer
* (referring URI) which is typically the page that contained the
* original URI (accessible from nsIHTTPChannel).
* NOTE: this is distinctly different from the http Referer (referring URI),
* which is typically the page that contained the original URI (accessible
* from nsIHttpChannel).
*/
attribute nsIURI originalURI;
/**
* Returns the URL to which the channel currently refers. If a redirect
* or URI resolution occurs, this accessor returns the current location
* to which the channel is referring.
* The URI corresponding to the channel. Its value is immutable.
*/
readonly attribute nsIURI URI;
/**
* Accesses the owner corresponding to the entity that is
* responsible for this channel. Used by security code to grant
* or deny privileges to mobile code loaded from this channel.
* The owner, corresponding to the entity that is responsible for this
* channel. Used by the security manager to grant or deny privileges to
* mobile code loaded from this channel.
*
* Note: This is a strong reference to the owner, so if the owner is also
* holding a pointer to the channel, care must be taken to explicitly drop
* its reference to the channel -- otherwise a leak will result.
* NOTE: this is a strong reference to the owner, so if the owner is also
* holding a strong reference to the channel, care must be taken to
* explicitly drop its reference to the channel.
*/
attribute nsISupports owner;
/**
* Accesses the capabilities callbacks of the channel. This is set by clients
* who wish to provide a means to receive progress, status and protocol-specific
* notifications. Interfaces commonly requested include: nsIProgressEventSink
* and nsIPrompt.
* The notification callbacks for the channel. This is set by clients, who
* wish to provide a means to receive progress, status and protocol-specific
* notifications. If this value is NULL, the channel implementation may use
* the notification callbacks from its load group.
*
* Interfaces commonly requested include: nsIProgressEventSink, nsIPrompt,
* and nsIAuthPrompt.
*/
attribute nsIInterfaceRequestor notificationCallbacks;
/**
* Any security information about this channel. This can be null.
* Transport-level security information (if any) corresponding to the channel.
*/
readonly attribute nsISupports securityInfo;
/**
* Returns the content MIME type of the channel if available. Note that the
* content type can often be wrongly specified (wrong file extension, wrong
* MIME type, wrong document type stored on a server, etc.) and the caller
* most likely wants to verify with the actual data.
* The MIME type of the channel's content if available.
*
* NOTE: the content type can often be wrongly specified (e.g., wrong file
* extension, wrong MIME type, wrong document type stored on a server, etc.),
* and the caller most likely wants to verify with the actual data.
*/
attribute string contentType;
attribute ACString contentType;
/**
* Returns the length of the data associated with the channel if available.
* If the length is unknown then -1 is returned.
* The character set of the channel's content if available and if applicable.
* This attribute only applies to textual data.
*/
attribute ACString contentCharset;
/**
* The length of the data associated with the channel if available. A value
* of -1 indicates that the content length is unknown.
*/
attribute long contentLength;
/**
* Synchronously open this channel. Returns a blocking input stream to this
* channel's data.
* Synchronously open the channel.
*
* @return blocking input stream to the channel's data.
*/
nsIInputStream open();
/**
* Asynchronously open this channel. Data is fed to the specified stream
* listener as it becomes available.
*
* @param aListener the nsIStreamListener implementation
* @param aContext an opaque parameter forwarded to aListener's methods
*/
void asyncOpen(in nsIStreamListener listener, in nsISupports ctxt);
void asyncOpen(in nsIStreamListener aListener, in nsISupports aContext);
/**************************************************************************
* Channel specific load flags:
*/
/**
* Used exclusively by the uriloader and docshell to indicate whether or
* not this request corresponds to the toplevel document.
* Used (e.g., by the uriloader and docshell) to indicate whether or not
* the channel corresponds to the toplevel document.
*/
const unsigned long LOAD_DOCUMENT_URI = 1 << 16;
@ -148,16 +161,4 @@ interface nsIChannel : nsIRequest
* used by the multipart/replace stream converter.
*/
const unsigned long LOAD_REPLACE = 1 << 18;
/**************************************************************************
* This flag is OBSOLETE and will be removed once the old cache is
* removed from the code base. Support for CACHE_AS_FILE is now provided
* via nsICachingChannel.
*/
const unsigned long CACHE_AS_FILE = 1 << 19;
};
%{C++
// There is no content available (when asyncOpen is called)
#define NS_ERROR_NO_CONTENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 17)
%}

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

@ -36,9 +36,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
%{C++
#include "nsFileSpec.h"
%}
interface nsITransport;
interface nsIEventSinkGetter;
@ -56,9 +53,10 @@ interface nsIFileTransportService : nsISupports
// This version can be used with an existing input stream to serve
// as a data pump:
nsITransport createTransportFromStream(in string name,
nsITransport createTransportFromStream(in AUTF8String name,
in nsIInputStream fromStream,
in string contentType,
in ACString contentType,
in ACString contentCharset,
in long contentLength,
in boolean closeStreamWhenDone);

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

@ -43,10 +43,6 @@ interface nsIURI;
interface nsIURLParser;
interface nsIFile;
%{C++
#include "nsAString.h"
%}
[scriptable, uuid(ab7c3a84-d488-11d3-8cda-0060b0fc14a3)]
interface nsIIOService : nsISupports
{

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

@ -33,7 +33,6 @@ interface nsIChannel;
[scriptable, uuid(62d77f66-8ad0-4a7f-91a1-bb048b136490)]
interface nsIMultiPartChannel : nsISupports
{
/**
* readonly attribute to access the underlying channel
*/
@ -44,5 +43,5 @@ interface nsIMultiPartChannel : nsISupports
* a multipart message. This allows getting the preferred
* handling method, preferred filename, etc. See RFC 2183.
*/
attribute string contentDisposition;
attribute ACString contentDisposition;
};

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

@ -40,10 +40,6 @@
interface nsIURI;
%{C++
#include "nsAString.h"
%}
[scriptable, uuid(15fd6940-8ea7-11d3-93ad-00104ba0fd40)]
interface nsIProtocolHandler : nsISupports
{

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

@ -50,19 +50,20 @@ typedef unsigned long nsLoadFlags;
interface nsIRequest : nsISupports
{
/**
* Returns the name of the request. Often this is the URL of the request.
* The name of the request. Often this is the URI of the request.
*/
readonly attribute wstring name;
readonly attribute AUTF8String name;
/**
* Returns true if the request is pending (active). Returns false
* after completion or successful calling Cancel. Suspended requests
* are still considered pending.
* @return TRUE if the request has yet to reach completion.
* @return FALSE if the request has reached completion (e.g., after
* OnStopRequest has fired).
* Suspended requests are still considered pending.
*/
boolean isPending();
/**
* Returns any error status associated with the request.
* The error status associated with the request.
*/
readonly attribute nsresult status;
@ -72,33 +73,48 @@ interface nsIRequest : nsISupports
* normally pass NS_BINDING_ABORTED, although other errors may also
* be passed. The error passed in will become the value of the
* status attribute.
*
* @param aStatus the reason for canceling this request.
*
* NOTE: most nsIRequest implementations expect aStatus to be a
* failure code; however, some implementations may allow aStatus to
* be a success code such as NS_OK. In general, aStatus should be
* a failure code.
*/
void cancel(in nsresult status);
void cancel(in nsresult aStatus);
/**
* Suspends the current requests. This may have the effect of closing
* Suspends the current request. This may have the effect of closing
* any underlying transport (in order to free up resources), although
* any open streams remain logically opened and will continue delivering
* data when the transport is resumed.
*
* NOTE: some implementations are unable to immediately suspend, and
* may continue to deliver events already posted to an event queue. In
* general, callers should be capable of handling events even after
* suspending a request.
*/
void suspend();
/**
* Resumes the current request. This may have the effect of re-opening
* any underlying transport and will resume the delivery of data to
* any open streams.
* any open streams.
*/
void resume();
/**
* Accesses the load group in which this request is currently a member.
* The load group of this request. While pending, the request is a
* member of the load group. It is the responsibility of the request
* to implement this policy.
*/
attribute nsILoadGroup loadGroup;
/**
* Accesses the load flags for this request. Bits 0-15 are defined (or
* reserved) by nsIRequest. When added to a load group, this request's
* load flags are merged with the load flags of the load group.
* The load flags of this request. Bits 0-15 are reserved.
*
* When added to a load group, this request's load flags are merged with
* the load flags of the load group.
*/
attribute nsLoadFlags loadFlags;
@ -174,7 +190,7 @@ interface nsIRequest : nsISupports
* for example, a HTTP response with a "Cache-control: no-cache" header.
* According to RFC2616, this response must be validated before it can
* be taken from a cache. Breaking this requirement could result in
* incorrect and potentially unpleasant side-effects.
* incorrect and potentially undesirable side-effects.
*/
const unsigned long VALIDATE_ALWAYS = 1 << 11;
const unsigned long VALIDATE_NEVER = 1 << 12;

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

@ -51,10 +51,10 @@ interface nsIFile;
interface nsIStreamIO : nsISupports
{
/**
* Logically opens a stream I/O object, returning its content length
* If this is unknown, the value -1 is returned.
* Logically opens a stream I/O object. This method may block the
* calling thread pending i/o or other delays.
*/
void open(out long contentLength);
void open();
/**
* Logically closes a stream I/O object. A status value is passed in
@ -76,12 +76,22 @@ interface nsIStreamIO : nsISupports
* The 'name' of a stream I/O object. This name is often
* used for display purposes.
*/
readonly attribute string name;
readonly attribute AUTF8String name;
/**
* Associated content type, if any.
**/
readonly attribute string contentType;
*/
readonly attribute ACString contentType;
/**
* Associated content charset, if any.
*/
readonly attribute ACString contentCharset;
/**
* Associated content length; -1 if unknown.
*/
readonly attribute long contentLength;
};
////////////////////////////////////////////////////////////////////////////////
@ -155,9 +165,10 @@ NS_NewFileIO(nsIFileIO **result,
[scriptable, uuid(2d64af08-0d06-11d4-986e-00c04fa0cf4a)]
interface nsIInputStreamIO : nsIStreamIO
{
void init(in string name,
void init(in AUTF8String name,
in nsIInputStream input,
in string contentType,
in ACString contentType,
in ACString contentCharset,
in long contentLength);
};
@ -176,9 +187,10 @@ interface nsIInputStreamIO : nsIStreamIO
inline nsresult
NS_NewInputStreamIO(nsIInputStreamIO* *result,
const char* name,
const nsACString &name,
nsIInputStream* inStr,
const char* contentType,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength)
{
nsresult rv;
@ -189,7 +201,7 @@ NS_NewInputStreamIO(nsIInputStreamIO* *result,
NS_GET_IID(nsIInputStreamIO),
getter_AddRefs(io));
if (NS_FAILED(rv)) return rv;
rv = io->Init(name, inStr, contentType, contentLength);
rv = io->Init(name, inStr, contentType, contentCharset, contentLength);
if (NS_FAILED(rv)) return rv;
*result = io;

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

@ -72,7 +72,6 @@
%{C++
#undef GetPort // XXX Windows!
#undef SetPort // XXX Windows!
#include "nsAString.h"
%}
/**

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

@ -38,8 +38,10 @@
#ifndef nsNetUtil_h__
#define nsNetUtil_h__
#include "nsIURI.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "netCore.h"
#include "nsIURI.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIStreamListener.h"
@ -48,8 +50,6 @@
#include "nsILoadGroup.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsIChannel.h"
@ -325,17 +325,18 @@ inline nsresult
NS_NewInputStreamChannel(nsIChannel **result,
nsIURI* uri,
nsIInputStream* inStr,
const char* contentType,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength)
{
nsresult rv;
nsCAutoString spec;
rv = uri->GetAsciiSpec(spec);
rv = uri->GetSpec(spec);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStreamIO> io;
rv = NS_NewInputStreamIO(getter_AddRefs(io), spec.get(), inStr,
contentType, contentLength);
rv = NS_NewInputStreamIO(getter_AddRefs(io), spec, inStr,
contentType, contentCharset, contentLength);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStreamIOChannel> channel;
@ -803,5 +804,30 @@ NS_ExamineForProxy(const char* scheme, const char* host, PRInt32 port,
return pps->ExamineForProxy(uri, proxyInfo);
}
inline nsresult
NS_ParseContentType(const nsACString &rawContentType,
nsCString &contentType,
nsCString &contentCharset)
{
// contentCharset is left untouched if not present in rawContentType
nsACString::const_iterator begin, it, end;
it = rawContentType.BeginReading(begin);
rawContentType.BeginReading(end);
if (FindCharInReadable(';', it, end)) {
contentType = Substring(begin, it);
// now look for "charset=FOO" and extract "FOO"
begin = ++it;
if (FindInReadable(NS_LITERAL_CSTRING("charset="), begin, it = end)) {
contentCharset = Substring(it, end);
contentCharset.StripWhitespace();
}
}
else
contentType = rawContentType;
ToLowerCase(contentType);
contentType.StripWhitespace();
return NS_OK;
}
#endif // nsNetUtil_h__

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

@ -169,15 +169,12 @@ nsFileIO::GetFile(nsIFile* *aFile)
}
NS_IMETHODIMP
nsFileIO::Open(PRInt32 *contentLength)
nsFileIO::Open()
{
NS_ASSERTION(mFile, "File must not be null");
if (mFile == nsnull)
return NS_ERROR_NOT_INITIALIZED;
if (contentLength)
*contentLength = 0;
nsresult rv = NS_OK;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mFile, &rv);
if (NS_FAILED(rv)) return rv;
@ -196,31 +193,16 @@ nsFileIO::Open(PRInt32 *contentLength)
return NS_ERROR_FILE_NOT_FOUND;
}
if (contentLength) {
// We'll try to use the file's length, if it has one. If not,
// assume the file to be special, and set the content length
// to -1, which means "read the stream until exhausted".
PRInt64 size;
rv = mFile->GetFileSize(&size);
if (NS_SUCCEEDED(rv)) {
*contentLength = nsInt64(size);
if (! *contentLength)
*contentLength = -1;
}
else
*contentLength = -1;
}
PR_LOG(gFileIOLog, PR_LOG_DEBUG,
("nsFileIO: logically opening %s", mSpec));
return rv;
}
NS_IMETHODIMP
nsFileIO::GetContentType(char * *aContentType)
nsFileIO::GetContentType(nsACString &result)
{
if (!mContentType.IsEmpty()) {
*aContentType = ToNewCString(mContentType);
result = mContentType;
return NS_OK;
}
@ -232,20 +214,49 @@ nsFileIO::GetContentType(char * *aContentType)
nsFileTransportService* fileTransportService = nsFileTransportService::GetInstance();
if (fileTransportService) {
mimeServ = fileTransportService->GetCachedMimeService();
if (mimeServ)
rv = mimeServ->GetTypeFromFile(mFile, aContentType);
if (mimeServ) {
nsXPIDLCString mimeType; // XXX fix mime service to use |ACString|
rv = mimeServ->GetTypeFromFile(mFile, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
result = mimeType;
}
}
if (!mimeServ || (NS_FAILED(rv))) {
// if all else fails treat it as text/html?
*aContentType = nsCRT::strdup(UNKNOWN_CONTENT_TYPE);
if (*aContentType == nsnull)
rv = NS_ERROR_OUT_OF_MEMORY;
else
rv = NS_OK;
result = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
}
mContentType.Assign(*aContentType);
mContentType = result;
return NS_OK;
}
NS_IMETHODIMP
nsFileIO::GetContentCharset(nsACString &result)
{
result.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsFileIO::GetContentLength(PRInt32 *result)
{
NS_ENSURE_ARG_POINTER(result);
*result = -1;
if (!mFile)
return NS_ERROR_NOT_INITIALIZED;
// We'll try to use the file's length, if it has one. If not,
// assume the file to be special, and set the content length
// to -1, which means "read the stream until exhausted".
PRInt64 size;
nsresult rv = mFile->GetFileSize(&size);
if (NS_SUCCEEDED(rv)) {
*result = nsInt64(size);
if (*result == 0)
*result = -1;
}
return rv;
}
@ -272,7 +283,7 @@ nsFileIO::GetInputStream(nsIInputStream * *aInputStream)
nsresult rv;
if (!mFD) {
rv = Open(nsnull);
rv = Open();
if (NS_FAILED(rv)) // file or directory does not exist
return rv;
}
@ -325,7 +336,7 @@ nsFileIO::GetOutputStream(nsIOutputStream * *aOutputStream)
nsresult rv;
if (!mFD) {
rv = Open(nsnull);
rv = Open();
if (NS_FAILED(rv)) // file or directory does not exist
return rv;
}
@ -361,13 +372,18 @@ nsFileIO::GetOutputStream(nsIOutputStream * *aOutputStream)
}
NS_IMETHODIMP
nsFileIO::GetName(char* *aName)
nsFileIO::GetName(nsACString &aName)
{
NS_ASSERTION(mFile, "File must not be null");
if (mFile == nsnull)
return NS_ERROR_NOT_INITIALIZED;
return mFile->GetPath(aName);
nsXPIDLCString path;
nsresult rv = mFile->GetPath(getter_Copies(path));
if (NS_FAILED(rv)) return rv;
aName = path;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

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

@ -245,13 +245,18 @@ nsFileTransport::Init(nsFileTransportService *aService, nsIFile* file, PRInt32 i
}
nsresult
nsFileTransport::Init(nsFileTransportService *aService, const char* name, nsIInputStream* inStr,
const char* contentType, PRInt32 contentLength, PRBool closeStreamWhenDone)
nsFileTransport::Init(nsFileTransportService *aService,
const nsACString &name,
nsIInputStream* inStr,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength,
PRBool closeStreamWhenDone)
{
nsresult rv;
nsCOMPtr<nsIInputStreamIO> io;
rv = NS_NewInputStreamIO(getter_AddRefs(io),
name, inStr, contentType, contentLength);
rv = NS_NewInputStreamIO(getter_AddRefs(io), name, inStr,
contentType, contentCharset, contentLength);
if (NS_FAILED(rv)) return rv;
mCloseStreamWhenDone = closeStreamWhenDone;
return Init(aService, io);
@ -267,9 +272,7 @@ nsFileTransport::Init(nsFileTransportService *aService, nsIStreamIO* io)
return NS_ERROR_OUT_OF_MEMORY;
}
mStreamIO = io;
nsXPIDLCString name;
rv = mStreamIO->GetName(getter_Copies(name));
mStreamName = NS_STATIC_CAST(const char*, name);
rv = mStreamIO->GetName(mStreamName);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetName failed");
NS_ADDREF(mService = aService);
@ -317,10 +320,10 @@ nsFileTransport::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileTransport::GetName(PRUnichar* *result)
nsFileTransport::GetName(nsACString &result)
{
*result = ToNewUnicode(mStreamName);
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
result = mStreamName;
return NS_OK;
}
NS_IMETHODIMP
@ -646,7 +649,9 @@ nsFileTransport::Process(nsIProgressEventSink *progressSink)
switch (mXferState) {
case OPEN_FOR_READ: {
mStatus = mStreamIO->Open(&mTotalAmount);
mStatus = mStreamIO->Open();
if (NS_SUCCEEDED(mStatus))
mStreamIO->GetContentLength(&mTotalAmount);
LOG(("nsFileTransport: OPEN_FOR_READ [this=%x %s] status=%x\n", this, mStreamName.get(), mStatus));
if (mListener) {
nsresult rv = mListener->OnStartRequest(this, mContext); // always send the start notification
@ -836,7 +841,9 @@ nsFileTransport::Process(nsIProgressEventSink *progressSink)
case OPEN_FOR_WRITE: {
LOG(("nsFileTransport: OPEN_FOR_WRITE [this=%x %s]\n",
this, mStreamName.get()));
mStatus = mStreamIO->Open(&mTotalAmount);
mStatus = mStreamIO->Open();
if (NS_SUCCEEDED(mStatus)) // XXX why do we care about this when writing?
mStatus = mStreamIO->GetContentLength(&mTotalAmount);
if (mStatus == NS_ERROR_FILE_NOT_FOUND)
mStatus = NS_OK;

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

@ -89,9 +89,10 @@ public:
nsresult Init(nsFileTransportService *aService, nsIFile* file,
PRInt32 ioFlags,
PRInt32 perm);
nsresult Init(nsFileTransportService *aService, const char* name,
nsIInputStream* fromStream,
const char* contentType,
nsresult Init(nsFileTransportService *aService, const nsACString &name,
nsIInputStream *fromStream,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength,
PRBool closeStreamWhenDone);
nsresult Init(nsFileTransportService *aService, nsIStreamIO* io);

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

@ -144,9 +144,10 @@ nsFileTransportService::CreateTransport(nsIFile* file,
}
NS_IMETHODIMP
nsFileTransportService::CreateTransportFromStream(const char* name,
nsFileTransportService::CreateTransportFromStream(const nsACString &name,
nsIInputStream *fromStream,
const char* contentType,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength,
PRBool closeStreamWhenDone,
nsITransport** result)
@ -156,7 +157,9 @@ nsFileTransportService::CreateTransportFromStream(const char* name,
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(trans);
rv = trans->Init(this, name, fromStream, contentType, contentLength, closeStreamWhenDone);
rv = trans->Init(this, name, fromStream,
contentType, contentCharset,
contentLength, closeStreamWhenDone);
if (NS_FAILED(rv)) {
NS_RELEASE(trans);
return rv;

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

@ -41,6 +41,7 @@
#include "nsIOService.h"
#include "nsEscape.h"
#include "nsPrintfCString.h"
#include "nsILocalFile.h"
static void SwapSlashColon(char *s)
{
@ -93,7 +94,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL)
PRBool dir;
rv = aFile->IsDirectory(&dir);
if (NS_FAILED(rv))
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
NS_WARNING(nsPrintfCString(128, "Cannot tell if %s is a directory or file", escPath.get()).get());
else if (dir) {
// make sure we have a trailing slash
escPath += "/";

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

@ -41,6 +41,7 @@
#include "nsIOService.h"
#include "nsEscape.h"
#include "nsPrintfCString.h"
#include "nsILocalFile.h"
#include <os2.h>
static int isleadbyte(int c);
@ -80,7 +81,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
PRBool dir;
rv = aFile->IsDirectory(&dir);
if (NS_FAILED(rv))
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
NS_WARNING(nsPrintfCString(128, "Cannot tell if %s is a directory or file", escPath.get()).get());
else if (dir) {
// make sure we have a trailing slash
escPath += "/";

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

@ -41,6 +41,7 @@
#include "nsIOService.h"
#include "nsEscape.h"
#include "nsPrintfCString.h"
#include "nsILocalFile.h"
NS_IMETHODIMP
nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
@ -65,7 +66,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
PRBool dir;
rv = aFile->IsDirectory(&dir);
if (NS_FAILED(rv))
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
NS_WARNING(nsPrintfCString(128, "Cannot tell if %s is a directory or file", escPath.get()).get());
else if (dir) {
// make sure we have a trailing slash
escPath += "/";

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

@ -41,6 +41,7 @@
#include "nsIOService.h"
#include "nsEscape.h"
#include "nsPrintfCString.h"
#include "nsILocalFile.h"
#include <windows.h>
NS_IMETHODIMP
@ -78,7 +79,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result)
PRBool dir;
rv = aFile->IsDirectory(&dir);
if (NS_FAILED(rv))
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
NS_WARNING(nsPrintfCString(128, "Cannot tell if %s is a directory or file", escPath.get()).get());
else if (dir) {
// make sure we have a trailing slash
escPath += "/";

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

@ -40,10 +40,8 @@
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsIFileTransportService.h"
#include "netCore.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
@ -55,16 +53,14 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsInputStreamIO,
nsIStreamIO)
nsInputStreamIO::nsInputStreamIO()
: mName(nsnull), mContentType(nsnull), mContentLength(-1), mStatus(NS_OK)
: mContentLength(-1), mStatus(NS_OK)
{
NS_INIT_REFCNT();
}
nsInputStreamIO::~nsInputStreamIO()
{
(void)Close(NS_OK);
if (mName) nsCRT::free(mName);
if (mContentType) nsCRT::free(mContentType);
Close(NS_OK);
}
NS_METHOD
@ -82,44 +78,45 @@ nsInputStreamIO::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
}
NS_IMETHODIMP
nsInputStreamIO::Init(const char* name, nsIInputStream* input,
const char* contentType, PRInt32 contentLength)
nsInputStreamIO::Init(const nsACString &name,
nsIInputStream* input,
const nsACString &contentType,
const nsACString &contentCharset,
PRInt32 contentLength)
{
mName = nsCRT::strdup(name);
if (mName == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mName = name;
mInputStream = input;
if (contentType) {
mContentType = nsCRT::strdup(contentType);
const char *constContentType = mContentType;
if (!constContentType) return NS_ERROR_OUT_OF_MEMORY;
char* semicolon = PL_strchr(constContentType, ';');
CBufDescriptor cbd(constContentType,
PR_TRUE,
semicolon ? (semicolon-constContentType) + 1: PL_strlen(constContentType), // capacity
semicolon ? (semicolon-constContentType) : PL_strlen(constContentType));
nsCAutoString str(cbd);
ToLowerCase(str);
}
mContentLength = contentLength;
mContentCharset = contentCharset;
// mContentCharset is unchanged if not parsed
NS_ParseContentType(contentType, mContentType, mContentCharset);
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamIO::Open(PRInt32 *contentLength)
nsInputStreamIO::Open()
{
*contentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamIO::GetContentType(nsACString &aContentType)
{
aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamIO::GetContentType(char * *aContentType)
nsInputStreamIO::GetContentCharset(nsACString &aContentCharset)
{
*aContentType = nsCRT::strdup(mContentType);
if (*aContentType == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
aContentCharset = mContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsInputStreamIO::GetContentLength(PRInt32 *aContentLength)
{
*aContentLength = mContentLength;
return NS_OK;
}
@ -129,7 +126,6 @@ nsInputStreamIO::Close(nsresult status)
mStatus = status;
if (mInputStream)
return mInputStream->Close();
return NS_OK;
}
@ -137,7 +133,7 @@ NS_IMETHODIMP
nsInputStreamIO::GetInputStream(nsIInputStream * *aInputStream)
{
*aInputStream = mInputStream;
NS_ADDREF(*aInputStream);
NS_IF_ADDREF(*aInputStream);
return NS_OK;
}
@ -150,17 +146,17 @@ nsInputStreamIO::GetOutputStream(nsIOutputStream * *aOutputStream)
}
NS_IMETHODIMP
nsInputStreamIO::GetName(char* *aName)
nsInputStreamIO::GetName(nsACString &aName)
{
*aName = nsCRT::strdup(mName);
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aName = mName;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsStreamIOChannel methods:
nsStreamIOChannel::nsStreamIOChannel()
: mContentType(nsnull), mContentLength(-1),
: mContentLength(-1),
mBufferSegmentSize(0), mBufferMaxSize(0),
mLoadFlags(LOAD_NORMAL), mStatus(NS_OK)
{
@ -169,7 +165,6 @@ nsStreamIOChannel::nsStreamIOChannel()
nsStreamIOChannel::~nsStreamIOChannel()
{
if (mContentType) nsCRT::free(mContentType);
}
NS_METHOD
@ -211,14 +206,9 @@ NS_IMPL_THREADSAFE_ADDREF(nsStreamIOChannel)
NS_IMPL_THREADSAFE_RELEASE(nsStreamIOChannel)
NS_IMETHODIMP
nsStreamIOChannel::GetName(PRUnichar* *result)
nsStreamIOChannel::GetName(nsACString &result)
{
nsresult rv;
nsCAutoString urlStr;
rv = mURI->GetSpec(urlStr);
if (NS_FAILED(rv)) return rv;
*result = ToNewUnicode(NS_ConvertUTF8toUCS2(urlStr));
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return mURI->GetSpec(result);
}
NS_IMETHODIMP
@ -299,6 +289,7 @@ nsStreamIOChannel::GetURI(nsIURI* *aURI)
NS_IMETHODIMP
nsStreamIOChannel::Open(nsIInputStream **result)
{
// XXX not calling mStreamIO->Open(), does that matter?
return mStreamIO->GetInputStream(result);
}
@ -415,35 +406,39 @@ nsStreamIOChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
}
NS_IMETHODIMP
nsStreamIOChannel::GetContentType(char * *aContentType)
nsStreamIOChannel::GetContentType(nsACString &aContentType)
{
nsresult rv;
if (mContentType)
{
*aContentType = nsCRT::strdup(mContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
if (mContentType.IsEmpty()) {
nsresult rv = mStreamIO->GetContentType(mContentType);
if (NS_FAILED(rv)) return rv;
}
if (mStreamIO) {
rv = mStreamIO->GetContentType(&mContentType);
*aContentType = nsCRT::strdup(mContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
return NS_ERROR_FAILURE;
aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentType(const char *aContentType)
nsStreamIOChannel::SetContentType(const nsACString &aContentType)
{
mContentType = nsCRT::strdup(aContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
// mContentCharset is unchanged if not parsed
NS_ParseContentType(aContentType, mContentType, mContentCharset);
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetContentCharset(nsACString &aContentCharset)
{
if (mContentCharset.IsEmpty()) {
nsresult rv = mStreamIO->GetContentCharset(mContentCharset);
if (NS_FAILED(rv)) return rv;
}
aContentCharset = mContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentCharset(const nsACString &aContentCharset)
{
mContentCharset = aContentCharset;
return NS_OK;
}
@ -451,15 +446,9 @@ NS_IMETHODIMP
nsStreamIOChannel::GetContentLength(PRInt32 *aContentLength)
{
nsresult rv;
if (mContentLength == -1)
{
// this is broken - should not have to do an open. content
// length should be an attribute of the nsIStreamIO.
rv = mStreamIO->Open(&mContentLength);
if (NS_FAILED(rv))
return rv;
if (mContentLength == -1) {
rv = mStreamIO->GetContentLength(&mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentLength = mContentLength;
return NS_OK;

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

@ -50,6 +50,7 @@
#include "nsIProgressEventSink.h"
#include "nsIStreamIO.h"
#include "nsITransport.h"
#include "nsString.h"
class nsInputStreamIO : public nsIInputStreamIO
{
@ -65,9 +66,10 @@ public:
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
char* mName;
nsCString mName;
nsCOMPtr<nsIInputStream> mInputStream;
char* mContentType;
nsCString mContentType;
nsCString mContentCharset;
PRInt32 mContentLength;
nsresult mStatus;
};
@ -108,8 +110,8 @@ protected:
nsCOMPtr<nsIProgressEventSink> mProgressSink;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mURI;
PRBool mOpened;
char* mContentType;
nsCString mContentType;
nsCString mContentCharset;
PRInt32 mContentLength;
nsCOMPtr<nsIStreamIO> mStreamIO;
nsCOMPtr<nsILoadGroup> mLoadGroup;

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

@ -164,12 +164,12 @@ nsLoadGroup::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
// nsIRequest methods:
NS_IMETHODIMP
nsLoadGroup::GetName(PRUnichar* *result)
nsLoadGroup::GetName(nsACString &result)
{
// XXX is this the right "name" for a load group?
if (!mDefaultLoadRequest) {
*result = nsnull;
result.Truncate();
return NS_OK;
}
@ -230,10 +230,10 @@ nsLoadGroup::Cancel(nsresult status)
continue;
#if defined(PR_LOGGING)
nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
nsCAutoString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Canceling request %x %s.\n",
this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
this, request, nameStr.get()));
#endif
//
@ -290,10 +290,10 @@ nsLoadGroup::Suspend()
continue;
#if defined(PR_LOGGING)
nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
nsCAutoString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Suspending request %x %s.\n",
this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
this, request, nameStr.get()));
#endif
// Suspend the request...
@ -332,10 +332,10 @@ nsLoadGroup::Resume()
continue;
#if defined(PR_LOGGING)
nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
nsCAutoString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Resuming request %x %s.\n",
this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
this, request, nameStr.get()));
#endif
// Resume the request...
@ -409,10 +409,10 @@ nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt)
#if defined(PR_LOGGING)
PRUint32 count = 0;
(void)mRequests->Count(&count);
nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
nsCAutoString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
this, request, NS_ConvertUCS2toUTF8(nameStr).get(), count));
this, request, nameStr.get(), count));
#endif /* PR_LOGGING */
//
@ -488,10 +488,10 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt, nsresult aSta
#if defined(PR_LOGGING)
PRUint32 count = 0;
(void)mRequests->Count(&count);
nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
nsCAutoString nameStr;
request->GetName(nameStr);
LOG(("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
this, request, NS_ConvertUCS2toUTF8(nameStr).get(), aStatus, count-1));
this, request, nameStr.get(), aStatus, count-1));
#endif
//

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

@ -55,6 +55,7 @@
#include "nsIProxyObjectManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsPrintfCString.h"
#include "nsNetUtil.h"
#include "nsISSLSocketControl.h"
#include "nsITransportSecurityInfo.h"
@ -1430,14 +1431,12 @@ nsSocketTransport::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks,
//
nsresult
nsSocketTransport::GetName(PRUnichar **result)
nsSocketTransport::GetName(nsACString &result)
{
nsString name;
name.AppendWithConversion(mHostName);
name.Append(NS_LITERAL_STRING(":"));
name.AppendInt(mPort);
*result = ToNewUnicode(name);
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
result = nsDependentCString(mHostName)
+ NS_LITERAL_CSTRING(":")
+ nsPrintfCString("%d", mPort);
return NS_OK;
}
nsresult
@ -2674,7 +2673,7 @@ nsSocketRequest::OnStop()
}
NS_IMETHODIMP
nsSocketRequest::GetName(PRUnichar **aResult)
nsSocketRequest::GetName(nsACString &aResult)
{
return mTransport ?
mTransport->GetName(aResult) : NS_ERROR_NOT_INITIALIZED;

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

@ -185,7 +185,7 @@ public:
//
// request helpers
//
nsresult GetName(PRUnichar **);
nsresult GetName(nsACString &);
nsresult Dispatch(nsSocketRequest *);
//

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

@ -27,6 +27,7 @@
#include "nsCRT.h"
#include "prmem.h"
#include "netCore.h"
#include "nsAString.h"
#define MAX_IO_CHUNK 8192 // maximum count reported per OnDataAvailable
#define MAX_COUNT ((PRUint32) -1)
@ -526,10 +527,9 @@ nsStorageTransport::nsReadRequest::GetTransport(nsITransport **aTransport)
}
NS_IMETHODIMP
nsStorageTransport::nsReadRequest::GetName(PRUnichar **aName)
nsStorageTransport::nsReadRequest::GetName(nsACString &aName)
{
NS_ENSURE_ARG_POINTER(aName);
*aName = nsnull;
aName.Truncate();
return NS_OK;
}

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

@ -119,7 +119,7 @@ nsURIChecker::AsyncCheckURI(const nsACString &aURI,
// See if it's an http channel, which needs special treatment:
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel);
if (httpChannel)
httpChannel->SetRequestMethod("HEAD");
httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD"));
// Hook us up to listen to redirects and the like
mChannel->SetNotificationCallbacks(this);
@ -138,7 +138,7 @@ nsURIChecker::GetBaseRequest(nsIRequest** aRequest)
// nsIRequest methods
//
NS_IMETHODIMP
nsURIChecker::GetName(PRUnichar** aName)
nsURIChecker::GetName(nsACString &aName)
{
return mChannel->GetName(aName);
}
@ -234,10 +234,11 @@ nsURIChecker::OnStartRequest(nsIRequest *aRequest, nsISupports *aCtxt)
// We don't want to read the actual data, so cancel now:
aRequest->Cancel(NS_BINDING_ABORTED);
char* server = 0;
rv = httpChannel->GetResponseHeader("Server", &server);
nsCAutoString server;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Server"), server);
if (NS_SUCCEEDED(rv)) {
if (!PL_strcasecmp(server, "Netscape-Enterprise/3.6")) {
if (server.Equals(NS_LITERAL_CSTRING("Netscape-Enterprise/3.6"),
nsCaseInsensitiveCStringComparator())) {
mStatus = NS_OK;
// Open a new channel for a real (not head) request:
nsCOMPtr<nsIIOService> ios (do_GetIOService(&rv));
@ -279,12 +280,9 @@ nsURIChecker::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt,
PRUint32 aCount)
{
#ifdef DEBUG_akkana
PRUnichar* uri;
GetName(&uri);
nsString uristr(uri);
char* cstr = ToNewCString(uristr);
printf("OnDataAvailable: %s\n", cstr);
Recycle(cstr);
nsCAutoString name;
GetName(name);
printf("OnDataAvailable: %s\n", name.get());
#endif
// If we've gotten here, something went wrong with the previous cancel,
// so return a failure code to cancel the request:

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

@ -415,7 +415,7 @@ nsDNSRequest::FireStop(nsresult status)
NS_IMETHODIMP
nsDNSRequest::GetName(PRUnichar ** result)
nsDNSRequest::GetName(nsACString & result)
{
NS_NOTREACHED("nsDNSRequest::GetName");
return NS_ERROR_NOT_IMPLEMENTED;

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

@ -56,7 +56,9 @@ nsAboutBlank::NewChannel(nsIURI *aURI, nsIChannel **result)
rv = NS_NewCStringInputStream(getter_AddRefs(in), nsDependentCString(kBlankPage));
if (NS_FAILED(rv)) return rv;
rv = NS_NewInputStreamChannel(&channel, aURI, in, "text/html",
rv = NS_NewInputStreamChannel(&channel, aURI, in,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING(""),
strlen(kBlankPage));
if (NS_FAILED(rv)) return rv;

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

@ -160,7 +160,10 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result)
}
nsIChannel* channel;
rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/plain", size);
rv = NS_NewInputStreamChannel(&channel, aURI, inStr,
NS_LITERAL_CSTRING("text/plain"),
NS_LITERAL_CSTRING(""),
size);
if (NS_FAILED(rv)) return rv;
*result = channel;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше