SheetLoadData* removedData; NS_ASSERTION(mPendingDatas.Get(aLoadData->mURI, &removedData) && removedData == existingData, "Bad pending table.");
SheetLoadData* removedData =
CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState){  LOG(("CSSLoaderImpl::LoadSheet"));  NS_PRECONDITION(aLoadData, "Need a load data");  NS_PRECONDITION(aLoadData->mURI, "Need a URI to load");  NS_PRECONDITION(aLoadData->mSheet, "Need a sheet to load into");  NS_PRECONDITION(aSheetState != eSheetComplete, "Why bother?");  NS_ASSERTION(mLoadingDatas.IsInitialized(), "mLoadingDatas should be initialized by now.");  LOG_URI("  Load from: '%s'", aLoadData->mURI);    nsresult rv = NS_OK;    if (!mDocument && !aLoadData->mIsAgent) {    // No point starting the load; just release all the data and such.    LOG_WARN(("  No document and not agent sheet; pre-dropping load"));    SheetComplete(aLoadData, PR_FALSE);    return NS_OK;  }  if (aLoadData->mSyncLoad) {    LOG(("  Synchronous load"));    NS_ASSERTION(aSheetState == eSheetNeedsParser,                 "Sync loads can't reuse existing async loads");    // Just load it    nsCOMPtr<nsIInputStream> stream;    rv = NS_OpenURI(getter_AddRefs(stream), aLoadData->mURI);    if (NS_FAILED(rv)) {      LOG_ERROR(("  Failed to open URI synchronously"));      SheetComplete(aLoadData, PR_FALSE);      return rv;    }    nsCOMPtr<nsIConverterInputStream> converterStream =       do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);        if (NS_FAILED(rv)) {      LOG_ERROR(("  Failed to create converter stream"));      SheetComplete(aLoadData, PR_FALSE);      return rv;    }    // This forces UA sheets to be UTF-8.  We should really look for    // @charset rules here via ReadSegments on the raw stream...    // 8192 is a nice magic number that happens to be what a lot of    // other things use for buffer sizes.    rv = converterStream->Init(stream, "UTF-8",                               8192, PR_TRUE);        if (NS_FAILED(rv)) {      LOG_ERROR(("  Failed to initialize converter stream"));      SheetComplete(aLoadData, PR_FALSE);      return rv;    }    PRBool completed;    rv = ParseSheet(converterStream, aLoadData, completed);    NS_ASSERTION(completed, "sync load did not complete");    return rv;  }  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; // transfer ownership    if (aSheetState == eSheetPending && !IsAlternate(aLoadData->mTitle)) {      // Kick the load off; someone cares about it right away#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);    }    // All done here; once the load completes we'll be marked complete    // automatically    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) {    // send a minimal Accept header for text/css    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);      }    }  }  // Now tell the channel we expect text/css data back....  We do  // this before opening it, so it's only treated as a hint.  channel->SetContentType(NS_LITERAL_CSTRING("text/css"));  // We don't have to hold on to the stream loader.  The ownership  // model is: Necko owns the stream loader, which owns the load data,  // which owns us  nsCOMPtr<nsIUnicharStreamLoader> streamLoader;  rv = NS_NewUnicharStreamLoader(getter_AddRefs(streamLoader),                                 channel, aLoadData);#ifdef DEBUG  mSyncCallback = PR_FALSE;#endif  if (NS_FAILED(rv)) {    LOG_ERROR(("  Failed to create stream loader"));    SheetComplete(aLoadData, PR_FALSE);    return rv;  }  mLoadingDatas.Put(aLoadData->mURI, aLoadData);  aLoadData->mIsLoading = PR_TRUE;    return NS_OK;}