nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mDocument->GetScriptGlobalObject());
nsPIDOMWindow *ourWindow = mDocument->GetWindow();
PresShell::GetSelectionForCopy(nsISelection** outSelection){  nsresult rv = NS_OK;  *outSelection = nsnull;  if (!mDocument) return NS_ERROR_FAILURE;  nsCOMPtr<nsIContent> content;  nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mDocument->GetScriptGlobalObject());  if (ourWindow) {    nsIFocusController *focusController = ourWindow->GetRootFocusController();    if (focusController) {      nsCOMPtr<nsIDOMElement> focusedElement;      focusController->GetFocusedElement(getter_AddRefs(focusedElement));      content = do_QueryInterface(focusedElement);    }  }  nsCOMPtr<nsISelection> sel;  if (content)  {    //check to see if we need to get selection from frame    //optimization that MAY need to be expanded as more things implement their own "selection"    nsCOMPtr<nsIDOMNSHTMLInputElement>    htmlInputElement(do_QueryInterface(content));    nsCOMPtr<nsIDOMNSHTMLTextAreaElement> htmlTextAreaElement(do_QueryInterface(content));    if (htmlInputElement || htmlTextAreaElement)    {      nsIFrame *htmlInputFrame = GetPrimaryFrameFor(content);      if (!htmlInputFrame) return NS_ERROR_FAILURE;      nsCOMPtr<nsISelectionController> selCon;      rv = htmlInputFrame->GetSelectionController(mPresContext,getter_AddRefs(selCon));      if (NS_FAILED(rv)) return rv;      if (!selCon) return NS_ERROR_FAILURE;      rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));    }  }  if (!sel) //get selection from this PresShell    rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));     *outSelection = sel;  NS_IF_ADDREF(*outSelection);  return rv;}