2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 DEFINE_GUID(CLSID_StartupNotifier
, 0x1f59b001,0x02c9,0x11d5,0xae,0x76,0xcc,0x92,0xf7,0xdb,0x9e,0x03);
43 DEFINE_GUID(CLSID_nsWebBrowser
, 0xf1eac761,0x87e9,0x11d3,0xaf,0x80,0x00,0xa0,0x24,0xff,0xc0,0x8c);
45 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
46 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
48 #define APPSTARTUP_TOPIC "app-startup"
50 #define PR_UINT32_MAX 0xffffffff
58 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
59 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
60 static nsresult (*NS_StringContainerInit
)(nsString
*);
61 static nsresult (*NS_StringContainerFinish
)(nsString
*);
62 static nsresult (*NS_StringSetData
)(nsString
*,const PRUnichar
*,PRUint32
);
63 static nsresult (*NS_NewLocalFile
)(const nsString
*,PRBool
,nsIFile
**);
65 static HINSTANCE hXPCOM
= NULL
;
67 static nsIServiceManager
*pServMgr
= NULL
;
68 static nsIComponentManager
*pCompMgr
= NULL
;
70 static BOOL
get_mozilla_path(PRUnichar
*gre_path
)
72 DWORD res
, type
, i
, size
= MAX_PATH
;
73 HKEY mozilla_key
, hkey
;
77 static const WCHAR wszGreKey
[] =
78 {'S','o','f','t','w','a','r','e','\\',
79 'm','o','z','i','l','l','a','.','o','r','g','\\',
82 static const WCHAR wszGreHome
[] = {'G','r','e','H','o','m','e',0};
84 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszGreKey
, &mozilla_key
);
85 if(res
!= ERROR_SUCCESS
) {
86 TRACE("Could not open key %s\n", debugstr_w(wszGreKey
));
90 for(i
=0; !ret
&& RegEnumKeyW(mozilla_key
, i
, key_name
, sizeof(key_name
)/sizeof(WCHAR
)) == ERROR_SUCCESS
; i
++) {
91 RegOpenKeyW(mozilla_key
, key_name
, &hkey
);
92 res
= RegQueryValueExW(hkey
, wszGreHome
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
93 if(res
== ERROR_SUCCESS
)
98 RegCloseKey(mozilla_key
);
102 static BOOL
get_mozctl_path(PRUnichar
*gre_path
)
105 DWORD res
, type
, size
= MAX_PATH
;
107 static const WCHAR wszMozCtlKey
[] =
108 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
109 static const WCHAR wszBinDirectoryPath
[] =
110 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
112 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMozCtlKey
, &hkey
);
113 if(res
!= ERROR_SUCCESS
) {
114 TRACE("Could not open key %s\n", debugstr_w(wszMozCtlKey
));
118 res
= RegQueryValueExW(hkey
, wszBinDirectoryPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
119 if(res
!= ERROR_SUCCESS
) {
120 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath
));
129 static BOOL
load_gecko()
132 nsIObserver
*pStartNotif
;
135 PRUnichar gre_path
[MAX_PATH
];
137 static BOOL tried_load
= FALSE
;
138 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
143 return pCompMgr
!= NULL
;
146 if(!(get_mozctl_path(gre_path
) || get_mozilla_path(gre_path
))) {
147 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
151 TRACE("found path %s\n", debugstr_w(gre_path
));
153 hXPCOM
= LoadLibraryW(strXPCOM
);
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 WCHAR path_env
[MAX_PATH
];
157 static WCHAR wszPATH
[] = {'P','A','T','H',0};
162 GetEnvironmentVariableW(wszPATH
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
163 len
= strlenW(path_env
);
164 path_env
[len
++] = ';';
165 strcpyW(path_env
+len
, gre_path
);
166 SetEnvironmentVariableW(wszPATH
, path_env
);
168 hXPCOM
= LoadLibraryW(strXPCOM
);
170 ERR("Could not load XPCOM: %ld\n", GetLastError());
175 #define NS_DLSYM(func) \
176 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
178 ERR("Could not GetProcAddress(" #func ") failed\n");
180 NS_DLSYM(NS_InitXPCOM2
)
181 NS_DLSYM(NS_ShutdownXPCOM
)
182 NS_DLSYM(NS_StringContainerInit
)
183 NS_DLSYM(NS_StringContainerFinish
)
184 NS_DLSYM(NS_StringSetData
)
185 NS_DLSYM(NS_NewLocalFile
)
189 NS_StringContainerInit(&path
);
190 NS_StringSetData(&path
, gre_path
, PR_UINT32_MAX
);
191 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
192 NS_StringContainerFinish(&path
);
193 if(NS_FAILED(nsres
)) {
194 ERR("NS_NewLocalFile failed: %08lx\n", nsres
);
199 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
200 if(NS_FAILED(nsres
)) {
201 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres
);
206 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
208 ERR("Could not get nsIComponentManager: %08lx\n", nsres
);
210 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
211 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
212 if(NS_SUCCEEDED(nsres
)) {
213 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
215 ERR("Observe failed: %08lx\n", nsres
);
217 nsIObserver_Release(pStartNotif
);
219 ERR("could not get appstartup-notifier: %08lx\n", nsres
);
230 nsIComponentManager_Release(pCompMgr
);
233 nsIServiceManager_Release(pServMgr
);
239 void HTMLDocument_NSContainer_Init(HTMLDocument
*This
)
242 nsIWebBrowserSetup
*wbsetup
;
245 This
->nscontainer
= NULL
;
250 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer
));
253 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
254 NS_WEBBROWSER_CONTRACTID
, NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
256 ERR("Creating WebBrowser failed: %08lx\n", nsres
);
258 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
259 (void**)&ret
->window
);
261 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres
);
263 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
,
264 &IID_nsIWebBrowserSetup
, (void**)&wbsetup
);
265 if(NS_SUCCEEDED(nsres
)) {
266 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, TRUE
);
268 ERR("SetProperty failed: %08lx\n", nsres
);
269 nsIWebBrowserSetup_Release(wbsetup
);
271 ERR("Could not get nsIWebBrowserSetup interface\n");
274 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
275 (void**)&ret
->navigation
);
277 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres
);
279 This
->nscontainer
= ret
;
282 void HTMLDocument_NSContainer_Destroy(HTMLDocument
*This
)
284 TRACE("(%p)\n", This
);
286 nsIWebBrowser_Release(This
->nscontainer
->webbrowser
);
287 nsIWebNavigation_Release(This
->nscontainer
->navigation
);
288 nsIBaseWindow_Release(This
->nscontainer
->window
);
290 HeapFree(GetProcessHeap(), 0, This
->nscontainer
);