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
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);
88 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider, riid)) {
89 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result);
92 WARN("(%s %p)\n", debugstr_guid(riid), result);
94 return NS_NOINTERFACE;
97 nsISupports_AddRef((nsISupports*)*result);
101 static nsrefcnt NSAPI nsDirectoryServiceProvider_AddRef(nsIDirectoryServiceProvider *iface)
106 static nsrefcnt NSAPI nsDirectoryServiceProvider_Release(nsIDirectoryServiceProvider *iface)
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)];
121 hres = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_DEFAULT, path);
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);
136 nsres = nsIFile_Exists(profile_directory, &exists);
137 if(NS_FAILED(nsres)) {
138 ERR("Exists failed: %08x\n", nsres);
143 nsres = nsIFile_Create(profile_directory, 1, 0700);
145 ERR("Create failed: %08x\n", 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) {
160 nsres = create_profile_directory();
165 return nsIFile_Clone(profile_directory, _retval);
168 return NS_ERROR_FAILURE;
171 #undef NSWEAKREF_THIS
173 static const nsIDirectoryServiceProviderVtbl nsDirectoryServiceProviderVtbl = {
174 nsDirectoryServiceProvider_QueryInterface,
175 nsDirectoryServiceProvider_AddRef,
176 nsDirectoryServiceProvider_Release,
177 nsDirectoryServiceProvider_GetFile
180 static nsIDirectoryServiceProvider nsDirectoryServiceProvider =
181 { &nsDirectoryServiceProviderVtbl };
183 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
188 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
190 if(msg == WM_CREATE) {
191 This = *(NSContainer**)lParam;
192 SetPropW(hwnd, wszTHIS, This);
194 This = GetPropW(hwnd, wszTHIS);
199 TRACE("(%p)->(WM_SIZE)\n", This);
201 nsres = nsIBaseWindow_SetSize(This->window,
202 LOWORD(lParam), HIWORD(lParam), TRUE);
204 WARN("SetSize failed: %08x\n", nsres);
207 case WM_PARENTNOTIFY:
208 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam);
213 nsIWebBrowserFocus_Activate(This->focus);
217 return DefWindowProcW(hwnd, msg, wParam, lParam);
221 static void register_nscontainer_class(void)
223 static WNDCLASSEXW wndclass = {
227 0, 0, NULL, NULL, NULL, NULL, NULL,
231 wndclass.hInstance = hInst;
232 nscontainer_class = RegisterClassExW(&wndclass);
235 static void set_environment(LPCWSTR gre_path)
237 WCHAR path_env[MAX_PATH], buf[20];
238 int len, debug_level = 0;
240 static const WCHAR pathW[] = {'P','A','T','H',0};
241 static const WCHAR warnW[] = {'w','a','r','n',0};
242 static const WCHAR xpcom_debug_breakW[] =
243 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
244 static const WCHAR nspr_log_modulesW[] =
245 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
246 static const WCHAR debug_formatW[] = {'a','l','l',':','%','d',0};
247 static const WCHAR moz_plugin_pathW[] = {'M','O','Z','_','P','L','U','G','I','N','_','P','A','T','H',0};
248 static const WCHAR gecko_pluginW[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
250 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
251 GetEnvironmentVariableW(pathW, path_env, sizeof(path_env)/sizeof(WCHAR));
252 len = strlenW(path_env);
253 path_env[len++] = ';';
254 strcpyW(path_env+len, gre_path);
255 SetEnvironmentVariableW(pathW, path_env);
257 SetEnvironmentVariableW(xpcom_debug_breakW, warnW);
261 else if(WARN_ON(gecko))
263 else if(ERR_ON(gecko))
266 sprintfW(buf, debug_formatW, debug_level);
267 SetEnvironmentVariableW(nspr_log_modulesW, buf);
269 len = GetSystemDirectoryW(path_env, (sizeof(path_env)-sizeof(gecko_pluginW))/sizeof(WCHAR)+1);
271 strcpyW(path_env+len, gecko_pluginW);
272 SetEnvironmentVariableW(moz_plugin_pathW, path_env);
276 static BOOL load_xpcom(const PRUnichar *gre_path)
278 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
280 TRACE("(%s)\n", debugstr_w(gre_path));
282 set_environment(gre_path);
284 hXPCOM = LoadLibraryW(strXPCOM);
286 WARN("Could not load XPCOM: %d\n", GetLastError());
290 #define NS_DLSYM(func) \
291 func = (void *)GetProcAddress(hXPCOM, #func); \
293 ERR("Could not GetProcAddress(" #func ") failed\n")
295 NS_DLSYM(NS_InitXPCOM2);
296 NS_DLSYM(NS_ShutdownXPCOM);
297 NS_DLSYM(NS_GetComponentRegistrar);
298 NS_DLSYM(NS_StringContainerInit2);
299 NS_DLSYM(NS_CStringContainerInit2);
300 NS_DLSYM(NS_StringContainerFinish);
301 NS_DLSYM(NS_CStringContainerFinish);
302 NS_DLSYM(NS_StringSetData);
303 NS_DLSYM(NS_CStringSetData);
304 NS_DLSYM(NS_NewLocalFile);
305 NS_DLSYM(NS_StringGetData);
306 NS_DLSYM(NS_CStringGetData);
313 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
315 WCHAR file_name[MAX_PATH];
320 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
322 strcpyW(file_name, gre_path);
323 strcatW(file_name, wszVersion);
325 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
326 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
327 if(hfile == INVALID_HANDLE_VALUE) {
328 ERR("Could not open VERSION file\n");
332 ReadFile(hfile, version, sizeof(version), &read, NULL);
336 TRACE("%s\n", debugstr_a(version));
338 if(strcmp(version, version_string)) {
339 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
340 debugstr_a(version_string));
347 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
348 const char *version, const char *version_string)
350 DWORD res, type, size = MAX_PATH;
351 HKEY hkey = mshtml_key;
353 static const WCHAR wszGeckoPath[] =
354 {'G','e','c','k','o','P','a','t','h',0};
357 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
358 res = RegOpenKeyA(mshtml_key, version, &hkey);
359 if(res != ERROR_SUCCESS)
363 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
364 if(hkey != mshtml_key)
366 if(res != ERROR_SUCCESS || type != REG_SZ)
369 if(!check_version(gre_path, version_string))
372 return load_xpcom(gre_path);
375 static BOOL load_wine_gecko(PRUnichar *gre_path)
381 static const WCHAR wszMshtmlKey[] = {
382 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
383 '\\','M','S','H','T','M','L',0};
385 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
386 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
387 if(res != ERROR_SUCCESS)
390 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING);
396 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
400 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
402 ERR("Could not set pref %s\n", debugstr_a(pref_name));
405 static void set_int_pref(nsIPrefBranch *pref, const char *pref_name, int val)
409 nsres = nsIPrefBranch_SetIntPref(pref, pref_name, val);
411 ERR("Could not set pref %s\n", debugstr_a(pref_name));
414 static void set_string_pref(nsIPrefBranch *pref, const char *pref_name, const char *val)
418 nsres = nsIPrefBranch_SetCharPref(pref, pref_name, val);
420 ERR("Could not set pref %s\n", debugstr_a(pref_name));
423 static void set_lang(nsIPrefBranch *pref)
426 DWORD res, size, type;
429 static const WCHAR international_keyW[] =
430 {'S','o','f','t','w','a','r','e',
431 '\\','M','i','c','r','o','s','o','f','t',
432 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
433 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
435 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
436 if(res != ERROR_SUCCESS)
439 size = sizeof(langs);
440 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
442 if(res != ERROR_SUCCESS || type != REG_SZ)
445 TRACE("Setting lang %s\n", debugstr_a(langs));
447 set_string_pref(pref, "intl.accept_languages", langs);
450 static void set_proxy(nsIPrefBranch *pref)
455 DWORD enabled = 0, res, size, type;
458 static const WCHAR proxy_keyW[] =
459 {'S','o','f','t','w','a','r','e',
460 '\\','M','i','c','r','o','s','o','f','t',
461 '\\','W','i','n','d','o','w','s',
462 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
463 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
465 res = RegOpenKeyW(HKEY_CURRENT_USER, proxy_keyW, &hkey);
466 if(res != ERROR_SUCCESS)
469 size = sizeof(enabled);
470 res = RegQueryValueExA(hkey, "ProxyEnable", 0, &type, (LPBYTE)&enabled, &size);
471 if(res != ERROR_SUCCESS || type != REG_DWORD || enabled == 0)
477 size = sizeof(proxy);
478 res = RegQueryValueExA(hkey, "ProxyServer", 0, &type, (LPBYTE)proxy, &size);
480 if(res != ERROR_SUCCESS || type != REG_SZ)
483 proxy_port = strchr(proxy, ':');
488 proxy_port_num = atoi(proxy_port + 1);
489 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy), proxy_port_num);
491 set_string_pref(pref, "network.proxy.http", proxy);
492 set_string_pref(pref, "network.proxy.ssl", proxy);
494 set_int_pref(pref, "network.proxy.type", 1);
495 set_int_pref(pref, "network.proxy.http_port", proxy_port_num);
496 set_int_pref(pref, "network.proxy.ssl_port", proxy_port_num);
499 static void set_preferences(void)
504 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
505 &IID_nsIPrefBranch, (void**)&pref);
506 if(NS_FAILED(nsres)) {
507 ERR("Could not get preference service: %08x\n", nsres);
513 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
514 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
515 set_int_pref(pref, "layout.spellcheckDefault", 0);
517 nsIPrefBranch_Release(pref);
520 static BOOL init_xpcom(const PRUnichar *gre_path)
523 nsIObserver *pStartNotif;
524 nsIComponentRegistrar *registrar = NULL;
529 nsAString_InitDepend(&path, gre_path);
530 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
531 nsAString_Finish(&path);
532 if(NS_FAILED(nsres)) {
533 ERR("NS_NewLocalFile failed: %08x\n", nsres);
538 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, &nsDirectoryServiceProvider);
539 if(NS_FAILED(nsres)) {
540 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
545 strcpyW(gecko_path, gre_path);
546 for(ptr = gecko_path; *ptr; ptr++) {
550 gecko_path_len = ptr-gecko_path;
552 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
554 ERR("Could not get nsIComponentManager: %08x\n", nsres);
556 nsres = NS_GetComponentRegistrar(®istrar);
557 if(NS_SUCCEEDED(nsres))
558 init_nsio(pCompMgr, registrar);
560 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
562 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
563 NULL, &IID_nsIObserver, (void**)&pStartNotif);
564 if(NS_SUCCEEDED(nsres)) {
565 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
567 ERR("Observe failed: %08x\n", nsres);
569 nsIObserver_Release(pStartNotif);
571 ERR("could not get appstartup-notifier: %08x\n", nsres);
576 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
577 NULL, &IID_nsIMemory, (void**)&nsmem);
579 ERR("Could not get nsIMemory: %08x\n", nsres);
582 register_nsservice(registrar, pServMgr);
583 nsIComponentRegistrar_Release(registrar);
589 static CRITICAL_SECTION cs_load_gecko;
590 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
592 0, 0, &cs_load_gecko,
593 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
594 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
596 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
598 BOOL load_gecko(BOOL silent)
600 PRUnichar gre_path[MAX_PATH];
603 static DWORD loading_thread;
607 /* load_gecko may be called recursively */
608 if(loading_thread == GetCurrentThreadId())
609 return pCompMgr != NULL;
611 EnterCriticalSection(&cs_load_gecko);
613 if(!loading_thread) {
614 loading_thread = GetCurrentThreadId();
616 if(load_wine_gecko(gre_path)
617 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
618 ret = init_xpcom(gre_path);
620 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
622 ret = pCompMgr != NULL;
625 LeaveCriticalSection(&cs_load_gecko);
630 void *nsalloc(size_t size)
632 return nsIMemory_Alloc(nsmem, size);
635 void nsfree(void *mem)
637 nsIMemory_Free(nsmem, mem);
640 static BOOL nsACString_Init(nsACString *str, const char *data)
642 return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
646 * Initializes nsACString with data owned by caller.
647 * Caller must ensure that data is valid during lifetime of string object.
649 void nsACString_InitDepend(nsACString *str, const char *data)
651 NS_CStringContainerInit2(str, data, PR_UINT32_MAX, NS_CSTRING_CONTAINER_INIT_DEPEND);
654 void nsACString_SetData(nsACString *str, const char *data)
656 NS_CStringSetData(str, data, PR_UINT32_MAX);
659 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
661 return NS_CStringGetData(str, data, NULL);
664 void nsACString_Finish(nsACString *str)
666 NS_CStringContainerFinish(str);
669 BOOL nsAString_Init(nsAString *str, const PRUnichar *data)
671 return NS_SUCCEEDED(NS_StringContainerInit2(str, data, PR_UINT32_MAX, 0));
675 * Initializes nsAString with data owned by caller.
676 * Caller must ensure that data is valid during lifetime of string object.
678 void nsAString_InitDepend(nsAString *str, const PRUnichar *data)
680 NS_StringContainerInit2(str, data, PR_UINT32_MAX, NS_STRING_CONTAINER_INIT_DEPEND);
683 void nsAString_SetData(nsAString *str, const PRUnichar *data)
685 NS_StringSetData(str, data, PR_UINT32_MAX);
688 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
690 return NS_StringGetData(str, data, NULL);
693 void nsAString_Finish(nsAString *str)
695 NS_StringContainerFinish(str);
698 nsICommandParams *create_nscommand_params(void)
700 nsICommandParams *ret = NULL;
706 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
707 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
710 ERR("Could not get nsICommandParams\n");
715 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
717 nsIInterfaceRequestor *iface_req;
720 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
724 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
725 nsIInterfaceRequestor_Release(iface_req);
730 static HRESULT nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
732 nsIDOMNodeList *node_list = NULL;
733 PRBool has_children = FALSE;
734 nsIContent *nscontent;
738 nsIDOMNode_HasChildNodes(nsnode, &has_children);
740 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
741 if(NS_FAILED(nsres)) {
742 ERR("GetType failed: %08x\n", nsres);
746 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIContent, (void**)&nscontent);
747 if(NS_FAILED(nsres)) {
748 ERR("Could not get nsIDontent interface: %08x\n", nsres);
754 nsIContentSerializer_AppendElementStart(serializer, nscontent, nscontent, str);
757 nsIContentSerializer_AppendText(serializer, nscontent, 0, -1, str);
760 nsres = nsIContentSerializer_AppendComment(serializer, nscontent, 0, -1, str);
762 case DOCUMENT_NODE: {
764 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDocument, (void**)&nsdoc);
765 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
766 nsIDocument_Release(nsdoc);
769 case DOCUMENT_TYPE_NODE:
770 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
772 case DOCUMENT_FRAGMENT_NODE:
775 FIXME("Unhandled type %u\n", type);
779 PRUint32 child_cnt, i;
780 nsIDOMNode *child_node;
782 nsIDOMNode_GetChildNodes(nsnode, &node_list);
783 nsIDOMNodeList_GetLength(node_list, &child_cnt);
785 for(i=0; i<child_cnt; i++) {
786 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
787 if(NS_SUCCEEDED(nsres)) {
788 nsnode_to_nsstring_rec(serializer, child_node, str);
789 nsIDOMNode_Release(child_node);
791 ERR("Item failed: %08x\n", nsres);
795 nsIDOMNodeList_Release(node_list);
798 if(type == ELEMENT_NODE)
799 nsIContentSerializer_AppendElementEnd(serializer, nscontent, str);
801 nsIContent_Release(nscontent);
805 HRESULT nsnode_to_nsstring(nsIDOMNode *nsnode, nsAString *str)
807 nsIContentSerializer *serializer;
811 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
812 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
813 (void**)&serializer);
814 if(NS_FAILED(nsres)) {
815 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
819 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE, FALSE /* FIXME */);
821 ERR("Init failed: %08x\n", nsres);
823 hres = nsnode_to_nsstring_rec(serializer, nsnode, str);
824 if(SUCCEEDED(hres)) {
825 nsres = nsIContentSerializer_Flush(serializer, str);
827 ERR("Flush failed: %08x\n", nsres);
830 nsIContentSerializer_Release(serializer);
834 void get_editor_controller(NSContainer *This)
836 nsIEditingSession *editing_session = NULL;
837 nsIControllerContext *ctrlctx;
841 nsIEditor_Release(This->editor);
845 if(This->editor_controller) {
846 nsIController_Release(This->editor_controller);
847 This->editor_controller = NULL;
850 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
851 (void**)&editing_session);
852 if(NS_FAILED(nsres)) {
853 ERR("Could not get nsIEditingSession: %08x\n", nsres);
857 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
858 This->doc->basedoc.window->nswindow, &This->editor);
859 nsIEditingSession_Release(editing_session);
860 if(NS_FAILED(nsres)) {
861 ERR("Could not get editor: %08x\n", nsres);
865 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
866 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
867 if(NS_SUCCEEDED(nsres)) {
868 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
870 ERR("SetCommandContext failed: %08x\n", nsres);
871 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
872 (void**)&This->editor_controller);
873 nsIControllerContext_Release(ctrlctx);
875 ERR("Could not get nsIController interface: %08x\n", nsres);
877 ERR("Could not create edit controller: %08x\n", nsres);
881 void close_gecko(void)
887 if(profile_directory) {
888 nsIFile_Release(profile_directory);
889 profile_directory = NULL;
893 nsIComponentManager_Release(pCompMgr);
896 nsIServiceManager_Release(pServMgr);
899 nsIMemory_Release(nsmem);
901 /* Gecko doesn't really support being unloaded */
902 /* if (hXPCOM) FreeLibrary(hXPCOM); */
905 BOOL is_gecko_path(const char *path)
910 buf = heap_strdupAtoW(path);
911 if(strlenW(buf) < gecko_path_len)
914 buf[gecko_path_len] = 0;
915 for(ptr = buf; *ptr; ptr++) {
920 ret = !strcmpiW(buf, gecko_path);
925 /**********************************************************
926 * nsIWebBrowserChrome interface
929 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
931 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
932 nsIIDRef riid, void **result)
934 NSContainer *This = NSWBCHROME_THIS(iface);
937 if(IsEqualGUID(&IID_nsISupports, riid)) {
938 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
939 *result = NSWBCHROME(This);
940 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
941 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
942 *result = NSWBCHROME(This);
943 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
944 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
945 *result = NSCML(This);
946 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
947 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
948 *result = NSURICL(This);
949 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
950 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
951 *result = NSEMBWNDS(This);
952 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
953 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
954 *result = NSTOOLTIP(This);
955 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
956 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
957 *result = NSIFACEREQ(This);
958 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
959 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
960 *result = NSWEAKREF(This);
961 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
962 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
963 *result = NSSUPWEAKREF(This);
967 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
971 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
972 return NS_NOINTERFACE;
975 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
977 NSContainer *This = NSWBCHROME_THIS(iface);
978 LONG ref = InterlockedIncrement(&This->ref);
980 TRACE("(%p) ref=%d\n", This, ref);
985 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
987 NSContainer *This = NSWBCHROME_THIS(iface);
988 LONG ref = InterlockedDecrement(&This->ref);
990 TRACE("(%p) ref=%d\n", This, ref);
994 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
1001 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
1002 PRUint32 statusType, const PRUnichar *status)
1004 NSContainer *This = NSWBCHROME_THIS(iface);
1005 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
1009 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
1010 nsIWebBrowser **aWebBrowser)
1012 NSContainer *This = NSWBCHROME_THIS(iface);
1014 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1017 return NS_ERROR_INVALID_ARG;
1019 if(This->webbrowser)
1020 nsIWebBrowser_AddRef(This->webbrowser);
1021 *aWebBrowser = This->webbrowser;
1025 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
1026 nsIWebBrowser *aWebBrowser)
1028 NSContainer *This = NSWBCHROME_THIS(iface);
1030 TRACE("(%p)->(%p)\n", This, aWebBrowser);
1032 if(aWebBrowser != This->webbrowser)
1033 ERR("Wrong nsWebBrowser!\n");
1038 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
1039 PRUint32 *aChromeFlags)
1041 NSContainer *This = NSWBCHROME_THIS(iface);
1042 WARN("(%p)->(%p)\n", This, aChromeFlags);
1043 return NS_ERROR_NOT_IMPLEMENTED;
1046 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
1047 PRUint32 aChromeFlags)
1049 NSContainer *This = NSWBCHROME_THIS(iface);
1050 WARN("(%p)->(%08x)\n", This, aChromeFlags);
1051 return NS_ERROR_NOT_IMPLEMENTED;
1054 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
1056 NSContainer *This = NSWBCHROME_THIS(iface);
1057 TRACE("(%p)\n", This);
1058 return NS_ERROR_NOT_IMPLEMENTED;
1061 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
1062 PRInt32 aCX, PRInt32 aCY)
1064 NSContainer *This = NSWBCHROME_THIS(iface);
1065 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
1066 return NS_ERROR_NOT_IMPLEMENTED;
1069 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
1071 NSContainer *This = NSWBCHROME_THIS(iface);
1072 WARN("(%p)\n", This);
1073 return NS_ERROR_NOT_IMPLEMENTED;
1076 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
1078 NSContainer *This = NSWBCHROME_THIS(iface);
1079 WARN("(%p)->(%p)\n", This, _retval);
1080 return NS_ERROR_NOT_IMPLEMENTED;
1083 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
1086 NSContainer *This = NSWBCHROME_THIS(iface);
1087 WARN("(%p)->(%08x)\n", This, aStatus);
1088 return NS_ERROR_NOT_IMPLEMENTED;
1091 #undef NSWBCHROME_THIS
1093 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
1094 nsWebBrowserChrome_QueryInterface,
1095 nsWebBrowserChrome_AddRef,
1096 nsWebBrowserChrome_Release,
1097 nsWebBrowserChrome_SetStatus,
1098 nsWebBrowserChrome_GetWebBrowser,
1099 nsWebBrowserChrome_SetWebBrowser,
1100 nsWebBrowserChrome_GetChromeFlags,
1101 nsWebBrowserChrome_SetChromeFlags,
1102 nsWebBrowserChrome_DestroyBrowserWindow,
1103 nsWebBrowserChrome_SizeBrowserTo,
1104 nsWebBrowserChrome_ShowAsModal,
1105 nsWebBrowserChrome_IsWindowModal,
1106 nsWebBrowserChrome_ExitModalEventLoop
1109 /**********************************************************
1110 * nsIContextMenuListener interface
1113 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1115 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1116 nsIIDRef riid, void **result)
1118 NSContainer *This = NSCML_THIS(iface);
1119 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1122 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1124 NSContainer *This = NSCML_THIS(iface);
1125 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1128 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1130 NSContainer *This = NSCML_THIS(iface);
1131 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1134 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1135 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1137 NSContainer *This = NSCML_THIS(iface);
1138 nsIDOMMouseEvent *event;
1141 DWORD dwID = CONTEXT_MENU_DEFAULT;
1145 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1147 fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent);
1149 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1150 if(NS_FAILED(nsres)) {
1151 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1155 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1156 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1157 nsIDOMMouseEvent_Release(event);
1159 switch(aContextFlags) {
1161 case CONTEXT_DOCUMENT:
1163 dwID = CONTEXT_MENU_DEFAULT;
1166 case CONTEXT_IMAGE|CONTEXT_LINK:
1167 dwID = CONTEXT_MENU_IMAGE;
1170 dwID = CONTEXT_MENU_ANCHOR;
1173 dwID = CONTEXT_MENU_CONTROL;
1176 FIXME("aContextFlags=%08x\n", aContextFlags);
1179 hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
1181 return NS_ERROR_FAILURE;
1183 show_context_menu(This->doc, dwID, &pt, (IDispatch*)HTMLDOMNODE(node));
1189 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1190 nsContextMenuListener_QueryInterface,
1191 nsContextMenuListener_AddRef,
1192 nsContextMenuListener_Release,
1193 nsContextMenuListener_OnShowContextMenu
1196 /**********************************************************
1197 * nsIURIContentListener interface
1200 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1202 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1203 nsIIDRef riid, void **result)
1205 NSContainer *This = NSURICL_THIS(iface);
1206 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1209 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1211 NSContainer *This = NSURICL_THIS(iface);
1212 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1215 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1217 NSContainer *This = NSURICL_THIS(iface);
1218 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1221 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1222 nsIURI *aURI, PRBool *_retval)
1224 NSContainer *This = NSURICL_THIS(iface);
1225 nsACString spec_str;
1229 nsACString_Init(&spec_str, NULL);
1230 nsIURI_GetSpec(aURI, &spec_str);
1231 nsACString_GetData(&spec_str, &spec);
1233 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1235 nsACString_Finish(&spec_str);
1237 nsres = on_start_uri_open(This, aURI, _retval);
1238 if(NS_FAILED(nsres))
1241 return !*_retval && This->content_listener
1242 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1246 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1247 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1248 nsIStreamListener **aContentHandler, PRBool *_retval)
1250 NSContainer *This = NSURICL_THIS(iface);
1252 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1253 aRequest, aContentHandler, _retval);
1255 return This->content_listener
1256 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1257 aIsContentPreferred, aRequest, aContentHandler, _retval)
1258 : NS_ERROR_NOT_IMPLEMENTED;
1261 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1262 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1264 NSContainer *This = NSURICL_THIS(iface);
1266 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1268 /* FIXME: Should we do something here? */
1271 return This->content_listener
1272 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1273 aDesiredContentType, _retval)
1277 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1278 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1281 NSContainer *This = NSURICL_THIS(iface);
1283 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1284 aDesiredContentType, _retval);
1286 return This->content_listener
1287 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1288 aIsContentPreferred, aDesiredContentType, _retval)
1289 : NS_ERROR_NOT_IMPLEMENTED;
1292 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1293 nsISupports **aLoadCookie)
1295 NSContainer *This = NSURICL_THIS(iface);
1297 WARN("(%p)->(%p)\n", This, aLoadCookie);
1299 return This->content_listener
1300 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1301 : NS_ERROR_NOT_IMPLEMENTED;
1304 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1305 nsISupports *aLoadCookie)
1307 NSContainer *This = NSURICL_THIS(iface);
1309 WARN("(%p)->(%p)\n", This, aLoadCookie);
1311 return This->content_listener
1312 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1313 : NS_ERROR_NOT_IMPLEMENTED;
1316 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1317 nsIURIContentListener **aParentContentListener)
1319 NSContainer *This = NSURICL_THIS(iface);
1321 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1323 if(This->content_listener)
1324 nsIURIContentListener_AddRef(This->content_listener);
1326 *aParentContentListener = This->content_listener;
1330 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1331 nsIURIContentListener *aParentContentListener)
1333 NSContainer *This = NSURICL_THIS(iface);
1335 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1337 if(aParentContentListener == NSURICL(This))
1340 if(This->content_listener)
1341 nsIURIContentListener_Release(This->content_listener);
1343 This->content_listener = aParentContentListener;
1344 if(This->content_listener)
1345 nsIURIContentListener_AddRef(This->content_listener);
1352 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1353 nsURIContentListener_QueryInterface,
1354 nsURIContentListener_AddRef,
1355 nsURIContentListener_Release,
1356 nsURIContentListener_OnStartURIOpen,
1357 nsURIContentListener_DoContent,
1358 nsURIContentListener_IsPreferred,
1359 nsURIContentListener_CanHandleContent,
1360 nsURIContentListener_GetLoadCookie,
1361 nsURIContentListener_SetLoadCookie,
1362 nsURIContentListener_GetParentContentListener,
1363 nsURIContentListener_SetParentContentListener
1366 /**********************************************************
1367 * nsIEmbeddinSiteWindow interface
1370 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1372 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1373 nsIIDRef riid, void **result)
1375 NSContainer *This = NSEMBWNDS_THIS(iface);
1376 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1379 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1381 NSContainer *This = NSEMBWNDS_THIS(iface);
1382 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1385 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1387 NSContainer *This = NSEMBWNDS_THIS(iface);
1388 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1391 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1392 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1394 NSContainer *This = NSEMBWNDS_THIS(iface);
1395 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1396 return NS_ERROR_NOT_IMPLEMENTED;
1399 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1400 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1402 NSContainer *This = NSEMBWNDS_THIS(iface);
1403 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1404 return NS_ERROR_NOT_IMPLEMENTED;
1407 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1409 NSContainer *This = NSEMBWNDS_THIS(iface);
1411 TRACE("(%p)\n", This);
1413 return nsIBaseWindow_SetFocus(This->window);
1416 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1417 PRBool *aVisibility)
1419 NSContainer *This = NSEMBWNDS_THIS(iface);
1421 TRACE("(%p)->(%p)\n", This, aVisibility);
1423 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1427 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1430 NSContainer *This = NSEMBWNDS_THIS(iface);
1432 TRACE("(%p)->(%x)\n", This, aVisibility);
1437 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1440 NSContainer *This = NSEMBWNDS_THIS(iface);
1441 WARN("(%p)->(%p)\n", This, aTitle);
1442 return NS_ERROR_NOT_IMPLEMENTED;
1445 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1446 const PRUnichar *aTitle)
1448 NSContainer *This = NSEMBWNDS_THIS(iface);
1449 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1450 return NS_ERROR_NOT_IMPLEMENTED;
1453 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1456 NSContainer *This = NSEMBWNDS_THIS(iface);
1458 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1460 *aSiteWindow = This->hwnd;
1464 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1465 nsEmbeddingSiteWindow_QueryInterface,
1466 nsEmbeddingSiteWindow_AddRef,
1467 nsEmbeddingSiteWindow_Release,
1468 nsEmbeddingSiteWindow_SetDimensions,
1469 nsEmbeddingSiteWindow_GetDimensions,
1470 nsEmbeddingSiteWindow_SetFocus,
1471 nsEmbeddingSiteWindow_GetVisibility,
1472 nsEmbeddingSiteWindow_SetVisibility,
1473 nsEmbeddingSiteWindow_GetTitle,
1474 nsEmbeddingSiteWindow_SetTitle,
1475 nsEmbeddingSiteWindow_GetSiteWindow
1478 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1480 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1483 NSContainer *This = NSTOOLTIP_THIS(iface);
1484 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1487 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1489 NSContainer *This = NSTOOLTIP_THIS(iface);
1490 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1493 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1495 NSContainer *This = NSTOOLTIP_THIS(iface);
1496 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1499 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1500 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1502 NSContainer *This = NSTOOLTIP_THIS(iface);
1505 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1510 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1512 NSContainer *This = NSTOOLTIP_THIS(iface);
1515 hide_tooltip(This->doc);
1520 #undef NSTOOLTIM_THIS
1522 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1523 nsTooltipListener_QueryInterface,
1524 nsTooltipListener_AddRef,
1525 nsTooltipListener_Release,
1526 nsTooltipListener_OnShowTooltip,
1527 nsTooltipListener_OnHideTooltip
1530 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1532 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1533 nsIIDRef riid, void **result)
1535 NSContainer *This = NSIFACEREQ_THIS(iface);
1536 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1539 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1541 NSContainer *This = NSIFACEREQ_THIS(iface);
1542 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1545 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1547 NSContainer *This = NSIFACEREQ_THIS(iface);
1548 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1551 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1552 nsIIDRef riid, void **result)
1554 NSContainer *This = NSIFACEREQ_THIS(iface);
1556 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1557 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1558 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1561 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1564 #undef NSIFACEREQ_THIS
1566 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1567 nsInterfaceRequestor_QueryInterface,
1568 nsInterfaceRequestor_AddRef,
1569 nsInterfaceRequestor_Release,
1570 nsInterfaceRequestor_GetInterface
1573 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1575 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1576 nsIIDRef riid, void **result)
1578 NSContainer *This = NSWEAKREF_THIS(iface);
1579 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1582 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1584 NSContainer *This = NSWEAKREF_THIS(iface);
1585 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1588 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1590 NSContainer *This = NSWEAKREF_THIS(iface);
1591 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1594 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1595 const nsIID *riid, void **result)
1597 NSContainer *This = NSWEAKREF_THIS(iface);
1598 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1601 #undef NSWEAKREF_THIS
1603 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1604 nsWeakReference_QueryInterface,
1605 nsWeakReference_AddRef,
1606 nsWeakReference_Release,
1607 nsWeakReference_QueryReferent
1610 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1612 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1613 nsIIDRef riid, void **result)
1615 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1616 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1619 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1621 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1622 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1625 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1627 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1628 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1631 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1632 nsIWeakReference **_retval)
1634 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1636 TRACE("(%p)->(%p)\n", This, _retval);
1638 nsIWeakReference_AddRef(NSWEAKREF(This));
1639 *_retval = NSWEAKREF(This);
1643 #undef NSWEAKREF_THIS
1645 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1646 nsSupportsWeakReference_QueryInterface,
1647 nsSupportsWeakReference_AddRef,
1648 nsSupportsWeakReference_Release,
1649 nsSupportsWeakReference_GetWeakReference
1653 NSContainer *NSContainer_Create(HTMLDocumentObj *doc, NSContainer *parent)
1655 nsIWebBrowserSetup *wbsetup;
1656 nsIScrollable *scrollable;
1660 if(!load_gecko(TRUE))
1663 ret = heap_alloc_zero(sizeof(NSContainer));
1665 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1666 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1667 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1668 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1669 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1670 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1671 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1672 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1677 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1678 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1679 if(NS_FAILED(nsres)) {
1680 ERR("Creating WebBrowser failed: %08x\n", nsres);
1686 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1687 ret->parent = parent;
1689 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1690 if(NS_FAILED(nsres))
1691 ERR("SetContainerWindow failed: %08x\n", nsres);
1693 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1694 (void**)&ret->window);
1695 if(NS_FAILED(nsres))
1696 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1698 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1700 if(NS_SUCCEEDED(nsres)) {
1701 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1702 nsIWebBrowserSetup_Release(wbsetup);
1703 if(NS_FAILED(nsres))
1704 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1706 ERR("Could not get nsIWebBrowserSetup interface\n");
1709 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1710 (void**)&ret->navigation);
1711 if(NS_FAILED(nsres))
1712 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1714 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1715 (void**)&ret->focus);
1716 if(NS_FAILED(nsres))
1717 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1719 if(!nscontainer_class)
1720 register_nscontainer_class();
1722 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1723 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1724 GetDesktopWindow(), NULL, hInst, ret);
1726 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1727 if(NS_SUCCEEDED(nsres)) {
1728 nsres = nsIBaseWindow_Create(ret->window);
1729 if(NS_FAILED(nsres))
1730 WARN("Creating window failed: %08x\n", nsres);
1732 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1733 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1735 ERR("InitWindow failed: %08x\n", nsres);
1738 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1739 if(NS_FAILED(nsres))
1740 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1742 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1743 if(NS_SUCCEEDED(nsres)) {
1744 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1745 ScrollOrientation_Y, Scrollbar_Always);
1746 if(NS_FAILED(nsres))
1747 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1749 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1750 ScrollOrientation_X, Scrollbar_Auto);
1751 if(NS_FAILED(nsres))
1752 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1754 nsIScrollable_Release(scrollable);
1756 ERR("Could not get nsIScrollable: %08x\n", nsres);
1762 void NSContainer_Release(NSContainer *This)
1764 TRACE("(%p)\n", This);
1768 ShowWindow(This->hwnd, SW_HIDE);
1769 SetParent(This->hwnd, NULL);
1771 nsIBaseWindow_SetVisibility(This->window, FALSE);
1772 nsIBaseWindow_Destroy(This->window);
1774 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1776 nsIWebBrowser_Release(This->webbrowser);
1777 This->webbrowser = NULL;
1779 nsIWebNavigation_Release(This->navigation);
1780 This->navigation = NULL;
1782 nsIBaseWindow_Release(This->window);
1783 This->window = NULL;
1785 nsIWebBrowserFocus_Release(This->focus);
1788 if(This->editor_controller) {
1789 nsIController_Release(This->editor_controller);
1790 This->editor_controller = NULL;
1794 nsIEditor_Release(This->editor);
1795 This->editor = NULL;
1798 if(This->content_listener) {
1799 nsIURIContentListener_Release(This->content_listener);
1800 This->content_listener = NULL;
1804 DestroyWindow(This->hwnd);
1808 nsIWebBrowserChrome_Release(NSWBCHROME(This));