ntdll/tests: Run the execution test only on x86 platforms.
[wine/multimedia.git] / dlls / mshtml / nsembed.c
blobb6de72f45875187d726cf065933820bc6bd762c8
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_preferences(void)
491 nsIPrefBranch *pref;
492 nsresult nsres;
494 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
495 &IID_nsIPrefBranch, (void**)&pref);
496 if(NS_FAILED(nsres)) {
497 ERR("Could not get preference service: %08x\n", nsres);
498 return;
501 set_lang(pref);
502 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
503 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
504 set_int_pref(pref, "layout.spellcheckDefault", 0);
506 nsIPrefBranch_Release(pref);
509 static BOOL init_xpcom(const PRUnichar *gre_path)
511 nsIComponentRegistrar *registrar = NULL;
512 nsAString path;
513 nsIFile *gre_dir;
514 WCHAR *ptr;
515 nsresult nsres;
517 nsAString_InitDepend(&path, gre_path);
518 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
519 nsAString_Finish(&path);
520 if(NS_FAILED(nsres)) {
521 ERR("NS_NewLocalFile failed: %08x\n", nsres);
522 FreeLibrary(xul_handle);
523 return FALSE;
526 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, &nsDirectoryServiceProvider);
527 if(NS_FAILED(nsres)) {
528 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
529 FreeLibrary(xul_handle);
530 return FALSE;
533 strcpyW(gecko_path, gre_path);
534 for(ptr = gecko_path; *ptr; ptr++) {
535 if(*ptr == '\\')
536 *ptr = '/';
538 gecko_path_len = ptr-gecko_path;
540 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
541 if(NS_FAILED(nsres))
542 ERR("Could not get nsIComponentManager: %08x\n", nsres);
544 nsres = NS_GetComponentRegistrar(&registrar);
545 if(NS_SUCCEEDED(nsres))
546 init_nsio(pCompMgr, registrar);
547 else
548 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
550 init_mutation(pCompMgr);
551 set_preferences();
553 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
554 NULL, &IID_nsIMemory, (void**)&nsmem);
555 if(NS_FAILED(nsres))
556 ERR("Could not get nsIMemory: %08x\n", nsres);
558 if(registrar) {
559 register_nsservice(registrar, pServMgr);
560 nsIComponentRegistrar_Release(registrar);
563 return TRUE;
566 static CRITICAL_SECTION cs_load_gecko;
567 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
569 0, 0, &cs_load_gecko,
570 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
571 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
573 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
575 BOOL load_gecko(BOOL silent)
577 PRUnichar gre_path[MAX_PATH];
578 BOOL ret = FALSE;
580 static DWORD loading_thread;
582 TRACE("()\n");
584 /* load_gecko may be called recursively */
585 if(loading_thread == GetCurrentThreadId())
586 return pCompMgr != NULL;
588 EnterCriticalSection(&cs_load_gecko);
590 if(!loading_thread) {
591 loading_thread = GetCurrentThreadId();
593 if(load_wine_gecko(gre_path)
594 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
595 ret = init_xpcom(gre_path);
596 else
597 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
598 }else {
599 ret = pCompMgr != NULL;
602 LeaveCriticalSection(&cs_load_gecko);
604 return ret;
607 void *nsalloc(size_t size)
609 return nsIMemory_Alloc(nsmem, size);
612 void nsfree(void *mem)
614 nsIMemory_Free(nsmem, mem);
617 static BOOL nsACString_Init(nsACString *str, const char *data)
619 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
623 * Initializes nsACString with data owned by caller.
624 * Caller must ensure that data is valid during lifetime of string object.
626 void nsACString_InitDepend(nsACString *str, const char *data)
628 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
631 void nsACString_SetData(nsACString *str, const char *data)
633 NS_CStringSetData(str, data, PR_UINT32_MAX);
636 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
638 return NS_CStringGetData(str, data, NULL);
641 void nsACString_Finish(nsACString *str)
643 NS_CStringContainerFinish(str);
646 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
648 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
652 * Initializes nsAString with data owned by caller.
653 * Caller must ensure that data is valid during lifetime of string object.
655 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
657 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
660 void nsAString_SetData(nsAString *str, const PRUnichar *data)
662 NS_StringSetData(str, data, PR_UINT32_MAX);
665 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
667 return NS_StringGetData(str, data, NULL);
670 void nsAString_Finish(nsAString *str)
672 NS_StringContainerFinish(str);
675 HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
677 const PRUnichar *str;
679 if(NS_FAILED(nsres)) {
680 ERR("failed: %08x\n", nsres);
681 nsAString_Finish(nsstr);
682 return E_FAIL;
685 nsAString_GetData(nsstr, &str);
686 TRACE("ret %s\n", debugstr_w(str));
687 if(*str) {
688 *p = SysAllocString(str);
689 if(!*p)
690 return E_OUTOFMEMORY;
691 }else {
692 *p = NULL;
695 nsAString_Finish(nsstr);
696 return S_OK;
699 nsICommandParams *create_nscommand_params(void)
701 nsICommandParams *ret = NULL;
702 nsresult nsres;
704 if(!pCompMgr)
705 return NULL;
707 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
708 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
709 (void**)&ret);
710 if(NS_FAILED(nsres))
711 ERR("Could not get nsICommandParams\n");
713 return ret;
716 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
718 nsIInterfaceRequestor *iface_req;
719 nsresult nsres;
721 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
722 if(NS_FAILED(nsres))
723 return nsres;
725 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
726 nsIInterfaceRequestor_Release(iface_req);
728 return nsres;
731 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
733 nsIDOMNodeList *node_list = NULL;
734 PRBool has_children = FALSE;
735 nsIContent *nscontent;
736 PRUint16 type;
737 nsresult nsres;
739 nsIDOMNode_HasChildNodes(nsnode, &has_children);
741 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
742 if(NS_FAILED(nsres)) {
743 ERR("GetType failed: %08x\n", nsres);
744 return E_FAIL;
747 if(type != DOCUMENT_NODE) {
748 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
749 if(NS_FAILED(nsres)) {
750 ERR("Could not get nsIContent interface: %08x\n", nsres);
751 return E_FAIL;
755 switch(type) {
756 case ELEMENT_NODE:
757 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
758 break;
759 case TEXT_NODE:
760 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
761 break;
762 case COMMENT_NODE:
763 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
764 break;
765 case DOCUMENT_NODE: {
766 nsIDocument *nsdoc;
767 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
768 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
769 nsIDocument_Release(nsdoc);
770 break;
772 case DOCUMENT_TYPE_NODE:
773 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
774 break;
775 case DOCUMENT_FRAGMENT_NODE:
776 break;
777 default:
778 FIXME("Unhandled type %u\n", type);
781 if(has_children) {
782 PRUint32 child_cnt, i;
783 nsIDOMNode *child_node;
785 nsIDOMNode_GetChildNodes(nsnode, &node_list);
786 nsIDOMNodeList_GetLength(node_list, &child_cnt);
788 for(i=0; i<child_cnt; i++) {
789 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
790 if(NS_SUCCEEDED(nsres)) {
791 nsnode_to_nsstring_rec(serializer, child_node, str);
792 nsIDOMNode_Release(child_node);
793 }else {
794 ERR("Item failed: %08x\n", nsres);
798 nsIDOMNodeList_Release(node_list);
801 if(type == ELEMENT_NODE)
802 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
804 if(type != DOCUMENT_NODE)
805 nsIContent_Release(nscontent);
806 return S_OK;
809 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
811 nsIContentSerializer *serializer;
812 nsresult nsres;
813 HRESULT hres;
815 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
816 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
817 (void**)&serializer);
818 if(NS_FAILED(nsres)) {
819 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
820 return E_FAIL;
823 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
824 if(NS_FAILED(nsres))
825 ERR("Init failed: %08x\n", nsres);
827 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
828 if(SUCCEEDED(hres)) {
829 nsres = nsIContentSerializer_Flush(serializer, str);
830 if(NS_FAILED(nsres))
831 ERR("Flush failed: %08x\n", nsres);
834 nsIContentSerializer_Release(serializer);
835 return hres;
838 void get_editor_controller(NSContainer *This)
840 nsIEditingSession *editing_session = NULL;
841 nsIControllerContext *ctrlctx;
842 nsresult nsres;
844 if(This->editor) {
845 nsIEditor_Release(This->editor);
846 This->editor = NULL;
849 if(This->editor_controller) {
850 nsIController_Release(This->editor_controller);
851 This->editor_controller = NULL;
854 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
855 (void**)&editing_session);
856 if(NS_FAILED(nsres)) {
857 ERR("Could not get nsIEditingSession: %08x\n", nsres);
858 return;
861 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
862 This->doc->basedoc.window->nswindow, &This->editor);
863 nsIEditingSession_Release(editing_session);
864 if(NS_FAILED(nsres)) {
865 ERR("Could not get editor: %08x\n", nsres);
866 return;
869 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
870 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
871 if(NS_SUCCEEDED(nsres)) {
872 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
873 if(NS_FAILED(nsres))
874 ERR("SetCommandContext failed: %08x\n", nsres);
875 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
876 (void**)&This->editor_controller);
877 nsIControllerContext_Release(ctrlctx);
878 if(NS_FAILED(nsres))
879 ERR("Could not get nsIController interface: %08x\n", nsres);
880 }else {
881 ERR("Could not create edit controller: %08x\n", nsres);
885 void close_gecko(void)
887 TRACE("()\n");
889 release_nsio();
890 init_mutation(NULL);
892 if(profile_directory) {
893 nsIFile_Release(profile_directory);
894 profile_directory = NULL;
897 if(pCompMgr)
898 nsIComponentManager_Release(pCompMgr);
900 if(pServMgr)
901 nsIServiceManager_Release(pServMgr);
903 if(nsmem)
904 nsIMemory_Release(nsmem);
906 /* Gecko doesn't really support being unloaded */
907 /* if (hXPCOM) FreeLibrary(hXPCOM); */
910 BOOL is_gecko_path(const char *path)
912 WCHAR *buf, *ptr;
913 BOOL ret;
915 buf = heap_strdupAtoW(path);
916 if(strlenW(buf) < gecko_path_len)
917 return FALSE;
919 buf[gecko_path_len] = 0;
920 for(ptr = buf; *ptr; ptr++) {
921 if(*ptr == '\\')
922 *ptr = '/';
925 ret = !strcmpiW(buf, gecko_path);
926 heap_free(buf);
927 return ret;
930 struct nsWeakReference {
931 nsIWeakReference nsIWeakReference_iface;
933 LONG ref;
935 NSContainer *nscontainer;
938 static inline nsWeakReference *impl_from_nsIWeakReference(nsIWeakReference *iface)
940 return CONTAINING_RECORD(iface, nsWeakReference, nsIWeakReference_iface);
943 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
944 nsIIDRef riid, void **result)
946 nsWeakReference *This = impl_from_nsIWeakReference(iface);
948 if(IsEqualGUID(&IID_nsISupports, riid)) {
949 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
950 *result = &This->nsIWeakReference_iface;
951 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
952 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
953 *result = &This->nsIWeakReference_iface;
954 }else {
955 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
956 *result = NULL;
957 return NS_NOINTERFACE;
960 nsISupports_AddRef((nsISupports*)*result);
961 return NS_OK;
964 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
966 nsWeakReference *This = impl_from_nsIWeakReference(iface);
967 LONG ref = InterlockedIncrement(&This->ref);
969 TRACE("(%p) ref=%d\n", This, ref);
971 return ref;
974 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
976 nsWeakReference *This = impl_from_nsIWeakReference(iface);
977 LONG ref = InterlockedIncrement(&This->ref);
979 TRACE("(%p) ref=%d\n", This, ref);
981 if(!ref) {
982 assert(!This->nscontainer);
983 heap_free(This);
986 return ref;
989 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
990 const nsIID *riid, void **result)
992 nsWeakReference *This = impl_from_nsIWeakReference(iface);
994 if(!This->nscontainer)
995 return NS_ERROR_NULL_POINTER;
997 return nsIWebBrowserChrome_QueryInterface(&This->nscontainer->nsIWebBrowserChrome_iface, riid, result);
1000 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1001 nsWeakReference_QueryInterface,
1002 nsWeakReference_AddRef,
1003 nsWeakReference_Release,
1004 nsWeakReference_QueryReferent
1007 /**********************************************************
1008 * nsIWebBrowserChrome interface
1011 static inline NSContainer *impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome *iface)
1013 return CONTAINING_RECORD(iface, NSContainer, nsIWebBrowserChrome_iface);
1016 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
1017 nsIIDRef riid, void **result)
1019 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1021 *result = NULL;
1022 if(IsEqualGUID(&IID_nsISupports, riid)) {
1023 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
1024 *result = &This->nsIWebBrowserChrome_iface;
1025 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
1026 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
1027 *result = &This->nsIWebBrowserChrome_iface;
1028 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
1029 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
1030 *result = &This->nsIContextMenuListener_iface;
1031 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
1032 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
1033 *result = &This->nsIURIContentListener_iface;
1034 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
1035 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
1036 *result = &This->nsIEmbeddingSiteWindow_iface;
1037 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
1038 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
1039 *result = &This->nsITooltipListener_iface;
1040 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
1041 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
1042 *result = &This->nsIInterfaceRequestor_iface;
1043 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
1044 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
1045 *result = &This->nsISupportsWeakReference_iface;
1048 if(*result) {
1049 nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1050 return NS_OK;
1053 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1054 return NS_NOINTERFACE;
1057 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
1059 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1060 LONG ref = InterlockedIncrement(&This->ref);
1062 TRACE("(%p) ref=%d\n", This, ref);
1064 return ref;
1067 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
1069 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1070 LONG ref = InterlockedDecrement(&This->ref);
1072 TRACE("(%p) ref=%d\n", This, ref);
1074 if(!ref) {
1075 if(This->parent)
1076 nsIWebBrowserChrome_Release(&This->parent->nsIWebBrowserChrome_iface);
1077 if(This->weak_reference) {
1078 This->weak_reference->nscontainer = NULL;
1079 nsIWeakReference_Release(&This->weak_reference->nsIWeakReference_iface);
1081 heap_free(This);
1084 return ref;
1087 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1088 PRUint32 statusType, const PRUnichar *status)
1090 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1091 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1092 return NS_OK;
1095 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1096 nsIWebBrowser **aWebBrowser)
1098 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1100 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1102 if(!aWebBrowser)
1103 return NS_ERROR_INVALID_ARG;
1105 if(This->webbrowser)
1106 nsIWebBrowser_AddRef(This->webbrowser);
1107 *aWebBrowser = This->webbrowser;
1108 return S_OK;
1111 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1112 nsIWebBrowser *aWebBrowser)
1114 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1116 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1118 if(aWebBrowser != This->webbrowser)
1119 ERR("Wrong nsWebBrowser!\n");
1121 return NS_OK;
1124 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1125 PRUint32 *aChromeFlags)
1127 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1128 WARN("(%p)->(%p)\n", This, aChromeFlags);
1129 return NS_ERROR_NOT_IMPLEMENTED;
1132 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1133 PRUint32 aChromeFlags)
1135 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1136 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1137 return NS_ERROR_NOT_IMPLEMENTED;
1140 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1142 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1143 TRACE("(%p)\n", This);
1144 return NS_ERROR_NOT_IMPLEMENTED;
1147 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1148 PRInt32 aCX, PRInt32 aCY)
1150 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1151 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1152 return NS_ERROR_NOT_IMPLEMENTED;
1155 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1157 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1158 WARN("(%p)\n", This);
1159 return NS_ERROR_NOT_IMPLEMENTED;
1162 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
1164 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1165 WARN("(%p)->(%p)\n", This, _retval);
1166 return NS_ERROR_NOT_IMPLEMENTED;
1169 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1170 nsresult aStatus)
1172 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1173 WARN("(%p)->(%08x)\n", This, aStatus);
1174 return NS_ERROR_NOT_IMPLEMENTED;
1177 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1178 nsWebBrowserChrome_QueryInterface,
1179 nsWebBrowserChrome_AddRef,
1180 nsWebBrowserChrome_Release,
1181 nsWebBrowserChrome_SetStatus,
1182 nsWebBrowserChrome_GetWebBrowser,
1183 nsWebBrowserChrome_SetWebBrowser,
1184 nsWebBrowserChrome_GetChromeFlags,
1185 nsWebBrowserChrome_SetChromeFlags,
1186 nsWebBrowserChrome_DestroyBrowserWindow,
1187 nsWebBrowserChrome_SizeBrowserTo,
1188 nsWebBrowserChrome_ShowAsModal,
1189 nsWebBrowserChrome_IsWindowModal,
1190 nsWebBrowserChrome_ExitModalEventLoop
1193 /**********************************************************
1194 * nsIContextMenuListener interface
1197 static inline NSContainer *impl_from_nsIContextMenuListener(nsIContextMenuListener *iface)
1199 return CONTAINING_RECORD(iface, NSContainer, nsIContextMenuListener_iface);
1202 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1203 nsIIDRef riid, void **result)
1205 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1206 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1209 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1211 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1212 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1215 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1217 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1218 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1221 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1222 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1224 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1225 nsIDOMMouseEvent *event;
1226 HTMLDOMNode *node;
1227 POINT pt;
1228 DWORD dwID = CONTEXT_MENU_DEFAULT;
1229 nsresult nsres;
1230 HRESULT hres;
1232 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1234 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1236 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1237 if(NS_FAILED(nsres)) {
1238 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1239 return nsres;
1242 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1243 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1244 nsIDOMMouseEvent_Release(event);
1246 switch(aContextFlags) {
1247 case CONTEXT_NONE:
1248 case CONTEXT_DOCUMENT:
1249 case CONTEXT_TEXT:
1250 dwID = CONTEXT_MENU_DEFAULT;
1251 break;
1252 case CONTEXT_IMAGE:
1253 case CONTEXT_IMAGE|CONTEXT_LINK:
1254 dwID = CONTEXT_MENU_IMAGE;
1255 break;
1256 case CONTEXT_LINK:
1257 dwID = CONTEXT_MENU_ANCHOR;
1258 break;
1259 case CONTEXT_INPUT:
1260 dwID = CONTEXT_MENU_CONTROL;
1261 break;
1262 default:
1263 FIXME("aContextFlags=%08x\n", aContextFlags);
1266 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1267 if(FAILED(hres))
1268 return NS_ERROR_FAILURE;
1270 show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
1271 return NS_OK;
1274 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1275 nsContextMenuListener_QueryInterface,
1276 nsContextMenuListener_AddRef,
1277 nsContextMenuListener_Release,
1278 nsContextMenuListener_OnShowContextMenu
1281 /**********************************************************
1282 * nsIURIContentListener interface
1285 static inline NSContainer *impl_from_nsIURIContentListener(nsIURIContentListener *iface)
1287 return CONTAINING_RECORD(iface, NSContainer, nsIURIContentListener_iface);
1290 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1291 nsIIDRef riid, void **result)
1293 NSContainer *This = impl_from_nsIURIContentListener(iface);
1294 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1297 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1299 NSContainer *This = impl_from_nsIURIContentListener(iface);
1300 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1303 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1305 NSContainer *This = impl_from_nsIURIContentListener(iface);
1306 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1309 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1310 nsIURI *aURI, PRBool *_retval)
1312 NSContainer *This = impl_from_nsIURIContentListener(iface);
1313 nsACString spec_str;
1314 const char *spec;
1315 nsresult nsres;
1317 nsACString_Init(&spec_str, NULL);
1318 nsIURI_GetSpec(aURI, &spec_str);
1319 nsACString_GetData(&spec_str, &spec);
1321 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1323 nsACString_Finish(&spec_str);
1325 nsres = on_start_uri_open(This, aURI, _retval);
1326 if(NS_FAILED(nsres))
1327 return nsres;
1329 return !*_retval && This->content_listener
1330 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1331 : NS_OK;
1334 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1335 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1336 nsIStreamListener **aContentHandler, PRBool *_retval)
1338 NSContainer *This = impl_from_nsIURIContentListener(iface);
1340 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1341 aRequest, aContentHandler, _retval);
1343 return This->content_listener
1344 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1345 aIsContentPreferred, aRequest, aContentHandler, _retval)
1346 : NS_ERROR_NOT_IMPLEMENTED;
1349 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1350 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1352 NSContainer *This = impl_from_nsIURIContentListener(iface);
1354 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1356 /* FIXME: Should we do something here? */
1357 *_retval = TRUE;
1359 return This->content_listener
1360 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1361 aDesiredContentType, _retval)
1362 : NS_OK;
1365 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1366 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1367 PRBool *_retval)
1369 NSContainer *This = impl_from_nsIURIContentListener(iface);
1371 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1372 aDesiredContentType, _retval);
1374 return This->content_listener
1375 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1376 aIsContentPreferred, aDesiredContentType, _retval)
1377 : NS_ERROR_NOT_IMPLEMENTED;
1380 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1381 nsISupports **aLoadCookie)
1383 NSContainer *This = impl_from_nsIURIContentListener(iface);
1385 WARN("(%p)->(%p)\n", This, aLoadCookie);
1387 return This->content_listener
1388 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1389 : NS_ERROR_NOT_IMPLEMENTED;
1392 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1393 nsISupports *aLoadCookie)
1395 NSContainer *This = impl_from_nsIURIContentListener(iface);
1397 WARN("(%p)->(%p)\n", This, aLoadCookie);
1399 return This->content_listener
1400 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1401 : NS_ERROR_NOT_IMPLEMENTED;
1404 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1405 nsIURIContentListener **aParentContentListener)
1407 NSContainer *This = impl_from_nsIURIContentListener(iface);
1409 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1411 if(This->content_listener)
1412 nsIURIContentListener_AddRef(This->content_listener);
1414 *aParentContentListener = This->content_listener;
1415 return NS_OK;
1418 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1419 nsIURIContentListener *aParentContentListener)
1421 NSContainer *This = impl_from_nsIURIContentListener(iface);
1423 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1425 if(aParentContentListener == &This->nsIURIContentListener_iface)
1426 return NS_OK;
1428 if(This->content_listener)
1429 nsIURIContentListener_Release(This->content_listener);
1431 This->content_listener = aParentContentListener;
1432 if(This->content_listener)
1433 nsIURIContentListener_AddRef(This->content_listener);
1435 return NS_OK;
1438 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1439 nsURIContentListener_QueryInterface,
1440 nsURIContentListener_AddRef,
1441 nsURIContentListener_Release,
1442 nsURIContentListener_OnStartURIOpen,
1443 nsURIContentListener_DoContent,
1444 nsURIContentListener_IsPreferred,
1445 nsURIContentListener_CanHandleContent,
1446 nsURIContentListener_GetLoadCookie,
1447 nsURIContentListener_SetLoadCookie,
1448 nsURIContentListener_GetParentContentListener,
1449 nsURIContentListener_SetParentContentListener
1452 /**********************************************************
1453 * nsIEmbeddinSiteWindow interface
1456 static inline NSContainer *impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow *iface)
1458 return CONTAINING_RECORD(iface, NSContainer, nsIEmbeddingSiteWindow_iface);
1461 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1462 nsIIDRef riid, void **result)
1464 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1465 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1468 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1470 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1471 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1474 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1476 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1477 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1480 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1481 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1483 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1484 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1485 return NS_ERROR_NOT_IMPLEMENTED;
1488 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1489 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1491 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1492 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1493 return NS_ERROR_NOT_IMPLEMENTED;
1496 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1498 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1500 TRACE("(%p)\n", This);
1502 return nsIBaseWindow_SetFocus(This->window);
1505 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1506 PRBool *aVisibility)
1508 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1510 TRACE("(%p)->(%p)\n", This, aVisibility);
1512 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1513 return NS_OK;
1516 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1517 PRBool aVisibility)
1519 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1521 TRACE("(%p)->(%x)\n", This, aVisibility);
1523 return NS_OK;
1526 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1527 PRUnichar **aTitle)
1529 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1530 WARN("(%p)->(%p)\n", This, aTitle);
1531 return NS_ERROR_NOT_IMPLEMENTED;
1534 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1535 const PRUnichar *aTitle)
1537 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1538 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1539 return NS_ERROR_NOT_IMPLEMENTED;
1542 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1543 void **aSiteWindow)
1545 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1547 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1549 *aSiteWindow = This->hwnd;
1550 return NS_OK;
1553 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1554 nsEmbeddingSiteWindow_QueryInterface,
1555 nsEmbeddingSiteWindow_AddRef,
1556 nsEmbeddingSiteWindow_Release,
1557 nsEmbeddingSiteWindow_SetDimensions,
1558 nsEmbeddingSiteWindow_GetDimensions,
1559 nsEmbeddingSiteWindow_SetFocus,
1560 nsEmbeddingSiteWindow_GetVisibility,
1561 nsEmbeddingSiteWindow_SetVisibility,
1562 nsEmbeddingSiteWindow_GetTitle,
1563 nsEmbeddingSiteWindow_SetTitle,
1564 nsEmbeddingSiteWindow_GetSiteWindow
1567 static inline NSContainer *impl_from_nsITooltipListener(nsITooltipListener *iface)
1569 return CONTAINING_RECORD(iface, NSContainer, nsITooltipListener_iface);
1572 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1573 void **result)
1575 NSContainer *This = impl_from_nsITooltipListener(iface);
1576 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1579 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1581 NSContainer *This = impl_from_nsITooltipListener(iface);
1582 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1585 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1587 NSContainer *This = impl_from_nsITooltipListener(iface);
1588 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1591 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1592 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1594 NSContainer *This = impl_from_nsITooltipListener(iface);
1596 if (This->doc)
1597 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1599 return NS_OK;
1602 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1604 NSContainer *This = impl_from_nsITooltipListener(iface);
1606 if (This->doc)
1607 hide_tooltip(This->doc);
1609 return NS_OK;
1612 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1613 nsTooltipListener_QueryInterface,
1614 nsTooltipListener_AddRef,
1615 nsTooltipListener_Release,
1616 nsTooltipListener_OnShowTooltip,
1617 nsTooltipListener_OnHideTooltip
1620 static inline NSContainer *impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor *iface)
1622 return CONTAINING_RECORD(iface, NSContainer, nsIInterfaceRequestor_iface);
1625 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1626 nsIIDRef riid, void **result)
1628 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1629 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1632 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1634 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1635 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1638 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1640 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1641 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1644 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1645 nsIIDRef riid, void **result)
1647 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1649 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1650 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1651 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1654 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1657 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1658 nsInterfaceRequestor_QueryInterface,
1659 nsInterfaceRequestor_AddRef,
1660 nsInterfaceRequestor_Release,
1661 nsInterfaceRequestor_GetInterface
1664 static inline NSContainer *impl_from_nsISupportsWeakReference(nsISupportsWeakReference *iface)
1666 return CONTAINING_RECORD(iface, NSContainer, nsISupportsWeakReference_iface);
1669 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1670 nsIIDRef riid, void **result)
1672 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1673 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1676 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1678 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1679 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1682 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1684 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1685 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1688 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1689 nsIWeakReference **_retval)
1691 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1693 TRACE("(%p)->(%p)\n", This, _retval);
1695 if(!This->weak_reference) {
1696 This->weak_reference = heap_alloc(sizeof(nsWeakReference));
1697 if(!This->weak_reference)
1698 return NS_ERROR_OUT_OF_MEMORY;
1700 This->weak_reference->nsIWeakReference_iface.lpVtbl = &nsWeakReferenceVtbl;
1701 This->weak_reference->ref = 1;
1702 This->weak_reference->nscontainer = This;
1705 *_retval = &This->weak_reference->nsIWeakReference_iface;
1706 nsIWeakReference_AddRef(*_retval);
1707 return NS_OK;
1710 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1711 nsSupportsWeakReference_QueryInterface,
1712 nsSupportsWeakReference_AddRef,
1713 nsSupportsWeakReference_Release,
1714 nsSupportsWeakReference_GetWeakReference
1717 nsresult create_chrome_window(nsIWebBrowserChrome *parent, nsIWebBrowserChrome **ret)
1719 NSContainer *new_container;
1721 if(parent->lpVtbl != &nsWebBrowserChromeVtbl)
1722 return NS_ERROR_UNEXPECTED;
1724 new_container = NSContainer_Create(NULL, impl_from_nsIWebBrowserChrome(parent));
1725 *ret = &new_container->nsIWebBrowserChrome_iface;
1726 return NS_OK;
1729 NSContainer *NSContainer_Create(HTMLDocumentObj *doc, NSContainer *parent)
1731 nsIWebBrowserSetup *wbsetup;
1732 nsIScrollable *scrollable;
1733 NSContainer *ret;
1734 nsresult nsres;
1736 if(!load_gecko(TRUE))
1737 return NULL;
1739 ret = heap_alloc_zero(sizeof(NSContainer));
1741 ret->nsIWebBrowserChrome_iface.lpVtbl = &nsWebBrowserChromeVtbl;
1742 ret->nsIContextMenuListener_iface.lpVtbl = &nsContextMenuListenerVtbl;
1743 ret->nsIURIContentListener_iface.lpVtbl = &nsURIContentListenerVtbl;
1744 ret->nsIEmbeddingSiteWindow_iface.lpVtbl = &nsEmbeddingSiteWindowVtbl;
1745 ret->nsITooltipListener_iface.lpVtbl = &nsTooltipListenerVtbl;
1746 ret->nsIInterfaceRequestor_iface.lpVtbl = &nsInterfaceRequestorVtbl;
1747 ret->nsISupportsWeakReference_iface.lpVtbl = &nsSupportsWeakReferenceVtbl;
1749 ret->doc = doc;
1750 ret->ref = 1;
1752 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1753 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1754 if(NS_FAILED(nsres)) {
1755 ERR("Creating WebBrowser failed: %08x\n", nsres);
1756 heap_free(ret);
1757 return NULL;
1760 if(parent)
1761 nsIWebBrowserChrome_AddRef(&parent->nsIWebBrowserChrome_iface);
1762 ret->parent = parent;
1764 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, &ret->nsIWebBrowserChrome_iface);
1765 if(NS_FAILED(nsres))
1766 ERR("SetContainerWindow failed: %08x\n", nsres);
1768 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1769 (void**)&ret->window);
1770 if(NS_FAILED(nsres))
1771 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1773 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1774 (void**)&wbsetup);
1775 if(NS_SUCCEEDED(nsres)) {
1776 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1777 nsIWebBrowserSetup_Release(wbsetup);
1778 if(NS_FAILED(nsres))
1779 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1780 }else {
1781 ERR("Could not get nsIWebBrowserSetup interface\n");
1784 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1785 (void**)&ret->navigation);
1786 if(NS_FAILED(nsres))
1787 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1789 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1790 (void**)&ret->focus);
1791 if(NS_FAILED(nsres))
1792 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1794 if(!nscontainer_class)
1795 register_nscontainer_class();
1797 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1798 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1799 GetDesktopWindow(), NULL, hInst, ret);
1801 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1802 if(NS_SUCCEEDED(nsres)) {
1803 nsres = nsIBaseWindow_Create(ret->window);
1804 if(NS_FAILED(nsres))
1805 WARN("Creating window failed: %08x\n", nsres);
1807 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1808 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1809 }else {
1810 ERR("InitWindow failed: %08x\n", nsres);
1813 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser,
1814 &ret->nsIURIContentListener_iface);
1815 if(NS_FAILED(nsres))
1816 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1818 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1819 if(NS_SUCCEEDED(nsres)) {
1820 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1821 ScrollOrientation_Y, Scrollbar_Always);
1822 if(NS_FAILED(nsres))
1823 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1825 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1826 ScrollOrientation_X, Scrollbar_Auto);
1827 if(NS_FAILED(nsres))
1828 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1830 nsIScrollable_Release(scrollable);
1831 }else {
1832 ERR("Could not get nsIScrollable: %08x\n", nsres);
1835 return ret;
1838 void NSContainer_Release(NSContainer *This)
1840 TRACE("(%p)\n", This);
1842 This->doc = NULL;
1844 ShowWindow(This->hwnd, SW_HIDE);
1845 SetParent(This->hwnd, NULL);
1847 nsIBaseWindow_SetVisibility(This->window, FALSE);
1848 nsIBaseWindow_Destroy(This->window);
1850 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1852 nsIWebBrowser_Release(This->webbrowser);
1853 This->webbrowser = NULL;
1855 nsIWebNavigation_Release(This->navigation);
1856 This->navigation = NULL;
1858 nsIBaseWindow_Release(This->window);
1859 This->window = NULL;
1861 nsIWebBrowserFocus_Release(This->focus);
1862 This->focus = NULL;
1864 if(This->editor_controller) {
1865 nsIController_Release(This->editor_controller);
1866 This->editor_controller = NULL;
1869 if(This->editor) {
1870 nsIEditor_Release(This->editor);
1871 This->editor = NULL;
1874 if(This->content_listener) {
1875 nsIURIContentListener_Release(This->content_listener);
1876 This->content_listener = NULL;
1879 if(This->hwnd) {
1880 DestroyWindow(This->hwnd);
1881 This->hwnd = NULL;
1884 nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);