Nisheeth checking in on behalf of Heikki from Harish's machine! Fix for PDT+ bug 88327. XMLHttpRequest correctly processes international char set XML text returned from the server.

git-svn-id: svn://10.0.0.236/branches/MOZILLA_0_9_2_BRANCH@99078 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
harishd%netscape.com
2001-07-11 20:36:04 +00:00
parent 14ea7b6bca
commit dc62af156c
2 changed files with 25 additions and 10 deletions

View File

@@ -54,6 +54,7 @@
#include "nsIInterfaceRequestor.h"
#endif
#include "nsIDOMClassInfo.h"
#include "nsIDOMElement.h"
static const char* kLoadAsData = "loadAsData";
#define LOADSTR NS_LITERAL_STRING("load")
@@ -405,7 +406,7 @@ nsXMLHttpRequest::DetectCharset(nsAWritableString& aCharset)
nsAutoString contentType;
contentType.AssignWithConversion( contenttypeheader.get() );
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
if(start<0) {
if(start>=0) {
start += 8; // 8 = "charset=".length
PRInt32 end = 0;
if(PRUnichar('"') == contentType.CharAt(start)) {
@@ -1147,6 +1148,19 @@ nsresult
nsXMLHttpRequest::Load(nsIDOMEvent* aEvent)
{
mStatus = XML_HTTP_REQUEST_COMPLETED;
// We might have been sent non-XML data. If that was the case,
// we should null out the document member. The idea in this
// check here is that if there is no document element it is not
// an XML document. We might need a fancier check...
if (mDocument) {
nsCOMPtr<nsIDOMElement> root;
mDocument->GetDocumentElement(getter_AddRefs(root));
if (!root) {
mDocument = nsnull;
}
}
#ifdef IMPLEMENT_SYNC_LOAD
if (mChromeWindow) {
mChromeWindow->ExitModalEventLoop(NS_OK);
@@ -1207,6 +1221,7 @@ nsresult
nsXMLHttpRequest::Abort(nsIDOMEvent* aEvent)
{
mStatus = XML_HTTP_REQUEST_ABORTED;
mDocument = nsnull;
#ifdef IMPLEMENT_SYNC_LOAD
if (mChromeWindow) {
mChromeWindow->ExitModalEventLoop(NS_OK);
@@ -1221,6 +1236,7 @@ nsresult
nsXMLHttpRequest::Error(nsIDOMEvent* aEvent)
{
mStatus = XML_HTTP_REQUEST_ABORTED;
mDocument = nsnull;
#ifdef IMPLEMENT_SYNC_LOAD
if (mChromeWindow) {
mChromeWindow->ExitModalEventLoop(NS_OK);

View File

@@ -94,6 +94,14 @@ protected:
nsresult GetStreamForWString(const PRUnichar* aStr,
PRInt32 aLength,
nsIInputStream** aStream);
nsresult DetectCharset(nsAWritableString& aCharset);
nsresult ConvertBodyToText(PRUnichar **aOutBuffer);
static NS_METHOD StreamReaderFunc(nsIInputStream* in,
void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount);
nsCOMPtr<nsISupports> mContext;
nsCOMPtr<nsIHttpChannel> mChannel;
@@ -111,15 +119,6 @@ protected:
nsCOMPtr<nsIDOMEventListener> mOnLoadListener;
nsCOMPtr<nsIDOMEventListener> mOnErrorListener;
nsresult DetectCharset(nsAWritableString& aCharset);
nsresult ConvertBodyToText(PRUnichar **aOutBuffer);
static NS_METHOD StreamReaderFunc(nsIInputStream* in,
void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount);
// used to implement getAllResponseHeaders()
class nsHeaderVisitor : public nsIHttpHeaderVisitor {
public: