From c7211a20f08ff246546831fc13c162d12c748807 Mon Sep 17 00:00:00 2001 From: "hwaara%chello.se" Date: Fri, 26 Oct 2001 19:19:35 +0000 Subject: [PATCH] #47981, link to newsgroups launches new mail window. Make our window handling in news a lot better, reuse whatever 3pane is already open. r/sr=sspitzer git-svn-id: svn://10.0.0.236/trunk@106380 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/news/src/nsNntpService.cpp | 44 +++++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/mozilla/mailnews/news/src/nsNntpService.cpp b/mozilla/mailnews/news/src/nsNntpService.cpp index 1ef03a03c00..62251dadf2c 100644 --- a/mozilla/mailnews/news/src/nsNntpService.cpp +++ b/mozilla/mailnews/news/src/nsNntpService.cpp @@ -23,6 +23,7 @@ * Seth Spitzer * Scott MacGregor * Pierre Phaneuf + * Håkan Waara * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -67,6 +68,8 @@ #include "nsIDocShell.h" #include "nsIDocShellLoadInfo.h" #include "nsIMessengerWindowService.h" +#include "nsIWindowMediator.h" +#include "nsIDOMWindowInternal.h" #include "nsIMsgSearchSession.h" #include "nsAppDirectoryServiceDefs.h" #include "nsIWebNavigation.h" @@ -1578,24 +1581,39 @@ NS_IMETHODIMP nsNntpService::GetChromeUrlForTask(char **aChromeUrlForTask) NS_IMETHODIMP nsNntpService::HandleContent(const char * aContentType, const char * aCommand, nsISupports * aWindowContext, nsIRequest *request) { - nsresult rv = NS_OK; + nsresult rv; if (!request) return NS_ERROR_NULL_POINTER; - nsCOMPtr aChannel = do_QueryInterface(request); - if (!aChannel) return NS_ERROR_NULL_POINTER; + nsCOMPtr aChannel = do_QueryInterface(request, &rv); + NS_ENSURE_SUCCESS(rv, rv); - if (nsCRT::strcasecmp(aContentType, "x-application-newsgroup") == 0) { - nsCOMPtr uri; - rv = aChannel->GetURI(getter_AddRefs(uri)); - if (NS_FAILED(rv)) return rv; + if (nsCRT::strcasecmp(aContentType, "x-application-newsgroup") == 0) + { + nsCOMPtr uri; + rv = aChannel->GetURI(getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); - if (uri) { - nsCOMPtr messengerWindowService = do_GetService(NS_MESSENGERWINDOWSERVICE_CONTRACTID,&rv); - if (NS_FAILED(rv)) return rv; + if (uri) + { + nsCOMPtr mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr window; - rv = messengerWindowService->OpenMessengerWindowWithUri(uri); - if (NS_FAILED(rv)) return rv; - } + // If there already is a messenger window open, don't waste time opening + // a new one; focus it. Otherwise, create a new messenger window. + mediator->GetMostRecentWindow(NS_LITERAL_STRING("mail:3pane").get(), getter_AddRefs(window)); + + if (window) + window->Focus(); + else + { + nsCOMPtr messengerWindowService = do_GetService(NS_MESSENGERWINDOWSERVICE_CONTRACTID,&rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = messengerWindowService->OpenMessengerWindowWithUri(uri); + NS_ENSURE_SUCCESS(rv, rv); + } + } } return rv;