272 lines
8.3 KiB
C
272 lines
8.3 KiB
C
![]() |
/*
|
||
|
* Copyright 2006 Jacek Caban for CodeWeavers
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
*/
|
||
|
|
||
|
#include "config.h"
|
||
|
|
||
|
#include <stdarg.h>
|
||
|
|
||
|
#define COBJMACROS
|
||
|
|
||
|
#include "windef.h"
|
||
|
#include "winbase.h"
|
||
|
#include "winuser.h"
|
||
|
#include "ole2.h"
|
||
|
|
||
|
#include "wine/debug.h"
|
||
|
#include "wine/unicode.h"
|
||
|
|
||
|
#include "mshtml_private.h"
|
||
|
|
||
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
||
|
|
||
|
#define NS_IOSERVICE_CLASSNAME "nsIOService"
|
||
|
#define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
|
||
|
|
||
|
static IID NS_IOSERVICE_CID =
|
||
|
{0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
|
||
|
|
||
|
static nsIIOService *nsio = NULL;
|
||
|
|
||
|
static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
|
||
|
nsQIResult result)
|
||
|
{
|
||
|
*result = NULL;
|
||
|
|
||
|
if(IsEqualGUID(&IID_nsISupports, riid)) {
|
||
|
TRACE("(IID_nsISupports %p)\n", result);
|
||
|
*result = iface;
|
||
|
}else if(IsEqualGUID(&IID_nsIIOService, riid)) {
|
||
|
TRACE("(IID_nsIIOService %p)\n", result);
|
||
|
*result = iface;
|
||
|
}
|
||
|
|
||
|
if(*result) {
|
||
|
nsIIOService_AddRef(iface);
|
||
|
return S_OK;
|
||
|
}
|
||
|
|
||
|
WARN("(%s %p)\n", debugstr_guid(riid), result);
|
||
|
return NS_NOINTERFACE;
|
||
|
}
|
||
|
|
||
|
static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
|
||
|
{
|
||
|
return 2;
|
||
|
}
|
||
|
|
||
|
static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
|
||
|
nsIProtocolHandler **_retval)
|
||
|
{
|
||
|
TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
|
||
|
return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
|
||
|
PRUint32 *_retval)
|
||
|
{
|
||
|
TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
|
||
|
return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
|
||
|
const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
|
||
|
{
|
||
|
TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
|
||
|
return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
|
||
|
nsIURI **_retval)
|
||
|
{
|
||
|
TRACE("(%p %p)\n", aFile, _retval);
|
||
|
return nsIIOService_NewFileURI(nsio, aFile, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
|
||
|
nsIChannel **_retval)
|
||
|
{
|
||
|
TRACE("(%p %p)\n", aURI, _retval);
|
||
|
return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
|
||
|
const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
|
||
|
{
|
||
|
TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
|
||
|
return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
|
||
|
{
|
||
|
TRACE("(%p)\n", aOffline);
|
||
|
return nsIIOService_GetOffline(nsio, aOffline);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
|
||
|
{
|
||
|
TRACE("(%x)\n", aOffline);
|
||
|
return nsIIOService_SetOffline(nsio, aOffline);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
|
||
|
const char *aScheme, PRBool *_retval)
|
||
|
{
|
||
|
TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
|
||
|
return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
|
||
|
nsACString * _retval)
|
||
|
{
|
||
|
TRACE("(%p %p)\n", urlString, _retval);
|
||
|
return nsIIOService_ExtractScheme(nsio, urlString, _retval);
|
||
|
}
|
||
|
|
||
|
static const nsIIOServiceVtbl nsIOServiceVtbl = {
|
||
|
nsIOService_QueryInterface,
|
||
|
nsIOService_AddRef,
|
||
|
nsIOService_Release,
|
||
|
nsIOService_GetProtocolHandler,
|
||
|
nsIOService_GetProtocolFlags,
|
||
|
nsIOService_NewURI,
|
||
|
nsIOService_NewFileURI,
|
||
|
nsIOService_NewChannelFromURI,
|
||
|
nsIOService_NewChannel,
|
||
|
nsIOService_GetOffline,
|
||
|
nsIOService_SetOffline,
|
||
|
nsIOService_AllowPort,
|
||
|
nsIOService_ExtractScheme
|
||
|
};
|
||
|
|
||
|
static nsIIOService nsIOService = { &nsIOServiceVtbl };
|
||
|
|
||
|
static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
|
||
|
nsQIResult result)
|
||
|
{
|
||
|
*result = NULL;
|
||
|
|
||
|
if(IsEqualGUID(&IID_nsISupports, riid)) {
|
||
|
TRACE("(IID_nsISupoprts %p)\n", result);
|
||
|
*result = iface;
|
||
|
}else if(IsEqualGUID(&IID_nsIFactory, riid)) {
|
||
|
TRACE("(IID_nsIFactory %p)\n", result);
|
||
|
*result = iface;
|
||
|
}
|
||
|
|
||
|
if(*result) {
|
||
|
nsIFactory_AddRef(iface);
|
||
|
return NS_OK;
|
||
|
}
|
||
|
|
||
|
WARN("(%s %p)\n", debugstr_guid(riid), result);
|
||
|
return NS_NOINTERFACE;
|
||
|
}
|
||
|
|
||
|
static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
|
||
|
{
|
||
|
return 2;
|
||
|
}
|
||
|
|
||
|
static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
|
||
|
nsISupports *aOuter, const nsIID *iid, void **result)
|
||
|
{
|
||
|
return nsIIOService_QueryInterface(&nsIOService, iid, result);
|
||
|
}
|
||
|
|
||
|
static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
|
||
|
{
|
||
|
WARN("(%x)\n", lock);
|
||
|
return NS_OK;
|
||
|
}
|
||
|
|
||
|
static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
|
||
|
nsIOServiceFactory_QueryInterface,
|
||
|
nsIOServiceFactory_AddRef,
|
||
|
nsIOServiceFactory_Release,
|
||
|
nsIOServiceFactory_CreateInstance,
|
||
|
nsIOServiceFactory_LockFactory
|
||
|
};
|
||
|
|
||
|
static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
|
||
|
|
||
|
void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
|
||
|
{
|
||
|
nsIFactory *old_factory = NULL;
|
||
|
nsresult nsres;
|
||
|
|
||
|
nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
|
||
|
&IID_nsIFactory, (void**)&old_factory);
|
||
|
if(NS_FAILED(nsres)) {
|
||
|
ERR("Could not get factory: %08lx\n", nsres);
|
||
|
nsIFactory_Release(old_factory);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
|
||
|
if(NS_FAILED(nsres)) {
|
||
|
ERR("Couldn not create nsIOService instance %08lx\n", nsres);
|
||
|
nsIFactory_Release(old_factory);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
|
||
|
nsIFactory_Release(old_factory);
|
||
|
if(NS_FAILED(nsres))
|
||
|
ERR("UnregisterFactory failed: %08lx\n", nsres);
|
||
|
|
||
|
nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
|
||
|
NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
|
||
|
if(NS_FAILED(nsres))
|
||
|
ERR("RegisterFactory failed: %08lx\n", nsres);
|
||
|
}
|
||
|
|
||
|
nsIURI *get_nsIURI(LPCWSTR url)
|
||
|
{
|
||
|
nsIURI *ret;
|
||
|
nsACString *acstr;
|
||
|
nsresult nsres;
|
||
|
char *urla;
|
||
|
int len;
|
||
|
|
||
|
len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
|
||
|
urla = HeapAlloc(GetProcessHeap(), 0, len);
|
||
|
WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
|
||
|
|
||
|
acstr = nsACString_Create();
|
||
|
nsACString_SetData(acstr, urla);
|
||
|
|
||
|
nsres = nsIIOService_NewURI(nsio, acstr, NULL, NULL, &ret);
|
||
|
if(NS_FAILED(nsres))
|
||
|
FIXME("NewURI failed: %08lx\n", nsres);
|
||
|
|
||
|
nsACString_Destroy(acstr);
|
||
|
HeapFree(GetProcessHeap(), 0, urla);
|
||
|
|
||
|
return ret;
|
||
|
}
|