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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
41 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
44 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
45 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
46 #define NS_ARRAY_CONTRACTID "@mozilla.org/array;1"
47 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define APPSTARTUP_TOPIC "app-startup"
52 #define PR_UINT32_MAX 0xffffffff
54 struct nsCStringContainer {
61 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
62 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
63 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
64 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
65 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
66 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
67 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
68 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
69 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
70 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
71 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
72 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
74 static HINSTANCE hXPCOM = NULL;
76 static nsIServiceManager *pServMgr = NULL;
77 static nsIComponentManager *pCompMgr = NULL;
78 static nsIMemory *nsmem = NULL;
80 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
82 static ATOM nscontainer_class;
84 #define WM_RESETFOCUS_HACK WM_USER+600
86 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
91 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
93 if(msg == WM_CREATE) {
94 This = *(NSContainer**)lParam;
95 SetPropW(hwnd, wszTHIS, This);
97 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
102 TRACE("(%p)->(WM_SIZE)\n", This);
104 nsres = nsIBaseWindow_SetSize(This->window,
105 LOWORD(lParam), HIWORD(lParam), TRUE);
107 WARN("SetSize failed: %08x\n", nsres);
110 case WM_RESETFOCUS_HACK:
113 * Gecko grabs focus in edit mode and some apps don't like it.
114 * We should somehow prevent grabbing focus.
117 TRACE("WM_RESETFOCUS_HACK\n");
119 if(This->reset_focus) {
120 SetFocus(This->reset_focus);
121 This->reset_focus = NULL;
123 This->doc->focus = FALSE;
127 return DefWindowProcW(hwnd, msg, wParam, lParam);
131 static void register_nscontainer_class(void)
133 static WNDCLASSEXW wndclass = {
137 0, 0, NULL, NULL, NULL, NULL, NULL,
141 wndclass.hInstance = hInst;
142 nscontainer_class = RegisterClassExW(&wndclass);
145 static BOOL load_xpcom(const PRUnichar *gre_path)
147 WCHAR path_env[MAX_PATH];
150 static const WCHAR wszPATH[] = {'P','A','T','H',0};
151 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
153 TRACE("(%s)\n", debugstr_w(gre_path));
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
157 len = strlenW(path_env);
158 path_env[len++] = ';';
159 strcpyW(path_env+len, gre_path);
160 SetEnvironmentVariableW(wszPATH, path_env);
162 hXPCOM = LoadLibraryW(strXPCOM);
164 WARN("Could not load XPCOM: %d\n", GetLastError());
168 #define NS_DLSYM(func) \
169 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
171 ERR("Could not GetProcAddress(" #func ") failed\n")
173 NS_DLSYM(NS_InitXPCOM2);
174 NS_DLSYM(NS_ShutdownXPCOM);
175 NS_DLSYM(NS_GetComponentRegistrar);
176 NS_DLSYM(NS_StringContainerInit);
177 NS_DLSYM(NS_CStringContainerInit);
178 NS_DLSYM(NS_StringContainerFinish);
179 NS_DLSYM(NS_CStringContainerFinish);
180 NS_DLSYM(NS_StringSetData);
181 NS_DLSYM(NS_CStringSetData);
182 NS_DLSYM(NS_NewLocalFile);
183 NS_DLSYM(NS_StringGetData);
184 NS_DLSYM(NS_CStringGetData);
191 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
193 WCHAR file_name[MAX_PATH];
198 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
200 strcpyW(file_name, gre_path);
201 strcatW(file_name, wszVersion);
203 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
204 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
205 if(hfile == INVALID_HANDLE_VALUE) {
206 ERR("Could not open VERSION file\n");
210 ReadFile(hfile, version, sizeof(version), &read, NULL);
214 TRACE("%s\n", debugstr_a(version));
216 if(strcmp(version, version_string)) {
217 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
218 debugstr_a(version_string));
225 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
226 const char *version, const char *version_string)
228 DWORD res, type, size = MAX_PATH;
229 HKEY hkey = mshtml_key;
231 static const WCHAR wszGeckoPath[] =
232 {'G','e','c','k','o','P','a','t','h',0};
235 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
236 res = RegOpenKeyA(mshtml_key, version, &hkey);
237 if(res != ERROR_SUCCESS)
241 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
242 if(hkey != mshtml_key)
244 if(res != ERROR_SUCCESS || type != REG_SZ)
247 if(!check_version(gre_path, version_string))
250 return load_xpcom(gre_path);
253 static BOOL load_wine_gecko(PRUnichar *gre_path)
259 static const WCHAR wszMshtmlKey[] = {
260 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
261 '\\','M','S','H','T','M','L',0};
263 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
264 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
265 if(res != ERROR_SUCCESS)
268 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING)
269 || load_wine_gecko_v(gre_path, hkey, "0.0.1", "Wine Gecko 0.0.1\n")
270 || load_wine_gecko_v(gre_path, hkey, NULL, "Wine Gecko 0.0.1\n");
276 static void set_lang(nsIPrefBranch *pref)
279 DWORD res, size, type;
283 static const WCHAR international_keyW[] =
284 {'S','o','f','t','w','a','r','e',
285 '\\','M','i','c','r','o','s','o','f','t',
286 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
287 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
289 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
290 if(res != ERROR_SUCCESS)
293 size = sizeof(langs);
294 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
296 if(res != ERROR_SUCCESS || type != REG_SZ)
299 TRACE("Setting lang %s\n", debugstr_a(langs));
301 nsres = nsIPrefBranch_SetCharPref(pref, "intl.accept_languages", langs);
303 ERR("SetCharPref failed: %08x\n", nsres);
306 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
310 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
312 ERR("Could not set pref %s\n", debugstr_a(pref_name));
315 static void set_profile(void)
319 PRBool exists = FALSE;
322 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
324 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PROFILE_CONTRACTID,
325 &IID_nsIProfile, (void**)&profile);
326 if(NS_FAILED(nsres)) {
327 ERR("Could not get profile service: %08x\n", nsres);
331 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
333 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
335 ERR("CreateNewProfile failed: %08x\n", nsres);
338 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
340 ERR("SetCurrentProfile failed: %08x\n", nsres);
342 nsIProfile_Release(profile);
344 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
345 &IID_nsIPrefBranch, (void**)&pref);
346 if(NS_FAILED(nsres)) {
347 ERR("Could not get preference service: %08x\n", nsres);
352 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
353 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
355 nsIPrefBranch_Release(pref);
358 static BOOL init_xpcom(const PRUnichar *gre_path)
361 nsIObserver *pStartNotif;
362 nsIComponentRegistrar *registrar = NULL;
366 nsAString_Init(&path, gre_path);
367 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
368 nsAString_Finish(&path);
369 if(NS_FAILED(nsres)) {
370 ERR("NS_NewLocalFile failed: %08x\n", nsres);
375 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
376 if(NS_FAILED(nsres)) {
377 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
382 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
384 ERR("Could not get nsIComponentManager: %08x\n", nsres);
386 nsres = NS_GetComponentRegistrar(®istrar);
387 if(NS_SUCCEEDED(nsres)) {
388 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
390 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
392 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
394 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
396 init_nsio(pCompMgr, registrar);
398 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
401 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
402 NULL, &IID_nsIObserver, (void**)&pStartNotif);
403 if(NS_SUCCEEDED(nsres)) {
404 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
406 ERR("Observe failed: %08x\n", nsres);
408 nsIObserver_Release(pStartNotif);
410 ERR("could not get appstartup-notifier: %08x\n", nsres);
415 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
416 NULL, &IID_nsIMemory, (void**)&nsmem);
418 ERR("Could not get nsIMemory: %08x\n", nsres);
421 register_nsservice(registrar, pServMgr);
422 nsIComponentRegistrar_Release(registrar);
428 static CRITICAL_SECTION cs_load_gecko;
429 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
431 0, 0, &cs_load_gecko,
432 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
433 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
435 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
437 BOOL load_gecko(BOOL silent)
439 PRUnichar gre_path[MAX_PATH];
442 static LONG loading_thread;
446 /* load_gecko may be called recursively */
447 if(loading_thread == GetCurrentThreadId())
448 return pCompMgr != NULL;
450 EnterCriticalSection(&cs_load_gecko);
452 if(!loading_thread) {
453 loading_thread = GetCurrentThreadId();
455 if(load_wine_gecko(gre_path)
456 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
457 ret = init_xpcom(gre_path);
459 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
461 ret = pCompMgr != NULL;
464 LeaveCriticalSection(&cs_load_gecko);
469 void *nsalloc(size_t size)
471 return nsIMemory_Alloc(nsmem, size);
474 void nsfree(void *mem)
476 nsIMemory_Free(nsmem, mem);
479 void nsACString_Init(nsACString *str, const char *data)
481 NS_CStringContainerInit(str);
483 nsACString_SetData(str, data);
486 void nsACString_SetData(nsACString *str, const char *data)
488 NS_CStringSetData(str, data, PR_UINT32_MAX);
491 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
493 return NS_CStringGetData(str, data, NULL);
496 void nsACString_Finish(nsACString *str)
498 NS_CStringContainerFinish(str);
501 void nsAString_Init(nsAString *str, const PRUnichar *data)
503 NS_StringContainerInit(str);
505 NS_StringSetData(str, data, PR_UINT32_MAX);
508 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
510 return NS_StringGetData(str, data, NULL);
513 void nsAString_Finish(nsAString *str)
515 NS_StringContainerFinish(str);
518 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
520 nsIStringInputStream *ret;
526 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
527 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
529 if(NS_FAILED(nsres)) {
530 ERR("Could not get nsIStringInputStream\n");
534 nsres = nsIStringInputStream_SetData(ret, data, data_len);
535 if(NS_FAILED(nsres)) {
536 ERR("AdoptData failed: %08x\n", nsres);
537 nsIStringInputStream_Release(ret);
541 return (nsIInputStream*)ret;
544 nsIMutableArray *create_nsarray(void)
546 nsIMutableArray *ret;
552 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
553 NS_ARRAY_CONTRACTID, NULL, &IID_nsIMutableArray,
555 if(NS_FAILED(nsres)) {
556 ERR("Could not get nsIArray: %08x\n", nsres);
563 nsIWritableVariant *create_nsvariant(void)
565 nsIWritableVariant *ret;
571 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
572 NS_VARIANT_CONTRACTID, NULL, &IID_nsIWritableVariant,
574 if(NS_FAILED(nsres)) {
575 ERR("Could not get nsIWritableVariant: %08x\n", nsres);
582 nsICommandParams *create_nscommand_params(void)
584 nsICommandParams *ret = NULL;
590 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
591 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
594 ERR("Could not get nsICommandParams\n");
599 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
601 nsIInterfaceRequestor *iface_req;
604 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
608 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
609 nsIInterfaceRequestor_Release(iface_req);
614 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
616 nsIDOMNodeList *node_list = NULL;
617 PRBool has_children = FALSE;
621 nsIDOMNode_HasChildNodes(nsnode, &has_children);
623 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
624 if(NS_FAILED(nsres)) {
625 ERR("GetType failed: %08x\n", nsres);
631 nsIDOMElement *nselem;
632 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
633 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
634 nsIDOMElement_Release(nselem);
639 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
640 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
641 nsIDOMText_Release(nstext);
645 nsIDOMComment *nscomment;
646 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMComment, (void**)&nscomment);
647 nsres = nsIContentSerializer_AppendComment(serializer, nscomment, 0, -1, str);
650 case DOCUMENT_NODE: {
651 nsIDOMDocument *nsdoc;
652 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
653 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
654 nsIDOMDocument_Release(nsdoc);
657 case DOCUMENT_FRAGMENT_NODE:
660 FIXME("Unhandled type %u\n", type);
664 PRUint32 child_cnt, i;
665 nsIDOMNode *child_node;
667 nsIDOMNode_GetChildNodes(nsnode, &node_list);
668 nsIDOMNodeList_GetLength(node_list, &child_cnt);
670 for(i=0; i<child_cnt; i++) {
671 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
672 if(NS_SUCCEEDED(nsres)) {
673 nsnode_to_nsstring_rec(serializer, child_node, str);
674 nsIDOMNode_Release(child_node);
676 ERR("Item failed: %08x\n", nsres);
680 nsIDOMNodeList_Release(node_list);
683 if(type == ELEMENT_NODE) {
684 nsIDOMElement *nselem;
685 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
686 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
687 nsIDOMElement_Release(nselem);
691 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
693 nsIContentSerializer *serializer;
697 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
698 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
699 (void**)&serializer);
700 if(NS_FAILED(nsres)) {
701 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
705 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
707 ERR("Init failed: %08x\n", nsres);
709 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
710 nsnode_to_nsstring_rec(serializer, nsnode, str);
711 nsIDOMNode_Release(nsnode);
713 nsres = nsIContentSerializer_Flush(serializer, str);
715 ERR("Flush failed: %08x\n", nsres);
717 nsIContentSerializer_Release(serializer);
720 void get_editor_controller(NSContainer *This)
722 nsIEditingSession *editing_session = NULL;
723 nsIControllerContext *ctrlctx;
727 nsIEditor_Release(This->editor);
731 if(This->editor_controller) {
732 nsIController_Release(This->editor_controller);
733 This->editor_controller = NULL;
736 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
737 (void**)&editing_session);
738 if(NS_FAILED(nsres)) {
739 ERR("Could not get nsIEditingSession: %08x\n", nsres);
743 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
744 This->doc->window->nswindow, &This->editor);
745 nsIEditingSession_Release(editing_session);
746 if(NS_FAILED(nsres)) {
747 ERR("Could not get editor: %08x\n", nsres);
751 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
752 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
753 if(NS_SUCCEEDED(nsres)) {
754 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
756 ERR("SetCommandContext failed: %08x\n", nsres);
757 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
758 (void**)&This->editor_controller);
759 nsIControllerContext_Release(ctrlctx);
761 ERR("Could not get nsIController interface: %08x\n", nsres);
763 ERR("Could not create edit controller: %08x\n", nsres);
767 void set_ns_editmode(NSContainer *This)
769 nsIEditingSession *editing_session = NULL;
770 nsIURIContentListener *listener = NULL;
771 nsIDOMWindow *dom_window = NULL;
774 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
775 (void**)&editing_session);
776 if(NS_FAILED(nsres)) {
777 ERR("Could not get nsIEditingSession: %08x\n", nsres);
781 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
782 if(NS_FAILED(nsres)) {
783 ERR("Could not get content DOM window: %08x\n", nsres);
784 nsIEditingSession_Release(editing_session);
788 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
789 nsIEditingSession_Release(editing_session);
790 nsIDOMWindow_Release(dom_window);
791 if(NS_FAILED(nsres)) {
792 ERR("MakeWindowEditable failed: %08x\n", nsres);
796 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
797 * It seams to be a bug in Gecko. To workaround it we set our content
798 * listener again and Gecko's one as its parent.
800 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
801 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
802 nsIURIContentListener_Release(listener);
803 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
806 void close_gecko(void)
811 nsIComponentManager_Release(pCompMgr);
814 nsIServiceManager_Release(pServMgr);
817 nsIMemory_Release(nsmem);
823 /**********************************************************
824 * nsIWebBrowserChrome interface
827 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
829 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
830 nsIIDRef riid, nsQIResult result)
832 NSContainer *This = NSWBCHROME_THIS(iface);
835 if(IsEqualGUID(&IID_nsISupports, riid)) {
836 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
837 *result = NSWBCHROME(This);
838 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
839 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
840 *result = NSWBCHROME(This);
841 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
842 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
843 *result = NSCML(This);
844 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
845 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
846 *result = NSURICL(This);
847 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
848 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
849 *result = NSEMBWNDS(This);
850 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
851 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
852 *result = NSTOOLTIP(This);
853 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
854 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
855 *result = NSIFACEREQ(This);
856 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
857 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
858 *result = NSWEAKREF(This);
859 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
860 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
861 *result = NSSUPWEAKREF(This);
865 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
869 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
870 return NS_NOINTERFACE;
873 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
875 NSContainer *This = NSWBCHROME_THIS(iface);
876 LONG ref = InterlockedIncrement(&This->ref);
878 TRACE("(%p) ref=%d\n", This, ref);
883 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
885 NSContainer *This = NSWBCHROME_THIS(iface);
886 LONG ref = InterlockedDecrement(&This->ref);
888 TRACE("(%p) ref=%d\n", This, ref);
892 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
899 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
900 PRUint32 statusType, const PRUnichar *status)
902 NSContainer *This = NSWBCHROME_THIS(iface);
903 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
904 return NS_ERROR_NOT_IMPLEMENTED;
907 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
908 nsIWebBrowser **aWebBrowser)
910 NSContainer *This = NSWBCHROME_THIS(iface);
912 TRACE("(%p)->(%p)\n", This, aWebBrowser);
915 return NS_ERROR_INVALID_ARG;
918 nsIWebBrowser_AddRef(This->webbrowser);
919 *aWebBrowser = This->webbrowser;
923 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
924 nsIWebBrowser *aWebBrowser)
926 NSContainer *This = NSWBCHROME_THIS(iface);
928 TRACE("(%p)->(%p)\n", This, aWebBrowser);
930 if(aWebBrowser != This->webbrowser)
931 ERR("Wrong nsWebBrowser!\n");
936 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
937 PRUint32 *aChromeFlags)
939 NSContainer *This = NSWBCHROME_THIS(iface);
940 WARN("(%p)->(%p)\n", This, aChromeFlags);
941 return NS_ERROR_NOT_IMPLEMENTED;
944 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
945 PRUint32 aChromeFlags)
947 NSContainer *This = NSWBCHROME_THIS(iface);
948 WARN("(%p)->(%08x)\n", This, aChromeFlags);
949 return NS_ERROR_NOT_IMPLEMENTED;
952 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
954 NSContainer *This = NSWBCHROME_THIS(iface);
955 TRACE("(%p)\n", This);
956 return NS_ERROR_NOT_IMPLEMENTED;
959 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
960 PRInt32 aCX, PRInt32 aCY)
962 NSContainer *This = NSWBCHROME_THIS(iface);
963 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
964 return NS_ERROR_NOT_IMPLEMENTED;
967 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
969 NSContainer *This = NSWBCHROME_THIS(iface);
970 WARN("(%p)\n", This);
971 return NS_ERROR_NOT_IMPLEMENTED;
974 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
976 NSContainer *This = NSWBCHROME_THIS(iface);
977 WARN("(%p)->(%p)\n", This, _retval);
978 return NS_ERROR_NOT_IMPLEMENTED;
981 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
984 NSContainer *This = NSWBCHROME_THIS(iface);
985 WARN("(%p)->(%08x)\n", This, aStatus);
986 return NS_ERROR_NOT_IMPLEMENTED;
989 #undef NSWBCHROME_THIS
991 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
992 nsWebBrowserChrome_QueryInterface,
993 nsWebBrowserChrome_AddRef,
994 nsWebBrowserChrome_Release,
995 nsWebBrowserChrome_SetStatus,
996 nsWebBrowserChrome_GetWebBrowser,
997 nsWebBrowserChrome_SetWebBrowser,
998 nsWebBrowserChrome_GetChromeFlags,
999 nsWebBrowserChrome_SetChromeFlags,
1000 nsWebBrowserChrome_DestroyBrowserWindow,
1001 nsWebBrowserChrome_SizeBrowserTo,
1002 nsWebBrowserChrome_ShowAsModal,
1003 nsWebBrowserChrome_IsWindowModal,
1004 nsWebBrowserChrome_ExitModalEventLoop
1007 /**********************************************************
1008 * nsIContextMenuListener interface
1011 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1013 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1014 nsIIDRef riid, nsQIResult result)
1016 NSContainer *This = NSCML_THIS(iface);
1017 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1020 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1022 NSContainer *This = NSCML_THIS(iface);
1023 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1026 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1028 NSContainer *This = NSCML_THIS(iface);
1029 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1032 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1033 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1035 NSContainer *This = NSCML_THIS(iface);
1036 nsIDOMMouseEvent *event;
1038 DWORD dwID = CONTEXT_MENU_DEFAULT;
1041 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1043 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1044 if(NS_FAILED(nsres)) {
1045 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1049 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1050 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1051 nsIDOMMouseEvent_Release(event);
1053 switch(aContextFlags) {
1055 case CONTEXT_DOCUMENT:
1057 dwID = CONTEXT_MENU_DEFAULT;
1060 case CONTEXT_IMAGE|CONTEXT_LINK:
1061 dwID = CONTEXT_MENU_IMAGE;
1064 dwID = CONTEXT_MENU_ANCHOR;
1067 dwID = CONTEXT_MENU_CONTROL;
1070 FIXME("aContextFlags=%08x\n", aContextFlags);
1073 show_context_menu(This->doc, dwID, &pt, (IDispatch*)HTMLDOMNODE(get_node(This->doc, aNode)));
1080 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1081 nsContextMenuListener_QueryInterface,
1082 nsContextMenuListener_AddRef,
1083 nsContextMenuListener_Release,
1084 nsContextMenuListener_OnShowContextMenu
1087 /**********************************************************
1088 * nsIURIContentListener interface
1091 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1093 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1094 nsIIDRef riid, nsQIResult result)
1096 NSContainer *This = NSURICL_THIS(iface);
1097 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1100 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1102 NSContainer *This = NSURICL_THIS(iface);
1103 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1106 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1108 NSContainer *This = NSURICL_THIS(iface);
1109 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1112 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1113 nsIURI *aURI, PRBool *_retval)
1115 NSContainer *This = NSURICL_THIS(iface);
1116 nsIWineURI *wine_uri;
1117 nsACString spec_str;
1121 nsACString_Init(&spec_str, NULL);
1122 nsIURI_GetSpec(aURI, &spec_str);
1123 nsACString_GetData(&spec_str, &spec);
1125 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1127 nsACString_Finish(&spec_str);
1129 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1130 if(NS_FAILED(nsres)) {
1131 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
1132 return NS_ERROR_NOT_IMPLEMENTED;
1135 nsIWineURI_SetNSContainer(wine_uri, This);
1136 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
1138 if(This->bscallback && This->bscallback->mon) {
1142 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
1143 if(SUCCEEDED(hres)) {
1144 nsIWineURI_SetWineURL(wine_uri, wine_url);
1145 CoTaskMemFree(wine_url);
1147 WARN("GetDisplayName failed: %08x\n", hres);
1151 nsIWineURI_Release(wine_uri);
1154 return This->content_listener
1155 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1159 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1160 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1161 nsIStreamListener **aContentHandler, PRBool *_retval)
1163 NSContainer *This = NSURICL_THIS(iface);
1165 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1166 aRequest, aContentHandler, _retval);
1168 return This->content_listener
1169 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1170 aIsContentPreferred, aRequest, aContentHandler, _retval)
1171 : NS_ERROR_NOT_IMPLEMENTED;
1174 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1175 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1177 NSContainer *This = NSURICL_THIS(iface);
1179 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1181 /* FIXME: Should we do something here? */
1184 return This->content_listener
1185 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1186 aDesiredContentType, _retval)
1190 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1191 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1194 NSContainer *This = NSURICL_THIS(iface);
1196 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1197 aDesiredContentType, _retval);
1199 return This->content_listener
1200 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1201 aIsContentPreferred, aDesiredContentType, _retval)
1202 : NS_ERROR_NOT_IMPLEMENTED;
1205 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1206 nsISupports **aLoadCookie)
1208 NSContainer *This = NSURICL_THIS(iface);
1210 WARN("(%p)->(%p)\n", This, aLoadCookie);
1212 return This->content_listener
1213 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1214 : NS_ERROR_NOT_IMPLEMENTED;
1217 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1218 nsISupports *aLoadCookie)
1220 NSContainer *This = NSURICL_THIS(iface);
1222 WARN("(%p)->(%p)\n", This, aLoadCookie);
1224 return This->content_listener
1225 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1226 : NS_ERROR_NOT_IMPLEMENTED;
1229 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1230 nsIURIContentListener **aParentContentListener)
1232 NSContainer *This = NSURICL_THIS(iface);
1234 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1236 if(This->content_listener)
1237 nsIURIContentListener_AddRef(This->content_listener);
1239 *aParentContentListener = This->content_listener;
1243 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1244 nsIURIContentListener *aParentContentListener)
1246 NSContainer *This = NSURICL_THIS(iface);
1248 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1250 if(aParentContentListener == NSURICL(This))
1253 if(This->content_listener)
1254 nsIURIContentListener_Release(This->content_listener);
1256 This->content_listener = aParentContentListener;
1257 if(This->content_listener)
1258 nsIURIContentListener_AddRef(This->content_listener);
1265 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1266 nsURIContentListener_QueryInterface,
1267 nsURIContentListener_AddRef,
1268 nsURIContentListener_Release,
1269 nsURIContentListener_OnStartURIOpen,
1270 nsURIContentListener_DoContent,
1271 nsURIContentListener_IsPreferred,
1272 nsURIContentListener_CanHandleContent,
1273 nsURIContentListener_GetLoadCookie,
1274 nsURIContentListener_SetLoadCookie,
1275 nsURIContentListener_GetParentContentListener,
1276 nsURIContentListener_SetParentContentListener
1279 /**********************************************************
1280 * nsIEmbeddinSiteWindow interface
1283 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1285 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1286 nsIIDRef riid, nsQIResult result)
1288 NSContainer *This = NSEMBWNDS_THIS(iface);
1289 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1292 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1294 NSContainer *This = NSEMBWNDS_THIS(iface);
1295 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1298 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1300 NSContainer *This = NSEMBWNDS_THIS(iface);
1301 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1304 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1305 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1307 NSContainer *This = NSEMBWNDS_THIS(iface);
1308 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1309 return NS_ERROR_NOT_IMPLEMENTED;
1312 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1313 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1315 NSContainer *This = NSEMBWNDS_THIS(iface);
1316 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1317 return NS_ERROR_NOT_IMPLEMENTED;
1320 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1322 NSContainer *This = NSEMBWNDS_THIS(iface);
1324 TRACE("(%p)\n", This);
1326 if(This->reset_focus)
1327 PostMessageW(This->hwnd, WM_RESETFOCUS_HACK, 0, 0);
1329 return nsIBaseWindow_SetFocus(This->window);
1332 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1333 PRBool *aVisibility)
1335 NSContainer *This = NSEMBWNDS_THIS(iface);
1337 TRACE("(%p)->(%p)\n", This, aVisibility);
1339 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1343 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1346 NSContainer *This = NSEMBWNDS_THIS(iface);
1348 TRACE("(%p)->(%x)\n", This, aVisibility);
1353 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1356 NSContainer *This = NSEMBWNDS_THIS(iface);
1357 WARN("(%p)->(%p)\n", This, aTitle);
1358 return NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1362 const PRUnichar *aTitle)
1364 NSContainer *This = NSEMBWNDS_THIS(iface);
1365 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1366 return NS_ERROR_NOT_IMPLEMENTED;
1369 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1372 NSContainer *This = NSEMBWNDS_THIS(iface);
1374 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1376 *aSiteWindow = This->hwnd;
1380 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1381 nsEmbeddingSiteWindow_QueryInterface,
1382 nsEmbeddingSiteWindow_AddRef,
1383 nsEmbeddingSiteWindow_Release,
1384 nsEmbeddingSiteWindow_SetDimensions,
1385 nsEmbeddingSiteWindow_GetDimensions,
1386 nsEmbeddingSiteWindow_SetFocus,
1387 nsEmbeddingSiteWindow_GetVisibility,
1388 nsEmbeddingSiteWindow_SetVisibility,
1389 nsEmbeddingSiteWindow_GetTitle,
1390 nsEmbeddingSiteWindow_SetTitle,
1391 nsEmbeddingSiteWindow_GetSiteWindow
1394 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1396 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1399 NSContainer *This = NSTOOLTIP_THIS(iface);
1400 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1403 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1405 NSContainer *This = NSTOOLTIP_THIS(iface);
1406 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1409 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1411 NSContainer *This = NSTOOLTIP_THIS(iface);
1412 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1415 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1416 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1418 NSContainer *This = NSTOOLTIP_THIS(iface);
1420 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1425 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1427 NSContainer *This = NSTOOLTIP_THIS(iface);
1429 hide_tooltip(This->doc);
1434 #undef NSTOOLTIM_THIS
1436 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1437 nsTooltipListener_QueryInterface,
1438 nsTooltipListener_AddRef,
1439 nsTooltipListener_Release,
1440 nsTooltipListener_OnShowTooltip,
1441 nsTooltipListener_OnHideTooltip
1444 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1446 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1447 nsIIDRef riid, nsQIResult result)
1449 NSContainer *This = NSIFACEREQ_THIS(iface);
1450 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1453 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1455 NSContainer *This = NSIFACEREQ_THIS(iface);
1456 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1459 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1461 NSContainer *This = NSIFACEREQ_THIS(iface);
1462 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1465 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1466 nsIIDRef riid, nsQIResult result)
1468 NSContainer *This = NSIFACEREQ_THIS(iface);
1470 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1471 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1472 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1475 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1478 #undef NSIFACEREQ_THIS
1480 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1481 nsInterfaceRequestor_QueryInterface,
1482 nsInterfaceRequestor_AddRef,
1483 nsInterfaceRequestor_Release,
1484 nsInterfaceRequestor_GetInterface
1487 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1489 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1490 nsIIDRef riid, nsQIResult result)
1492 NSContainer *This = NSWEAKREF_THIS(iface);
1493 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1496 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1498 NSContainer *This = NSWEAKREF_THIS(iface);
1499 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1502 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1504 NSContainer *This = NSWEAKREF_THIS(iface);
1505 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1508 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1509 const nsIID *riid, void **result)
1511 NSContainer *This = NSWEAKREF_THIS(iface);
1512 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1515 #undef NSWEAKREF_THIS
1517 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1518 nsWeakReference_QueryInterface,
1519 nsWeakReference_AddRef,
1520 nsWeakReference_Release,
1521 nsWeakReference_QueryReferent
1524 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1526 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1527 nsIIDRef riid, nsQIResult result)
1529 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1530 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1533 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1535 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1536 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1539 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1541 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1542 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1545 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1546 nsIWeakReference **_retval)
1548 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1550 TRACE("(%p)->(%p)\n", This, _retval);
1552 nsIWeakReference_AddRef(NSWEAKREF(This));
1553 *_retval = NSWEAKREF(This);
1557 #undef NSWEAKREF_THIS
1559 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1560 nsSupportsWeakReference_QueryInterface,
1561 nsSupportsWeakReference_AddRef,
1562 nsSupportsWeakReference_Release,
1563 nsSupportsWeakReference_GetWeakReference
1567 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1569 nsIWebBrowserSetup *wbsetup;
1570 nsIScrollable *scrollable;
1574 if(!load_gecko(FALSE))
1577 ret = heap_alloc(sizeof(NSContainer));
1579 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1580 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1581 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1582 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1583 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1584 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1585 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1586 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1590 ret->bscallback = NULL;
1591 ret->content_listener = NULL;
1592 ret->editor_controller = NULL;
1594 ret->reset_focus = NULL;
1597 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1598 ret->parent = parent;
1600 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1601 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1602 if(NS_FAILED(nsres))
1603 ERR("Creating WebBrowser failed: %08x\n", nsres);
1605 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1606 if(NS_FAILED(nsres))
1607 ERR("SetContainerWindow failed: %08x\n", nsres);
1609 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1610 (void**)&ret->window);
1611 if(NS_FAILED(nsres))
1612 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1614 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1616 if(NS_SUCCEEDED(nsres)) {
1617 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1618 nsIWebBrowserSetup_Release(wbsetup);
1619 if(NS_FAILED(nsres))
1620 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1622 ERR("Could not get nsIWebBrowserSetup interface\n");
1625 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1626 (void**)&ret->navigation);
1627 if(NS_FAILED(nsres))
1628 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1630 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1631 (void**)&ret->focus);
1632 if(NS_FAILED(nsres))
1633 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1635 if(!nscontainer_class)
1636 register_nscontainer_class();
1638 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1639 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1640 GetDesktopWindow(), NULL, hInst, ret);
1642 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1643 if(NS_SUCCEEDED(nsres)) {
1644 nsres = nsIBaseWindow_Create(ret->window);
1645 if(NS_FAILED(nsres))
1646 WARN("Creating window failed: %08x\n", nsres);
1648 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1649 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1651 ERR("InitWindow failed: %08x\n", nsres);
1654 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1655 if(NS_FAILED(nsres))
1656 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1660 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1661 if(NS_SUCCEEDED(nsres)) {
1662 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1663 ScrollOrientation_Y, Scrollbar_Always);
1664 if(NS_FAILED(nsres))
1665 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1667 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1668 ScrollOrientation_X, Scrollbar_Auto);
1669 if(NS_FAILED(nsres))
1670 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1672 nsIScrollable_Release(scrollable);
1674 ERR("Could not get nsIScrollable: %08x\n", nsres);
1680 void NSContainer_Release(NSContainer *This)
1682 TRACE("(%p)\n", This);
1684 ShowWindow(This->hwnd, SW_HIDE);
1685 SetParent(This->hwnd, NULL);
1687 nsIBaseWindow_SetVisibility(This->window, FALSE);
1688 nsIBaseWindow_Destroy(This->window);
1690 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1692 nsIWebBrowser_Release(This->webbrowser);
1693 This->webbrowser = NULL;
1695 nsIWebNavigation_Release(This->navigation);
1696 This->navigation = NULL;
1698 nsIBaseWindow_Release(This->window);
1699 This->window = NULL;
1701 nsIWebBrowserFocus_Release(This->focus);
1704 if(This->editor_controller) {
1705 nsIController_Release(This->editor_controller);
1706 This->editor_controller = NULL;
1710 nsIEditor_Release(This->editor);
1711 This->editor = NULL;
1714 if(This->content_listener) {
1715 nsIURIContentListener_Release(This->content_listener);
1716 This->content_listener = NULL;
1720 DestroyWindow(This->hwnd);
1724 nsIWebBrowserChrome_Release(NSWBCHROME(This));