From 8aeb04934122dd0d4878a537ea0bf3da481515a1 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 9 Feb 2006 12:17:08 +0100 Subject: [PATCH] mshtml: Added wrapper of nsIOService. --- dlls/mshtml/Makefile.in | 1 + dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/nsembed.c | 39 +------ dlls/mshtml/nsiface.idl | 7 +- dlls/mshtml/nsio.c | 271 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+), 38 deletions(-) create mode 100644 dlls/mshtml/nsio.c diff --git a/dlls/mshtml/Makefile.in b/dlls/mshtml/Makefile.in index 2b8e3dac1c0..d369b3be081 100644 --- a/dlls/mshtml/Makefile.in +++ b/dlls/mshtml/Makefile.in @@ -14,6 +14,7 @@ C_SRCS = \ htmldoc3.c \ main.c \ nsembed.c \ + nsio.c \ nsservice.c\ oleobj.c \ olewnd.c \ diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index cc0d4e7eca4..6640f9012a9 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -146,6 +146,7 @@ HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**); void close_gecko(void); void register_nsservice(nsIComponentRegistrar*); +void init_nsio(nsIComponentManager*,nsIComponentRegistrar*); nsIURI *get_nsIURI(LPCWSTR); diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 34f4a464763..004901ea005 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -37,7 +37,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml); #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1" #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1" -#define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1" #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1" #define APPSTARTUP_TOPIC "app-startup" @@ -67,7 +66,6 @@ static HINSTANCE hXPCOM = NULL; static nsIServiceManager *pServMgr = NULL; static nsIComponentManager *pCompMgr = NULL; -static nsIIOService *pIOService = NULL; static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0}; @@ -348,13 +346,14 @@ static BOOL load_gecko(void) ERR("could not get appstartup-notifier: %08lx\n", nsres); } + set_profile(); + if(registrar) { register_nsservice(registrar); + init_nsio(pCompMgr, registrar); nsIComponentRegistrar_Release(registrar); } - set_profile(); - return TRUE; } @@ -396,38 +395,6 @@ void close_gecko() FreeLibrary(hXPCOM); } -nsIURI *get_nsIURI(LPCWSTR url) -{ - nsIURI *ret; - nsACString *acstr; - nsresult nsres; - char *urla; - int len; - - if(!pIOService) { - nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_IOSERVICE_CONTRACTID, - &IID_nsIIOService, (void**)&pIOService); - if(NS_FAILED(nsres)) - ERR("Failed to create nsIOService: %08lx\n", nsres); - } - - 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(pIOService, acstr, NULL, NULL, &ret); - if(NS_FAILED(nsres)) - FIXME("NewURI failed: %08lx\n", nsres); - - nsACString_Destroy(acstr); - HeapFree(GetProcessHeap(), 0, urla); - - return ret; -} - /********************************************************** * nsIWebBrowserChrome interface */ diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl index 0567c6a1a1f..d97c3bd8899 100644 --- a/dlls/mshtml/nsiface.idl +++ b/dlls/mshtml/nsiface.idl @@ -333,13 +333,16 @@ interface nsIIOService : nsISupports { nsresult GetProtocolHandler(const char *aScheme, nsIProtocolHandler **_retval); nsresult GetProtocolFlags(const char *aScheme, PRUint32 *_retval); - nsresult NewURI(const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval); + nsresult NewURI(const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, + nsIURI **_retval); nsresult NewFileURI(nsIFile *aFile, nsIURI **_retval); nsresult NewChannelFromURI(nsIURI *aURI, nsIChannel **_retval); - nsresult NewChannel(const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval); + nsresult NewChannel(const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, + nsIChannel **_retval); nsresult GetOffline(PRBool *aOffline); nsresult SetOffline(PRBool aOffline); nsresult AllowPort(PRInt32 aPort, const char *aScheme, PRBool *_retval); + nsresult ExtractScheme(const nsACString *urlString, nsACString * _retval); } [ diff --git a/dlls/mshtml/nsio.c b/dlls/mshtml/nsio.c new file mode 100644 index 00000000000..e5535036c26 --- /dev/null +++ b/dlls/mshtml/nsio.c @@ -0,0 +1,271 @@ +/* + * 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 + +#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; +} -- 2.11.4.GIT