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"
49 #define APPSTARTUP_TOPIC "app-startup"
51 #define PR_UINT32_MAX 0xffffffff
53 struct nsCStringContainer {
60 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
61 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
62 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
63 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
64 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
65 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
66 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
67 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
68 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
69 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
70 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
71 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
73 static HINSTANCE hXPCOM = NULL;
75 static nsIServiceManager *pServMgr = NULL;
76 static nsIComponentManager *pCompMgr = NULL;
77 static nsIMemory *nsmem = NULL;
79 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
81 static ATOM nscontainer_class;
83 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
88 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
90 if(msg == WM_CREATE) {
91 This = *(NSContainer**)lParam;
92 SetPropW(hwnd, wszTHIS, This);
94 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
99 TRACE("(%p)->(WM_SIZE)\n", This);
101 nsres = nsIBaseWindow_SetSize(This->window,
102 LOWORD(lParam), HIWORD(lParam), TRUE);
104 WARN("SetSize failed: %08x\n", nsres);
107 return DefWindowProcW(hwnd, msg, wParam, lParam);
111 static void register_nscontainer_class(void)
113 static WNDCLASSEXW wndclass = {
117 0, 0, NULL, NULL, NULL, NULL, NULL,
121 wndclass.hInstance = hInst;
122 nscontainer_class = RegisterClassExW(&wndclass);
125 static BOOL load_xpcom(const PRUnichar *gre_path)
127 WCHAR path_env[MAX_PATH];
130 static const WCHAR wszPATH[] = {'P','A','T','H',0};
131 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
133 TRACE("(%s)\n", debugstr_w(gre_path));
135 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
136 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
137 len = strlenW(path_env);
138 path_env[len++] = ';';
139 strcpyW(path_env+len, gre_path);
140 SetEnvironmentVariableW(wszPATH, path_env);
142 hXPCOM = LoadLibraryW(strXPCOM);
144 WARN("Could not load XPCOM: %d\n", GetLastError());
148 #define NS_DLSYM(func) \
149 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
151 ERR("Could not GetProcAddress(" #func ") failed\n")
153 NS_DLSYM(NS_InitXPCOM2);
154 NS_DLSYM(NS_ShutdownXPCOM);
155 NS_DLSYM(NS_GetComponentRegistrar);
156 NS_DLSYM(NS_StringContainerInit);
157 NS_DLSYM(NS_CStringContainerInit);
158 NS_DLSYM(NS_StringContainerFinish);
159 NS_DLSYM(NS_CStringContainerFinish);
160 NS_DLSYM(NS_StringSetData);
161 NS_DLSYM(NS_CStringSetData);
162 NS_DLSYM(NS_NewLocalFile);
163 NS_DLSYM(NS_StringGetData);
164 NS_DLSYM(NS_CStringGetData);
171 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
173 WCHAR file_name[MAX_PATH];
178 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
180 strcpyW(file_name, gre_path);
181 strcatW(file_name, wszVersion);
183 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
184 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
185 if(hfile == INVALID_HANDLE_VALUE) {
186 ERR("Could not open VERSION file\n");
190 ReadFile(hfile, version, sizeof(version), &read, NULL);
194 TRACE("%s\n", debugstr_a(version));
196 if(strcmp(version, version_string)) {
197 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
198 debugstr_a(version_string));
205 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
206 const char *version, const char *version_string)
208 DWORD res, type, size = MAX_PATH;
209 HKEY hkey = mshtml_key;
211 static const WCHAR wszGeckoPath[] =
212 {'G','e','c','k','o','P','a','t','h',0};
215 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
216 res = RegOpenKeyA(mshtml_key, version, &hkey);
217 if(res != ERROR_SUCCESS)
221 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
222 if(hkey != mshtml_key)
224 if(res != ERROR_SUCCESS || type != REG_SZ)
227 if(!check_version(gre_path, version_string))
230 return load_xpcom(gre_path);
233 static BOOL load_wine_gecko(PRUnichar *gre_path)
239 static const WCHAR wszMshtmlKey[] = {
240 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
241 '\\','M','S','H','T','M','L',0};
243 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
244 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
245 if(res != ERROR_SUCCESS)
248 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING)
249 || load_wine_gecko_v(gre_path, hkey, "0.0.1", "Wine Gecko 0.0.1\n")
250 || load_wine_gecko_v(gre_path, hkey, NULL, "Wine Gecko 0.0.1\n");
256 static void set_profile(void)
259 PRBool exists = FALSE;
262 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
264 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PROFILE_CONTRACTID,
265 &IID_nsIProfile, (void**)&profile);
266 if(NS_FAILED(nsres)) {
267 ERR("Could not get profile service: %08x\n", nsres);
271 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
273 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
275 ERR("CreateNewProfile failed: %08x\n", nsres);
278 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
280 ERR("SetCurrentProfile failed: %08x\n", nsres);
282 nsIProfile_Release(profile);
285 static BOOL init_xpcom(const PRUnichar *gre_path)
288 nsIObserver *pStartNotif;
289 nsIComponentRegistrar *registrar = NULL;
293 nsAString_Init(&path, gre_path);
294 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
295 nsAString_Finish(&path);
296 if(NS_FAILED(nsres)) {
297 ERR("NS_NewLocalFile failed: %08x\n", nsres);
302 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
303 if(NS_FAILED(nsres)) {
304 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
309 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
311 ERR("Could not get nsIComponentManager: %08x\n", nsres);
313 nsres = NS_GetComponentRegistrar(®istrar);
314 if(NS_SUCCEEDED(nsres)) {
315 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
317 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
319 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
321 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
323 init_nsio(pCompMgr, registrar);
325 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
328 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
329 NULL, &IID_nsIObserver, (void**)&pStartNotif);
330 if(NS_SUCCEEDED(nsres)) {
331 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
333 ERR("Observe failed: %08x\n", nsres);
335 nsIObserver_Release(pStartNotif);
337 ERR("could not get appstartup-notifier: %08x\n", nsres);
342 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
343 NULL, &IID_nsIMemory, (void**)&nsmem);
345 ERR("Could not get nsIMemory: %08x\n", nsres);
348 register_nsservice(registrar, pServMgr);
349 nsIComponentRegistrar_Release(registrar);
355 static CRITICAL_SECTION cs_load_gecko;
356 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
358 0, 0, &cs_load_gecko,
359 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
360 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
362 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
364 BOOL load_gecko(BOOL silent)
366 PRUnichar gre_path[MAX_PATH];
369 static LONG loading_thread;
373 /* load_gecko may be called recursively */
374 if(loading_thread == GetCurrentThreadId())
375 return pCompMgr != NULL;
377 EnterCriticalSection(&cs_load_gecko);
379 if(!loading_thread) {
380 loading_thread = GetCurrentThreadId();
382 if(load_wine_gecko(gre_path)
383 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
384 ret = init_xpcom(gre_path);
386 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
388 ret = pCompMgr != NULL;
391 LeaveCriticalSection(&cs_load_gecko);
396 void *nsalloc(size_t size)
398 return nsIMemory_Alloc(nsmem, size);
401 void nsfree(void *mem)
403 nsIMemory_Free(nsmem, mem);
406 void nsACString_Init(nsACString *str, const char *data)
408 NS_CStringContainerInit(str);
410 nsACString_SetData(str, data);
413 void nsACString_SetData(nsACString *str, const char *data)
415 NS_CStringSetData(str, data, PR_UINT32_MAX);
418 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
420 return NS_CStringGetData(str, data, termited);
423 void nsACString_Finish(nsACString *str)
425 NS_CStringContainerFinish(str);
428 void nsAString_Init(nsAString *str, const PRUnichar *data)
430 NS_StringContainerInit(str);
432 NS_StringSetData(str, data, PR_UINT32_MAX);
435 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
437 return NS_StringGetData(str, data, termited);
440 void nsAString_Finish(nsAString *str)
442 NS_StringContainerFinish(str);
445 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
447 nsIStringInputStream *ret;
453 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
454 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
456 if(NS_FAILED(nsres)) {
457 ERR("Could not get nsIStringInputStream\n");
461 nsres = nsIStringInputStream_SetData(ret, data, data_len);
462 if(NS_FAILED(nsres)) {
463 ERR("AdoptData failed: %08x\n", nsres);
464 nsIStringInputStream_Release(ret);
468 return (nsIInputStream*)ret;
471 nsIMutableArray *create_nsarray(void)
473 nsIMutableArray *ret;
479 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
480 NS_ARRAY_CONTRACTID, NULL, &IID_nsIMutableArray,
482 if(NS_FAILED(nsres)) {
483 ERR("Could not get nsIArray: %08x\n", nsres);
490 nsIWritableVariant *create_nsvariant(void)
492 nsIWritableVariant *ret;
498 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
499 NS_VARIANT_CONTRACTID, NULL, &IID_nsIWritableVariant,
501 if(NS_FAILED(nsres)) {
502 ERR("Could not get nsIWritableVariant: %08x\n", nsres);
509 nsICommandParams *create_nscommand_params(void)
511 nsICommandParams *ret = NULL;
517 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
518 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
521 ERR("Could not get nsICommandParams\n");
526 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
528 nsIInterfaceRequestor *iface_req;
531 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
535 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
536 nsIInterfaceRequestor_Release(iface_req);
541 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
543 nsIDOMNodeList *node_list = NULL;
544 PRBool has_children = FALSE;
548 nsIDOMNode_HasChildNodes(nsnode, &has_children);
550 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
551 if(NS_FAILED(nsres)) {
552 ERR("GetType failed: %08x\n", nsres);
558 nsIDOMElement *nselem;
559 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
560 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
561 nsIDOMElement_Release(nselem);
566 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
567 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
568 nsIDOMText_Release(nstext);
572 nsIDOMComment *nscomment;
573 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMComment, (void**)&nscomment);
574 nsres = nsIContentSerializer_AppendComment(serializer, nscomment, 0, -1, str);
577 case DOCUMENT_NODE: {
578 nsIDOMDocument *nsdoc;
579 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
580 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
581 nsIDOMDocument_Release(nsdoc);
584 case DOCUMENT_FRAGMENT_NODE:
587 FIXME("Unhandled type %u\n", type);
591 PRUint32 child_cnt, i;
592 nsIDOMNode *child_node;
594 nsIDOMNode_GetChildNodes(nsnode, &node_list);
595 nsIDOMNodeList_GetLength(node_list, &child_cnt);
597 for(i=0; i<child_cnt; i++) {
598 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
599 if(NS_SUCCEEDED(nsres)) {
600 nsnode_to_nsstring_rec(serializer, child_node, str);
601 nsIDOMNode_Release(child_node);
603 ERR("Item failed: %08x\n", nsres);
607 nsIDOMNodeList_Release(node_list);
610 if(type == ELEMENT_NODE) {
611 nsIDOMElement *nselem;
612 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
613 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
614 nsIDOMElement_Release(nselem);
618 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
620 nsIContentSerializer *serializer;
624 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
625 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
626 (void**)&serializer);
627 if(NS_FAILED(nsres)) {
628 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
632 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
634 ERR("Init failed: %08x\n", nsres);
636 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
637 nsnode_to_nsstring_rec(serializer, nsnode, str);
638 nsIDOMNode_Release(nsnode);
640 nsres = nsIContentSerializer_Flush(serializer, str);
642 ERR("Flush failed: %08x\n", nsres);
644 nsIContentSerializer_Release(serializer);
647 void get_editor_controller(NSContainer *This)
649 nsIEditingSession *editing_session = NULL;
650 nsIControllerContext *ctrlctx;
654 nsIEditor_Release(This->editor);
658 if(This->editor_controller) {
659 nsIController_Release(This->editor_controller);
660 This->editor_controller = NULL;
663 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
664 (void**)&editing_session);
665 if(NS_FAILED(nsres)) {
666 ERR("Could not get nsIEditingSession: %08x\n", nsres);
670 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
671 This->doc->window->nswindow, &This->editor);
672 nsIEditingSession_Release(editing_session);
673 if(NS_FAILED(nsres)) {
674 ERR("Could not get editor: %08x\n", nsres);
678 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
679 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
680 if(NS_SUCCEEDED(nsres)) {
681 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
683 ERR("SetCommandContext failed: %08x\n", nsres);
684 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
685 (void**)&This->editor_controller);
686 nsIControllerContext_Release(ctrlctx);
688 ERR("Could not get nsIController interface: %08x\n", nsres);
690 ERR("Could not create edit controller: %08x\n", nsres);
694 void set_ns_editmode(NSContainer *This)
696 nsIEditingSession *editing_session = NULL;
697 nsIURIContentListener *listener = NULL;
698 nsIDOMWindow *dom_window = NULL;
701 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
702 (void**)&editing_session);
703 if(NS_FAILED(nsres)) {
704 ERR("Could not get nsIEditingSession: %08x\n", nsres);
708 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
709 if(NS_FAILED(nsres)) {
710 ERR("Could not get content DOM window: %08x\n", nsres);
711 nsIEditingSession_Release(editing_session);
715 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
716 nsIEditingSession_Release(editing_session);
717 nsIDOMWindow_Release(dom_window);
718 if(NS_FAILED(nsres)) {
719 ERR("MakeWindowEditable failed: %08x\n", nsres);
723 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
724 * It seams to be a bug in Gecko. To workaround it we set our content
725 * listener again and Gecko's one as its parent.
727 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
728 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
729 nsIURIContentListener_Release(listener);
730 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
733 void close_gecko(void)
738 nsIComponentManager_Release(pCompMgr);
741 nsIServiceManager_Release(pServMgr);
744 nsIMemory_Release(nsmem);
750 /**********************************************************
751 * nsIWebBrowserChrome interface
754 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
756 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
757 nsIIDRef riid, nsQIResult result)
759 NSContainer *This = NSWBCHROME_THIS(iface);
762 if(IsEqualGUID(&IID_nsISupports, riid)) {
763 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
764 *result = NSWBCHROME(This);
765 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
766 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
767 *result = NSWBCHROME(This);
768 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
769 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
770 *result = NSCML(This);
771 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
772 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
773 *result = NSURICL(This);
774 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
775 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
776 *result = NSEMBWNDS(This);
777 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
778 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
779 *result = NSTOOLTIP(This);
780 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
781 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
782 *result = NSIFACEREQ(This);
783 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
784 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
785 *result = NSWEAKREF(This);
786 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
787 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
788 *result = NSSUPWEAKREF(This);
792 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
796 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
797 return NS_NOINTERFACE;
800 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
802 NSContainer *This = NSWBCHROME_THIS(iface);
803 LONG ref = InterlockedIncrement(&This->ref);
805 TRACE("(%p) ref=%d\n", This, ref);
810 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
812 NSContainer *This = NSWBCHROME_THIS(iface);
813 LONG ref = InterlockedDecrement(&This->ref);
815 TRACE("(%p) ref=%d\n", This, ref);
819 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
826 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
827 PRUint32 statusType, const PRUnichar *status)
829 NSContainer *This = NSWBCHROME_THIS(iface);
830 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
835 nsIWebBrowser **aWebBrowser)
837 NSContainer *This = NSWBCHROME_THIS(iface);
839 TRACE("(%p)->(%p)\n", This, aWebBrowser);
842 return NS_ERROR_INVALID_ARG;
845 nsIWebBrowser_AddRef(This->webbrowser);
846 *aWebBrowser = This->webbrowser;
850 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
851 nsIWebBrowser *aWebBrowser)
853 NSContainer *This = NSWBCHROME_THIS(iface);
855 TRACE("(%p)->(%p)\n", This, aWebBrowser);
857 if(aWebBrowser != This->webbrowser)
858 ERR("Wrong nsWebBrowser!\n");
863 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
864 PRUint32 *aChromeFlags)
866 NSContainer *This = NSWBCHROME_THIS(iface);
867 WARN("(%p)->(%p)\n", This, aChromeFlags);
868 return NS_ERROR_NOT_IMPLEMENTED;
871 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
872 PRUint32 aChromeFlags)
874 NSContainer *This = NSWBCHROME_THIS(iface);
875 WARN("(%p)->(%08x)\n", This, aChromeFlags);
876 return NS_ERROR_NOT_IMPLEMENTED;
879 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
881 NSContainer *This = NSWBCHROME_THIS(iface);
882 TRACE("(%p)\n", This);
883 return NS_ERROR_NOT_IMPLEMENTED;
886 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
887 PRInt32 aCX, PRInt32 aCY)
889 NSContainer *This = NSWBCHROME_THIS(iface);
890 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
891 return NS_ERROR_NOT_IMPLEMENTED;
894 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
896 NSContainer *This = NSWBCHROME_THIS(iface);
897 WARN("(%p)\n", This);
898 return NS_ERROR_NOT_IMPLEMENTED;
901 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
903 NSContainer *This = NSWBCHROME_THIS(iface);
904 WARN("(%p)->(%p)\n", This, _retval);
905 return NS_ERROR_NOT_IMPLEMENTED;
908 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
911 NSContainer *This = NSWBCHROME_THIS(iface);
912 WARN("(%p)->(%08x)\n", This, aStatus);
913 return NS_ERROR_NOT_IMPLEMENTED;
916 #undef NSWBCHROME_THIS
918 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
919 nsWebBrowserChrome_QueryInterface,
920 nsWebBrowserChrome_AddRef,
921 nsWebBrowserChrome_Release,
922 nsWebBrowserChrome_SetStatus,
923 nsWebBrowserChrome_GetWebBrowser,
924 nsWebBrowserChrome_SetWebBrowser,
925 nsWebBrowserChrome_GetChromeFlags,
926 nsWebBrowserChrome_SetChromeFlags,
927 nsWebBrowserChrome_DestroyBrowserWindow,
928 nsWebBrowserChrome_SizeBrowserTo,
929 nsWebBrowserChrome_ShowAsModal,
930 nsWebBrowserChrome_IsWindowModal,
931 nsWebBrowserChrome_ExitModalEventLoop
934 /**********************************************************
935 * nsIContextMenuListener interface
938 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
940 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
941 nsIIDRef riid, nsQIResult result)
943 NSContainer *This = NSCML_THIS(iface);
944 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
947 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
949 NSContainer *This = NSCML_THIS(iface);
950 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
953 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
955 NSContainer *This = NSCML_THIS(iface);
956 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
959 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
960 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
962 NSContainer *This = NSCML_THIS(iface);
963 nsIDOMMouseEvent *event;
965 DWORD dwID = CONTEXT_MENU_DEFAULT;
968 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
970 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
971 if(NS_FAILED(nsres)) {
972 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
976 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
977 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
978 nsIDOMMouseEvent_Release(event);
980 switch(aContextFlags) {
982 case CONTEXT_DOCUMENT:
984 dwID = CONTEXT_MENU_DEFAULT;
987 case CONTEXT_IMAGE|CONTEXT_LINK:
988 dwID = CONTEXT_MENU_IMAGE;
991 dwID = CONTEXT_MENU_ANCHOR;
994 dwID = CONTEXT_MENU_CONTROL;
997 FIXME("aContextFlags=%08x\n", aContextFlags);
1000 show_context_menu(This->doc, dwID, &pt, (IDispatch*)HTMLDOMNODE(get_node(This->doc, aNode)));
1007 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1008 nsContextMenuListener_QueryInterface,
1009 nsContextMenuListener_AddRef,
1010 nsContextMenuListener_Release,
1011 nsContextMenuListener_OnShowContextMenu
1014 /**********************************************************
1015 * nsIURIContentListener interface
1018 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1020 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1021 nsIIDRef riid, nsQIResult result)
1023 NSContainer *This = NSURICL_THIS(iface);
1024 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1027 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1029 NSContainer *This = NSURICL_THIS(iface);
1030 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1033 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1035 NSContainer *This = NSURICL_THIS(iface);
1036 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1039 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1040 nsIURI *aURI, PRBool *_retval)
1042 NSContainer *This = NSURICL_THIS(iface);
1043 nsIWineURI *wine_uri;
1044 nsACString spec_str;
1048 nsACString_Init(&spec_str, NULL);
1049 nsIURI_GetSpec(aURI, &spec_str);
1050 nsACString_GetData(&spec_str, &spec, NULL);
1052 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1054 nsACString_Finish(&spec_str);
1056 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1057 if(NS_FAILED(nsres)) {
1058 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
1059 return NS_ERROR_NOT_IMPLEMENTED;
1062 nsIWineURI_SetNSContainer(wine_uri, This);
1063 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
1065 if(This->bscallback && This->bscallback->mon) {
1069 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
1070 if(SUCCEEDED(hres)) {
1071 nsIWineURI_SetWineURL(wine_uri, wine_url);
1072 CoTaskMemFree(wine_url);
1074 WARN("GetDisplayName failed: %08x\n", hres);
1078 nsIWineURI_Release(wine_uri);
1081 return This->content_listener
1082 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1086 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1087 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1088 nsIStreamListener **aContentHandler, PRBool *_retval)
1090 NSContainer *This = NSURICL_THIS(iface);
1092 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1093 aRequest, aContentHandler, _retval);
1095 return This->content_listener
1096 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1097 aIsContentPreferred, aRequest, aContentHandler, _retval)
1098 : NS_ERROR_NOT_IMPLEMENTED;
1101 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1102 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1104 NSContainer *This = NSURICL_THIS(iface);
1106 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1108 /* FIXME: Should we do something here? */
1111 return This->content_listener
1112 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1113 aDesiredContentType, _retval)
1117 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1118 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1121 NSContainer *This = NSURICL_THIS(iface);
1123 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1124 aDesiredContentType, _retval);
1126 return This->content_listener
1127 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1128 aIsContentPreferred, aDesiredContentType, _retval)
1129 : NS_ERROR_NOT_IMPLEMENTED;
1132 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1133 nsISupports **aLoadCookie)
1135 NSContainer *This = NSURICL_THIS(iface);
1137 WARN("(%p)->(%p)\n", This, aLoadCookie);
1139 return This->content_listener
1140 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1141 : NS_ERROR_NOT_IMPLEMENTED;
1144 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1145 nsISupports *aLoadCookie)
1147 NSContainer *This = NSURICL_THIS(iface);
1149 WARN("(%p)->(%p)\n", This, aLoadCookie);
1151 return This->content_listener
1152 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1153 : NS_ERROR_NOT_IMPLEMENTED;
1156 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1157 nsIURIContentListener **aParentContentListener)
1159 NSContainer *This = NSURICL_THIS(iface);
1161 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1163 if(This->content_listener)
1164 nsIURIContentListener_AddRef(This->content_listener);
1166 *aParentContentListener = This->content_listener;
1170 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1171 nsIURIContentListener *aParentContentListener)
1173 NSContainer *This = NSURICL_THIS(iface);
1175 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1177 if(aParentContentListener == NSURICL(This))
1180 if(This->content_listener)
1181 nsIURIContentListener_Release(This->content_listener);
1183 This->content_listener = aParentContentListener;
1184 if(This->content_listener)
1185 nsIURIContentListener_AddRef(This->content_listener);
1192 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1193 nsURIContentListener_QueryInterface,
1194 nsURIContentListener_AddRef,
1195 nsURIContentListener_Release,
1196 nsURIContentListener_OnStartURIOpen,
1197 nsURIContentListener_DoContent,
1198 nsURIContentListener_IsPreferred,
1199 nsURIContentListener_CanHandleContent,
1200 nsURIContentListener_GetLoadCookie,
1201 nsURIContentListener_SetLoadCookie,
1202 nsURIContentListener_GetParentContentListener,
1203 nsURIContentListener_SetParentContentListener
1206 /**********************************************************
1207 * nsIEmbeddinSiteWindow interface
1210 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1212 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1213 nsIIDRef riid, nsQIResult result)
1215 NSContainer *This = NSEMBWNDS_THIS(iface);
1216 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1219 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1221 NSContainer *This = NSEMBWNDS_THIS(iface);
1222 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1225 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1227 NSContainer *This = NSEMBWNDS_THIS(iface);
1228 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1231 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1232 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1234 NSContainer *This = NSEMBWNDS_THIS(iface);
1235 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1236 return NS_ERROR_NOT_IMPLEMENTED;
1239 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1240 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1242 NSContainer *This = NSEMBWNDS_THIS(iface);
1243 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1244 return NS_ERROR_NOT_IMPLEMENTED;
1247 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1249 NSContainer *This = NSEMBWNDS_THIS(iface);
1251 TRACE("(%p)\n", This);
1253 return nsIBaseWindow_SetFocus(This->window);
1256 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1257 PRBool *aVisibility)
1259 NSContainer *This = NSEMBWNDS_THIS(iface);
1261 TRACE("(%p)->(%p)\n", This, aVisibility);
1263 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1267 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1270 NSContainer *This = NSEMBWNDS_THIS(iface);
1272 TRACE("(%p)->(%x)\n", This, aVisibility);
1277 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1280 NSContainer *This = NSEMBWNDS_THIS(iface);
1281 WARN("(%p)->(%p)\n", This, aTitle);
1282 return NS_ERROR_NOT_IMPLEMENTED;
1285 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1286 const PRUnichar *aTitle)
1288 NSContainer *This = NSEMBWNDS_THIS(iface);
1289 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1290 return NS_ERROR_NOT_IMPLEMENTED;
1293 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1296 NSContainer *This = NSEMBWNDS_THIS(iface);
1298 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1300 *aSiteWindow = This->hwnd;
1304 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1305 nsEmbeddingSiteWindow_QueryInterface,
1306 nsEmbeddingSiteWindow_AddRef,
1307 nsEmbeddingSiteWindow_Release,
1308 nsEmbeddingSiteWindow_SetDimensions,
1309 nsEmbeddingSiteWindow_GetDimensions,
1310 nsEmbeddingSiteWindow_SetFocus,
1311 nsEmbeddingSiteWindow_GetVisibility,
1312 nsEmbeddingSiteWindow_SetVisibility,
1313 nsEmbeddingSiteWindow_GetTitle,
1314 nsEmbeddingSiteWindow_SetTitle,
1315 nsEmbeddingSiteWindow_GetSiteWindow
1318 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1320 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1323 NSContainer *This = NSTOOLTIP_THIS(iface);
1324 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1327 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1329 NSContainer *This = NSTOOLTIP_THIS(iface);
1330 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1333 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1335 NSContainer *This = NSTOOLTIP_THIS(iface);
1336 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1339 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1340 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1342 NSContainer *This = NSTOOLTIP_THIS(iface);
1344 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1349 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1351 NSContainer *This = NSTOOLTIP_THIS(iface);
1353 hide_tooltip(This->doc);
1358 #undef NSTOOLTIM_THIS
1360 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1361 nsTooltipListener_QueryInterface,
1362 nsTooltipListener_AddRef,
1363 nsTooltipListener_Release,
1364 nsTooltipListener_OnShowTooltip,
1365 nsTooltipListener_OnHideTooltip
1368 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1370 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1371 nsIIDRef riid, nsQIResult result)
1373 NSContainer *This = NSIFACEREQ_THIS(iface);
1374 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1377 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1379 NSContainer *This = NSIFACEREQ_THIS(iface);
1380 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1383 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1385 NSContainer *This = NSIFACEREQ_THIS(iface);
1386 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1389 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1390 nsIIDRef riid, nsQIResult result)
1392 NSContainer *This = NSIFACEREQ_THIS(iface);
1394 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1395 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1396 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1399 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1402 #undef NSIFACEREQ_THIS
1404 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1405 nsInterfaceRequestor_QueryInterface,
1406 nsInterfaceRequestor_AddRef,
1407 nsInterfaceRequestor_Release,
1408 nsInterfaceRequestor_GetInterface
1411 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1413 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1414 nsIIDRef riid, nsQIResult result)
1416 NSContainer *This = NSWEAKREF_THIS(iface);
1417 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1420 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1422 NSContainer *This = NSWEAKREF_THIS(iface);
1423 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1426 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1428 NSContainer *This = NSWEAKREF_THIS(iface);
1429 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1432 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1433 const nsIID *riid, void **result)
1435 NSContainer *This = NSWEAKREF_THIS(iface);
1436 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1439 #undef NSWEAKREF_THIS
1441 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1442 nsWeakReference_QueryInterface,
1443 nsWeakReference_AddRef,
1444 nsWeakReference_Release,
1445 nsWeakReference_QueryReferent
1448 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1450 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1451 nsIIDRef riid, nsQIResult result)
1453 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1454 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1457 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1459 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1460 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1463 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1465 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1466 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1469 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1470 nsIWeakReference **_retval)
1472 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1474 TRACE("(%p)->(%p)\n", This, _retval);
1476 nsIWeakReference_AddRef(NSWEAKREF(This));
1477 *_retval = NSWEAKREF(This);
1481 #undef NSWEAKREF_THIS
1483 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1484 nsSupportsWeakReference_QueryInterface,
1485 nsSupportsWeakReference_AddRef,
1486 nsSupportsWeakReference_Release,
1487 nsSupportsWeakReference_GetWeakReference
1491 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1493 nsIWebBrowserSetup *wbsetup;
1494 nsIScrollable *scrollable;
1498 if(!load_gecko(FALSE))
1501 ret = mshtml_alloc(sizeof(NSContainer));
1503 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1504 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1505 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1506 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1507 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1508 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1509 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1510 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1514 ret->bscallback = NULL;
1515 ret->content_listener = NULL;
1516 ret->editor_controller = NULL;
1520 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1521 ret->parent = parent;
1523 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1524 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1525 if(NS_FAILED(nsres))
1526 ERR("Creating WebBrowser failed: %08x\n", nsres);
1528 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1529 if(NS_FAILED(nsres))
1530 ERR("SetContainerWindow failed: %08x\n", nsres);
1532 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1533 (void**)&ret->window);
1534 if(NS_FAILED(nsres))
1535 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1537 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1539 if(NS_SUCCEEDED(nsres)) {
1540 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1541 nsIWebBrowserSetup_Release(wbsetup);
1542 if(NS_FAILED(nsres))
1543 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1545 ERR("Could not get nsIWebBrowserSetup interface\n");
1548 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1549 (void**)&ret->navigation);
1550 if(NS_FAILED(nsres))
1551 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1553 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1554 (void**)&ret->focus);
1555 if(NS_FAILED(nsres))
1556 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1558 if(!nscontainer_class)
1559 register_nscontainer_class();
1561 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1562 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1563 GetDesktopWindow(), NULL, hInst, ret);
1565 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1566 if(NS_SUCCEEDED(nsres)) {
1567 nsres = nsIBaseWindow_Create(ret->window);
1568 if(NS_FAILED(nsres))
1569 WARN("Creating window failed: %08x\n", nsres);
1571 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1572 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1574 ERR("InitWindow failed: %08x\n", nsres);
1577 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1578 if(NS_FAILED(nsres))
1579 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1583 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1584 if(NS_SUCCEEDED(nsres)) {
1585 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1586 ScrollOrientation_Y, Scrollbar_Always);
1587 if(NS_FAILED(nsres))
1588 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1590 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1591 ScrollOrientation_X, Scrollbar_Auto);
1592 if(NS_FAILED(nsres))
1593 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1595 nsIScrollable_Release(scrollable);
1597 ERR("Could not get nsIScrollable: %08x\n", nsres);
1603 void NSContainer_Release(NSContainer *This)
1605 TRACE("(%p)\n", This);
1607 ShowWindow(This->hwnd, SW_HIDE);
1608 SetParent(This->hwnd, NULL);
1610 nsIBaseWindow_SetVisibility(This->window, FALSE);
1611 nsIBaseWindow_Destroy(This->window);
1613 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1615 nsIWebBrowser_Release(This->webbrowser);
1616 This->webbrowser = NULL;
1618 nsIWebNavigation_Release(This->navigation);
1619 This->navigation = NULL;
1621 nsIBaseWindow_Release(This->window);
1622 This->window = NULL;
1624 nsIWebBrowserFocus_Release(This->focus);
1627 if(This->editor_controller) {
1628 nsIController_Release(This->editor_controller);
1629 This->editor_controller = NULL;
1633 nsIEditor_Release(This->editor);
1634 This->editor = NULL;
1637 if(This->content_listener) {
1638 nsIURIContentListener_Release(This->content_listener);
1639 This->content_listener = NULL;
1643 DestroyWindow(This->hwnd);
1647 nsIWebBrowserChrome_Release(NSWBCHROME(This));