else { nsIUnicharStreamLoader* loader; nsIURL* urlClone = CloneURL(aKey.mURL); if (urlClone) { result = NS_NewUnicharStreamLoader(&loader, urlClone, DoneLoadingStyle, aData); NS_RELEASE(urlClone); if (NS_SUCCEEDED(result)) { mLoadingSheets.Put(&aKey, aData);  loadingData = aData; PRInt32 index = 0; while (index < mPendingAlternateSheets.Count()) { SheetLoadData* data = (SheetLoadData*)mPendingAlternateSheets.ElementAt(index); if (aKey.mURL->Equals(data->mURL)) { mPendingAlternateSheets.RemoveElementAt(index); loadingData->mNext = data; loadingData = data; } else { index++; } }
SheetLoadData* existingData = nsnull;  if (aSheetState == eSheetLoading) { mLoadingDatas.Get(aLoadData->mURI, &existingData); NS_ASSERTION(existingData, "CreateSheet lied about the state"); } else if (aSheetState == eSheetPending){ mPendingDatas.Get(aLoadData->mURI, &existingData); NS_ASSERTION(existingData, "CreateSheet lied about the state"); }  if (existingData) { LOG(("  Glomming on to existing load")); SheetLoadData* data = existingData; while (data->mNext) { data = data->mNext; } data->mNext = aLoadData; if (aSheetState == eSheetPending && !IsAlternate(aLoadData->mTitle)) {   #ifdef DEBUG SheetLoadData* removedData; NS_ASSERTION(mPendingDatas.Get(aLoadData->mURI, &removedData) && removedData == existingData, "Bad pending table."); #endif  mPendingDatas.Remove(aLoadData->mURI);  LOG(("  Forcing load of pending data")); LoadSheet(existingData, eSheetNeedsParser); }   return NS_OK; }  #ifdef DEBUG mSyncCallback = PR_TRUE; #endif nsCOMPtr<nsILoadGroup> loadGroup; if (mDocument) { mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); NS_ASSERTION(loadGroup, "No loadgroup for stylesheet; onload will fire early"); }  #ifdef MOZ_TIMELINE NS_TIMELINE_MARK_URI("Loading style sheet: %s", aLoadData->mURI); NS_TIMELINE_INDENT(); #endif  nsCOMPtr<nsIChannel> channel; rv = NS_NewChannel(getter_AddRefs(channel), aLoadData->mURI, nsnull, loadGroup, nsnull, nsIChannel::LOAD_NORMAL);  if (NS_FAILED(rv)) { LOG_ERROR(("  Failed to create channel")); SheetComplete(aLoadData, PR_FALSE); return rv; }  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); if (httpChannel) {  httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), NS_LITERAL_CSTRING("text/css,*/*;q=0.1"), PR_FALSE); if (mDocument) { nsCOMPtr<nsIURI> documentURI; mDocument->GetDocumentURL(getter_AddRefs(documentURI)); NS_ASSERTION(documentURI, "Null document uri is bad!"); if (documentURI) { httpChannel->SetReferrer(documentURI);
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    nsIUnicharStreamLoader* loader;    nsIURL* urlClone = CloneURL(aKey.mURL); // don't give the key to netlib, it munges it    if (urlClone) {      result = NS_NewUnicharStreamLoader(&loader, urlClone, DoneLoadingStyle, aData);      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);          if (aKey.mURL->Equals(data->mURL)) {            mPendingAlternateSheets.RemoveElementAt(index);            loadingData->mNext = data;            loadingData = data;          }          else {            index++;          }        }      }    }  }  return result;}