if (nsnull != aDocShell) { nsIContentViewer* cv = nsnull; aDocShell->GetContentViewer(&cv); if (nsnull != cv) { nsIDocumentViewer* docv = nsnull; CallQueryInterface(cv, &docv); if (nsnull != docv) { nsIPresContext* cx; docv->GetPresContext(cx); if (nsnull != cx) { cx->GetShell(&shell); NS_RELEASE(cx); } NS_RELEASE(docv); } NS_RELEASE(cv); } }
doc->GetShellAt(0, &shell);
GetPresShellFor(nsIDocShell* aDocShell){  nsIPresShell* shell = nsnull;  if (nsnull != aDocShell) {    nsIContentViewer* cv = nsnull;    aDocShell->GetContentViewer(&cv);    if (nsnull != cv) {      nsIDocumentViewer* docv = nsnull;      CallQueryInterface(cv, &docv);      if (nsnull != docv) {        nsIPresContext* cx;        docv->GetPresContext(cx);        if (nsnull != cx) {          cx->GetShell(&shell);          NS_RELEASE(cx);        }        NS_RELEASE(docv);      }      NS_RELEASE(cv);    }  }  return shell;}