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
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.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"
49 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
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*,cpp_bool,nsIFile**);
66 static PRUint32 (CDECL *NS_StringGetData)(const nsAString*,const PRUnichar **,cpp_bool*);
67 static PRUint32 (CDECL *NS_CStringGetData)(const nsACString*,const char**,cpp_bool*);
69 static HINSTANCE xul_handle = NULL;
71 static nsIServiceManager *pServMgr = NULL;
72 static nsIComponentManager *pCompMgr = NULL;
73 static nsIMemory *nsmem = NULL;
74 static nsIFile *profile_directory, *plugin_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 nsresult create_nsfile(const PRUnichar *path, nsIFile **ret)
87 nsAString_InitDepend(&str, path);
88 nsres = NS_NewLocalFile(&str, FALSE, ret);
89 nsAString_Finish(&str);
92 WARN("NS_NewLocalFile failed: %08x\n", nsres);
97 nsISimpleEnumerator nsISimpleEnumerator_iface;
100 } nsSingletonEnumerator;
102 static inline nsSingletonEnumerator *impl_from_nsISimpleEnumerator(nsISimpleEnumerator *iface)
104 return CONTAINING_RECORD(iface, nsSingletonEnumerator, nsISimpleEnumerator_iface);
107 static nsresult NSAPI nsSingletonEnumerator_QueryInterface(nsISimpleEnumerator *iface, nsIIDRef riid, void **ppv)
109 nsSingletonEnumerator *This = impl_from_nsISimpleEnumerator(iface);
111 if(IsEqualGUID(&IID_nsISupports, riid)) {
112 TRACE("(%p)->(IID_nsISupports %p)\n", This, ppv);
113 *ppv = &This->nsISimpleEnumerator_iface;
114 }else if(IsEqualGUID(&IID_nsISimpleEnumerator, riid)) {
115 TRACE("(%p)->(IID_nsISimpleEnumerator %p)\n", This, ppv);
116 *ppv = &This->nsISimpleEnumerator_iface;
118 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
120 return NS_NOINTERFACE;
123 nsISupports_AddRef((nsISupports*)*ppv);
127 static nsrefcnt NSAPI nsSingletonEnumerator_AddRef(nsISimpleEnumerator *iface)
129 nsSingletonEnumerator *This = impl_from_nsISimpleEnumerator(iface);
130 nsrefcnt ref = InterlockedIncrement(&This->ref);
132 TRACE("(%p) ref=%d\n", This, ref);
137 static nsrefcnt NSAPI nsSingletonEnumerator_Release(nsISimpleEnumerator *iface)
139 nsSingletonEnumerator *This = impl_from_nsISimpleEnumerator(iface);
140 nsrefcnt ref = InterlockedDecrement(&This->ref);
142 TRACE("(%p) ref=%d\n", This, ref);
146 nsISupports_Release(This->value);
153 static nsresult NSAPI nsSingletonEnumerator_HasMoreElements(nsISimpleEnumerator *iface, cpp_bool *_retval)
155 nsSingletonEnumerator *This = impl_from_nsISimpleEnumerator(iface);
157 TRACE("(%p)->()\n", This);
159 *_retval = This->value != NULL;
163 static nsresult NSAPI nsSingletonEnumerator_GetNext(nsISimpleEnumerator *iface, nsISupports **_retval)
165 nsSingletonEnumerator *This = impl_from_nsISimpleEnumerator(iface);
167 TRACE("(%p)->()\n", This);
170 return NS_ERROR_UNEXPECTED;
172 *_retval = This->value;
177 static const nsISimpleEnumeratorVtbl nsSingletonEnumeratorVtbl = {
178 nsSingletonEnumerator_QueryInterface,
179 nsSingletonEnumerator_AddRef,
180 nsSingletonEnumerator_Release,
181 nsSingletonEnumerator_HasMoreElements,
182 nsSingletonEnumerator_GetNext
185 static nsISimpleEnumerator *create_singleton_enumerator(nsISupports *value)
187 nsSingletonEnumerator *ret;
189 ret = heap_alloc(sizeof(*ret));
193 ret->nsISimpleEnumerator_iface.lpVtbl = &nsSingletonEnumeratorVtbl;
197 nsISupports_AddRef(value);
199 return &ret->nsISimpleEnumerator_iface;
202 static nsresult NSAPI nsDirectoryServiceProvider2_QueryInterface(nsIDirectoryServiceProvider2 *iface,
203 nsIIDRef riid, void **result)
205 if(IsEqualGUID(&IID_nsISupports, riid)) {
206 TRACE("(IID_nsISupports %p)\n", result);
208 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider, riid)) {
209 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result);
211 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider2, riid)) {
212 TRACE("(IID_nsIDirectoryServiceProvider2 %p)\n", result);
215 WARN("(%s %p)\n", debugstr_guid(riid), result);
217 return NS_NOINTERFACE;
220 nsISupports_AddRef((nsISupports*)*result);
224 static nsrefcnt NSAPI nsDirectoryServiceProvider2_AddRef(nsIDirectoryServiceProvider2 *iface)
229 static nsrefcnt NSAPI nsDirectoryServiceProvider2_Release(nsIDirectoryServiceProvider2 *iface)
234 static nsresult create_profile_directory(void)
236 static const WCHAR wine_geckoW[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
238 WCHAR path[MAX_PATH + sizeof(wine_geckoW)/sizeof(WCHAR)];
243 hres = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
245 ERR("SHGetFolderPath failed: %08x\n", hres);
246 return NS_ERROR_FAILURE;
249 strcatW(path, wine_geckoW);
250 nsres = create_nsfile(path, &profile_directory);
254 nsres = nsIFile_Exists(profile_directory, &exists);
255 if(NS_FAILED(nsres)) {
256 ERR("Exists failed: %08x\n", nsres);
261 nsres = nsIFile_Create(profile_directory, 1, 0700);
263 ERR("Create failed: %08x\n", nsres);
269 static nsresult NSAPI nsDirectoryServiceProvider2_GetFile(nsIDirectoryServiceProvider2 *iface,
270 const char *prop, cpp_bool *persistent, nsIFile **_retval)
272 TRACE("(%s %p %p)\n", debugstr_a(prop), persistent, _retval);
274 if(!strcmp(prop, "ProfD")) {
275 if(!profile_directory) {
278 nsres = create_profile_directory();
283 return nsIFile_Clone(profile_directory, _retval);
286 return NS_ERROR_FAILURE;
289 static nsresult NSAPI nsDirectoryServiceProvider2_GetFiles(nsIDirectoryServiceProvider2 *iface,
290 const char *prop, nsISimpleEnumerator **_retval)
292 TRACE("(%s %p)\n", debugstr_a(prop), _retval);
294 if(!strcmp(prop, "APluginsDL")) {
295 WCHAR plugin_path[MAX_PATH];
300 if(!plugin_directory) {
301 static const WCHAR gecko_pluginW[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
303 len = GetSystemDirectoryW(plugin_path, (sizeof(plugin_path)-sizeof(gecko_pluginW))/sizeof(WCHAR)+1);
305 return NS_ERROR_UNEXPECTED;
307 strcpyW(plugin_path+len, gecko_pluginW);
308 nsres = create_nsfile(plugin_path, &plugin_directory);
313 nsres = nsIFile_Clone(plugin_directory, &file);
317 *_retval = create_singleton_enumerator((nsISupports*)file);
318 nsIFile_Release(file);
320 return NS_ERROR_OUT_OF_MEMORY;
325 return NS_ERROR_FAILURE;
328 static const nsIDirectoryServiceProvider2Vtbl nsDirectoryServiceProvider2Vtbl = {
329 nsDirectoryServiceProvider2_QueryInterface,
330 nsDirectoryServiceProvider2_AddRef,
331 nsDirectoryServiceProvider2_Release,
332 nsDirectoryServiceProvider2_GetFile,
333 nsDirectoryServiceProvider2_GetFiles
336 static nsIDirectoryServiceProvider2 nsDirectoryServiceProvider2 =
337 { &nsDirectoryServiceProvider2Vtbl };
339 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
344 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
346 if(msg == WM_CREATE) {
347 This = *(NSContainer**)lParam;
348 SetPropW(hwnd, wszTHIS, This);
350 This = GetPropW(hwnd, wszTHIS);
355 TRACE("(%p)->(WM_SIZE)\n", This);
357 nsres = nsIBaseWindow_SetSize(This->window,
358 LOWORD(lParam), HIWORD(lParam), TRUE);
360 WARN("SetSize failed: %08x\n", nsres);
363 case WM_PARENTNOTIFY:
364 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam);
369 nsIWebBrowserFocus_Activate(This->focus);
373 return DefWindowProcW(hwnd, msg, wParam, lParam);
377 static void register_nscontainer_class(void)
379 static WNDCLASSEXW wndclass = {
383 0, 0, NULL, NULL, NULL, NULL, NULL,
387 wndclass.hInstance = hInst;
388 nscontainer_class = RegisterClassExW(&wndclass);
391 static BOOL install_wine_gecko(void)
393 PROCESS_INFORMATION pi;
400 static const WCHAR controlW[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
401 static const WCHAR argsW[] =
402 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
404 len = GetSystemDirectoryW(app, MAX_PATH-sizeof(controlW)/sizeof(WCHAR));
405 memcpy(app+len, controlW, sizeof(controlW));
407 args = heap_alloc(len*sizeof(WCHAR) + sizeof(controlW) + sizeof(argsW));
411 memcpy(args, app, len*sizeof(WCHAR) + sizeof(controlW));
412 memcpy(args + len + sizeof(controlW)/sizeof(WCHAR)-1, argsW, sizeof(argsW));
414 TRACE("starting %s\n", debugstr_w(args));
416 memset(&si, 0, sizeof(si));
418 ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
421 CloseHandle(pi.hThread);
422 WaitForSingleObject(pi.hProcess, INFINITE);
423 CloseHandle(pi.hProcess);
429 static void set_environment(LPCWSTR gre_path)
431 WCHAR path_env[MAX_PATH], buf[20];
432 int len, debug_level = 0;
434 static const WCHAR pathW[] = {'P','A','T','H',0};
435 static const WCHAR warnW[] = {'w','a','r','n',0};
436 static const WCHAR xpcom_debug_breakW[] =
437 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
438 static const WCHAR nspr_log_modulesW[] =
439 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
440 static const WCHAR debug_formatW[] = {'a','l','l',':','%','d',0};
442 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
443 GetEnvironmentVariableW(pathW, path_env, sizeof(path_env)/sizeof(WCHAR));
444 len = strlenW(path_env);
445 path_env[len++] = ';';
446 strcpyW(path_env+len, gre_path);
447 SetEnvironmentVariableW(pathW, path_env);
449 SetEnvironmentVariableW(xpcom_debug_breakW, warnW);
453 else if(WARN_ON(gecko))
455 else if(ERR_ON(gecko))
458 sprintfW(buf, debug_formatW, debug_level);
459 SetEnvironmentVariableW(nspr_log_modulesW, buf);
462 static BOOL load_xul(const PRUnichar *gre_path)
464 static const WCHAR xul_dllW[] = {'\\','x','u','l','.','d','l','l',0};
465 WCHAR file_name[MAX_PATH];
467 strcpyW(file_name, gre_path);
468 strcatW(file_name, xul_dllW);
470 TRACE("(%s)\n", debugstr_w(file_name));
472 set_environment(gre_path);
474 xul_handle = LoadLibraryExW(file_name, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
476 WARN("Could not load XUL: %d\n", GetLastError());
480 #define NS_DLSYM(func) \
481 func = (void *)GetProcAddress(xul_handle, #func "_P"); \
483 ERR("Could not GetProcAddress(" #func ") failed\n")
485 NS_DLSYM(NS_InitXPCOM2);
486 NS_DLSYM(NS_ShutdownXPCOM);
487 NS_DLSYM(NS_GetComponentRegistrar);
488 NS_DLSYM(NS_StringContainerInit2);
489 NS_DLSYM(NS_CStringContainerInit2);
490 NS_DLSYM(NS_StringContainerFinish);
491 NS_DLSYM(NS_CStringContainerFinish);
492 NS_DLSYM(NS_StringSetData);
493 NS_DLSYM(NS_CStringSetData);
494 NS_DLSYM(NS_NewLocalFile);
495 NS_DLSYM(NS_StringGetData);
496 NS_DLSYM(NS_CStringGetData);
500 #define NS_DLSYM(func) \
501 func = (void *)GetProcAddress(xul_handle, #func); \
503 ERR("Could not GetProcAddress(" #func ") failed\n")
505 NS_DLSYM(ccref_incr);
506 NS_DLSYM(ccref_decr);
507 NS_DLSYM(ccref_init);
508 NS_DLSYM(ccref_unmark_if_purple);
510 NS_DLSYM(describe_cc_node);
511 NS_DLSYM(note_cc_edge);
518 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
520 WCHAR file_name[MAX_PATH];
525 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
527 strcpyW(file_name, gre_path);
528 strcatW(file_name, wszVersion);
530 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
531 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
532 if(hfile == INVALID_HANDLE_VALUE) {
533 ERR("Could not open VERSION file\n");
537 ReadFile(hfile, version, sizeof(version), &read, NULL);
541 TRACE("%s\n", debugstr_a(version));
543 if(strcmp(version, version_string)) {
544 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
545 debugstr_a(version_string));
552 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
553 const char *version, const char *version_string)
555 DWORD res, type, size = MAX_PATH;
556 HKEY hkey = mshtml_key;
558 static const WCHAR wszGeckoPath[] =
559 {'G','e','c','k','o','P','a','t','h',0};
562 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
563 res = RegOpenKeyA(mshtml_key, version, &hkey);
564 if(res != ERROR_SUCCESS)
568 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
569 if(hkey != mshtml_key)
571 if(res != ERROR_SUCCESS || type != REG_SZ)
574 if(!check_version(gre_path, version_string))
577 return load_xul(gre_path);
580 static BOOL load_wine_gecko(PRUnichar *gre_path)
586 static const WCHAR wszMshtmlKey[] = {
587 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
588 '\\','M','S','H','T','M','L',0};
590 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
591 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMshtmlKey, &hkey);
592 if(res != ERROR_SUCCESS)
595 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING);
601 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
605 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
607 ERR("Could not set pref %s\n", debugstr_a(pref_name));
610 static void set_int_pref(nsIPrefBranch *pref, const char *pref_name, int val)
614 nsres = nsIPrefBranch_SetIntPref(pref, pref_name, val);
616 ERR("Could not set pref %s\n", debugstr_a(pref_name));
619 static void set_string_pref(nsIPrefBranch *pref, const char *pref_name, const char *val)
623 nsres = nsIPrefBranch_SetCharPref(pref, pref_name, val);
625 ERR("Could not set pref %s\n", debugstr_a(pref_name));
628 static void set_lang(nsIPrefBranch *pref)
631 DWORD res, size, type;
634 static const WCHAR international_keyW[] =
635 {'S','o','f','t','w','a','r','e',
636 '\\','M','i','c','r','o','s','o','f','t',
637 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
638 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
640 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
641 if(res != ERROR_SUCCESS)
644 size = sizeof(langs);
645 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
647 if(res != ERROR_SUCCESS || type != REG_SZ)
650 TRACE("Setting lang %s\n", debugstr_a(langs));
652 set_string_pref(pref, "intl.accept_languages", langs);
655 static void set_preferences(void)
660 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
661 &IID_nsIPrefBranch, (void**)&pref);
662 if(NS_FAILED(nsres)) {
663 ERR("Could not get preference service: %08x\n", nsres);
668 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
669 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
670 set_int_pref(pref, "layout.spellcheckDefault", 0);
672 nsIPrefBranch_Release(pref);
675 static BOOL init_xpcom(const PRUnichar *gre_path)
677 nsIComponentRegistrar *registrar = NULL;
682 nsres = create_nsfile(gre_path, &gre_dir);
683 if(NS_FAILED(nsres)) {
684 FreeLibrary(xul_handle);
688 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, (nsIDirectoryServiceProvider*)&nsDirectoryServiceProvider2);
689 if(NS_FAILED(nsres)) {
690 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
691 FreeLibrary(xul_handle);
695 strcpyW(gecko_path, gre_path);
696 for(ptr = gecko_path; *ptr; ptr++) {
700 gecko_path_len = ptr-gecko_path;
702 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
704 ERR("Could not get nsIComponentManager: %08x\n", nsres);
706 nsres = NS_GetComponentRegistrar(®istrar);
707 if(NS_SUCCEEDED(nsres))
708 init_nsio(pCompMgr, registrar);
710 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
712 init_mutation(pCompMgr);
715 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
716 NULL, &IID_nsIMemory, (void**)&nsmem);
718 ERR("Could not get nsIMemory: %08x\n", nsres);
721 register_nsservice(registrar, pServMgr);
722 nsIComponentRegistrar_Release(registrar);
730 static CRITICAL_SECTION cs_load_gecko;
731 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
733 0, 0, &cs_load_gecko,
734 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
735 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
737 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
739 BOOL load_gecko(void)
741 PRUnichar gre_path[MAX_PATH];
744 static DWORD loading_thread;
748 /* load_gecko may be called recursively */
749 if(loading_thread == GetCurrentThreadId())
750 return pCompMgr != NULL;
752 EnterCriticalSection(&cs_load_gecko);
754 if(!loading_thread) {
755 loading_thread = GetCurrentThreadId();
757 if(load_wine_gecko(gre_path)
758 || (install_wine_gecko() && load_wine_gecko(gre_path)))
759 ret = init_xpcom(gre_path);
761 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
763 ret = pCompMgr != NULL;
766 LeaveCriticalSection(&cs_load_gecko);
771 void *nsalloc(size_t size)
773 return nsIMemory_Alloc(nsmem, size);
776 void nsfree(void *mem)
778 nsIMemory_Free(nsmem, mem);
781 static BOOL nsACString_Init(nsACString *str, const char *data)
783 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
787 * Initializes nsACString with data owned by caller.
788 * Caller must ensure that data is valid during lifetime of string object.
790 void nsACString_InitDepend(nsACString *str, const char *data)
792 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
795 void nsACString_SetData(nsACString *str, const char *data)
797 NS_CStringSetData(str, data, PR_UINT32_MAX);
800 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
802 return NS_CStringGetData(str, data, NULL);
805 void nsACString_Finish(nsACString *str)
807 NS_CStringContainerFinish(str);
810 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
812 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
816 * Initializes nsAString with data owned by caller.
817 * Caller must ensure that data is valid during lifetime of string object.
819 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
821 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
824 void nsAString_SetData(nsAString *str, const PRUnichar *data)
826 NS_StringSetData(str, data, PR_UINT32_MAX);
829 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
831 return NS_StringGetData(str, data, NULL);
834 void nsAString_Finish(nsAString *str)
836 NS_StringContainerFinish(str);
839 HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
841 const PRUnichar *str;
843 if(NS_FAILED(nsres)) {
844 ERR("failed: %08x\n", nsres);
845 nsAString_Finish(nsstr);
849 nsAString_GetData(nsstr, &str);
850 TRACE("ret %s\n", debugstr_w(str));
852 *p = SysAllocString(str);
854 return E_OUTOFMEMORY;
859 nsAString_Finish(nsstr);
863 nsICommandParams *create_nscommand_params(void)
865 nsICommandParams *ret = NULL;
871 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
872 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
875 ERR("Could not get nsICommandParams\n");
880 nsIWritableVariant *create_nsvariant(void)
882 nsIWritableVariant *ret = NULL;
888 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
889 NS_VARIANT_CONTRACTID, NULL, &IID_nsIWritableVariant, (void**)&ret);
891 ERR("Could not get nsIVariant\n");
896 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
898 nsIInterfaceRequestor *iface_req;
901 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
905 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
906 nsIInterfaceRequestor_Release(iface_req);
911 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
913 nsIDOMNodeList *node_list = NULL;
914 cpp_bool has_children = FALSE;
915 nsIContent *nscontent;
919 nsIDOMNode_HasChildNodes(nsnode, &has_children);
921 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
922 if(NS_FAILED(nsres)) {
923 ERR("GetType failed: %08x\n", nsres);
927 if(type != DOCUMENT_NODE) {
928 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
929 if(NS_FAILED(nsres)) {
930 ERR("Could not get nsIContent interface: %08x\n", nsres);
937 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
940 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
943 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
945 case DOCUMENT_NODE: {
947 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
948 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
949 nsIDocument_Release(nsdoc);
952 case DOCUMENT_TYPE_NODE:
953 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
955 case DOCUMENT_FRAGMENT_NODE:
958 FIXME("Unhandled type %u\n", type);
962 PRUint32 child_cnt, i;
963 nsIDOMNode *child_node;
965 nsIDOMNode_GetChildNodes(nsnode, &node_list);
966 nsIDOMNodeList_GetLength(node_list, &child_cnt);
968 for(i=0; i<child_cnt; i++) {
969 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
970 if(NS_SUCCEEDED(nsres)) {
971 nsnode_to_nsstring_rec(serializer, child_node, str);
972 nsIDOMNode_Release(child_node);
974 ERR("Item failed: %08x\n", nsres);
978 nsIDOMNodeList_Release(node_list);
981 if(type == ELEMENT_NODE)
982 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
984 if(type != DOCUMENT_NODE)
985 nsIContent_Release(nscontent);
989 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
991 nsIContentSerializer *serializer;
995 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
996 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
997 (void**)&serializer);
998 if(NS_FAILED(nsres)) {
999 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
1003 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
1004 if(NS_FAILED(nsres))
1005 ERR("Init failed: %08x\n", nsres);
1007 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
1008 if(SUCCEEDED(hres)) {
1009 nsres = nsIContentSerializer_Flush(serializer, str);
1010 if(NS_FAILED(nsres))
1011 ERR("Flush failed: %08x\n", nsres);
1014 nsIContentSerializer_Release(serializer);
1018 void get_editor_controller(NSContainer *This)
1020 nsIEditingSession *editing_session = NULL;
1021 nsIControllerContext *ctrlctx;
1025 nsIEditor_Release(This->editor);
1026 This->editor = NULL;
1029 if(This->editor_controller) {
1030 nsIController_Release(This->editor_controller);
1031 This->editor_controller = NULL;
1034 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
1035 (void**)&editing_session);
1036 if(NS_FAILED(nsres)) {
1037 ERR("Could not get nsIEditingSession: %08x\n", nsres);
1041 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
1042 This->doc->basedoc.window->nswindow, &This->editor);
1043 nsIEditingSession_Release(editing_session);
1044 if(NS_FAILED(nsres)) {
1045 ERR("Could not get editor: %08x\n", nsres);
1049 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
1050 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
1051 if(NS_SUCCEEDED(nsres)) {
1052 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
1053 if(NS_FAILED(nsres))
1054 ERR("SetCommandContext failed: %08x\n", nsres);
1055 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
1056 (void**)&This->editor_controller);
1057 nsIControllerContext_Release(ctrlctx);
1058 if(NS_FAILED(nsres))
1059 ERR("Could not get nsIController interface: %08x\n", nsres);
1061 ERR("Could not create edit controller: %08x\n", nsres);
1065 void close_gecko(void)
1070 init_mutation(NULL);
1072 if(profile_directory) {
1073 nsIFile_Release(profile_directory);
1074 profile_directory = NULL;
1077 if(plugin_directory) {
1078 nsIFile_Release(plugin_directory);
1079 plugin_directory = NULL;
1083 nsIComponentManager_Release(pCompMgr);
1086 nsIServiceManager_Release(pServMgr);
1089 nsIMemory_Release(nsmem);
1091 /* Gecko doesn't really support being unloaded */
1092 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1094 DeleteCriticalSection(&cs_load_gecko);
1097 BOOL is_gecko_path(const char *path)
1102 buf = heap_strdupAtoW(path);
1103 if(strlenW(buf) < gecko_path_len)
1106 buf[gecko_path_len] = 0;
1107 for(ptr = buf; *ptr; ptr++) {
1112 ret = !strcmpiW(buf, gecko_path);
1117 struct nsWeakReference {
1118 nsIWeakReference nsIWeakReference_iface;
1122 NSContainer *nscontainer;
1125 static inline nsWeakReference *impl_from_nsIWeakReference(nsIWeakReference *iface)
1127 return CONTAINING_RECORD(iface, nsWeakReference, nsIWeakReference_iface);
1130 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1131 nsIIDRef riid, void **result)
1133 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1135 if(IsEqualGUID(&IID_nsISupports, riid)) {
1136 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1137 *result = &This->nsIWeakReference_iface;
1138 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
1139 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
1140 *result = &This->nsIWeakReference_iface;
1142 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1144 return NS_NOINTERFACE;
1147 nsISupports_AddRef((nsISupports*)*result);
1151 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1153 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1154 LONG ref = InterlockedIncrement(&This->ref);
1156 TRACE("(%p) ref=%d\n", This, ref);
1161 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1163 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1164 LONG ref = InterlockedIncrement(&This->ref);
1166 TRACE("(%p) ref=%d\n", This, ref);
1169 assert(!This->nscontainer);
1176 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1177 const nsIID *riid, void **result)
1179 nsWeakReference *This = impl_from_nsIWeakReference(iface);
1181 if(!This->nscontainer)
1182 return NS_ERROR_NULL_POINTER;
1184 return nsIWebBrowserChrome_QueryInterface(&This->nscontainer->nsIWebBrowserChrome_iface, riid, result);
1187 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1188 nsWeakReference_QueryInterface,
1189 nsWeakReference_AddRef,
1190 nsWeakReference_Release,
1191 nsWeakReference_QueryReferent
1194 /**********************************************************
1195 * nsIWebBrowserChrome interface
1198 static inline NSContainer *impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome *iface)
1200 return CONTAINING_RECORD(iface, NSContainer, nsIWebBrowserChrome_iface);
1203 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
1204 nsIIDRef riid, void **result)
1206 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1209 if(IsEqualGUID(&IID_nsISupports, riid)) {
1210 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
1211 *result = &This->nsIWebBrowserChrome_iface;
1212 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
1213 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
1214 *result = &This->nsIWebBrowserChrome_iface;
1215 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
1216 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
1217 *result = &This->nsIContextMenuListener_iface;
1218 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
1219 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
1220 *result = &This->nsIURIContentListener_iface;
1221 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
1222 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
1223 *result = &This->nsIEmbeddingSiteWindow_iface;
1224 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
1225 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
1226 *result = &This->nsITooltipListener_iface;
1227 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
1228 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
1229 *result = &This->nsIInterfaceRequestor_iface;
1230 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
1231 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
1232 *result = &This->nsISupportsWeakReference_iface;
1236 nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1240 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1241 return NS_NOINTERFACE;
1244 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
1246 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1247 LONG ref = InterlockedIncrement(&This->ref);
1249 TRACE("(%p) ref=%d\n", This, ref);
1254 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
1256 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1257 LONG ref = InterlockedDecrement(&This->ref);
1259 TRACE("(%p) ref=%d\n", This, ref);
1263 nsIWebBrowserChrome_Release(&This->parent->nsIWebBrowserChrome_iface);
1264 if(This->weak_reference) {
1265 This->weak_reference->nscontainer = NULL;
1266 nsIWeakReference_Release(&This->weak_reference->nsIWeakReference_iface);
1274 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1275 PRUint32 statusType, const PRUnichar *status)
1277 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1278 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1282 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1283 nsIWebBrowser **aWebBrowser)
1285 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1287 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1290 return NS_ERROR_INVALID_ARG;
1292 if(This->webbrowser)
1293 nsIWebBrowser_AddRef(This->webbrowser);
1294 *aWebBrowser = This->webbrowser;
1298 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1299 nsIWebBrowser *aWebBrowser)
1301 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1303 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1305 if(aWebBrowser != This->webbrowser)
1306 ERR("Wrong nsWebBrowser!\n");
1311 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1312 PRUint32 *aChromeFlags)
1314 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1315 WARN("(%p)->(%p)\n", This, aChromeFlags);
1316 return NS_ERROR_NOT_IMPLEMENTED;
1319 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1320 PRUint32 aChromeFlags)
1322 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1323 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1324 return NS_ERROR_NOT_IMPLEMENTED;
1327 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1329 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1330 TRACE("(%p)\n", This);
1331 return NS_ERROR_NOT_IMPLEMENTED;
1334 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1335 PRInt32 aCX, PRInt32 aCY)
1337 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1338 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1339 return NS_ERROR_NOT_IMPLEMENTED;
1342 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1344 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1345 WARN("(%p)\n", This);
1346 return NS_ERROR_NOT_IMPLEMENTED;
1349 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, cpp_bool *_retval)
1351 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1352 WARN("(%p)->(%p)\n", This, _retval);
1353 return NS_ERROR_NOT_IMPLEMENTED;
1356 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1359 NSContainer *This = impl_from_nsIWebBrowserChrome(iface);
1360 WARN("(%p)->(%08x)\n", This, aStatus);
1361 return NS_ERROR_NOT_IMPLEMENTED;
1364 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1365 nsWebBrowserChrome_QueryInterface,
1366 nsWebBrowserChrome_AddRef,
1367 nsWebBrowserChrome_Release,
1368 nsWebBrowserChrome_SetStatus,
1369 nsWebBrowserChrome_GetWebBrowser,
1370 nsWebBrowserChrome_SetWebBrowser,
1371 nsWebBrowserChrome_GetChromeFlags,
1372 nsWebBrowserChrome_SetChromeFlags,
1373 nsWebBrowserChrome_DestroyBrowserWindow,
1374 nsWebBrowserChrome_SizeBrowserTo,
1375 nsWebBrowserChrome_ShowAsModal,
1376 nsWebBrowserChrome_IsWindowModal,
1377 nsWebBrowserChrome_ExitModalEventLoop
1380 /**********************************************************
1381 * nsIContextMenuListener interface
1384 static inline NSContainer *impl_from_nsIContextMenuListener(nsIContextMenuListener *iface)
1386 return CONTAINING_RECORD(iface, NSContainer, nsIContextMenuListener_iface);
1389 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1390 nsIIDRef riid, void **result)
1392 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1393 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1396 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1398 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1399 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1402 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1404 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1405 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1408 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1409 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1411 NSContainer *This = impl_from_nsIContextMenuListener(iface);
1412 nsIDOMMouseEvent *event;
1415 DWORD dwID = CONTEXT_MENU_DEFAULT;
1419 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1421 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1423 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1424 if(NS_FAILED(nsres)) {
1425 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1429 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1430 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1431 nsIDOMMouseEvent_Release(event);
1433 switch(aContextFlags) {
1435 case CONTEXT_DOCUMENT:
1437 dwID = CONTEXT_MENU_DEFAULT;
1440 case CONTEXT_IMAGE|CONTEXT_LINK:
1441 dwID = CONTEXT_MENU_IMAGE;
1444 dwID = CONTEXT_MENU_ANCHOR;
1447 dwID = CONTEXT_MENU_CONTROL;
1450 FIXME("aContextFlags=%08x\n", aContextFlags);
1453 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1455 return NS_ERROR_FAILURE;
1457 show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
1462 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1463 nsContextMenuListener_QueryInterface,
1464 nsContextMenuListener_AddRef,
1465 nsContextMenuListener_Release,
1466 nsContextMenuListener_OnShowContextMenu
1469 /**********************************************************
1470 * nsIURIContentListener interface
1473 static inline NSContainer *impl_from_nsIURIContentListener(nsIURIContentListener *iface)
1475 return CONTAINING_RECORD(iface, NSContainer, nsIURIContentListener_iface);
1478 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1479 nsIIDRef riid, void **result)
1481 NSContainer *This = impl_from_nsIURIContentListener(iface);
1482 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1485 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1487 NSContainer *This = impl_from_nsIURIContentListener(iface);
1488 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1491 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1493 NSContainer *This = impl_from_nsIURIContentListener(iface);
1494 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1497 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1498 nsIURI *aURI, cpp_bool *_retval)
1500 NSContainer *This = impl_from_nsIURIContentListener(iface);
1501 nsACString spec_str;
1505 nsACString_Init(&spec_str, NULL);
1506 nsIURI_GetSpec(aURI, &spec_str);
1507 nsACString_GetData(&spec_str, &spec);
1509 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1511 nsACString_Finish(&spec_str);
1513 nsres = on_start_uri_open(This, aURI, _retval);
1514 if(NS_FAILED(nsres))
1517 return !*_retval && This->content_listener
1518 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1522 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1523 const char *aContentType, cpp_bool aIsContentPreferred, nsIRequest *aRequest,
1524 nsIStreamListener **aContentHandler, cpp_bool *_retval)
1526 NSContainer *This = impl_from_nsIURIContentListener(iface);
1528 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1529 aRequest, aContentHandler, _retval);
1531 return This->content_listener
1532 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1533 aIsContentPreferred, aRequest, aContentHandler, _retval)
1534 : NS_ERROR_NOT_IMPLEMENTED;
1537 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1538 const char *aContentType, char **aDesiredContentType, cpp_bool *_retval)
1540 NSContainer *This = impl_from_nsIURIContentListener(iface);
1542 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1544 /* FIXME: Should we do something here? */
1547 return This->content_listener
1548 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1549 aDesiredContentType, _retval)
1553 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1554 const char *aContentType, cpp_bool aIsContentPreferred, char **aDesiredContentType,
1557 NSContainer *This = impl_from_nsIURIContentListener(iface);
1559 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1560 aDesiredContentType, _retval);
1562 return This->content_listener
1563 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1564 aIsContentPreferred, aDesiredContentType, _retval)
1565 : NS_ERROR_NOT_IMPLEMENTED;
1568 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1569 nsISupports **aLoadCookie)
1571 NSContainer *This = impl_from_nsIURIContentListener(iface);
1573 WARN("(%p)->(%p)\n", This, aLoadCookie);
1575 return This->content_listener
1576 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1577 : NS_ERROR_NOT_IMPLEMENTED;
1580 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1581 nsISupports *aLoadCookie)
1583 NSContainer *This = impl_from_nsIURIContentListener(iface);
1585 WARN("(%p)->(%p)\n", This, aLoadCookie);
1587 return This->content_listener
1588 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1589 : NS_ERROR_NOT_IMPLEMENTED;
1592 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1593 nsIURIContentListener **aParentContentListener)
1595 NSContainer *This = impl_from_nsIURIContentListener(iface);
1597 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1599 if(This->content_listener)
1600 nsIURIContentListener_AddRef(This->content_listener);
1602 *aParentContentListener = This->content_listener;
1606 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1607 nsIURIContentListener *aParentContentListener)
1609 NSContainer *This = impl_from_nsIURIContentListener(iface);
1611 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1613 if(aParentContentListener == &This->nsIURIContentListener_iface)
1616 if(This->content_listener)
1617 nsIURIContentListener_Release(This->content_listener);
1619 This->content_listener = aParentContentListener;
1620 if(This->content_listener)
1621 nsIURIContentListener_AddRef(This->content_listener);
1626 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1627 nsURIContentListener_QueryInterface,
1628 nsURIContentListener_AddRef,
1629 nsURIContentListener_Release,
1630 nsURIContentListener_OnStartURIOpen,
1631 nsURIContentListener_DoContent,
1632 nsURIContentListener_IsPreferred,
1633 nsURIContentListener_CanHandleContent,
1634 nsURIContentListener_GetLoadCookie,
1635 nsURIContentListener_SetLoadCookie,
1636 nsURIContentListener_GetParentContentListener,
1637 nsURIContentListener_SetParentContentListener
1640 /**********************************************************
1641 * nsIEmbeddinSiteWindow interface
1644 static inline NSContainer *impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow *iface)
1646 return CONTAINING_RECORD(iface, NSContainer, nsIEmbeddingSiteWindow_iface);
1649 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1650 nsIIDRef riid, void **result)
1652 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1653 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1656 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1658 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1659 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1662 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1664 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1665 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1668 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1669 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1671 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1672 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1673 return NS_ERROR_NOT_IMPLEMENTED;
1676 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1677 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1679 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1680 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1681 return NS_ERROR_NOT_IMPLEMENTED;
1684 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1686 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1688 TRACE("(%p)\n", This);
1690 return nsIBaseWindow_SetFocus(This->window);
1693 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1694 cpp_bool *aVisibility)
1696 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1698 TRACE("(%p)->(%p)\n", This, aVisibility);
1700 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1704 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1705 cpp_bool aVisibility)
1707 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1709 TRACE("(%p)->(%x)\n", This, aVisibility);
1714 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1717 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1718 WARN("(%p)->(%p)\n", This, aTitle);
1719 return NS_ERROR_NOT_IMPLEMENTED;
1722 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1723 const PRUnichar *aTitle)
1725 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1726 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1727 return NS_ERROR_NOT_IMPLEMENTED;
1730 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1733 NSContainer *This = impl_from_nsIEmbeddingSiteWindow(iface);
1735 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1737 *aSiteWindow = This->hwnd;
1741 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1742 nsEmbeddingSiteWindow_QueryInterface,
1743 nsEmbeddingSiteWindow_AddRef,
1744 nsEmbeddingSiteWindow_Release,
1745 nsEmbeddingSiteWindow_SetDimensions,
1746 nsEmbeddingSiteWindow_GetDimensions,
1747 nsEmbeddingSiteWindow_SetFocus,
1748 nsEmbeddingSiteWindow_GetVisibility,
1749 nsEmbeddingSiteWindow_SetVisibility,
1750 nsEmbeddingSiteWindow_GetTitle,
1751 nsEmbeddingSiteWindow_SetTitle,
1752 nsEmbeddingSiteWindow_GetSiteWindow
1755 static inline NSContainer *impl_from_nsITooltipListener(nsITooltipListener *iface)
1757 return CONTAINING_RECORD(iface, NSContainer, nsITooltipListener_iface);
1760 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1763 NSContainer *This = impl_from_nsITooltipListener(iface);
1764 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1767 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1769 NSContainer *This = impl_from_nsITooltipListener(iface);
1770 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1773 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1775 NSContainer *This = impl_from_nsITooltipListener(iface);
1776 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1779 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1780 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1782 NSContainer *This = impl_from_nsITooltipListener(iface);
1785 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1790 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1792 NSContainer *This = impl_from_nsITooltipListener(iface);
1795 hide_tooltip(This->doc);
1800 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1801 nsTooltipListener_QueryInterface,
1802 nsTooltipListener_AddRef,
1803 nsTooltipListener_Release,
1804 nsTooltipListener_OnShowTooltip,
1805 nsTooltipListener_OnHideTooltip
1808 static inline NSContainer *impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor *iface)
1810 return CONTAINING_RECORD(iface, NSContainer, nsIInterfaceRequestor_iface);
1813 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1814 nsIIDRef riid, void **result)
1816 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1817 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1820 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1822 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1823 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1826 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1828 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1829 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1832 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1833 nsIIDRef riid, void **result)
1835 NSContainer *This = impl_from_nsIInterfaceRequestor(iface);
1837 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1838 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1839 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1842 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1845 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1846 nsInterfaceRequestor_QueryInterface,
1847 nsInterfaceRequestor_AddRef,
1848 nsInterfaceRequestor_Release,
1849 nsInterfaceRequestor_GetInterface
1852 static inline NSContainer *impl_from_nsISupportsWeakReference(nsISupportsWeakReference *iface)
1854 return CONTAINING_RECORD(iface, NSContainer, nsISupportsWeakReference_iface);
1857 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1858 nsIIDRef riid, void **result)
1860 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1861 return nsIWebBrowserChrome_QueryInterface(&This->nsIWebBrowserChrome_iface, riid, result);
1864 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1866 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1867 return nsIWebBrowserChrome_AddRef(&This->nsIWebBrowserChrome_iface);
1870 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1872 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1873 return nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);
1876 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1877 nsIWeakReference **_retval)
1879 NSContainer *This = impl_from_nsISupportsWeakReference(iface);
1881 TRACE("(%p)->(%p)\n", This, _retval);
1883 if(!This->weak_reference) {
1884 This->weak_reference = heap_alloc(sizeof(nsWeakReference));
1885 if(!This->weak_reference)
1886 return NS_ERROR_OUT_OF_MEMORY;
1888 This->weak_reference->nsIWeakReference_iface.lpVtbl = &nsWeakReferenceVtbl;
1889 This->weak_reference->ref = 1;
1890 This->weak_reference->nscontainer = This;
1893 *_retval = &This->weak_reference->nsIWeakReference_iface;
1894 nsIWeakReference_AddRef(*_retval);
1898 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1899 nsSupportsWeakReference_QueryInterface,
1900 nsSupportsWeakReference_AddRef,
1901 nsSupportsWeakReference_Release,
1902 nsSupportsWeakReference_GetWeakReference
1905 static HRESULT init_nscontainer(NSContainer *nscontainer)
1907 nsIWebBrowserSetup *wbsetup;
1908 nsIScrollable *scrollable;
1911 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1912 NULL, &IID_nsIWebBrowser, (void**)&nscontainer->webbrowser);
1913 if(NS_FAILED(nsres)) {
1914 ERR("Creating WebBrowser failed: %08x\n", nsres);
1918 nsres = nsIWebBrowser_SetContainerWindow(nscontainer->webbrowser, &nscontainer->nsIWebBrowserChrome_iface);
1919 if(NS_FAILED(nsres)) {
1920 ERR("SetContainerWindow failed: %08x\n", nsres);
1924 nsres = nsIWebBrowser_QueryInterface(nscontainer->webbrowser, &IID_nsIBaseWindow,
1925 (void**)&nscontainer->window);
1926 if(NS_FAILED(nsres)) {
1927 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1931 nsres = nsIWebBrowser_QueryInterface(nscontainer->webbrowser, &IID_nsIWebBrowserSetup,
1933 if(NS_SUCCEEDED(nsres)) {
1934 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1935 nsIWebBrowserSetup_Release(wbsetup);
1936 if(NS_FAILED(nsres)) {
1937 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1941 ERR("Could not get nsIWebBrowserSetup interface\n");
1945 nsres = nsIWebBrowser_QueryInterface(nscontainer->webbrowser, &IID_nsIWebNavigation,
1946 (void**)&nscontainer->navigation);
1947 if(NS_FAILED(nsres)) {
1948 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1952 nsres = nsIWebBrowser_QueryInterface(nscontainer->webbrowser, &IID_nsIWebBrowserFocus,
1953 (void**)&nscontainer->focus);
1954 if(NS_FAILED(nsres)) {
1955 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1959 if(!nscontainer_class) {
1960 register_nscontainer_class();
1961 if(!nscontainer_class)
1965 nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1966 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1967 GetDesktopWindow(), NULL, hInst, nscontainer);
1968 if(!nscontainer->hwnd) {
1969 WARN("Could not create window\n");
1973 nsres = nsIBaseWindow_InitWindow(nscontainer->window, nscontainer->hwnd, NULL, 0, 0, 100, 100);
1974 if(NS_SUCCEEDED(nsres)) {
1975 nsres = nsIBaseWindow_Create(nscontainer->window);
1976 if(NS_FAILED(nsres)) {
1977 WARN("Creating window failed: %08x\n", nsres);
1981 nsIBaseWindow_SetVisibility(nscontainer->window, FALSE);
1982 nsIBaseWindow_SetEnabled(nscontainer->window, FALSE);
1984 ERR("InitWindow failed: %08x\n", nsres);
1988 nsres = nsIWebBrowser_SetParentURIContentListener(nscontainer->webbrowser,
1989 &nscontainer->nsIURIContentListener_iface);
1990 if(NS_FAILED(nsres))
1991 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1993 nsres = nsIWebBrowser_QueryInterface(nscontainer->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1994 if(NS_SUCCEEDED(nsres)) {
1995 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1996 ScrollOrientation_Y, Scrollbar_Always);
1997 if(NS_FAILED(nsres))
1998 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
2000 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
2001 ScrollOrientation_X, Scrollbar_Auto);
2002 if(NS_FAILED(nsres))
2003 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
2005 nsIScrollable_Release(scrollable);
2007 ERR("Could not get nsIScrollable: %08x\n", nsres);
2013 HRESULT create_nscontainer(HTMLDocumentObj *doc, NSContainer **_ret)
2019 return CLASS_E_CLASSNOTAVAILABLE;
2021 ret = heap_alloc_zero(sizeof(NSContainer));
2023 return E_OUTOFMEMORY;
2025 ret->nsIWebBrowserChrome_iface.lpVtbl = &nsWebBrowserChromeVtbl;
2026 ret->nsIContextMenuListener_iface.lpVtbl = &nsContextMenuListenerVtbl;
2027 ret->nsIURIContentListener_iface.lpVtbl = &nsURIContentListenerVtbl;
2028 ret->nsIEmbeddingSiteWindow_iface.lpVtbl = &nsEmbeddingSiteWindowVtbl;
2029 ret->nsITooltipListener_iface.lpVtbl = &nsTooltipListenerVtbl;
2030 ret->nsIInterfaceRequestor_iface.lpVtbl = &nsInterfaceRequestorVtbl;
2031 ret->nsISupportsWeakReference_iface.lpVtbl = &nsSupportsWeakReferenceVtbl;
2036 hres = init_nscontainer(ret);
2040 nsIWebBrowserChrome_Release(&ret->nsIWebBrowserChrome_iface);
2044 void NSContainer_Release(NSContainer *This)
2046 TRACE("(%p)\n", This);
2050 ShowWindow(This->hwnd, SW_HIDE);
2051 SetParent(This->hwnd, NULL);
2053 nsIBaseWindow_SetVisibility(This->window, FALSE);
2054 nsIBaseWindow_Destroy(This->window);
2056 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
2058 nsIWebBrowser_Release(This->webbrowser);
2059 This->webbrowser = NULL;
2061 nsIWebNavigation_Release(This->navigation);
2062 This->navigation = NULL;
2064 nsIBaseWindow_Release(This->window);
2065 This->window = NULL;
2067 nsIWebBrowserFocus_Release(This->focus);
2070 if(This->editor_controller) {
2071 nsIController_Release(This->editor_controller);
2072 This->editor_controller = NULL;
2076 nsIEditor_Release(This->editor);
2077 This->editor = NULL;
2080 if(This->content_listener) {
2081 nsIURIContentListener_Release(This->content_listener);
2082 This->content_listener = NULL;
2086 DestroyWindow(This->hwnd);
2090 nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface);