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 BOOL load_mozilla(PRUnichar *gre_path)
170 DWORD res, type, i, size = MAX_PATH;
171 HKEY mozilla_key, hkey;
175 static const WCHAR wszGreKey[] =
176 {'S','o','f','t','w','a','r','e','\\',
177 'm','o','z','i','l','l','a','.','o','r','g','\\',
180 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
182 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
183 if(res != ERROR_SUCCESS) {
184 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
188 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
189 RegOpenKeyW(mozilla_key, key_name, &hkey);
190 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
191 if(res == ERROR_SUCCESS)
196 RegCloseKey(mozilla_key);
197 return ret ? load_xpcom(gre_path) : FALSE;
200 static BOOL load_mozctl(PRUnichar *gre_path)
203 DWORD res, type, size = MAX_PATH;
205 static const WCHAR wszMozCtlKey[] =
206 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
207 static const WCHAR wszBinDirectoryPath[] =
208 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
209 static const WCHAR wszMozCtlClsidKey[] =
210 {'C','L','S','I','D','\\',
211 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
212 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
213 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
215 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
216 if(res == ERROR_SUCCESS) {
217 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
218 if(res == ERROR_SUCCESS)
219 return load_xpcom(gre_path);
221 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
224 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
225 if(res == ERROR_SUCCESS) {
226 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
227 if(res == ERROR_SUCCESS) {
229 if((ptr = strrchrW(gre_path, '\\')))
231 return load_xpcom(gre_path);
233 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
237 TRACE("Could not find Mozilla ActiveX Control\n");
242 static void check_version(LPCWSTR gre_path)
244 WCHAR file_name[MAX_PATH];
249 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
251 strcpyW(file_name, gre_path);
252 strcatW(file_name, wszVersion);
254 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
255 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
256 if(hfile == INVALID_HANDLE_VALUE) {
257 TRACE("unknown version\n");
261 ReadFile(hfile, version, sizeof(version), &read, NULL);
264 TRACE("%s\n", debugstr_a(version));
269 static BOOL load_wine_gecko(PRUnichar *gre_path)
272 DWORD res, type, size = MAX_PATH;
274 static const WCHAR wszMshtmlKey[] = {
275 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
276 '\\','M','S','H','T','M','L',0};
277 static const WCHAR wszGeckoPath[] =
278 {'G','e','c','k','o','P','a','t','h',0};
280 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
281 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
282 if(res != ERROR_SUCCESS)
285 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
286 if(res != ERROR_SUCCESS || type != REG_SZ)
290 check_version(gre_path);
292 return load_xpcom(gre_path);
295 static void set_profile(void)
298 PRBool exists = FALSE;
301 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
303 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
304 &IID_nsIProfile, (void**)&profile);
305 if(NS_FAILED(nsres)) {
306 ERR("Could not get profile service: %08x\n", nsres);
310 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
312 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
314 ERR("CreateNewProfile failed: %08x\n", nsres);
317 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
319 ERR("SetCurrentProfile failed: %08x\n", nsres);
321 nsIProfile_Release(profile);
324 static BOOL load_gecko(void)
327 nsIObserver *pStartNotif;
328 nsIComponentRegistrar *registrar = NULL;
331 PRUnichar gre_path[MAX_PATH];
333 static BOOL tried_load = FALSE;
338 return pCompMgr != NULL;
341 if(!load_wine_gecko(gre_path) && !load_mozctl(gre_path) && !load_mozilla(gre_path)) {
342 install_wine_gecko();
343 if(!load_wine_gecko(gre_path)) {
344 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
349 nsAString_Init(&path, gre_path);
350 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
351 nsAString_Finish(&path);
352 if(NS_FAILED(nsres)) {
353 ERR("NS_NewLocalFile failed: %08x\n", nsres);
358 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
359 if(NS_FAILED(nsres)) {
360 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
365 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
367 ERR("Could not get nsIComponentManager: %08x\n", nsres);
369 nsres = NS_GetComponentRegistrar(®istrar);
370 if(NS_SUCCEEDED(nsres)) {
371 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
373 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
375 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
377 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
379 init_nsio(pCompMgr, registrar);
381 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
384 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
385 NULL, &IID_nsIObserver, (void**)&pStartNotif);
386 if(NS_SUCCEEDED(nsres)) {
387 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
389 ERR("Observe failed: %08x\n", nsres);
391 nsIObserver_Release(pStartNotif);
393 ERR("could not get appstartup-notifier: %08x\n", nsres);
398 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
399 NULL, &IID_nsIMemory, (void**)&nsmem);
401 ERR("Could not get nsIMemory: %08x\n", nsres);
404 register_nsservice(registrar, pServMgr);
405 nsIComponentRegistrar_Release(registrar);
411 void *nsalloc(size_t size)
413 return nsIMemory_Alloc(nsmem, size);
416 void nsfree(void *mem)
418 nsIMemory_Free(nsmem, mem);
421 void nsACString_Init(nsACString *str, const char *data)
423 NS_CStringContainerInit(str);
425 NS_CStringSetData(str, data, PR_UINT32_MAX);
428 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
430 return NS_CStringGetData(str, data, termited);
433 void nsACString_Finish(nsACString *str)
435 NS_CStringContainerFinish(str);
438 void nsAString_Init(nsAString *str, const PRUnichar *data)
440 NS_StringContainerInit(str);
442 NS_StringSetData(str, data, PR_UINT32_MAX);
445 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
447 return NS_StringGetData(str, data, termited);
450 void nsAString_Finish(nsAString *str)
452 NS_StringContainerFinish(str);
455 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
457 nsIStringInputStream *ret;
463 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
464 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
466 if(NS_FAILED(nsres)) {
467 ERR("Could not get nsIStringInputStream\n");
471 nsres = nsIStringInputStream_SetData(ret, data, data_len);
472 if(NS_FAILED(nsres)) {
473 ERR("AdoptData failed: %08x\n", nsres);
474 nsIStringInputStream_Release(ret);
478 return (nsIInputStream*)ret;
481 nsICommandParams *create_nscommand_params(void)
483 nsICommandParams *ret = NULL;
489 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
490 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
493 ERR("Could not get nsICommandParams\n");
498 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
500 nsIDOMNodeList *node_list = NULL;
501 PRBool has_children = FALSE;
505 nsIDOMNode_HasChildNodes(nsnode, &has_children);
507 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
508 if(NS_FAILED(nsres)) {
509 ERR("GetType failed: %08x\n", nsres);
515 nsIDOMElement *nselem;
516 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
517 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
518 nsIDOMElement_Release(nselem);
523 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
524 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
525 nsIDOMText_Release(nstext);
528 case DOCUMENT_NODE: {
529 nsIDOMDocument *nsdoc;
530 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
531 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
532 nsIDOMDocument_Release(nsdoc);
536 FIXME("Unhandled type %u\n", type);
540 PRUint32 child_cnt, i;
541 nsIDOMNode *child_node;
543 nsIDOMNode_GetChildNodes(nsnode, &node_list);
544 nsIDOMNodeList_GetLength(node_list, &child_cnt);
546 for(i=0; i<child_cnt; i++) {
547 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
548 if(NS_SUCCEEDED(nsres)) {
549 nsnode_to_nsstring_rec(serializer, child_node, str);
550 nsIDOMNode_Release(child_node);
552 ERR("Item failed: %08x\n", nsres);
556 nsIDOMNodeList_Release(node_list);
559 if(type == ELEMENT_NODE) {
560 nsIDOMElement *nselem;
561 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
562 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
563 nsIDOMElement_Release(nselem);
567 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
569 nsIContentSerializer *serializer;
573 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
574 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
575 (void**)&serializer);
576 if(NS_FAILED(nsres)) {
577 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
581 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
583 ERR("Init failed: %08x\n", nsres);
585 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
586 nsnode_to_nsstring_rec(serializer, nsnode, str);
587 nsIDOMNode_Release(nsnode);
589 nsres = nsIContentSerializer_Flush(serializer, str);
591 ERR("Flush failed: %08x\n", nsres);
593 nsIContentSerializer_Release(serializer);
601 nsIComponentManager_Release(pCompMgr);
604 nsIServiceManager_Release(pServMgr);
607 nsIMemory_Release(nsmem);
613 /**********************************************************
614 * nsIWebBrowserChrome interface
617 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
619 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
620 nsIIDRef riid, nsQIResult result)
622 NSContainer *This = NSWBCHROME_THIS(iface);
625 if(IsEqualGUID(&IID_nsISupports, riid)) {
626 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
627 *result = NSWBCHROME(This);
628 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
629 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
630 *result = NSWBCHROME(This);
631 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
632 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
633 *result = NSCML(This);
634 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
635 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
636 *result = NSURICL(This);
637 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
638 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
639 *result = NSEMBWNDS(This);
640 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
641 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
642 *result = NSTOOLTIP(This);
643 }else if(IsEqualGUID(&IID_nsIDOMEventListener, riid)) {
644 TRACE("(%p)->(IID_nsIDOMEventListener %p)\n", This, result);
645 *result = NSEVENTLIST(This);
646 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
647 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
648 *result = NSIFACEREQ(This);
649 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
650 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
651 *result = NSWEAKREF(This);
652 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
653 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
654 *result = NSSUPWEAKREF(This);
658 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
662 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
663 return NS_NOINTERFACE;
666 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
668 NSContainer *This = NSWBCHROME_THIS(iface);
669 LONG ref = InterlockedIncrement(&This->ref);
671 TRACE("(%p) ref=%d\n", This, ref);
676 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
678 NSContainer *This = NSWBCHROME_THIS(iface);
679 LONG ref = InterlockedDecrement(&This->ref);
681 TRACE("(%p) ref=%d\n", This, ref);
685 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
692 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
693 PRUint32 statusType, const PRUnichar *status)
695 NSContainer *This = NSWBCHROME_THIS(iface);
696 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
697 return NS_ERROR_NOT_IMPLEMENTED;
700 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
701 nsIWebBrowser **aWebBrowser)
703 NSContainer *This = NSWBCHROME_THIS(iface);
705 TRACE("(%p)->(%p)\n", This, aWebBrowser);
708 return NS_ERROR_INVALID_ARG;
711 nsIWebBrowser_AddRef(This->webbrowser);
712 *aWebBrowser = This->webbrowser;
716 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
717 nsIWebBrowser *aWebBrowser)
719 NSContainer *This = NSWBCHROME_THIS(iface);
721 TRACE("(%p)->(%p)\n", This, aWebBrowser);
723 if(aWebBrowser != This->webbrowser)
724 ERR("Wrong nsWebBrowser!\n");
729 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
730 PRUint32 *aChromeFlags)
732 NSContainer *This = NSWBCHROME_THIS(iface);
733 WARN("(%p)->(%p)\n", This, aChromeFlags);
734 return NS_ERROR_NOT_IMPLEMENTED;
737 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
738 PRUint32 aChromeFlags)
740 NSContainer *This = NSWBCHROME_THIS(iface);
741 WARN("(%p)->(%08x)\n", This, aChromeFlags);
742 return NS_ERROR_NOT_IMPLEMENTED;
745 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
747 NSContainer *This = NSWBCHROME_THIS(iface);
748 TRACE("(%p)\n", This);
749 return NS_ERROR_NOT_IMPLEMENTED;
752 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
753 PRInt32 aCX, PRInt32 aCY)
755 NSContainer *This = NSWBCHROME_THIS(iface);
756 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
757 return NS_ERROR_NOT_IMPLEMENTED;
760 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
762 NSContainer *This = NSWBCHROME_THIS(iface);
763 WARN("(%p)\n", This);
764 return NS_ERROR_NOT_IMPLEMENTED;
767 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
769 NSContainer *This = NSWBCHROME_THIS(iface);
770 WARN("(%p)->(%p)\n", This, _retval);
771 return NS_ERROR_NOT_IMPLEMENTED;
774 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
777 NSContainer *This = NSWBCHROME_THIS(iface);
778 WARN("(%p)->(%08x)\n", This, aStatus);
779 return NS_ERROR_NOT_IMPLEMENTED;
782 #undef NSWBCHROME_THIS
784 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
785 nsWebBrowserChrome_QueryInterface,
786 nsWebBrowserChrome_AddRef,
787 nsWebBrowserChrome_Release,
788 nsWebBrowserChrome_SetStatus,
789 nsWebBrowserChrome_GetWebBrowser,
790 nsWebBrowserChrome_SetWebBrowser,
791 nsWebBrowserChrome_GetChromeFlags,
792 nsWebBrowserChrome_SetChromeFlags,
793 nsWebBrowserChrome_DestroyBrowserWindow,
794 nsWebBrowserChrome_SizeBrowserTo,
795 nsWebBrowserChrome_ShowAsModal,
796 nsWebBrowserChrome_IsWindowModal,
797 nsWebBrowserChrome_ExitModalEventLoop
800 /**********************************************************
801 * nsIContextMenuListener interface
804 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
806 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
807 nsIIDRef riid, nsQIResult result)
809 NSContainer *This = NSCML_THIS(iface);
810 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
813 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
815 NSContainer *This = NSCML_THIS(iface);
816 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
819 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
821 NSContainer *This = NSCML_THIS(iface);
822 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
825 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
826 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
828 NSContainer *This = NSCML_THIS(iface);
829 nsIDOMMouseEvent *event;
831 DWORD dwID = CONTEXT_MENU_DEFAULT;
834 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
836 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
837 if(NS_FAILED(nsres)) {
838 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
842 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
843 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
844 nsIDOMMouseEvent_Release(event);
846 switch(aContextFlags) {
848 case CONTEXT_DOCUMENT:
850 dwID = CONTEXT_MENU_DEFAULT;
853 case CONTEXT_IMAGE|CONTEXT_LINK:
854 dwID = CONTEXT_MENU_IMAGE;
857 dwID = CONTEXT_MENU_ANCHOR;
860 dwID = CONTEXT_MENU_CONTROL;
863 FIXME("aContextFlags=%08x\n", aContextFlags);
866 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
873 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
874 nsContextMenuListener_QueryInterface,
875 nsContextMenuListener_AddRef,
876 nsContextMenuListener_Release,
877 nsContextMenuListener_OnShowContextMenu
880 /**********************************************************
881 * nsIURIContentListener interface
884 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
886 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
887 nsIIDRef riid, nsQIResult result)
889 NSContainer *This = NSURICL_THIS(iface);
890 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
893 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
895 NSContainer *This = NSURICL_THIS(iface);
896 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
899 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
901 NSContainer *This = NSURICL_THIS(iface);
902 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
905 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
906 nsIURI *aURI, PRBool *_retval)
908 NSContainer *This = NSURICL_THIS(iface);
909 nsIWineURI *wine_uri;
914 nsACString_Init(&spec_str, NULL);
915 nsIURI_GetSpec(aURI, &spec_str);
916 nsACString_GetData(&spec_str, &spec, NULL);
918 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
920 nsACString_Finish(&spec_str);
922 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
923 if(NS_FAILED(nsres)) {
924 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
925 return NS_ERROR_NOT_IMPLEMENTED;
928 nsIWineURI_SetNSContainer(wine_uri, This);
930 if(This->bscallback && This->bscallback->mon) {
934 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &url);
935 if(SUCCEEDED(hres)) {
936 IMoniker *mon = NULL;
938 hres = CreateURLMoniker(NULL, url, &mon);
939 if(SUCCEEDED(hres)) {
940 nsIWineURI_SetMoniker(wine_uri, mon);
941 IMoniker_Release(mon);
943 WARN("CreateURLMoniker failed: %08x\n", hres);
946 WARN("GetDisplayName failed: %08x\n", hres);
950 nsIWineURI_Release(wine_uri);
953 return This->content_listener
954 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
958 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
959 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
960 nsIStreamListener **aContentHandler, PRBool *_retval)
962 NSContainer *This = NSURICL_THIS(iface);
964 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
965 aRequest, aContentHandler, _retval);
967 return This->content_listener
968 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
969 aIsContentPreferred, aRequest, aContentHandler, _retval)
970 : NS_ERROR_NOT_IMPLEMENTED;
973 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
974 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
976 NSContainer *This = NSURICL_THIS(iface);
978 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
980 /* FIXME: Should we do something here? */
983 return This->content_listener
984 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
985 aDesiredContentType, _retval)
989 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
990 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
993 NSContainer *This = NSURICL_THIS(iface);
995 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
996 aDesiredContentType, _retval);
998 return This->content_listener
999 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1000 aIsContentPreferred, aDesiredContentType, _retval)
1001 : NS_ERROR_NOT_IMPLEMENTED;
1004 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1005 nsISupports **aLoadCookie)
1007 NSContainer *This = NSURICL_THIS(iface);
1009 WARN("(%p)->(%p)\n", This, aLoadCookie);
1011 return This->content_listener
1012 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1013 : NS_ERROR_NOT_IMPLEMENTED;
1016 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1017 nsISupports *aLoadCookie)
1019 NSContainer *This = NSURICL_THIS(iface);
1021 WARN("(%p)->(%p)\n", This, aLoadCookie);
1023 return This->content_listener
1024 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1025 : NS_ERROR_NOT_IMPLEMENTED;
1028 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1029 nsIURIContentListener **aParentContentListener)
1031 NSContainer *This = NSURICL_THIS(iface);
1033 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1035 if(This->content_listener)
1036 nsIURIContentListener_AddRef(This->content_listener);
1038 *aParentContentListener = This->content_listener;
1042 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1043 nsIURIContentListener *aParentContentListener)
1045 NSContainer *This = NSURICL_THIS(iface);
1047 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1049 if(aParentContentListener == NSURICL(This))
1052 if(This->content_listener)
1053 nsIURIContentListener_Release(This->content_listener);
1055 This->content_listener = aParentContentListener;
1056 if(This->content_listener)
1057 nsIURIContentListener_AddRef(This->content_listener);
1064 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1065 nsURIContentListener_QueryInterface,
1066 nsURIContentListener_AddRef,
1067 nsURIContentListener_Release,
1068 nsURIContentListener_OnStartURIOpen,
1069 nsURIContentListener_DoContent,
1070 nsURIContentListener_IsPreferred,
1071 nsURIContentListener_CanHandleContent,
1072 nsURIContentListener_GetLoadCookie,
1073 nsURIContentListener_SetLoadCookie,
1074 nsURIContentListener_GetParentContentListener,
1075 nsURIContentListener_SetParentContentListener
1078 /**********************************************************
1079 * nsIEmbeddinSiteWindow interface
1082 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1084 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1085 nsIIDRef riid, nsQIResult result)
1087 NSContainer *This = NSEMBWNDS_THIS(iface);
1088 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1091 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1093 NSContainer *This = NSEMBWNDS_THIS(iface);
1094 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1097 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1099 NSContainer *This = NSEMBWNDS_THIS(iface);
1100 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1103 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1104 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1106 NSContainer *This = NSEMBWNDS_THIS(iface);
1107 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1108 return NS_ERROR_NOT_IMPLEMENTED;
1111 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1112 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1114 NSContainer *This = NSEMBWNDS_THIS(iface);
1115 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1116 return NS_ERROR_NOT_IMPLEMENTED;
1119 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1121 NSContainer *This = NSEMBWNDS_THIS(iface);
1122 WARN("(%p)\n", This);
1123 return NS_ERROR_NOT_IMPLEMENTED;
1126 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1127 PRBool *aVisibility)
1129 NSContainer *This = NSEMBWNDS_THIS(iface);
1130 WARN("(%p)->(%p)\n", This, aVisibility);
1131 return NS_ERROR_NOT_IMPLEMENTED;
1134 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1137 NSContainer *This = NSEMBWNDS_THIS(iface);
1138 WARN("(%p)->(%x)\n", This, aVisibility);
1139 return NS_ERROR_NOT_IMPLEMENTED;
1142 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1145 NSContainer *This = NSEMBWNDS_THIS(iface);
1146 WARN("(%p)->(%p)\n", This, aTitle);
1147 return NS_ERROR_NOT_IMPLEMENTED;
1150 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1151 const PRUnichar *aTitle)
1153 NSContainer *This = NSEMBWNDS_THIS(iface);
1154 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1155 return NS_ERROR_NOT_IMPLEMENTED;
1158 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1161 NSContainer *This = NSEMBWNDS_THIS(iface);
1163 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1165 *aSiteWindow = This->hwnd;
1169 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1170 nsEmbeddingSiteWindow_QueryInterface,
1171 nsEmbeddingSiteWindow_AddRef,
1172 nsEmbeddingSiteWindow_Release,
1173 nsEmbeddingSiteWindow_SetDimensions,
1174 nsEmbeddingSiteWindow_GetDimensions,
1175 nsEmbeddingSiteWindow_SetFocus,
1176 nsEmbeddingSiteWindow_GetVisibility,
1177 nsEmbeddingSiteWindow_SetVisibility,
1178 nsEmbeddingSiteWindow_GetTitle,
1179 nsEmbeddingSiteWindow_SetTitle,
1180 nsEmbeddingSiteWindow_GetSiteWindow
1183 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1185 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1188 NSContainer *This = NSTOOLTIP_THIS(iface);
1189 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1192 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1194 NSContainer *This = NSTOOLTIP_THIS(iface);
1195 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1198 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1200 NSContainer *This = NSTOOLTIP_THIS(iface);
1201 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1204 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1205 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1207 NSContainer *This = NSTOOLTIP_THIS(iface);
1209 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1214 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1216 NSContainer *This = NSTOOLTIP_THIS(iface);
1218 hide_tooltip(This->doc);
1223 #undef NSTOOLTIM_THIS
1225 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1226 nsTooltipListener_QueryInterface,
1227 nsTooltipListener_AddRef,
1228 nsTooltipListener_Release,
1229 nsTooltipListener_OnShowTooltip,
1230 nsTooltipListener_OnHideTooltip
1233 #define NSEVENTLIST_THIS(iface) DEFINE_THIS(NSContainer, DOMEventListener, iface)
1235 static nsresult NSAPI nsDOMEventListener_QueryInterface(nsIDOMEventListener *iface,
1236 nsIIDRef riid, nsQIResult result)
1238 NSContainer *This = NSEVENTLIST_THIS(iface);
1239 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1242 static nsrefcnt NSAPI nsDOMEventListener_AddRef(nsIDOMEventListener *iface)
1244 NSContainer *This = NSEVENTLIST_THIS(iface);
1245 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1248 static nsrefcnt NSAPI nsDOMEventListener_Release(nsIDOMEventListener *iface)
1250 NSContainer *This = NSEVENTLIST_THIS(iface);
1251 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1254 static nsresult NSAPI nsDOMEventListener_HandleEvent(nsIDOMEventListener *iface, nsIDOMEvent *event)
1256 NSContainer *This = NSEVENTLIST_THIS(iface);
1258 TRACE("(%p)->(%p)\n", This, event);
1260 if(This->doc->usermode == EDITMODE)
1261 handle_edit_event(This->doc, event);
1266 #undef NSEVENTLIST_THIS
1268 static const nsIDOMEventListenerVtbl nsDOMEventListenerVtbl = {
1269 nsDOMEventListener_QueryInterface,
1270 nsDOMEventListener_AddRef,
1271 nsDOMEventListener_Release,
1272 nsDOMEventListener_HandleEvent
1275 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1277 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1278 nsIIDRef riid, nsQIResult result)
1280 NSContainer *This = NSIFACEREQ_THIS(iface);
1281 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1284 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1286 NSContainer *This = NSIFACEREQ_THIS(iface);
1287 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1290 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1292 NSContainer *This = NSIFACEREQ_THIS(iface);
1293 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1296 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1297 nsIIDRef riid, nsQIResult result)
1299 NSContainer *This = NSIFACEREQ_THIS(iface);
1301 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1302 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1303 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1306 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1309 #undef NSIFACEREQ_THIS
1311 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1312 nsInterfaceRequestor_QueryInterface,
1313 nsInterfaceRequestor_AddRef,
1314 nsInterfaceRequestor_Release,
1315 nsInterfaceRequestor_GetInterface
1318 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1320 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1321 nsIIDRef riid, nsQIResult result)
1323 NSContainer *This = NSWEAKREF_THIS(iface);
1324 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1327 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1329 NSContainer *This = NSWEAKREF_THIS(iface);
1330 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1333 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1335 NSContainer *This = NSWEAKREF_THIS(iface);
1336 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1339 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1340 const nsIID *riid, void **result)
1342 NSContainer *This = NSWEAKREF_THIS(iface);
1343 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1346 #undef NSWEAKREF_THIS
1348 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1349 nsWeakReference_QueryInterface,
1350 nsWeakReference_AddRef,
1351 nsWeakReference_Release,
1352 nsWeakReference_QueryReferent
1355 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1357 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1358 nsIIDRef riid, nsQIResult result)
1360 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1361 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1364 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1366 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1367 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1370 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1372 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1373 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1376 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1377 nsIWeakReference **_retval)
1379 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1381 TRACE("(%p)->(%p)\n", This, _retval);
1383 nsIWeakReference_AddRef(NSWEAKREF(This));
1384 *_retval = NSWEAKREF(This);
1388 #undef NSWEAKREF_THIS
1390 const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1391 nsSupportsWeakReference_QueryInterface,
1392 nsSupportsWeakReference_AddRef,
1393 nsSupportsWeakReference_Release,
1394 nsSupportsWeakReference_GetWeakReference
1398 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1400 nsIDOMWindow *dom_window;
1401 nsIWebBrowserSetup *wbsetup;
1408 ret = mshtml_alloc(sizeof(NSContainer));
1410 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1411 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1412 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1413 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1414 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1415 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1416 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1417 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1418 ret->lpDOMEventListenerVtbl = &nsDOMEventListenerVtbl;
1422 ret->bscallback = NULL;
1423 ret->content_listener = NULL;
1426 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1427 ret->parent = parent;
1429 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1430 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1431 if(NS_FAILED(nsres))
1432 ERR("Creating WebBrowser failed: %08x\n", nsres);
1434 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1435 if(NS_FAILED(nsres))
1436 ERR("SetContainerWindow failed: %08x\n", nsres);
1438 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1439 (void**)&ret->window);
1440 if(NS_FAILED(nsres))
1441 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1443 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1445 if(NS_SUCCEEDED(nsres)) {
1446 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1447 nsIWebBrowserSetup_Release(wbsetup);
1448 if(NS_FAILED(nsres))
1449 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1451 ERR("Could not get nsIWebBrowserSetup interface\n");
1454 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1455 (void**)&ret->navigation);
1456 if(NS_FAILED(nsres))
1457 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1459 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1460 (void**)&ret->focus);
1461 if(NS_FAILED(nsres))
1462 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1464 if(!nscontainer_class)
1465 register_nscontainer_class();
1467 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1468 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1469 GetDesktopWindow(), NULL, hInst, ret);
1471 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1472 if(NS_SUCCEEDED(nsres)) {
1473 nsres = nsIBaseWindow_Create(ret->window);
1474 if(NS_FAILED(nsres))
1475 WARN("Creating window failed: %08x\n", nsres);
1477 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1478 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1480 ERR("InitWindow failed: %08x\n", nsres);
1483 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1484 if(NS_FAILED(nsres))
1485 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1487 nsres = nsIWebBrowser_GetContentDOMWindow(ret->webbrowser, &dom_window);
1488 if(NS_SUCCEEDED(nsres)) {
1489 nsIDOMEventTarget *target;
1490 nsres = nsIDOMWindow_QueryInterface(dom_window, &IID_nsIDOMEventTarget, (void**)&target);
1491 nsIDOMWindow_Release(dom_window);
1492 if(NS_SUCCEEDED(nsres)) {
1493 nsAString keypress_str;
1494 static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
1495 nsAString_Init(&keypress_str, wsz_keypress);
1496 nsres = nsIDOMEventTarget_AddEventListener(target, &keypress_str, NSEVENTLIST(ret), TRUE);
1497 nsAString_Finish(&keypress_str);
1498 nsIDOMEventTarget_Release(target);
1499 if(NS_FAILED(nsres))
1500 ERR("AddEventTarget failed: %08x\n", nsres);
1502 ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
1505 ERR("GetContentDOMWindow failed: %08x\n", nsres);
1512 void NSContainer_Release(NSContainer *This)
1514 TRACE("(%p)\n", This);
1516 ShowWindow(This->hwnd, SW_HIDE);
1517 SetParent(This->hwnd, NULL);
1519 nsIBaseWindow_SetVisibility(This->window, FALSE);
1520 nsIBaseWindow_Destroy(This->window);
1522 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1524 nsIWebBrowser_Release(This->webbrowser);
1525 This->webbrowser = NULL;
1527 nsIWebNavigation_Release(This->navigation);
1528 This->navigation = NULL;
1530 nsIBaseWindow_Release(This->window);
1531 This->window = NULL;
1533 nsIWebBrowserFocus_Release(This->focus);
1536 if(This->content_listener) {
1537 nsIURIContentListener_Release(This->content_listener);
1538 This->content_listener = NULL;
1542 DestroyWindow(This->hwnd);
1546 nsIWebBrowserChrome_Release(NSWBCHROME(This));