if(0 != nsCRT::strcasecmp(aTag, "META")) return NS_ERROR_ILLEGAL_VALUE; else return Notify(aDocumentID, numOfAttributes, nameArray, valueArray);
nsresult res = NS_OK; PRUint32 i; char command[256]; command[0]='\0';          if((numOfAttributes >= 4) && (0 == nsCRT::strcasecmp(nameArray[0], "HTTP-EQUIV")) && (0 == nsCRT::strncasecmp(((('\'' == valueArray[0][0]) || ('\"' == valueArray[0][0])) ? (valueArray[0]+1) : valueArray[0]), "Content-Type", 12))) { PRBool bGotCharset = PR_FALSE; PRBool bGotCharsetSource = PR_FALSE; nsAutoString currentCharset("unknown"); nsAutoString charsetSourceStr("unknown");  for(i=0; i < numOfAttributes; i++) { if(0==nsCRT::strcmp(nameArray[i], "charset")) { bGotCharset = PR_TRUE; currentCharset = valueArray[i]; } else if(0==nsCRT::strcmp(nameArray[i], "charsetSource")) { bGotCharsetSource = PR_TRUE; charsetSourceStr = valueArray[i]; } else if(0==nsCRT::strcmp(nameArray[i], "X_COMMAND")) { nsAutoString tmp(valueArray[i]); tmp.ToCString(command, 256); } }    if(! ( bGotCharsetSource && bGotCharset )) { return NS_ERROR_ILLEGAL_VALUE; }  PRInt32 err; PRInt32 charsetSourceInt = charsetSourceStr.ToInteger(&err);   if(NS_FAILED(err)) return NS_ERROR_ILLEGAL_VALUE;  nsCharsetSource currentCharsetSource = (nsCharsetSource)charsetSourceInt;  if(kCharsetFromMetaTag > currentCharsetSource) { for(i=0; i < numOfAttributes; i++) { if (0==nsCRT::strcasecmp(nameArray[i],"CONTENT")) { const PRUnichar *attr = valueArray[i] ; if(('\"' == attr[0]) || ('\'' == attr[0])) attr++;  nsAutoString content(attr); nsAutoString type;  content.Left(type, 9); if(type.EqualsIgnoreCase("text/html")) { PRInt32 charsetValueStart = content.RFind("charset=", PR_TRUE ) ; if(kNotFound != charsetValueStart) { charsetValueStart += 8; PRInt32 charsetValueEnd = content.FindCharInSet("\'\";", charsetValueStart  ); if(kNotFound == charsetValueEnd ) charsetValueEnd = content.Length(); nsAutoString theCharset; content.Mid(theCharset, charsetValueStart, charsetValueEnd - charsetValueStart); if(! theCharset.Equals(currentCharset)) { nsICharsetAlias* calias = nsnull; res = nsServiceManager::GetService( kCharsetAliasCID, nsICharsetAlias::GetIID(), (nsISupports**) &calias); if(NS_SUCCEEDED(res) && (nsnull != calias) ) { PRBool same = PR_FALSE; res = calias->Equals( theCharset, currentCharset, &same); if(NS_SUCCEEDED(res) && (! same)) { nsAutoString preferred; res = calias->GetPreferred(theCharset, preferred); if(NS_SUCCEEDED(res)) { const char* charsetInCStr = preferred.ToNewCString(); if(nsnull != charsetInCStr) { res = NotifyWebShell(aDocumentID, charsetInCStr, kCharsetFromMetaTag , command[0]?command:nsnull); delete [] (char*)charsetInCStr; return res; } } } nsServiceManager::ReleaseService(kCharsetAliasCID, calias); } } } } break; } } } } return NS_OK;
NS_IMETHODIMP nsMetaCharsetObserver::Notify(                     PRUint32 aDocumentID,                      const PRUnichar* aTag,                      PRUint32 numOfAttributes,                      const PRUnichar* nameArray[],                      const PRUnichar* valueArray[]){    if(0 != nsCRT::strcasecmp(aTag, "META"))         return NS_ERROR_ILLEGAL_VALUE;    else        return Notify(aDocumentID, numOfAttributes, nameArray, valueArray);}