nsresult rv;  nsCOMPtr<nsIDocumentViewer> docViewer; rv = mContentViewer->QueryInterface(kIDocumentViewerIID, getter_AddRefs(docViewer)); if (NS_FAILED(rv) || !docViewer) return rv;  nsCOMPtr<nsIPresShell> presShell; rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); if (NS_FAILED(rv) || !presShell) return rv;  nsCOMPtr<nsIDOMSelection> selection; rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(rv) || !selection) return rv;   nsCOMPtr<nsIDocument> doc; rv = docViewer->GetDocument(*getter_AddRefs(doc)); if (NS_FAILED(rv) || !doc) return rv;   nsCOMPtr<nsIDOMHTMLDocument> htmldoc; rv = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc); if (NS_FAILED(rv) || !htmldoc) return rv;  nsCOMPtr<nsIDOMHTMLElement>bodyElement; rv = htmldoc->GetBody(getter_AddRefs(bodyElement)); if (NS_FAILED(rv) || !bodyElement) return rv;  nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement); if (!bodyNode) return NS_ERROR_NO_INTERFACE;  #if 0 rv = selection->Collapse(bodyNode, 0); if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDOMRange>range; rv = selection->GetRangeAt(0, getter_AddRefs(range)); if (NS_FAILED(rv) || !range) return rv; #endif  rv = selection->ClearSelection(); if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDOMRange> range; rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull, NS_GET_IID(nsIDOMRange), getter_AddRefs(range));  rv = range->SelectNodeContents(bodyNode); if (NS_FAILED(rv)) return rv;  rv = selection->AddRange(range); return rv;
return DoCommand ( NS_LITERAL_STRING("cmd_selectAll") );
nsWebShell::SelectAll(void){  nsresult rv;  nsCOMPtr<nsIDocumentViewer> docViewer;  rv = mContentViewer->QueryInterface(kIDocumentViewerIID,                                      getter_AddRefs(docViewer));  if (NS_FAILED(rv) || !docViewer) return rv;  nsCOMPtr<nsIPresShell> presShell;  rv = docViewer->GetPresShell(*getter_AddRefs(presShell));  if (NS_FAILED(rv) || !presShell) return rv;  nsCOMPtr<nsIDOMSelection> selection;  rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));  if (NS_FAILED(rv) || !selection) return rv;  // Get the document object  nsCOMPtr<nsIDocument> doc;  rv = docViewer->GetDocument(*getter_AddRefs(doc));  if (NS_FAILED(rv) || !doc) return rv;  nsCOMPtr<nsIDOMHTMLDocument> htmldoc;  rv = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc);  if (NS_FAILED(rv) || !htmldoc) return rv;  nsCOMPtr<nsIDOMHTMLElement>bodyElement;  rv = htmldoc->GetBody(getter_AddRefs(bodyElement));  if (NS_FAILED(rv) || !bodyElement) return rv;  nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);  if (!bodyNode) return NS_ERROR_NO_INTERFACE;#if 0  rv = selection->Collapse(bodyNode, 0);  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDOMRange>range;  rv = selection->GetRangeAt(0, getter_AddRefs(range));  if (NS_FAILED(rv) || !range) return rv;#endif  rv = selection->ClearSelection();  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDOMRange> range;  rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,                                          NS_GET_IID(nsIDOMRange),                                          getter_AddRefs(range));  rv = range->SelectNodeContents(bodyNode);  if (NS_FAILED(rv)) return rv;  rv = selection->AddRange(range);  return rv;}