wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / mshtml / nsembed.c
blob7592b621a626dcf4f36c31c56c7d9d7dbc452a82
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: HKCU\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: HKCU\Software\Wine\MSHTML */
426 res = RegOpenKeyW(HKEY_CURRENT_USER, 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 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
603 NULL, &IID_nsIObserver, (void**)&pStartNotif);
604 if(NS_SUCCEEDED(nsres)) {
605 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
606 if(NS_FAILED(nsres))
607 ERR("Observe failed: %08x\n", nsres);
609 nsIObserver_Release(pStartNotif);
610 }else {
611 ERR("could not get appstartup-notifier: %08x\n", nsres);
614 set_preferences();
616 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
617 NULL, &IID_nsIMemory, (void**)&nsmem);
618 if(NS_FAILED(nsres))
619 ERR("Could not get nsIMemory: %08x\n", nsres);
621 if(registrar) {
622 register_nsservice(registrar, pServMgr);
623 nsIComponentRegistrar_Release(registrar);
626 return TRUE;
629 static CRITICAL_SECTION cs_load_gecko;
630 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
632 0, 0, &cs_load_gecko,
633 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
634 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
636 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
638 BOOL load_gecko(BOOL silent)
640 PRUnichar gre_path[MAX_PATH];
641 BOOL ret = FALSE;
643 static DWORD loading_thread;
645 TRACE("()\n");
647 /* load_gecko may be called recursively */
648 if(loading_thread == GetCurrentThreadId())
649 return pCompMgr != NULL;
651 EnterCriticalSection(&cs_load_gecko);
653 if(!loading_thread) {
654 loading_thread = GetCurrentThreadId();
656 if(load_wine_gecko(gre_path)
657 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
658 ret = init_xpcom(gre_path);
659 else
660 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
661 }else {
662 ret = pCompMgr != NULL;
665 LeaveCriticalSection(&cs_load_gecko);
667 return ret;
670 void *nsalloc(size_t size)
672 return nsIMemory_Alloc(nsmem, size);
675 void nsfree(void *mem)
677 nsIMemory_Free(nsmem, mem);
680 static BOOL nsACString_Init(nsACString *str, const char *data)
682 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
686 * Initializes nsACString with data owned by caller.
687 * Caller must ensure that data is valid during lifetime of string object.
689 void nsACString_InitDepend(nsACString *str, const char *data)
691 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
694 void nsACString_SetData(nsACString *str, const char *data)
696 NS_CStringSetData(str, data, PR_UINT32_MAX);
699 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
701 return NS_CStringGetData(str, data, NULL);
704 void nsACString_Finish(nsACString *str)
706 NS_CStringContainerFinish(str);
709 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
711 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
715 * Initializes nsAString with data owned by caller.
716 * Caller must ensure that data is valid during lifetime of string object.
718 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
720 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
723 void nsAString_SetData(nsAString *str, const PRUnichar *data)
725 NS_StringSetData(str, data, PR_UINT32_MAX);
728 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
730 return NS_StringGetData(str, data, NULL);
733 void nsAString_Finish(nsAString *str)
735 NS_StringContainerFinish(str);
738 HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
740 const PRUnichar *str;
742 if(NS_FAILED(nsres)) {
743 ERR("failed: %08x\n", nsres);
744 nsAString_Finish(nsstr);
745 return E_FAIL;
748 nsAString_GetData(nsstr, &str);
749 TRACE("ret %s\n", debugstr_w(str));
750 if(*str) {
751 *p = SysAllocString(str);
752 if(!*p)
753 return E_OUTOFMEMORY;
754 }else {
755 *p = NULL;
758 nsAString_Finish(nsstr);
759 return S_OK;
762 nsICommandParams *create_nscommand_params(void)
764 nsICommandParams *ret = NULL;
765 nsresult nsres;
767 if(!pCompMgr)
768 return NULL;
770 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
771 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
772 (void**)&ret);
773 if(NS_FAILED(nsres))
774 ERR("Could not get nsICommandParams\n");
776 return ret;
779 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
781 nsIInterfaceRequestor *iface_req;
782 nsresult nsres;
784 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
785 if(NS_FAILED(nsres))
786 return nsres;
788 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
789 nsIInterfaceRequestor_Release(iface_req);
791 return nsres;
794 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
796 nsIDOMNodeList *node_list = NULL;
797 PRBool has_children = FALSE;
798 nsIContent *nscontent;
799 PRUint16 type;
800 nsresult nsres;
802 nsIDOMNode_HasChildNodes(nsnode, &has_children);
804 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
805 if(NS_FAILED(nsres)) {
806 ERR("GetType failed: %08x\n", nsres);
807 return E_FAIL;
810 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
811 if(NS_FAILED(nsres)) {
812 ERR("Could not get nsIDontent interface: %08x\n", nsres);
813 return E_FAIL;
816 switch(type) {
817 case ELEMENT_NODE:
818 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
819 break;
820 case TEXT_NODE:
821 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
822 break;
823 case COMMENT_NODE:
824 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
825 break;
826 case DOCUMENT_NODE: {
827 nsIDocument *nsdoc;
828 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
829 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
830 nsIDocument_Release(nsdoc);
831 break;
833 case DOCUMENT_TYPE_NODE:
834 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
835 break;
836 case DOCUMENT_FRAGMENT_NODE:
837 break;
838 default:
839 FIXME("Unhandled type %u\n", type);
842 if(has_children) {
843 PRUint32 child_cnt, i;
844 nsIDOMNode *child_node;
846 nsIDOMNode_GetChildNodes(nsnode, &node_list);
847 nsIDOMNodeList_GetLength(node_list, &child_cnt);
849 for(i=0; i<child_cnt; i++) {
850 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
851 if(NS_SUCCEEDED(nsres)) {
852 nsnode_to_nsstring_rec(serializer, child_node, str);
853 nsIDOMNode_Release(child_node);
854 }else {
855 ERR("Item failed: %08x\n", nsres);
859 nsIDOMNodeList_Release(node_list);
862 if(type == ELEMENT_NODE)
863 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
865 nsIContent_Release(nscontent);
866 return S_OK;
869 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
871 nsIContentSerializer *serializer;
872 nsresult nsres;
873 HRESULT hres;
875 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
876 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
877 (void**)&serializer);
878 if(NS_FAILED(nsres)) {
879 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
880 return E_FAIL;
883 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
884 if(NS_FAILED(nsres))
885 ERR("Init failed: %08x\n", nsres);
887 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
888 if(SUCCEEDED(hres)) {
889 nsres = nsIContentSerializer_Flush(serializer, str);
890 if(NS_FAILED(nsres))
891 ERR("Flush failed: %08x\n", nsres);
894 nsIContentSerializer_Release(serializer);
895 return hres;
898 void get_editor_controller(NSContainer *This)
900 nsIEditingSession *editing_session = NULL;
901 nsIControllerContext *ctrlctx;
902 nsresult nsres;
904 if(This->editor) {
905 nsIEditor_Release(This->editor);
906 This->editor = NULL;
909 if(This->editor_controller) {
910 nsIController_Release(This->editor_controller);
911 This->editor_controller = NULL;
914 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
915 (void**)&editing_session);
916 if(NS_FAILED(nsres)) {
917 ERR("Could not get nsIEditingSession: %08x\n", nsres);
918 return;
921 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
922 This->doc->basedoc.window->nswindow, &This->editor);
923 nsIEditingSession_Release(editing_session);
924 if(NS_FAILED(nsres)) {
925 ERR("Could not get editor: %08x\n", nsres);
926 return;
929 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
930 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
931 if(NS_SUCCEEDED(nsres)) {
932 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
933 if(NS_FAILED(nsres))
934 ERR("SetCommandContext failed: %08x\n", nsres);
935 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
936 (void**)&This->editor_controller);
937 nsIControllerContext_Release(ctrlctx);
938 if(NS_FAILED(nsres))
939 ERR("Could not get nsIController interface: %08x\n", nsres);
940 }else {
941 ERR("Could not create edit controller: %08x\n", nsres);
945 void close_gecko(void)
947 TRACE("()\n");
949 release_nsio();
951 if(profile_directory) {
952 nsIFile_Release(profile_directory);
953 profile_directory = NULL;
956 if(pCompMgr)
957 nsIComponentManager_Release(pCompMgr);
959 if(pServMgr)
960 nsIServiceManager_Release(pServMgr);
962 if(nsmem)
963 nsIMemory_Release(nsmem);
965 /* Gecko doesn't really support being unloaded */
966 /* if (hXPCOM) FreeLibrary(hXPCOM); */
969 BOOL is_gecko_path(const char *path)
971 WCHAR *buf, *ptr;
972 BOOL ret;
974 buf = heap_strdupAtoW(path);
975 if(strlenW(buf) < gecko_path_len)
976 return FALSE;
978 buf[gecko_path_len] = 0;
979 for(ptr = buf; *ptr; ptr++) {
980 if(*ptr == '\\')
981 *ptr = '/';
984 ret = !strcmpiW(buf, gecko_path);
985 heap_free(buf);
986 return ret;
989 /**********************************************************
990 * nsIWebBrowserChrome interface
993 static inline NSContainer *impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome *iface)
995 return CONTAINING_RECORD(iface, NSContainer, nsIWebBrowserChrome_iface);
998 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
999 nsIIDRef riid, void **result)
1001 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1003 *result = NULL;
1004 if(IsEqualGUID(&IID_nsISupports, riid)) {
1005 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
1006 *result = &This->nsIWebBrowserChrome_iface;
1007 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
1008 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
1009 *result = &This->nsIWebBrowserChrome_iface;
1010 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
1011 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
1012 *result = &This->nsIContextMenuListener_iface;
1013 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
1014 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
1015 *result = &This->nsIURIContentListener_iface;
1016 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
1017 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
1018 *result = &This->nsIEmbeddingSiteWindow_iface;
1019 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
1020 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
1021 *result = &This->nsITooltipListener_iface;
1022 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
1023 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
1024 *result = &This->nsIInterfaceRequestor_iface;
1025 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
1026 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
1027 *result = &This->nsIWeakReference_iface;
1028 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
1029 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
1030 *result = &This->nsISupportsWeakReference_iface;
1033 if(*result) {
1034 nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1035 return NS_OK;
1038 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1039 return NS_NOINTERFACE;
1042 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
1044 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1045 LONG ref = InterlockedIncrement(&This->ref);
1047 TRACE("(%p) ref=%d\n", This, ref);
1049 return ref;
1052 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
1054 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1055 LONG ref = InterlockedDecrement(&This->ref);
1057 TRACE("(%p) ref=%d\n", This, ref);
1059 if(!ref) {
1060 if(This->parent)
1061 nsIWebBrowserChrome_Release(&This->parent->nsIWebBrowserChrome_iface);
1062 heap_free(This);
1065 return ref;
1068 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1069 PRUint32 statusType, const PRUnichar *status)
1071 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1072 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1073 return NS_OK;
1076 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1077 nsIWebBrowser **aWebBrowser)
1079 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1081 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1083 if(!aWebBrowser)
1084 return NS_ERROR_INVALID_ARG;
1086 if(This->webbrowser)
1087 nsIWebBrowser_AddRef(This->webbrowser);
1088 *aWebBrowser = This->webbrowser;
1089 return S_OK;
1092 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1093 nsIWebBrowser *aWebBrowser)
1095 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1097 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1099 if(aWebBrowser != This->webbrowser)
1100 ERR("Wrong nsWebBrowser!\n");
1102 return NS_OK;
1105 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1106 PRUint32 *aChromeFlags)
1108 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1109 WARN("(%p)->(%p)\n", This, aChromeFlags);
1110 return NS_ERROR_NOT_IMPLEMENTED;
1113 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1114 PRUint32 aChromeFlags)
1116 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1117 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1118 return NS_ERROR_NOT_IMPLEMENTED;
1121 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1123 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1124 TRACE("(%p)\n", This);
1125 return NS_ERROR_NOT_IMPLEMENTED;
1128 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1129 PRInt32 aCX, PRInt32 aCY)
1131 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1132 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1133 return NS_ERROR_NOT_IMPLEMENTED;
1136 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1138 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1139 WARN("(%p)\n", This);
1140 return NS_ERROR_NOT_IMPLEMENTED;
1143 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
1145 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1146 WARN("(%p)->(%p)\n", This, _retval);
1147 return NS_ERROR_NOT_IMPLEMENTED;
1150 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1151 nsresult aStatus)
1153 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1154 WARN("(%p)->(%08x)\n", This, aStatus);
1155 return NS_ERROR_NOT_IMPLEMENTED;
1158 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1159 nsWebBrowserChrome_QueryInterface,
1160 nsWebBrowserChrome_AddRef,
1161 nsWebBrowserChrome_Release,
1162 nsWebBrowserChrome_SetStatus,
1163 nsWebBrowserChrome_GetWebBrowser,
1164 nsWebBrowserChrome_SetWebBrowser,
1165 nsWebBrowserChrome_GetChromeFlags,
1166 nsWebBrowserChrome_SetChromeFlags,
1167 nsWebBrowserChrome_DestroyBrowserWindow,
1168 nsWebBrowserChrome_SizeBrowserTo,
1169 nsWebBrowserChrome_ShowAsModal,
1170 nsWebBrowserChrome_IsWindowModal,
1171 nsWebBrowserChrome_ExitModalEventLoop
1174 /**********************************************************
1175 * nsIContextMenuListener interface
1178 static inline NSContainer *impl_from_nsIContextMenuListener(nsIContextMenuListener *iface)
1180 return CONTAINING_RECORD(iface, NSContainer, nsIContextMenuListener_iface);
1183 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1184 nsIIDRef riid, void **result)
1186 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1187 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1190 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1192 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1193 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1196 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1198 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1199 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1202 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1203 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1205 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1206 nsIDOMMouseEvent *event;
1207 HTMLDOMNode *node;
1208 POINT pt;
1209 DWORD dwID = CONTEXT_MENU_DEFAULT;
1210 nsresult nsres;
1211 HRESULT hres;
1213 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1215 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1217 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1218 if(NS_FAILED(nsres)) {
1219 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1220 return nsres;
1223 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1224 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1225 nsIDOMMouseEvent_Release(event);
1227 switch(aContextFlags) {
1228 case CONTEXT_NONE:
1229 case CONTEXT_DOCUMENT:
1230 case CONTEXT_TEXT:
1231 dwID = CONTEXT_MENU_DEFAULT;
1232 break;
1233 case CONTEXT_IMAGE:
1234 case CONTEXT_IMAGE|CONTEXT_LINK:
1235 dwID = CONTEXT_MENU_IMAGE;
1236 break;
1237 case CONTEXT_LINK:
1238 dwID = CONTEXT_MENU_ANCHOR;
1239 break;
1240 case CONTEXT_INPUT:
1241 dwID = CONTEXT_MENU_CONTROL;
1242 break;
1243 default:
1244 FIXME("aContextFlags=%08x\n", aContextFlags);
1247 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1248 if(FAILED(hres))
1249 return NS_ERROR_FAILURE;
1251 show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
1252 return NS_OK;
1255 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1256 nsContextMenuListener_QueryInterface,
1257 nsContextMenuListener_AddRef,
1258 nsContextMenuListener_Release,
1259 nsContextMenuListener_OnShowContextMenu
1262 /**********************************************************
1263 * nsIURIContentListener interface
1266 static inline NSContainer *impl_from_nsIURIContentListener(nsIURIContentListener *iface)
1268 return CONTAINING_RECORD(iface, NSContainer, nsIURIContentListener_iface);
1271 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1272 nsIIDRef riid, void **result)
1274 NSContainer *This = impl_from_nsIURIContentListener(iface);
1275 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1278 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1280 NSContainer *This = impl_from_nsIURIContentListener(iface);
1281 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1284 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1286 NSContainer *This = impl_from_nsIURIContentListener(iface);
1287 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1290 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1291 nsIURI *aURI, PRBool *_retval)
1293 NSContainer *This = impl_from_nsIURIContentListener(iface);
1294 nsACString spec_str;
1295 const char *spec;
1296 nsresult nsres;
1298 nsACString_Init(&spec_str, NULL);
1299 nsIURI_GetSpec(aURI, &spec_str);
1300 nsACString_GetData(&spec_str, &spec);
1302 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1304 nsACString_Finish(&spec_str);
1306 nsres = on_start_uri_open(This, aURI, _retval);
1307 if(NS_FAILED(nsres))
1308 return nsres;
1310 return !*_retval && This->content_listener
1311 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1312 : NS_OK;
1315 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1316 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1317 nsIStreamListener **aContentHandler, PRBool *_retval)
1319 NSContainer *This = impl_from_nsIURIContentListener(iface);
1321 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1322 aRequest, aContentHandler, _retval);
1324 return This->content_listener
1325 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1326 aIsContentPreferred, aRequest, aContentHandler, _retval)
1327 : NS_ERROR_NOT_IMPLEMENTED;
1330 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1331 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1333 NSContainer *This = impl_from_nsIURIContentListener(iface);
1335 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1337 /* FIXME: Should we do something here? */
1338 *_retval = TRUE;
1340 return This->content_listener
1341 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1342 aDesiredContentType, _retval)
1343 : NS_OK;
1346 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1347 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1348 PRBool *_retval)
1350 NSContainer *This = impl_from_nsIURIContentListener(iface);
1352 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1353 aDesiredContentType, _retval);
1355 return This->content_listener
1356 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1357 aIsContentPreferred, aDesiredContentType, _retval)
1358 : NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1362 nsISupports **aLoadCookie)
1364 NSContainer *This = impl_from_nsIURIContentListener(iface);
1366 WARN("(%p)->(%p)\n", This, aLoadCookie);
1368 return This->content_listener
1369 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1370 : NS_ERROR_NOT_IMPLEMENTED;
1373 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1374 nsISupports *aLoadCookie)
1376 NSContainer *This = impl_from_nsIURIContentListener(iface);
1378 WARN("(%p)->(%p)\n", This, aLoadCookie);
1380 return This->content_listener
1381 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1382 : NS_ERROR_NOT_IMPLEMENTED;
1385 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1386 nsIURIContentListener **aParentContentListener)
1388 NSContainer *This = impl_from_nsIURIContentListener(iface);
1390 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1392 if(This->content_listener)
1393 nsIURIContentListener_AddRef(This->content_listener);
1395 *aParentContentListener = This->content_listener;
1396 return NS_OK;
1399 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1400 nsIURIContentListener *aParentContentListener)
1402 NSContainer *This = impl_from_nsIURIContentListener(iface);
1404 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1406 if(aParentContentListener == &This->nsIURIContentListener_iface)
1407 return NS_OK;
1409 if(This->content_listener)
1410 nsIURIContentListener_Release(This->content_listener);
1412 This->content_listener = aParentContentListener;
1413 if(This->content_listener)
1414 nsIURIContentListener_AddRef(This->content_listener);
1416 return NS_OK;
1419 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1420 nsURIContentListener_QueryInterface,
1421 nsURIContentListener_AddRef,
1422 nsURIContentListener_Release,
1423 nsURIContentListener_OnStartURIOpen,
1424 nsURIContentListener_DoContent,
1425 nsURIContentListener_IsPreferred,
1426 nsURIContentListener_CanHandleContent,
1427 nsURIContentListener_GetLoadCookie,
1428 nsURIContentListener_SetLoadCookie,
1429 nsURIContentListener_GetParentContentListener,
1430 nsURIContentListener_SetParentContentListener
1433 /**********************************************************
1434 * nsIEmbeddinSiteWindow interface
1437 static inline NSContainer *impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow *iface)
1439 return CONTAINING_RECORD(iface, NSContainer, nsIEmbeddingSiteWindow_iface);
1442 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1443 nsIIDRef riid, void **result)
1445 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1446 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1449 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1451 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1452 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1455 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1457 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1458 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1461 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1462 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1464 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1465 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1466 return NS_ERROR_NOT_IMPLEMENTED;
1469 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1470 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1472 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1473 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1474 return NS_ERROR_NOT_IMPLEMENTED;
1477 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1479 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1481 TRACE("(%p)\n", This);
1483 return nsIBaseWindow_SetFocus(This->window);
1486 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1487 PRBool *aVisibility)
1489 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1491 TRACE("(%p)->(%p)\n", This, aVisibility);
1493 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1494 return NS_OK;
1497 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1498 PRBool aVisibility)
1500 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1502 TRACE("(%p)->(%x)\n", This, aVisibility);
1504 return NS_OK;
1507 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1508 PRUnichar **aTitle)
1510 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1511 WARN("(%p)->(%p)\n", This, aTitle);
1512 return NS_ERROR_NOT_IMPLEMENTED;
1515 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1516 const PRUnichar *aTitle)
1518 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1519 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1520 return NS_ERROR_NOT_IMPLEMENTED;
1523 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1524 void **aSiteWindow)
1526 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1528 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1530 *aSiteWindow = This->hwnd;
1531 return NS_OK;
1534 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1535 nsEmbeddingSiteWindow_QueryInterface,
1536 nsEmbeddingSiteWindow_AddRef,
1537 nsEmbeddingSiteWindow_Release,
1538 nsEmbeddingSiteWindow_SetDimensions,
1539 nsEmbeddingSiteWindow_GetDimensions,
1540 nsEmbeddingSiteWindow_SetFocus,
1541 nsEmbeddingSiteWindow_GetVisibility,
1542 nsEmbeddingSiteWindow_SetVisibility,
1543 nsEmbeddingSiteWindow_GetTitle,
1544 nsEmbeddingSiteWindow_SetTitle,
1545 nsEmbeddingSiteWindow_GetSiteWindow
1548 static inline NSContainer *impl_from_nsITooltipListener(nsITooltipListener *iface)
1550 return CONTAINING_RECORD(iface, NSContainer, nsITooltipListener_iface);
1553 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1554 void **result)
1556 NSContainer *This = impl_from_nsITooltipListener(iface);
1557 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1560 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1562 NSContainer *This = impl_from_nsITooltipListener(iface);
1563 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1566 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1568 NSContainer *This = impl_from_nsITooltipListener(iface);
1569 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1572 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1573 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1575 NSContainer *This = impl_from_nsITooltipListener(iface);
1577 if (This->doc)
1578 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1580 return NS_OK;
1583 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1585 NSContainer *This = impl_from_nsITooltipListener(iface);
1587 if (This->doc)
1588 hide_tooltip(This->doc);
1590 return NS_OK;
1593 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1594 nsTooltipListener_QueryInterface,
1595 nsTooltipListener_AddRef,
1596 nsTooltipListener_Release,
1597 nsTooltipListener_OnShowTooltip,
1598 nsTooltipListener_OnHideTooltip
1601 static inline NSContainer *impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor *iface)
1603 return CONTAINING_RECORD(iface, NSContainer, nsIInterfaceRequestor_iface);
1606 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1607 nsIIDRef riid, void **result)
1609 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1610 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1613 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1615 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1616 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1619 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1621 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1622 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1625 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1626 nsIIDRef riid, void **result)
1628 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1630 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1631 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1632 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1635 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1638 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1639 nsInterfaceRequestor_QueryInterface,
1640 nsInterfaceRequestor_AddRef,
1641 nsInterfaceRequestor_Release,
1642 nsInterfaceRequestor_GetInterface
1645 static inline NSContainer *impl_from_nsIWeakReference(nsIWeakReference *iface)
1647 return CONTAINING_RECORD(iface, NSContainer, nsIWeakReference_iface);
1650 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1651 nsIIDRef riid, void **result)
1653 NSContainer *This = impl_from_nsIWeakReference(iface);
1654 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1657 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1659 NSContainer *This = impl_from_nsIWeakReference(iface);
1660 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1663 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1665 NSContainer *This = impl_from_nsIWeakReference(iface);
1666 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1669 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1670 const nsIID *riid, void **result)
1672 NSContainer *This = impl_from_nsIWeakReference(iface);
1673 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1676 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1677 nsWeakReference_QueryInterface,
1678 nsWeakReference_AddRef,
1679 nsWeakReference_Release,
1680 nsWeakReference_QueryReferent
1683 static inline NSContainer *impl_from_nsISupportsWeakReference(nsISupportsWeakReference *iface)
1685 return CONTAINING_RECORD(iface, NSContainer, nsISupportsWeakReference_iface);
1688 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1689 nsIIDRef riid, void **result)
1691 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1692 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1695 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1697 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1698 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1701 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1703 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1704 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1707 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1708 nsIWeakReference **_retval)
1710 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1712 TRACE("(%p)->(%p)\n", This, _retval);
1714 nsIWeakReference_AddRef(&This->nsIWeakReference_iface);
1715 *_retval = &This->nsIWeakReference_iface;
1716 return NS_OK;
1719 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1720 nsSupportsWeakReference_QueryInterface,
1721 nsSupportsWeakReference_AddRef,
1722 nsSupportsWeakReference_Release,
1723 nsSupportsWeakReference_GetWeakReference
1726 nsresult create_chrome_window(nsIWebBrowserChrome *parent, nsIWebBrowserChrome **ret)
1728 NSContainer *new_container;
1730 if(parent->lpVtbl != &nsWebBrowserChromeVtbl)
1731 return NS_ERROR_UNEXPECTED;
1733 new_container = NSContainer_Create(NULL, impl_from_nsIWebBrowserChrome(parent));
1734 *ret = &new_container->nsIWebBrowserChrome_iface;
1735 return NS_OK;
1738 NSContainer *NSContainer_Create(HTMLDocumentObj *doc, NSContainer *parent)
1740 nsIWebBrowserSetup *wbsetup;
1741 nsIScrollable *scrollable;
1742 NSContainer *ret;
1743 nsresult nsres;
1745 if(!load_gecko(TRUE))
1746 return NULL;
1748 ret = heap_alloc_zero(sizeof(NSContainer));
1750 ret->nsIWebBrowserChrome_iface.lpVtbl = &nsWebBrowserChromeVtbl;
1751 ret->nsIContextMenuListener_iface.lpVtbl = &nsContextMenuListenerVtbl;
1752 ret->nsIURIContentListener_iface.lpVtbl = &nsURIContentListenerVtbl;
1753 ret->nsIEmbeddingSiteWindow_iface.lpVtbl = &nsEmbeddingSiteWindowVtbl;
1754 ret->nsITooltipListener_iface.lpVtbl = &nsTooltipListenerVtbl;
1755 ret->nsIInterfaceRequestor_iface.lpVtbl = &nsInterfaceRequestorVtbl;
1756 ret->nsIWeakReference_iface.lpVtbl = &nsWeakReferenceVtbl;
1757 ret->nsISupportsWeakReference_iface.lpVtbl = &nsSupportsWeakReferenceVtbl;
1759 ret->doc = doc;
1760 ret->ref = 1;
1762 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1763 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1764 if(NS_FAILED(nsres)) {
1765 ERR("Creating WebBrowser failed: %08x\n", nsres);
1766 heap_free(ret);
1767 return NULL;
1770 if(parent)
1771 nsIWebBrowserChrome_AddRef(&parent->nsIWebBrowserChrome_iface);
1772 ret->parent = parent;
1774 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, &ret->nsIWebBrowserChrome_iface);
1775 if(NS_FAILED(nsres))
1776 ERR("SetContainerWindow failed: %08x\n", nsres);
1778 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1779 (void**)&ret->window);
1780 if(NS_FAILED(nsres))
1781 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1783 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1784 (void**)&wbsetup);
1785 if(NS_SUCCEEDED(nsres)) {
1786 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1787 nsIWebBrowserSetup_Release(wbsetup);
1788 if(NS_FAILED(nsres))
1789 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1790 }else {
1791 ERR("Could not get nsIWebBrowserSetup interface\n");
1794 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1795 (void**)&ret->navigation);
1796 if(NS_FAILED(nsres))
1797 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1799 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1800 (void**)&ret->focus);
1801 if(NS_FAILED(nsres))
1802 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1804 if(!nscontainer_class)
1805 register_nscontainer_class();
1807 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1808 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1809 GetDesktopWindow(), NULL, hInst, ret);
1811 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1812 if(NS_SUCCEEDED(nsres)) {
1813 nsres = nsIBaseWindow_Create(ret->window);
1814 if(NS_FAILED(nsres))
1815 WARN("Creating window failed: %08x\n", nsres);
1817 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1818 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1819 }else {
1820 ERR("InitWindow failed: %08x\n", nsres);
1823 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser,
1824 &ret->nsIURIContentListener_iface);
1825 if(NS_FAILED(nsres))
1826 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1828 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1829 if(NS_SUCCEEDED(nsres)) {
1830 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1831 ScrollOrientation_Y, Scrollbar_Always);
1832 if(NS_FAILED(nsres))
1833 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1835 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1836 ScrollOrientation_X, Scrollbar_Auto);
1837 if(NS_FAILED(nsres))
1838 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1840 nsIScrollable_Release(scrollable);
1841 }else {
1842 ERR("Could not get nsIScrollable: %08x\n", nsres);
1845 return ret;
1848 void NSContainer_Release(NSContainer *This)
1850 TRACE("(%p)\n", This);
1852 This->doc = NULL;
1854 ShowWindow(This->hwnd, SW_HIDE);
1855 SetParent(This->hwnd, NULL);
1857 nsIBaseWindow_SetVisibility(This->window, FALSE);
1858 nsIBaseWindow_Destroy(This->window);
1860 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1862 nsIWebBrowser_Release(This->webbrowser);
1863 This->webbrowser = NULL;
1865 nsIWebNavigation_Release(This->navigation);
1866 This->navigation = NULL;
1868 nsIBaseWindow_Release(This->window);
1869 This->window = NULL;
1871 nsIWebBrowserFocus_Release(This->focus);
1872 This->focus = NULL;
1874 if(This->editor_controller) {
1875 nsIController_Release(This->editor_controller);
1876 This->editor_controller = NULL;
1879 if(This->editor) {
1880 nsIEditor_Release(This->editor);
1881 This->editor = NULL;
1884 if(This->content_listener) {
1885 nsIURIContentListener_Release(This->content_listener);
1886 This->content_listener = NULL;
1889 if(This->hwnd) {
1890 DestroyWindow(This->hwnd);
1891 This->hwnd = NULL;
1894 nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);