diff --git a/mozilla/uriloader/extprotocol/Makefile.in b/mozilla/uriloader/extprotocol/Makefile.in new file mode 100644 index 00000000000..c5482543108 --- /dev/null +++ b/mozilla/uriloader/extprotocol/Makefile.in @@ -0,0 +1,32 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = .. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/uriloader/extprotocol/base/Makefile.in b/mozilla/uriloader/extprotocol/base/Makefile.in new file mode 100644 index 00000000000..87b53c734ad --- /dev/null +++ b/mozilla/uriloader/extprotocol/base/Makefile.in @@ -0,0 +1,52 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = extprotocol +LIBRARY_NAME = extprotocol +IS_COMPONENT = 1 + + +CPPSRCS = nsExternalFactory.cpp \ + nsExternalProtocol.cpp \ + $(NULL) + +SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/extprotocolunix_s.$(LIB_SUFFIX) \ + $(NULL) + +EXTRA_DSO_LDOPTS = \ + -L$(DIST)/bin \ + $(SHARED_LIBRARY_LIBS) \ + $(NSPR_LIBS) \ + $(XPCOM_LIBS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +$(LIBRARY) $(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS) Makefile + diff --git a/mozilla/uriloader/extprotocol/base/Makefile.win b/mozilla/uriloader/extprotocol/base/Makefile.win new file mode 100644 index 00000000000..f5d3ccd3bbf --- /dev/null +++ b/mozilla/uriloader/extprotocol/base/Makefile.win @@ -0,0 +1,48 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. +MODULE=extprotocol + +MAKE_OBJ_TYPE=DLL +DLLNAME=$(MODULE) +DLL=.\$(OBJDIR)\$(DLLNAME).dll + + +CPP_OBJS=\ + .\$(OBJDIR)\nsExternalFactory.obj \ + .\$(OBJDIR)\nsExternalProtocol.obj \ + $(NULL) + +LLIBS=\ + $(DIST)\lib\extprotocolwin_s.lib \ + $(DIST)\lib\xpcom.lib \ + $(LIBNSPR) \ + $(NULL) + +WIN_LIBS= shell32.lib + +include <$(DEPTH)\config\rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) $(DLL) $(DIST)\bin\components + + diff --git a/mozilla/uriloader/extprotocol/base/nsExternalFactory.cpp b/mozilla/uriloader/extprotocol/base/nsExternalFactory.cpp new file mode 100644 index 00000000000..eb6a2a84cef --- /dev/null +++ b/mozilla/uriloader/extprotocol/base/nsExternalFactory.cpp @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + Text import module +*/ + +#include "nsCOMPtr.h" +#include "nsCRT.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIServiceManager.h" +#include "nsICategoryManager.h" +#include "nsXPIDLString.h" +#include "nsExternalProtocol.h" + + +static NS_DEFINE_CID(kExternalProtocolCID, NS_EXTERNALPROTOCOL_CID); + + +NS_GENERIC_FACTORY_CONSTRUCTOR( nsExternalProtocol) + +static NS_IMETHODIMP nsExternalMailtoConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv = nsExternalProtocolConstructor( aOuter, aIID, aResult); + if (NS_SUCCEEDED( rv)) { + nsIExternalProtocol *pProto = (nsIExternalProtocol *) (*aResult); + pProto->SetScheme( "mailto"); + } + return( rv); +} + +static nsModuleComponentInfo components[] = { + { "External protocol handler", + NS_EXTERNALPROTOCOL_CID, + "component://mozilla/externalprotocol/default", + nsExternalProtocolConstructor, + nsnull, + nsnull + }, + { "External mailto protocol handler", + NS_EXTERNALMAILTO_CID, + NS_EXTERNALMAILTO_PROGID, + nsExternalMailtoConstructor, + nsnull, + nsnull + } +}; + + +NS_IMPL_NSGETMODULE("nsExternalProtocolModule", components) + + diff --git a/mozilla/uriloader/extprotocol/base/nsExternalProtocol.cpp b/mozilla/uriloader/extprotocol/base/nsExternalProtocol.cpp new file mode 100644 index 00000000000..8cedcf1e19b --- /dev/null +++ b/mozilla/uriloader/extprotocol/base/nsExternalProtocol.cpp @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributor(s): + * + */ + + +#include "nscore.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsIURI.h" +#include "nsIURL.h" +#include "nsIComponentManager.h" +#include "nsExternalProtocol.h" +#include "nsXPIDLString.h" + + + +#ifdef NS_DEBUG +#define DEBUG_LOG0( x) printf( x) +#define DEBUG_LOG1( x, y) printf( x, y) +#else +#define DEBUG_LOG0( x) +#define DEBUG_LOG1( x, y) +#endif + +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); + + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + + +nsExternalProtocol::nsExternalProtocol() +{ + NS_INIT_REFCNT(); + m_pData = nsnull; + m_schemeName = "default"; +} + + +nsExternalProtocol::~nsExternalProtocol() +{ + if (m_pData) + delete [] m_pData; +} + + + +NS_IMPL_ISUPPORTS(nsExternalProtocol, NS_GET_IID(nsIExternalProtocol)); + + + +NS_IMETHODIMP nsExternalProtocol::SetScheme(const char *scheme) +{ + m_schemeName = scheme; + return( NS_OK); +} + +/* readonly attribute string scheme; */ +NS_IMETHODIMP nsExternalProtocol::GetScheme(char * *aScheme) +{ + *aScheme = m_schemeName.ToNewCString(); + + return( NS_OK); +} + +/* readonly attribute long defaultPort; */ +NS_IMETHODIMP nsExternalProtocol::GetDefaultPort(PRInt32 *aDefaultPort) +{ + *aDefaultPort = 0; + return( NS_OK); +} + +/* nsIURI newURI (in string aSpec, in nsIURI aBaseURI); */ +NS_IMETHODIMP nsExternalProtocol::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval) +{ + nsresult rv; + + nsIURI* url; + if (aBaseURI) { + rv = aBaseURI->Clone(&url); + } else { + rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, + NS_GET_IID(nsIURI), + (void**)&url); + } + if (NS_FAILED(rv)) + return rv; + + rv = url->SetSpec((char*)aSpec); + if (NS_FAILED(rv)) { + NS_RELEASE(url); + return rv; + } + + *_retval = url; + return rv; +} + +/* nsIChannel newChannel (in nsIURI aURI); */ +NS_IMETHODIMP nsExternalProtocol::NewChannel(nsIURI *aURI, nsIChannel **_retval) +{ + if (NS_SUCCEEDED( LaunchViaHelper( aURI))) + return( NS_ERROR_EXTERNAL_LAUNCH); + + return( DefaultLaunch( aURI)); +} + + +nsresult nsExternalProtocol::LaunchViaHelper( nsIURI *pUri) +{ + // check the category manager for an installed external + // handler for this protocol. If one exists, get it + // and try and launch the URI. If it succeeds return NS_OK, + // any other return value will cause the default to be called. + + return( NS_ERROR_FAILURE); +} + diff --git a/mozilla/uriloader/extprotocol/base/nsExternalProtocol.h b/mozilla/uriloader/extprotocol/base/nsExternalProtocol.h new file mode 100644 index 00000000000..851746e2a5f --- /dev/null +++ b/mozilla/uriloader/extprotocol/base/nsExternalProtocol.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsExternalProtocol_h___ +#define nsExternalProtocol_h___ + +#include "nsIProtocolHandler.h" +#include "nsIExternalProtocol.h" +#include "nsCOMPtr.h" +#include "nsString.h" + +#define NS_EXTERNALPROTOCOL_CID \ +{ /* 99BD73D1-F835-11d3-AA27-00A0CC26DA63 */ \ + 0x99bd73d1, 0xf835, 0x11d3, \ + {0xaa, 0x27, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 }} + + + +class nsExternalProtocol : public nsIExternalProtocol +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPROTOCOLHANDLER + NS_DECL_NSIEXTERNALPROTOCOL + + nsExternalProtocol(); + virtual ~nsExternalProtocol(); + /* additional members */ + +protected: + // Launch via an installed helper, if the helper fails + // then we will try and launch using our the default + // external app mechanism. (If that fails too, then + // we fall through to the default handler.) + nsresult LaunchViaHelper( nsIURI *pUri); + + nsresult DefaultLaunch( nsIURI *pUri); + + nsCString m_schemeName; + char * m_pData; // some data to use if you need it +}; + + +#endif // nsExternalProtocol_h__ + diff --git a/mozilla/uriloader/extprotocol/mac/MANIFEST b/mozilla/uriloader/extprotocol/mac/MANIFEST new file mode 100644 index 00000000000..e69de29bb2d diff --git a/mozilla/uriloader/extprotocol/mac/extProtocol.mcp b/mozilla/uriloader/extprotocol/mac/extProtocol.mcp new file mode 100644 index 00000000000..62a26268086 Binary files /dev/null and b/mozilla/uriloader/extprotocol/mac/extProtocol.mcp differ diff --git a/mozilla/uriloader/extprotocol/mac/extProtocolIDL.mcp b/mozilla/uriloader/extprotocol/mac/extProtocolIDL.mcp new file mode 100644 index 00000000000..2efc713a8fd Binary files /dev/null and b/mozilla/uriloader/extprotocol/mac/extProtocolIDL.mcp differ diff --git a/mozilla/uriloader/extprotocol/mac/extProtocolPrefix.h b/mozilla/uriloader/extprotocol/mac/extProtocolPrefix.h new file mode 100644 index 00000000000..a5430f119e9 --- /dev/null +++ b/mozilla/uriloader/extprotocol/mac/extProtocolPrefix.h @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + + + +#include "MacPrefix.h" diff --git a/mozilla/uriloader/extprotocol/mac/extProtocolPrefixDebug.h b/mozilla/uriloader/extprotocol/mac/extProtocolPrefixDebug.h new file mode 100644 index 00000000000..145b3cc22b7 --- /dev/null +++ b/mozilla/uriloader/extprotocol/mac/extProtocolPrefixDebug.h @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + + + +#include "MacPrefix_debug.h" diff --git a/mozilla/uriloader/extprotocol/mac/nsExternalProtocolMac.cpp b/mozilla/uriloader/extprotocol/mac/nsExternalProtocolMac.cpp new file mode 100644 index 00000000000..19964c7cdda --- /dev/null +++ b/mozilla/uriloader/extprotocol/mac/nsExternalProtocolMac.cpp @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributor(s): + * + */ + + +#include "nscore.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsIURI.h" +#include "nsExternalProtocol.h" +#include "nsXPIDLString.h" + +#include + +#ifdef NS_DEBUG +#define DEBUG_LOG0( x) printf( x) +#define DEBUG_LOG1( x, y) printf( x, y) +#else +#define DEBUG_LOG0( x) +#define DEBUG_LOG1( x, y) +#endif + + + +nsresult nsExternalProtocol::DefaultLaunch( nsIURI *pUri) +{ + nsresult rv = NS_ERROR_FAILURE; + + // use internet config to launch the uri + nsXPIDLCString uriStr; + if (pUri) { + pUri->GetSpec( getter_Copies( uriStr)); + } + else { + uriStr = m_schemeName; + } + + + OSStatus err; + ICInstance inst; + long startSel; + long endSel = nsCRT::strlen( (const char *)uriStr); + + err = ICStart(&inst, 'MOSS'); + if (err == noErr) { + err = ICFindConfigFile( inst, 0, nil); + if (err == noErr) { + startSel = 0; + err = ICLaunchURL(inst, "\p", (char *)((const char *) uriStr), endSel, &startSel, &endSel); + if (err == noErr) + rv = NS_ERROR_EXTERNAL_LAUNCH; + } + (void) ICStop(inst); + } + + return( rv); +} + diff --git a/mozilla/uriloader/extprotocol/makefile.win b/mozilla/uriloader/extprotocol/makefile.win new file mode 100644 index 00000000000..9138c1ff07d --- /dev/null +++ b/mozilla/uriloader/extprotocol/makefile.win @@ -0,0 +1,26 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\.. + +DIRS=public win base + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/uriloader/extprotocol/public/Makefile.in b/mozilla/uriloader/extprotocol/public/Makefile.in new file mode 100644 index 00000000000..a3b88124995 --- /dev/null +++ b/mozilla/uriloader/extprotocol/public/Makefile.in @@ -0,0 +1,37 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = extprotocol + +XPIDLSRCS = \ + nsIExternalURIHandler.idl \ + nsIExternalProtocol.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/uriloader/extprotocol/public/makefile.win b/mozilla/uriloader/extprotocol/public/makefile.win new file mode 100644 index 00000000000..8e662119977 --- /dev/null +++ b/mozilla/uriloader/extprotocol/public/makefile.win @@ -0,0 +1,32 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. +IGNORE_MANIFEST=1 + +XPIDLSRCS= .\nsIExternalURIHandler.idl \ + .\nsIExternalProtocol.idl \ + $(NULL) + +MODULE= extprotocol + +include <$(DEPTH)\config\rules.mak> + diff --git a/mozilla/uriloader/extprotocol/public/nsIExternalProtocol.idl b/mozilla/uriloader/extprotocol/public/nsIExternalProtocol.idl new file mode 100644 index 00000000000..766047f36a7 --- /dev/null +++ b/mozilla/uriloader/extprotocol/public/nsIExternalProtocol.idl @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/* + + The import service. + + */ + +#include "nsISupports.idl" +#include "nsIProtocolHandler.idl" +interface nsIURI; + +/* + Unlike most protocol handlers, an external protocol + handler is capable of handling ANY scheme. Of course, it may + not always successfully launch every URI but it has the ability + to try. Consequently, we can either have a single handler that + is "special" or just create a bunch of them and install them + as appropriate. The current implementation provides a bunch + of CLSID's for common protocol handlers that may want to use + an external handler. +*/ + +[scriptable, uuid(4ed3a580-0dfc-11d4-9ad2-00601df05068)] +interface nsIExternalProtocol : nsIProtocolHandler +{ + void setScheme( in string scheme); +}; + +%{C++ +#define NS_EXTERNALMAILTO_CID \ +{ /* 364d6c20-0e16-11d4-9ad2-00601df05068 */ \ + 0x364d6c20, 0x0e16, 0x11d4, \ + { 0x9a, 0xd2, 0x0, 0x60, 0x1d, 0xf0, 0x50, 0x68 } \ +} +#define NS_EXTERNALMAILTO_PROGID \ + "component://mozilla/externalprotocol/mailto" + + +#define NS_ERROR_EXTERNAL_LAUNCH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 100) + +%} diff --git a/mozilla/uriloader/extprotocol/public/nsIExternalURIHandler.idl b/mozilla/uriloader/extprotocol/public/nsIExternalURIHandler.idl new file mode 100644 index 00000000000..94a24a21335 --- /dev/null +++ b/mozilla/uriloader/extprotocol/public/nsIExternalURIHandler.idl @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/* + + The import service. + + */ + +#include "nsISupports.idl" + +interface nsIURI; + +/* + Pretty simple. Just register your class with the category manager under + the proper protocol and someday we'll figure out how to tie that in + to the rest of the mozilla! The idea is that some one will specify in a preference + or some other way that the particular protocol be handled via external app. + When that happens, the external app protocol handler will check the category manager + to see what external handler is available and use it to launch URI's with that protocol. + + Seems almost too simple, there must be more to this?! +*/ + +[scriptable, uuid(578cd5d1-f82b-11d3-aa27-00a0cc26da63)] +interface nsIExternalURILauncher : nsISupports +{ + // mailto, http, nntp, etc. + readonly attribute string protocol; + + // send this URI to an external entity. + nsresult LaunchURI( in nsIURI uri); +}; + diff --git a/mozilla/uriloader/extprotocol/unix/Makefile.in b/mozilla/uriloader/extprotocol/unix/Makefile.in new file mode 100644 index 00000000000..b116b69d1ab --- /dev/null +++ b/mozilla/uriloader/extprotocol/unix/Makefile.in @@ -0,0 +1,41 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1999 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = extprotocol +LIBRARY_NAME = extprotocolunix_s + +CPPSRCS = \ + nsExternalProcotolUnix.cpp \ + $(NULL) + +# we don't want the shared lib, but we want to force the creation of a static lib. +override NO_SHARED_LIB=1 +override NO_STATIC_LIB= + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/uriloader/extprotocol/unix/nsExternalProtocolUnix.cpp b/mozilla/uriloader/extprotocol/unix/nsExternalProtocolUnix.cpp new file mode 100644 index 00000000000..19ecd778af8 --- /dev/null +++ b/mozilla/uriloader/extprotocol/unix/nsExternalProtocolUnix.cpp @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributor(s): + * + */ + + +#include "nscore.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsIURI.h" +#include "nsExternalProtocol.h" +#include "nsXPIDLString.h" + + +#ifdef NS_DEBUG +#define DEBUG_LOG0( x) printf( x) +#define DEBUG_LOG1( x, y) printf( x, y) +#else +#define DEBUG_LOG0( x) +#define DEBUG_LOG1( x, y) +#endif + + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +nsresult nsExternalProtocol::DefaultLaunch( nsIURI *pUri) +{ + nsresult rv = NS_ERROR_FAILURE; + + return( rv); +} + diff --git a/mozilla/uriloader/extprotocol/win/Makefile.win b/mozilla/uriloader/extprotocol/win/Makefile.win new file mode 100644 index 00000000000..6da920940bb --- /dev/null +++ b/mozilla/uriloader/extprotocol/win/Makefile.win @@ -0,0 +1,45 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. +MODULE=extprotocol + +LIBRARY_NAME=extprotocolwin_s + +CPP_OBJS=\ + .\$(OBJDIR)\nsExternalProtocolWin.obj \ + $(NULL) + +INCS = $(INCS) \ + -I$(DEPTH)\dist\include \ + -I..\base \ + $(NULL) + + +include <$(DEPTH)\config\rules.mak> + +install:: $(LIBRARY) + $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib + + +clobber:: + rm -f $(DIST)\lib\$(LIBRARY_NAME).lib + diff --git a/mozilla/uriloader/extprotocol/win/nsExternalProtocolWin.cpp b/mozilla/uriloader/extprotocol/win/nsExternalProtocolWin.cpp new file mode 100644 index 00000000000..d4f3b5fe73e --- /dev/null +++ b/mozilla/uriloader/extprotocol/win/nsExternalProtocolWin.cpp @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributor(s): + * + */ + + +#include "nscore.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsIURI.h" +#include "nsExternalProtocol.h" +#include "nsXPIDLString.h" + +#include + +#ifdef NS_DEBUG +#define DEBUG_LOG0( x) printf( x) +#define DEBUG_LOG1( x, y) printf( x, y) +#else +#define DEBUG_LOG0( x) +#define DEBUG_LOG1( x, y) +#endif + + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +// ::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Accounts", 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &sKey) == ERROR_SUCCESS) + +BYTE * GetValueBytes( HKEY hKey, const char *pValueName) +{ + LONG err; + DWORD bufSz; + LPBYTE pBytes = NULL; + + err = ::RegQueryValueEx( hKey, pValueName, NULL, NULL, NULL, &bufSz); + if (err == ERROR_SUCCESS) { + pBytes = new BYTE[bufSz]; + err = ::RegQueryValueEx( hKey, pValueName, NULL, NULL, pBytes, &bufSz); + if (err != ERROR_SUCCESS) { + delete [] pBytes; + pBytes = NULL; + } + } + + return( pBytes); +} + + +PRBool GetCommandString( const char *pProtocol, nsCString& command) +{ + // HKEY_CLASSES_ROOT + // /shell/open/command + + PRBool result = PR_FALSE; + nsCString reg = pProtocol; + reg.Append( "\\shell\\open\\command"); + HKEY hKey; + LONG err = ::RegOpenKeyEx( HKEY_CLASSES_ROOT, reg, 0, KEY_QUERY_VALUE, &hKey); + if (err == ERROR_SUCCESS) { + LPBYTE pBytes = GetValueBytes( hKey, NULL); + if (pBytes) { + command = (char *)pBytes; + delete [] pBytes; + result = PR_TRUE; + } + } + + return( result); +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +nsresult nsExternalProtocol::DefaultLaunch( nsIURI *pUri) +{ + nsresult rv = NS_OK; + + // 1. Find the default app for this protocol + // 2. Set up the command line + // 3. Launch the app. + + // For now, we'll just cheat essentially, check for the command line + // then just call ShellExecute()! + nsCString cmd; + if (GetCommandString( m_schemeName, cmd)) { + nsXPIDLCString uriStr; + if (pUri) { + pUri->GetSpec( getter_Copies( uriStr)); + } + else { + uriStr = m_schemeName; + } + LONG r = (LONG) ::ShellExecute( NULL, "open", uriStr, NULL, NULL, SW_SHOWNORMAL); + if (r < 32) { + DEBUG_LOG1( "ShellExecute failed: %d\n", (int)r); + rv = NS_ERROR_FAILURE; + } + else + rv = NS_ERROR_EXTERNAL_LAUNCH; + + } + else + rv = NS_ERROR_FAILURE; + + return( rv); +} +