nsresult rv; nsRect bounds;  WEB_TRACE(WEB_TRACE_CALLS, ("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p", this, aContentViewer, aCommand ? aCommand : "", aExtraInfo));               nsCOMPtr<nsIWebShell> parent; rv = GetParent(*getter_AddRefs(parent)); if (NS_FAILED(rv)) { return rv; }  if (mContentViewer || parent) { nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV; if (mContentViewer) {   oldMUDV = do_QueryInterface(mContentViewer); } else { nsCOMPtr<nsIContentViewer> parentContentViewer; rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer)); if (NS_FAILED(rv)) { return rv; } if (parentContentViewer) { oldMUDV = do_QueryInterface(parentContentViewer); } }  PRUnichar *defaultCharset=nsnull; PRUnichar *forceCharset=nsnull; PRUnichar *hintCharset=nsnull; PRInt32 hintCharsetSource;  nsCOMPtr<nsIMarkupDocumentViewer> newMUDV = do_QueryInterface(aContentViewer); if (oldMUDV && newMUDV) { NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE);   NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE);  if (defaultCharset) { Recycle(defaultCharset); } if (forceCharset) { Recycle(forceCharset); } if (hintCharset) { Recycle(hintCharset); } } }   mContentViewer = nsnull; if (nsnull != mScriptContext) { mScriptContext->GC(); } mContentViewer = aContentViewer;    if(mWindow && mWindow->GetNativeData(NS_NATIVE_WIDGET)) { mWindow->GetClientBounds(bounds); bounds.x = bounds.y = 0; rv = mContentViewer->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET), mDeviceContext, mPrefs, bounds, mScrollPref);     if (mContentViewer && mHistoryState) { nsCOMPtr<nsIDocumentViewer> docv = do_QueryInterface(mContentViewer); if (nsnull != docv) { nsCOMPtr<nsIPresShell> shell; rv = docv->GetPresShell(*getter_AddRefs(shell)); if (NS_SUCCEEDED(rv)) { rv = shell->SetHistoryState((nsILayoutHistoryState*) mHistoryState); } } }  if (NS_SUCCEEDED(rv)) { mContentViewer->Show(); } } else { mContentViewer = nsnull; }   DestroyChildren();  return rv;
return nsDocShell::Embed(aContentViewer, aCommand, aExtraInfo);
nsWebShell::Embed(nsIContentViewer* aContentViewer,                  const char* aCommand,                  nsISupports* aExtraInfo){  nsresult rv;  nsRect bounds;  WEB_TRACE(WEB_TRACE_CALLS,      ("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p",       this, aContentViewer, aCommand ? aCommand : "", aExtraInfo));  //  // Copy content viewer state from previous or parent content viewer.  //  // The following logic is mirrored in nsHTMLDocument::StartDocumentLoad!  //  // Do NOT to maintain a reference to the old content viewer outside  // of this "copying" block, or it will not be destroyed until the end of  // this routine and all <SCRIPT>s and event handlers fail! (bug 20315)  //  // In this block of code, if we get an error result, we return it  // but if we get a null pointer, that's perfectly legal for parent  // and parentContentViewer.  //  nsCOMPtr<nsIWebShell> parent;  rv = GetParent(*getter_AddRefs(parent));  if (NS_FAILED(rv)) { return rv; }    if (mContentViewer || parent)   {    nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV;    if (mContentViewer) { // Get any interesting state from old content viewer      // XXX: it would be far better to just reuse the document viewer ,      //      since we know we're just displaying the same document as before      oldMUDV = do_QueryInterface(mContentViewer);    }    else    { // No old content viewer, so get state from parent's content viewer      nsCOMPtr<nsIContentViewer> parentContentViewer;      rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));      if (NS_FAILED(rv)) { return rv; }      if (parentContentViewer) {        oldMUDV = do_QueryInterface(parentContentViewer);      }    }    PRUnichar *defaultCharset=nsnull;    PRUnichar *forceCharset=nsnull;    PRUnichar *hintCharset=nsnull;    PRInt32 hintCharsetSource;    nsCOMPtr<nsIMarkupDocumentViewer> newMUDV = do_QueryInterface(aContentViewer);    if (oldMUDV && newMUDV)    {      NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE);      // set the old state onto the new content viewer      NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE);      NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE);      if (defaultCharset) {        Recycle(defaultCharset);      }      if (forceCharset) {        Recycle(forceCharset);      }      if (hintCharset) {        Recycle(hintCharset);      }    }  }  // End copying block (Don't hold content/document viewer ref beyond here!!)  mContentViewer = nsnull;  if (nsnull != mScriptContext) {    mScriptContext->GC();  }  mContentViewer = aContentViewer;  // check to see if we have a window to embed into --dwc0001  /* Note we also need to check for the presence of a native widget. If the     webshell is hidden before it's embedded, which can happen in an onload     handler, the native widget is destroyed before this code is run.  This     appears to be mostly harmless except on Windows, where the subsequent     attempt to create a child window without a parent is met with disdain     by the OS. It's handy, then, that GetNativeData on Windows returns     null in this case. */  if(mWindow && mWindow->GetNativeData(NS_NATIVE_WIDGET)) {    mWindow->GetClientBounds(bounds);    bounds.x = bounds.y = 0;    rv = mContentViewer->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),                              mDeviceContext,                              mPrefs,                              bounds,                              mScrollPref);    // If the history state has been set by session history,    // set it on the pres shell now that we have a content    // viewer.    if (mContentViewer && mHistoryState) {      nsCOMPtr<nsIDocumentViewer> docv = do_QueryInterface(mContentViewer);      if (nsnull != docv) {        nsCOMPtr<nsIPresShell> shell;        rv = docv->GetPresShell(*getter_AddRefs(shell));        if (NS_SUCCEEDED(rv)) {          rv = shell->SetHistoryState((nsILayoutHistoryState*) mHistoryState);        }      }    }    if (NS_SUCCEEDED(rv)) {      mContentViewer->Show();    }  } else {    mContentViewer = nsnull;  }  // Now that we have switched documents, forget all of our children  DestroyChildren();  return rv;}