Closed Bug 12500 Opened 21 years ago Closed 21 years ago

HTTP Header Charset does not work for XUL/XML/RDF yet

Categories

(Core :: Internationalization, defect, P3)

defect

Tracking

()

VERIFIED FIXED

People

(Reporter: ftang, Assigned: ftang)

Details

(Whiteboard: code is there. Have not crate test cases yet.)

I fix the HTML part . But I have not fix the XML/XUL/RDF part
Status: NEW → ASSIGNED
Target Milestone: M11
Mark it assigned M11. Should be easy to do.
Whiteboard: code is there. Have not crate test cases yet.
Here is the fix. I have not test them yet.

Index: src/nsXMLDocument.cpp
===================================================================
RCS file: /m/pub/mozilla/layout/xml/document/src/nsXMLDocument.cpp,v
retrieving revision 1.37
diff -c -r1.37 nsXMLDocument.cpp
*** nsXMLDocument.cpp	1999/07/20 08:46:06	1.37
--- nsXMLDocument.cpp	1999/08/31 01:36:08
***************
*** 47,52 ****
--- 47,56 ----
  #include "nsCOMPtr.h"
  #include "nsIURI.h"
  #endif
+ #include "nsXPIDLString.h"
+ #include "nsIHTTPChannel.h"
+ #include "nsIServiceManager.h"
+ #include "nsICharsetAlias.h"

  // XXX The XML world depends on the html atoms
  #include "nsHTMLAtoms.h"
***************
*** 226,236 ****
--- 230,280 ----
    }

    nsIWebShell* webShell;
+   nsAutoString charset("utf-8");
+   nsCharsetSource charsetSource = kCharsetFromDocTypeDefault;

  #ifdef NECKO
    nsCOMPtr<nsIURI> aUrl;
    rv = aChannel->GetURI(getter_AddRefs(aUrl));
    if (NS_FAILED(rv)) return rv;
+
+   nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(aChannel);
+   if(httpChannel) {
+      nsIAtom* contentTypeKey = NS_NewAtom("content-type");
+      nsXPIDLCString contenttypeheader;
+      rv = httpChannel->GetResponseHeader(contentTypeKey,
getter_Copies(contenttypeheader));
+      NS_RELEASE(contentTypeKey);
+      if (NS_SUCCEEDED(rv)) {
+ 	nsAutoString contentType;
+ 	contentType = contenttypeheader;
+ 	PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
+ 	if(kNotFound != start)
+ 	{
+ 		 start += 8; // 8 = "charset=".length
+ 		 PRInt32 end = contentType.FindCharInSet(";\n\r ", start  );
+ 		 if(kNotFound == end )
+ 			 end = contentType.Length();
+ 		 nsAutoString theCharset;
+ 		 contentType.Mid(theCharset, start, end - start);
+ 		 nsICharsetAlias* calias = nsnull;
+ 		 rv = nsServiceManager::GetService(
+ 							kCharsetAliasCID,
+
nsICharsetAlias::GetIID(),
+ 							(nsISupports**)
&calias);
+ 		 if(NS_SUCCEEDED(rv) && (nsnull != calias) )
+ 		 {
+ 			  nsAutoString preferred;
+ 			  rv = calias->GetPreferred(theCharset, preferred);
+ 			  if(NS_SUCCEEDED(rv))
+ 			  {
+ 				  charset = preferred;
+  				  charsetSource = kCharsetFromHTTPHeader;
+ 			  }
+ 			  nsServiceManager::ReleaseService(kCharsetAliasCID,
calias);
+ 		 }
+         }
+      }
+   }
  #endif

    static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
***************
*** 261,268 ****
          /* Commenting out the call to RegisterDTD() as per rickg's
instructions.
             XML and HTML DTD's are going to be pre-registered withing nsParser.
*/
          // mParser->RegisterDTD(theDTD);
!         nsAutoString utf8("utf-8");
!         mParser->SetDocumentCharset(utf8, kCharsetFromDocTypeDefault);
          mParser->SetCommand(aCommand);
          mParser->SetContentSink(sink);
          mParser->Parse(aUrl, nsnull, PR_FALSE, (void *)this);
--- 305,311 ----
          /* Commenting out the call to RegisterDTD() as per rickg's
instructions.
             XML and HTML DTD's are going to be pre-registered withing nsParser.
*/
          // mParser->RegisterDTD(theDTD);
!         mParser->SetDocumentCharset(charset, charsetSource);
          mParser->SetCommand(aCommand);
          mParser->SetContentSink(sink);
          mParser->Parse(aUrl, nsnull, PR_FALSE, (void *)this);

Jim: Do you have a test case for this ?
fix and check in nsTextFrame.cpp
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Status: RESOLVED → VERIFIED
Test cases are in http://babel/automation/erik/framework/
I verified this 9-30 build.
You need to log in before you can comment on or make changes to this bug.