nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow)
nsMessenger::SetWindow(nsIDOMWindow *aWin, nsIMsgStatusFeedback *aStatusFeedback)
nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow){  nsCOMPtr<nsIPrefBranchInternal> pbi;  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);  if (prefs)  {    nsCOMPtr<nsIPrefBranch> prefBranch;    prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));    if (prefBranch)      pbi = do_QueryInterface(prefBranch);  }	if(!aWin)	{    // it isn't an error to pass in null for aWin, in fact it means we are shutting    // down and we should start cleaning things up...		if (mMsgWindow)		{			nsCOMPtr<nsIMsgStatusFeedback> aStatusFeedback;			mMsgWindow->GetStatusFeedback(getter_AddRefs(aStatusFeedback));			if (aStatusFeedback)				aStatusFeedback->SetDocShell(nsnull, nsnull);      // Remove pref observer      if (pbi)        pbi->RemoveObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this);		}		return NS_OK;	}  mMsgWindow = aMsgWindow;  NS_IF_RELEASE(mWindow);  mWindow = aWin;  NS_ADDREF(aWin);  nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );  NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);  nsCOMPtr<nsIDocShell> docShell;  globalObj->GetDocShell(getter_AddRefs(docShell));  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));  NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);  nsCOMPtr<nsIDocShellTreeItem> rootDocShellAsItem;  docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootDocShellAsItem));  nsCOMPtr<nsIDocShellTreeNode>                      rootDocShellAsNode(do_QueryInterface(rootDocShellAsItem));  if (rootDocShellAsNode)   {    nsCOMPtr<nsIDocShellTreeItem> childAsItem;    nsresult rv = rootDocShellAsNode->FindChildWithName(NS_LITERAL_STRING("messagepane").get(),      PR_TRUE, PR_FALSE, nsnull, getter_AddRefs(childAsItem));    mDocShell = do_QueryInterface(childAsItem);    if (NS_SUCCEEDED(rv) && mDocShell) {        if (aMsgWindow) {            nsCOMPtr<nsIMsgStatusFeedback> aStatusFeedback;                        aMsgWindow->GetStatusFeedback(getter_AddRefs(aStatusFeedback));            if (aStatusFeedback)            {                aStatusFeedback->SetDocShell(mDocShell, mWindow);            }            aMsgWindow->GetTransactionManager(getter_AddRefs(mTxnMgr));            // Add pref observer            if (pbi)              pbi->AddObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this, PR_TRUE);            SetDisplayProperties();        }    }  }  // we don't always have a message pane, like in the addressbook  // so if we don't havea docshell, use the one for the xul window.  // we do this so OpenURL() will work.  if (!mDocShell)    mDocShell = docShell;  return NS_OK;}