diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index 7a75e2ad953..c75050c1073 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -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) { diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 90bb40378bf..657c49813fd 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -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 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; } } diff --git a/mozilla/content/base/src/nsRange.cpp b/mozilla/content/base/src/nsRange.cpp index 056993bbb5c..66442de07ec 100644 --- a/mozilla/content/base/src/nsRange.cpp +++ b/mozilla/content/base/src/nsRange.cpp @@ -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 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, diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index 76ce84d4157..a27d2415865 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -637,7 +637,6 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, if (stringLen) { nsAutoString characterSet, preferred; nsCOMPtr unicodeDecoder; - nsCOMPtr httpChannel; nsCOMPtr channel; nsCOMPtr 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 calias(do_GetService(kCharsetAliasCID,&rv)); if(NS_SUCCEEDED(rv) && calias) { diff --git a/mozilla/content/build/nsContentDLF.cpp b/mozilla/content/build/nsContentDLF.cpp index d33254cd4fb..1289be3ab94 100644 --- a/mozilla/content/build/nsContentDLF.cpp +++ b/mozilla/content/build/nsContentDLF.cpp @@ -188,7 +188,7 @@ nsContentDLF::CreateInstance(const char* aCommand, // where 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]; } diff --git a/mozilla/content/build/nsContentHTTPStartup.cpp b/mozilla/content/build/nsContentHTTPStartup.cpp index 9f00ce77054..1849ca68e52 100644 --- a/mozilla/content/build/nsContentHTTPStartup.cpp +++ b/mozilla/content/build/nsContentHTTPStartup.cpp @@ -65,10 +65,10 @@ nsContentHTTPStartup::Observe( nsISupports *aSubject, nsCOMPtr 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; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index b20f090892d..8084d08c873 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -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 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 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 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; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 23f7b2354b3..a52ae1fbfba 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -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 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 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(""), 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--; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index abb3409fc30..5d15dc05feb 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -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); diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.cpp b/mozilla/content/html/document/src/nsWyciwygChannel.cpp index 03c6660de1e..639407ea760 100644 --- a/mozilla/content/html/document/src/nsWyciwygChannel.cpp +++ b/mozilla/content/html/document/src/nsWyciwygChannel.cpp @@ -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; } diff --git a/mozilla/content/html/style/src/nsCSSLoader.cpp b/mozilla/content/html/style/src/nsCSSLoader.cpp index 3d21b03a261..d06479071b1 100644 --- a/mozilla/content/html/style/src/nsCSSLoader.cpp +++ b/mozilla/content/html/style/src/nsCSSLoader.cpp @@ -620,20 +620,19 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader, if (aString && aStringLen>0) { nsCOMPtr request; aLoader->GetRequest(getter_AddRefs(request)); - nsXPIDLCString contentType; + nsCAutoString contentType; if (! (mLoader->mNavQuirkMode)) { nsCOMPtr 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 or * @@ -641,16 +640,16 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader, * default (document charset or ISO-8859-1 if we have no document * charset) */ - nsAutoString strHTTPCharset; - nsCOMPtr httpChannel = do_QueryInterface(request); - if (httpChannel) { - nsXPIDLCString httpCharset; - httpChannel->GetCharset(getter_Copies(httpCharset)); - CopyASCIItoUCS2(httpCharset, strHTTPCharset); + nsAutoString strChannelCharset; + nsCOMPtr 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. diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 96a58a3fe58..f1859a751ba 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -783,7 +783,7 @@ nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aV nsCOMPtr 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 diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index e018b5c60ae..48138a8eaf6 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -433,23 +433,22 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, aContentType = nsnull; } - nsCOMPtr 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 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); diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 020ce2468a7..e9816a4ad49 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -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 proto; @@ -5582,8 +5583,7 @@ nsXULDocument::PrepareToWalk() nsCOMPtr group = do_QueryReferent(mDocumentLoadGroup); if (group) { - nsCOMPtr 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; diff --git a/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp b/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp index e4643575563..d493b584d3f 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp @@ -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. diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index fbae0051f78..cc28c9ed9c5 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -697,7 +697,9 @@ nsDocShell::LoadStream(nsIInputStream * aStream, nsIURI * aURI, // build up a channel for this stream. nsCOMPtr 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 @@ -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 // @@ -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; } diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 7cc9996a0ed..746ceafff00 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -4989,10 +4989,9 @@ NavigatorImpl::GetUserAgent(nsAWritableString& aUserAgent) nsCOMPtr 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 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 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 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 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 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 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 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 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; diff --git a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp index c9775734cf4..f866892200d 100644 --- a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -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) { diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 5a20b6a28bc..8e827e00855 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -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); } } diff --git a/mozilla/embedding/browser/gtk/src/EmbedStream.cpp b/mozilla/embedding/browser/gtk/src/EmbedStream.cpp index 302daf992c5..6216001aa0d 100644 --- a/mozilla/embedding/browser/gtk/src/EmbedStream.cpp +++ b/mozilla/embedding/browser/gtk/src/EmbedStream.cpp @@ -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; diff --git a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp index 8fe354a1a37..11ff2f4e2b6 100644 --- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -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 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 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 diff --git a/mozilla/extensions/cookie/nsCookieHTTPNotify.cpp b/mozilla/extensions/cookie/nsCookieHTTPNotify.cpp index 8fa067ab805..3dd5f0ca17e 100644 --- a/mozilla/extensions/cookie/nsCookieHTTPNotify.cpp +++ b/mozilla/extensions/cookie/nsCookieHTTPNotify.cpp @@ -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 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; } diff --git a/mozilla/extensions/datetime/nsDateTimeChannel.cpp b/mozilla/extensions/datetime/nsDateTimeChannel.cpp index dafa8f487b5..710c05ba9d4 100644 --- a/mozilla/extensions/datetime/nsDateTimeChannel.cpp +++ b/mozilla/extensions/datetime/nsDateTimeChannel.cpp @@ -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) { diff --git a/mozilla/extensions/finger/nsFingerChannel.cpp b/mozilla/extensions/finger/nsFingerChannel.cpp index 76f32765247..b80242261e0 100644 --- a/mozilla/extensions/finger/nsFingerChannel.cpp +++ b/mozilla/extensions/finger/nsFingerChannel.cpp @@ -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) { diff --git a/mozilla/extensions/inspector/base/src/inBitmapChannel.cpp b/mozilla/extensions/inspector/base/src/inBitmapChannel.cpp index 6a9a68264be..c7d43b3f3d6 100644 --- a/mozilla/extensions/inspector/base/src/inBitmapChannel.cpp +++ b/mozilla/extensions/inspector/base/src/inBitmapChannel.cpp @@ -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; } diff --git a/mozilla/extensions/p3p/src/nsP3PService.cpp b/mozilla/extensions/p3p/src/nsP3PService.cpp index f79e014bbe4..36e0f6fc9b2 100644 --- a/mozilla/extensions/p3p/src/nsP3PService.cpp +++ b/mozilla/extensions/p3p/src/nsP3PService.cpp @@ -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 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()); } } diff --git a/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp b/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp index 46448a44878..1407998fafb 100644 --- a/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp +++ b/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp @@ -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, diff --git a/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.h b/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.h index 896cd40b5df..debbc49f9d6 100644 --- a/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.h +++ b/mozilla/extensions/transformiix/source/xslt/txMozillaXMLOutput.h @@ -174,7 +174,7 @@ private: nsCOMPtr mNonAddedNode; PRInt32 mStyleSheetCount; - nsAutoString mRefreshString; + nsCString mRefreshString; nsCOMPtr mNameSpaceManager; diff --git a/mozilla/extensions/xmlextras/base/src/nsDOMParser.cpp b/mozilla/extensions/xmlextras/base/src/nsDOMParser.cpp index caef0fe3936..9a60c82d264 100644 --- a/mozilla/extensions/xmlextras/base/src/nsDOMParser.cpp +++ b/mozilla/extensions/xmlextras/base/src/nsDOMParser.cpp @@ -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) { diff --git a/mozilla/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp b/mozilla/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp index 3f790688fd1..d9bf87826c5 100644 --- a/mozilla/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp +++ b/mozilla/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp @@ -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 httpChannel(do_QueryInterface(mChannel,&rv)); - if(httpChannel) { - nsXPIDLCString charsetheader; - rv = httpChannel->GetCharset(getter_Copies(charsetheader)); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr 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 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 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 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 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 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 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 postDataStream; @@ -1204,7 +1211,8 @@ nsXMLHttpRequest::SetRequestHeader(const char *header, const char *value) nsCOMPtr 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(": "); diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp index 9b612c59694..69bc4d4bbb5 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp @@ -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; diff --git a/mozilla/htmlparser/public/nsIParser.h b/mozilla/htmlparser/public/nsIParser.h index 11463911505..fc7acf63108 100644 --- a/mozilla/htmlparser/public/nsIParser.h +++ b/mozilla/htmlparser/public/nsIParser.h @@ -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; /** diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 0dfb603a30c..2606e9ff227 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -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: diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h index a26912520bd..7b39e84effd 100644 --- a/mozilla/htmlparser/src/CNavDTD.h +++ b/mozilla/htmlparser/src/CNavDTD.h @@ -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; diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 67b0a3daa46..aed03466e75 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -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: diff --git a/mozilla/htmlparser/src/CParserContext.cpp b/mozilla/htmlparser/src/CParserContext.cpp index 5c098e53e81..eb8a9e54aeb 100644 --- a/mozilla/htmlparser/src/CParserContext.cpp +++ b/mozilla/htmlparser/src/CParserContext.cpp @@ -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; } diff --git a/mozilla/htmlparser/src/CParserContext.h b/mozilla/htmlparser/src/CParserContext.h index ff96f192977..9d07555a238 100644 --- a/mozilla/htmlparser/src/CParserContext.h +++ b/mozilla/htmlparser/src/CParserContext.h @@ -77,7 +77,7 @@ public: CParserContext( const CParserContext& aContext); ~CParserContext(); - void SetMimeType(nsAReadableString& aMimeType); + void SetMimeType(const nsACString& aMimeType); nsCOMPtr 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; diff --git a/mozilla/htmlparser/src/nsExpatDriver.cpp b/mozilla/htmlparser/src/nsExpatDriver.cpp index a5cfb6da1c6..7b146b17bc3 100644 --- a/mozilla/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/htmlparser/src/nsExpatDriver.cpp @@ -812,7 +812,7 @@ nsExpatDriver::CanParse(CParserContext& aParserContext, else { if (0 == aParserContext.mMimeType.Length() && kNotFound != aBuffer.Find("mRequest = request; nsresult rv; - char* contentType = nsnull; + nsCAutoString contentType; nsCOMPtr 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("")); } diff --git a/mozilla/htmlparser/src/nsParser.h b/mozilla/htmlparser/src/nsParser.h index 77440c1ffb3..6e58c7f2ed8 100644 --- a/mozilla/htmlparser/src/nsParser.h +++ b/mozilla/htmlparser/src/nsParser.h @@ -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); diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.h b/mozilla/htmlparser/src/nsViewSourceHTML.h index 35af6d8af9e..9c7b0a40f0a 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/htmlparser/src/nsViewSourceHTML.h @@ -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; diff --git a/mozilla/htmlparser/tests/outsinks/Convert.cpp b/mozilla/htmlparser/tests/outsinks/Convert.cpp index 75443b23d09..425b81d382d 100644 --- a/mozilla/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/htmlparser/tests/outsinks/Convert.cpp @@ -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); diff --git a/mozilla/intl/chardet/src/nsObserverBase.cpp b/mozilla/intl/chardet/src/nsObserverBase.cpp index 6236db711df..b85bd35568d 100644 --- a/mozilla/intl/chardet/src/nsObserverBase.cpp +++ b/mozilla/intl/chardet/src/nsObserverBase.cpp @@ -65,12 +65,10 @@ NS_IMETHODIMP nsObserverBase::NotifyWebShell(nsISupports* aWebShell, if (NS_SUCCEEDED(res)) { nsCOMPtr 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; } } } diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index bc0d55f5991..0b6343fc62f 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -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 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; diff --git a/mozilla/layout/build/nsContentDLF.cpp b/mozilla/layout/build/nsContentDLF.cpp index d33254cd4fb..1289be3ab94 100644 --- a/mozilla/layout/build/nsContentDLF.cpp +++ b/mozilla/layout/build/nsContentDLF.cpp @@ -188,7 +188,7 @@ nsContentDLF::CreateInstance(const char* aCommand, // where 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]; } diff --git a/mozilla/layout/build/nsContentHTTPStartup.cpp b/mozilla/layout/build/nsContentHTTPStartup.cpp index 9f00ce77054..1849ca68e52 100644 --- a/mozilla/layout/build/nsContentHTTPStartup.cpp +++ b/mozilla/layout/build/nsContentHTTPStartup.cpp @@ -65,10 +65,10 @@ nsContentHTTPStartup::Observe( nsISupports *aSubject, nsCOMPtr 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; diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index bc0d55f5991..0b6343fc62f 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -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 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; diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index 3d21b03a261..d06479071b1 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -620,20 +620,19 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader, if (aString && aStringLen>0) { nsCOMPtr request; aLoader->GetRequest(getter_AddRefs(request)); - nsXPIDLCString contentType; + nsCAutoString contentType; if (! (mLoader->mNavQuirkMode)) { nsCOMPtr 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 or * @@ -641,16 +640,16 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader, * default (document charset or ISO-8859-1 if we have no document * charset) */ - nsAutoString strHTTPCharset; - nsCOMPtr httpChannel = do_QueryInterface(request); - if (httpChannel) { - nsXPIDLCString httpCharset; - httpChannel->GetCharset(getter_Copies(httpCharset)); - CopyASCIItoUCS2(httpCharset, strHTTPCharset); + nsAutoString strChannelCharset; + nsCOMPtr 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. diff --git a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp index 62ab6360844..d65361cbc0c 100644 --- a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp +++ b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp @@ -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 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 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; } } diff --git a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h index 70724b1ebc0..d1030b2b8a5 100644 --- a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h +++ b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h @@ -108,8 +108,8 @@ private: 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 + nsCString mContentType; // The content type retrieved from the server + nsCString mCharset; // The charset retrieved from the server nsCOMPtr mLoadCookie; // load cookie used by the uri loader when we post the url char *mCookie; diff --git a/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp b/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp index a86e4de7d1b..8e29793a920 100644 --- a/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp @@ -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; diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp index ee238a75264..ca3f46a19fd 100644 --- a/mozilla/mailnews/base/src/nsMessenger.cpp +++ b/mozilla/mailnews/base/src/nsMessenger.cpp @@ -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); diff --git a/mozilla/mailnews/base/util/nsMsgProtocol.cpp b/mozilla/mailnews/base/util/nsMsgProtocol.cpp index 252b73e5d49..a50f3b894f4 100644 --- a/mozilla/mailnews/base/util/nsMsgProtocol.cpp +++ b/mozilla/mailnews/base/util/nsMsgProtocol.cpp @@ -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; } diff --git a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp index d216449b7f7..5cff5ee9c87 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp @@ -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... diff --git a/mozilla/mailnews/compose/src/nsMsgCreate.cpp b/mozilla/mailnews/compose/src/nsMsgCreate.cpp index 4aca631c002..aeb0adeb1ac 100644 --- a/mozilla/mailnews/compose/src/nsMsgCreate.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCreate.cpp @@ -179,7 +179,8 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType } nsCOMPtr 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(); diff --git a/mozilla/mailnews/compose/src/nsSmtpService.cpp b/mozilla/mailnews/compose/src/nsSmtpService.cpp index 3d9ecfc0975..5b2315583c1 100644 --- a/mozilla/mailnews/compose/src/nsSmtpService.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpService.cpp @@ -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; } diff --git a/mozilla/mailnews/compose/src/nsURLFetcher.cpp b/mozilla/mailnews/compose/src/nsURLFetcher.cpp index f52bac4f148..c14560cd219 100644 --- a/mozilla/mailnews/compose/src/nsURLFetcher.cpp +++ b/mozilla/mailnews/compose/src/nsURLFetcher.cpp @@ -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 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 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; } diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.cpp b/mozilla/mailnews/imap/src/nsImapProtocol.cpp index 531e7d8bf10..5ab9f903550 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.cpp +++ b/mozilla/mailnews/imap/src/nsImapProtocol.cpp @@ -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; } diff --git a/mozilla/mailnews/local/src/nsMailboxProtocol.cpp b/mozilla/mailnews/local/src/nsMailboxProtocol.cpp index 40ae0bb6d20..2d3b583d040 100644 --- a/mozilla/mailnews/local/src/nsMailboxProtocol.cpp +++ b/mozilla/mailnews/local/src/nsMailboxProtocol.cpp @@ -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; diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp index 8c00e694518..7aa83aad2dd 100644 --- a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp +++ b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp @@ -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)); } } diff --git a/mozilla/mailnews/mime/src/mimeiimg.cpp b/mozilla/mailnews/mime/src/mimeiimg.cpp index 1b730652006..08b382e510a 100644 --- a/mozilla/mailnews/mime/src/mimeiimg.cpp +++ b/mozilla/mailnews/mime/src/mimeiimg.cpp @@ -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)); } } diff --git a/mozilla/mailnews/mime/src/mimemoz2.cpp b/mozilla/mailnews/mime/src/mimemoz2.cpp index dfacf0ec45c..c3a6bd68054 100644 --- a/mozilla/mailnews/mime/src/mimemoz2.cpp +++ b/mozilla/mailnews/mime/src/mimemoz2.cpp @@ -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! diff --git a/mozilla/modules/libjar/nsIJARChannel.idl b/mozilla/modules/libjar/nsIJARChannel.idl index d3c95f16cee..56ad867e1a4 100644 --- a/mozilla/modules/libjar/nsIJARChannel.idl +++ b/mozilla/modules/libjar/nsIJARChannel.idl @@ -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); - }; diff --git a/mozilla/modules/libjar/nsJARChannel.cpp b/mozilla/modules/libjar/nsJARChannel.cpp index 93f007c6bd8..ccb03572ab9 100644 --- a/mozilla/modules/libjar/nsJARChannel.cpp +++ b/mozilla/modules/libjar/nsJARChannel.cpp @@ -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 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 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) diff --git a/mozilla/modules/libjar/nsJARChannel.h b/mozilla/modules/libjar/nsJARChannel.h index 0f1f7bb9147..89045eb094a 100644 --- a/mozilla/modules/libjar/nsJARChannel.h +++ b/mozilla/modules/libjar/nsJARChannel.h @@ -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 mUserContext; nsCOMPtr mUserListener; - char* mContentType; + nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mJARBaseURI; nsCString mJAREntry; diff --git a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp index ae3f5cd5927..78a9e0ad1db 100644 --- a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp +++ b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp @@ -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; } diff --git a/mozilla/modules/libpr0n/src/imgLoader.cpp b/mozilla/modules/libpr0n/src/imgLoader.cpp index 438cdf7c641..7662249866c 100644 --- a/mozilla/modules/libpr0n/src/imgLoader.cpp +++ b/mozilla/modules/libpr0n/src/imgLoader.cpp @@ -555,10 +555,10 @@ NS_IMETHODIMP ProxyListener::OnStartRequest(nsIRequest *aRequest, nsISupports *c nsCOMPtr 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. diff --git a/mozilla/modules/libpr0n/src/imgRequest.cpp b/mozilla/modules/libpr0n/src/imgRequest.cpp index 70ceee33029..68d3d06e3ff 100644 --- a/mozilla/modules/libpr0n/src/imgRequest.cpp +++ b/mozilla/modules/libpr0n/src/imgRequest.cpp @@ -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 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; } diff --git a/mozilla/modules/libpr0n/src/imgRequest.h b/mozilla/modules/libpr0n/src/imgRequest.h index 63b53df5b25..5d102bead92 100644 --- a/mozilla/modules/libpr0n/src/imgRequest.h +++ b/mozilla/modules/libpr0n/src/imgRequest.h @@ -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 mCacheEntry; /* we hold on to this to this so long as we have observers */ diff --git a/mozilla/modules/libpr0n/src/imgRequestProxy.cpp b/mozilla/modules/libpr0n/src/imgRequestProxy.cpp index 8a509a5d006..55c77546241 100644 --- a/mozilla/modules/libpr0n/src/imgRequestProxy.cpp +++ b/mozilla/modules/libpr0n/src/imgRequestProxy.cpp @@ -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 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, diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 57a6f785f89..edce80031ad 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -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 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 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; diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 234aaf45887..83ef3b81bb3 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -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 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 channel = do_QueryInterface(request); - rv = channel->GetContentType(&contentType); - - if (NS_FAILED(rv)) { - return rv; - } rv = mViewer->StartLoad(request, mNextStream); if (NS_FAILED(rv)) { diff --git a/mozilla/netwerk/base/public/netCore.h b/mozilla/netwerk/base/public/netCore.h index 2cc561d73bf..44dfea2a743 100644 --- a/mozilla/netwerk/base/public/netCore.h +++ b/mozilla/netwerk/base/public/netCore.h @@ -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) diff --git a/mozilla/netwerk/base/public/nsIChannel.idl b/mozilla/netwerk/base/public/nsIChannel.idl index 2660cf3f1c2..27125ef2abf 100644 --- a/mozilla/netwerk/base/public/nsIChannel.idl +++ b/mozilla/netwerk/base/public/nsIChannel.idl @@ -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) -%} diff --git a/mozilla/netwerk/base/public/nsIFileTransportService.idl b/mozilla/netwerk/base/public/nsIFileTransportService.idl index 4017b2e047c..2f262a30624 100644 --- a/mozilla/netwerk/base/public/nsIFileTransportService.idl +++ b/mozilla/netwerk/base/public/nsIFileTransportService.idl @@ -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); diff --git a/mozilla/netwerk/base/public/nsIIOService.idl b/mozilla/netwerk/base/public/nsIIOService.idl index 71fed229ab6..0e11c401a9e 100644 --- a/mozilla/netwerk/base/public/nsIIOService.idl +++ b/mozilla/netwerk/base/public/nsIIOService.idl @@ -43,10 +43,6 @@ interface nsIURI; interface nsIURLParser; interface nsIFile; -%{C++ -#include "nsAString.h" -%} - [scriptable, uuid(ab7c3a84-d488-11d3-8cda-0060b0fc14a3)] interface nsIIOService : nsISupports { diff --git a/mozilla/netwerk/base/public/nsIMultiPartChannel.idl b/mozilla/netwerk/base/public/nsIMultiPartChannel.idl index 362820a44de..62cdbd882e7 100644 --- a/mozilla/netwerk/base/public/nsIMultiPartChannel.idl +++ b/mozilla/netwerk/base/public/nsIMultiPartChannel.idl @@ -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; }; diff --git a/mozilla/netwerk/base/public/nsIProtocolHandler.idl b/mozilla/netwerk/base/public/nsIProtocolHandler.idl index 15c015b39f2..22f4f0c62bc 100644 --- a/mozilla/netwerk/base/public/nsIProtocolHandler.idl +++ b/mozilla/netwerk/base/public/nsIProtocolHandler.idl @@ -40,10 +40,6 @@ interface nsIURI; -%{C++ -#include "nsAString.h" -%} - [scriptable, uuid(15fd6940-8ea7-11d3-93ad-00104ba0fd40)] interface nsIProtocolHandler : nsISupports { diff --git a/mozilla/netwerk/base/public/nsIRequest.idl b/mozilla/netwerk/base/public/nsIRequest.idl index 8de259ddaaf..f1bafa2e9f9 100644 --- a/mozilla/netwerk/base/public/nsIRequest.idl +++ b/mozilla/netwerk/base/public/nsIRequest.idl @@ -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; diff --git a/mozilla/netwerk/base/public/nsIStreamIO.idl b/mozilla/netwerk/base/public/nsIStreamIO.idl index 1e6a9511e88..31e344583f3 100644 --- a/mozilla/netwerk/base/public/nsIStreamIO.idl +++ b/mozilla/netwerk/base/public/nsIStreamIO.idl @@ -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; diff --git a/mozilla/netwerk/base/public/nsIURI.idl b/mozilla/netwerk/base/public/nsIURI.idl index 574f7744c0b..79ddad15475 100644 --- a/mozilla/netwerk/base/public/nsIURI.idl +++ b/mozilla/netwerk/base/public/nsIURI.idl @@ -72,7 +72,6 @@ %{C++ #undef GetPort // XXX Windows! #undef SetPort // XXX Windows! -#include "nsAString.h" %} /** diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index aa225df1088..ca881e43057 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.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 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 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__ diff --git a/mozilla/netwerk/base/src/nsFileStreams.cpp b/mozilla/netwerk/base/src/nsFileStreams.cpp index 98469cef834..d286cc7e1a4 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.cpp +++ b/mozilla/netwerk/base/src/nsFileStreams.cpp @@ -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 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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsFileTransport.cpp b/mozilla/netwerk/base/src/nsFileTransport.cpp index 0d6e5a8a819..6660220e11c 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.cpp +++ b/mozilla/netwerk/base/src/nsFileTransport.cpp @@ -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 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; diff --git a/mozilla/netwerk/base/src/nsFileTransport.h b/mozilla/netwerk/base/src/nsFileTransport.h index 231806ea770..2a1720779af 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.h +++ b/mozilla/netwerk/base/src/nsFileTransport.h @@ -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); diff --git a/mozilla/netwerk/base/src/nsFileTransportService.cpp b/mozilla/netwerk/base/src/nsFileTransportService.cpp index 309b379364c..3b7efcb8cb4 100644 --- a/mozilla/netwerk/base/src/nsFileTransportService.cpp +++ b/mozilla/netwerk/base/src/nsFileTransportService.cpp @@ -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; diff --git a/mozilla/netwerk/base/src/nsIOServiceMac.cpp b/mozilla/netwerk/base/src/nsIOServiceMac.cpp index 53cee6493db..ea3e07b7a62 100644 --- a/mozilla/netwerk/base/src/nsIOServiceMac.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceMac.cpp @@ -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 += "/"; diff --git a/mozilla/netwerk/base/src/nsIOServiceOS2.cpp b/mozilla/netwerk/base/src/nsIOServiceOS2.cpp index 300d0644001..9d48ab3f6eb 100644 --- a/mozilla/netwerk/base/src/nsIOServiceOS2.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceOS2.cpp @@ -41,6 +41,7 @@ #include "nsIOService.h" #include "nsEscape.h" #include "nsPrintfCString.h" +#include "nsILocalFile.h" #include 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 += "/"; diff --git a/mozilla/netwerk/base/src/nsIOServiceUnix.cpp b/mozilla/netwerk/base/src/nsIOServiceUnix.cpp index 36b544473c9..6ac0be1bf45 100644 --- a/mozilla/netwerk/base/src/nsIOServiceUnix.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceUnix.cpp @@ -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 += "/"; diff --git a/mozilla/netwerk/base/src/nsIOServiceWin.cpp b/mozilla/netwerk/base/src/nsIOServiceWin.cpp index 44743434b3f..c32e4fb8d74 100644 --- a/mozilla/netwerk/base/src/nsIOServiceWin.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceWin.cpp @@ -41,6 +41,7 @@ #include "nsIOService.h" #include "nsEscape.h" #include "nsPrintfCString.h" +#include "nsILocalFile.h" #include 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 += "/"; diff --git a/mozilla/netwerk/base/src/nsInputStreamChannel.cpp b/mozilla/netwerk/base/src/nsInputStreamChannel.cpp index 5b81e151ce1..5348bc08943 100644 --- a/mozilla/netwerk/base/src/nsInputStreamChannel.cpp +++ b/mozilla/netwerk/base/src/nsInputStreamChannel.cpp @@ -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; diff --git a/mozilla/netwerk/base/src/nsInputStreamChannel.h b/mozilla/netwerk/base/src/nsInputStreamChannel.h index 258b4a7bea0..ade4e63c98a 100644 --- a/mozilla/netwerk/base/src/nsInputStreamChannel.h +++ b/mozilla/netwerk/base/src/nsInputStreamChannel.h @@ -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 mInputStream; - char* mContentType; + nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsresult mStatus; }; @@ -108,8 +110,8 @@ protected: nsCOMPtr mProgressSink; nsCOMPtr mOriginalURI; nsCOMPtr mURI; - PRBool mOpened; - char* mContentType; + nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mStreamIO; nsCOMPtr mLoadGroup; diff --git a/mozilla/netwerk/base/src/nsLoadGroup.cpp b/mozilla/netwerk/base/src/nsLoadGroup.cpp index 2a008dd91ba..2835c328ac3 100644 --- a/mozilla/netwerk/base/src/nsLoadGroup.cpp +++ b/mozilla/netwerk/base/src/nsLoadGroup.cpp @@ -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 // diff --git a/mozilla/netwerk/base/src/nsSocketTransport.cpp b/mozilla/netwerk/base/src/nsSocketTransport.cpp index 8a8395e698f..39107e723e7 100644 --- a/mozilla/netwerk/base/src/nsSocketTransport.cpp +++ b/mozilla/netwerk/base/src/nsSocketTransport.cpp @@ -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; diff --git a/mozilla/netwerk/base/src/nsSocketTransport.h b/mozilla/netwerk/base/src/nsSocketTransport.h index d33791eeb01..8ced37acd75 100644 --- a/mozilla/netwerk/base/src/nsSocketTransport.h +++ b/mozilla/netwerk/base/src/nsSocketTransport.h @@ -185,7 +185,7 @@ public: // // request helpers // - nsresult GetName(PRUnichar **); + nsresult GetName(nsACString &); nsresult Dispatch(nsSocketRequest *); // diff --git a/mozilla/netwerk/base/src/nsStorageTransport.cpp b/mozilla/netwerk/base/src/nsStorageTransport.cpp index 308d497417d..357aeb41860 100644 --- a/mozilla/netwerk/base/src/nsStorageTransport.cpp +++ b/mozilla/netwerk/base/src/nsStorageTransport.cpp @@ -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; } diff --git a/mozilla/netwerk/base/src/nsURIChecker.cpp b/mozilla/netwerk/base/src/nsURIChecker.cpp index 65556946bf5..945294fce3b 100644 --- a/mozilla/netwerk/base/src/nsURIChecker.cpp +++ b/mozilla/netwerk/base/src/nsURIChecker.cpp @@ -119,7 +119,7 @@ nsURIChecker::AsyncCheckURI(const nsACString &aURI, // See if it's an http channel, which needs special treatment: nsCOMPtr 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 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: diff --git a/mozilla/netwerk/dns/src/nsDnsService.cpp b/mozilla/netwerk/dns/src/nsDnsService.cpp index a2a605ebc38..e1b8ef2944c 100644 --- a/mozilla/netwerk/dns/src/nsDnsService.cpp +++ b/mozilla/netwerk/dns/src/nsDnsService.cpp @@ -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; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutBlank.cpp b/mozilla/netwerk/protocol/about/src/nsAboutBlank.cpp index 07fe115d515..d874194c916 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutBlank.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutBlank.cpp @@ -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; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp index 22ac13287cb..ce756ea4867 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp @@ -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; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutCache.cpp b/mozilla/netwerk/protocol/about/src/nsAboutCache.cpp index 9831669cb68..a0da6bdfe20 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutCache.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutCache.cpp @@ -147,7 +147,10 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) if (NS_FAILED(rv)) return rv; nsIChannel* channel; - rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/html", size); + rv = NS_NewInputStreamChannel(&channel, aURI, inStr, + NS_LITERAL_CSTRING("text/html"), + NS_LITERAL_CSTRING(""), + size); if (NS_FAILED(rv)) return rv; *result = channel; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp b/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp index 879d69e31f2..acf4b9121b3 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutCacheEntry.cpp @@ -130,11 +130,14 @@ nsAboutCacheEntry::OnCacheEntryAvailable(nsICacheEntryDescriptor *descriptor, if (NS_FAILED(rv)) return rv; nsCAutoString spec; - rv = uri->GetAsciiSpec(spec); + rv = uri->GetSpec(spec); if (NS_FAILED(rv)) return rv; nsCOMPtr io; - rv = NS_NewInputStreamIO(getter_AddRefs(io), spec.get(), inStr, "text/html", size); + rv = NS_NewInputStreamIO(getter_AddRefs(io), spec, inStr, + NS_LITERAL_CSTRING("text/html"), + NS_LITERAL_CSTRING(""), + size); nsCOMPtr chan = do_QueryInterface(mStreamChannel, &rv); if (NS_FAILED(rv)) return rv; @@ -150,7 +153,7 @@ nsAboutCacheEntry::OnCacheEntryAvailable(nsICacheEntryDescriptor *descriptor, //----------------------------------------------------------------------------- NS_IMETHODIMP -nsAboutCacheEntry::GetName(PRUnichar **result) +nsAboutCacheEntry::GetName(nsACString &result) { NS_ENSURE_TRUE(mStreamChannel, NS_ERROR_NOT_INITIALIZED); return mStreamChannel->GetName(result); @@ -280,19 +283,33 @@ nsAboutCacheEntry::GetSecurityInfo(nsISupports **value) } NS_IMETHODIMP -nsAboutCacheEntry::GetContentType(char **value) +nsAboutCacheEntry::GetContentType(nsACString &value) { NS_ENSURE_TRUE(mStreamChannel, NS_ERROR_NOT_INITIALIZED); return mStreamChannel->GetContentType(value); } NS_IMETHODIMP -nsAboutCacheEntry::SetContentType(const char *value) +nsAboutCacheEntry::SetContentType(const nsACString &value) { NS_ENSURE_TRUE(mStreamChannel, NS_ERROR_NOT_INITIALIZED); return mStreamChannel->SetContentType(value); } +NS_IMETHODIMP +nsAboutCacheEntry::GetContentCharset(nsACString &value) +{ + NS_ENSURE_TRUE(mStreamChannel, NS_ERROR_NOT_INITIALIZED); + return mStreamChannel->GetContentCharset(value); +} + +NS_IMETHODIMP +nsAboutCacheEntry::SetContentCharset(const nsACString &value) +{ + NS_ENSURE_TRUE(mStreamChannel, NS_ERROR_NOT_INITIALIZED); + return mStreamChannel->SetContentCharset(value); +} + NS_IMETHODIMP nsAboutCacheEntry::GetContentLength(PRInt32 *value) { diff --git a/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp b/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp index 971c9fc5dd4..cf92a39698c 100644 --- a/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp +++ b/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp @@ -146,24 +146,30 @@ nsDataChannel::ParseData() { if (comma == buffer) { // nothing but data - mContentType = "text/plain;charset=US-ASCII"; + // XXX maybe we shouldn't include the charset in the content-type?!? + mContentType = NS_LITERAL_CSTRING("text/plain;charset=US-ASCII"); + mContentCharset = NS_LITERAL_CSTRING("US-ASCII"); } else { // everything else is content type char *semiColon = PL_strchr(buffer, ';'); if (semiColon) *semiColon = '\0'; - nsCAutoString cType(buffer); - ToLowerCase(cType); - mContentType = cType.get(); + mContentType = buffer; + ToLowerCase(mContentType); + + char *charset = PL_strcasestr(semiColon + 1, "charset="); + if (charset) + mContentCharset = charset + sizeof("charset=") - 1; if (semiColon) *semiColon = ';'; } + mContentType.StripWhitespace(); + mContentCharset.StripWhitespace(); char *dataBuffer = nsnull; PRBool cleanup = PR_FALSE; - mContentType.StripWhitespace(); if (!mContentType.Find("text") && !lBase64) { // it's text, don't compress spaces dataBuffer = comma+1; @@ -245,12 +251,11 @@ nsDataChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) // nsIRequest methods: NS_IMETHODIMP -nsDataChannel::GetName(PRUnichar* *result) +nsDataChannel::GetName(nsACString &result) { - nsCAutoString name; if (mUrl) - mUrl->GetSpec(name); - *result = ToNewUnicode(NS_ConvertUTF8toUCS2(name)); + return mUrl->GetSpec(result); + result.Truncate(); return NS_OK; } @@ -391,28 +396,34 @@ nsDataChannel::SetLoadFlags(PRUint32 aLoadFlags) } NS_IMETHODIMP -nsDataChannel::GetContentType(char* *aContentType) { - // Parameter validation... - if (!aContentType) return NS_ERROR_NULL_POINTER; - - if (mContentType.Length()) { - *aContentType = ToNewCString(mContentType); - if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY; - } else { - NS_ASSERTION(0, "data protocol should have content type by now"); - return NS_ERROR_FAILURE; - } - +nsDataChannel::GetContentType(nsACString &aContentType) +{ + NS_ASSERTION(mContentType.Length() > 0, "data protocol should have content type by now"); + aContentType = mContentType; return NS_OK; } NS_IMETHODIMP -nsDataChannel::SetContentType(const char *aContentType) +nsDataChannel::SetContentType(const nsACString &aContentType) { mContentType = aContentType; return NS_OK; } +NS_IMETHODIMP +nsDataChannel::GetContentCharset(nsACString &aContentCharset) +{ + aContentCharset = mContentCharset; + return NS_OK; +} + +NS_IMETHODIMP +nsDataChannel::SetContentCharset(const nsACString &aContentCharset) +{ + mContentCharset = aContentCharset; + return NS_OK; +} + NS_IMETHODIMP nsDataChannel::GetContentLength(PRInt32 *aContentLength) { diff --git a/mozilla/netwerk/protocol/data/src/nsDataChannel.h b/mozilla/netwerk/protocol/data/src/nsDataChannel.h index b8c38207ec2..31cd4c95407 100644 --- a/mozilla/netwerk/protocol/data/src/nsDataChannel.h +++ b/mozilla/netwerk/protocol/data/src/nsDataChannel.h @@ -80,6 +80,7 @@ protected: PRUint32 mLoadFlags; nsCOMPtr mLoadGroup; nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mOwner; nsCOMPtr mListener; diff --git a/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp b/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp index dafa8f487b5..710c05ba9d4 100644 --- a/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp +++ b/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp @@ -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) { diff --git a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp index e24f2f8c592..f5f787ae4f4 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp @@ -44,12 +44,11 @@ #include "nsIServiceManager.h" #include "nsCExternalHandlerService.h" #include "nsIMIMEService.h" -#include "netCore.h" #include "nsIFileTransportService.h" #include "nsIFile.h" #include "nsInt64.h" #include "nsMimeTypes.h" -#include "nsNetCID.h" +#include "nsNetUtil.h" #include "prio.h" // Need to pick up def of PR_RDONLY static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); @@ -135,16 +134,11 @@ nsFileChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) //////////////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsFileChannel::GetName(PRUnichar* *result) +nsFileChannel::GetName(nsACString &result) { if (mCurrentRequest) return mCurrentRequest->GetName(result); - nsresult rv; - nsCAutoString name; - rv = mURI->GetSpec(name); - if (NS_FAILED(rv)) return rv; - *result = ToNewUnicode(NS_ConvertUTF8toUCS2(name)); - return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return mURI->GetSpec(result); } NS_IMETHODIMP @@ -321,45 +315,51 @@ nsFileChannel::SetLoadFlags(PRUint32 aLoadFlags) } NS_IMETHODIMP -nsFileChannel::GetContentType(char * *aContentType) +nsFileChannel::GetContentType(nsACString &aContentType) { - nsresult rv = NS_OK; - - *aContentType = nsnull; + aContentType.Truncate(); if (mContentType.IsEmpty()) { PRBool directory; mFile->IsDirectory(&directory); - if (directory) { - mContentType = APPLICATION_HTTP_INDEX_FORMAT; - } + if (directory) + mContentType = NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT); else { + nsresult rv; nsCOMPtr MIMEService(do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = MIMEService->GetTypeFromFile(mFile, aContentType); - if (NS_SUCCEEDED(rv)) { - mContentType = *aContentType; - return rv; - } + nsXPIDLCString mimeType; + rv = MIMEService->GetTypeFromFile(mFile, getter_Copies(mimeType)); + if (NS_SUCCEEDED(rv)) + mContentType = mimeType; } - if (mContentType.IsEmpty()) { - mContentType = UNKNOWN_CONTENT_TYPE; - } - } - *aContentType = ToNewCString(mContentType); - - if (!*aContentType) { - return NS_ERROR_OUT_OF_MEMORY; - } else { - return NS_OK; + if (mContentType.IsEmpty()) + mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); } + aContentType = mContentType; + return NS_OK; } NS_IMETHODIMP -nsFileChannel::SetContentType(const char *aContentType) +nsFileChannel::SetContentType(const nsACString &aContentType) { - mContentType = aContentType; + // only modifies mContentCharset if a charset is parsed + NS_ParseContentType(aContentType, mContentType, mContentCharset); + return NS_OK; +} + +NS_IMETHODIMP +nsFileChannel::GetContentCharset(nsACString &aContentCharset) +{ + aContentCharset = mContentCharset; + return NS_OK; +} + +NS_IMETHODIMP +nsFileChannel::SetContentCharset(const nsACString &aContentCharset) +{ + mContentCharset = aContentCharset; return NS_OK; } diff --git a/mozilla/netwerk/protocol/file/src/nsFileChannel.h b/mozilla/netwerk/protocol/file/src/nsFileChannel.h index 04841ce35dd..8c0802c576f 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileChannel.h +++ b/mozilla/netwerk/protocol/file/src/nsFileChannel.h @@ -92,6 +92,7 @@ protected: PRInt32 mPerm; nsCOMPtr mFileTransport; nsCString mContentType; + nsCString mContentCharset; PRUint32 mLoadFlags; nsCOMPtr mLoadGroup; nsCOMPtr mOwner; diff --git a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp index 76f32765247..b80242261e0 100644 --- a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp +++ b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp @@ -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) { diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp index af34fbbe63c..49edf3a51ab 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp @@ -167,14 +167,9 @@ nsFTPChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) // cross thread call. NS_IMETHODIMP -nsFTPChannel::GetName(PRUnichar* *result) +nsFTPChannel::GetName(nsACString &result) { - nsresult rv; - nsCAutoString urlStr; - rv = mURL->GetSpec(urlStr); - if (NS_FAILED(rv)) return rv; - *result = ToNewUnicode(NS_ConvertUTF8toUCS2(urlStr)); - return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return mURL->GetSpec(result); } NS_IMETHODIMP @@ -411,40 +406,48 @@ nsFTPChannel::SetLoadFlags(PRUint32 aLoadFlags) // extension mapping. NS_IMETHODIMP -nsFTPChannel::GetContentType(char* *aContentType) { - nsresult rv = NS_OK; - - if (!aContentType) return NS_ERROR_NULL_POINTER; - +nsFTPChannel::GetContentType(nsACString &aContentType) +{ nsAutoLock lock(mLock); - *aContentType = nsnull; - if (mContentType.IsEmpty()) { + aContentType.Truncate(); + if (mContentType.IsEmpty()) { + nsresult rv; nsCOMPtr MIMEService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = MIMEService->GetTypeFromURI(mURL, aContentType); - if (NS_SUCCEEDED(rv)) { - mContentType = *aContentType; - } else { - mContentType = UNKNOWN_CONTENT_TYPE; - rv = NS_OK; - } + nsXPIDLCString mimeType; + rv = MIMEService->GetTypeFromURI(mURL, getter_Copies(mimeType)); + if (NS_SUCCEEDED(rv)) + mContentType = mimeType; + else + mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); } - if (!*aContentType) { - *aContentType = ToNewCString(mContentType); - } + aContentType = mContentType; - if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY; - PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::GetContentType() returned %s\n", *aContentType)); - return rv; + PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::GetContentType() returned %s\n", mContentType.get())); + return NS_OK; } NS_IMETHODIMP -nsFTPChannel::SetContentType(const char *aContentType) +nsFTPChannel::SetContentType(const nsACString &aContentType) { nsAutoLock lock(mLock); - mContentType = aContentType; + NS_ParseContentType(aContentType, mContentType, mContentCharset); + return NS_OK; +} + +NS_IMETHODIMP +nsFTPChannel::GetContentCharset(nsACString &aContentCharset) +{ + aContentCharset = mContentCharset; + return NS_OK; +} + +NS_IMETHODIMP +nsFTPChannel::SetContentCharset(const nsACString &aContentCharset) +{ + mContentCharset = aContentCharset; return NS_OK; } diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h index dd2d956d5d2..47dc206f8ac 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h @@ -138,6 +138,7 @@ protected: PRInt32 mAmount; nsCOMPtr mLoadGroup; nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mOwner; diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index 2b13955b864..cf409f697f7 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -1408,24 +1408,24 @@ nsFtpState::SetContentType() switch (mListFormat) { case nsIDirectoryListing::FORMAT_RAW: { - nsAutoString fromStr(NS_LITERAL_STRING("text/ftp-dir-")); + nsAutoString fromStr(NS_LITERAL_STRING("text/ftp-dir-")); SetDirMIMEType(fromStr); - contentType.Assign("text/ftp-dir-"); + contentType = NS_LITERAL_CSTRING("text/ftp-dir-"); } break; default: NS_WARNING("Unknown directory type"); // fall through case nsIDirectoryListing::FORMAT_HTML: - contentType.Assign(TEXT_HTML); + contentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case nsIDirectoryListing::FORMAT_HTTP_INDEX: - contentType.Assign(APPLICATION_HTTP_INDEX_FORMAT); + contentType = NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT); break; } - return mChannel->SetContentType(contentType.get()); + return mChannel->SetContentType(contentType); } nsresult @@ -1820,14 +1820,9 @@ nsFtpState::R_pasv() { // nsIRequest methods: NS_IMETHODIMP -nsFtpState::GetName(PRUnichar* *result) +nsFtpState::GetName(nsACString &result) { - nsresult rv; - nsCAutoString urlStr; - rv = mURL->GetSpec(urlStr); - if (NS_FAILED(rv)) return rv; - *result = ToNewUnicode(NS_ConvertUTF8toUCS2(urlStr)); - return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return mURL->GetSpec(result); } NS_IMETHODIMP diff --git a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp index d64f33da45d..f16ddcb64f2 100644 --- a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp +++ b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.cpp @@ -147,14 +147,9 @@ nsGopherChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) // nsIRequest methods: NS_IMETHODIMP -nsGopherChannel::GetName(PRUnichar* *result) +nsGopherChannel::GetName(nsACString &result) { - nsString name; - name.AppendWithConversion(mHost); - name.Append(NS_LITERAL_STRING(":")); - name.AppendInt(mPort); - *result = ToNewUnicode(name); - return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return mUrl->GetHostPort(result); } NS_IMETHODIMP @@ -315,89 +310,101 @@ nsGopherChannel::SetLoadFlags(PRUint32 aLoadFlags) } NS_IMETHODIMP -nsGopherChannel::GetContentType(char* *aContentType) +nsGopherChannel::GetContentType(nsACString &aContentType) { - if (!aContentType) return NS_ERROR_NULL_POINTER; - if (!mContentType.IsEmpty()) { - *aContentType = ToNewCString(mContentType); + aContentType = mContentType; return NS_OK; } switch(mType) { case '0': - *aContentType = nsCRT::strdup(TEXT_HTML); + aContentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case '1': switch (mListFormat) { case nsIDirectoryListing::FORMAT_RAW: - *aContentType = nsCRT::strdup("text/gopher-dir"); + aContentType = NS_LITERAL_CSTRING("text/gopher-dir"); break; default: NS_WARNING("Unknown directory type"); // fall through case nsIDirectoryListing::FORMAT_HTML: - *aContentType = nsCRT::strdup(TEXT_HTML); + aContentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case nsIDirectoryListing::FORMAT_HTTP_INDEX: - *aContentType = nsCRT::strdup(APPLICATION_HTTP_INDEX_FORMAT); + aContentType = NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT); break; } break; case '2': // CSO search - unhandled, should not be selectable - *aContentType = nsCRT::strdup(TEXT_HTML); + aContentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case '3': // "Error" - should not be selectable - *aContentType = nsCRT::strdup(TEXT_HTML); + aContentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case '4': // "BinHexed Macintosh file" - *aContentType = nsCRT::strdup(APPLICATION_BINHEX); + aContentType = NS_LITERAL_CSTRING(APPLICATION_BINHEX); break; case '5': // "DOS binary archive of some sort" - is the mime-type correct? - *aContentType = nsCRT::strdup(APPLICATION_OCTET_STREAM); + aContentType = NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM); break; case '6': - *aContentType = nsCRT::strdup(APPLICATION_UUENCODE); + aContentType = NS_LITERAL_CSTRING(APPLICATION_UUENCODE); break; case '7': // search - returns a directory listing - *aContentType = nsCRT::strdup(APPLICATION_HTTP_INDEX_FORMAT); + aContentType = NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT); break; case '8': // telnet - type doesn't make sense - *aContentType = nsCRT::strdup(TEXT_PLAIN); + aContentType = NS_LITERAL_CSTRING(TEXT_PLAIN); break; case '9': // "Binary file!" - *aContentType = nsCRT::strdup(APPLICATION_OCTET_STREAM); + aContentType = NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM); break; case 'g': - *aContentType = nsCRT::strdup(IMAGE_GIF); + aContentType = NS_LITERAL_CSTRING(IMAGE_GIF); break; case 'i': // info line- should not be selectable - *aContentType = nsCRT::strdup(TEXT_HTML); + aContentType = NS_LITERAL_CSTRING(TEXT_HTML); break; case 'I': - *aContentType = nsCRT::strdup(IMAGE_GIF); + aContentType = NS_LITERAL_CSTRING(IMAGE_GIF); break; case 'T': // tn3270 - type doesn't make sense - *aContentType = nsCRT::strdup(TEXT_PLAIN); + aContentType = NS_LITERAL_CSTRING(TEXT_PLAIN); break; default: NS_WARNING("Unknown gopher type"); - *aContentType = nsCRT::strdup(UNKNOWN_CONTENT_TYPE); + aContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); } - if (!*aContentType) - return NS_ERROR_OUT_OF_MEMORY; PR_LOG(gGopherLog,PR_LOG_DEBUG, - ("GetContentType returning %s\n",*aContentType)); + ("GetContentType returning %s\n", PromiseFlatCString(aContentType).get())); + // XXX do we want to cache this result? return NS_OK; } NS_IMETHODIMP -nsGopherChannel::SetContentType(const char *aContentType) +nsGopherChannel::SetContentType(const nsACString &aContentType) { - mContentType.Assign(aContentType); + // only changes mContentCharset if a charset is parsed + NS_ParseContentType(aContentType, mContentType, mContentCharset); + return NS_OK; +} + +NS_IMETHODIMP +nsGopherChannel::GetContentCharset(nsACString &aContentCharset) +{ + aContentCharset = mContentCharset; + return NS_OK; +} + +NS_IMETHODIMP +nsGopherChannel::SetContentCharset(const nsACString &aContentCharset) +{ + mContentCharset = aContentCharset; return NS_OK; } diff --git a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.h b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.h index bfdec6d55a8..f6b694370f7 100644 --- a/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.h +++ b/mozilla/netwerk/protocol/gopher/src/nsGopherChannel.h @@ -71,6 +71,7 @@ protected: PRUint32 mLoadFlags; nsCOMPtr mLoadGroup; nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mOwner; PRUint32 mBufferSegmentSize; diff --git a/mozilla/netwerk/protocol/http/public/nsIHttpChannel.idl b/mozilla/netwerk/protocol/http/public/nsIHttpChannel.idl index 50ee22dddbe..55daa5aeaa3 100644 --- a/mozilla/netwerk/protocol/http/public/nsIHttpChannel.idl +++ b/mozilla/netwerk/protocol/http/public/nsIHttpChannel.idl @@ -37,7 +37,7 @@ interface nsIHttpChannel : nsIChannel /** * The request method is case insensitive */ - attribute string requestMethod; + attribute ACString requestMethod; /** * Get/set the referrer URI on the request. This is the address (URI) of @@ -59,13 +59,12 @@ interface nsIHttpChannel : nsIChannel */ attribute nsIURI documentURI; - /** * Header strings are case insensitive */ - string getRequestHeader(in string header); - void setRequestHeader(in string header, in string value); - void visitRequestHeaders(in nsIHttpHeaderVisitor visitor); + ACString getRequestHeader(in ACString header); + void setRequestHeader(in ACString header, in ACString value); + void visitRequestHeaders(in nsIHttpHeaderVisitor visitor); /** * Get the stream (to be) uploaded by this HTTP channel. @@ -77,14 +76,14 @@ interface nsIHttpChannel : nsIChannel */ readonly attribute unsigned long responseStatus; - readonly attribute string responseStatusText; + readonly attribute ACString responseStatusText; /** * Header strings are case insensitive */ - string getResponseHeader(in string header); - void setResponseHeader(in string header, in string value); - void visitResponseHeaders(in nsIHttpHeaderVisitor visitor); + ACString getResponseHeader(in ACString header); + void setResponseHeader(in ACString header, in ACString value); + void visitResponseHeaders(in nsIHttpHeaderVisitor visitor); /** * True if the server sent a "Cache-control: no-store" response header. @@ -98,12 +97,6 @@ interface nsIHttpChannel : nsIChannel */ boolean isNoCacheResponse(); - /** - * Get the charset for the response, which may be NULL if not specified - * by the server (ie. the Content-Type header may not specify a charset). - */ - readonly attribute string charset; - /** * This attribute holds the MIME types corresponding to the content * encodings on the channel. The enumerator returns nsISupportsString @@ -141,5 +134,8 @@ interface nsIHttpChannel : nsIChannel [scriptable, uuid(0cf40717-d7c1-4a94-8c1e-d6c9734101bb)] interface nsIHttpHeaderVisitor : nsISupports { - void visitHeader(in string header, in string value); + /** + * @throw any exception to terminate enumeration + */ + void visitHeader(in ACString header, in ACString value); }; diff --git a/mozilla/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl b/mozilla/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl index d0e061623cd..dd06f1e9dba 100644 --- a/mozilla/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl +++ b/mozilla/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl @@ -30,51 +30,51 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler /** * Get the HTTP advertised user agent string. */ - readonly attribute string userAgent; + readonly attribute ACString userAgent; /** * Get the application name. * * @return The name of this application (eg. "Mozilla"). */ - readonly attribute string appName; + readonly attribute ACString appName; /** * Get the application version string. * * @return The complete version (major and minor) string. (eg. "5.0") */ - readonly attribute string appVersion; + readonly attribute ACString appVersion; /** * @return The vendor name. */ - attribute string vendor; + attribute ACString vendor; /** * @return The vendor sub string. */ - attribute string vendorSub; + attribute ACString vendorSub; /** * @return The vendor comment. */ - attribute string vendorComment; + attribute ACString vendorComment; /** * @return The product name. */ - attribute string product; + attribute ACString product; /** * @return A product sub string. */ - attribute string productSub; + attribute ACString productSub; /** * @return A product comment. */ - attribute string productComment; + attribute ACString productComment; /** * Get the current platform. @@ -82,26 +82,26 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler * @return The platform this application is running on * (eg. "Windows", "Macintosh", "X11") */ - readonly attribute string platform; + readonly attribute ACString platform; /** * Get the current oscpu. * * @return The oscpu this application is running on */ - readonly attribute string oscpu; + readonly attribute ACString oscpu; /** * Get the translation of the application. The value for language * is usually a 2-letter code such as "en" and occasionally a * five-character code to indicate a language subtype, such as "zh_CN". */ - attribute string language; + attribute ACString language; /** * Get/Set the application comment misc portion. */ - attribute string misc; + attribute ACString misc; }; %{C++ diff --git a/mozilla/netwerk/protocol/http/src/nsHttp.h b/mozilla/netwerk/protocol/http/src/nsHttp.h index 03342b5479d..c393d447161 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttp.h +++ b/mozilla/netwerk/protocol/http/src/nsHttp.h @@ -32,6 +32,7 @@ #include "prlog.h" #include "prtime.h" #include "nsISupportsUtils.h" +#include "nsPromiseFlatString.h" #if defined(PR_LOGGING) // @@ -99,6 +100,7 @@ struct nsHttp // will dynamically add atoms to the table if they don't already exist static nsHttpAtom ResolveAtom(const char *); + static nsHttpAtom ResolveAtom(const nsACString &s) { return ResolveAtom(PromiseFlatCString(s).get()); } /* Declare all atoms * diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp index ae25c288c4a..b5589fa7f25 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -1,4 +1,3 @@ - /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Mozilla Public @@ -39,6 +38,7 @@ #include "nsMimeTypes.h" #include "nsNetUtil.h" #include "nsString.h" +#include "nsPrintfCString.h" #include "nsReadableUtils.h" #include "nsIIDNService.h" #include "plstr.h" @@ -174,7 +174,7 @@ nsHttpChannel::Init(nsIURI *uri, hostLine.AppendInt(port); } - rv = mRequestHead.SetHeader(nsHttp::Host, hostLine.get()); + rv = mRequestHead.SetHeader(nsHttp::Host, hostLine); if (NS_FAILED(rv)) return rv; rv = nsHttpHandler::get()-> @@ -413,11 +413,11 @@ nsHttpChannel::SetupTransaction() // We need to send 'Pragma:no-cache' to inhibit proxy caching even if // no proxy is configured since we might be talking with a transparent // proxy, i.e. one that operates at the network level. See bug #14772. - mRequestHead.SetHeader(nsHttp::Pragma, "no-cache"); + mRequestHead.SetHeader(nsHttp::Pragma, NS_LITERAL_CSTRING("no-cache")); // If we're configured to speak HTTP/1.1 then also send 'Cache-control: // no-cache' if (mRequestHead.Version() >= NS_HTTP_VERSION_1_1) - mRequestHead.SetHeader(nsHttp::Cache_Control, "no-cache"); + mRequestHead.SetHeader(nsHttp::Cache_Control, NS_LITERAL_CSTRING("no-cache")); } else if ((mLoadFlags & VALIDATE_ALWAYS) && (mCacheAccess & nsICache::ACCESS_READ)) { // We need to send 'Cache-Control: max-age=0' to force each cache along @@ -426,9 +426,9 @@ nsHttpChannel::SetupTransaction() // // If we're configured to speak HTTP/1.0 then just send 'Pragma: no-cache' if (mRequestHead.Version() >= NS_HTTP_VERSION_1_1) - mRequestHead.SetHeader(nsHttp::Cache_Control, "max-age=0"); + mRequestHead.SetHeader(nsHttp::Cache_Control, NS_LITERAL_CSTRING("max-age=0")); else - mRequestHead.SetHeader(nsHttp::Pragma, "no-cache"); + mRequestHead.SetHeader(nsHttp::Pragma, NS_LITERAL_CSTRING("no-cache")); } return mTransaction->SetupRequest(&mRequestHead, mUploadStream, @@ -562,17 +562,17 @@ nsHttpChannel::ProcessNormal() // Apache installs. const char *encoding = mResponseHead->PeekHeader(nsHttp::Content_Encoding); if (encoding && PL_strcasestr(encoding, "gzip") && ( - !PL_strcmp(mResponseHead->ContentType(), APPLICATION_GZIP) || - !PL_strcmp(mResponseHead->ContentType(), APPLICATION_GZIP2) || - !PL_strcmp(mResponseHead->ContentType(), APPLICATION_GZIP3))) { + mResponseHead->ContentType().Equals(NS_LITERAL_CSTRING(APPLICATION_GZIP)) || + mResponseHead->ContentType().Equals(NS_LITERAL_CSTRING(APPLICATION_GZIP2)) || + mResponseHead->ContentType().Equals(NS_LITERAL_CSTRING(APPLICATION_GZIP3)))) { // clear the Content-Encoding header - mResponseHead->SetHeader(nsHttp::Content_Encoding, nsnull); + mResponseHead->SetHeader(nsHttp::Content_Encoding, NS_LITERAL_CSTRING("")); } else if (encoding && PL_strcasestr(encoding, "compress") && ( - !PL_strcmp(mResponseHead->ContentType(), APPLICATION_COMPRESS) || - !PL_strcmp(mResponseHead->ContentType(), APPLICATION_COMPRESS2))) { + mResponseHead->ContentType().Equals(NS_LITERAL_CSTRING(APPLICATION_COMPRESS)) || + mResponseHead->ContentType().Equals(NS_LITERAL_CSTRING(APPLICATION_COMPRESS2)))) { // clear the Content-Encoding header - mResponseHead->SetHeader(nsHttp::Content_Encoding, nsnull); + mResponseHead->SetHeader(nsHttp::Content_Encoding, NS_LITERAL_CSTRING("")); } // this must be called before firing OnStartRequest, since http clients, @@ -869,8 +869,8 @@ nsHttpChannel::CheckCache() PRBool doValidation = PR_FALSE; // Be optimistic: assume that we won't need to do validation - mRequestHead.SetHeader(nsHttp::If_Modified_Since, nsnull); - mRequestHead.SetHeader(nsHttp::If_None_Match, nsnull); + mRequestHead.SetHeader(nsHttp::If_Modified_Since, NS_LITERAL_CSTRING("")); + mRequestHead.SetHeader(nsHttp::If_None_Match, NS_LITERAL_CSTRING("")); // If the LOAD_FROM_CACHE flag is set, any cached data can simply be used. if (mLoadFlags & LOAD_FROM_CACHE) { @@ -962,12 +962,12 @@ nsHttpChannel::CheckCache() // Add If-Modified-Since header if a Last-Modified was given val = mCachedResponseHead->PeekHeader(nsHttp::Last_Modified); if (val) - mRequestHead.SetHeader(nsHttp::If_Modified_Since, val); + mRequestHead.SetHeader(nsHttp::If_Modified_Since, nsDependentCString(val)); // Add If-None-Match header if an ETag was given in the response val = mCachedResponseHead->PeekHeader(nsHttp::ETag); if (val) - mRequestHead.SetHeader(nsHttp::If_None_Match, val); + mRequestHead.SetHeader(nsHttp::If_None_Match, nsDependentCString(val)); } LOG(("CheckCache [this=%x doValidation=%d]\n", this, doValidation)); @@ -1358,9 +1358,9 @@ nsHttpChannel::ProcessAuthentication(PRUint32 httpStatus) // set the authentication credentials if (proxyAuth) - mRequestHead.SetHeader(nsHttp::Proxy_Authorization, creds.get()); + mRequestHead.SetHeader(nsHttp::Proxy_Authorization, creds); else - mRequestHead.SetHeader(nsHttp::Authorization, creds.get()); + mRequestHead.SetHeader(nsHttp::Authorization, creds); // kill off the current transaction mTransaction->Cancel(NS_BINDING_REDIRECTED); @@ -1758,7 +1758,7 @@ nsHttpChannel::SetAuthorizationHeader(nsHttpAuthCache *authCache, } if (creds) { LOG((" adding \"%s\" request header\n", header.get())); - mRequestHead.SetHeader(header, creds); + mRequestHead.SetHeader(header, nsDependentCString(creds)); } } } @@ -1823,10 +1823,9 @@ NS_IMPL_THREADSAFE_ISUPPORTS10(nsHttpChannel, //----------------------------------------------------------------------------- NS_IMETHODIMP -nsHttpChannel::GetName(PRUnichar **aName) +nsHttpChannel::GetName(nsACString &aName) { - NS_ENSURE_ARG_POINTER(aName); - *aName = ToNewUnicode(mSpec); + aName = mSpec; return NS_OK; } @@ -1986,15 +1985,16 @@ nsHttpChannel::GetSecurityInfo(nsISupports **securityInfo) } NS_IMETHODIMP -nsHttpChannel::GetContentType(char **value) +nsHttpChannel::GetContentType(nsACString &value) { nsresult rv; - NS_ENSURE_ARG_POINTER(value); - *value = nsnull; + value.Truncate(); - if (mResponseHead && mResponseHead->ContentType()) - return DupString(mResponseHead->ContentType(), value); + if (mResponseHead && !mResponseHead->ContentType().IsEmpty()) { + value = mResponseHead->ContentType(); + return NS_OK; + } // else if the there isn't a response yet or if the response does not // contain a content-type header, try to determine the content type @@ -2022,11 +2022,13 @@ nsHttpChannel::GetContentType(char **value) nsCOMPtr mime; nsHttpHandler::get()->GetMimeService(getter_AddRefs(mime)); if (mime) { - rv = mime->GetTypeFromURI(mURI, value); + nsXPIDLCString mimeType; + rv = mime->GetTypeFromURI(mURI, getter_Copies(mimeType)); if (NS_SUCCEEDED(rv)) { // cache this result if possible if (mResponseHead) - mResponseHead->SetContentType(*value); + mResponseHead->SetContentType(mimeType); + value = mimeType; return rv; } } @@ -2037,16 +2039,43 @@ nsHttpChannel::GetContentType(char **value) if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; - *value = PL_strdup(UNKNOWN_CONTENT_TYPE); - return *value ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + value = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); + return NS_OK; } NS_IMETHODIMP -nsHttpChannel::SetContentType(const char *value) +nsHttpChannel::SetContentType(const nsACString &value) { if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; - mResponseHead->SetContentType(value); + nsCAutoString contentTypeBuf, charsetBuf; + NS_ParseContentType(value, contentTypeBuf, charsetBuf); + + mResponseHead->SetContentType(contentTypeBuf); + + // take care not to stomp on an existing charset + if (!charsetBuf.IsEmpty()) + mResponseHead->SetContentCharset(charsetBuf); + return NS_OK; +} + +NS_IMETHODIMP +nsHttpChannel::GetContentCharset(nsACString &value) +{ + if (!mResponseHead) + return NS_ERROR_NOT_AVAILABLE; + + value = mResponseHead->ContentCharset(); + return NS_OK; +} + +NS_IMETHODIMP +nsHttpChannel::SetContentCharset(const nsACString &value) +{ + if (!mResponseHead) + return NS_ERROR_NOT_AVAILABLE; + + mResponseHead->SetContentCharset(value); return NS_OK; } @@ -2121,12 +2150,13 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context) //----------------------------------------------------------------------------- NS_IMETHODIMP -nsHttpChannel::GetRequestMethod(char **method) +nsHttpChannel::GetRequestMethod(nsACString &method) { - return DupString(mRequestHead.Method().get(), method); + method = mRequestHead.Method(); + return NS_OK; } NS_IMETHODIMP -nsHttpChannel::SetRequestMethod(const char *method) +nsHttpChannel::SetRequestMethod(const nsACString &method) { NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); @@ -2227,7 +2257,7 @@ nsHttpChannel::SetReferrer(nsIURI *referrer, PRUint32 referrerType) mReferrerType = (PRUint8) referrerType; // clear the old referer first - mRequestHead.SetHeader(nsHttp::Referer, nsnull); + mRequestHead.SetHeader(nsHttp::Referer, NS_LITERAL_CSTRING("")); if (referrer) { nsCAutoString spec; @@ -2249,15 +2279,18 @@ nsHttpChannel::SetReferrer(nsIURI *referrer, PRUint32 referrerType) rv = clone->GetAsciiSpec(spec); if (NS_FAILED(rv)) return rv; } - mRequestHead.SetHeader(nsHttp::Referer, spec.get()); + mRequestHead.SetHeader(nsHttp::Referer, spec); } } return NS_OK; } NS_IMETHODIMP -nsHttpChannel::GetRequestHeader(const char *header, char **value) +nsHttpChannel::GetRequestHeader(const nsACString &header, nsACString &value) { + // XXX might be better to search the header list directly instead of + // hitting the http atom hash table. + nsHttpAtom atom = nsHttp::ResolveAtom(header); if (!atom) return NS_ERROR_NOT_AVAILABLE; @@ -2266,12 +2299,12 @@ nsHttpChannel::GetRequestHeader(const char *header, char **value) } NS_IMETHODIMP -nsHttpChannel::SetRequestHeader(const char *header, const char *value) +nsHttpChannel::SetRequestHeader(const nsACString &header, const nsACString &value) { NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); LOG(("nsHttpChannel::SetRequestHeader [this=%x header=%s value=%s]\n", - this, header, value)); + this, PromiseFlatCString(header).get(), PromiseFlatCString(value).get())); nsHttpAtom atom = nsHttp::ResolveAtom(header); if (!atom) { @@ -2316,9 +2349,8 @@ nsHttpChannel::SetUploadStream(nsIInputStream *stream, const char* contentType, return NS_ERROR_FAILURE; } } - nsCAutoString buf; buf.AppendInt(contentLength); - mRequestHead.SetHeader(nsHttp::Content_Length, buf.get()); - mRequestHead.SetHeader(nsHttp::Content_Type, contentType); + mRequestHead.SetHeader(nsHttp::Content_Length, nsPrintfCString("%d", contentLength)); + mRequestHead.SetHeader(nsHttp::Content_Type, nsDependentCString(contentType)); mUploadStreamHasHeaders = PR_FALSE; mRequestHead.SetMethod(nsHttp::Put); // PUT request } @@ -2373,15 +2405,16 @@ nsHttpChannel::GetResponseStatus(PRUint32 *value) } NS_IMETHODIMP -nsHttpChannel::GetResponseStatusText(char **value) +nsHttpChannel::GetResponseStatusText(nsACString &value) { if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; - return DupString(mResponseHead->StatusText(), value); + value = mResponseHead->StatusText(); + return NS_OK; } NS_IMETHODIMP -nsHttpChannel::GetResponseHeader(const char *header, char **value) +nsHttpChannel::GetResponseHeader(const nsACString &header, nsACString &value) { if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; @@ -2392,10 +2425,10 @@ nsHttpChannel::GetResponseHeader(const char *header, char **value) } NS_IMETHODIMP -nsHttpChannel::SetResponseHeader(const char *header, const char *value) +nsHttpChannel::SetResponseHeader(const nsACString &header, const nsACString &value) { LOG(("nsHttpChannel::SetResponseHeader [this=%x header=\"%s\" value=\"%s\"]\n", - this, header, value)); + this, PromiseFlatCString(header).get(), PromiseFlatCString(value).get())); if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; @@ -2449,14 +2482,6 @@ nsHttpChannel::IsNoCacheResponse(PRBool *value) return NS_OK; } -NS_IMETHODIMP -nsHttpChannel::GetCharset(char **value) -{ - if (!mResponseHead) - return NS_ERROR_NOT_AVAILABLE; - return DupString(mResponseHead->ContentCharset(), value); -} - NS_IMETHODIMP nsHttpChannel::GetApplyConversion(PRBool *value) { diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h index 6d3cb176996..2237fee6db0 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h @@ -145,7 +145,7 @@ private: nsHttpTransaction *mPrevTransaction; // hard ref nsHttpConnectionInfo *mConnectionInfo; // hard ref - nsSharableCString mSpec; // ASCII encoded URL spec + nsCString mSpec; // ASCII encoded URL spec PRUint32 mLoadFlags; PRUint32 mStatus; diff --git a/mozilla/netwerk/protocol/http/src/nsHttpConnection.cpp b/mozilla/netwerk/protocol/http/src/nsHttpConnection.cpp index b14542a3582..2fe6923f735 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpConnection.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpConnection.cpp @@ -502,14 +502,14 @@ nsHttpConnection::SetupSSLProxyConnect() if (val) { // all HTTP/1.1 requests must include a Host header (even though it // may seem redundant in this case; see bug 82388). - request.SetHeader(nsHttp::Host, val); + request.SetHeader(nsHttp::Host, nsDependentCString(val)); } val = trans->RequestHead()->PeekHeader(nsHttp::Proxy_Authorization); if (val) { // we don't know for sure if this authorization is intended for the // SSL proxy, so we add it just in case. - request.SetHeader(nsHttp::Proxy_Authorization, val); + request.SetHeader(nsHttp::Proxy_Authorization, nsDependentCString(val)); } buf.Truncate(0); diff --git a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp index 155288e786a..b6c338d7513 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpDigestAuth.cpp @@ -116,7 +116,7 @@ nsHttpDigestAuth::GenerateCredentials(nsIHttpChannel *httpChannel, nsresult rv; nsCOMPtr uri; nsCAutoString path; - nsXPIDLCString httpMethod; + nsCAutoString httpMethod; rv = httpChannel->GetURI(getter_AddRefs(uri)); if (NS_FAILED(rv)) return rv; @@ -124,7 +124,7 @@ nsHttpDigestAuth::GenerateCredentials(nsIHttpChannel *httpChannel, rv = uri->GetPath(path); if (NS_FAILED(rv)) return rv; - rv = httpChannel->GetRequestMethod(getter_Copies(httpMethod)); + rv = httpChannel->GetRequestMethod(httpMethod); if (NS_FAILED(rv)) return rv; nsCAutoString realm, domain, nonce, opaque; diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp index 69ebdc96c00..055794098b6 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -237,7 +237,7 @@ nsHttpHandler::Init() LOG(("> product = %s\n", mProduct.get())); LOG(("> product-sub = %s\n", mProductSub.get())); LOG(("> product-comment = %s\n", mProductComment.get())); - LOG(("> user-agent = %s\n", UserAgent())); + LOG(("> user-agent = %s\n", UserAgent().get())); #endif mSessionStartTime = NowInSeconds(); @@ -288,22 +288,22 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request, // MIME based content negotiation lives! // Add the "Accept" header - rv = request->SetHeader(nsHttp::Accept, mAccept.get()); + rv = request->SetHeader(nsHttp::Accept, mAccept); if (NS_FAILED(rv)) return rv; // Add the "Accept-Language" header if (!mAcceptLanguages.IsEmpty()) { // Add the "Accept-Language" header - rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages.get()); + rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages); if (NS_FAILED(rv)) return rv; } // Add the "Accept-Encoding" header - rv = request->SetHeader(nsHttp::Accept_Encoding, mAcceptEncodings.get()); + rv = request->SetHeader(nsHttp::Accept_Encoding, mAcceptEncodings); if (NS_FAILED(rv)) return rv; // Add the "Accept-Charset" header - rv = request->SetHeader(nsHttp::Accept_Charset, mAcceptCharsets.get()); + rv = request->SetHeader(nsHttp::Accept_Charset, mAcceptCharsets); if (NS_FAILED(rv)) return rv; // RFC2616 section 19.6.2 states that the "Connection: keep-alive" @@ -317,22 +317,17 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request, const char* connectionType = "close"; if (caps & NS_HTTP_ALLOW_KEEPALIVE) { - char buf[32]; - - PR_snprintf(buf, sizeof(buf), "%u", (PRUintn) mIdleTimeout); - - rv = request->SetHeader(nsHttp::Keep_Alive, buf); + rv = request->SetHeader(nsHttp::Keep_Alive, nsPrintfCString("%u", mIdleTimeout)); if (NS_FAILED(rv)) return rv; - connectionType = "keep-alive"; } else if (useProxy) { // Bug 92006 - request->SetHeader(nsHttp::Connection, "close"); + request->SetHeader(nsHttp::Connection, NS_LITERAL_CSTRING("close")); } const nsHttpAtom &header = useProxy ? nsHttp::Proxy_Connection : nsHttp::Connection; - return request->SetHeader(header, connectionType); + return request->SetHeader(header, nsDependentCString(connectionType)); } PRBool @@ -666,12 +661,12 @@ nsHttpHandler::OnExamineResponse(nsIHttpChannel *chan) // nsHttpHandler //----------------------------------------------------------------------------- -const char * +const nsAFlatCString & nsHttpHandler::UserAgent() { if (mUserAgentOverride) { LOG(("using general.useragent.override : %s\n", mUserAgentOverride.get())); - return mUserAgentOverride.get(); + return mUserAgentOverride; } if (mUserAgentIsDirty) { @@ -679,7 +674,7 @@ nsHttpHandler::UserAgent() mUserAgentIsDirty = PR_FALSE; } - return mUserAgent.get(); + return mUserAgent; } nsresult @@ -967,13 +962,30 @@ nsHttpHandler::BuildUserAgent() { LOG(("nsHttpHandler::BuildUserAgent\n")); - NS_ASSERTION(mAppName && - mAppVersion && - mPlatform && - mSecurity && - mOscpu, + NS_ASSERTION(!mAppName.IsEmpty() && + !mAppVersion.IsEmpty() && + !mPlatform.IsEmpty() && + !mSecurity.IsEmpty() && + !mOscpu.IsEmpty(), "HTTP cannot send practical requests without this much"); + // preallocate to worst-case size, which should always be better + // than if we didn't preallocate at all. + mUserAgent.SetCapacity(mAppName.Length() + + mAppVersion.Length() + + mPlatform.Length() + + mSecurity.Length() + + mOscpu.Length() + + mLanguage.Length() + + mMisc.Length() + + mProduct.Length() + + mProductSub.Length() + + mProductComment.Length() + + mVendor.Length() + + mVendorSub.Length() + + mVendorComment.Length() + + 22); + // Application portion mUserAgent.Assign(mAppName); mUserAgent += '/'; @@ -987,25 +999,25 @@ nsHttpHandler::BuildUserAgent() mUserAgent += mSecurity; mUserAgent += "; "; mUserAgent += mOscpu; - if (mLanguage) { + if (!mLanguage.IsEmpty()) { mUserAgent += "; "; mUserAgent += mLanguage; } - if (mMisc) { + if (!mMisc.IsEmpty()) { mUserAgent += "; "; mUserAgent += mMisc; } mUserAgent += ')'; // Product portion - if (mProduct) { + if (!mProduct.IsEmpty()) { mUserAgent += ' '; mUserAgent += mProduct; - if (mProductSub) { + if (!mProductSub.IsEmpty()) { mUserAgent += '/'; mUserAgent += mProductSub; } - if (mProductComment) { + if (!mProductComment.IsEmpty()) { mUserAgent += " ("; mUserAgent += mProductComment; mUserAgent += ')'; @@ -1013,14 +1025,14 @@ nsHttpHandler::BuildUserAgent() } // Vendor portion - if (mVendor) { + if (!mVendor.IsEmpty()) { mUserAgent += ' '; mUserAgent += mVendor; - if (mVendorSub) { + if (!mVendorSub.IsEmpty()) { mUserAgent += '/'; mUserAgent += mVendorSub; } - if (mVendorComment) { + if (!mVendorComment.IsEmpty()) { mUserAgent += " ("; mUserAgent += mVendorComment; mUserAgent += ')'; @@ -1520,7 +1532,7 @@ nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages) nsCString buf; nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf); if (NS_SUCCEEDED(rv)) - mAcceptLanguages.Assign(buf.get()); + mAcceptLanguages.Assign(buf); return rv; } @@ -1648,7 +1660,7 @@ nsHttpHandler::SetAcceptCharsets(const char *aAcceptCharsets) nsCString buf; nsresult rv = PrepareAcceptCharsets(aAcceptCharsets, buf); if (NS_SUCCEEDED(rv)) - mAcceptCharsets.Assign(buf.get()); + mAcceptCharsets.Assign(buf); return rv; } @@ -1792,135 +1804,148 @@ nsHttpHandler::NewProxiedChannel(nsIURI *uri, //----------------------------------------------------------------------------- NS_IMETHODIMP -nsHttpHandler::GetUserAgent(char **aUserAgent) +nsHttpHandler::GetUserAgent(nsACString &value) { - return DupString(UserAgent(), aUserAgent); + value = UserAgent(); + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetAppName(char **aAppName) +nsHttpHandler::GetAppName(nsACString &value) { - return DupString(mAppName, aAppName); + value = mAppName; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetAppVersion(char **aAppVersion) +nsHttpHandler::GetAppVersion(nsACString &value) { - return DupString(mAppVersion, aAppVersion); + value = mAppVersion; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetVendor(char **aVendor) +nsHttpHandler::GetVendor(nsACString &value) { - return DupString(mVendor, aVendor); + value = mVendor; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetVendor(const char *aVendor) +nsHttpHandler::SetVendor(const nsACString &value) { - mVendor.Adopt(aVendor ? nsCRT::strdup(aVendor) : 0); + mVendor = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetVendorSub(char **aVendorSub) +nsHttpHandler::GetVendorSub(nsACString &value) { - return DupString(mVendorSub, aVendorSub); + value = mVendorSub; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetVendorSub(const char *aVendorSub) +nsHttpHandler::SetVendorSub(const nsACString &value) { - mVendorSub.Adopt(aVendorSub ? nsCRT::strdup(aVendorSub) : 0); + mVendorSub = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetVendorComment(char **aVendorComment) +nsHttpHandler::GetVendorComment(nsACString &value) { - return DupString(mVendorComment, aVendorComment); + value = mVendorComment; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetVendorComment(const char *aVendorComment) +nsHttpHandler::SetVendorComment(const nsACString &value) { - mVendorComment.Adopt(aVendorComment ? nsCRT::strdup(aVendorComment) : 0); + mVendorComment = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetProduct(char **aProduct) +nsHttpHandler::GetProduct(nsACString &value) { - return DupString(mProduct, aProduct); + value = mProduct; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetProduct(const char *aProduct) +nsHttpHandler::SetProduct(const nsACString &value) { - mProduct.Adopt(aProduct ? nsCRT::strdup(aProduct) : 0); + mProduct = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetProductSub(char **aProductSub) +nsHttpHandler::GetProductSub(nsACString &value) { - return DupString(mProductSub, aProductSub); + value = mProductSub; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetProductSub(const char *aProductSub) +nsHttpHandler::SetProductSub(const nsACString &value) { - mProductSub.Adopt(aProductSub ? nsCRT::strdup(aProductSub) : 0); + mProductSub = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetProductComment(char **aProductComment) +nsHttpHandler::GetProductComment(nsACString &value) { - return DupString(mProductComment, aProductComment); + mProductComment = value; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetProductComment(const char *aProductComment) +nsHttpHandler::SetProductComment(const nsACString &value) { - mProductComment.Adopt(aProductComment ? nsCRT::strdup(aProductComment) : 0); + mProductComment = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetPlatform(char **aPlatform) +nsHttpHandler::GetPlatform(nsACString &value) { - return DupString(mPlatform, aPlatform); + mPlatform = value; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetOscpu(char **aOscpu) +nsHttpHandler::GetOscpu(nsACString &value) { - return DupString(mOscpu, aOscpu); + value = mOscpu; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetLanguage(char **aLanguage) +nsHttpHandler::GetLanguage(nsACString &value) { - return DupString(mLanguage, aLanguage); + value = mLanguage; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetLanguage(const char *aLanguage) +nsHttpHandler::SetLanguage(const nsACString &value) { - mLanguage.Adopt(aLanguage ? nsCRT::strdup(aLanguage) : 0); + mLanguage = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } NS_IMETHODIMP -nsHttpHandler::GetMisc(char **aMisc) +nsHttpHandler::GetMisc(nsACString &value) { - return DupString(mMisc, aMisc); + value = mMisc; + return NS_OK; } NS_IMETHODIMP -nsHttpHandler::SetMisc(const char *aMisc) +nsHttpHandler::SetMisc(const nsACString &value) { - mMisc.Adopt(aMisc ? nsCRT::strdup(aMisc) : 0); + mMisc = value; mUserAgentIsDirty = PR_TRUE; return NS_OK; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHandler.h b/mozilla/netwerk/protocol/http/src/nsHttpHandler.h index bdd59758162..3129226ee07 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHandler.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpHandler.h @@ -83,14 +83,15 @@ public: PRBool useProxy); PRBool IsAcceptableEncoding(const char *encoding); - const char *UserAgent(); - nsHttpVersion DefaultVersion() { return mHttpVersion; } - PRUint8 ReferrerLevel() { return mReferrerLevel; } - PRBool SendSecureXSiteReferrer() { return mSendSecureXSiteReferrer; } - PRUint8 RedirectionLimit() { return mRedirectionLimit; } - PRUint16 IdleTimeout() { return mIdleTimeout; } - PRUint16 MaxRequestAttempts() { return mMaxRequestAttempts; } - nsIIDNService *IDNConverter() { return mIDNConverter; } + const nsAFlatCString &UserAgent(); + + nsHttpVersion DefaultVersion() { return mHttpVersion; } + PRUint8 ReferrerLevel() { return mReferrerLevel; } + PRBool SendSecureXSiteReferrer() { return mSendSecureXSiteReferrer; } + PRUint8 RedirectionLimit() { return mRedirectionLimit; } + PRUint16 IdleTimeout() { return mIdleTimeout; } + PRUint16 MaxRequestAttempts() { return mMaxRequestAttempts; } + nsIIDNService *IDNConverter() { return mIDNConverter; } nsHttpAuthCache *AuthCache() { return mAuthCache; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.cpp b/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.cpp index 7383d58ebec..1782b9af7b1 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.cpp @@ -29,14 +29,14 @@ //----------------------------------------------------------------------------- nsresult -nsHttpHeaderArray::SetHeader(nsHttpAtom header, const char *value) +nsHttpHeaderArray::SetHeader(nsHttpAtom header, const nsACString &value) { nsEntry *entry = nsnull; PRInt32 index; - // If a NULL value is passed in, then delete the header entry... + // If an empty value is passed in, then delete the header entry... index = LookupEntry(header, &entry); - if (!value || !*value) { + if (value.IsEmpty()) { if (entry) { mHeaders.RemoveElementAt(index); delete entry; @@ -83,10 +83,14 @@ nsHttpHeaderArray::PeekHeader(nsHttpAtom header) } nsresult -nsHttpHeaderArray::GetHeader(nsHttpAtom header, char **result) +nsHttpHeaderArray::GetHeader(nsHttpAtom header, nsACString &result) { - const char *val = PeekHeader(header); - return val ? DupString(val, result) : NS_ERROR_NOT_AVAILABLE; + nsEntry *entry = nsnull; + LookupEntry(header, &entry); + if (!entry) + return NS_ERROR_NOT_AVAILABLE; + result = entry->value; + return NS_OK; } nsresult @@ -96,7 +100,7 @@ nsHttpHeaderArray::VisitHeaders(nsIHttpHeaderVisitor *visitor) PRInt32 i, count = mHeaders.Count(); for (i=0; iVisitHeader(entry->header, entry->value.get()))) + if (NS_FAILED(visitor->VisitHeader(nsDependentCString(entry->header), entry->value))) break; } return NS_OK; @@ -146,7 +150,7 @@ nsHttpHeaderArray::ParseHeaderLine(char *line, nsHttpAtom *hdr, char **val) if (val) *val = p; // assign response header - SetHeader(atom, p); + SetHeader(atom, nsDependentCString(p)); } else LOG(("unknown header; skipping\n")); diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.h b/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.h index 5144b369ec0..cb0666f5cde 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpHeaderArray.h @@ -38,8 +38,8 @@ public: const char *PeekHeader(nsHttpAtom header); - nsresult SetHeader(nsHttpAtom header, const char *value); - nsresult GetHeader(nsHttpAtom header, char **value); + nsresult SetHeader(nsHttpAtom header, const nsACString &value); + nsresult GetHeader(nsHttpAtom header, nsACString &value); nsresult VisitHeaders(nsIHttpHeaderVisitor *visitor); @@ -58,7 +58,7 @@ public: private: struct nsEntry { - nsEntry(nsHttpAtom h, const char *v) + nsEntry(nsHttpAtom h, const nsACString &v) : header(h) { value = v; } nsHttpAtom header; diff --git a/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h b/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h index cba719bf461..1eebe82ed69 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpRequestHead.h @@ -26,7 +26,7 @@ #include "nsHttpHeaderArray.h" #include "nsHttp.h" -#include "nsXPIDLString.h" +#include "nsString.h" //----------------------------------------------------------------------------- // nsHttpRequestHead represents the request line and headers from an HTTP @@ -43,15 +43,15 @@ public: void SetVersion(nsHttpVersion version) { mVersion = version; } void SetRequestURI(const char *s) { mRequestURI.Adopt(s ? nsCRT::strdup(s) : 0); } - nsHttpHeaderArray &Headers() { return mHeaders; } - nsHttpAtom Method() { return mMethod; } - nsHttpVersion Version() { return mVersion; } - const char *RequestURI() { return mRequestURI; } + nsHttpHeaderArray &Headers() { return mHeaders; } + nsHttpAtom Method() { return mMethod; } + nsHttpVersion Version() { return mVersion; } + const nsAFlatCString &RequestURI() { return mRequestURI; } - const char *PeekHeader(nsHttpAtom h) { return mHeaders.PeekHeader(h); } - nsresult SetHeader(nsHttpAtom h, const char *v) { return mHeaders.SetHeader(h, v); } - nsresult GetHeader(nsHttpAtom h, char **v) { return mHeaders.GetHeader(h, v); } - void ClearHeaders() { mHeaders.Clear(); } + const char *PeekHeader(nsHttpAtom h) { return mHeaders.PeekHeader(h); } + nsresult SetHeader(nsHttpAtom h, const nsACString &v) { return mHeaders.SetHeader(h, v); } + nsresult GetHeader(nsHttpAtom h, nsACString &v) { return mHeaders.GetHeader(h, v); } + void ClearHeaders() { mHeaders.Clear(); } void Flatten(nsACString &, PRBool pruneProxyHeaders = PR_FALSE); @@ -59,7 +59,7 @@ private: nsHttpHeaderArray mHeaders; nsHttpAtom mMethod; nsHttpVersion mVersion; - nsXPIDLCString mRequestURI; + nsCString mRequestURI; }; #endif // nsHttpRequestHead_h__ diff --git a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp index 1ca8378c3e1..7084c3159fb 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.cpp @@ -24,6 +24,7 @@ #include #include "nsHttpResponseHead.h" +#include "nsPrintfCString.h" #include "prprf.h" #include "prtime.h" @@ -32,16 +33,16 @@ //----------------------------------------------------------------------------- nsresult -nsHttpResponseHead::SetHeader(nsHttpAtom hdr, const char *val) +nsHttpResponseHead::SetHeader(nsHttpAtom hdr, const nsACString &val) { nsresult rv = mHeaders.SetHeader(hdr, val); if (NS_FAILED(rv)) return rv; // response to changes in these headers if (hdr == nsHttp::Cache_Control) - ParseCacheControl(val); + ParseCacheControl(PromiseFlatCString(val).get()); else if (hdr == nsHttp::Pragma) - ParsePragma(val); + ParsePragma(PromiseFlatCString(val).get()); return NS_OK; } @@ -51,12 +52,9 @@ nsHttpResponseHead::SetContentLength(PRInt32 len) { mContentLength = len; if (len < 0) - SetHeader(nsHttp::Content_Length, nsnull); - else { - nsCAutoString buf; - buf.AppendInt(len); - SetHeader(nsHttp::Content_Length, buf.get()); - } + SetHeader(nsHttp::Content_Length, NS_LITERAL_CSTRING("")); + else + SetHeader(nsHttp::Content_Length, nsPrintfCString("%d", len)); } void @@ -158,7 +156,7 @@ nsHttpResponseHead::ParseStatusLine(char *line) if ((mVersion == NS_HTTP_VERSION_0_9) || !(line = PL_strchr(line, ' '))) { mStatus = 200; - mStatusText = nsCRT::strdup("OK"); + mStatusText = NS_LITERAL_CSTRING("OK"); } else { // Status-Code @@ -171,14 +169,14 @@ nsHttpResponseHead::ParseStatusLine(char *line) // Reason-Phrase is whatever is remaining of the line if (!(line = PL_strchr(line, ' '))) { LOG(("mal-formed response status line; assuming statusText = 'OK'\n")); - mStatusText = nsCRT::strdup("OK"); + mStatusText = NS_LITERAL_CSTRING("OK"); } else - mStatusText = nsCRT::strdup(++line); + mStatusText = ++line; } LOG(("Have status line [version=%u status=%u statusText=%s]\n", - PRUintn(mVersion), PRUintn(mStatus), mStatusText)); + PRUintn(mVersion), PRUintn(mStatus), mStatusText.get())); } void @@ -418,10 +416,10 @@ nsHttpResponseHead::UpdateHeaders(nsHttpHeaderArray &headers) LOG(("new response header [%s: %s]\n", header.get(), val)); // delete the current header value (if any) - mHeaders.SetHeader(header, nsnull); + mHeaders.SetHeader(header, NS_LITERAL_CSTRING("")); // copy the new header value... - mHeaders.SetHeader(header, val); + mHeaders.SetHeader(header, nsDependentCString(val)); } } @@ -441,9 +439,9 @@ nsHttpResponseHead::Reset() mCacheControlNoStore = PR_FALSE; mCacheControlNoCache = PR_FALSE; mPragmaNoCache = PR_FALSE; - CRTFREEIF(mStatusText); - CRTFREEIF(mContentType); - CRTFREEIF(mContentCharset); + mStatusText.Truncate(); + mContentType.Truncate(); + mContentCharset.Truncate(); } nsresult @@ -551,24 +549,24 @@ nsHttpResponseHead::ParseContentType(char *type) // a response could have multiple content type headers... we'll honor // the last one. - CRTFREEIF(mContentCharset); - CRTFREEIF(mContentType); + mContentCharset.Truncate(); + mContentType.Truncate(); // we don't care about comments (although they are invalid here) - char *p = PL_strchr(type, '('); + char *p = (char *) strchr(type, '('); if (p) *p = 0; // check if the content-type has additional fields... - if ((p = PL_strchr(type, ';')) != nsnull) { + if ((p = (char *) strchr(type, ';')) != nsnull) { char *p2, *p3; // is there a charset field? if ((p2 = PL_strcasestr(p, "charset=")) != nsnull) { p2 += 8; // check end of charset parameter - if ((p3 = PL_strchr(p2, ';')) == nsnull) - p3 = p2 + PL_strlen(p2); + if ((p3 = (char *) strchr(p2, ';')) == nsnull) + p3 = p2 + strlen(p2); // trim any trailing whitespace do { @@ -576,11 +574,11 @@ nsHttpResponseHead::ParseContentType(char *type) } while ((*p3 == ' ') || (*p3 == '\t')); *++p3 = 0; // overwrite first char after the charset field - mContentCharset = nsCRT::strdup(p2); + mContentCharset = p2; } } else - p = type + PL_strlen(type); + p = type + strlen(type); // trim any trailing whitespace while (--p >= type && ((*p == ' ') || (*p == '\t'))) @@ -593,7 +591,7 @@ nsHttpResponseHead::ParseContentType(char *type) // If the server sent "*/*", it is meaningless, so do not store it. if (PL_strcmp(type, "*/*")) - mContentType = nsCRT::strdup(type); + mContentType = type; } void diff --git a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h index 9f8a1a2827c..8e26b4edc4a 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpResponseHead.h @@ -26,7 +26,7 @@ #include "nsHttpHeaderArray.h" #include "nsHttp.h" -#include "nsXPIDLString.h" +#include "nsString.h" //----------------------------------------------------------------------------- // nsHttpResponseHead represents the status line and headers from an HTTP @@ -38,34 +38,32 @@ class nsHttpResponseHead public: nsHttpResponseHead() : mVersion(NS_HTTP_VERSION_1_1) , mStatus(200) - , mStatusText(nsnull) , mContentLength(-1) - , mContentType(nsnull) - , mContentCharset(nsnull) , mCacheControlNoStore(PR_FALSE) , mCacheControlNoCache(PR_FALSE) , mPragmaNoCache(PR_FALSE) {} ~nsHttpResponseHead() - { - Reset(); - } + { + Reset(); + } - nsHttpHeaderArray &Headers() { return mHeaders; } - nsHttpVersion Version() { return mVersion; } - PRUint16 Status() { return mStatus; } - const char *StatusText() { return mStatusText; } - PRInt32 ContentLength() { return mContentLength; } - const char *ContentType() { return mContentType; } - const char *ContentCharset() { return mContentCharset; } - PRBool NoStore() { return mCacheControlNoStore; } - PRBool NoCache() { return (mCacheControlNoCache || mPragmaNoCache); } + nsHttpHeaderArray &Headers() { return mHeaders; } + nsHttpVersion Version() { return mVersion; } + PRUint16 Status() { return mStatus; } + const nsAFlatCString &StatusText() { return mStatusText; } + PRInt32 ContentLength() { return mContentLength; } + const nsAFlatCString &ContentType() { return mContentType; } + const nsAFlatCString &ContentCharset() { return mContentCharset; } + PRBool NoStore() { return mCacheControlNoStore; } + PRBool NoCache() { return (mCacheControlNoCache || mPragmaNoCache); } const char *PeekHeader(nsHttpAtom h) { return mHeaders.PeekHeader(h); } - nsresult SetHeader(nsHttpAtom h, const char *v); - nsresult GetHeader(nsHttpAtom h, char **v) { return mHeaders.GetHeader(h, v); } + nsresult SetHeader(nsHttpAtom h, const nsACString &v); + nsresult GetHeader(nsHttpAtom h, nsACString &v) { return mHeaders.GetHeader(h, v); } void ClearHeaders() { mHeaders.Clear(); } - void SetContentType(const char *s) { CRTFREEIF(mContentType); mContentType = strdup_if(s); } + void SetContentType(const nsACString &s) { mContentType = s; } + void SetContentCharset(const nsACString &s) { mContentCharset = s; } void SetContentLength(PRInt32); // write out the response status line and headers as a single text block, @@ -117,10 +115,10 @@ private: nsHttpHeaderArray mHeaders; nsHttpVersion mVersion; PRUint16 mStatus; - char *mStatusText; + nsCString mStatusText; PRInt32 mContentLength; - char *mContentType; - char *mContentCharset; + nsCString mContentType; + nsCString mContentCharset; PRPackedBool mCacheControlNoStore; PRPackedBool mCacheControlNoCache; PRPackedBool mPragmaNoCache; diff --git a/mozilla/netwerk/protocol/http/src/nsHttpTransaction.cpp b/mozilla/netwerk/protocol/http/src/nsHttpTransaction.cpp index 9d4ba395b00..8bcff4f7685 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpTransaction.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpTransaction.cpp @@ -712,7 +712,7 @@ NS_IMPL_THREADSAFE_QUERY_INTERFACE2(nsHttpTransaction, //----------------------------------------------------------------------------- NS_IMETHODIMP -nsHttpTransaction::GetName(PRUnichar **aName) +nsHttpTransaction::GetName(nsACString &aName) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/netwerk/protocol/jar/public/nsIJARChannel.idl b/mozilla/netwerk/protocol/jar/public/nsIJARChannel.idl index d3c95f16cee..56ad867e1a4 100644 --- a/mozilla/netwerk/protocol/jar/public/nsIJARChannel.idl +++ b/mozilla/netwerk/protocol/jar/public/nsIJARChannel.idl @@ -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); - }; diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp index 93f007c6bd8..ccb03572ab9 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -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 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 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) diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h index 0f1f7bb9147..89045eb094a 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h @@ -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 mUserContext; nsCOMPtr mUserListener; - char* mContentType; + nsCString mContentType; + nsCString mContentCharset; PRInt32 mContentLength; nsCOMPtr mJARBaseURI; nsCString mJAREntry; diff --git a/mozilla/netwerk/protocol/keyword/src/nsKeywordProtocolHandler.cpp b/mozilla/netwerk/protocol/keyword/src/nsKeywordProtocolHandler.cpp index b006f82e6d1..140bb6a47ac 100644 --- a/mozilla/netwerk/protocol/keyword/src/nsKeywordProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/keyword/src/nsKeywordProtocolHandler.cpp @@ -123,6 +123,7 @@ MangleKeywordIntoHTTPURL(const char *aSpec, const char *aHTTPURL) { if(unescaped == nsnull) return nsnull; + // XXX this doesn't play nicely w/ i18n URLs nsUnescape(unescaped); // build up a request to the keyword server. diff --git a/mozilla/netwerk/protocol/viewsource/public/nsIViewSourceChannel.idl b/mozilla/netwerk/protocol/viewsource/public/nsIViewSourceChannel.idl index c34a355d00c..f0b1db1cce6 100644 --- a/mozilla/netwerk/protocol/viewsource/public/nsIViewSourceChannel.idl +++ b/mozilla/netwerk/protocol/viewsource/public/nsIViewSourceChannel.idl @@ -55,8 +55,7 @@ interface nsIViewSourceChannel : nsIChannel * However, callers interested in finding out the original * content type can utilize this attribute */ - readonly attribute string originalContentType; - + readonly attribute ACString originalContentType; }; diff --git a/mozilla/netwerk/protocol/viewsource/src/nsViewSourceChannel.cpp b/mozilla/netwerk/protocol/viewsource/src/nsViewSourceChannel.cpp index 24a6c500982..1492e8a4d09 100644 --- a/mozilla/netwerk/protocol/viewsource/src/nsViewSourceChannel.cpp +++ b/mozilla/netwerk/protocol/viewsource/src/nsViewSourceChannel.cpp @@ -104,7 +104,7 @@ nsViewSourceChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResu // nsIRequest methods: NS_IMETHODIMP -nsViewSourceChannel::GetName(PRUnichar* *result) +nsViewSourceChannel::GetName(nsACString &result) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -217,17 +217,18 @@ nsViewSourceChannel::SetLoadFlags(PRUint32 aLoadFlags) #define X_VIEW_SOURCE_PARAM "; x-view-type=view-source" NS_IMETHODIMP -nsViewSourceChannel::GetContentType(char* *aContentType) +nsViewSourceChannel::GetContentType(nsACString &aContentType) { - NS_ENSURE_ARG_POINTER(aContentType); NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); - if(mContentType.IsEmpty()) + aContentType.Truncate(); + + if (mContentType.IsEmpty()) { // Get the current content type nsresult rv; - nsXPIDLCString contentType; - rv = mChannel->GetContentType(getter_Copies(contentType)); + nsCAutoString contentType; + rv = mChannel->GetContentType(contentType); if (NS_FAILED(rv)) return rv; // Tack on the view-source param to the content type @@ -236,40 +237,25 @@ nsViewSourceChannel::GetContentType(char* *aContentType) // the x-view-type param we're indicating a custom preference // of how this should be displayed - viewsource or regular view - nsCAutoString viewSrcContentType; - viewSrcContentType.Append(contentType); - viewSrcContentType.Append(X_VIEW_SOURCE_PARAM); + contentType += NS_LITERAL_CSTRING(X_VIEW_SOURCE_PARAM); // At this stage the content-type string will be // of the form "text/html; x-view-type=view-source" - *aContentType = nsCRT::strdup(viewSrcContentType.get()); - - if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY; - - mContentType = *aContentType; - - return NS_OK; + mContentType = contentType; } - else - { - *aContentType = ToNewCString(mContentType); - if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY; - - return NS_OK; - } + aContentType = mContentType; + return NS_OK; } NS_IMETHODIMP -nsViewSourceChannel::SetContentType(const char *aContentType) +nsViewSourceChannel::SetContentType(const nsACString &aContentType) { - NS_ENSURE_ARG(aContentType); - // Our GetContentType() currently returns strings of the // form "text/html; x-view-type=view-source"(see above) // - // However, during the parsing phase the parser calls our channels' + // However, during the parsing phase the parser calls our channel's // GetContentType(). Returing a string of the form given above // trips up the parser. In order to avoid messy changes and not to have // the parser depend on nsIViewSourceChannel Vidur proposed the @@ -281,15 +267,30 @@ nsViewSourceChannel::SetContentType(const char *aContentType) // After the viewer is created, nsLayoutDLF::CreateInstance() // calls this SetContentType() with the original content type. // When it's time for the parser to find out the content type it - // will call our channels' GetContentType() and it will get the + // will call our channel's GetContentType() and it will get the // original content type, such as, text/html and everything // is kosher from then on mContentType = aContentType; - return NS_OK; } +NS_IMETHODIMP +nsViewSourceChannel::GetContentCharset(nsACString &aContentCharset) +{ + NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); + + return mChannel->GetContentCharset(aContentCharset); +} + +NS_IMETHODIMP +nsViewSourceChannel::SetContentCharset(const nsACString &aContentCharset) +{ + NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); + + return mChannel->SetContentCharset(aContentCharset); +} + NS_IMETHODIMP nsViewSourceChannel::GetContentLength(PRInt32 *aContentLength) { @@ -364,9 +365,8 @@ nsViewSourceChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) // nsIViewSourceChannel methods NS_IMETHODIMP -nsViewSourceChannel::GetOriginalContentType(char* *aContentType) +nsViewSourceChannel::GetOriginalContentType(nsACString &aContentType) { - NS_ENSURE_ARG_POINTER(aContentType); NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); return mChannel->GetContentType(aContentType); @@ -379,7 +379,8 @@ nsViewSourceChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); if (mHttpChannel) { // we don't want view-source following Refresh: headers, so clear it - mHttpChannel->SetResponseHeader("Refresh", nsnull); + mHttpChannel->SetResponseHeader(NS_LITERAL_CSTRING("Refresh"), + NS_LITERAL_CSTRING("")); } return mListener->OnStartRequest(NS_STATIC_CAST(nsIViewSourceChannel*, this), diff --git a/mozilla/netwerk/streamconv/converters/nsBinHexDecoder.cpp b/mozilla/netwerk/streamconv/converters/nsBinHexDecoder.cpp index f0ce9322ac0..fd5e98dda45 100644 --- a/mozilla/netwerk/streamconv/converters/nsBinHexDecoder.cpp +++ b/mozilla/netwerk/streamconv/converters/nsBinHexDecoder.cpp @@ -545,7 +545,7 @@ nsresult nsBinHexDecoder::SetContentType(nsIRequest * aRequest, const char * fil { rv = mimeService->GetTypeFromExtension(fileExt.get(), getter_Copies(contentType)); if (NS_SUCCEEDED(rv) && *(contentType.get())) - mContentType = contentType; + mContentType = contentType; } } } @@ -556,11 +556,11 @@ nsresult nsBinHexDecoder::SetContentType(nsIRequest * aRequest, const char * fil // content type and still think it's mac binhex, then reset to unknown. if (mContentType.IsEmpty() || mContentType.Equals("application/mac-binhex40")) { - mContentType = UNKNOWN_CONTENT_TYPE; + mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); } // now set the content type on the channel. - channel->SetContentType(mContentType.get()); + channel->SetContentType(mContentType); return NS_OK; } diff --git a/mozilla/netwerk/streamconv/converters/nsFTPDirListingConv.cpp b/mozilla/netwerk/streamconv/converters/nsFTPDirListingConv.cpp index 8d0bc78b6f1..5be92969403 100644 --- a/mozilla/netwerk/streamconv/converters/nsFTPDirListingConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsFTPDirListingConv.cpp @@ -221,7 +221,8 @@ nsFTPDirListingConv::AsyncConvertData(const PRUnichar *aFromType, const PRUnicha rv = NS_NewInputStreamChannel(&mPartChannel, uri, nsnull, - APPLICATION_HTTP_INDEX_FORMAT, + NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT), + NS_LITERAL_CSTRING(""), -1); // XXX fix contentLength NS_RELEASE(uri); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp index 48127aeb353..eea49357f22 100644 --- a/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp @@ -137,7 +137,8 @@ nsGopherDirListingConv::AsyncConvertData(const PRUnichar *aFromType, rv = NS_NewInputStreamChannel(&mPartChannel, mUri, nsnull, - APPLICATION_HTTP_INDEX_FORMAT, + NS_LITERAL_CSTRING(APPLICATION_HTTP_INDEX_FORMAT), + NS_LITERAL_CSTRING(""), -1); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp index 26dc738ef25..50dbe2233b9 100644 --- a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -39,7 +39,6 @@ #include "nsMemory.h" #include "plstr.h" #include "nsIHttpChannel.h" -#include "nsIAtom.h" #include "nsIServiceManager.h" #include "nsNetUtil.h" #include "nsMimeTypes.h" @@ -82,6 +81,7 @@ protected: nsCOMPtr mLoadGroup; nsCString mContentType; + nsCString mContentCharset; nsCString mContentDisposition; PRInt32 mContentLength; @@ -140,7 +140,7 @@ NS_INTERFACE_MAP_END // NS_IMETHODIMP -nsPartChannel::GetName(PRUnichar * *aResult) +nsPartChannel::GetName(nsACString &aResult) { return mMultipartChannel->GetName(aResult); } @@ -291,16 +291,30 @@ nsPartChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) } NS_IMETHODIMP -nsPartChannel::GetContentType(char * *aContentType) +nsPartChannel::GetContentType(nsACString &aContentType) { - *aContentType = ToNewCString(mContentType); + aContentType = mContentType; return NS_OK; } NS_IMETHODIMP -nsPartChannel::SetContentType(const char *aContentType) +nsPartChannel::SetContentType(const nsACString &aContentType) { - mContentType.Assign(aContentType); + NS_ParseContentType(aContentType, mContentType, mContentCharset); + return NS_OK; +} + +NS_IMETHODIMP +nsPartChannel::GetContentCharset(nsACString &aContentCharset) +{ + aContentCharset = mContentCharset; + return NS_OK; +} + +NS_IMETHODIMP +nsPartChannel::SetContentCharset(const nsACString &aContentCharset) +{ + mContentCharset = aContentCharset; return NS_OK; } @@ -319,16 +333,16 @@ nsPartChannel::SetContentLength(PRInt32 aContentLength) } NS_IMETHODIMP -nsPartChannel::GetContentDisposition(char * *aContentDisposition) +nsPartChannel::GetContentDisposition(nsACString &aContentDisposition) { - *aContentDisposition = ToNewCString(mContentDisposition); + aContentDisposition = mContentDisposition; return NS_OK; } NS_IMETHODIMP -nsPartChannel::SetContentDisposition(const char *aContentDisposition) +nsPartChannel::SetContentDisposition(const nsACString &aContentDisposition) { - mContentDisposition.Assign(aContentDisposition); + mContentDisposition = aContentDisposition; return NS_OK; } @@ -412,7 +426,7 @@ NS_IMETHODIMP nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) { - if (!mToken.get()) // no token, no love. + if (mToken.IsEmpty()) // no token, no love. return NS_ERROR_FAILURE; nsresult rv = NS_OK; @@ -457,7 +471,7 @@ nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context, // boundary token in for the server. mFirstOnData = PR_FALSE; NS_ASSERTION(!mBufLen, "this is our first time through, we can't have buffered data"); - const char * token = mToken; + const char * token = mToken.get(); PushOverLine(cursor, bufLen); @@ -594,9 +608,9 @@ nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context, NS_IMETHODIMP nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { // we're assuming the content-type is available at this stage - NS_ASSERTION(!mToken, "a second on start???"); - char *bndry = nsnull; - nsXPIDLCString delimiter; + NS_ASSERTION(mToken.IsEmpty(), "a second on start???"); + const char *bndry = nsnull; + nsCAutoString delimiter; nsresult rv = NS_OK; mContext = ctxt; @@ -609,24 +623,23 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { // ask the HTTP channel for the content-type and extract the boundary from it. nsCOMPtr httpChannel = do_QueryInterface(channel, &rv); if (NS_SUCCEEDED(rv)) { - rv = httpChannel->GetResponseHeader("content-type", getter_Copies(delimiter)); + rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-type"), delimiter); if (NS_FAILED(rv)) return rv; } else { // try asking the channel directly - rv = channel->GetContentType(getter_Copies(delimiter)); - if (!delimiter || NS_FAILED(rv)) return NS_ERROR_FAILURE; + rv = channel->GetContentType(delimiter); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; } - if (!delimiter) return NS_ERROR_FAILURE; - bndry = PL_strstr(delimiter, "boundary"); + bndry = strstr(delimiter.get(), "boundary"); if (!bndry) return NS_ERROR_FAILURE; - bndry = PL_strchr(bndry, '='); + bndry = strchr(bndry, '='); if (!bndry) return NS_ERROR_FAILURE; bndry++; // move past the equals sign - char *attrib = PL_strchr(bndry, ';'); + char *attrib = (char *) strchr(bndry, ';'); if (attrib) *attrib = '\0'; nsCAutoString boundaryString(bndry); @@ -634,10 +647,10 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { boundaryString.Trim(" \""); - mToken.Adopt(nsCRT::strdup(boundaryString.get())); + mToken = boundaryString; mTokenLen = boundaryString.Length(); - if (mTokenLen == 0 || !boundaryString.get()) + if (mTokenLen == 0) return NS_ERROR_FAILURE; return NS_OK; @@ -647,7 +660,7 @@ NS_IMETHODIMP nsMultiMixedConv::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus) { - if (!mToken.get()) // no token, no love. + if (mToken.IsEmpty()) // no token, no love. return NS_ERROR_FAILURE; if (mPartChannel) { @@ -721,7 +734,7 @@ nsMultiMixedConv::SendStart(nsIChannel *aChannel) { nsresult rv = NS_OK; if (mContentType.IsEmpty()) - mContentType = UNKNOWN_CONTENT_TYPE; + mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE); // if we already have an mPartChannel, that means we never sent a Stop() // before starting up another "part." that would be bad. @@ -741,7 +754,10 @@ nsMultiMixedConv::SendStart(nsIChannel *aChannel) { // Set up the new part channel... mPartChannel = newChannel; - rv = mPartChannel->SetContentType(mContentType.get()); + rv = mPartChannel->SetContentType(mContentType); + if (NS_FAILED(rv)) return rv; + + rv = mPartChannel->SetContentCharset(mContentCharset); if (NS_FAILED(rv)) return rv; rv = mPartChannel->SetContentLength(mContentLength); @@ -749,7 +765,7 @@ nsMultiMixedConv::SendStart(nsIChannel *aChannel) { nsCOMPtr partChannel(do_QueryInterface(mPartChannel)); if (partChannel) { - rv = partChannel->SetContentDisposition(mContentDisposition.get()); + rv = partChannel->SetContentDisposition(mContentDisposition); if (NS_FAILED(rv)) return rv; } @@ -803,7 +819,7 @@ nsMultiMixedConv::SendData(char *aBuffer, PRUint32 aLen) { if (mContentLength != -1) { // make sure that we don't send more than the mContentLength - if ((aLen + mTotalSent) > mContentLength) + if ((aLen + mTotalSent) > PRUint32(mContentLength)) aLen = mContentLength - mTotalSent; if (aLen == 0) @@ -869,7 +885,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr, if (newLine == cursor) { // move the newLine beyond the double linefeed marker - if ( (newLine - cursor) <= ((PRInt32)cursorLen - lineFeedIncrement) ) { + if (cursorLen >= lineFeedIncrement) { newLine += lineFeedIncrement; } cursorLen -= (newLine - cursor); @@ -893,9 +909,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr, // examine header if (headerStr.EqualsIgnoreCase("content-type")) { - char *tmpString = ToNewCString(headerVal); - ParseContentType(tmpString); - nsCRT::free(tmpString); + NS_ParseContentType(headerVal, mContentType, mContentCharset); } else if (headerStr.EqualsIgnoreCase("content-length")) { mContentLength = atoi(headerVal.get()); } else if (headerStr.EqualsIgnoreCase("content-disposition")) { @@ -906,7 +920,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr, // it's header observers. nsCOMPtr httpChannel = do_QueryInterface(aChannel); if (httpChannel) { - rv = httpChannel->SetResponseHeader(headerStr.get(), headerVal.get()); + rv = httpChannel->SetResponseHeader(headerStr, headerVal); if (NS_FAILED(rv)) return rv; } } else if (headerStr.EqualsIgnoreCase("content-range") || @@ -957,62 +971,10 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr, return rv; } -// This code is duplicated in nsHttpResponseHead.cpp. If you change it -// here, change it there, too! - -nsresult -nsMultiMixedConv::ParseContentType(char *type) -{ - // don't bother with an empty content-type header - bug 83465 - if (!*type) - return NS_OK; - - // we don't care about comments (although they are invalid here) - char *p = PL_strchr(type, '('); - if (p) - *p = 0; - - // check if the content-type has additional fields... - if ((p = PL_strchr(type, ';')) != nsnull) { - char *p2, *p3; - // is there a charset field? - if ((p2 = PL_strcasestr(p, "charset=")) != nsnull) { - p2 += 8; - - // check end of charset parameter - if ((p3 = PL_strchr(p2, ';')) == nsnull) - p3 = p2 + PL_strlen(p2); - - // trim any trailing whitespace - do { - --p3; - } while ((*p3 == ' ') || (*p3 == '\t')); - *++p3 = 0; // overwrite first char after the charset field - - mContentCharset = p2; - } - } - else - p = type + PL_strlen(type); - - // trim any trailing whitespace - while (--p >= type && ((*p == ' ') || (*p == '\t'))) - ; - *++p = 0; // overwrite first char after the media type - - // force the content-type to lowercase - while (--p >= type) - *p = nsCRT::ToLower(*p); - - mContentType = type; - - return NS_OK; -} - char * nsMultiMixedConv::FindToken(char *aCursor, PRUint32 aLen) { // strnstr without looking for null termination - const char *token = mToken; + const char *token = mToken.get(); char *cur = aCursor; NS_ASSERTION(token && aCursor && *token, "bad data"); @@ -1029,9 +991,8 @@ nsMultiMixedConv::FindToken(char *aCursor, PRUint32 aLen) { aLen += 2; // we're playing w/ double dash tokens, adjust. - nsCString newToken("--"); - newToken.Append(mToken); - mToken.Adopt(nsCRT::strdup(newToken.get())); + nsCAutoString newToken(NS_LITERAL_CSTRING("--") + mToken); + mToken = newToken; mTokenLen += 2; } } diff --git a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.h b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.h index 3e2c373a83c..e82c52842e2 100644 --- a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.h +++ b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.h @@ -107,7 +107,6 @@ protected: nsresult SendData(char *aBuffer, PRUint32 aLen); nsresult ParseHeaders(nsIChannel *aChannel, char *&aPtr, PRUint32 &aLen, PRBool *_retval); - nsresult ParseContentType(char *type); PRInt32 PushOverLine(char *&aPtr, PRUint32 &aLen); char *FindToken(char *aCursor, PRUint32 aLen); nsresult BufferData(char *aData, PRUint32 aLen); @@ -117,7 +116,7 @@ protected: PRBool mProcessingHeaders; nsCOMPtr mFinalListener; // this guy gets the converted data via his OnDataAvailable() - nsXPIDLCString mToken; + nsCString mToken; PRUint32 mTokenLen; nsCOMPtrmPartChannel; // the channel for the given part we're processing. diff --git a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp index ce7778f147a..6c579164710 100644 --- a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp +++ b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp @@ -484,7 +484,7 @@ nsresult nsUnknownDecoder::FireListenerNotifications(nsIRequest* request, if (NS_FAILED(rv)) return rv; // Set the new content type on the channel... - rv = channel->SetContentType(mContentType.get()); + rv = channel->SetContentType(mContentType); NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to set content type on channel!"); if (NS_FAILED(rv)) diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index 517d7583e36..e91d8d86b9c 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -59,6 +59,7 @@ #include "nsCOMPtr.h" #include #include "nsInt64.h" +#include "nsFileSpec.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); diff --git a/mozilla/netwerk/test/TestPerf.cpp b/mozilla/netwerk/test/TestPerf.cpp index 4bf4571d12e..e0c68bb727e 100644 --- a/mozilla/netwerk/test/TestPerf.cpp +++ b/mozilla/netwerk/test/TestPerf.cpp @@ -104,9 +104,9 @@ NS_IMETHODIMP MyListener::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status) { if (NS_FAILED(status)) { - nsXPIDLString spec; - req->GetName(getter_Copies(spec)); - fprintf(stderr, "*** failed loading %s\n", NS_ConvertUCS2toUTF8(spec).get()); + nsCAutoString spec; + req->GetName(spec); + fprintf(stderr, "*** failed loading %s\n", spec.get()); } if (--gRequestCount == 0) { // post shutdown event diff --git a/mozilla/netwerk/test/TestProtocols.cpp b/mozilla/netwerk/test/TestProtocols.cpp index 9df89f5e605..960ee8cd897 100644 --- a/mozilla/netwerk/test/TestProtocols.cpp +++ b/mozilla/netwerk/test/TestProtocols.cpp @@ -98,9 +98,11 @@ public: NS_IMPL_ISUPPORTS1(HeaderVisitor, nsIHttpHeaderVisitor) NS_IMETHODIMP -HeaderVisitor::VisitHeader(const char *header, const char *value) +HeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value) { - printf("%s: %s\n", header, value); + printf("%s: %s\n", + PromiseFlatCString(header).get(), + PromiseFlatCString(value).get()); return NS_OK; } @@ -218,7 +220,7 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context) if (gVerbose) printf("\nStarted loading: %s\n", info ? info->Name() : "UNKNOWN URL"); - nsXPIDLCString value; + nsCAutoString value; nsCOMPtr channel = do_QueryInterface(request); if (channel) { @@ -226,8 +228,12 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context) channel->GetStatus(&status); if (NS_SUCCEEDED(status)) { printf("Channel Info:\n"); - channel->GetContentType(getter_Copies(value)); - printf("\tContent-Type: %s\n", (const char*)value); + + channel->GetContentType(value); + printf("\tContent-Type: %s\n", value.get()); + + channel->GetContentCharset(value); + printf("\tContent-Charset: %s\n", value.get()); PRInt32 length = -1; if (NS_SUCCEEDED(channel->GetContentLength(&length))) @@ -244,9 +250,6 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(visitor); - httpChannel->GetCharset(getter_Copies(value)); - printf("\tCharset: %s\n", (const char*)value); - printf("\nHTTP request headers:\n"); httpChannel->VisitRequestHeaders(visitor); @@ -466,7 +469,8 @@ nsresult StartLoadingURL(const char* aUrlString) if (pHTTPCon) { // Setting a sample header. - rv = pHTTPCon->SetRequestHeader("sample-header", "Sample-Value"); + rv = pHTTPCon->SetRequestHeader(NS_LITERAL_CSTRING("sample-header"), + NS_LITERAL_CSTRING("Sample-Value")); if (NS_FAILED(rv)) return rv; } InputTestConsumer* listener; diff --git a/mozilla/parser/htmlparser/public/nsIParser.h b/mozilla/parser/htmlparser/public/nsIParser.h index 11463911505..fc7acf63108 100644 --- a/mozilla/parser/htmlparser/public/nsIParser.h +++ b/mozilla/parser/htmlparser/public/nsIParser.h @@ -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; /** diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index 0dfb603a30c..2606e9ff227 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -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: diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h index a26912520bd..7b39e84effd 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.h +++ b/mozilla/parser/htmlparser/src/CNavDTD.h @@ -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; diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index 67b0a3daa46..aed03466e75 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -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: diff --git a/mozilla/parser/htmlparser/src/CParserContext.cpp b/mozilla/parser/htmlparser/src/CParserContext.cpp index 5c098e53e81..eb8a9e54aeb 100644 --- a/mozilla/parser/htmlparser/src/CParserContext.cpp +++ b/mozilla/parser/htmlparser/src/CParserContext.cpp @@ -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; } diff --git a/mozilla/parser/htmlparser/src/CParserContext.h b/mozilla/parser/htmlparser/src/CParserContext.h index ff96f192977..9d07555a238 100644 --- a/mozilla/parser/htmlparser/src/CParserContext.h +++ b/mozilla/parser/htmlparser/src/CParserContext.h @@ -77,7 +77,7 @@ public: CParserContext( const CParserContext& aContext); ~CParserContext(); - void SetMimeType(nsAReadableString& aMimeType); + void SetMimeType(const nsACString& aMimeType); nsCOMPtr 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; diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index a5cfb6da1c6..7b146b17bc3 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -812,7 +812,7 @@ nsExpatDriver::CanParse(CParserContext& aParserContext, else { if (0 == aParserContext.mMimeType.Length() && kNotFound != aBuffer.Find("mRequest = request; nsresult rv; - char* contentType = nsnull; + nsCAutoString contentType; nsCOMPtr 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("")); } diff --git a/mozilla/parser/htmlparser/src/nsParser.h b/mozilla/parser/htmlparser/src/nsParser.h index 77440c1ffb3..6e58c7f2ed8 100644 --- a/mozilla/parser/htmlparser/src/nsParser.h +++ b/mozilla/parser/htmlparser/src/nsParser.h @@ -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); diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h index 35af6d8af9e..9c7b0a40f0a 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h @@ -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; diff --git a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp index 75443b23d09..425b81d382d 100644 --- a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp @@ -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); diff --git a/mozilla/rdf/base/src/nsRDFXMLParser.cpp b/mozilla/rdf/base/src/nsRDFXMLParser.cpp index 925e0ee4a0c..37cd6c67240 100644 --- a/mozilla/rdf/base/src/nsRDFXMLParser.cpp +++ b/mozilla/rdf/base/src/nsRDFXMLParser.cpp @@ -129,8 +129,10 @@ nsRDFXMLParser::ParseString(nsIRDFDataSource* aSink, nsIURI* aBaseURI, const nsA if (NS_FAILED(rv)) return rv; nsCOMPtr channel; - rv = NS_NewInputStreamChannel(getter_AddRefs(channel), aBaseURI, - stream, "text/xml", aString.Length()); + rv = NS_NewInputStreamChannel(getter_AddRefs(channel), aBaseURI, stream, + NS_LITERAL_CSTRING("text/xml"), + NS_LITERAL_CSTRING(""), + aString.Length()); if (NS_FAILED(rv)) return rv; listener->OnStartRequest(channel, nsnull); diff --git a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp index 7a75e2ad953..c75050c1073 100644 --- a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp @@ -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) { diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index e564918e021..dfe2a08af83 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -80,17 +80,12 @@ PRLogModuleInfo* gDocLoaderLog = nsnull; #if defined(DEBUG) -void GetURIStringFromRequest(nsIRequest* request, nsXPIDLCString &aStr) +void GetURIStringFromRequest(nsIRequest* request, nsACString &name) { - aStr.Adopt(nsCRT::strdup("???")); - - if (request) { - nsXPIDLString name; - request->GetName(getter_Copies(name)); - - if (name) - *getter_Copies(aStr) = ToNewUTF8String(nsDependentString(name)); - } + if (request) + request->GetName(name); + else + name = NS_LITERAL_CSTRING("???"); } #endif /* DEBUG */ @@ -431,8 +426,8 @@ nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt) #ifdef PR_LOGGING if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) { - nsXPIDLString name; - request->GetName(getter_Copies(name)); + nsCAutoString name; + request->GetName(name); PRUint32 count = 0; if (mLoadGroup) @@ -440,7 +435,7 @@ nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt) PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: OnStartRequest[%p](%s) mIsLoadingDocument=%s, %u active URLs", - this, request, NS_ConvertUCS2toUTF8(name).get(), + this, request, name.get(), (mIsLoadingDocument ? "true" : "false"), count)); } @@ -516,8 +511,8 @@ nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest, #ifdef PR_LOGGING if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) { - nsXPIDLString name; - aRequest->GetName(getter_Copies(name)); + nsCAutoString name; + aRequest->GetName(name); PRUint32 count = 0; if (mLoadGroup) @@ -525,7 +520,7 @@ nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest, PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: OnStopRequest[%p](%s) status=%x mIsLoadingDocument=%s, %u active URLs", - this, aRequest, NS_ConvertUCS2toUTF8(name).get(), + this, aRequest, name.get(), aStatus, (mIsLoadingDocument ? "true" : "false"), count)); } @@ -655,13 +650,13 @@ void nsDocLoaderImpl::doStartDocumentLoad(void) { #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(mDocumentRequest, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: ++ Firing OnStateChange for start document load (...)." "\tURI: %s \n", - this, (const char *) buffer)); + this, buffer.get())); #endif /* DEBUG */ // Fire an OnStatus(...) notification STATE_START. This indicates @@ -679,13 +674,13 @@ void nsDocLoaderImpl::doStartDocumentLoad(void) void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request) { #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(request, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: ++ Firing OnStateChange start url load (...)." "\tURI: %s\n", - this, (const char *) buffer)); + this, buffer.get())); #endif /* DEBUG */ FireOnStateChange(this, @@ -698,13 +693,13 @@ void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request) void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus) { #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(request, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: ++ Firing OnStateChange for end url load (...)." "\tURI: %s status=%x\n", - this, (const char *) buffer, aStatus)); + this, buffer.get(), aStatus)); #endif /* DEBUG */ FireOnStateChange(this, @@ -718,13 +713,13 @@ void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request, nsresult aStatus) { #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(request, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: ++ Firing OnStateChange for end document load (...)." "\tURI: %s Status=%x\n", - this, (const char *) buffer, aStatus)); + this, buffer.get(), aStatus)); #endif /* DEBUG */ // @@ -939,12 +934,12 @@ NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctx // else { #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(aRequest, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p OOPS - No Request Info for: %s\n", - this, (const char *)buffer)); + this, buffer.get())); #endif /* DEBUG */ return NS_OK; @@ -1007,12 +1002,12 @@ void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator, } #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(request, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: Progress (%s): curSelf: %d maxSelf: %d curTotal: %d maxTotal %d\n", - this, (const char *)buffer, aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress)); + this, buffer.get(), aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress)); #endif /* DEBUG */ /* @@ -1075,12 +1070,12 @@ void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress, } #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; GetURIStringFromRequest(aRequest, buffer); PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: Status (%s): code: %x\n", - this, (const char *)buffer, aStateFlags)); + this, buffer.get(), aStateFlags)); #endif /* DEBUG */ NS_ASSERTION(aRequest, "Firing OnStateChange(...) notification with a NULL request!"); @@ -1355,15 +1350,15 @@ void nsDocLoaderImpl::DumpChannelInfo() info = (nsChannelInfo *)mChannelInfoList.ElementAt(i); #if defined(DEBUG) - nsXPIDLCString buffer; + nsCAutoString buffer; nsresult rv = NS_OK; if (info->mURI) { - rv = info->mURI->GetSpec(getter_Copies(buffer)); + rv = info->mURI->GetSpec(buffer); } printf(" [%d] current=%d max=%d [%s]\n", i, info->mCurrentProgress, - info->mMaxProgress, (const char *)buffer); + info->mMaxProgress, buffer.get()); #endif /* DEBUG */ current += info->mCurrentProgress; diff --git a/mozilla/uriloader/base/nsURILoader.cpp b/mozilla/uriloader/base/nsURILoader.cpp index bb3f98d2df9..2fb16e41f95 100644 --- a/mozilla/uriloader/base/nsURILoader.cpp +++ b/mozilla/uriloader/base/nsURILoader.cpp @@ -54,6 +54,7 @@ #include "nsIStreamConverterService.h" #include "nsWeakReference.h" #include "nsIHttpChannel.h" +#include "netCore.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" @@ -263,7 +264,7 @@ NS_IMETHODIMP nsDocumentOpenInfo::OnStopRequest(nsIRequest *request, nsISupports nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * aCtxt) { nsresult rv; - nsXPIDLCString contentType; + nsCAutoString contentType; nsCOMPtr originalWindowContext = m_originalContext; // local variable to keep track of this. nsCOMPtr contentStreamListener; nsCOMPtr aChannel = do_QueryInterface(request); @@ -271,7 +272,7 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * return NS_ERROR_FAILURE; } - rv = aChannel->GetContentType(getter_Copies(contentType)); + rv = aChannel->GetContentType(contentType); if (NS_FAILED(rv)) return rv; // go to the uri dispatcher and give them our stuff... @@ -287,7 +288,8 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * // content type. // PRBool abortDispatch = PR_FALSE; - rv = uriLoader->DispatchContent(contentType, mIsContentPreferred, + rv = uriLoader->DispatchContent(contentType.get(), + mIsContentPreferred, request, aCtxt, m_contentListener, m_originalContext, @@ -306,7 +308,7 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * // if (!contentListener) { - rv = RetargetOutput(request, contentType, "*/*", nsnull); + rv = RetargetOutput(request, contentType.get(), "*/*", nsnull); if (m_targetStreamListener) return NS_OK; } @@ -372,9 +374,9 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * nsCOMPtr helperAppService (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID)); if (helperAppService) { - rv = helperAppService->DoContent(contentType, uri, m_originalContext, &abortProcess, getter_AddRefs(contentStreamListener)); + rv = helperAppService->DoContent(contentType.get(), uri, m_originalContext, &abortProcess, getter_AddRefs(contentStreamListener)); if (NS_SUCCEEDED(rv) && contentStreamListener) - return RetargetOutput(request, contentType, contentType, contentStreamListener); + return RetargetOutput(request, contentType.get(), contentType.get(), contentStreamListener); } rv = NS_ERROR_FAILURE; // this will cause us to bring up the unknown content handler dialog. } @@ -382,7 +384,7 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * // okay, all registered listeners have had a chance to handle this content... // did one of them give us a stream listener back? if so, let's start reading data // into it... - rv = RetargetOutput(request, contentType, desiredContentType, contentStreamListener); + rv = RetargetOutput(request, contentType.get(), desiredContentType, contentStreamListener); // Reinitialize the content listener in case this is a multipart stream. m_contentListener = do_GetInterface(m_originalContext); } diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp index 09da41270a8..d2d5c4a3c05 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -670,7 +670,6 @@ nsresult nsExternalHelperAppService::ExpungeTemporaryFiles() { if (!mTemporaryFilesList) return NS_OK; - nsresult rv = NS_OK; PRUint32 numEntries = 0; mTemporaryFilesList->Count(&numEntries); nsCOMPtr element; @@ -837,20 +836,20 @@ void nsExternalAppHandler::ExtractSuggestedFileNameFromChannel(nsIChannel* aChan * user. we shouldn't actually use that without their * permission...o.t. just use our temp file */ - nsXPIDLCString disp; + nsCAutoString disp; nsresult rv = NS_OK; // First see whether this is an http channel nsCOMPtr httpChannel( do_QueryInterface( aChannel ) ); if ( httpChannel ) { - rv = httpChannel->GetResponseHeader( "content-disposition", getter_Copies( disp ) ); + rv = httpChannel->GetResponseHeader( NS_LITERAL_CSTRING("content-disposition"), disp ); } if ( NS_FAILED(rv) || disp.IsEmpty() ) { nsCOMPtr multipartChannel( do_QueryInterface( aChannel ) ); if ( multipartChannel ) { - rv = multipartChannel->GetContentDisposition( getter_Copies( disp ) ); + rv = multipartChannel->GetContentDisposition( disp ); } } // content-disposition: has format: diff --git a/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp b/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp index 385c57bbc1a..9a552e8eaf3 100644 --- a/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -172,16 +172,26 @@ NS_IMETHODIMP nsExtProtocolChannel::SetLoadFlags(nsLoadFlags aLoadFlags) return NS_OK; } -NS_IMETHODIMP nsExtProtocolChannel::GetContentType(char * *aContentType) +NS_IMETHODIMP nsExtProtocolChannel::GetContentType(nsACString &aContentType) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsExtProtocolChannel::SetContentType(const char *aContentType) +NS_IMETHODIMP nsExtProtocolChannel::SetContentType(const nsACString &aContentType) { return NS_ERROR_FAILURE; } +NS_IMETHODIMP nsExtProtocolChannel::GetContentCharset(nsACString &aContentCharset) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsExtProtocolChannel::SetContentCharset(const nsACString &aContentCharset) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsExtProtocolChannel::GetContentLength(PRInt32 * aContentLength) { *aContentLength = -1; @@ -211,7 +221,7 @@ NS_IMETHODIMP nsExtProtocolChannel::SetOwner(nsISupports * aPrincipal) // From nsIRequest //////////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsExtProtocolChannel::GetName(PRUnichar* *result) +NS_IMETHODIMP nsExtProtocolChannel::GetName(nsACString &result) { NS_NOTREACHED("nsExtProtocolChannel::GetName"); return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/webshell/public/nsIRefreshURI.idl b/mozilla/webshell/public/nsIRefreshURI.idl index 42a85f2cfae..d6f2f1cab4d 100644 --- a/mozilla/webshell/public/nsIRefreshURI.idl +++ b/mozilla/webshell/public/nsIRefreshURI.idl @@ -58,7 +58,7 @@ interface nsIRefreshURI : nsISupports { * @param aBaseURI base URI to resolve refresh uri with. * @param aHeader The meta refresh header string. */ - void setupRefreshURIFromHeader(in nsIURI aBaseURI, in AString aHeader); + void setupRefreshURIFromHeader(in nsIURI aBaseURI, in ACString aHeader); /** * Cancels all timer loads. diff --git a/mozilla/widget/src/mac/nsSound.cpp b/mozilla/widget/src/mac/nsSound.cpp index 8e69950934b..352eee16459 100644 --- a/mozilla/widget/src/mac/nsSound.cpp +++ b/mozilla/widget/src/mac/nsSound.cpp @@ -691,13 +691,13 @@ nsMovieSoundRequest::OnStreamComplete(nsIStreamLoader *aLoader, if (NS_FAILED(aStatus)) return NS_ERROR_FAILURE; - nsXPIDLCString contentType; + nsCAutoString contentType; nsCOMPtr request; aLoader->GetRequest(getter_AddRefs(request)); nsCOMPtr channel = do_QueryInterface(request); if (channel) - channel->GetContentType(getter_Copies(contentType)); + channel->GetContentType(contentType); // we could use a Pointer data handler type, and avoid this // allocation/copy, in QuickTime 5 and above. diff --git a/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp b/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp index dfae726d041..784e920a207 100644 --- a/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp +++ b/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp @@ -315,8 +315,7 @@ nsHTMLFormatConverter::ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, n parser->SetContentSink(sink); - nsAutoString contentType; contentType = NS_LITERAL_STRING("text/html"); - parser->Parse(aFromStr, 0, contentType, PR_FALSE, PR_TRUE); + parser->Parse(aFromStr, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE); return NS_OK; } // ConvertFromHTMLToUnicode diff --git a/mozilla/xpcom/threads/makefile.win b/mozilla/xpcom/threads/makefile.win index aa49c3ddd48..24c150307ca 100644 --- a/mozilla/xpcom/threads/makefile.win +++ b/mozilla/xpcom/threads/makefile.win @@ -55,7 +55,7 @@ XPIDLSRCS = \ LIBRARY_NAME=xpcomthreads_s -LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN +LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN -DDEBUG_danm C_OBJS = \ .\$(OBJDIR)\plevent.obj \ diff --git a/mozilla/xpcom/threads/nsEventQueueService.cpp b/mozilla/xpcom/threads/nsEventQueueService.cpp index 698f88bff4a..5226cb6e468 100644 --- a/mozilla/xpcom/threads/nsEventQueueService.cpp +++ b/mozilla/xpcom/threads/nsEventQueueService.cpp @@ -244,7 +244,7 @@ nsresult nsEventQueueServiceImpl::GetYoungestEventQueue(nsIEventQueue *queue, ns if (queue) { nsCOMPtr ourChain(do_QueryInterface(queue)); if (ourChain) - ourChain->GetYoungest(getter_AddRefs(answer)); + ourChain->GetYoungestActive(getter_AddRefs(answer)); else answer = queue; } diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index af45be55c05..b229699150a 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -1462,8 +1462,8 @@ static nsresult DumpVersion(char *appname) nsCOMPtr httpHandler(do_GetService("@mozilla.org/network/protocol;1?name=http", &rv)); NS_ENSURE_SUCCESS(rv,rv); - nsXPIDLCString agent; - httpHandler->GetUserAgent(getter_Copies(agent)); + nsCAutoString agent; + httpHandler->GetUserAgent(agent); printf("%s", agent.get()); diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index 7865f0f5954..257a40344ce 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -705,8 +705,8 @@ PRBool nsBrowserContentHandler::NeedHomepageOverride(nsIPref *aPrefService) do_GetService("@mozilla.org/network/protocol;1?name=http", &rv)); if (NS_FAILED(rv)) return PR_TRUE; - nsXPIDLCString currMilestone; - httpHandler->GetMisc(getter_Copies(currMilestone)); + nsCAutoString currMilestone; + httpHandler->GetMisc(currMilestone); // get saved milestone from user's prefs nsXPIDLCString savedMilestone; diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index a042c01dd22..8b9336a37ee 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -2112,7 +2112,7 @@ nsBookmarksService::FireTimer(nsITimer* aTimer, void* aClosure) if (httpChannel) { bmks->htmlSize = 0; - httpChannel->SetRequestMethod("HEAD"); + httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD")); if (NS_SUCCEEDED(rv = channel->AsyncOpen(bmks, nsnull))) { bmks->busySchedule = PR_TRUE; @@ -2187,14 +2187,14 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt, { nsAutoString eTagValue, lastModValue, contentLengthValue; - nsXPIDLCString val; - if (NS_SUCCEEDED(httpChannel->GetResponseHeader("ETag", getter_Copies(val)))) + nsCAutoString val; + if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("ETag"), val))) CopyASCIItoUCS2(val, eTagValue); - if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Last-Modified", getter_Copies(val)))) + if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), val))) CopyASCIItoUCS2(val, lastModValue); - if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Content-Length", getter_Copies(val)))) + if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), val))) CopyASCIItoUCS2(val, contentLengthValue); - val.Adopt(0); + val.Truncate(); PRBool changedFlag = PR_FALSE; diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp index b005e15fb58..488f465aa5c 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp @@ -1437,7 +1437,7 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand, NS_ADDREF(*aDocListenerResult); // ... and set the original channel's content type up - (void)aChannel->SetContentType("application/vnd.mozilla.xul+xml"); + (void)aChannel->SetContentType(NS_LITERAL_CSTRING("application/vnd.mozilla.xul+xml")); return NS_OK; } @@ -1487,7 +1487,7 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand, NS_ADDREF(*aDocListenerResult); // ... and set the original channel's content type up - (void)aChannel->SetContentType("text/html"); + (void)aChannel->SetContentType(NS_LITERAL_CSTRING("text/html")); return NS_OK; } diff --git a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp index 613771447e7..04c6fe70ee3 100755 --- a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp @@ -690,7 +690,7 @@ InternetSearchDataSource::FireTimer(nsITimer* aTimer, void* aClosure) if (!httpChannel) return; // rjc says: just check "HEAD" info for whether a search file has changed - httpChannel->SetRequestMethod("HEAD"); + httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD")); if (NS_SUCCEEDED(rv = channel->AsyncOpen(search, engineContext))) { search->busySchedule = PR_TRUE; @@ -3714,7 +3714,8 @@ InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engin nsCOMPtr httpMultiChannel (do_QueryInterface(channel)); if (httpMultiChannel) { - httpMultiChannel->SetRequestHeader("MultiSearch", "true"); + httpMultiChannel->SetRequestHeader(NS_LITERAL_CSTRING("MultiSearch"), + NS_LITERAL_CSTRING("true")); } // get it just from the cache if we can (do not validate) @@ -3725,7 +3726,7 @@ InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engin nsCOMPtr httpChannel (do_QueryInterface(channel)); if (httpChannel) { - httpChannel->SetRequestMethod("POST"); + httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST")); // construct post data to send nsAutoString postStr; @@ -4657,12 +4658,10 @@ InternetSearchDataSource::OnStopRequest(nsIRequest *request, nsISupports *ctxt, // get last-modified & content-length info nsCAutoString lastModValue, contentLengthValue; - nsXPIDLCString val; - if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Last-Modified", getter_Copies(val)))) - lastModValue = val; - if (NS_SUCCEEDED(httpChannel->GetResponseHeader("Content-Length", getter_Copies(val)))) - contentLengthValue = val; - val.Adopt(0); + if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), lastModValue))) + lastModValue.Truncate(); + if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthValue))) + contentLengthValue.Truncate(); // should we fetch the entire file? PRBool updateSearchEngineFile = PR_FALSE; diff --git a/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp b/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp index 886ec76c3fc..3dfcd676c63 100644 --- a/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp +++ b/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp @@ -102,8 +102,8 @@ nsStreamTransfer::SelectFileAndTransferLocation( nsIChannel *aChannel, nsIDOMWin if (NS_FAILED(rv)) return rv; // Content type comes straight from channel. - nsXPIDLCString contentType; - aChannel->GetContentType( getter_Copies( contentType ) ); + nsCAutoString contentType; + aChannel->GetContentType( contentType ); // Suggested name derived from content-disposition response header. nsCAutoString suggestedName; @@ -112,11 +112,10 @@ nsStreamTransfer::SelectFileAndTransferLocation( nsIChannel *aChannel, nsIDOMWin nsCOMPtr httpChannel = do_QueryInterface( aChannel ); if ( httpChannel ) { // Get content-disposition response header. - nsXPIDLCString disp; - rv = httpChannel->GetResponseHeader( "content-disposition", getter_Copies( disp ) ); - if ( NS_SUCCEEDED( rv ) && disp ) { + nsCAutoString contentDisp; + rv = httpChannel->GetResponseHeader( NS_LITERAL_CSTRING("content-disposition"), contentDisp ); + if ( NS_SUCCEEDED( rv ) && !contentDisp.IsEmpty() ) { // Parse out file name. - nsCAutoString contentDisp(NS_STATIC_CAST(const char*, disp)); // Remove whitespace. contentDisp.StripWhitespace(); // Look for ";filename=". @@ -124,7 +123,7 @@ nsStreamTransfer::SelectFileAndTransferLocation( nsIChannel *aChannel, nsIDOMWin PRInt32 i = contentDisp.Find( key ); if ( i != kNotFound ) { // Name comes after that. - suggestedName = contentDisp.get() + i + PL_strlen( key ) + 1; + suggestedName = contentDisp.get() + i + strlen( key ) + 1; } } } @@ -217,7 +216,7 @@ nsStreamTransfer::SelectFileAndTransferLocationSpec( char const *aURL, NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel"); uploadChannel->SetUploadStream( postData, nsnull, -1); - httpChannel->SetRequestMethod("POST"); + httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST")); } } }