mshtml: Get rid of (currently disabled anyway) nsIWebBrowserStream.
[wine] / dlls / mshtml / nsembed.c
1 /*
2  * Copyright 2005-2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "mshtml_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
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
44 #define APPSTARTUP_TOPIC "app-startup"
45
46 #define PR_UINT32_MAX 0xffffffff
47
48 struct nsCStringContainer {
49     void *v;
50     void *d1;
51     PRUint32 d2;
52     void *d3;
53 };
54
55 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
56 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
57 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
58 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
59 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
60 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
61 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
62 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
63 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
64 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
65 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
66 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
67
68 static HINSTANCE hXPCOM = NULL;
69
70 static nsIServiceManager *pServMgr = NULL;
71 static nsIComponentManager *pCompMgr = NULL;
72 static nsIMemory *nsmem = NULL;
73
74 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
75
76 static ATOM nscontainer_class;
77
78 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
79 {
80     NSContainer *This;
81     nsresult nsres;
82
83     static const WCHAR wszTHIS[] = {'T','H','I','S',0};
84
85     if(msg == WM_CREATE) {
86         This = *(NSContainer**)lParam;
87         SetPropW(hwnd, wszTHIS, This);
88     }else {
89         This = (NSContainer*)GetPropW(hwnd, wszTHIS);
90     }
91
92     switch(msg) {
93         case WM_SIZE:
94             TRACE("(%p)->(WM_SIZE)\n", This);
95
96             nsres = nsIBaseWindow_SetSize(This->window,
97                     LOWORD(lParam), HIWORD(lParam), TRUE);
98             if(NS_FAILED(nsres))
99                 WARN("SetSize failed: %08lx\n", nsres);
100     }
101
102     return DefWindowProcW(hwnd, msg, wParam, lParam);
103 }
104
105
106 static void register_nscontainer_class(void)
107 {
108     static WNDCLASSEXW wndclass = {
109         sizeof(WNDCLASSEXW),
110         CS_DBLCLKS,
111         nsembed_proc,
112         0, 0, NULL, NULL, NULL, NULL, NULL,
113         wszNsContainer,
114         NULL,
115     };
116     wndclass.hInstance = hInst;
117     nscontainer_class = RegisterClassExW(&wndclass);
118 }
119
120 static BOOL get_mozilla_path(PRUnichar *gre_path)
121 {
122     DWORD res, type, i, size = MAX_PATH;
123     HKEY mozilla_key, hkey;
124     WCHAR key_name[100];
125     BOOL ret = FALSE;
126
127     static const WCHAR wszGreKey[] =
128         {'S','o','f','t','w','a','r','e','\\',
129             'm','o','z','i','l','l','a','.','o','r','g','\\',
130                 'G','R','E',0};
131
132     static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
133
134     res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
135     if(res != ERROR_SUCCESS) {
136         TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
137         return FALSE;
138     }
139
140     for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
141         RegOpenKeyW(mozilla_key, key_name, &hkey);
142         res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
143         if(res == ERROR_SUCCESS)
144             ret = TRUE;
145         RegCloseKey(hkey);
146     }
147
148     RegCloseKey(mozilla_key);
149     return ret;
150 }
151
152 static BOOL get_mozctl_path(PRUnichar *gre_path)
153 {
154     HKEY hkey;
155     DWORD res, type, size = MAX_PATH;
156
157     static const WCHAR wszMozCtlKey[] =
158         {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
159     static const WCHAR wszBinDirectoryPath[] =
160         {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
161     static const WCHAR wszMozCtlClsidKey[] =
162         {'C','L','S','I','D','\\',
163          '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
164          '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
165          'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
166
167     res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
168     if(res == ERROR_SUCCESS) {
169         res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
170         if(res == ERROR_SUCCESS)
171             return TRUE;
172         else
173             ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
174     }
175
176     res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
177     if(res == ERROR_SUCCESS) {
178         res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
179         if(res == ERROR_SUCCESS) {
180             WCHAR *ptr;
181             if((ptr = strrchrW(gre_path, '\\')))
182                 ptr[1] = 0;
183             return TRUE;
184         }else {
185             ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
186         }
187     }
188
189     TRACE("Could not find Mozilla ActiveX Control\n");
190
191     return FALSE;
192 }
193
194 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
195 {
196     HKEY hkey;
197     DWORD res, type, size = MAX_PATH;
198
199     static const WCHAR wszMshtmlKey[] = {
200         'S','o','f','t','w','a','r','e','\\','W','i','n','e',
201         '\\','M','S','H','T','M','L',0};
202     static const WCHAR wszGeckoPath[] =
203         {'G','e','c','k','o','P','a','t','h',0};
204
205     /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
206     res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
207     if(res != ERROR_SUCCESS)
208         return FALSE;
209
210     res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
211     if(res != ERROR_SUCCESS || type != REG_SZ)
212         return FALSE;
213
214     return TRUE;
215 }
216
217 static void set_profile(void)
218 {
219     nsIProfile *profile;
220     PRBool exists = FALSE;
221     nsresult nsres;
222
223     static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
224
225     nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
226                                          &IID_nsIProfile, (void**)&profile);
227     if(NS_FAILED(nsres)) {
228         ERR("Could not get profile service: %08lx\n", nsres);
229         return;
230     }
231
232     nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
233     if(!exists) {
234         nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
235         if(NS_FAILED(nsres))
236             ERR("CreateNewProfile failed: %08lx\n", nsres);
237     }
238
239     nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
240     if(NS_FAILED(nsres))
241         ERR("SetCurrentProfile failed: %08lx\n", nsres);
242
243     nsIProfile_Release(profile);
244 }
245
246 static BOOL load_gecko(void)
247 {
248     nsresult nsres;
249     nsIObserver *pStartNotif;
250     nsIComponentRegistrar *registrar = NULL;
251     nsAString path;
252     nsIFile *gre_dir;
253     PRUnichar gre_path[MAX_PATH];
254     WCHAR path_env[MAX_PATH];
255     int len;
256
257     static BOOL tried_load = FALSE;
258     static const WCHAR wszPATH[] = {'P','A','T','H',0};
259     static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
260
261     TRACE("()\n");
262
263     if(tried_load)
264         return pCompMgr != NULL;
265     tried_load = TRUE;
266
267     if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
268        && !get_mozilla_path(gre_path)) {
269         MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
270         return FALSE;
271     }
272
273     TRACE("found path %s\n", debugstr_w(gre_path));
274
275     /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
276     GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
277     len = strlenW(path_env);
278     path_env[len++] = ';';
279     strcpyW(path_env+len, gre_path);
280     SetEnvironmentVariableW(wszPATH, path_env);
281
282     hXPCOM = LoadLibraryW(strXPCOM);
283     if(!hXPCOM) {
284         ERR("Could not load XPCOM: %ld\n", GetLastError());
285         return FALSE;
286     }
287
288 #define NS_DLSYM(func) \
289     func = (typeof(func))GetProcAddress(hXPCOM, #func); \
290     if(!func) \
291         ERR("Could not GetProcAddress(" #func ") failed\n")
292
293     NS_DLSYM(NS_InitXPCOM2);
294     NS_DLSYM(NS_ShutdownXPCOM);
295     NS_DLSYM(NS_GetComponentRegistrar);
296     NS_DLSYM(NS_StringContainerInit);
297     NS_DLSYM(NS_CStringContainerInit);
298     NS_DLSYM(NS_StringContainerFinish);
299     NS_DLSYM(NS_CStringContainerFinish);
300     NS_DLSYM(NS_StringSetData);
301     NS_DLSYM(NS_CStringSetData);
302     NS_DLSYM(NS_NewLocalFile);
303     NS_DLSYM(NS_StringGetData);
304     NS_DLSYM(NS_CStringGetData);
305
306 #undef NS_DLSYM
307
308     NS_StringContainerInit(&path);
309     NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
310     nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
311     NS_StringContainerFinish(&path);
312     if(NS_FAILED(nsres)) {
313         ERR("NS_NewLocalFile failed: %08lx\n", nsres);
314         FreeLibrary(hXPCOM);
315         return FALSE;
316     }
317
318     nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
319     if(NS_FAILED(nsres)) {
320         ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
321         FreeLibrary(hXPCOM);
322         return FALSE;
323     }
324
325     nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
326     if(NS_FAILED(nsres))
327         ERR("Could not get nsIComponentManager: %08lx\n", nsres);
328
329     nsres = NS_GetComponentRegistrar(&registrar);
330     if(NS_SUCCEEDED(nsres)) {
331         nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
332         if(NS_FAILED(nsres))
333             ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
334
335         nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
336         if(NS_FAILED(nsres))
337             ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
338
339         init_nsio(pCompMgr, registrar);
340     }else {
341         ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
342     }
343
344     nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
345             NULL, &IID_nsIObserver, (void**)&pStartNotif);
346     if(NS_SUCCEEDED(nsres)) {
347         nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
348         if(NS_FAILED(nsres))
349             ERR("Observe failed: %08lx\n", nsres);
350
351         nsIObserver_Release(pStartNotif);
352     }else {
353         ERR("could not get appstartup-notifier: %08lx\n", nsres);
354     }
355
356     set_profile();
357
358     nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
359             NULL, &IID_nsIMemory, (void**)&nsmem);
360     if(NS_FAILED(nsres))
361         ERR("Could not get nsIMemory: %08lx\n", nsres);
362
363     if(registrar) {
364         register_nsservice(registrar, pServMgr);
365         nsIComponentRegistrar_Release(registrar);
366     }
367
368     return TRUE;
369 }
370
371 void *nsalloc(size_t size)
372 {
373     return nsIMemory_Alloc(nsmem, size);
374 }
375
376 void nsfree(void *mem)
377 {
378     nsIMemory_Free(nsmem, mem);
379 }
380
381 void nsACString_Init(nsACString *str, const char *data)
382 {
383     NS_CStringContainerInit(str);
384     if(data)
385         NS_CStringSetData(str, data, PR_UINT32_MAX);
386 }
387
388 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
389 {
390     return NS_CStringGetData(str, data, termited);
391 }
392
393 void nsACString_Finish(nsACString *str)
394 {
395     NS_CStringContainerFinish(str);
396 }
397
398 void nsAString_Init(nsAString *str, const PRUnichar *data)
399 {
400     NS_StringContainerInit(str);
401     if(data)
402         NS_StringSetData(str, data, PR_UINT32_MAX);
403 }
404
405 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
406 {
407     return NS_StringGetData(str, data, termited);
408 }
409
410 void nsAString_Finish(nsAString *str)
411 {
412     NS_StringContainerFinish(str);
413 }
414
415 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
416 {
417     nsIStringInputStream *ret;
418     nsresult nsres;
419
420     if(!pCompMgr)
421         return NULL;
422
423     nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
424             NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
425             (void**)&ret);
426     if(NS_FAILED(nsres)) {
427         ERR("Could not get nsIStringInputStream\n");
428         return NULL;
429     }
430
431     nsres = nsIStringInputStream_SetData(ret, data, data_len);
432     if(NS_FAILED(nsres)) {
433         ERR("AdoptData failed: %08lx\n", nsres);
434         nsIStringInputStream_Release(ret);
435         return NULL;
436     }
437
438     return (nsIInputStream*)ret;
439 }
440
441 void close_gecko()
442 {
443     TRACE("()\n");
444
445     if(pCompMgr)
446         nsIComponentManager_Release(pCompMgr);
447
448     if(pServMgr)
449         nsIServiceManager_Release(pServMgr);
450
451     if(nsmem)
452         nsIMemory_Release(nsmem);
453
454     if(hXPCOM)
455         FreeLibrary(hXPCOM);
456 }
457
458 /**********************************************************
459  *      nsIWebBrowserChrome interface
460  */
461
462 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
463
464 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
465         nsIIDRef riid, nsQIResult result)
466 {
467     NSContainer *This = NSWBCHROME_THIS(iface);
468
469     *result = NULL;
470     if(IsEqualGUID(&IID_nsISupports, riid)) {
471         TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
472         *result = NSWBCHROME(This);
473     }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
474         TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
475         *result = NSWBCHROME(This);
476     }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
477         TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
478         *result = NSCML(This);
479     }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
480         TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
481         *result = NSURICL(This);
482     }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
483         TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
484         *result = NSEMBWNDS(This);
485     }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
486         TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
487         *result = NSTOOLTIP(This);
488     }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
489         TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
490         *result = NSIFACEREQ(This);
491     }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
492         TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
493         *result = NSWEAKREF(This);
494     }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
495         TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
496         *result = NSSUPWEAKREF(This);
497     }
498
499     if(*result) {
500         nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
501         return NS_OK;
502     }
503
504     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
505     return NS_NOINTERFACE;
506 }
507
508 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
509 {
510     NSContainer *This = NSWBCHROME_THIS(iface);
511     LONG ref = InterlockedIncrement(&This->ref);
512
513     TRACE("(%p) ref=%ld\n", This, ref);
514
515     return ref;
516 }
517
518 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
519 {
520     NSContainer *This = NSWBCHROME_THIS(iface);
521     LONG ref = InterlockedDecrement(&This->ref);
522
523     TRACE("(%p) ref=%ld\n", This, ref);
524
525     if(!ref) {
526         if(This->parent)
527             nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
528         HeapFree(GetProcessHeap(), 0, This);
529     }
530
531     return ref;
532 }
533
534 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
535         PRUint32 statusType, const PRUnichar *status)
536 {
537     NSContainer *This = NSWBCHROME_THIS(iface);
538     TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
539     return NS_ERROR_NOT_IMPLEMENTED;
540 }
541
542 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
543         nsIWebBrowser **aWebBrowser)
544 {
545     NSContainer *This = NSWBCHROME_THIS(iface);
546
547     TRACE("(%p)->(%p)\n", This, aWebBrowser);
548
549     if(!aWebBrowser)
550         return NS_ERROR_INVALID_ARG;
551
552     if(This->webbrowser)
553         nsIWebBrowser_AddRef(This->webbrowser);
554     *aWebBrowser = This->webbrowser;
555     return S_OK;
556 }
557
558 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
559         nsIWebBrowser *aWebBrowser)
560 {
561     NSContainer *This = NSWBCHROME_THIS(iface);
562
563     TRACE("(%p)->(%p)\n", This, aWebBrowser);
564
565     if(aWebBrowser != This->webbrowser)
566         ERR("Wrong nsWebBrowser!\n");
567
568     return NS_OK;
569 }
570
571 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
572         PRUint32 *aChromeFlags)
573 {
574     NSContainer *This = NSWBCHROME_THIS(iface);
575     WARN("(%p)->(%p)\n", This, aChromeFlags);
576     return NS_ERROR_NOT_IMPLEMENTED;
577 }
578
579 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
580         PRUint32 aChromeFlags)
581 {
582     NSContainer *This = NSWBCHROME_THIS(iface);
583     WARN("(%p)->(%08lx)\n", This, aChromeFlags);
584     return NS_ERROR_NOT_IMPLEMENTED;
585 }
586
587 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
588 {
589     NSContainer *This = NSWBCHROME_THIS(iface);
590     TRACE("(%p)\n", This);
591     return NS_ERROR_NOT_IMPLEMENTED;
592 }
593
594 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
595         PRInt32 aCX, PRInt32 aCY)
596 {
597     NSContainer *This = NSWBCHROME_THIS(iface);
598     WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
599     return NS_ERROR_NOT_IMPLEMENTED;
600 }
601
602 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
603 {
604     NSContainer *This = NSWBCHROME_THIS(iface);
605     WARN("(%p)\n", This);
606     return NS_ERROR_NOT_IMPLEMENTED;
607 }
608
609 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
610 {
611     NSContainer *This = NSWBCHROME_THIS(iface);
612     WARN("(%p)->(%p)\n", This, _retval);
613     return NS_ERROR_NOT_IMPLEMENTED;
614 }
615
616 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
617         nsresult aStatus)
618 {
619     NSContainer *This = NSWBCHROME_THIS(iface);
620     WARN("(%p)->(%08lx)\n", This, aStatus);
621     return NS_ERROR_NOT_IMPLEMENTED;
622 }
623
624 #undef NSWBCHROME_THIS
625
626 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
627     nsWebBrowserChrome_QueryInterface,
628     nsWebBrowserChrome_AddRef,
629     nsWebBrowserChrome_Release,
630     nsWebBrowserChrome_SetStatus,
631     nsWebBrowserChrome_GetWebBrowser,
632     nsWebBrowserChrome_SetWebBrowser,
633     nsWebBrowserChrome_GetChromeFlags,
634     nsWebBrowserChrome_SetChromeFlags,
635     nsWebBrowserChrome_DestroyBrowserWindow,
636     nsWebBrowserChrome_SizeBrowserTo,
637     nsWebBrowserChrome_ShowAsModal,
638     nsWebBrowserChrome_IsWindowModal,
639     nsWebBrowserChrome_ExitModalEventLoop
640 };
641
642 /**********************************************************
643  *      nsIContextMenuListener interface
644  */
645
646 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
647
648 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
649         nsIIDRef riid, nsQIResult result)
650 {
651     NSContainer *This = NSCML_THIS(iface);
652     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
653 }
654
655 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
656 {
657     NSContainer *This = NSCML_THIS(iface);
658     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
659 }
660
661 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
662 {
663     NSContainer *This = NSCML_THIS(iface);
664     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
665 }
666
667 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
668         PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
669 {
670     NSContainer *This = NSCML_THIS(iface);
671     nsIDOMMouseEvent *event;
672     POINT pt;
673     DWORD dwID = CONTEXT_MENU_DEFAULT;
674     nsresult nsres;
675
676     TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
677
678     nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
679     if(NS_FAILED(nsres)) {
680         ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
681         return nsres;
682     }
683
684     nsIDOMMouseEvent_GetScreenX(event, &pt.x);
685     nsIDOMMouseEvent_GetScreenY(event, &pt.y);
686     nsIDOMMouseEvent_Release(event);
687
688     switch(aContextFlags) {
689     case CONTEXT_NONE:
690     case CONTEXT_DOCUMENT:
691     case CONTEXT_TEXT:
692         dwID = CONTEXT_MENU_DEFAULT;
693         break;
694     case CONTEXT_IMAGE:
695     case CONTEXT_IMAGE|CONTEXT_LINK:
696         dwID = CONTEXT_MENU_IMAGE;
697         break;
698     case CONTEXT_LINK:
699         dwID = CONTEXT_MENU_ANCHOR;
700         break;
701     case CONTEXT_INPUT:
702         dwID = CONTEXT_MENU_CONTROL;
703         break;
704     default:
705         FIXME("aContextFlags=%08lx\n", aContextFlags);
706     };
707
708     HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
709
710     return NS_OK;
711 }
712
713 #undef NSCML_THIS
714
715 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
716     nsContextMenuListener_QueryInterface,
717     nsContextMenuListener_AddRef,
718     nsContextMenuListener_Release,
719     nsContextMenuListener_OnShowContextMenu
720 };
721
722 /**********************************************************
723  *      nsIURIContentListener interface
724  */
725
726 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
727
728 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
729         nsIIDRef riid, nsQIResult result)
730 {
731     NSContainer *This = NSURICL_THIS(iface);
732     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
733 }
734
735 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
736 {
737     NSContainer *This = NSURICL_THIS(iface);
738     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
739 }
740
741 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
742 {
743     NSContainer *This = NSURICL_THIS(iface);
744     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
745 }
746
747 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
748                                                           nsIURI *aURI, PRBool *_retval)
749 {
750     NSContainer *This = NSURICL_THIS(iface);
751     nsIWineURI *wine_uri;
752     nsACString spec_str;
753     const char *spec;
754     nsresult nsres;
755
756     nsACString_Init(&spec_str, NULL);
757     nsIURI_GetSpec(aURI, &spec_str);
758     nsACString_GetData(&spec_str, &spec, NULL);
759
760     TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
761
762     nsACString_Finish(&spec_str);
763
764     nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
765     if(NS_SUCCEEDED(nsres)) {
766         nsIWineURI_SetNSContainer(wine_uri, This);
767         nsIWineURI_Release(wine_uri);
768     }else {
769         WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
770     }
771
772     return NS_ERROR_NOT_IMPLEMENTED;
773 }
774
775 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
776         const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
777         nsIStreamListener **aContentHandler, PRBool *_retval)
778 {
779     NSContainer *This = NSURICL_THIS(iface);
780     TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
781             aRequest, aContentHandler, _retval);
782     return NS_ERROR_NOT_IMPLEMENTED;
783 }
784
785 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
786         const char *aContentType, char **aDesiredContentType, PRBool *_retval)
787 {
788     NSContainer *This = NSURICL_THIS(iface);
789
790     TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
791
792     /* FIXME: Should we do something here? */
793     *_retval = TRUE; 
794     return NS_OK;
795 }
796
797 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
798         const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
799         PRBool *_retval)
800 {
801     NSContainer *This = NSURICL_THIS(iface);
802     TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
803             aDesiredContentType, _retval);
804     return NS_ERROR_NOT_IMPLEMENTED;
805 }
806
807 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
808         nsISupports **aLoadCookie)
809 {
810     NSContainer *This = NSURICL_THIS(iface);
811     WARN("(%p)->(%p)\n", This, aLoadCookie);
812     return NS_ERROR_NOT_IMPLEMENTED;
813 }
814
815 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
816         nsISupports *aLoadCookie)
817 {
818     NSContainer *This = NSURICL_THIS(iface);
819     WARN("(%p)->(%p)\n", This, aLoadCookie);
820     return NS_ERROR_NOT_IMPLEMENTED;
821 }
822
823 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
824         nsIURIContentListener **aParentContentListener)
825 {
826     NSContainer *This = NSURICL_THIS(iface);
827     WARN("(%p)->(%p)\n", This, aParentContentListener);
828     return NS_ERROR_NOT_IMPLEMENTED;
829 }
830
831 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
832         nsIURIContentListener *aParentContentListener)
833 {
834     NSContainer *This = NSURICL_THIS(iface);
835     WARN("(%p)->(%p)\n", This, aParentContentListener);
836     return NS_ERROR_NOT_IMPLEMENTED;
837 }
838
839 #undef NSURICL_THIS
840
841 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
842     nsURIContentListener_QueryInterface,
843     nsURIContentListener_AddRef,
844     nsURIContentListener_Release,
845     nsURIContentListener_OnStartURIOpen,
846     nsURIContentListener_DoContent,
847     nsURIContentListener_IsPreferred,
848     nsURIContentListener_CanHandleContent,
849     nsURIContentListener_GetLoadCookie,
850     nsURIContentListener_SetLoadCookie,
851     nsURIContentListener_GetParentContentListener,
852     nsURIContentListener_SetParentContentListener
853 };
854
855 /**********************************************************
856  *      nsIEmbeddinSiteWindow interface
857  */
858
859 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
860
861 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
862         nsIIDRef riid, nsQIResult result)
863 {
864     NSContainer *This = NSEMBWNDS_THIS(iface);
865     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
866 }
867
868 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
869 {
870     NSContainer *This = NSEMBWNDS_THIS(iface);
871     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
872 }
873
874 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
875 {
876     NSContainer *This = NSEMBWNDS_THIS(iface);
877     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
878 }
879
880 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
881         PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
882 {
883     NSContainer *This = NSEMBWNDS_THIS(iface);
884     WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
885     return NS_ERROR_NOT_IMPLEMENTED;
886 }
887
888 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
889         PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
890 {
891     NSContainer *This = NSEMBWNDS_THIS(iface);
892     WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
893     return NS_ERROR_NOT_IMPLEMENTED;
894 }
895
896 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
897 {
898     NSContainer *This = NSEMBWNDS_THIS(iface);
899     WARN("(%p)\n", This);
900     return NS_ERROR_NOT_IMPLEMENTED;
901 }
902
903 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
904         PRBool *aVisibility)
905 {
906     NSContainer *This = NSEMBWNDS_THIS(iface);
907     WARN("(%p)->(%p)\n", This, aVisibility);
908     return NS_ERROR_NOT_IMPLEMENTED;
909 }
910
911 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
912         PRBool aVisibility)
913 {
914     NSContainer *This = NSEMBWNDS_THIS(iface);
915     WARN("(%p)->(%x)\n", This, aVisibility);
916     return NS_ERROR_NOT_IMPLEMENTED;
917 }
918
919 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
920         PRUnichar **aTitle)
921 {
922     NSContainer *This = NSEMBWNDS_THIS(iface);
923     WARN("(%p)->(%p)\n", This, aTitle);
924     return NS_ERROR_NOT_IMPLEMENTED;
925 }
926
927 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
928         const PRUnichar *aTitle)
929 {
930     NSContainer *This = NSEMBWNDS_THIS(iface);
931     WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
932     return NS_ERROR_NOT_IMPLEMENTED;
933 }
934
935 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
936         void **aSiteWindow)
937 {
938     NSContainer *This = NSEMBWNDS_THIS(iface);
939
940     TRACE("(%p)->(%p)\n", This, aSiteWindow);
941
942     *aSiteWindow = This->hwnd;
943     return NS_OK;
944 }
945
946 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
947     nsEmbeddingSiteWindow_QueryInterface,
948     nsEmbeddingSiteWindow_AddRef,
949     nsEmbeddingSiteWindow_Release,
950     nsEmbeddingSiteWindow_SetDimensions,
951     nsEmbeddingSiteWindow_GetDimensions,
952     nsEmbeddingSiteWindow_SetFocus,
953     nsEmbeddingSiteWindow_GetVisibility,
954     nsEmbeddingSiteWindow_SetVisibility,
955     nsEmbeddingSiteWindow_GetTitle,
956     nsEmbeddingSiteWindow_SetTitle,
957     nsEmbeddingSiteWindow_GetSiteWindow
958 };
959
960 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
961
962 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
963                                                        nsQIResult result)
964 {
965     NSContainer *This = NSTOOLTIP_THIS(iface);
966     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
967 }
968
969 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
970 {
971     NSContainer *This = NSTOOLTIP_THIS(iface);
972     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
973 }
974
975 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
976 {
977     NSContainer *This = NSTOOLTIP_THIS(iface);
978     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
979 }
980
981 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
982         PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
983 {
984     NSContainer *This = NSTOOLTIP_THIS(iface);
985
986     show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
987
988     return NS_OK;
989 }
990
991 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
992 {
993     NSContainer *This = NSTOOLTIP_THIS(iface);
994
995     hide_tooltip(This->doc);
996
997     return NS_OK;
998 }
999
1000 #undef NSTOOLTIM_THIS
1001
1002 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1003     nsTooltipListener_QueryInterface,
1004     nsTooltipListener_AddRef,
1005     nsTooltipListener_Release,
1006     nsTooltipListener_OnShowTooltip,
1007     nsTooltipListener_OnHideTooltip
1008 };
1009
1010 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1011
1012 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1013                                                           nsIIDRef riid, nsQIResult result)
1014 {
1015     NSContainer *This = NSIFACEREQ_THIS(iface);
1016     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1017 }
1018
1019 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1020 {
1021     NSContainer *This = NSIFACEREQ_THIS(iface);
1022     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1023 }
1024
1025 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1026 {
1027     NSContainer *This = NSIFACEREQ_THIS(iface);
1028     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1029 }
1030
1031 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1032                                                         nsIIDRef riid, nsQIResult result)
1033 {
1034     NSContainer *This = NSIFACEREQ_THIS(iface);
1035
1036     if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1037         TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1038         return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1039     }
1040
1041     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1042 }
1043
1044 #undef NSIFACEREQ_THIS
1045
1046 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1047     nsInterfaceRequestor_QueryInterface,
1048     nsInterfaceRequestor_AddRef,
1049     nsInterfaceRequestor_Release,
1050     nsInterfaceRequestor_GetInterface
1051 };
1052
1053 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1054
1055 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1056         nsIIDRef riid, nsQIResult result)
1057 {
1058     NSContainer *This = NSWEAKREF_THIS(iface);
1059     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1060 }
1061
1062 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1063 {
1064     NSContainer *This = NSWEAKREF_THIS(iface);
1065     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1066 }
1067
1068 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1069 {
1070     NSContainer *This = NSWEAKREF_THIS(iface);
1071     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1072 }
1073
1074 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1075         const nsIID *riid, void **result)
1076 {
1077     NSContainer *This = NSWEAKREF_THIS(iface);
1078     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1079 }
1080
1081 #undef NSWEAKREF_THIS
1082
1083 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1084     nsWeakReference_QueryInterface,
1085     nsWeakReference_AddRef,
1086     nsWeakReference_Release,
1087     nsWeakReference_QueryReferent
1088 };
1089
1090 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1091
1092 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1093         nsIIDRef riid, nsQIResult result)
1094 {
1095     NSContainer *This = NSSUPWEAKREF_THIS(iface);
1096     return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1097 }
1098
1099 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1100 {
1101     NSContainer *This = NSSUPWEAKREF_THIS(iface);
1102     return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1103 }
1104
1105 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1106 {
1107     NSContainer *This = NSSUPWEAKREF_THIS(iface);
1108     return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1109 }
1110
1111 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1112         nsIWeakReference **_retval)
1113 {
1114     NSContainer *This = NSSUPWEAKREF_THIS(iface);
1115
1116     TRACE("(%p)->(%p)\n", This, _retval);
1117
1118     nsIWeakReference_AddRef(NSWEAKREF(This));
1119     *_retval = NSWEAKREF(This);
1120     return NS_OK;
1121 }
1122
1123 #undef NSWEAKREF_THIS
1124
1125 const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1126     nsSupportsWeakReference_QueryInterface,
1127     nsSupportsWeakReference_AddRef,
1128     nsSupportsWeakReference_Release,
1129     nsSupportsWeakReference_GetWeakReference
1130 };
1131
1132
1133 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1134 {
1135     nsIWebBrowserSetup *wbsetup;
1136     NSContainer *ret;
1137     nsresult nsres;
1138
1139     if(!load_gecko())
1140         return NULL;
1141
1142     ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
1143
1144     ret->lpWebBrowserChromeVtbl      = &nsWebBrowserChromeVtbl;
1145     ret->lpContextMenuListenerVtbl   = &nsContextMenuListenerVtbl;
1146     ret->lpURIContentListenerVtbl    = &nsURIContentListenerVtbl;
1147     ret->lpEmbeddingSiteWindowVtbl   = &nsEmbeddingSiteWindowVtbl;
1148     ret->lpTooltipListenerVtbl       = &nsTooltipListenerVtbl;
1149     ret->lpInterfaceRequestorVtbl    = &nsInterfaceRequestorVtbl;
1150     ret->lpWeakReferenceVtbl         = &nsWeakReferenceVtbl;
1151     ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1152
1153
1154     ret->doc = doc;
1155     ret->ref = 1;
1156     ret->load_call = FALSE;
1157
1158     if(parent)
1159         nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1160     ret->parent = parent;
1161
1162     nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1163             NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1164     if(NS_FAILED(nsres))
1165         ERR("Creating WebBrowser failed: %08lx\n", nsres);
1166
1167     nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1168     if(NS_FAILED(nsres))
1169         ERR("SetContainerWindow failed: %08lx\n", nsres);
1170
1171     nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1172             (void**)&ret->window);
1173     if(NS_FAILED(nsres))
1174         ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1175
1176     nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1177                                          (void**)&wbsetup);
1178     if(NS_SUCCEEDED(nsres)) {
1179         nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1180         nsIWebBrowserSetup_Release(wbsetup);
1181         if(NS_FAILED(nsres))
1182             ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1183     }else {
1184         ERR("Could not get nsIWebBrowserSetup interface\n");
1185     }
1186
1187     nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1188             (void**)&ret->navigation);
1189     if(NS_FAILED(nsres))
1190         ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1191
1192     nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1193             (void**)&ret->focus);
1194     if(NS_FAILED(nsres))
1195         ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1196
1197     if(!nscontainer_class)
1198         register_nscontainer_class();
1199
1200     ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1201             WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1202             GetDesktopWindow(), NULL, hInst, ret);
1203
1204     nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1205     if(NS_SUCCEEDED(nsres)) {
1206         nsres = nsIBaseWindow_Create(ret->window);
1207         if(NS_FAILED(nsres))
1208             WARN("Creating window failed: %08lx\n", nsres);
1209
1210         nsIBaseWindow_SetVisibility(ret->window, FALSE);
1211         nsIBaseWindow_SetEnabled(ret->window, FALSE);
1212     }else {
1213         ERR("InitWindow failed: %08lx\n", nsres);
1214     }
1215
1216     nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1217     if(NS_FAILED(nsres))
1218         ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1219
1220     return ret;
1221 }
1222
1223 void NSContainer_Release(NSContainer *This)
1224 {
1225     TRACE("(%p)\n", This);
1226
1227     ShowWindow(This->hwnd, SW_HIDE);
1228     SetParent(This->hwnd, NULL);
1229
1230     nsIBaseWindow_SetVisibility(This->window, FALSE);
1231     nsIBaseWindow_Destroy(This->window);
1232
1233     nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1234
1235     nsIWebBrowser_Release(This->webbrowser);
1236     This->webbrowser = NULL;
1237
1238     nsIWebNavigation_Release(This->navigation);
1239     This->navigation = NULL;
1240
1241     nsIBaseWindow_Release(This->window);
1242     This->window = NULL;
1243
1244     nsIWebBrowserFocus_Release(This->focus);
1245     This->focus = NULL;
1246
1247     if(This->hwnd) {
1248         DestroyWindow(This->hwnd);
1249         This->hwnd = NULL;
1250     }
1251
1252     nsIWebBrowserChrome_Release(NSWBCHROME(This));
1253 }