diff --git a/mailnews/base/build/Makefile.in b/mailnews/base/build/Makefile.in index 2f3453d3d6d..910a3224efe 100644 --- a/mailnews/base/build/Makefile.in +++ b/mailnews/base/build/Makefile.in @@ -53,6 +53,7 @@ EXTRA_DSO_LDOPTS = \ $(MOZ_TIMER_LIBS) \ -L$(DIST)/bin \ $(EXTRA_DSO_LIBS) \ + $(MOZ_JS_LIBS) \ $(MOZ_COMPONENT_LIBS) \ $(NULL) diff --git a/mailnews/base/build/makefile.win b/mailnews/base/build/makefile.win index ec9cfd81d01..ef79f6ab203 100644 --- a/mailnews/base/build/makefile.win +++ b/mailnews/base/build/makefile.win @@ -39,6 +39,7 @@ CPP_OBJS= \ LLIBS= \ $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\js32$(VERSION_NUMBER).lib \ $(DIST)\lib\msgbsutl.lib \ $(DIST)\lib\msgbase_s.lib \ $(DIST)\lib\msgsearch_s.lib \ diff --git a/mailnews/base/build/nsMsgBaseCID.h b/mailnews/base/build/nsMsgBaseCID.h index bce7e83242a..d79d707442c 100644 --- a/mailnews/base/build/nsMsgBaseCID.h +++ b/mailnews/base/build/nsMsgBaseCID.h @@ -240,6 +240,11 @@ "component://netscape/appshell/component/messenger" #define NS_MAILSTARTUPHANDLER_PROGID \ "component://netscape/commandlinehandler/general-startup-mail" +#define NS_MESSENGERWINDOWSERVICE_PROGID \ + "component://netscape/messenger/windowservice" +#define NS_MESSENGERWINDOWSERVICE_CID \ +{ 0xa01b6724, 0x1dd1, 0x11b2, \ + {0xaa, 0xb9, 0x82,0xf2, 0x4c,0x59, 0x5f, 0x41} } // // nsMessenger diff --git a/mailnews/base/build/nsMsgFactory.cpp b/mailnews/base/build/nsMsgFactory.cpp index 082283bafce..e1cd0cd09cc 100644 --- a/mailnews/base/build/nsMsgFactory.cpp +++ b/mailnews/base/build/nsMsgFactory.cpp @@ -117,6 +117,10 @@ static nsModuleComponentInfo gComponents[] = { NS_MESSENGERBOOTSTRAP_PROGID, nsMessengerBootstrapConstructor, }, + { "Netscape Messenger Window Service", NS_MESSENGERWINDOWSERVICE_CID, + NS_MESSENGERWINDOWSERVICE_PROGID, + nsMessengerBootstrapConstructor, + }, { "Mail Startup Handler", NS_MESSENGERBOOTSTRAP_CID, NS_MAILSTARTUPHANDLER_PROGID, nsMessengerBootstrapConstructor, diff --git a/mailnews/base/public/Makefile.in b/mailnews/base/public/Makefile.in index 4d284328773..2cff9abee2d 100644 --- a/mailnews/base/public/Makefile.in +++ b/mailnews/base/public/Makefile.in @@ -72,6 +72,7 @@ XPIDLSRCS = \ nsIIncomingServerListener.idl \ nsIMsgHdr.idl \ nsIMessengerMigrator.idl \ + nsIMessengerWindowService.idl \ nsIMsgStringService.idl \ nsIMsgViewNavigationService.idl \ nsIMsgPrintEngine.idl \ diff --git a/mailnews/base/public/makefile.win b/mailnews/base/public/makefile.win index b08fdab50e5..fc3dfc0ad53 100644 --- a/mailnews/base/public/makefile.win +++ b/mailnews/base/public/makefile.win @@ -33,6 +33,7 @@ XPIDLSRCS = \ .\nsIMsgAccount.idl \ .\nsIMsgAccountManager.idl \ .\nsIMessengerMigrator.idl \ + .\nsIMessengerWindowService.idl \ .\nsIMsgFolder.idl \ .\nsIMsgFolderCache.idl \ .\nsIMsgFolderCacheElement.idl \ diff --git a/mailnews/base/src/nsMessengerBootstrap.cpp b/mailnews/base/src/nsMessengerBootstrap.cpp index 49728d31c91..46138524a72 100644 --- a/mailnews/base/src/nsMessengerBootstrap.cpp +++ b/mailnews/base/src/nsMessengerBootstrap.cpp @@ -29,7 +29,12 @@ #include "nsIMsgMailSession.h" #include "nsIMsgFolderCache.h" #include "nsIPref.h" +#include "nsIDOMWindow.h" +#include "nsIAppShellService.h" +#include "nsAppShellCIDs.h" +#include "nsIURI.h" +static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID); static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -37,7 +42,7 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); NS_IMPL_THREADSAFE_ADDREF(nsMessengerBootstrap); NS_IMPL_THREADSAFE_RELEASE(nsMessengerBootstrap); -NS_IMPL_QUERY_INTERFACE2(nsMessengerBootstrap, nsIAppShellComponent, nsICmdLineHandler); +NS_IMPL_QUERY_INTERFACE3(nsMessengerBootstrap, nsIAppShellComponent, nsICmdLineHandler, nsIMessengerWindowService); nsMessengerBootstrap::nsMessengerBootstrap() { @@ -101,3 +106,57 @@ NS_IMETHODIMP nsMessengerBootstrap::GetChromeUrlForTask(char **aChromeUrlForTask return NS_OK; } +// Utility function to open a messenger window and pass an argument string to it. +static nsresult openWindow( const PRUnichar *chrome, const PRUnichar *args ) { + nsCOMPtr hiddenWindow; + JSContext *jsContext; + nsresult rv; + NS_WITH_SERVICE( nsIAppShellService, appShell, kAppShellServiceCID, &rv ) + if ( NS_SUCCEEDED( rv ) ) { + rv = appShell->GetHiddenWindowAndJSContext( getter_AddRefs( hiddenWindow ), + &jsContext ); + if ( NS_SUCCEEDED( rv ) ) { + // Set up arguments for "window.openDialog" + void *stackPtr; + jsval *argv = JS_PushArguments( jsContext, + &stackPtr, + "WssW", + chrome, + "_blank", + "chrome,dialog=no,all", + args ); + if ( argv ) { + nsCOMPtr newWindow; + rv = hiddenWindow->OpenDialog( jsContext, + argv, + 4, + getter_AddRefs( newWindow ) ); + JS_PopArguments( jsContext, stackPtr ); + } + } + } + return rv; +} + +NS_IMETHODIMP nsMessengerBootstrap::OpenMessengerWindowWithUri(nsIURI *aURI) +{ + nsresult rv; + + nsXPIDLCString args; + nsXPIDLCString chromeurl; + + if (!aURI) return NS_ERROR_FAILURE; + + rv = aURI->GetSpec(getter_Copies(args)); + if (NS_FAILED(rv)) return rv; + + rv = GetChromeUrlForTask(getter_Copies(chromeurl)); + if (NS_FAILED(rv)) return rv; + + // we need to use the "mailnews.reuse_thread_window2" pref + // to determine if we should open a new window, or use an existing one. + rv = openWindow(nsString(chromeurl).GetUnicode(),nsString(args).GetUnicode()); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} diff --git a/mailnews/base/src/nsMessengerBootstrap.h b/mailnews/base/src/nsMessengerBootstrap.h index c9b3fd580c6..c16cb7c4fa1 100644 --- a/mailnews/base/src/nsMessengerBootstrap.h +++ b/mailnews/base/src/nsMessengerBootstrap.h @@ -29,6 +29,7 @@ #include "nsIAppShellService.h" #include "nsIAppShellComponent.h" #include "nsICmdLineHandler.h" +#include "nsIMessengerWindowService.h" #define NS_MESSENGERBOOTSTRAP_CID \ { /* 4a85a5d0-cddd-11d2-b7f6-00805f05ffa5 */ \ @@ -36,7 +37,7 @@ {0xb7, 0xf6, 0x00, 0x80, 0x5f, 0x05, 0xff, 0xa5}} -class nsMessengerBootstrap : public nsIAppShellComponent, public nsICmdLineHandler { +class nsMessengerBootstrap : public nsIAppShellComponent, public nsICmdLineHandler, public nsIMessengerWindowService { public: nsMessengerBootstrap(); @@ -45,6 +46,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIAPPSHELLCOMPONENT NS_DECL_NSICMDLINEHANDLER + NS_DECL_NSIMESSENGERWINDOWSERVICE CMDLINEHANDLER_REGISTERPROC_DECLS }; diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp index 7038f386a7d..7b8a53fc16a 100644 --- a/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mailnews/compose/src/nsMsgComposeService.cpp @@ -353,19 +353,15 @@ NS_IMETHODIMP nsMsgComposeService::HandleContent(const char * aContentType, cons const char * aWindowTarget, nsISupports * aWindowContext, nsIChannel * aChannel) { nsresult rv = NS_OK; - if (aChannel) - { - // First of all, get the content type and make sure it is a content type we know how to handle! - if (nsCRT::strcasecmp(aContentType, "x-application-mailto") == 0) - { + if (!aChannel) return NS_ERROR_NULL_POINTER; + + // First of all, get the content type and make sure it is a content type we know how to handle! + if (nsCRT::strcasecmp(aContentType, "x-application-mailto") == 0) { nsCOMPtr aUri; rv = aChannel->GetURI(getter_AddRefs(aUri)); if (aUri) rv = OpenComposeWindowWithURI(nsnull, aUri); - } } - else - rv = NS_ERROR_NULL_POINTER; return rv; } diff --git a/mailnews/news/build/nsMsgNewsFactory.cpp b/mailnews/news/build/nsMsgNewsFactory.cpp index b708095bf81..bafec8bee59 100644 --- a/mailnews/news/build/nsMsgNewsFactory.cpp +++ b/mailnews/news/build/nsMsgNewsFactory.cpp @@ -45,6 +45,8 @@ #include "nsNNTPNewsgroupList.h" #include "nsNNTPArticleList.h" #include "nsNNTPHost.h" +#include "nsIContentHandler.h" +#include "nsCURILoader.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsNntpUrl) NS_GENERIC_FACTORY_CONSTRUCTOR(nsNntpService) @@ -93,6 +95,10 @@ static nsModuleComponentInfo components[] = NS_NNTPSERVICE_CID, NS_SNEWSPROTOCOLHANDLER_PROGID, nsNntpServiceConstructor }, + { "newsgroup content handler", + NS_NNTPSERVICE_CID, + NS_CONTENT_HANDLER_PROGID_PREFIX"x-application-newsgroup", + nsNntpServiceConstructor }, { "News Folder Resource", NS_NEWSFOLDERRESOURCE_CID, NS_NEWSFOLDERRESOURCE_PROGID, diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 846efeeddba..9d0b019fd16 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -1062,20 +1062,18 @@ nsresult nsNNTPProtocol::ParseURL(nsIURI * aURL, PRBool * bValP, char ** aGroup, char ** aCommandSpecificData) { PRInt32 status = 0; - char *fullPath = 0; + nsXPIDLCString fullPath; char *group = 0; char *message_id = 0; char *command_specific_data = 0; char * s = 0; // get the file path part and store it as the group... - aURL->GetPath(&fullPath); - if (fullPath && *fullPath == '/') - group = PL_strdup(fullPath+1); + aURL->GetPath(getter_Copies(fullPath)); + if ((const char *)fullPath && ((*(const char *)fullPath) == '/')) + group = PL_strdup((const char *)fullPath+1); else - group = PL_strdup(fullPath); - - nsAllocator::Free(fullPath); + group = PL_strdup((const char *)fullPath); // more to do here, but for now, this works. // only escape if we are doing a search @@ -5049,3 +5047,14 @@ nsNNTPProtocol::SetProgressStatus(char *message) } PR_FREEIF(progressMsg); } + +NS_IMETHODIMP nsNNTPProtocol::GetContentType(char * *aContentType) +{ + if ((const char *)m_currentGroup && nsCRT::strlen((const char *)m_currentGroup)) { + *aContentType = nsCRT::strdup("x-application-newsgroup"); + } + else { + *aContentType = nsCRT::strdup("message/rfc822"); + } + return NS_OK; +} diff --git a/mailnews/news/src/nsNNTPProtocol.h b/mailnews/news/src/nsNNTPProtocol.h index 6ce732e8275..e7e5652e1ed 100644 --- a/mailnews/news/src/nsNNTPProtocol.h +++ b/mailnews/news/src/nsNNTPProtocol.h @@ -161,6 +161,7 @@ public: char * m_ProxyServer; /* proxy server hostname */ NS_IMETHOD Cancel(nsresult status); // handle stop button + NS_IMETHOD GetContentType(char * *aContentType); nsresult LoadUrl(nsIURI * aURL, nsISupports * aConsumer); diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp index 524a3694caa..bfcf075896a 100644 --- a/mailnews/news/src/nsNntpService.cpp +++ b/mailnews/news/src/nsNntpService.cpp @@ -53,6 +53,7 @@ #include "nsICmdLineHandler.h" #include "nsICategoryManager.h" #include "nsIDocShell.h" +#include "nsIMessengerWindowService.h" #undef GetPort // XXX Windows! #undef SetPort // XXX Windows! @@ -84,12 +85,13 @@ nsNntpService::~nsNntpService() NS_IMPL_THREADSAFE_ADDREF(nsNntpService); NS_IMPL_THREADSAFE_RELEASE(nsNntpService); -NS_IMPL_QUERY_INTERFACE5(nsNntpService, +NS_IMPL_QUERY_INTERFACE6(nsNntpService, nsINntpService, nsIMsgMessageService, nsIProtocolHandler, nsIMsgProtocolInfo, - nsICmdLineHandler) + nsICmdLineHandler, + nsIContentHandler) //////////////////////////////////////////////////////////////////////////////////////// // nsIMsgMessageService support @@ -1349,3 +1351,27 @@ NS_IMETHODIMP nsNntpService::GetChromeUrlForTask(char **aChromeUrlForTask) return NS_OK; } + + +NS_IMETHODIMP +nsNntpService::HandleContent(const char * aContentType, const char * aCommand, const char * aWindowTarget, nsISupports * aWindowContext, nsIChannel * aChannel) +{ + nsresult rv = NS_OK; + if (!aChannel) return NS_ERROR_NULL_POINTER; + + if (nsCRT::strcasecmp(aContentType, "x-application-newsgroup") == 0) { + nsCOMPtr uri; + rv = aChannel->GetURI(getter_AddRefs(uri)); + if (NS_FAILED(rv)) return rv; + + if (uri) { + nsCOMPtr messengerWindowService = do_GetService(NS_MESSENGERWINDOWSERVICE_PROGID,&rv); + if (NS_FAILED(rv)) return rv; + + rv = messengerWindowService->OpenMessengerWindowWithUri(uri); + if (NS_FAILED(rv)) return rv; + } + } + + return rv; +} diff --git a/mailnews/news/src/nsNntpService.h b/mailnews/news/src/nsNntpService.h index aa16ab314be..5b14a9e7cc1 100644 --- a/mailnews/news/src/nsNntpService.h +++ b/mailnews/news/src/nsNntpService.h @@ -35,6 +35,7 @@ #include "nsINntpUrl.h" #include "nsICmdLineHandler.h" #include "nsCOMPtr.h" +#include "nsIContentHandler.h" class nsIURI; class nsIUrlListener; @@ -43,7 +44,8 @@ class nsNntpService : public nsINntpService, public nsIMsgMessageService, public nsIProtocolHandler, public nsIMsgProtocolInfo, - public nsICmdLineHandler + public nsICmdLineHandler, + public nsIContentHandler { public: @@ -53,6 +55,7 @@ public: NS_DECL_NSIPROTOCOLHANDLER NS_DECL_NSIMSGPROTOCOLINFO NS_DECL_NSICMDLINEHANDLER + NS_DECL_NSICONTENTHANDLER // nsNntpService nsNntpService();