PRINTF("CSSLoaderImpl::LoadSheet: Load of URL '%s' failed.  Error code: %x\n", url, result);
CSSLoaderImpl::LoadSheet(URLKey& aKey, SheetLoadData* aData){  nsresult result = NS_OK;  SheetLoadData* loadingData = (SheetLoadData*)mLoadingSheets.Get(&aKey);  if (loadingData) {  // already loading this sheet, glom on to the load    while (loadingData->mNext) {      loadingData = loadingData->mNext;    }    loadingData->mNext = aData;  }  else {  // not loading, go load it    if (aData->mSyncLoad) { // handle agent sheets synchronously      nsIURI* urlClone;      result = aKey.mURL->Clone(&urlClone); // dont give key URL to netlib, it gets munged      if (NS_SUCCEEDED(result)) {        nsIInputStream* in;        result = NS_OpenURI(&in, urlClone);        NS_RELEASE(urlClone);        if (NS_SUCCEEDED(result)) {          // Translate the input using the argument character set id into unicode          nsIUnicharInputStream* uin;          result = NS_NewConverterStream(&uin, nsnull, in);          if (NS_SUCCEEDED(result)) {            mLoadingSheets.Put(&aKey, aData);            PRBool completed;            nsICSSStyleSheet* sheet;            result = ParseSheet(uin, aData, completed, sheet);            NS_ASSERTION(completed, "sync sheet load failed to complete");            NS_IF_RELEASE(sheet);            NS_RELEASE(uin);          }          else {            fputs("CSSLoader::LoadSheet - failed to get converter stream\n", stderr);          }          NS_RELEASE(in);        }        else {          // Dump an error message to the console          char *url;          aKey.mURL->GetSpec(&url);#ifdef DEBUG          cerr << "CSSLoaderImpl::LoadSheet: Load of URL '" << url                << "' failed.  Error code: " << NS_ERROR_GET_CODE(result)  << "\n";#endif          nsCRT::free(url);        }      }    }    else if (mDocument || aData->mIsAgent) {  // we're still live, start an async load      nsIStreamLoader* loader;      nsIURI* urlClone;      result = aKey.mURL->Clone(&urlClone); // dont give key URL to netlib, it gets munged      if (NS_SUCCEEDED(result)) {#ifdef NS_DEBUG        mSyncCallback = PR_TRUE;#endif        nsCOMPtr<nsILoadGroup> loadGroup;        mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));        PRBool isLocalFile;#ifdef INCLUDE_XUL        isLocalFile = (IsChromeURI(urlClone) || IsFileURI(urlClone));#else        isLocalFile = IsFileURI(urlClone);#endif        nsLoadFlags loadAttributes;        if (isLocalFile)          loadAttributes = (nsLoadFlags)nsIChannel::LOAD_NORMAL;        else          loadAttributes = (nsLoadFlags)nsIChannel::FORCE_RELOAD;        result = NS_NewStreamLoader(&loader, urlClone, aData, nsnull, loadGroup,                                      nsnull, loadAttributes);#ifdef NS_DEBUG        mSyncCallback = PR_FALSE;#endif        NS_RELEASE(urlClone);        if (NS_SUCCEEDED(result)) {          mLoadingSheets.Put(&aKey, aData);          // grab any pending alternates that have this URL          loadingData = aData;          PRInt32 index = 0;          while (index < mPendingAlternateSheets.Count()) {            SheetLoadData* data = (SheetLoadData*)mPendingAlternateSheets.ElementAt(index);            PRBool equals = PR_FALSE;            result = aKey.mURL->Equals(data->mURL, &equals);            if (NS_SUCCEEDED(result) && equals)            {              mPendingAlternateSheets.RemoveElementAt(index);              NS_IF_RELEASE(loadingData->mNext);              loadingData->mNext = data;              loadingData = data;            }            else {              index++;            }          }        }      }    }    else { // document gone,  no point in starting the load      NS_RELEASE(aData);    }  }  return result;}