(*aSheet)->SetDefaultNameSpaceID(aDefaultNameSpaceID);
CSSLoaderImpl::CreateSheet(nsIURI* aURI,                           nsIContent* aLinkingContent,                           PRBool aSyncLoad,                           StyleSheetState& aSheetState,                           nsICSSStyleSheet** aSheet){  LOG(("CSSLoaderImpl::CreateSheet"));  NS_PRECONDITION(aSheet, "Null out param!");  NS_ENSURE_TRUE((mCompleteSheets.IsInitialized() || mCompleteSheets.Init()) &&                   (mLoadingDatas.IsInitialized() || mLoadingDatas.Init()) &&                   (mPendingDatas.IsInitialized() || mPendingDatas.Init()),                 NS_ERROR_OUT_OF_MEMORY);    nsresult rv = NS_OK;  *aSheet = nsnull;  aSheetState = eSheetStateUnknown;    if (aURI) {    aSheetState = eSheetComplete;    nsCOMPtr<nsICSSStyleSheet> sheet;    // First, the XUL cache#ifdef MOZ_XUL    if (IsChromeURI(aURI)) {      nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1"));      if (cache) {        PRBool enabled;        cache->GetEnabled(&enabled);        if (enabled) {          cache->GetStyleSheet(aURI, getter_AddRefs(sheet));          LOG(("  From XUL cache: %p", sheet.get()));        }      }    }#endif    if (!sheet) {      // Then complete sheets      mCompleteSheets.Get(aURI, getter_AddRefs(sheet));      LOG(("  From completed: %p", sheet.get()));          // Then loading sheets      if (!sheet && !aSyncLoad) {        aSheetState = eSheetLoading;        SheetLoadData* loadData = nsnull;        mLoadingDatas.Get(aURI, &loadData);        if (loadData) {          sheet = loadData->mSheet;          LOG(("  From loading: %p", sheet.get()));        }        // Then alternate sheets        if (!sheet) {          aSheetState = eSheetPending;          SheetLoadData* loadData = nsnull;          mPendingDatas.Get(aURI, &loadData);          if (loadData) {            sheet = loadData->mSheet;            LOG(("  From pending: %p", sheet.get()));          }        }      }    }    if (sheet) {      // We can use this cached sheet if it's either incomplete or unmodified      PRBool modified = PR_TRUE;      sheet->IsModified(&modified);      PRBool complete = PR_FALSE;      sheet->GetComplete(complete);      if (!modified || !complete) {        // Proceed on failures; at worst we'll try to create one below        sheet->Clone(nsnull, nsnull, nsnull, nsnull, aSheet);        NS_ASSERTION(complete || aSheetState != eSheetComplete,                     "Sheet thinks it's not complete while we think it is");      }    }  }  if (!*aSheet) {    aSheetState = eSheetNeedsParser;    nsCOMPtr<nsIURI> sheetURI = aURI;    if (!sheetURI) {      // Inline style.  Use the document's base URL so that @import in      // the inline sheet picks up the right base.      NS_ASSERTION(aLinkingContent, "Inline stylesheet without linking content?");      aLinkingContent->GetBaseURL(getter_AddRefs(sheetURI));    }    rv = NS_NewCSSStyleSheet(aSheet, sheetURI);    NS_ENSURE_SUCCESS(rv, rv);  }  NS_ASSERTION(*aSheet, "We should have a sheet by now!");  NS_ASSERTION(aSheetState != eSheetStateUnknown, "Have to set a state!");  LOG(("  State: %s", gStateStrings[aSheetState]));    return NS_OK;}