nsIDOMSelection* sel; GetSelection(nsISelectionController::SELECTION_NORMAL, &sel);
nsCOMPtr<nsIDOMSelection> sel;  nsCOMPtr<nsIEventStateManager> manager; nsCOMPtr<nsIContent> content; rv = mPresContext->GetEventStateManager(getter_AddRefs(manager)); if (NS_FAILED(rv) || !manager) return rv?rv:NS_ERROR_FAILURE; rv = manager->GetFocusedContent(getter_AddRefs(content)); if (NS_SUCCEEDED(rv) && content) {    nsCOMPtr<nsIDOMNSHTMLInputElement> htmlElement(do_QueryInterface(content)); if (htmlElement) { nsIFrame *htmlInputFrame; rv = GetPrimaryFrameFor(content, &htmlInputFrame); if (NS_FAILED(rv) || !htmlInputFrame) return rv?rv:NS_ERROR_FAILURE; nsCOMPtr<nsISelectionController> selCon; rv = htmlInputFrame->GetSelectionController(mPresContext,getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return rv?rv:NS_ERROR_FAILURE; rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel)); } } if (!sel) rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel));
PresShell::DoCopy(){  nsCOMPtr<nsIDocument> doc;  GetDocument(getter_AddRefs(doc));  if (doc) {    nsString buffer;    nsresult rv;    nsIDOMSelection* sel;    GetSelection(nsISelectionController::SELECTION_NORMAL, &sel);          if (sel != nsnull)      doc->CreateXIF(buffer,sel);    NS_IF_RELEASE(sel);    // Get the Clipboard    NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv);    if (NS_FAILED(rv)) return rv;    if ( clipboard ) {      // Create a transferable for putting data on the Clipboard      nsCOMPtr<nsITransferable> trans;      rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,                                               NS_GET_IID(nsITransferable),                                               getter_AddRefs(trans));      if ( trans ) {        // The data on the clipboard will be in "XIF" format        // so give the clipboard transferable a "XIFConverter" for         // converting from XIF to other formats        nsCOMPtr<nsIFormatConverter> xifConverter;        rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull,                                                 NS_GET_IID(nsIFormatConverter),                                                getter_AddRefs(xifConverter));        if ( xifConverter ) {          // Add the XIF DataFlavor to the transferable          // this tells the transferable that it can handle receiving the XIF format          trans->AddDataFlavor(kXIFMime);          // Add the converter for going from XIF to other formats          trans->SetConverter(xifConverter);          // Now add the XIF data to the transferable, placing it into a nsISupportsWString object.          // the transferable wants the number bytes for the data and since it is double byte          // we multiply by 2.           nsCOMPtr<nsISupportsWString> dataWrapper;          rv = nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_PROGID,                                                  nsnull,                                                   NS_GET_IID(nsISupportsWString),                                                  getter_AddRefs(dataWrapper));          if ( dataWrapper ) {            dataWrapper->SetData ( NS_CONST_CAST(PRUnichar*,buffer.GetUnicode()) );            // QI the data object an |nsISupports| so that when the transferable holds            // onto it, it will addref the correct interface.            nsCOMPtr<nsISupports> genericDataObj ( do_QueryInterface(dataWrapper) );            trans->SetTransferData(kXIFMime, genericDataObj, buffer.Length()*2);          }                    // put the transferable on the clipboard          clipboard->SetData(trans, nsnull, nsIClipboard::kGlobalClipboard);        }      }    }  }  return NS_OK;}