if (aCharsetSrc.Length() == 0) { mCharset.AssignWithConversion("ISO-8859-1"); } else { NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &rv); NS_ASSERTION(calias, "cannot find charset alias"); nsAutoString charsetName(aCharsetSrc); if( NS_SUCCEEDED(rv) && (nsnull != calias)) { PRBool same = PR_FALSE; rv = calias->Equals(aCharsetSrc, mCharset, &same); if(NS_SUCCEEDED(rv) && same) { return NS_OK;
nsString str; PRBool setCharset = PR_FALSE;  if (aHTTPHeader.Length() > 0) {  PRInt32 charsetOffset; static const char charsetStr[] = "charset="; if ((charsetOffset = aHTTPHeader.Find(charsetStr,PR_TRUE)) > 0) { aHTTPHeader.Mid(str, charsetOffset + sizeof(charsetStr)-1, -1); setCharset = PR_TRUE; } } else if (aStyleSheetData.Length() > 0) { static const char atCharsetStr[] = "@charset"; if (aStyleSheetData.Find(atCharsetStr) > -1) { nsString strValue;  aStyleSheetData.Mid(str,sizeof(atCharsetStr)-1,-1);  str.StripWhitespace();  PRInt32 pos = str.Find(";"); if (pos > -1) { str.Left(strValue,pos);
NS_IMETHODIMP CSSLoaderImpl::SetCharset(/*in*/ const nsString &aCharsetSrc)  // public methods for clients to set the charset if they know it  //  NOTE: the SetCharset method will always get the preferred charset from the charset passed in  //        unless it is the emptystring, which causes the default charset to be set{  nsresult rv = NS_OK;  if (aCharsetSrc.Length() == 0) {    mCharset.AssignWithConversion("ISO-8859-1");  } else {    NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &rv);    NS_ASSERTION(calias, "cannot find charset alias");    nsAutoString charsetName(aCharsetSrc);    if( NS_SUCCEEDED(rv) && (nsnull != calias))    {      PRBool same = PR_FALSE;      rv = calias->Equals(aCharsetSrc, mCharset, &same);      if(NS_SUCCEEDED(rv) && same)      {        return NS_OK; // no difference, don't change it      }      // different, need to change it      rv = calias->GetPreferred(aCharsetSrc, charsetName);      if(NS_FAILED(rv))      {         // failed - unknown alias , fallback to ISO-8859-1        charsetName.AssignWithConversion("ISO-8859-1");      }      mCharset = charsetName;    }  }  return rv;}