1998-12-16 08:40:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsIProtocolURLFactory.h"
|
|
|
|
#include "nsHttpUrl.h"
|
|
|
|
#include "nsINetService.h"
|
1999-01-15 02:21:06 +03:00
|
|
|
#include "nsNetThread.h"
|
1998-12-16 08:40:20 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
class nsHttpURLFactory : public nsIProtocolURLFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolURLFactory:
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD CreateURL(nsIURI* *aResult,
|
1998-12-16 08:40:20 +03:00
|
|
|
const nsString& aSpec,
|
1999-06-23 07:29:44 +04:00
|
|
|
const nsIURI* aContextURL = nsnull,
|
1998-12-16 08:40:20 +03:00
|
|
|
nsISupports* aContainer = nsnull,
|
1999-06-25 06:17:37 +04:00
|
|
|
nsILoadGroup* aGroup = nsnull);
|
1998-12-16 08:40:20 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHttpURLFactory:
|
|
|
|
|
|
|
|
nsHttpURLFactory(void);
|
|
|
|
virtual ~nsHttpURLFactory(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
nsHttpURLFactory::nsHttpURLFactory(void)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpURLFactory::~nsHttpURLFactory(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIProtocolURLFactoryIID, NS_IPROTOCOLURLFACTORY_IID);
|
|
|
|
NS_IMPL_ISUPPORTS(nsHttpURLFactory, kIProtocolURLFactoryIID);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
nsHttpURLFactory::CreateURL(nsIURI* *aResult,
|
1998-12-16 08:40:20 +03:00
|
|
|
const nsString& aSpec,
|
1999-06-23 07:29:44 +04:00
|
|
|
const nsIURI* aContextURL,
|
1998-12-16 08:40:20 +03:00
|
|
|
nsISupports* aContainer,
|
1999-06-25 06:17:37 +04:00
|
|
|
nsILoadGroup* aGroup)
|
1998-12-16 08:40:20 +03:00
|
|
|
{
|
|
|
|
nsHttpUrlImpl* url = new nsHttpUrlImpl(aContainer, aGroup);
|
|
|
|
if (url == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(url);
|
|
|
|
nsresult err = url->ParseURL(aSpec, aContextURL);
|
1999-03-25 03:22:56 +03:00
|
|
|
if (err != NS_OK) {
|
|
|
|
NS_RELEASE(url);
|
1998-12-16 08:40:20 +03:00
|
|
|
return err;
|
1999-03-25 03:22:56 +03:00
|
|
|
}
|
1998-12-16 08:40:20 +03:00
|
|
|
*aResult = url;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
|
|
|
|
|
|
|
// XXX temporarily, until we have pluggable protocols...
|
|
|
|
extern "C" NS_NET nsresult
|
|
|
|
NS_InitializeHttpURLFactory(nsINetService* inet)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsHttpURLFactory* urlf = new nsHttpURLFactory();
|
|
|
|
if (urlf == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
#if 0
|
|
|
|
nsINetService *inet = nsnull;
|
|
|
|
rv = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&inet);
|
|
|
|
if (rv != NS_OK) return rv;
|
|
|
|
#endif
|
|
|
|
rv = inet->RegisterProtocol(*new nsString("http"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
|
|
|
inet->RegisterProtocol(*new nsString("https"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
|
|
|
|
|
|
|
// XXX Hacks until we have real urlf objects for these...
|
1999-03-21 22:38:45 +03:00
|
|
|
inet->RegisterProtocol(*new nsString("ftp"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
1998-12-16 08:40:20 +03:00
|
|
|
inet->RegisterProtocol(*new nsString("resource"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
1999-04-02 23:05:52 +04:00
|
|
|
inet->RegisterProtocol(*new nsString("chrome"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
1998-12-16 08:40:20 +03:00
|
|
|
inet->RegisterProtocol(*new nsString("file"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
|
|
|
inet->RegisterProtocol(*new nsString("javascript"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
1999-02-03 22:36:24 +03:00
|
|
|
inet->RegisterProtocol(*new nsString("sockstub"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
|
|
|
inet->RegisterProtocol(*new nsString("about"), urlf, NULL);
|
|
|
|
if (rv != NS_OK) goto done;
|
1998-12-16 08:40:20 +03:00
|
|
|
|
|
|
|
done:
|
|
|
|
#if 0
|
|
|
|
nsServiceManager::ReleaseService(kNetServiceCID, inet);
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|