2 * Copyright 2005-2006 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"
46 #define APPSTARTUP_TOPIC "app-startup"
48 #define PR_UINT32_MAX 0xffffffff
50 struct nsCStringContainer {
57 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
58 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
59 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
60 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
61 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
62 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
63 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
64 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
65 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
66 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
67 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
68 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
70 static HINSTANCE hXPCOM = NULL;
72 static nsIServiceManager *pServMgr = NULL;
73 static nsIComponentManager *pCompMgr = NULL;
74 static nsIMemory *nsmem = NULL;
76 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
78 static ATOM nscontainer_class;
80 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
85 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
87 if(msg == WM_CREATE) {
88 This = *(NSContainer**)lParam;
89 SetPropW(hwnd, wszTHIS, This);
91 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
96 TRACE("(%p)->(WM_SIZE)\n", This);
98 nsres = nsIBaseWindow_SetSize(This->window,
99 LOWORD(lParam), HIWORD(lParam), TRUE);
101 WARN("SetSize failed: %08x\n", nsres);
104 return DefWindowProcW(hwnd, msg, wParam, lParam);
108 static void register_nscontainer_class(void)
110 static WNDCLASSEXW wndclass = {
114 0, 0, NULL, NULL, NULL, NULL, NULL,
118 wndclass.hInstance = hInst;
119 nscontainer_class = RegisterClassExW(&wndclass);
122 static BOOL load_xpcom(PRUnichar *gre_path)
124 WCHAR path_env[MAX_PATH];
127 static const WCHAR wszPATH[] = {'P','A','T','H',0};
128 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
130 TRACE("(%s)\n", debugstr_w(gre_path));
132 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
133 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
134 len = strlenW(path_env);
135 path_env[len++] = ';';
136 strcpyW(path_env+len, gre_path);
137 SetEnvironmentVariableW(wszPATH, path_env);
139 hXPCOM = LoadLibraryW(strXPCOM);
141 WARN("Could not load XPCOM: %d\n", GetLastError());
145 #define NS_DLSYM(func) \
146 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
148 ERR("Could not GetProcAddress(" #func ") failed\n")
150 NS_DLSYM(NS_InitXPCOM2);
151 NS_DLSYM(NS_ShutdownXPCOM);
152 NS_DLSYM(NS_GetComponentRegistrar);
153 NS_DLSYM(NS_StringContainerInit);
154 NS_DLSYM(NS_CStringContainerInit);
155 NS_DLSYM(NS_StringContainerFinish);
156 NS_DLSYM(NS_CStringContainerFinish);
157 NS_DLSYM(NS_StringSetData);
158 NS_DLSYM(NS_CStringSetData);
159 NS_DLSYM(NS_NewLocalFile);
160 NS_DLSYM(NS_StringGetData);
161 NS_DLSYM(NS_CStringGetData);
168 static void check_version(LPCWSTR gre_path)
170 WCHAR file_name[MAX_PATH];
175 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
177 strcpyW(file_name, gre_path);
178 strcatW(file_name, wszVersion);
180 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
181 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
182 if(hfile == INVALID_HANDLE_VALUE) {
183 TRACE("unknown version\n");
187 ReadFile(hfile, version, sizeof(version), &read, NULL);
190 TRACE("%s\n", debugstr_a(version));
195 static BOOL load_wine_gecko(PRUnichar *gre_path)
198 DWORD res, type, size = MAX_PATH;
200 static const WCHAR wszMshtmlKey[] = {
201 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
202 '\\','M','S','H','T','M','L',0};
203 static const WCHAR wszGeckoPath[] =
204 {'G','e','c','k','o','P','a','t','h',0};
206 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
207 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
208 if(res != ERROR_SUCCESS)
211 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
212 if(res != ERROR_SUCCESS || type != REG_SZ)
216 check_version(gre_path);
218 return load_xpcom(gre_path);
221 static void set_profile(void)
224 PRBool exists = FALSE;
227 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
229 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
230 &IID_nsIProfile, (void**)&profile);
231 if(NS_FAILED(nsres)) {
232 ERR("Could not get profile service: %08x\n", nsres);
236 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
238 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
240 ERR("CreateNewProfile failed: %08x\n", nsres);
243 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
245 ERR("SetCurrentProfile failed: %08x\n", nsres);
247 nsIProfile_Release(profile);
250 static BOOL init_xpcom(PRUnichar *gre_path)
253 nsIObserver *pStartNotif;
254 nsIComponentRegistrar *registrar = NULL;
258 nsAString_Init(&path, gre_path);
259 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
260 nsAString_Finish(&path);
261 if(NS_FAILED(nsres)) {
262 ERR("NS_NewLocalFile failed: %08x\n", nsres);
267 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
268 if(NS_FAILED(nsres)) {
269 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
274 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
276 ERR("Could not get nsIComponentManager: %08x\n", nsres);
278 nsres = NS_GetComponentRegistrar(®istrar);
279 if(NS_SUCCEEDED(nsres)) {
280 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
282 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
284 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
286 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
288 init_nsio(pCompMgr, registrar);
290 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
293 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
294 NULL, &IID_nsIObserver, (void**)&pStartNotif);
295 if(NS_SUCCEEDED(nsres)) {
296 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
298 ERR("Observe failed: %08x\n", nsres);
300 nsIObserver_Release(pStartNotif);
302 ERR("could not get appstartup-notifier: %08x\n", nsres);
307 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
308 NULL, &IID_nsIMemory, (void**)&nsmem);
310 ERR("Could not get nsIMemory: %08x\n", nsres);
313 register_nsservice(registrar, pServMgr);
314 nsIComponentRegistrar_Release(registrar);
320 static CRITICAL_SECTION cs_load_gecko;
321 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
323 0, 0, &cs_load_gecko,
324 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
325 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
327 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
329 static BOOL load_gecko(void)
331 PRUnichar gre_path[MAX_PATH];
334 static LONG loading_thread;
338 /* load_gecko may be called recursively */
339 if(loading_thread == GetCurrentThreadId())
340 return pCompMgr != NULL;
342 EnterCriticalSection(&cs_load_gecko);
344 if(!loading_thread) {
345 loading_thread = GetCurrentThreadId();
347 if(load_wine_gecko(gre_path)
348 || (install_wine_gecko() && load_wine_gecko(gre_path)))
349 ret = init_xpcom(gre_path);
351 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
353 ret = pCompMgr != NULL;
356 LeaveCriticalSection(&cs_load_gecko);
361 void *nsalloc(size_t size)
363 return nsIMemory_Alloc(nsmem, size);
366 void nsfree(void *mem)
368 nsIMemory_Free(nsmem, mem);
371 void nsACString_Init(nsACString *str, const char *data)
373 NS_CStringContainerInit(str);
375 nsACString_SetData(str, data);
378 void nsACString_SetData(nsACString *str, const char *data)
380 NS_CStringSetData(str, data, PR_UINT32_MAX);
383 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
385 return NS_CStringGetData(str, data, termited);
388 void nsACString_Finish(nsACString *str)
390 NS_CStringContainerFinish(str);
393 void nsAString_Init(nsAString *str, const PRUnichar *data)
395 NS_StringContainerInit(str);
397 NS_StringSetData(str, data, PR_UINT32_MAX);
400 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
402 return NS_StringGetData(str, data, termited);
405 void nsAString_Finish(nsAString *str)
407 NS_StringContainerFinish(str);
410 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
412 nsIStringInputStream *ret;
418 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
419 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
421 if(NS_FAILED(nsres)) {
422 ERR("Could not get nsIStringInputStream\n");
426 nsres = nsIStringInputStream_SetData(ret, data, data_len);
427 if(NS_FAILED(nsres)) {
428 ERR("AdoptData failed: %08x\n", nsres);
429 nsIStringInputStream_Release(ret);
433 return (nsIInputStream*)ret;
436 nsICommandParams *create_nscommand_params(void)
438 nsICommandParams *ret = NULL;
444 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
445 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
448 ERR("Could not get nsICommandParams\n");
453 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
455 nsIDOMNodeList *node_list = NULL;
456 PRBool has_children = FALSE;
460 nsIDOMNode_HasChildNodes(nsnode, &has_children);
462 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
463 if(NS_FAILED(nsres)) {
464 ERR("GetType failed: %08x\n", nsres);
470 nsIDOMElement *nselem;
471 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
472 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
473 nsIDOMElement_Release(nselem);
478 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
479 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
480 nsIDOMText_Release(nstext);
483 case DOCUMENT_NODE: {
484 nsIDOMDocument *nsdoc;
485 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
486 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
487 nsIDOMDocument_Release(nsdoc);
491 FIXME("Unhandled type %u\n", type);
495 PRUint32 child_cnt, i;
496 nsIDOMNode *child_node;
498 nsIDOMNode_GetChildNodes(nsnode, &node_list);
499 nsIDOMNodeList_GetLength(node_list, &child_cnt);
501 for(i=0; i<child_cnt; i++) {
502 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
503 if(NS_SUCCEEDED(nsres)) {
504 nsnode_to_nsstring_rec(serializer, child_node, str);
505 nsIDOMNode_Release(child_node);
507 ERR("Item failed: %08x\n", nsres);
511 nsIDOMNodeList_Release(node_list);
514 if(type == ELEMENT_NODE) {
515 nsIDOMElement *nselem;
516 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
517 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
518 nsIDOMElement_Release(nselem);
522 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
524 nsIContentSerializer *serializer;
528 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
529 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
530 (void**)&serializer);
531 if(NS_FAILED(nsres)) {
532 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
536 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
538 ERR("Init failed: %08x\n", nsres);
540 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
541 nsnode_to_nsstring_rec(serializer, nsnode, str);
542 nsIDOMNode_Release(nsnode);
544 nsres = nsIContentSerializer_Flush(serializer, str);
546 ERR("Flush failed: %08x\n", nsres);
548 nsIContentSerializer_Release(serializer);
551 void close_gecko(void)
556 nsIComponentManager_Release(pCompMgr);
559 nsIServiceManager_Release(pServMgr);
562 nsIMemory_Release(nsmem);
568 /**********************************************************
569 * nsIWebBrowserChrome interface
572 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
574 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
575 nsIIDRef riid, nsQIResult result)
577 NSContainer *This = NSWBCHROME_THIS(iface);
580 if(IsEqualGUID(&IID_nsISupports, riid)) {
581 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
582 *result = NSWBCHROME(This);
583 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
584 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
585 *result = NSWBCHROME(This);
586 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
587 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
588 *result = NSCML(This);
589 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
590 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
591 *result = NSURICL(This);
592 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
593 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
594 *result = NSEMBWNDS(This);
595 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
596 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
597 *result = NSTOOLTIP(This);
598 }else if(IsEqualGUID(&IID_nsIDOMEventListener, riid)) {
599 TRACE("(%p)->(IID_nsIDOMEventListener %p)\n", This, result);
600 *result = NSEVENTLIST(This);
601 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
602 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
603 *result = NSIFACEREQ(This);
604 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
605 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
606 *result = NSWEAKREF(This);
607 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
608 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
609 *result = NSSUPWEAKREF(This);
613 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
617 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
618 return NS_NOINTERFACE;
621 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
623 NSContainer *This = NSWBCHROME_THIS(iface);
624 LONG ref = InterlockedIncrement(&This->ref);
626 TRACE("(%p) ref=%d\n", This, ref);
631 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
633 NSContainer *This = NSWBCHROME_THIS(iface);
634 LONG ref = InterlockedDecrement(&This->ref);
636 TRACE("(%p) ref=%d\n", This, ref);
640 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
647 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
648 PRUint32 statusType, const PRUnichar *status)
650 NSContainer *This = NSWBCHROME_THIS(iface);
651 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
652 return NS_ERROR_NOT_IMPLEMENTED;
655 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
656 nsIWebBrowser **aWebBrowser)
658 NSContainer *This = NSWBCHROME_THIS(iface);
660 TRACE("(%p)->(%p)\n", This, aWebBrowser);
663 return NS_ERROR_INVALID_ARG;
666 nsIWebBrowser_AddRef(This->webbrowser);
667 *aWebBrowser = This->webbrowser;
671 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
672 nsIWebBrowser *aWebBrowser)
674 NSContainer *This = NSWBCHROME_THIS(iface);
676 TRACE("(%p)->(%p)\n", This, aWebBrowser);
678 if(aWebBrowser != This->webbrowser)
679 ERR("Wrong nsWebBrowser!\n");
684 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
685 PRUint32 *aChromeFlags)
687 NSContainer *This = NSWBCHROME_THIS(iface);
688 WARN("(%p)->(%p)\n", This, aChromeFlags);
689 return NS_ERROR_NOT_IMPLEMENTED;
692 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
693 PRUint32 aChromeFlags)
695 NSContainer *This = NSWBCHROME_THIS(iface);
696 WARN("(%p)->(%08x)\n", This, aChromeFlags);
697 return NS_ERROR_NOT_IMPLEMENTED;
700 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
702 NSContainer *This = NSWBCHROME_THIS(iface);
703 TRACE("(%p)\n", This);
704 return NS_ERROR_NOT_IMPLEMENTED;
707 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
708 PRInt32 aCX, PRInt32 aCY)
710 NSContainer *This = NSWBCHROME_THIS(iface);
711 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
712 return NS_ERROR_NOT_IMPLEMENTED;
715 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
717 NSContainer *This = NSWBCHROME_THIS(iface);
718 WARN("(%p)\n", This);
719 return NS_ERROR_NOT_IMPLEMENTED;
722 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
724 NSContainer *This = NSWBCHROME_THIS(iface);
725 WARN("(%p)->(%p)\n", This, _retval);
726 return NS_ERROR_NOT_IMPLEMENTED;
729 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
732 NSContainer *This = NSWBCHROME_THIS(iface);
733 WARN("(%p)->(%08x)\n", This, aStatus);
734 return NS_ERROR_NOT_IMPLEMENTED;
737 #undef NSWBCHROME_THIS
739 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
740 nsWebBrowserChrome_QueryInterface,
741 nsWebBrowserChrome_AddRef,
742 nsWebBrowserChrome_Release,
743 nsWebBrowserChrome_SetStatus,
744 nsWebBrowserChrome_GetWebBrowser,
745 nsWebBrowserChrome_SetWebBrowser,
746 nsWebBrowserChrome_GetChromeFlags,
747 nsWebBrowserChrome_SetChromeFlags,
748 nsWebBrowserChrome_DestroyBrowserWindow,
749 nsWebBrowserChrome_SizeBrowserTo,
750 nsWebBrowserChrome_ShowAsModal,
751 nsWebBrowserChrome_IsWindowModal,
752 nsWebBrowserChrome_ExitModalEventLoop
755 /**********************************************************
756 * nsIContextMenuListener interface
759 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
761 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
762 nsIIDRef riid, nsQIResult result)
764 NSContainer *This = NSCML_THIS(iface);
765 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
768 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
770 NSContainer *This = NSCML_THIS(iface);
771 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
774 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
776 NSContainer *This = NSCML_THIS(iface);
777 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
780 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
781 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
783 NSContainer *This = NSCML_THIS(iface);
784 nsIDOMMouseEvent *event;
786 DWORD dwID = CONTEXT_MENU_DEFAULT;
789 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
791 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
792 if(NS_FAILED(nsres)) {
793 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
797 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
798 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
799 nsIDOMMouseEvent_Release(event);
801 switch(aContextFlags) {
803 case CONTEXT_DOCUMENT:
805 dwID = CONTEXT_MENU_DEFAULT;
808 case CONTEXT_IMAGE|CONTEXT_LINK:
809 dwID = CONTEXT_MENU_IMAGE;
812 dwID = CONTEXT_MENU_ANCHOR;
815 dwID = CONTEXT_MENU_CONTROL;
818 FIXME("aContextFlags=%08x\n", aContextFlags);
821 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
828 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
829 nsContextMenuListener_QueryInterface,
830 nsContextMenuListener_AddRef,
831 nsContextMenuListener_Release,
832 nsContextMenuListener_OnShowContextMenu
835 /**********************************************************
836 * nsIURIContentListener interface
839 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
841 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
842 nsIIDRef riid, nsQIResult result)
844 NSContainer *This = NSURICL_THIS(iface);
845 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
848 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
850 NSContainer *This = NSURICL_THIS(iface);
851 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
854 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
856 NSContainer *This = NSURICL_THIS(iface);
857 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
860 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
861 nsIURI *aURI, PRBool *_retval)
863 NSContainer *This = NSURICL_THIS(iface);
864 nsIWineURI *wine_uri;
869 nsACString_Init(&spec_str, NULL);
870 nsIURI_GetSpec(aURI, &spec_str);
871 nsACString_GetData(&spec_str, &spec, NULL);
873 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
875 nsACString_Finish(&spec_str);
877 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
878 if(NS_FAILED(nsres)) {
879 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
880 return NS_ERROR_NOT_IMPLEMENTED;
883 nsIWineURI_SetNSContainer(wine_uri, This);
884 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
886 if(This->bscallback && This->bscallback->mon) {
890 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
891 if(SUCCEEDED(hres)) {
892 nsIWineURI_SetWineURL(wine_uri, wine_url);
893 CoTaskMemFree(wine_url);
895 WARN("GetDisplayName failed: %08x\n", hres);
899 nsIWineURI_Release(wine_uri);
902 return This->content_listener
903 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
907 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
908 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
909 nsIStreamListener **aContentHandler, PRBool *_retval)
911 NSContainer *This = NSURICL_THIS(iface);
913 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
914 aRequest, aContentHandler, _retval);
916 return This->content_listener
917 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
918 aIsContentPreferred, aRequest, aContentHandler, _retval)
919 : NS_ERROR_NOT_IMPLEMENTED;
922 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
923 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
925 NSContainer *This = NSURICL_THIS(iface);
927 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
929 /* FIXME: Should we do something here? */
932 return This->content_listener
933 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
934 aDesiredContentType, _retval)
938 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
939 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
942 NSContainer *This = NSURICL_THIS(iface);
944 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
945 aDesiredContentType, _retval);
947 return This->content_listener
948 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
949 aIsContentPreferred, aDesiredContentType, _retval)
950 : NS_ERROR_NOT_IMPLEMENTED;
953 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
954 nsISupports **aLoadCookie)
956 NSContainer *This = NSURICL_THIS(iface);
958 WARN("(%p)->(%p)\n", This, aLoadCookie);
960 return This->content_listener
961 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
962 : NS_ERROR_NOT_IMPLEMENTED;
965 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
966 nsISupports *aLoadCookie)
968 NSContainer *This = NSURICL_THIS(iface);
970 WARN("(%p)->(%p)\n", This, aLoadCookie);
972 return This->content_listener
973 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
974 : NS_ERROR_NOT_IMPLEMENTED;
977 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
978 nsIURIContentListener **aParentContentListener)
980 NSContainer *This = NSURICL_THIS(iface);
982 TRACE("(%p)->(%p)\n", This, aParentContentListener);
984 if(This->content_listener)
985 nsIURIContentListener_AddRef(This->content_listener);
987 *aParentContentListener = This->content_listener;
991 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
992 nsIURIContentListener *aParentContentListener)
994 NSContainer *This = NSURICL_THIS(iface);
996 TRACE("(%p)->(%p)\n", This, aParentContentListener);
998 if(aParentContentListener == NSURICL(This))
1001 if(This->content_listener)
1002 nsIURIContentListener_Release(This->content_listener);
1004 This->content_listener = aParentContentListener;
1005 if(This->content_listener)
1006 nsIURIContentListener_AddRef(This->content_listener);
1013 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1014 nsURIContentListener_QueryInterface,
1015 nsURIContentListener_AddRef,
1016 nsURIContentListener_Release,
1017 nsURIContentListener_OnStartURIOpen,
1018 nsURIContentListener_DoContent,
1019 nsURIContentListener_IsPreferred,
1020 nsURIContentListener_CanHandleContent,
1021 nsURIContentListener_GetLoadCookie,
1022 nsURIContentListener_SetLoadCookie,
1023 nsURIContentListener_GetParentContentListener,
1024 nsURIContentListener_SetParentContentListener
1027 /**********************************************************
1028 * nsIEmbeddinSiteWindow interface
1031 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1033 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1034 nsIIDRef riid, nsQIResult result)
1036 NSContainer *This = NSEMBWNDS_THIS(iface);
1037 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1040 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1042 NSContainer *This = NSEMBWNDS_THIS(iface);
1043 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1046 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1048 NSContainer *This = NSEMBWNDS_THIS(iface);
1049 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1052 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1053 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1055 NSContainer *This = NSEMBWNDS_THIS(iface);
1056 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1057 return NS_ERROR_NOT_IMPLEMENTED;
1060 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1061 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1063 NSContainer *This = NSEMBWNDS_THIS(iface);
1064 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1065 return NS_ERROR_NOT_IMPLEMENTED;
1068 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1070 NSContainer *This = NSEMBWNDS_THIS(iface);
1071 WARN("(%p)\n", This);
1072 return NS_ERROR_NOT_IMPLEMENTED;
1075 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1076 PRBool *aVisibility)
1078 NSContainer *This = NSEMBWNDS_THIS(iface);
1079 WARN("(%p)->(%p)\n", This, aVisibility);
1080 return NS_ERROR_NOT_IMPLEMENTED;
1083 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1086 NSContainer *This = NSEMBWNDS_THIS(iface);
1087 WARN("(%p)->(%x)\n", This, aVisibility);
1088 return NS_ERROR_NOT_IMPLEMENTED;
1091 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1094 NSContainer *This = NSEMBWNDS_THIS(iface);
1095 WARN("(%p)->(%p)\n", This, aTitle);
1096 return NS_ERROR_NOT_IMPLEMENTED;
1099 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1100 const PRUnichar *aTitle)
1102 NSContainer *This = NSEMBWNDS_THIS(iface);
1103 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1104 return NS_ERROR_NOT_IMPLEMENTED;
1107 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1110 NSContainer *This = NSEMBWNDS_THIS(iface);
1112 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1114 *aSiteWindow = This->hwnd;
1118 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1119 nsEmbeddingSiteWindow_QueryInterface,
1120 nsEmbeddingSiteWindow_AddRef,
1121 nsEmbeddingSiteWindow_Release,
1122 nsEmbeddingSiteWindow_SetDimensions,
1123 nsEmbeddingSiteWindow_GetDimensions,
1124 nsEmbeddingSiteWindow_SetFocus,
1125 nsEmbeddingSiteWindow_GetVisibility,
1126 nsEmbeddingSiteWindow_SetVisibility,
1127 nsEmbeddingSiteWindow_GetTitle,
1128 nsEmbeddingSiteWindow_SetTitle,
1129 nsEmbeddingSiteWindow_GetSiteWindow
1132 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1134 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1137 NSContainer *This = NSTOOLTIP_THIS(iface);
1138 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1141 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1143 NSContainer *This = NSTOOLTIP_THIS(iface);
1144 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1147 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1149 NSContainer *This = NSTOOLTIP_THIS(iface);
1150 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1153 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1154 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1156 NSContainer *This = NSTOOLTIP_THIS(iface);
1158 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1163 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1165 NSContainer *This = NSTOOLTIP_THIS(iface);
1167 hide_tooltip(This->doc);
1172 #undef NSTOOLTIM_THIS
1174 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1175 nsTooltipListener_QueryInterface,
1176 nsTooltipListener_AddRef,
1177 nsTooltipListener_Release,
1178 nsTooltipListener_OnShowTooltip,
1179 nsTooltipListener_OnHideTooltip
1182 #define NSEVENTLIST_THIS(iface) DEFINE_THIS(NSContainer, DOMEventListener, iface)
1184 static nsresult NSAPI nsDOMEventListener_QueryInterface(nsIDOMEventListener *iface,
1185 nsIIDRef riid, nsQIResult result)
1187 NSContainer *This = NSEVENTLIST_THIS(iface);
1188 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1191 static nsrefcnt NSAPI nsDOMEventListener_AddRef(nsIDOMEventListener *iface)
1193 NSContainer *This = NSEVENTLIST_THIS(iface);
1194 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1197 static nsrefcnt NSAPI nsDOMEventListener_Release(nsIDOMEventListener *iface)
1199 NSContainer *This = NSEVENTLIST_THIS(iface);
1200 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1203 static nsresult NSAPI nsDOMEventListener_HandleEvent(nsIDOMEventListener *iface, nsIDOMEvent *event)
1205 NSContainer *This = NSEVENTLIST_THIS(iface);
1207 TRACE("(%p)->(%p)\n", This, event);
1209 if(This->doc->usermode == EDITMODE)
1210 handle_edit_event(This->doc, event);
1215 #undef NSEVENTLIST_THIS
1217 static const nsIDOMEventListenerVtbl nsDOMEventListenerVtbl = {
1218 nsDOMEventListener_QueryInterface,
1219 nsDOMEventListener_AddRef,
1220 nsDOMEventListener_Release,
1221 nsDOMEventListener_HandleEvent
1224 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1226 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1227 nsIIDRef riid, nsQIResult result)
1229 NSContainer *This = NSIFACEREQ_THIS(iface);
1230 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1233 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1235 NSContainer *This = NSIFACEREQ_THIS(iface);
1236 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1239 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1241 NSContainer *This = NSIFACEREQ_THIS(iface);
1242 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1245 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1246 nsIIDRef riid, nsQIResult result)
1248 NSContainer *This = NSIFACEREQ_THIS(iface);
1250 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1251 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1252 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1255 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1258 #undef NSIFACEREQ_THIS
1260 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1261 nsInterfaceRequestor_QueryInterface,
1262 nsInterfaceRequestor_AddRef,
1263 nsInterfaceRequestor_Release,
1264 nsInterfaceRequestor_GetInterface
1267 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1269 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1270 nsIIDRef riid, nsQIResult result)
1272 NSContainer *This = NSWEAKREF_THIS(iface);
1273 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1276 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1278 NSContainer *This = NSWEAKREF_THIS(iface);
1279 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1282 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1284 NSContainer *This = NSWEAKREF_THIS(iface);
1285 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1288 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1289 const nsIID *riid, void **result)
1291 NSContainer *This = NSWEAKREF_THIS(iface);
1292 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1295 #undef NSWEAKREF_THIS
1297 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1298 nsWeakReference_QueryInterface,
1299 nsWeakReference_AddRef,
1300 nsWeakReference_Release,
1301 nsWeakReference_QueryReferent
1304 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1306 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1307 nsIIDRef riid, nsQIResult result)
1309 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1310 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1313 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1315 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1316 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1319 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1321 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1322 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1325 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1326 nsIWeakReference **_retval)
1328 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1330 TRACE("(%p)->(%p)\n", This, _retval);
1332 nsIWeakReference_AddRef(NSWEAKREF(This));
1333 *_retval = NSWEAKREF(This);
1337 #undef NSWEAKREF_THIS
1339 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1340 nsSupportsWeakReference_QueryInterface,
1341 nsSupportsWeakReference_AddRef,
1342 nsSupportsWeakReference_Release,
1343 nsSupportsWeakReference_GetWeakReference
1347 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1349 nsIDOMWindow *dom_window;
1350 nsIWebBrowserSetup *wbsetup;
1357 ret = mshtml_alloc(sizeof(NSContainer));
1359 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1360 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1361 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1362 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1363 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1364 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1365 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1366 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1367 ret->lpDOMEventListenerVtbl = &nsDOMEventListenerVtbl;
1371 ret->bscallback = NULL;
1372 ret->content_listener = NULL;
1375 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1376 ret->parent = parent;
1378 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1379 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1380 if(NS_FAILED(nsres))
1381 ERR("Creating WebBrowser failed: %08x\n", nsres);
1383 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1384 if(NS_FAILED(nsres))
1385 ERR("SetContainerWindow failed: %08x\n", nsres);
1387 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1388 (void**)&ret->window);
1389 if(NS_FAILED(nsres))
1390 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1392 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1394 if(NS_SUCCEEDED(nsres)) {
1395 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1396 nsIWebBrowserSetup_Release(wbsetup);
1397 if(NS_FAILED(nsres))
1398 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1400 ERR("Could not get nsIWebBrowserSetup interface\n");
1403 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1404 (void**)&ret->navigation);
1405 if(NS_FAILED(nsres))
1406 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1408 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1409 (void**)&ret->focus);
1410 if(NS_FAILED(nsres))
1411 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1413 if(!nscontainer_class)
1414 register_nscontainer_class();
1416 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1417 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1418 GetDesktopWindow(), NULL, hInst, ret);
1420 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1421 if(NS_SUCCEEDED(nsres)) {
1422 nsres = nsIBaseWindow_Create(ret->window);
1423 if(NS_FAILED(nsres))
1424 WARN("Creating window failed: %08x\n", nsres);
1426 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1427 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1429 ERR("InitWindow failed: %08x\n", nsres);
1432 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1433 if(NS_FAILED(nsres))
1434 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1436 nsres = nsIWebBrowser_GetContentDOMWindow(ret->webbrowser, &dom_window);
1437 if(NS_SUCCEEDED(nsres)) {
1438 nsIDOMEventTarget *target;
1439 nsres = nsIDOMWindow_QueryInterface(dom_window, &IID_nsIDOMEventTarget, (void**)&target);
1440 nsIDOMWindow_Release(dom_window);
1441 if(NS_SUCCEEDED(nsres)) {
1442 nsAString keypress_str;
1443 static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
1444 nsAString_Init(&keypress_str, wsz_keypress);
1445 nsres = nsIDOMEventTarget_AddEventListener(target, &keypress_str, NSEVENTLIST(ret), TRUE);
1446 nsAString_Finish(&keypress_str);
1447 nsIDOMEventTarget_Release(target);
1448 if(NS_FAILED(nsres))
1449 ERR("AddEventTarget failed: %08x\n", nsres);
1451 ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
1454 ERR("GetContentDOMWindow failed: %08x\n", nsres);
1460 void NSContainer_Release(NSContainer *This)
1462 TRACE("(%p)\n", This);
1464 ShowWindow(This->hwnd, SW_HIDE);
1465 SetParent(This->hwnd, NULL);
1467 nsIBaseWindow_SetVisibility(This->window, FALSE);
1468 nsIBaseWindow_Destroy(This->window);
1470 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1472 nsIWebBrowser_Release(This->webbrowser);
1473 This->webbrowser = NULL;
1475 nsIWebNavigation_Release(This->navigation);
1476 This->navigation = NULL;
1478 nsIBaseWindow_Release(This->window);
1479 This->window = NULL;
1481 nsIWebBrowserFocus_Release(This->focus);
1484 if(This->content_listener) {
1485 nsIURIContentListener_Release(This->content_listener);
1486 This->content_listener = NULL;
1490 DestroyWindow(This->hwnd);
1494 nsIWebBrowserChrome_Release(NSWBCHROME(This));