aCharset = NS_ConvertUCS2toUTF8(charset);
SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,                                  nsISupports* aContext,                                  const char* aData,                                  PRUint32 aDataLength,                                  nsACString& aCharset){  nsCOMPtr<nsIChannel> channel;  nsresult result = aLoader->GetChannel(getter_AddRefs(channel));  if (NS_FAILED(result))    channel = nsnull;  /*   * First determine the charset (if one is indicated)   * 1)  Check nsIChannel::contentCharset   * 2)  Check @charset rules in the data   * 3)  Check "charset" attribute of the <LINK> or <?xml-stylesheet?>   *   * If all these fail to give us a charset, fall back on our   * default (document charset or ISO-8859-1 if we have no document   * charset)   */  nsAutoString charset;  nsAutoString charsetCandidate;  if (channel) {    nsCAutoString charsetVal;    channel->GetContentCharset(charsetVal);    CopyASCIItoUCS2(charsetVal, charsetCandidate);  }  result = NS_ERROR_NOT_AVAILABLE;  if (! charsetCandidate.IsEmpty()) {#ifdef DEBUG_bzbarsky    fprintf(stderr, "Setting from HTTP to: %s\n", NS_ConvertUCS2toUTF8(charsetCandidate).get());#endif    result = ResolveCharset(charsetCandidate, charset);  }  if (NS_FAILED(result)) {    //  We have no charset or the HTTP charset is not recognized.    //  Try @charset rule    result = GetCharsetFromData((const unsigned char*)aData,                                aDataLength, charsetCandidate);    if (NS_SUCCEEDED(result)) {#ifdef DEBUG_bzbarsky      fprintf(stderr, "Setting from @charset rule: %s\n",              NS_ConvertUCS2toUTF8(charsetCandidate).get());#endif      result = ResolveCharset(charsetCandidate, charset);    }  }  if (NS_FAILED(result)) {    // Now try the charset on the <link> or processing instruction    // that loaded us    nsCOMPtr<nsIStyleSheetLinkingElement>      element(do_QueryInterface(mOwningElement));    if (element) {      element->GetCharset(charsetCandidate);      if (! charsetCandidate.IsEmpty()) {#ifdef DEBUG_bzbarsky        fprintf(stderr, "Setting from property on element: %s\n",                NS_ConvertUCS2toUTF8(charsetCandidate).get());#endif        result = ResolveCharset(charsetCandidate, charset);      }    }  }  if (NS_FAILED(result) && mLoader->mDocument) {    // no useful data on charset.  Try the document charset.    // That needs no resolution, since it's already fully resolved    mLoader->mDocument->GetDocumentCharacterSet(charset);#ifdef DEBUG_bzbarsky    fprintf(stderr, "Set from document: %s\n",            NS_ConvertUCS2toUTF8(charset).get());#endif  }        if (charset.IsEmpty()) {    NS_WARNING("Unable to determine charset for sheet, using ISO-8859-1!");    charset = NS_LITERAL_STRING("ISO-8859-1");  }    aCharset = NS_ConvertUCS2toUTF8(charset);  return NS_OK;}