gdi32: Simplify the code a little by using a separate variable for the return value.
[wine/multimedia.git] / dlls / mshtml / nsembed.c
blob33d34b9a4f638e46d4350c6c6f18484ac52679aa
1 /*
2 * Copyright 2005-2007 Jacek Caban for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <assert.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "ole2.h"
31 #include "shlobj.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
37 #include "binding.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 WINE_DECLARE_DEBUG_CHANNEL(gecko);
42 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
43 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
44 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
45 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
46 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
47 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define PR_UINT32_MAX 0xffffffff
52 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
53 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
55 static nsresult (CDECL *NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
56 static nsresult (CDECL *NS_ShutdownXPCOM)(nsIServiceManager*);
57 static nsresult (CDECL *NS_GetComponentRegistrar)(nsIComponentRegistrar**);
58 static nsresult (CDECL *NS_StringContainerInit2)(nsStringContainer*,const PRUnichar*,PRUint32,PRUint32);
59 static nsresult (CDECL *NS_CStringContainerInit2)(nsCStringContainer*,const char*,PRUint32,PRUint32);
60 static nsresult (CDECL *NS_StringContainerFinish)(nsStringContainer*);
61 static nsresult (CDECL *NS_CStringContainerFinish)(nsCStringContainer*);
62 static nsresult (CDECL *NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
63 static nsresult (CDECL *NS_CStringSetData)(nsACString*,const char*,PRUint32);
64 static nsresult (CDECL *NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
65 static PRUint32 (CDECL *NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
66 static PRUint32 (CDECL *NS_CStringGetData)(const nsACString*,const char**,PRBool*);
68 static HINSTANCE xul_handle = NULL;
70 static nsIServiceManager *pServMgr = NULL;
71 static nsIComponentManager *pCompMgr = NULL;
72 static nsIMemory *nsmem = NULL;
73 static nsIFile *profile_directory;
75 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
77 static ATOM nscontainer_class;
78 static WCHAR gecko_path[MAX_PATH];
79 static unsigned gecko_path_len;
81 static nsresult NSAPI nsDirectoryServiceProvider_QueryInterface(nsIDirectoryServiceProvider *iface,
82 nsIIDRef riid, void **result)
84 if(IsEqualGUID(&IID_nsISupports, riid)) {
85 TRACE("(IID_nsISupports %p)\n", result);
86 *result = iface;
87 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider, riid)) {
88 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result);
89 *result = iface;
90 }else {
91 WARN("(%s %p)\n", debugstr_guid(riid), result);
92 *result = NULL;
93 return NS_NOINTERFACE;
96 nsISupports_AddRef((nsISupports*)*result);
97 return NS_OK;
100 static nsrefcnt NSAPI nsDirectoryServiceProvider_AddRef(nsIDirectoryServiceProvider *iface)
102 return 2;
105 static nsrefcnt NSAPI nsDirectoryServiceProvider_Release(nsIDirectoryServiceProvider *iface)
107 return 1;
110 static nsresult create_profile_directory(void)
112 static const WCHAR wine_geckoW[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
114 WCHAR path[MAX_PATH + sizeof(wine_geckoW)/sizeof(WCHAR)];
115 nsAString str;
116 PRBool exists;
117 nsresult nsres;
118 HRESULT hres;
120 hres = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_DEFAULT, path);
121 if(FAILED(hres)) {
122 ERR("SHGetFolderPath failed: %08x\n", hres);
123 return NS_ERROR_FAILURE;
126 strcatW(path, wine_geckoW);
127 nsAString_InitDepend(&str, path);
128 nsres = NS_NewLocalFile(&str, FALSE, &profile_directory);
129 nsAString_Finish(&str);
130 if(NS_FAILED(nsres)) {
131 ERR("NS_NewLocalFile failed: %08x\n", nsres);
132 return nsres;
135 nsres = nsIFile_Exists(profile_directory, &exists);
136 if(NS_FAILED(nsres)) {
137 ERR("Exists failed: %08x\n", nsres);
138 return nsres;
141 if(!exists) {
142 nsres = nsIFile_Create(profile_directory, 1, 0700);
143 if(NS_FAILED(nsres))
144 ERR("Create failed: %08x\n", nsres);
147 return nsres;
150 static nsresult NSAPI nsDirectoryServiceProvider_GetFile(nsIDirectoryServiceProvider *iface,
151 const char *prop, PRBool *persistent, nsIFile **_retval)
153 TRACE("(%s %p %p)\n", debugstr_a(prop), persistent, _retval);
155 if(!strcmp(prop, "ProfD")) {
156 if(!profile_directory) {
157 nsresult nsres;
159 nsres = create_profile_directory();
160 if(NS_FAILED(nsres))
161 return nsres;
164 return nsIFile_Clone(profile_directory, _retval);
167 return NS_ERROR_FAILURE;
170 static const nsIDirectoryServiceProviderVtbl nsDirectoryServiceProviderVtbl = {
171 nsDirectoryServiceProvider_QueryInterface,
172 nsDirectoryServiceProvider_AddRef,
173 nsDirectoryServiceProvider_Release,
174 nsDirectoryServiceProvider_GetFile
177 static nsIDirectoryServiceProvider nsDirectoryServiceProvider =
178 { &nsDirectoryServiceProviderVtbl };
180 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
182 NSContainer *This;
183 nsresult nsres;
185 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
187 if(msg == WM_CREATE) {
188 This = *(NSContainer**)lParam;
189 SetPropW(hwnd, wszTHIS, This);
190 }else {
191 This = GetPropW(hwnd, wszTHIS);
194 switch(msg) {
195 case WM_SIZE:
196 TRACE("(%p)->(WM_SIZE)\n", This);
198 nsres = nsIBaseWindow_SetSize(This->window,
199 LOWORD(lParam), HIWORD(lParam), TRUE);
200 if(NS_FAILED(nsres))
201 WARN("SetSize failed: %08x\n", nsres);
202 break;
204 case WM_PARENTNOTIFY:
205 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam);
207 switch(wParam) {
208 case WM_LBUTTONDOWN:
209 case WM_RBUTTONDOWN:
210 nsIWebBrowserFocus_Activate(This->focus);
214 return DefWindowProcW(hwnd, msg, wParam, lParam);
218 static void register_nscontainer_class(void)
220 static WNDCLASSEXW wndclass = {
221 sizeof(WNDCLASSEXW),
222 CS_DBLCLKS,
223 nsembed_proc,
224 0, 0, NULL, NULL, NULL, NULL, NULL,
225 wszNsContainer,
226 NULL,
228 wndclass.hInstance = hInst;
229 nscontainer_class = RegisterClassExW(&wndclass);
232 static BOOL install_wine_gecko(BOOL silent)
234 PROCESS_INFORMATION pi;
235 STARTUPINFOW si;
236 WCHAR app[MAX_PATH];
237 WCHAR *args;
238 LONG len;
239 BOOL ret;
241 static const WCHAR controlW[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
242 static const WCHAR argsW[] =
243 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
245 len = GetSystemDirectoryW(app, MAX_PATH-sizeof(controlW)/sizeof(WCHAR));
246 memcpy(app+len, controlW, sizeof(controlW));
248 args = heap_alloc(len*sizeof(WCHAR) + sizeof(controlW) + sizeof(argsW));
249 if(!args)
250 return FALSE;
252 memcpy(args, app, len*sizeof(WCHAR) + sizeof(controlW));
253 memcpy(args + len + sizeof(controlW)/sizeof(WCHAR)-1, argsW, sizeof(argsW));
255 TRACE("starting %s\n", debugstr_w(args));
257 memset(&si, 0, sizeof(si));
258 si.cb = sizeof(si);
259 ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
260 heap_free(args);
261 if (ret) {
262 CloseHandle(pi.hThread);
263 WaitForSingleObject(pi.hProcess, INFINITE);
264 CloseHandle(pi.hProcess);
267 return ret;
270 static void set_environment(LPCWSTR gre_path)
272 WCHAR path_env[MAX_PATH], buf[20];
273 int len, debug_level = 0;
275 static const WCHAR pathW[] = {'P','A','T','H',0};
276 static const WCHAR warnW[] = {'w','a','r','n',0};
277 static const WCHAR xpcom_debug_breakW[] =
278 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
279 static const WCHAR nspr_log_modulesW[] =
280 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
281 static const WCHAR debug_formatW[] = {'a','l','l',':','%','d',0};
282 static const WCHAR moz_plugin_pathW[] = {'M','O','Z','_','P','L','U','G','I','N','_','P','A','T','H',0};
283 static const WCHAR gecko_pluginW[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
285 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
286 GetEnvironmentVariableW(pathW, path_env, sizeof(path_env)/sizeof(WCHAR));
287 len = strlenW(path_env);
288 path_env[len++] = ';';
289 strcpyW(path_env+len, gre_path);
290 SetEnvironmentVariableW(pathW, path_env);
292 SetEnvironmentVariableW(xpcom_debug_breakW, warnW);
294 if(TRACE_ON(gecko))
295 debug_level = 5;
296 else if(WARN_ON(gecko))
297 debug_level = 3;
298 else if(ERR_ON(gecko))
299 debug_level = 2;
301 sprintfW(buf, debug_formatW, debug_level);
302 SetEnvironmentVariableW(nspr_log_modulesW, buf);
304 len = GetSystemDirectoryW(path_env, (sizeof(path_env)-sizeof(gecko_pluginW))/sizeof(WCHAR)+1);
305 if(len) {
306 strcpyW(path_env+len, gecko_pluginW);
307 SetEnvironmentVariableW(moz_plugin_pathW, path_env);
311 static BOOL load_xul(const PRUnichar *gre_path)
313 static const WCHAR xul_dllW[] = {'\\','x','u','l','.','d','l','l',0};
314 WCHAR file_name[MAX_PATH];
316 strcpyW(file_name, gre_path);
317 strcatW(file_name, xul_dllW);
319 TRACE("(%s)\n", debugstr_w(file_name));
321 set_environment(gre_path);
323 xul_handle = LoadLibraryExW(file_name, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
324 if(!xul_handle) {
325 WARN("Could not load XUL: %d\n", GetLastError());
326 return FALSE;
329 #define NS_DLSYM(func) \
330 func = (void *)GetProcAddress(xul_handle, #func "_P"); \
331 if(!func) \
332 ERR("Could not GetProcAddress(" #func ") failed\n")
334 NS_DLSYM(NS_InitXPCOM2);
335 NS_DLSYM(NS_ShutdownXPCOM);
336 NS_DLSYM(NS_GetComponentRegistrar);
337 NS_DLSYM(NS_StringContainerInit2);
338 NS_DLSYM(NS_CStringContainerInit2);
339 NS_DLSYM(NS_StringContainerFinish);
340 NS_DLSYM(NS_CStringContainerFinish);
341 NS_DLSYM(NS_StringSetData);
342 NS_DLSYM(NS_CStringSetData);
343 NS_DLSYM(NS_NewLocalFile);
344 NS_DLSYM(NS_StringGetData);
345 NS_DLSYM(NS_CStringGetData);
347 #undef NS_DLSYM
349 return TRUE;
352 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
354 WCHAR file_name[MAX_PATH];
355 char version[128];
356 DWORD read=0;
357 HANDLE hfile;
359 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
361 strcpyW(file_name, gre_path);
362 strcatW(file_name, wszVersion);
364 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
365 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
366 if(hfile == INVALID_HANDLE_VALUE) {
367 ERR("Could not open VERSION file\n");
368 return FALSE;
371 ReadFile(hfile, version, sizeof(version), &read, NULL);
372 version[read] = 0;
373 CloseHandle(hfile);
375 TRACE("%s\n", debugstr_a(version));
377 if(strcmp(version, version_string)) {
378 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
379 debugstr_a(version_string));
380 return FALSE;
383 return TRUE;
386 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
387 const char *version, const char *version_string)
389 DWORD res, type, size = MAX_PATH;
390 HKEY hkey = mshtml_key;
392 static const WCHAR wszGeckoPath[] =
393 {'G','e','c','k','o','P','a','t','h',0};
395 if(version) {
396 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
397 res = RegOpenKeyA(mshtml_key, version, &hkey);
398 if(res != ERROR_SUCCESS)
399 return FALSE;
402 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
403 if(hkey != mshtml_key)
404 RegCloseKey(hkey);
405 if(res != ERROR_SUCCESS || type != REG_SZ)
406 return FALSE;
408 if(!check_version(gre_path, version_string))
409 return FALSE;
411 return load_xul(gre_path);
414 static BOOL load_wine_gecko(PRUnichar *gre_path)
416 HKEY hkey;
417 DWORD res;
418 BOOL ret;
420 static const WCHAR wszMshtmlKey[] = {
421 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
422 '\\','M','S','H','T','M','L',0};
424 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
425 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMshtmlKey, &hkey);
426 if(res != ERROR_SUCCESS)
427 return FALSE;
429 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING);
431 RegCloseKey(hkey);
432 return ret;
435 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
437 nsresult nsres;
439 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
440 if(NS_FAILED(nsres))
441 ERR("Could not set pref %s\n", debugstr_a(pref_name));
444 static void set_int_pref(nsIPrefBranch *pref, const char *pref_name, int val)
446 nsresult nsres;
448 nsres = nsIPrefBranch_SetIntPref(pref, pref_name, val);
449 if(NS_FAILED(nsres))
450 ERR("Could not set pref %s\n", debugstr_a(pref_name));
453 static void set_string_pref(nsIPrefBranch *pref, const char *pref_name, const char *val)
455 nsresult nsres;
457 nsres = nsIPrefBranch_SetCharPref(pref, pref_name, val);
458 if(NS_FAILED(nsres))
459 ERR("Could not set pref %s\n", debugstr_a(pref_name));
462 static void set_lang(nsIPrefBranch *pref)
464 char langs[100];
465 DWORD res, size, type;
466 HKEY hkey;
468 static const WCHAR international_keyW[] =
469 {'S','o','f','t','w','a','r','e',
470 '\\','M','i','c','r','o','s','o','f','t',
471 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
472 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
474 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
475 if(res != ERROR_SUCCESS)
476 return;
478 size = sizeof(langs);
479 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
480 RegCloseKey(hkey);
481 if(res != ERROR_SUCCESS || type != REG_SZ)
482 return;
484 TRACE("Setting lang %s\n", debugstr_a(langs));
486 set_string_pref(pref, "intl.accept_languages", langs);
489 static void set_proxy(nsIPrefBranch *pref)
491 char proxy[512];
492 char * proxy_port;
493 int proxy_port_num;
494 DWORD enabled = 0, res, size, type;
495 HKEY hkey;
497 static const WCHAR proxy_keyW[] =
498 {'S','o','f','t','w','a','r','e',
499 '\\','M','i','c','r','o','s','o','f','t',
500 '\\','W','i','n','d','o','w','s',
501 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
502 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
504 res = RegOpenKeyW(HKEY_CURRENT_USER, proxy_keyW, &hkey);
505 if(res != ERROR_SUCCESS)
506 return;
508 size = sizeof(enabled);
509 res = RegQueryValueExA(hkey, "ProxyEnable", 0, &type, (LPBYTE)&enabled, &size);
510 if(res != ERROR_SUCCESS || type != REG_DWORD || enabled == 0)
512 RegCloseKey(hkey);
513 return;
516 size = sizeof(proxy);
517 res = RegQueryValueExA(hkey, "ProxyServer", 0, &type, (LPBYTE)proxy, &size);
518 RegCloseKey(hkey);
519 if(res != ERROR_SUCCESS || type != REG_SZ)
520 return;
522 proxy_port = strchr(proxy, ':');
523 if (!proxy_port)
524 return;
526 *proxy_port = 0;
527 proxy_port_num = atoi(proxy_port + 1);
528 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy), proxy_port_num);
530 set_string_pref(pref, "network.proxy.http", proxy);
531 set_string_pref(pref, "network.proxy.ssl", proxy);
533 set_int_pref(pref, "network.proxy.type", 1);
534 set_int_pref(pref, "network.proxy.http_port", proxy_port_num);
535 set_int_pref(pref, "network.proxy.ssl_port", proxy_port_num);
538 static void set_preferences(void)
540 nsIPrefBranch *pref;
541 nsresult nsres;
543 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
544 &IID_nsIPrefBranch, (void**)&pref);
545 if(NS_FAILED(nsres)) {
546 ERR("Could not get preference service: %08x\n", nsres);
547 return;
550 set_lang(pref);
551 set_proxy(pref);
552 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
553 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
554 set_int_pref(pref, "layout.spellcheckDefault", 0);
556 nsIPrefBranch_Release(pref);
559 static BOOL init_xpcom(const PRUnichar *gre_path)
561 nsIComponentRegistrar *registrar = NULL;
562 nsAString path;
563 nsIFile *gre_dir;
564 WCHAR *ptr;
565 nsresult nsres;
567 nsAString_InitDepend(&path, gre_path);
568 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
569 nsAString_Finish(&path);
570 if(NS_FAILED(nsres)) {
571 ERR("NS_NewLocalFile failed: %08x\n", nsres);
572 FreeLibrary(xul_handle);
573 return FALSE;
576 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, &nsDirectoryServiceProvider);
577 if(NS_FAILED(nsres)) {
578 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
579 FreeLibrary(xul_handle);
580 return FALSE;
583 strcpyW(gecko_path, gre_path);
584 for(ptr = gecko_path; *ptr; ptr++) {
585 if(*ptr == '\\')
586 *ptr = '/';
588 gecko_path_len = ptr-gecko_path;
590 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
591 if(NS_FAILED(nsres))
592 ERR("Could not get nsIComponentManager: %08x\n", nsres);
594 nsres = NS_GetComponentRegistrar(&registrar);
595 if(NS_SUCCEEDED(nsres))
596 init_nsio(pCompMgr, registrar);
597 else
598 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
600 init_mutation(pCompMgr);
601 set_preferences();
603 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
604 NULL, &IID_nsIMemory, (void**)&nsmem);
605 if(NS_FAILED(nsres))
606 ERR("Could not get nsIMemory: %08x\n", nsres);
608 if(registrar) {
609 register_nsservice(registrar, pServMgr);
610 nsIComponentRegistrar_Release(registrar);
613 return TRUE;
616 static CRITICAL_SECTION cs_load_gecko;
617 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
619 0, 0, &cs_load_gecko,
620 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
621 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
623 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
625 BOOL load_gecko(BOOL silent)
627 PRUnichar gre_path[MAX_PATH];
628 BOOL ret = FALSE;
630 static DWORD loading_thread;
632 TRACE("()\n");
634 /* load_gecko may be called recursively */
635 if(loading_thread == GetCurrentThreadId())
636 return pCompMgr != NULL;
638 EnterCriticalSection(&cs_load_gecko);
640 if(!loading_thread) {
641 loading_thread = GetCurrentThreadId();
643 if(load_wine_gecko(gre_path)
644 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
645 ret = init_xpcom(gre_path);
646 else
647 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
648 }else {
649 ret = pCompMgr != NULL;
652 LeaveCriticalSection(&cs_load_gecko);
654 return ret;
657 void *nsalloc(size_t size)
659 return nsIMemory_Alloc(nsmem, size);
662 void nsfree(void *mem)
664 nsIMemory_Free(nsmem, mem);
667 static BOOL nsACString_Init(nsACString *str, const char *data)
669 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
673 * Initializes nsACString with data owned by caller.
674 * Caller must ensure that data is valid during lifetime of string object.
676 void nsACString_InitDepend(nsACString *str, const char *data)
678 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
681 void nsACString_SetData(nsACString *str, const char *data)
683 NS_CStringSetData(str, data, PR_UINT32_MAX);
686 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
688 return NS_CStringGetData(str, data, NULL);
691 void nsACString_Finish(nsACString *str)
693 NS_CStringContainerFinish(str);
696 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
698 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
702 * Initializes nsAString with data owned by caller.
703 * Caller must ensure that data is valid during lifetime of string object.
705 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
707 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
710 void nsAString_SetData(nsAString *str, const PRUnichar *data)
712 NS_StringSetData(str, data, PR_UINT32_MAX);
715 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
717 return NS_StringGetData(str, data, NULL);
720 void nsAString_Finish(nsAString *str)
722 NS_StringContainerFinish(str);
725 HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
727 const PRUnichar *str;
729 if(NS_FAILED(nsres)) {
730 ERR("failed: %08x\n", nsres);
731 nsAString_Finish(nsstr);
732 return E_FAIL;
735 nsAString_GetData(nsstr, &str);
736 TRACE("ret %s\n", debugstr_w(str));
737 if(*str) {
738 *p = SysAllocString(str);
739 if(!*p)
740 return E_OUTOFMEMORY;
741 }else {
742 *p = NULL;
745 nsAString_Finish(nsstr);
746 return S_OK;
749 nsICommandParams *create_nscommand_params(void)
751 nsICommandParams *ret = NULL;
752 nsresult nsres;
754 if(!pCompMgr)
755 return NULL;
757 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
758 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
759 (void**)&ret);
760 if(NS_FAILED(nsres))
761 ERR("Could not get nsICommandParams\n");
763 return ret;
766 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
768 nsIInterfaceRequestor *iface_req;
769 nsresult nsres;
771 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
772 if(NS_FAILED(nsres))
773 return nsres;
775 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
776 nsIInterfaceRequestor_Release(iface_req);
778 return nsres;
781 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
783 nsIDOMNodeList *node_list = NULL;
784 PRBool has_children = FALSE;
785 nsIContent *nscontent;
786 PRUint16 type;
787 nsresult nsres;
789 nsIDOMNode_HasChildNodes(nsnode, &has_children);
791 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
792 if(NS_FAILED(nsres)) {
793 ERR("GetType failed: %08x\n", nsres);
794 return E_FAIL;
797 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
798 if(NS_FAILED(nsres)) {
799 ERR("Could not get nsIDontent interface: %08x\n", nsres);
800 return E_FAIL;
803 switch(type) {
804 case ELEMENT_NODE:
805 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
806 break;
807 case TEXT_NODE:
808 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
809 break;
810 case COMMENT_NODE:
811 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
812 break;
813 case DOCUMENT_NODE: {
814 nsIDocument *nsdoc;
815 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
816 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
817 nsIDocument_Release(nsdoc);
818 break;
820 case DOCUMENT_TYPE_NODE:
821 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
822 break;
823 case DOCUMENT_FRAGMENT_NODE:
824 break;
825 default:
826 FIXME("Unhandled type %u\n", type);
829 if(has_children) {
830 PRUint32 child_cnt, i;
831 nsIDOMNode *child_node;
833 nsIDOMNode_GetChildNodes(nsnode, &node_list);
834 nsIDOMNodeList_GetLength(node_list, &child_cnt);
836 for(i=0; i<child_cnt; i++) {
837 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
838 if(NS_SUCCEEDED(nsres)) {
839 nsnode_to_nsstring_rec(serializer, child_node, str);
840 nsIDOMNode_Release(child_node);
841 }else {
842 ERR("Item failed: %08x\n", nsres);
846 nsIDOMNodeList_Release(node_list);
849 if(type == ELEMENT_NODE)
850 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
852 nsIContent_Release(nscontent);
853 return S_OK;
856 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
858 nsIContentSerializer *serializer;
859 nsresult nsres;
860 HRESULT hres;
862 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
863 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
864 (void**)&serializer);
865 if(NS_FAILED(nsres)) {
866 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
867 return E_FAIL;
870 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
871 if(NS_FAILED(nsres))
872 ERR("Init failed: %08x\n", nsres);
874 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
875 if(SUCCEEDED(hres)) {
876 nsres = nsIContentSerializer_Flush(serializer, str);
877 if(NS_FAILED(nsres))
878 ERR("Flush failed: %08x\n", nsres);
881 nsIContentSerializer_Release(serializer);
882 return hres;
885 void get_editor_controller(NSContainer *This)
887 nsIEditingSession *editing_session = NULL;
888 nsIControllerContext *ctrlctx;
889 nsresult nsres;
891 if(This->editor) {
892 nsIEditor_Release(This->editor);
893 This->editor = NULL;
896 if(This->editor_controller) {
897 nsIController_Release(This->editor_controller);
898 This->editor_controller = NULL;
901 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
902 (void**)&editing_session);
903 if(NS_FAILED(nsres)) {
904 ERR("Could not get nsIEditingSession: %08x\n", nsres);
905 return;
908 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
909 This->doc->basedoc.window->nswindow, &This->editor);
910 nsIEditingSession_Release(editing_session);
911 if(NS_FAILED(nsres)) {
912 ERR("Could not get editor: %08x\n", nsres);
913 return;
916 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
917 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
918 if(NS_SUCCEEDED(nsres)) {
919 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
920 if(NS_FAILED(nsres))
921 ERR("SetCommandContext failed: %08x\n", nsres);
922 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
923 (void**)&This->editor_controller);
924 nsIControllerContext_Release(ctrlctx);
925 if(NS_FAILED(nsres))
926 ERR("Could not get nsIController interface: %08x\n", nsres);
927 }else {
928 ERR("Could not create edit controller: %08x\n", nsres);
932 void close_gecko(void)
934 TRACE("()\n");
936 release_nsio();
937 init_mutation(NULL);
939 if(profile_directory) {
940 nsIFile_Release(profile_directory);
941 profile_directory = NULL;
944 if(pCompMgr)
945 nsIComponentManager_Release(pCompMgr);
947 if(pServMgr)
948 nsIServiceManager_Release(pServMgr);
950 if(nsmem)
951 nsIMemory_Release(nsmem);
953 /* Gecko doesn't really support being unloaded */
954 /* if (hXPCOM) FreeLibrary(hXPCOM); */
957 BOOL is_gecko_path(const char *path)
959 WCHAR *buf, *ptr;
960 BOOL ret;
962 buf = heap_strdupAtoW(path);
963 if(strlenW(buf) < gecko_path_len)
964 return FALSE;
966 buf[gecko_path_len] = 0;
967 for(ptr = buf; *ptr; ptr++) {
968 if(*ptr == '\\')
969 *ptr = '/';
972 ret = !strcmpiW(buf, gecko_path);
973 heap_free(buf);
974 return ret;
977 struct nsWeakReference {
978 nsIWeakReference nsIWeakReference_iface;
980 LONG ref;
982 NSContainer *nscontainer;
985 static inline nsWeakReference *impl_from_nsIWeakReference(nsIWeakReference *iface)
987 return CONTAINING_RECORD(iface, nsWeakReference, nsIWeakReference_iface);
990 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
991 nsIIDRef riid, void **result)
993 nsWeakReference *This = impl_from_nsIWeakReference(iface);
995 if(IsEqualGUID(&IID_nsISupports, riid)) {
996 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
997 *result = &This->nsIWeakReference_iface;
998 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
999 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
1000 *result = &This->nsIWeakReference_iface;
1001 }else {
1002 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1003 *result = NULL;
1004 return NS_NOINTERFACE;
1007 nsISupports_AddRef((nsISupports*)*result);
1008 return NS_OK;
1011 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1013 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1014 LONG ref = InterlockedIncrement(&This->ref);
1016 TRACE("(%p) ref=%d\n", This, ref);
1018 return ref;
1021 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1023 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1024 LONG ref = InterlockedIncrement(&This->ref);
1026 TRACE("(%p) ref=%d\n", This, ref);
1028 if(!ref) {
1029 assert(!This->nscontainer);
1030 heap_free(This);
1033 return ref;
1036 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1037 const nsIID *riid, void **result)
1039 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1041 if(!This->nscontainer)
1042 return NS_ERROR_NULL_POINTER;
1044 return nsIWebBrowserChrome_QueryInterface(&This->nscontainer->nsIWebBrowserChrome_iface, riid, result);
1047 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1048 nsWeakReference_QueryInterface,
1049 nsWeakReference_AddRef,
1050 nsWeakReference_Release,
1051 nsWeakReference_QueryReferent
1054 /**********************************************************
1055 * nsIWebBrowserChrome interface
1058 static inline NSContainer *impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome *iface)
1060 return CONTAINING_RECORD(iface, NSContainer, nsIWebBrowserChrome_iface);
1063 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
1064 nsIIDRef riid, void **result)
1066 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1068 *result = NULL;
1069 if(IsEqualGUID(&IID_nsISupports, riid)) {
1070 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
1071 *result = &This->nsIWebBrowserChrome_iface;
1072 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
1073 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
1074 *result = &This->nsIWebBrowserChrome_iface;
1075 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
1076 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
1077 *result = &This->nsIContextMenuListener_iface;
1078 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
1079 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
1080 *result = &This->nsIURIContentListener_iface;
1081 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
1082 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
1083 *result = &This->nsIEmbeddingSiteWindow_iface;
1084 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
1085 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
1086 *result = &This->nsITooltipListener_iface;
1087 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
1088 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
1089 *result = &This->nsIInterfaceRequestor_iface;
1090 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
1091 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
1092 *result = &This->nsISupportsWeakReference_iface;
1095 if(*result) {
1096 nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1097 return NS_OK;
1100 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1101 return NS_NOINTERFACE;
1104 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
1106 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1107 LONG ref = InterlockedIncrement(&This->ref);
1109 TRACE("(%p) ref=%d\n", This, ref);
1111 return ref;
1114 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
1116 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1117 LONG ref = InterlockedDecrement(&This->ref);
1119 TRACE("(%p) ref=%d\n", This, ref);
1121 if(!ref) {
1122 if(This->parent)
1123 nsIWebBrowserChrome_Release(&This->parent->nsIWebBrowserChrome_iface);
1124 if(This->weak_reference) {
1125 This->weak_reference->nscontainer = NULL;
1126 nsIWeakReference_Release(&This->weak_reference->nsIWeakReference_iface);
1128 heap_free(This);
1131 return ref;
1134 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1135 PRUint32 statusType, const PRUnichar *status)
1137 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1138 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1139 return NS_OK;
1142 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1143 nsIWebBrowser **aWebBrowser)
1145 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1147 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1149 if(!aWebBrowser)
1150 return NS_ERROR_INVALID_ARG;
1152 if(This->webbrowser)
1153 nsIWebBrowser_AddRef(This->webbrowser);
1154 *aWebBrowser = This->webbrowser;
1155 return S_OK;
1158 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1159 nsIWebBrowser *aWebBrowser)
1161 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1163 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1165 if(aWebBrowser != This->webbrowser)
1166 ERR("Wrong nsWebBrowser!\n");
1168 return NS_OK;
1171 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1172 PRUint32 *aChromeFlags)
1174 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1175 WARN("(%p)->(%p)\n", This, aChromeFlags);
1176 return NS_ERROR_NOT_IMPLEMENTED;
1179 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1180 PRUint32 aChromeFlags)
1182 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1183 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1184 return NS_ERROR_NOT_IMPLEMENTED;
1187 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1189 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1190 TRACE("(%p)\n", This);
1191 return NS_ERROR_NOT_IMPLEMENTED;
1194 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1195 PRInt32 aCX, PRInt32 aCY)
1197 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1198 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1199 return NS_ERROR_NOT_IMPLEMENTED;
1202 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1204 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1205 WARN("(%p)\n", This);
1206 return NS_ERROR_NOT_IMPLEMENTED;
1209 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
1211 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1212 WARN("(%p)->(%p)\n", This, _retval);
1213 return NS_ERROR_NOT_IMPLEMENTED;
1216 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1217 nsresult aStatus)
1219 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1220 WARN("(%p)->(%08x)\n", This, aStatus);
1221 return NS_ERROR_NOT_IMPLEMENTED;
1224 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1225 nsWebBrowserChrome_QueryInterface,
1226 nsWebBrowserChrome_AddRef,
1227 nsWebBrowserChrome_Release,
1228 nsWebBrowserChrome_SetStatus,
1229 nsWebBrowserChrome_GetWebBrowser,
1230 nsWebBrowserChrome_SetWebBrowser,
1231 nsWebBrowserChrome_GetChromeFlags,
1232 nsWebBrowserChrome_SetChromeFlags,
1233 nsWebBrowserChrome_DestroyBrowserWindow,
1234 nsWebBrowserChrome_SizeBrowserTo,
1235 nsWebBrowserChrome_ShowAsModal,
1236 nsWebBrowserChrome_IsWindowModal,
1237 nsWebBrowserChrome_ExitModalEventLoop
1240 /**********************************************************
1241 * nsIContextMenuListener interface
1244 static inline NSContainer *impl_from_nsIContextMenuListener(nsIContextMenuListener *iface)
1246 return CONTAINING_RECORD(iface, NSContainer, nsIContextMenuListener_iface);
1249 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1250 nsIIDRef riid, void **result)
1252 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1253 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1256 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1258 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1259 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1262 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1264 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1265 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1268 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1269 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1271 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1272 nsIDOMMouseEvent *event;
1273 HTMLDOMNode *node;
1274 POINT pt;
1275 DWORD dwID = CONTEXT_MENU_DEFAULT;
1276 nsresult nsres;
1277 HRESULT hres;
1279 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1281 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1283 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1284 if(NS_FAILED(nsres)) {
1285 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1286 return nsres;
1289 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1290 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1291 nsIDOMMouseEvent_Release(event);
1293 switch(aContextFlags) {
1294 case CONTEXT_NONE:
1295 case CONTEXT_DOCUMENT:
1296 case CONTEXT_TEXT:
1297 dwID = CONTEXT_MENU_DEFAULT;
1298 break;
1299 case CONTEXT_IMAGE:
1300 case CONTEXT_IMAGE|CONTEXT_LINK:
1301 dwID = CONTEXT_MENU_IMAGE;
1302 break;
1303 case CONTEXT_LINK:
1304 dwID = CONTEXT_MENU_ANCHOR;
1305 break;
1306 case CONTEXT_INPUT:
1307 dwID = CONTEXT_MENU_CONTROL;
1308 break;
1309 default:
1310 FIXME("aContextFlags=%08x\n", aContextFlags);
1313 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1314 if(FAILED(hres))
1315 return NS_ERROR_FAILURE;
1317 show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
1318 return NS_OK;
1321 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1322 nsContextMenuListener_QueryInterface,
1323 nsContextMenuListener_AddRef,
1324 nsContextMenuListener_Release,
1325 nsContextMenuListener_OnShowContextMenu
1328 /**********************************************************
1329 * nsIURIContentListener interface
1332 static inline NSContainer *impl_from_nsIURIContentListener(nsIURIContentListener *iface)
1334 return CONTAINING_RECORD(iface, NSContainer, nsIURIContentListener_iface);
1337 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1338 nsIIDRef riid, void **result)
1340 NSContainer *This = impl_from_nsIURIContentListener(iface);
1341 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1344 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1346 NSContainer *This = impl_from_nsIURIContentListener(iface);
1347 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1350 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1352 NSContainer *This = impl_from_nsIURIContentListener(iface);
1353 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1356 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1357 nsIURI *aURI, PRBool *_retval)
1359 NSContainer *This = impl_from_nsIURIContentListener(iface);
1360 nsACString spec_str;
1361 const char *spec;
1362 nsresult nsres;
1364 nsACString_Init(&spec_str, NULL);
1365 nsIURI_GetSpec(aURI, &spec_str);
1366 nsACString_GetData(&spec_str, &spec);
1368 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1370 nsACString_Finish(&spec_str);
1372 nsres = on_start_uri_open(This, aURI, _retval);
1373 if(NS_FAILED(nsres))
1374 return nsres;
1376 return !*_retval && This->content_listener
1377 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1378 : NS_OK;
1381 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1382 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1383 nsIStreamListener **aContentHandler, PRBool *_retval)
1385 NSContainer *This = impl_from_nsIURIContentListener(iface);
1387 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1388 aRequest, aContentHandler, _retval);
1390 return This->content_listener
1391 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1392 aIsContentPreferred, aRequest, aContentHandler, _retval)
1393 : NS_ERROR_NOT_IMPLEMENTED;
1396 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1397 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1399 NSContainer *This = impl_from_nsIURIContentListener(iface);
1401 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1403 /* FIXME: Should we do something here? */
1404 *_retval = TRUE;
1406 return This->content_listener
1407 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1408 aDesiredContentType, _retval)
1409 : NS_OK;
1412 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1413 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1414 PRBool *_retval)
1416 NSContainer *This = impl_from_nsIURIContentListener(iface);
1418 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1419 aDesiredContentType, _retval);
1421 return This->content_listener
1422 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1423 aIsContentPreferred, aDesiredContentType, _retval)
1424 : NS_ERROR_NOT_IMPLEMENTED;
1427 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1428 nsISupports **aLoadCookie)
1430 NSContainer *This = impl_from_nsIURIContentListener(iface);
1432 WARN("(%p)->(%p)\n", This, aLoadCookie);
1434 return This->content_listener
1435 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1436 : NS_ERROR_NOT_IMPLEMENTED;
1439 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1440 nsISupports *aLoadCookie)
1442 NSContainer *This = impl_from_nsIURIContentListener(iface);
1444 WARN("(%p)->(%p)\n", This, aLoadCookie);
1446 return This->content_listener
1447 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1448 : NS_ERROR_NOT_IMPLEMENTED;
1451 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1452 nsIURIContentListener **aParentContentListener)
1454 NSContainer *This = impl_from_nsIURIContentListener(iface);
1456 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1458 if(This->content_listener)
1459 nsIURIContentListener_AddRef(This->content_listener);
1461 *aParentContentListener = This->content_listener;
1462 return NS_OK;
1465 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1466 nsIURIContentListener *aParentContentListener)
1468 NSContainer *This = impl_from_nsIURIContentListener(iface);
1470 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1472 if(aParentContentListener == &This->nsIURIContentListener_iface)
1473 return NS_OK;
1475 if(This->content_listener)
1476 nsIURIContentListener_Release(This->content_listener);
1478 This->content_listener = aParentContentListener;
1479 if(This->content_listener)
1480 nsIURIContentListener_AddRef(This->content_listener);
1482 return NS_OK;
1485 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1486 nsURIContentListener_QueryInterface,
1487 nsURIContentListener_AddRef,
1488 nsURIContentListener_Release,
1489 nsURIContentListener_OnStartURIOpen,
1490 nsURIContentListener_DoContent,
1491 nsURIContentListener_IsPreferred,
1492 nsURIContentListener_CanHandleContent,
1493 nsURIContentListener_GetLoadCookie,
1494 nsURIContentListener_SetLoadCookie,
1495 nsURIContentListener_GetParentContentListener,
1496 nsURIContentListener_SetParentContentListener
1499 /**********************************************************
1500 * nsIEmbeddinSiteWindow interface
1503 static inline NSContainer *impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow *iface)
1505 return CONTAINING_RECORD(iface, NSContainer, nsIEmbeddingSiteWindow_iface);
1508 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1509 nsIIDRef riid, void **result)
1511 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1512 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1515 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1517 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1518 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1521 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1523 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1524 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1527 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1528 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1530 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1531 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1532 return NS_ERROR_NOT_IMPLEMENTED;
1535 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1536 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1538 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1539 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1540 return NS_ERROR_NOT_IMPLEMENTED;
1543 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1545 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1547 TRACE("(%p)\n", This);
1549 return nsIBaseWindow_SetFocus(This->window);
1552 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1553 PRBool *aVisibility)
1555 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1557 TRACE("(%p)->(%p)\n", This, aVisibility);
1559 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1560 return NS_OK;
1563 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1564 PRBool aVisibility)
1566 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1568 TRACE("(%p)->(%x)\n", This, aVisibility);
1570 return NS_OK;
1573 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1574 PRUnichar **aTitle)
1576 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1577 WARN("(%p)->(%p)\n", This, aTitle);
1578 return NS_ERROR_NOT_IMPLEMENTED;
1581 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1582 const PRUnichar *aTitle)
1584 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1585 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1586 return NS_ERROR_NOT_IMPLEMENTED;
1589 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1590 void **aSiteWindow)
1592 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1594 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1596 *aSiteWindow = This->hwnd;
1597 return NS_OK;
1600 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1601 nsEmbeddingSiteWindow_QueryInterface,
1602 nsEmbeddingSiteWindow_AddRef,
1603 nsEmbeddingSiteWindow_Release,
1604 nsEmbeddingSiteWindow_SetDimensions,
1605 nsEmbeddingSiteWindow_GetDimensions,
1606 nsEmbeddingSiteWindow_SetFocus,
1607 nsEmbeddingSiteWindow_GetVisibility,
1608 nsEmbeddingSiteWindow_SetVisibility,
1609 nsEmbeddingSiteWindow_GetTitle,
1610 nsEmbeddingSiteWindow_SetTitle,
1611 nsEmbeddingSiteWindow_GetSiteWindow
1614 static inline NSContainer *impl_from_nsITooltipListener(nsITooltipListener *iface)
1616 return CONTAINING_RECORD(iface, NSContainer, nsITooltipListener_iface);
1619 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1620 void **result)
1622 NSContainer *This = impl_from_nsITooltipListener(iface);
1623 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1626 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1628 NSContainer *This = impl_from_nsITooltipListener(iface);
1629 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1632 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1634 NSContainer *This = impl_from_nsITooltipListener(iface);
1635 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1638 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1639 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1641 NSContainer *This = impl_from_nsITooltipListener(iface);
1643 if (This->doc)
1644 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1646 return NS_OK;
1649 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1651 NSContainer *This = impl_from_nsITooltipListener(iface);
1653 if (This->doc)
1654 hide_tooltip(This->doc);
1656 return NS_OK;
1659 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1660 nsTooltipListener_QueryInterface,
1661 nsTooltipListener_AddRef,
1662 nsTooltipListener_Release,
1663 nsTooltipListener_OnShowTooltip,
1664 nsTooltipListener_OnHideTooltip
1667 static inline NSContainer *impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor *iface)
1669 return CONTAINING_RECORD(iface, NSContainer, nsIInterfaceRequestor_iface);
1672 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1673 nsIIDRef riid, void **result)
1675 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1676 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1679 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1681 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1682 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1685 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1687 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1688 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1691 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1692 nsIIDRef riid, void **result)
1694 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1696 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1697 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1698 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1701 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1704 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1705 nsInterfaceRequestor_QueryInterface,
1706 nsInterfaceRequestor_AddRef,
1707 nsInterfaceRequestor_Release,
1708 nsInterfaceRequestor_GetInterface
1711 static inline NSContainer *impl_from_nsISupportsWeakReference(nsISupportsWeakReference *iface)
1713 return CONTAINING_RECORD(iface, NSContainer, nsISupportsWeakReference_iface);
1716 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1717 nsIIDRef riid, void **result)
1719 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1720 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1723 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1725 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1726 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1729 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1731 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1732 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1735 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1736 nsIWeakReference **_retval)
1738 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1740 TRACE("(%p)->(%p)\n", This, _retval);
1742 if(!This->weak_reference) {
1743 This->weak_reference = heap_alloc(sizeof(nsWeakReference));
1744 if(!This->weak_reference)
1745 return NS_ERROR_OUT_OF_MEMORY;
1747 This->weak_reference->nsIWeakReference_iface.lpVtbl = &nsWeakReferenceVtbl;
1748 This->weak_reference->ref = 1;
1749 This->weak_reference->nscontainer = This;
1752 *_retval = &This->weak_reference->nsIWeakReference_iface;
1753 nsIWeakReference_AddRef(*_retval);
1754 return NS_OK;
1757 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1758 nsSupportsWeakReference_QueryInterface,
1759 nsSupportsWeakReference_AddRef,
1760 nsSupportsWeakReference_Release,
1761 nsSupportsWeakReference_GetWeakReference
1764 nsresult create_chrome_window(nsIWebBrowserChrome *parent, nsIWebBrowserChrome **ret)
1766 NSContainer *new_container;
1768 if(parent->lpVtbl != &nsWebBrowserChromeVtbl)
1769 return NS_ERROR_UNEXPECTED;
1771 new_container = NSContainer_Create(NULL, impl_from_nsIWebBrowserChrome(parent));
1772 *ret = &new_container->nsIWebBrowserChrome_iface;
1773 return NS_OK;
1776 NSContainer *NSContainer_Create(HTMLDocumentObj *doc, NSContainer *parent)
1778 nsIWebBrowserSetup *wbsetup;
1779 nsIScrollable *scrollable;
1780 NSContainer *ret;
1781 nsresult nsres;
1783 if(!load_gecko(TRUE))
1784 return NULL;
1786 ret = heap_alloc_zero(sizeof(NSContainer));
1788 ret->nsIWebBrowserChrome_iface.lpVtbl = &nsWebBrowserChromeVtbl;
1789 ret->nsIContextMenuListener_iface.lpVtbl = &nsContextMenuListenerVtbl;
1790 ret->nsIURIContentListener_iface.lpVtbl = &nsURIContentListenerVtbl;
1791 ret->nsIEmbeddingSiteWindow_iface.lpVtbl = &nsEmbeddingSiteWindowVtbl;
1792 ret->nsITooltipListener_iface.lpVtbl = &nsTooltipListenerVtbl;
1793 ret->nsIInterfaceRequestor_iface.lpVtbl = &nsInterfaceRequestorVtbl;
1794 ret->nsISupportsWeakReference_iface.lpVtbl = &nsSupportsWeakReferenceVtbl;
1796 ret->doc = doc;
1797 ret->ref = 1;
1799 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1800 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1801 if(NS_FAILED(nsres)) {
1802 ERR("Creating WebBrowser failed: %08x\n", nsres);
1803 heap_free(ret);
1804 return NULL;
1807 if(parent)
1808 nsIWebBrowserChrome_AddRef(&parent->nsIWebBrowserChrome_iface);
1809 ret->parent = parent;
1811 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, &ret->nsIWebBrowserChrome_iface);
1812 if(NS_FAILED(nsres))
1813 ERR("SetContainerWindow failed: %08x\n", nsres);
1815 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1816 (void**)&ret->window);
1817 if(NS_FAILED(nsres))
1818 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1820 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1821 (void**)&wbsetup);
1822 if(NS_SUCCEEDED(nsres)) {
1823 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1824 nsIWebBrowserSetup_Release(wbsetup);
1825 if(NS_FAILED(nsres))
1826 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1827 }else {
1828 ERR("Could not get nsIWebBrowserSetup interface\n");
1831 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1832 (void**)&ret->navigation);
1833 if(NS_FAILED(nsres))
1834 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1836 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1837 (void**)&ret->focus);
1838 if(NS_FAILED(nsres))
1839 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1841 if(!nscontainer_class)
1842 register_nscontainer_class();
1844 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1845 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1846 GetDesktopWindow(), NULL, hInst, ret);
1848 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1849 if(NS_SUCCEEDED(nsres)) {
1850 nsres = nsIBaseWindow_Create(ret->window);
1851 if(NS_FAILED(nsres))
1852 WARN("Creating window failed: %08x\n", nsres);
1854 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1855 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1856 }else {
1857 ERR("InitWindow failed: %08x\n", nsres);
1860 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser,
1861 &ret->nsIURIContentListener_iface);
1862 if(NS_FAILED(nsres))
1863 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1865 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1866 if(NS_SUCCEEDED(nsres)) {
1867 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1868 ScrollOrientation_Y, Scrollbar_Always);
1869 if(NS_FAILED(nsres))
1870 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1872 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1873 ScrollOrientation_X, Scrollbar_Auto);
1874 if(NS_FAILED(nsres))
1875 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1877 nsIScrollable_Release(scrollable);
1878 }else {
1879 ERR("Could not get nsIScrollable: %08x\n", nsres);
1882 return ret;
1885 void NSContainer_Release(NSContainer *This)
1887 TRACE("(%p)\n", This);
1889 This->doc = NULL;
1891 ShowWindow(This->hwnd, SW_HIDE);
1892 SetParent(This->hwnd, NULL);
1894 nsIBaseWindow_SetVisibility(This->window, FALSE);
1895 nsIBaseWindow_Destroy(This->window);
1897 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1899 nsIWebBrowser_Release(This->webbrowser);
1900 This->webbrowser = NULL;
1902 nsIWebNavigation_Release(This->navigation);
1903 This->navigation = NULL;
1905 nsIBaseWindow_Release(This->window);
1906 This->window = NULL;
1908 nsIWebBrowserFocus_Release(This->focus);
1909 This->focus = NULL;
1911 if(This->editor_controller) {
1912 nsIController_Release(This->editor_controller);
1913 This->editor_controller = NULL;
1916 if(This->editor) {
1917 nsIEditor_Release(This->editor);
1918 This->editor = NULL;
1921 if(This->content_listener) {
1922 nsIURIContentListener_Release(This->content_listener);
1923 This->content_listener = NULL;
1926 if(This->hwnd) {
1927 DestroyWindow(This->hwnd);
1928 This->hwnd = NULL;
1931 nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);