comdlg32: We only want to check the low word of wparam.
[wine.git] / dlls / mshtml / nsembed.c
blobc2332e0611fd298a8ab46c70d20bde68f81578e2
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>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlobj.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 WINE_DECLARE_DEBUG_CHANNEL(gecko);
41 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
42 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
43 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
44 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
45 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
46 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
47 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
49 #define APPSTARTUP_TOPIC "app-startup"
51 #define PR_UINT32_MAX 0xffffffff
53 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
54 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
56 static nsresult (CDECL *NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
57 static nsresult (CDECL *NS_ShutdownXPCOM)(nsIServiceManager*);
58 static nsresult (CDECL *NS_GetComponentRegistrar)(nsIComponentRegistrar**);
59 static nsresult (CDECL *NS_StringContainerInit2)(nsStringContainer*,const PRUnichar*,PRUint32,PRUint32);
60 static nsresult (CDECL *NS_CStringContainerInit2)(nsCStringContainer*,const char*,PRUint32,PRUint32);
61 static nsresult (CDECL *NS_StringContainerFinish)(nsStringContainer*);
62 static nsresult (CDECL *NS_CStringContainerFinish)(nsCStringContainer*);
63 static nsresult (CDECL *NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
64 static nsresult (CDECL *NS_CStringSetData)(nsACString*,const char*,PRUint32);
65 static nsresult (CDECL *NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
66 static PRUint32 (CDECL *NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
67 static PRUint32 (CDECL *NS_CStringGetData)(const nsACString*,const char**,PRBool*);
69 static HINSTANCE hXPCOM = NULL;
71 static nsIServiceManager *pServMgr = NULL;
72 static nsIComponentManager *pCompMgr = NULL;
73 static nsIMemory *nsmem = NULL;
74 static nsIFile *profile_directory;
76 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
78 static ATOM nscontainer_class;
79 static WCHAR gecko_path[MAX_PATH];
80 static unsigned gecko_path_len;
82 static nsresult NSAPI nsDirectoryServiceProvider_QueryInterface(nsIDirectoryServiceProvider *iface,
83 nsIIDRef riid, void **result)
85 if(IsEqualGUID(&IID_nsISupports, riid)) {
86 TRACE("(IID_nsISupports %p)\n", result);
87 *result = iface;
88 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider, riid)) {
89 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result);
90 *result = iface;
91 }else {
92 WARN("(%s %p)\n", debugstr_guid(riid), result);
93 *result = NULL;
94 return NS_NOINTERFACE;
97 nsISupports_AddRef((nsISupports*)*result);
98 return NS_OK;
101 static nsrefcnt NSAPI nsDirectoryServiceProvider_AddRef(nsIDirectoryServiceProvider *iface)
103 return 2;
106 static nsrefcnt NSAPI nsDirectoryServiceProvider_Release(nsIDirectoryServiceProvider *iface)
108 return 1;
111 static nsresult create_profile_directory(void)
113 static const WCHAR wine_geckoW[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
115 WCHAR path[MAX_PATH + sizeof(wine_geckoW)/sizeof(WCHAR)];
116 nsAString str;
117 PRBool exists;
118 nsresult nsres;
119 HRESULT hres;
121 hres = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_DEFAULT, path);
122 if(FAILED(hres)) {
123 ERR("SHGetFolderPath failed: %08x\n", hres);
124 return NS_ERROR_FAILURE;
127 strcatW(path, wine_geckoW);
128 nsAString_InitDepend(&str, path);
129 nsres = NS_NewLocalFile(&str, FALSE, &profile_directory);
130 nsAString_Finish(&str);
131 if(NS_FAILED(nsres)) {
132 ERR("NS_NewLocalFile failed: %08x\n", nsres);
133 return nsres;
136 nsres = nsIFile_Exists(profile_directory, &exists);
137 if(NS_FAILED(nsres)) {
138 ERR("Exists failed: %08x\n", nsres);
139 return nsres;
142 if(!exists) {
143 nsres = nsIFile_Create(profile_directory, 1, 0700);
144 if(NS_FAILED(nsres))
145 ERR("Create failed: %08x\n", nsres);
148 return nsres;
151 static nsresult NSAPI nsDirectoryServiceProvider_GetFile(nsIDirectoryServiceProvider *iface,
152 const char *prop, PRBool *persistent, nsIFile **_retval)
154 TRACE("(%s %p %p)\n", debugstr_a(prop), persistent, _retval);
156 if(!strcmp(prop, "ProfD")) {
157 if(!profile_directory) {
158 nsresult nsres;
160 nsres = create_profile_directory();
161 if(NS_FAILED(nsres))
162 return nsres;
165 return nsIFile_Clone(profile_directory, _retval);
168 return NS_ERROR_FAILURE;
171 static const nsIDirectoryServiceProviderVtbl nsDirectoryServiceProviderVtbl = {
172 nsDirectoryServiceProvider_QueryInterface,
173 nsDirectoryServiceProvider_AddRef,
174 nsDirectoryServiceProvider_Release,
175 nsDirectoryServiceProvider_GetFile
178 static nsIDirectoryServiceProvider nsDirectoryServiceProvider =
179 { &nsDirectoryServiceProviderVtbl };
181 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
183 NSContainer *This;
184 nsresult nsres;
186 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
188 if(msg == WM_CREATE) {
189 This = *(NSContainer**)lParam;
190 SetPropW(hwnd, wszTHIS, This);
191 }else {
192 This = GetPropW(hwnd, wszTHIS);
195 switch(msg) {
196 case WM_SIZE:
197 TRACE("(%p)->(WM_SIZE)\n", This);
199 nsres = nsIBaseWindow_SetSize(This->window,
200 LOWORD(lParam), HIWORD(lParam), TRUE);
201 if(NS_FAILED(nsres))
202 WARN("SetSize failed: %08x\n", nsres);
203 break;
205 case WM_PARENTNOTIFY:
206 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam);
208 switch(wParam) {
209 case WM_LBUTTONDOWN:
210 case WM_RBUTTONDOWN:
211 nsIWebBrowserFocus_Activate(This->focus);
215 return DefWindowProcW(hwnd, msg, wParam, lParam);
219 static void register_nscontainer_class(void)
221 static WNDCLASSEXW wndclass = {
222 sizeof(WNDCLASSEXW),
223 CS_DBLCLKS,
224 nsembed_proc,
225 0, 0, NULL, NULL, NULL, NULL, NULL,
226 wszNsContainer,
227 NULL,
229 wndclass.hInstance = hInst;
230 nscontainer_class = RegisterClassExW(&wndclass);
233 static BOOL install_wine_gecko(BOOL silent)
235 PROCESS_INFORMATION pi;
236 STARTUPINFOW si;
237 WCHAR app[MAX_PATH];
238 WCHAR *args;
239 LONG len;
240 BOOL ret;
242 static const WCHAR controlW[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
243 static const WCHAR argsW[] =
244 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
246 len = GetSystemDirectoryW(app, MAX_PATH-sizeof(controlW)/sizeof(WCHAR));
247 memcpy(app+len, controlW, sizeof(controlW));
249 args = heap_alloc(len*sizeof(WCHAR) + sizeof(controlW) + sizeof(argsW));
250 if(!args)
251 return FALSE;
253 memcpy(args, app, len*sizeof(WCHAR) + sizeof(controlW));
254 memcpy(args + len + sizeof(controlW)/sizeof(WCHAR)-1, argsW, sizeof(argsW));
256 TRACE("starting %s\n", debugstr_w(args));
258 memset(&si, 0, sizeof(si));
259 si.cb = sizeof(si);
260 ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
261 heap_free(args);
262 if (ret) {
263 CloseHandle(pi.hThread);
264 WaitForSingleObject(pi.hProcess, INFINITE);
265 CloseHandle(pi.hProcess);
268 return ret;
271 static void set_environment(LPCWSTR gre_path)
273 WCHAR path_env[MAX_PATH], buf[20];
274 int len, debug_level = 0;
276 static const WCHAR pathW[] = {'P','A','T','H',0};
277 static const WCHAR warnW[] = {'w','a','r','n',0};
278 static const WCHAR xpcom_debug_breakW[] =
279 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
280 static const WCHAR nspr_log_modulesW[] =
281 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
282 static const WCHAR debug_formatW[] = {'a','l','l',':','%','d',0};
283 static const WCHAR moz_plugin_pathW[] = {'M','O','Z','_','P','L','U','G','I','N','_','P','A','T','H',0};
284 static const WCHAR gecko_pluginW[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
286 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
287 GetEnvironmentVariableW(pathW, path_env, sizeof(path_env)/sizeof(WCHAR));
288 len = strlenW(path_env);
289 path_env[len++] = ';';
290 strcpyW(path_env+len, gre_path);
291 SetEnvironmentVariableW(pathW, path_env);
293 SetEnvironmentVariableW(xpcom_debug_breakW, warnW);
295 if(TRACE_ON(gecko))
296 debug_level = 5;
297 else if(WARN_ON(gecko))
298 debug_level = 3;
299 else if(ERR_ON(gecko))
300 debug_level = 2;
302 sprintfW(buf, debug_formatW, debug_level);
303 SetEnvironmentVariableW(nspr_log_modulesW, buf);
305 len = GetSystemDirectoryW(path_env, (sizeof(path_env)-sizeof(gecko_pluginW))/sizeof(WCHAR)+1);
306 if(len) {
307 strcpyW(path_env+len, gecko_pluginW);
308 SetEnvironmentVariableW(moz_plugin_pathW, path_env);
312 static BOOL load_xpcom(const PRUnichar *gre_path)
314 static const WCHAR strXPCOM[] = {'\\','x','p','c','o','m','.','d','l','l',0};
315 WCHAR file_name[MAX_PATH];
317 strcpyW(file_name, gre_path);
318 strcatW(file_name, strXPCOM);
320 TRACE("(%s)\n", debugstr_w(file_name));
322 set_environment(gre_path);
324 hXPCOM = LoadLibraryExW(file_name, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
325 if(!hXPCOM) {
326 WARN("Could not load XPCOM: %d\n", GetLastError());
327 return FALSE;
330 #define NS_DLSYM(func) \
331 func = (void *)GetProcAddress(hXPCOM, #func); \
332 if(!func) \
333 ERR("Could not GetProcAddress(" #func ") failed\n")
335 NS_DLSYM(NS_InitXPCOM2);
336 NS_DLSYM(NS_ShutdownXPCOM);
337 NS_DLSYM(NS_GetComponentRegistrar);
338 NS_DLSYM(NS_StringContainerInit2);
339 NS_DLSYM(NS_CStringContainerInit2);
340 NS_DLSYM(NS_StringContainerFinish);
341 NS_DLSYM(NS_CStringContainerFinish);
342 NS_DLSYM(NS_StringSetData);
343 NS_DLSYM(NS_CStringSetData);
344 NS_DLSYM(NS_NewLocalFile);
345 NS_DLSYM(NS_StringGetData);
346 NS_DLSYM(NS_CStringGetData);
348 #undef NS_DLSYM
350 return TRUE;
353 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
355 WCHAR file_name[MAX_PATH];
356 char version[128];
357 DWORD read=0;
358 HANDLE hfile;
360 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
362 strcpyW(file_name, gre_path);
363 strcatW(file_name, wszVersion);
365 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
366 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
367 if(hfile == INVALID_HANDLE_VALUE) {
368 ERR("Could not open VERSION file\n");
369 return FALSE;
372 ReadFile(hfile, version, sizeof(version), &read, NULL);
373 version[read] = 0;
374 CloseHandle(hfile);
376 TRACE("%s\n", debugstr_a(version));
378 if(strcmp(version, version_string)) {
379 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
380 debugstr_a(version_string));
381 return FALSE;
384 return TRUE;
387 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
388 const char *version, const char *version_string)
390 DWORD res, type, size = MAX_PATH;
391 HKEY hkey = mshtml_key;
393 static const WCHAR wszGeckoPath[] =
394 {'G','e','c','k','o','P','a','t','h',0};
396 if(version) {
397 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
398 res = RegOpenKeyA(mshtml_key, version, &hkey);
399 if(res != ERROR_SUCCESS)
400 return FALSE;
403 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
404 if(hkey != mshtml_key)
405 RegCloseKey(hkey);
406 if(res != ERROR_SUCCESS || type != REG_SZ)
407 return FALSE;
409 if(!check_version(gre_path, version_string))
410 return FALSE;
412 return load_xpcom(gre_path);
415 static BOOL load_wine_gecko(PRUnichar *gre_path)
417 HKEY hkey;
418 DWORD res;
419 BOOL ret;
421 static const WCHAR wszMshtmlKey[] = {
422 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
423 '\\','M','S','H','T','M','L',0};
425 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
426 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMshtmlKey, &hkey);
427 if(res != ERROR_SUCCESS)
428 return FALSE;
430 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING);
432 RegCloseKey(hkey);
433 return ret;
436 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
438 nsresult nsres;
440 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
441 if(NS_FAILED(nsres))
442 ERR("Could not set pref %s\n", debugstr_a(pref_name));
445 static void set_int_pref(nsIPrefBranch *pref, const char *pref_name, int val)
447 nsresult nsres;
449 nsres = nsIPrefBranch_SetIntPref(pref, pref_name, val);
450 if(NS_FAILED(nsres))
451 ERR("Could not set pref %s\n", debugstr_a(pref_name));
454 static void set_string_pref(nsIPrefBranch *pref, const char *pref_name, const char *val)
456 nsresult nsres;
458 nsres = nsIPrefBranch_SetCharPref(pref, pref_name, val);
459 if(NS_FAILED(nsres))
460 ERR("Could not set pref %s\n", debugstr_a(pref_name));
463 static void set_lang(nsIPrefBranch *pref)
465 char langs[100];
466 DWORD res, size, type;
467 HKEY hkey;
469 static const WCHAR international_keyW[] =
470 {'S','o','f','t','w','a','r','e',
471 '\\','M','i','c','r','o','s','o','f','t',
472 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
473 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
475 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
476 if(res != ERROR_SUCCESS)
477 return;
479 size = sizeof(langs);
480 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
481 RegCloseKey(hkey);
482 if(res != ERROR_SUCCESS || type != REG_SZ)
483 return;
485 TRACE("Setting lang %s\n", debugstr_a(langs));
487 set_string_pref(pref, "intl.accept_languages", langs);
490 static void set_proxy(nsIPrefBranch *pref)
492 char proxy[512];
493 char * proxy_port;
494 int proxy_port_num;
495 DWORD enabled = 0, res, size, type;
496 HKEY hkey;
498 static const WCHAR proxy_keyW[] =
499 {'S','o','f','t','w','a','r','e',
500 '\\','M','i','c','r','o','s','o','f','t',
501 '\\','W','i','n','d','o','w','s',
502 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
503 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
505 res = RegOpenKeyW(HKEY_CURRENT_USER, proxy_keyW, &hkey);
506 if(res != ERROR_SUCCESS)
507 return;
509 size = sizeof(enabled);
510 res = RegQueryValueExA(hkey, "ProxyEnable", 0, &type, (LPBYTE)&enabled, &size);
511 if(res != ERROR_SUCCESS || type != REG_DWORD || enabled == 0)
513 RegCloseKey(hkey);
514 return;
517 size = sizeof(proxy);
518 res = RegQueryValueExA(hkey, "ProxyServer", 0, &type, (LPBYTE)proxy, &size);
519 RegCloseKey(hkey);
520 if(res != ERROR_SUCCESS || type != REG_SZ)
521 return;
523 proxy_port = strchr(proxy, ':');
524 if (!proxy_port)
525 return;
527 *proxy_port = 0;
528 proxy_port_num = atoi(proxy_port + 1);
529 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy), proxy_port_num);
531 set_string_pref(pref, "network.proxy.http", proxy);
532 set_string_pref(pref, "network.proxy.ssl", proxy);
534 set_int_pref(pref, "network.proxy.type", 1);
535 set_int_pref(pref, "network.proxy.http_port", proxy_port_num);
536 set_int_pref(pref, "network.proxy.ssl_port", proxy_port_num);
539 static void set_preferences(void)
541 nsIPrefBranch *pref;
542 nsresult nsres;
544 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
545 &IID_nsIPrefBranch, (void**)&pref);
546 if(NS_FAILED(nsres)) {
547 ERR("Could not get preference service: %08x\n", nsres);
548 return;
551 set_lang(pref);
552 set_proxy(pref);
553 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
554 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
555 set_int_pref(pref, "layout.spellcheckDefault", 0);
557 nsIPrefBranch_Release(pref);
560 static BOOL init_xpcom(const PRUnichar *gre_path)
562 nsresult nsres;
563 nsIObserver *pStartNotif;
564 nsIComponentRegistrar *registrar = NULL;
565 nsAString path;
566 nsIFile *gre_dir;
567 WCHAR *ptr;
569 nsAString_InitDepend(&path, gre_path);
570 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
571 nsAString_Finish(&path);
572 if(NS_FAILED(nsres)) {
573 ERR("NS_NewLocalFile failed: %08x\n", nsres);
574 FreeLibrary(hXPCOM);
575 return FALSE;
578 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, &nsDirectoryServiceProvider);
579 if(NS_FAILED(nsres)) {
580 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
581 FreeLibrary(hXPCOM);
582 return FALSE;
585 strcpyW(gecko_path, gre_path);
586 for(ptr = gecko_path; *ptr; ptr++) {
587 if(*ptr == '\\')
588 *ptr = '/';
590 gecko_path_len = ptr-gecko_path;
592 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
593 if(NS_FAILED(nsres))
594 ERR("Could not get nsIComponentManager: %08x\n", nsres);
596 nsres = NS_GetComponentRegistrar(&registrar);
597 if(NS_SUCCEEDED(nsres))
598 init_nsio(pCompMgr, registrar);
599 else
600 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
602 init_mutation(pCompMgr);
604 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
605 NULL, &IID_nsIObserver, (void**)&pStartNotif);
606 if(NS_SUCCEEDED(nsres)) {
607 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
608 if(NS_FAILED(nsres))
609 ERR("Observe failed: %08x\n", nsres);
611 nsIObserver_Release(pStartNotif);
612 }else {
613 ERR("could not get appstartup-notifier: %08x\n", nsres);
616 set_preferences();
618 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
619 NULL, &IID_nsIMemory, (void**)&nsmem);
620 if(NS_FAILED(nsres))
621 ERR("Could not get nsIMemory: %08x\n", nsres);
623 if(registrar) {
624 register_nsservice(registrar, pServMgr);
625 nsIComponentRegistrar_Release(registrar);
628 return TRUE;
631 static CRITICAL_SECTION cs_load_gecko;
632 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
634 0, 0, &cs_load_gecko,
635 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
636 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
638 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
640 BOOL load_gecko(BOOL silent)
642 PRUnichar gre_path[MAX_PATH];
643 BOOL ret = FALSE;
645 static DWORD loading_thread;
647 TRACE("()\n");
649 /* load_gecko may be called recursively */
650 if(loading_thread == GetCurrentThreadId())
651 return pCompMgr != NULL;
653 EnterCriticalSection(&cs_load_gecko);
655 if(!loading_thread) {
656 loading_thread = GetCurrentThreadId();
658 if(load_wine_gecko(gre_path)
659 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
660 ret = init_xpcom(gre_path);
661 else
662 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
663 }else {
664 ret = pCompMgr != NULL;
667 LeaveCriticalSection(&cs_load_gecko);
669 return ret;
672 void *nsalloc(size_t size)
674 return nsIMemory_Alloc(nsmem, size);
677 void nsfree(void *mem)
679 nsIMemory_Free(nsmem, mem);
682 static BOOL nsACString_Init(nsACString *str, const char *data)
684 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
688 * Initializes nsACString with data owned by caller.
689 * Caller must ensure that data is valid during lifetime of string object.
691 void nsACString_InitDepend(nsACString *str, const char *data)
693 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
696 void nsACString_SetData(nsACString *str, const char *data)
698 NS_CStringSetData(str, data, PR_UINT32_MAX);
701 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
703 return NS_CStringGetData(str, data, NULL);
706 void nsACString_Finish(nsACString *str)
708 NS_CStringContainerFinish(str);
711 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
713 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
717 * Initializes nsAString with data owned by caller.
718 * Caller must ensure that data is valid during lifetime of string object.
720 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
722 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
725 void nsAString_SetData(nsAString *str, const PRUnichar *data)
727 NS_StringSetData(str, data, PR_UINT32_MAX);
730 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
732 return NS_StringGetData(str, data, NULL);
735 void nsAString_Finish(nsAString *str)
737 NS_StringContainerFinish(str);
740 HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
742 const PRUnichar *str;
744 if(NS_FAILED(nsres)) {
745 ERR("failed: %08x\n", nsres);
746 nsAString_Finish(nsstr);
747 return E_FAIL;
750 nsAString_GetData(nsstr, &str);
751 TRACE("ret %s\n", debugstr_w(str));
752 if(*str) {
753 *p = SysAllocString(str);
754 if(!*p)
755 return E_OUTOFMEMORY;
756 }else {
757 *p = NULL;
760 nsAString_Finish(nsstr);
761 return S_OK;
764 nsICommandParams *create_nscommand_params(void)
766 nsICommandParams *ret = NULL;
767 nsresult nsres;
769 if(!pCompMgr)
770 return NULL;
772 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
773 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
774 (void**)&ret);
775 if(NS_FAILED(nsres))
776 ERR("Could not get nsICommandParams\n");
778 return ret;
781 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
783 nsIInterfaceRequestor *iface_req;
784 nsresult nsres;
786 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
787 if(NS_FAILED(nsres))
788 return nsres;
790 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
791 nsIInterfaceRequestor_Release(iface_req);
793 return nsres;
796 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
798 nsIDOMNodeList *node_list = NULL;
799 PRBool has_children = FALSE;
800 nsIContent *nscontent;
801 PRUint16 type;
802 nsresult nsres;
804 nsIDOMNode_HasChildNodes(nsnode, &has_children);
806 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
807 if(NS_FAILED(nsres)) {
808 ERR("GetType failed: %08x\n", nsres);
809 return E_FAIL;
812 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
813 if(NS_FAILED(nsres)) {
814 ERR("Could not get nsIDontent interface: %08x\n", nsres);
815 return E_FAIL;
818 switch(type) {
819 case ELEMENT_NODE:
820 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
821 break;
822 case TEXT_NODE:
823 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
824 break;
825 case COMMENT_NODE:
826 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
827 break;
828 case DOCUMENT_NODE: {
829 nsIDocument *nsdoc;
830 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
831 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
832 nsIDocument_Release(nsdoc);
833 break;
835 case DOCUMENT_TYPE_NODE:
836 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
837 break;
838 case DOCUMENT_FRAGMENT_NODE:
839 break;
840 default:
841 FIXME("Unhandled type %u\n", type);
844 if(has_children) {
845 PRUint32 child_cnt, i;
846 nsIDOMNode *child_node;
848 nsIDOMNode_GetChildNodes(nsnode, &node_list);
849 nsIDOMNodeList_GetLength(node_list, &child_cnt);
851 for(i=0; i<child_cnt; i++) {
852 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
853 if(NS_SUCCEEDED(nsres)) {
854 nsnode_to_nsstring_rec(serializer, child_node, str);
855 nsIDOMNode_Release(child_node);
856 }else {
857 ERR("Item failed: %08x\n", nsres);
861 nsIDOMNodeList_Release(node_list);
864 if(type == ELEMENT_NODE)
865 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
867 nsIContent_Release(nscontent);
868 return S_OK;
871 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
873 nsIContentSerializer *serializer;
874 nsresult nsres;
875 HRESULT hres;
877 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
878 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
879 (void**)&serializer);
880 if(NS_FAILED(nsres)) {
881 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
882 return E_FAIL;
885 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
886 if(NS_FAILED(nsres))
887 ERR("Init failed: %08x\n", nsres);
889 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
890 if(SUCCEEDED(hres)) {
891 nsres = nsIContentSerializer_Flush(serializer, str);
892 if(NS_FAILED(nsres))
893 ERR("Flush failed: %08x\n", nsres);
896 nsIContentSerializer_Release(serializer);
897 return hres;
900 void get_editor_controller(NSContainer *This)
902 nsIEditingSession *editing_session = NULL;
903 nsIControllerContext *ctrlctx;
904 nsresult nsres;
906 if(This->editor) {
907 nsIEditor_Release(This->editor);
908 This->editor = NULL;
911 if(This->editor_controller) {
912 nsIController_Release(This->editor_controller);
913 This->editor_controller = NULL;
916 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
917 (void**)&editing_session);
918 if(NS_FAILED(nsres)) {
919 ERR("Could not get nsIEditingSession: %08x\n", nsres);
920 return;
923 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
924 This->doc->basedoc.window->nswindow, &This->editor);
925 nsIEditingSession_Release(editing_session);
926 if(NS_FAILED(nsres)) {
927 ERR("Could not get editor: %08x\n", nsres);
928 return;
931 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
932 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
933 if(NS_SUCCEEDED(nsres)) {
934 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
935 if(NS_FAILED(nsres))
936 ERR("SetCommandContext failed: %08x\n", nsres);
937 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
938 (void**)&This->editor_controller);
939 nsIControllerContext_Release(ctrlctx);
940 if(NS_FAILED(nsres))
941 ERR("Could not get nsIController interface: %08x\n", nsres);
942 }else {
943 ERR("Could not create edit controller: %08x\n", nsres);
947 void close_gecko(void)
949 TRACE("()\n");
951 release_nsio();
952 init_mutation(NULL);
954 if(profile_directory) {
955 nsIFile_Release(profile_directory);
956 profile_directory = NULL;
959 if(pCompMgr)
960 nsIComponentManager_Release(pCompMgr);
962 if(pServMgr)
963 nsIServiceManager_Release(pServMgr);
965 if(nsmem)
966 nsIMemory_Release(nsmem);
968 /* Gecko doesn't really support being unloaded */
969 /* if (hXPCOM) FreeLibrary(hXPCOM); */
972 BOOL is_gecko_path(const char *path)
974 WCHAR *buf, *ptr;
975 BOOL ret;
977 buf = heap_strdupAtoW(path);
978 if(strlenW(buf) < gecko_path_len)
979 return FALSE;
981 buf[gecko_path_len] = 0;
982 for(ptr = buf; *ptr; ptr++) {
983 if(*ptr == '\\')
984 *ptr = '/';
987 ret = !strcmpiW(buf, gecko_path);
988 heap_free(buf);
989 return ret;
992 /**********************************************************
993 * nsIWebBrowserChrome interface
996 static inline NSContainer *impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome *iface)
998 return CONTAINING_RECORD(iface, NSContainer, nsIWebBrowserChrome_iface);
1001 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
1002 nsIIDRef riid, void **result)
1004 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1006 *result = NULL;
1007 if(IsEqualGUID(&IID_nsISupports, riid)) {
1008 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
1009 *result = &This->nsIWebBrowserChrome_iface;
1010 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
1011 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
1012 *result = &This->nsIWebBrowserChrome_iface;
1013 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
1014 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
1015 *result = &This->nsIContextMenuListener_iface;
1016 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
1017 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
1018 *result = &This->nsIURIContentListener_iface;
1019 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
1020 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
1021 *result = &This->nsIEmbeddingSiteWindow_iface;
1022 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
1023 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
1024 *result = &This->nsITooltipListener_iface;
1025 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
1026 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
1027 *result = &This->nsIInterfaceRequestor_iface;
1028 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
1029 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
1030 *result = &This->nsIWeakReference_iface;
1031 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
1032 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
1033 *result = &This->nsISupportsWeakReference_iface;
1036 if(*result) {
1037 nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1038 return NS_OK;
1041 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1042 return NS_NOINTERFACE;
1045 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
1047 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1048 LONG ref = InterlockedIncrement(&This->ref);
1050 TRACE("(%p) ref=%d\n", This, ref);
1052 return ref;
1055 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
1057 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1058 LONG ref = InterlockedDecrement(&This->ref);
1060 TRACE("(%p) ref=%d\n", This, ref);
1062 if(!ref) {
1063 if(This->parent)
1064 nsIWebBrowserChrome_Release(&This->parent->nsIWebBrowserChrome_iface);
1065 heap_free(This);
1068 return ref;
1071 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1072 PRUint32 statusType, const PRUnichar *status)
1074 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1075 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1076 return NS_OK;
1079 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1080 nsIWebBrowser **aWebBrowser)
1082 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1084 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1086 if(!aWebBrowser)
1087 return NS_ERROR_INVALID_ARG;
1089 if(This->webbrowser)
1090 nsIWebBrowser_AddRef(This->webbrowser);
1091 *aWebBrowser = This->webbrowser;
1092 return S_OK;
1095 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1096 nsIWebBrowser *aWebBrowser)
1098 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1100 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1102 if(aWebBrowser != This->webbrowser)
1103 ERR("Wrong nsWebBrowser!\n");
1105 return NS_OK;
1108 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1109 PRUint32 *aChromeFlags)
1111 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1112 WARN("(%p)->(%p)\n", This, aChromeFlags);
1113 return NS_ERROR_NOT_IMPLEMENTED;
1116 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1117 PRUint32 aChromeFlags)
1119 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1120 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1121 return NS_ERROR_NOT_IMPLEMENTED;
1124 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1126 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1127 TRACE("(%p)\n", This);
1128 return NS_ERROR_NOT_IMPLEMENTED;
1131 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1132 PRInt32 aCX, PRInt32 aCY)
1134 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1135 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1136 return NS_ERROR_NOT_IMPLEMENTED;
1139 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1141 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1142 WARN("(%p)\n", This);
1143 return NS_ERROR_NOT_IMPLEMENTED;
1146 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
1148 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1149 WARN("(%p)->(%p)\n", This, _retval);
1150 return NS_ERROR_NOT_IMPLEMENTED;
1153 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1154 nsresult aStatus)
1156 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1157 WARN("(%p)->(%08x)\n", This, aStatus);
1158 return NS_ERROR_NOT_IMPLEMENTED;
1161 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1162 nsWebBrowserChrome_QueryInterface,
1163 nsWebBrowserChrome_AddRef,
1164 nsWebBrowserChrome_Release,
1165 nsWebBrowserChrome_SetStatus,
1166 nsWebBrowserChrome_GetWebBrowser,
1167 nsWebBrowserChrome_SetWebBrowser,
1168 nsWebBrowserChrome_GetChromeFlags,
1169 nsWebBrowserChrome_SetChromeFlags,
1170 nsWebBrowserChrome_DestroyBrowserWindow,
1171 nsWebBrowserChrome_SizeBrowserTo,
1172 nsWebBrowserChrome_ShowAsModal,
1173 nsWebBrowserChrome_IsWindowModal,
1174 nsWebBrowserChrome_ExitModalEventLoop
1177 /**********************************************************
1178 * nsIContextMenuListener interface
1181 static inline NSContainer *impl_from_nsIContextMenuListener(nsIContextMenuListener *iface)
1183 return CONTAINING_RECORD(iface, NSContainer, nsIContextMenuListener_iface);
1186 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1187 nsIIDRef riid, void **result)
1189 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1190 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1193 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1195 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1196 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1199 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1201 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1202 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1205 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1206 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1208 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1209 nsIDOMMouseEvent *event;
1210 HTMLDOMNode *node;
1211 POINT pt;
1212 DWORD dwID = CONTEXT_MENU_DEFAULT;
1213 nsresult nsres;
1214 HRESULT hres;
1216 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1218 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1220 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1221 if(NS_FAILED(nsres)) {
1222 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1223 return nsres;
1226 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1227 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1228 nsIDOMMouseEvent_Release(event);
1230 switch(aContextFlags) {
1231 case CONTEXT_NONE:
1232 case CONTEXT_DOCUMENT:
1233 case CONTEXT_TEXT:
1234 dwID = CONTEXT_MENU_DEFAULT;
1235 break;
1236 case CONTEXT_IMAGE:
1237 case CONTEXT_IMAGE|CONTEXT_LINK:
1238 dwID = CONTEXT_MENU_IMAGE;
1239 break;
1240 case CONTEXT_LINK:
1241 dwID = CONTEXT_MENU_ANCHOR;
1242 break;
1243 case CONTEXT_INPUT:
1244 dwID = CONTEXT_MENU_CONTROL;
1245 break;
1246 default:
1247 FIXME("aContextFlags=%08x\n", aContextFlags);
1250 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1251 if(FAILED(hres))
1252 return NS_ERROR_FAILURE;
1254 show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
1255 return NS_OK;
1258 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1259 nsContextMenuListener_QueryInterface,
1260 nsContextMenuListener_AddRef,
1261 nsContextMenuListener_Release,
1262 nsContextMenuListener_OnShowContextMenu
1265 /**********************************************************
1266 * nsIURIContentListener interface
1269 static inline NSContainer *impl_from_nsIURIContentListener(nsIURIContentListener *iface)
1271 return CONTAINING_RECORD(iface, NSContainer, nsIURIContentListener_iface);
1274 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1275 nsIIDRef riid, void **result)
1277 NSContainer *This = impl_from_nsIURIContentListener(iface);
1278 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1281 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1283 NSContainer *This = impl_from_nsIURIContentListener(iface);
1284 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1287 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1289 NSContainer *This = impl_from_nsIURIContentListener(iface);
1290 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1293 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1294 nsIURI *aURI, PRBool *_retval)
1296 NSContainer *This = impl_from_nsIURIContentListener(iface);
1297 nsACString spec_str;
1298 const char *spec;
1299 nsresult nsres;
1301 nsACString_Init(&spec_str, NULL);
1302 nsIURI_GetSpec(aURI, &spec_str);
1303 nsACString_GetData(&spec_str, &spec);
1305 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1307 nsACString_Finish(&spec_str);
1309 nsres = on_start_uri_open(This, aURI, _retval);
1310 if(NS_FAILED(nsres))
1311 return nsres;
1313 return !*_retval && This->content_listener
1314 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1315 : NS_OK;
1318 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1319 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1320 nsIStreamListener **aContentHandler, PRBool *_retval)
1322 NSContainer *This = impl_from_nsIURIContentListener(iface);
1324 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1325 aRequest, aContentHandler, _retval);
1327 return This->content_listener
1328 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1329 aIsContentPreferred, aRequest, aContentHandler, _retval)
1330 : NS_ERROR_NOT_IMPLEMENTED;
1333 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1334 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1336 NSContainer *This = impl_from_nsIURIContentListener(iface);
1338 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1340 /* FIXME: Should we do something here? */
1341 *_retval = TRUE;
1343 return This->content_listener
1344 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1345 aDesiredContentType, _retval)
1346 : NS_OK;
1349 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1350 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1351 PRBool *_retval)
1353 NSContainer *This = impl_from_nsIURIContentListener(iface);
1355 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1356 aDesiredContentType, _retval);
1358 return This->content_listener
1359 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1360 aIsContentPreferred, aDesiredContentType, _retval)
1361 : NS_ERROR_NOT_IMPLEMENTED;
1364 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1365 nsISupports **aLoadCookie)
1367 NSContainer *This = impl_from_nsIURIContentListener(iface);
1369 WARN("(%p)->(%p)\n", This, aLoadCookie);
1371 return This->content_listener
1372 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1373 : NS_ERROR_NOT_IMPLEMENTED;
1376 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1377 nsISupports *aLoadCookie)
1379 NSContainer *This = impl_from_nsIURIContentListener(iface);
1381 WARN("(%p)->(%p)\n", This, aLoadCookie);
1383 return This->content_listener
1384 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1385 : NS_ERROR_NOT_IMPLEMENTED;
1388 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1389 nsIURIContentListener **aParentContentListener)
1391 NSContainer *This = impl_from_nsIURIContentListener(iface);
1393 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1395 if(This->content_listener)
1396 nsIURIContentListener_AddRef(This->content_listener);
1398 *aParentContentListener = This->content_listener;
1399 return NS_OK;
1402 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1403 nsIURIContentListener *aParentContentListener)
1405 NSContainer *This = impl_from_nsIURIContentListener(iface);
1407 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1409 if(aParentContentListener == &This->nsIURIContentListener_iface)
1410 return NS_OK;
1412 if(This->content_listener)
1413 nsIURIContentListener_Release(This->content_listener);
1415 This->content_listener = aParentContentListener;
1416 if(This->content_listener)
1417 nsIURIContentListener_AddRef(This->content_listener);
1419 return NS_OK;
1422 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1423 nsURIContentListener_QueryInterface,
1424 nsURIContentListener_AddRef,
1425 nsURIContentListener_Release,
1426 nsURIContentListener_OnStartURIOpen,
1427 nsURIContentListener_DoContent,
1428 nsURIContentListener_IsPreferred,
1429 nsURIContentListener_CanHandleContent,
1430 nsURIContentListener_GetLoadCookie,
1431 nsURIContentListener_SetLoadCookie,
1432 nsURIContentListener_GetParentContentListener,
1433 nsURIContentListener_SetParentContentListener
1436 /**********************************************************
1437 * nsIEmbeddinSiteWindow interface
1440 static inline NSContainer *impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow *iface)
1442 return CONTAINING_RECORD(iface, NSContainer, nsIEmbeddingSiteWindow_iface);
1445 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1446 nsIIDRef riid, void **result)
1448 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1449 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1452 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1454 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1455 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1458 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1460 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1461 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1464 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1465 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1467 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1468 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1469 return NS_ERROR_NOT_IMPLEMENTED;
1472 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1473 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1475 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1476 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1477 return NS_ERROR_NOT_IMPLEMENTED;
1480 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1482 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1484 TRACE("(%p)\n", This);
1486 return nsIBaseWindow_SetFocus(This->window);
1489 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1490 PRBool *aVisibility)
1492 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1494 TRACE("(%p)->(%p)\n", This, aVisibility);
1496 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1497 return NS_OK;
1500 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1501 PRBool aVisibility)
1503 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1505 TRACE("(%p)->(%x)\n", This, aVisibility);
1507 return NS_OK;
1510 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1511 PRUnichar **aTitle)
1513 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1514 WARN("(%p)->(%p)\n", This, aTitle);
1515 return NS_ERROR_NOT_IMPLEMENTED;
1518 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1519 const PRUnichar *aTitle)
1521 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1522 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1523 return NS_ERROR_NOT_IMPLEMENTED;
1526 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1527 void **aSiteWindow)
1529 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1531 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1533 *aSiteWindow = This->hwnd;
1534 return NS_OK;
1537 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1538 nsEmbeddingSiteWindow_QueryInterface,
1539 nsEmbeddingSiteWindow_AddRef,
1540 nsEmbeddingSiteWindow_Release,
1541 nsEmbeddingSiteWindow_SetDimensions,
1542 nsEmbeddingSiteWindow_GetDimensions,
1543 nsEmbeddingSiteWindow_SetFocus,
1544 nsEmbeddingSiteWindow_GetVisibility,
1545 nsEmbeddingSiteWindow_SetVisibility,
1546 nsEmbeddingSiteWindow_GetTitle,
1547 nsEmbeddingSiteWindow_SetTitle,
1548 nsEmbeddingSiteWindow_GetSiteWindow
1551 static inline NSContainer *impl_from_nsITooltipListener(nsITooltipListener *iface)
1553 return CONTAINING_RECORD(iface, NSContainer, nsITooltipListener_iface);
1556 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1557 void **result)
1559 NSContainer *This = impl_from_nsITooltipListener(iface);
1560 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1563 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1565 NSContainer *This = impl_from_nsITooltipListener(iface);
1566 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1569 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1571 NSContainer *This = impl_from_nsITooltipListener(iface);
1572 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1575 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1576 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1578 NSContainer *This = impl_from_nsITooltipListener(iface);
1580 if (This->doc)
1581 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1583 return NS_OK;
1586 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1588 NSContainer *This = impl_from_nsITooltipListener(iface);
1590 if (This->doc)
1591 hide_tooltip(This->doc);
1593 return NS_OK;
1596 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1597 nsTooltipListener_QueryInterface,
1598 nsTooltipListener_AddRef,
1599 nsTooltipListener_Release,
1600 nsTooltipListener_OnShowTooltip,
1601 nsTooltipListener_OnHideTooltip
1604 static inline NSContainer *impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor *iface)
1606 return CONTAINING_RECORD(iface, NSContainer, nsIInterfaceRequestor_iface);
1609 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1610 nsIIDRef riid, void **result)
1612 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1613 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1616 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1618 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1619 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1622 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1624 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1625 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1628 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1629 nsIIDRef riid, void **result)
1631 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1633 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1634 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1635 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1638 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1641 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1642 nsInterfaceRequestor_QueryInterface,
1643 nsInterfaceRequestor_AddRef,
1644 nsInterfaceRequestor_Release,
1645 nsInterfaceRequestor_GetInterface
1648 static inline NSContainer *impl_from_nsIWeakReference(nsIWeakReference *iface)
1650 return CONTAINING_RECORD(iface, NSContainer, nsIWeakReference_iface);
1653 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1654 nsIIDRef riid, void **result)
1656 NSContainer *This = impl_from_nsIWeakReference(iface);
1657 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1660 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1662 NSContainer *This = impl_from_nsIWeakReference(iface);
1663 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1666 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1668 NSContainer *This = impl_from_nsIWeakReference(iface);
1669 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1672 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1673 const nsIID *riid, void **result)
1675 NSContainer *This = impl_from_nsIWeakReference(iface);
1676 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1679 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1680 nsWeakReference_QueryInterface,
1681 nsWeakReference_AddRef,
1682 nsWeakReference_Release,
1683 nsWeakReference_QueryReferent
1686 static inline NSContainer *impl_from_nsISupportsWeakReference(nsISupportsWeakReference *iface)
1688 return CONTAINING_RECORD(iface, NSContainer, nsISupportsWeakReference_iface);
1691 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1692 nsIIDRef riid, void **result)
1694 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1695 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1698 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1700 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1701 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1704 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1706 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1707 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1710 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1711 nsIWeakReference **_retval)
1713 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1715 TRACE("(%p)->(%p)\n", This, _retval);
1717 nsIWeakReference_AddRef(&This->nsIWeakReference_iface);
1718 *_retval = &This->nsIWeakReference_iface;
1719 return NS_OK;
1722 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1723 nsSupportsWeakReference_QueryInterface,
1724 nsSupportsWeakReference_AddRef,
1725 nsSupportsWeakReference_Release,
1726 nsSupportsWeakReference_GetWeakReference
1729 nsresult create_chrome_window(nsIWebBrowserChrome *parent, nsIWebBrowserChrome **ret)
1731 NSContainer *new_container;
1733 if(parent->lpVtbl != &nsWebBrowserChromeVtbl)
1734 return NS_ERROR_UNEXPECTED;
1736 new_container = NSContainer_Create(NULL, impl_from_nsIWebBrowserChrome(parent));
1737 *ret = &new_container->nsIWebBrowserChrome_iface;
1738 return NS_OK;
1741 NSContainer *NSContainer_Create(HTMLDocumentObj *doc, NSContainer *parent)
1743 nsIWebBrowserSetup *wbsetup;
1744 nsIScrollable *scrollable;
1745 NSContainer *ret;
1746 nsresult nsres;
1748 if(!load_gecko(TRUE))
1749 return NULL;
1751 ret = heap_alloc_zero(sizeof(NSContainer));
1753 ret->nsIWebBrowserChrome_iface.lpVtbl = &nsWebBrowserChromeVtbl;
1754 ret->nsIContextMenuListener_iface.lpVtbl = &nsContextMenuListenerVtbl;
1755 ret->nsIURIContentListener_iface.lpVtbl = &nsURIContentListenerVtbl;
1756 ret->nsIEmbeddingSiteWindow_iface.lpVtbl = &nsEmbeddingSiteWindowVtbl;
1757 ret->nsITooltipListener_iface.lpVtbl = &nsTooltipListenerVtbl;
1758 ret->nsIInterfaceRequestor_iface.lpVtbl = &nsInterfaceRequestorVtbl;
1759 ret->nsIWeakReference_iface.lpVtbl = &nsWeakReferenceVtbl;
1760 ret->nsISupportsWeakReference_iface.lpVtbl = &nsSupportsWeakReferenceVtbl;
1762 ret->doc = doc;
1763 ret->ref = 1;
1765 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1766 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1767 if(NS_FAILED(nsres)) {
1768 ERR("Creating WebBrowser failed: %08x\n", nsres);
1769 heap_free(ret);
1770 return NULL;
1773 if(parent)
1774 nsIWebBrowserChrome_AddRef(&parent->nsIWebBrowserChrome_iface);
1775 ret->parent = parent;
1777 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, &ret->nsIWebBrowserChrome_iface);
1778 if(NS_FAILED(nsres))
1779 ERR("SetContainerWindow failed: %08x\n", nsres);
1781 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1782 (void**)&ret->window);
1783 if(NS_FAILED(nsres))
1784 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1786 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1787 (void**)&wbsetup);
1788 if(NS_SUCCEEDED(nsres)) {
1789 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1790 nsIWebBrowserSetup_Release(wbsetup);
1791 if(NS_FAILED(nsres))
1792 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1793 }else {
1794 ERR("Could not get nsIWebBrowserSetup interface\n");
1797 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1798 (void**)&ret->navigation);
1799 if(NS_FAILED(nsres))
1800 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1802 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1803 (void**)&ret->focus);
1804 if(NS_FAILED(nsres))
1805 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1807 if(!nscontainer_class)
1808 register_nscontainer_class();
1810 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1811 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1812 GetDesktopWindow(), NULL, hInst, ret);
1814 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1815 if(NS_SUCCEEDED(nsres)) {
1816 nsres = nsIBaseWindow_Create(ret->window);
1817 if(NS_FAILED(nsres))
1818 WARN("Creating window failed: %08x\n", nsres);
1820 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1821 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1822 }else {
1823 ERR("InitWindow failed: %08x\n", nsres);
1826 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser,
1827 &ret->nsIURIContentListener_iface);
1828 if(NS_FAILED(nsres))
1829 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1831 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1832 if(NS_SUCCEEDED(nsres)) {
1833 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1834 ScrollOrientation_Y, Scrollbar_Always);
1835 if(NS_FAILED(nsres))
1836 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1838 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1839 ScrollOrientation_X, Scrollbar_Auto);
1840 if(NS_FAILED(nsres))
1841 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1843 nsIScrollable_Release(scrollable);
1844 }else {
1845 ERR("Could not get nsIScrollable: %08x\n", nsres);
1848 return ret;
1851 void NSContainer_Release(NSContainer *This)
1853 TRACE("(%p)\n", This);
1855 This->doc = NULL;
1857 ShowWindow(This->hwnd, SW_HIDE);
1858 SetParent(This->hwnd, NULL);
1860 nsIBaseWindow_SetVisibility(This->window, FALSE);
1861 nsIBaseWindow_Destroy(This->window);
1863 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1865 nsIWebBrowser_Release(This->webbrowser);
1866 This->webbrowser = NULL;
1868 nsIWebNavigation_Release(This->navigation);
1869 This->navigation = NULL;
1871 nsIBaseWindow_Release(This->window);
1872 This->window = NULL;
1874 nsIWebBrowserFocus_Release(This->focus);
1875 This->focus = NULL;
1877 if(This->editor_controller) {
1878 nsIController_Release(This->editor_controller);
1879 This->editor_controller = NULL;
1882 if(This->editor) {
1883 nsIEditor_Release(This->editor);
1884 This->editor = NULL;
1887 if(This->content_listener) {
1888 nsIURIContentListener_Release(This->content_listener);
1889 This->content_listener = NULL;
1892 if(This->hwnd) {
1893 DestroyWindow(This->hwnd);
1894 This->hwnd = NULL;
1897 nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);