nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService("@mozilla.org/chrome/chrome-registry;1");
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer)); PRInt32 shellType; docShell->GetItemType(&shellType); nsICSSStyleSheet* sheet = nsnull; if (shellType == nsIDocShellTreeItem::typeChrome) { sheet = nsLayoutStylesheetCache::UserChromeSheet(); } else { sheet = nsLayoutStylesheetCache::UserContentSheet(); }
DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,                                   nsStyleSet** aStyleSet){  // this should eventually get expanded to allow for creating  // different sets for different media  if (!mUAStyleSheet) {    NS_WARNING("unable to load UA style sheet");  }  nsStyleSet *styleSet = new nsStyleSet();  if (!styleSet) {    return NS_ERROR_OUT_OF_MEMORY;  }  PRInt32 index = aDocument->GetNumberOfStyleSheets(PR_TRUE);  styleSet->BeginUpdate();  while (0 < index--) {    nsIStyleSheet *sheet = aDocument->GetStyleSheetAt(index, PR_TRUE);    /*     * GetStyleSheetAt will return all style sheets in the document but     * we're only interested in the ones that are enabled.     */    PRBool styleApplicable;    sheet->GetApplicable(styleApplicable);    if (styleApplicable) {      styleSet->AddDocStyleSheet(sheet, aDocument);    }  }  nsCOMPtr<nsIChromeRegistry> chromeRegistry =    do_GetService("@mozilla.org/chrome/chrome-registry;1");  if (chromeRegistry) {    nsCOMPtr<nsISupportsArray> sheets;    // Now handle the user sheets.    nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));    PRInt32 shellType;    docShell->GetItemType(&shellType);    PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome);    chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets));    if (sheets) {      nsCOMPtr<nsICSSStyleSheet> sheet;      PRUint32 count;      sheets->Count(&count);      // Insert the user sheets at the front of the user sheet list      // so that they are most significant user sheets.      for (PRUint32 i=0; i<count; i++) {        sheets->GetElementAt(i, getter_AddRefs(sheet));        styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet);      }    }    // Append chrome sheets (scrollbars + forms).    nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));    chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets));    if (sheets) {      nsCOMPtr<nsICSSStyleSheet> sheet;      PRUint32 count;      sheets->Count(&count);      for (PRUint32 i=0; i<count; i++) {        sheets->GetElementAt(i, getter_AddRefs(sheet));        styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);      }    }  }  if (mUAStyleSheet) {    styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet);  }  styleSet->EndUpdate();  *aStyleSet = styleSet;  return NS_OK;}