Changes of picasa-wine-2.2.2820-5 except to configure
[wine/hacks.git] / dlls / mshtml / nsembed.c
blobddd030a8ee9e676c6a2a3cd1074283bf48f457d1
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
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"
44 #define APPSTARTUP_TOPIC "app-startup"
46 #define PR_UINT32_MAX 0xffffffff
48 struct nsCStringContainer {
49 void *v;
50 void *d1;
51 PRUint32 d2;
52 void *d3;
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*);
68 static HINSTANCE hXPCOM = NULL;
70 static nsIServiceManager *pServMgr = NULL;
71 static nsIComponentManager *pCompMgr = NULL;
72 static nsIMemory *nsmem = NULL;
74 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
76 static ATOM nscontainer_class;
78 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
80 NSContainer *This;
81 nsresult nsres;
83 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
85 if(msg == WM_CREATE) {
86 This = *(NSContainer**)lParam;
87 SetPropW(hwnd, wszTHIS, This);
88 }else {
89 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
92 switch(msg) {
93 case WM_SIZE:
94 TRACE("(%p)->(WM_SIZE)\n", This);
96 nsres = nsIBaseWindow_SetSize(This->window,
97 LOWORD(lParam), HIWORD(lParam), TRUE);
98 if(NS_FAILED(nsres))
99 WARN("SetSize failed: %08lx\n", nsres);
102 return DefWindowProcW(hwnd, msg, wParam, lParam);
106 static void register_nscontainer_class(void)
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,
116 wndclass.hInstance = hInst;
117 nscontainer_class = RegisterClassExW(&wndclass);
120 static BOOL get_mozilla_path(PRUnichar *gre_path)
122 DWORD res, type, i, size = MAX_PATH;
123 HKEY mozilla_key, hkey;
124 WCHAR key_name[100];
125 BOOL ret = FALSE;
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};
132 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
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;
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);
148 RegCloseKey(mozilla_key);
149 return ret;
152 static BOOL get_mozctl_path(PRUnichar *gre_path)
154 HKEY hkey;
155 DWORD res, type, size = MAX_PATH;
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};
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));
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));
189 TRACE("Could not find Mozilla ActiveX Control\n");
191 return FALSE;
194 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
196 HKEY hkey;
197 DWORD res, type, size = MAX_PATH;
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};
205 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
206 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
207 if(res != ERROR_SUCCESS)
208 return FALSE;
210 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
211 if(res != ERROR_SUCCESS || type != REG_SZ)
212 return FALSE;
214 return TRUE;
217 static void set_profile(void)
219 nsIProfile *profile;
220 PRBool exists = FALSE;
221 nsresult nsres;
223 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
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;
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);
239 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
240 if(NS_FAILED(nsres))
241 ERR("SetCurrentProfile failed: %08lx\n", nsres);
243 nsIProfile_Release(profile);
246 static BOOL load_gecko(void)
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;
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};
261 TRACE("()\n");
263 if(tried_load)
264 return pCompMgr != NULL;
265 tried_load = TRUE;
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;
273 TRACE("found path %s\n", debugstr_w(gre_path));
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);
282 hXPCOM = LoadLibraryW(strXPCOM);
283 if(!hXPCOM) {
284 ERR("Could not load XPCOM: %ld\n", GetLastError());
285 return FALSE;
288 #define NS_DLSYM(func) \
289 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
290 if(!func) \
291 ERR("Could not GetProcAddress(" #func ") failed\n")
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);
306 #undef NS_DLSYM
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;
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;
325 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
326 if(NS_FAILED(nsres))
327 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
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);
335 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
336 if(NS_FAILED(nsres))
337 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
339 init_nsio(pCompMgr, registrar);
340 }else {
341 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
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);
351 nsIObserver_Release(pStartNotif);
352 }else {
353 ERR("could not get appstartup-notifier: %08lx\n", nsres);
356 set_profile();
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);
363 if(registrar) {
364 register_nsservice(registrar, pServMgr);
365 nsIComponentRegistrar_Release(registrar);
368 return TRUE;
371 void *nsalloc(size_t size)
373 return nsIMemory_Alloc(nsmem, size);
376 void nsfree(void *mem)
378 nsIMemory_Free(nsmem, mem);
381 void nsACString_Init(nsACString *str, const char *data)
383 NS_CStringContainerInit(str);
384 if(data)
385 NS_CStringSetData(str, data, PR_UINT32_MAX);
388 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
390 return NS_CStringGetData(str, data, termited);
393 void nsACString_Finish(nsACString *str)
395 NS_CStringContainerFinish(str);
398 void nsAString_Init(nsAString *str, const PRUnichar *data)
400 NS_StringContainerInit(str);
401 if(data)
402 NS_StringSetData(str, data, PR_UINT32_MAX);
405 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
407 return NS_StringGetData(str, data, termited);
410 void nsAString_Finish(nsAString *str)
412 NS_StringContainerFinish(str);
415 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
417 nsIStringInputStream *ret;
418 nsresult nsres;
420 if(!pCompMgr)
421 return NULL;
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;
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;
438 return (nsIInputStream*)ret;
441 void close_gecko()
443 TRACE("()\n");
445 if(pCompMgr)
446 nsIComponentManager_Release(pCompMgr);
448 if(pServMgr)
449 nsIServiceManager_Release(pServMgr);
451 if(nsmem)
452 nsIMemory_Release(nsmem);
454 if(hXPCOM)
455 FreeLibrary(hXPCOM);
458 /**********************************************************
459 * nsIWebBrowserChrome interface
462 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
464 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
465 nsIIDRef riid, nsQIResult result)
467 NSContainer *This = NSWBCHROME_THIS(iface);
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);
499 if(*result) {
500 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
501 return NS_OK;
504 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
505 return NS_NOINTERFACE;
508 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
510 NSContainer *This = NSWBCHROME_THIS(iface);
511 LONG ref = InterlockedIncrement(&This->ref);
513 TRACE("(%p) ref=%ld\n", This, ref);
515 return ref;
518 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
520 NSContainer *This = NSWBCHROME_THIS(iface);
521 LONG ref = InterlockedDecrement(&This->ref);
523 TRACE("(%p) ref=%ld\n", This, ref);
525 if(!ref) {
526 if(This->parent)
527 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
528 HeapFree(GetProcessHeap(), 0, This);
531 return ref;
534 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
535 PRUint32 statusType, const PRUnichar *status)
537 NSContainer *This = NSWBCHROME_THIS(iface);
538 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
539 return NS_ERROR_NOT_IMPLEMENTED;
542 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
543 nsIWebBrowser **aWebBrowser)
545 NSContainer *This = NSWBCHROME_THIS(iface);
547 TRACE("(%p)->(%p)\n", This, aWebBrowser);
549 if(!aWebBrowser)
550 return NS_ERROR_INVALID_ARG;
552 if(This->webbrowser)
553 nsIWebBrowser_AddRef(This->webbrowser);
554 *aWebBrowser = This->webbrowser;
555 return S_OK;
558 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
559 nsIWebBrowser *aWebBrowser)
561 NSContainer *This = NSWBCHROME_THIS(iface);
563 TRACE("(%p)->(%p)\n", This, aWebBrowser);
565 if(aWebBrowser != This->webbrowser)
566 ERR("Wrong nsWebBrowser!\n");
568 return NS_OK;
571 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
572 PRUint32 *aChromeFlags)
574 NSContainer *This = NSWBCHROME_THIS(iface);
575 WARN("(%p)->(%p)\n", This, aChromeFlags);
576 return NS_ERROR_NOT_IMPLEMENTED;
579 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
580 PRUint32 aChromeFlags)
582 NSContainer *This = NSWBCHROME_THIS(iface);
583 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
584 return NS_ERROR_NOT_IMPLEMENTED;
587 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
589 NSContainer *This = NSWBCHROME_THIS(iface);
590 TRACE("(%p)\n", This);
591 return NS_ERROR_NOT_IMPLEMENTED;
594 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
595 PRInt32 aCX, PRInt32 aCY)
597 NSContainer *This = NSWBCHROME_THIS(iface);
598 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
599 return NS_ERROR_NOT_IMPLEMENTED;
602 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
604 NSContainer *This = NSWBCHROME_THIS(iface);
605 WARN("(%p)\n", This);
606 return NS_ERROR_NOT_IMPLEMENTED;
609 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
611 NSContainer *This = NSWBCHROME_THIS(iface);
612 WARN("(%p)->(%p)\n", This, _retval);
613 return NS_ERROR_NOT_IMPLEMENTED;
616 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
617 nsresult aStatus)
619 NSContainer *This = NSWBCHROME_THIS(iface);
620 WARN("(%p)->(%08lx)\n", This, aStatus);
621 return NS_ERROR_NOT_IMPLEMENTED;
624 #undef NSWBCHROME_THIS
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
642 /**********************************************************
643 * nsIContextMenuListener interface
646 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
648 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
649 nsIIDRef riid, nsQIResult result)
651 NSContainer *This = NSCML_THIS(iface);
652 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
655 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
657 NSContainer *This = NSCML_THIS(iface);
658 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
661 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
663 NSContainer *This = NSCML_THIS(iface);
664 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
667 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
668 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
670 NSContainer *This = NSCML_THIS(iface);
671 nsIDOMMouseEvent *event;
672 POINT pt;
673 DWORD dwID = CONTEXT_MENU_DEFAULT;
674 nsresult nsres;
676 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
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;
684 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
685 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
686 nsIDOMMouseEvent_Release(event);
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);
708 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
710 return NS_OK;
713 #undef NSCML_THIS
715 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
716 nsContextMenuListener_QueryInterface,
717 nsContextMenuListener_AddRef,
718 nsContextMenuListener_Release,
719 nsContextMenuListener_OnShowContextMenu
722 /**********************************************************
723 * nsIURIContentListener interface
726 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
728 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
729 nsIIDRef riid, nsQIResult result)
731 NSContainer *This = NSURICL_THIS(iface);
732 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
735 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
737 NSContainer *This = NSURICL_THIS(iface);
738 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
741 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
743 NSContainer *This = NSURICL_THIS(iface);
744 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
747 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
748 nsIURI *aURI, PRBool *_retval)
750 NSContainer *This = NSURICL_THIS(iface);
751 nsIWineURI *wine_uri;
752 nsACString spec_str;
753 const char *spec;
754 nsresult nsres;
756 nsACString_Init(&spec_str, NULL);
757 nsIURI_GetSpec(aURI, &spec_str);
758 nsACString_GetData(&spec_str, &spec, NULL);
760 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
762 nsACString_Finish(&spec_str);
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);
772 return NS_ERROR_NOT_IMPLEMENTED;
775 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
776 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
777 nsIStreamListener **aContentHandler, PRBool *_retval)
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;
785 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
786 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
788 NSContainer *This = NSURICL_THIS(iface);
790 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
792 /* FIXME: Should we do something here? */
793 *_retval = TRUE;
794 return NS_OK;
797 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
798 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
799 PRBool *_retval)
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;
807 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
808 nsISupports **aLoadCookie)
810 NSContainer *This = NSURICL_THIS(iface);
811 WARN("(%p)->(%p)\n", This, aLoadCookie);
812 return NS_ERROR_NOT_IMPLEMENTED;
815 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
816 nsISupports *aLoadCookie)
818 NSContainer *This = NSURICL_THIS(iface);
819 WARN("(%p)->(%p)\n", This, aLoadCookie);
820 return NS_ERROR_NOT_IMPLEMENTED;
823 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
824 nsIURIContentListener **aParentContentListener)
826 NSContainer *This = NSURICL_THIS(iface);
827 WARN("(%p)->(%p)\n", This, aParentContentListener);
828 return NS_ERROR_NOT_IMPLEMENTED;
831 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
832 nsIURIContentListener *aParentContentListener)
834 NSContainer *This = NSURICL_THIS(iface);
835 WARN("(%p)->(%p)\n", This, aParentContentListener);
836 return NS_ERROR_NOT_IMPLEMENTED;
839 #undef NSURICL_THIS
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
855 /**********************************************************
856 * nsIEmbeddinSiteWindow interface
859 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
861 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
862 nsIIDRef riid, nsQIResult result)
864 NSContainer *This = NSEMBWNDS_THIS(iface);
865 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
868 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
870 NSContainer *This = NSEMBWNDS_THIS(iface);
871 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
874 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
876 NSContainer *This = NSEMBWNDS_THIS(iface);
877 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
880 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
881 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
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;
888 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
889 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
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;
896 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
898 NSContainer *This = NSEMBWNDS_THIS(iface);
899 WARN("(%p)\n", This);
900 return NS_ERROR_NOT_IMPLEMENTED;
903 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
904 PRBool *aVisibility)
906 NSContainer *This = NSEMBWNDS_THIS(iface);
907 WARN("(%p)->(%p)\n", This, aVisibility);
908 return NS_ERROR_NOT_IMPLEMENTED;
911 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
912 PRBool aVisibility)
914 NSContainer *This = NSEMBWNDS_THIS(iface);
915 WARN("(%p)->(%x)\n", This, aVisibility);
916 return NS_ERROR_NOT_IMPLEMENTED;
919 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
920 PRUnichar **aTitle)
922 NSContainer *This = NSEMBWNDS_THIS(iface);
923 WARN("(%p)->(%p)\n", This, aTitle);
924 return NS_ERROR_NOT_IMPLEMENTED;
927 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
928 const PRUnichar *aTitle)
930 NSContainer *This = NSEMBWNDS_THIS(iface);
931 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
932 return NS_ERROR_NOT_IMPLEMENTED;
935 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
936 void **aSiteWindow)
938 NSContainer *This = NSEMBWNDS_THIS(iface);
940 TRACE("(%p)->(%p)\n", This, aSiteWindow);
942 *aSiteWindow = This->hwnd;
943 return NS_OK;
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
960 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
962 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
963 nsQIResult result)
965 NSContainer *This = NSTOOLTIP_THIS(iface);
966 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
969 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
971 NSContainer *This = NSTOOLTIP_THIS(iface);
972 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
975 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
977 NSContainer *This = NSTOOLTIP_THIS(iface);
978 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
981 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
982 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
984 NSContainer *This = NSTOOLTIP_THIS(iface);
986 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
988 return NS_OK;
991 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
993 NSContainer *This = NSTOOLTIP_THIS(iface);
995 hide_tooltip(This->doc);
997 return NS_OK;
1000 #undef NSTOOLTIM_THIS
1002 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1003 nsTooltipListener_QueryInterface,
1004 nsTooltipListener_AddRef,
1005 nsTooltipListener_Release,
1006 nsTooltipListener_OnShowTooltip,
1007 nsTooltipListener_OnHideTooltip
1010 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1012 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1013 nsIIDRef riid, nsQIResult result)
1015 NSContainer *This = NSIFACEREQ_THIS(iface);
1016 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1019 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1021 NSContainer *This = NSIFACEREQ_THIS(iface);
1022 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1025 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1027 NSContainer *This = NSIFACEREQ_THIS(iface);
1028 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1031 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1032 nsIIDRef riid, nsQIResult result)
1034 NSContainer *This = NSIFACEREQ_THIS(iface);
1036 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1037 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1038 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1041 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1044 #undef NSIFACEREQ_THIS
1046 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1047 nsInterfaceRequestor_QueryInterface,
1048 nsInterfaceRequestor_AddRef,
1049 nsInterfaceRequestor_Release,
1050 nsInterfaceRequestor_GetInterface
1053 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1055 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1056 nsIIDRef riid, nsQIResult result)
1058 NSContainer *This = NSWEAKREF_THIS(iface);
1059 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1062 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1064 NSContainer *This = NSWEAKREF_THIS(iface);
1065 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1068 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1070 NSContainer *This = NSWEAKREF_THIS(iface);
1071 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1074 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1075 const nsIID *riid, void **result)
1077 NSContainer *This = NSWEAKREF_THIS(iface);
1078 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1081 #undef NSWEAKREF_THIS
1083 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1084 nsWeakReference_QueryInterface,
1085 nsWeakReference_AddRef,
1086 nsWeakReference_Release,
1087 nsWeakReference_QueryReferent
1090 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1092 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1093 nsIIDRef riid, nsQIResult result)
1095 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1096 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1099 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1101 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1102 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1105 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1107 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1108 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1111 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1112 nsIWeakReference **_retval)
1114 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1116 TRACE("(%p)->(%p)\n", This, _retval);
1118 nsIWeakReference_AddRef(NSWEAKREF(This));
1119 *_retval = NSWEAKREF(This);
1120 return NS_OK;
1123 #undef NSWEAKREF_THIS
1125 const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1126 nsSupportsWeakReference_QueryInterface,
1127 nsSupportsWeakReference_AddRef,
1128 nsSupportsWeakReference_Release,
1129 nsSupportsWeakReference_GetWeakReference
1133 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1135 nsIWebBrowserSetup *wbsetup;
1136 NSContainer *ret;
1137 nsresult nsres;
1139 if(!load_gecko())
1140 return NULL;
1142 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
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;
1154 ret->doc = doc;
1155 ret->ref = 1;
1156 ret->load_call = FALSE;
1158 if(parent)
1159 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1160 ret->parent = parent;
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);
1167 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1168 if(NS_FAILED(nsres))
1169 ERR("SetContainerWindow failed: %08lx\n", nsres);
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);
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");
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);
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);
1197 #if 0
1198 nsres = nsIWebBrowserStream_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserStream,
1199 (void**)&ret->stream);
1200 if(NS_FAILED(nsres))
1201 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
1202 #else
1203 ret->stream = NULL;
1204 #endif
1206 if(!nscontainer_class)
1207 register_nscontainer_class();
1209 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1210 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1211 GetDesktopWindow(), NULL, hInst, ret);
1213 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1214 if(NS_SUCCEEDED(nsres)) {
1215 nsres = nsIBaseWindow_Create(ret->window);
1216 if(NS_FAILED(nsres))
1217 WARN("Creating window failed: %08lx\n", nsres);
1219 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1220 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1221 }else {
1222 ERR("InitWindow failed: %08lx\n", nsres);
1225 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1226 if(NS_FAILED(nsres))
1227 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1229 return ret;
1232 void NSContainer_Release(NSContainer *This)
1234 TRACE("(%p)\n", This);
1236 ShowWindow(This->hwnd, SW_HIDE);
1237 SetParent(This->hwnd, NULL);
1239 nsIBaseWindow_SetVisibility(This->window, FALSE);
1240 nsIBaseWindow_Destroy(This->window);
1242 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1244 nsIWebBrowser_Release(This->webbrowser);
1245 This->webbrowser = NULL;
1247 nsIWebNavigation_Release(This->navigation);
1248 This->navigation = NULL;
1250 nsIBaseWindow_Release(This->window);
1251 This->window = NULL;
1253 nsIWebBrowserFocus_Release(This->focus);
1254 This->focus = NULL;
1256 if(This->stream) {
1257 nsIWebBrowserStream_Release(This->stream);
1258 This->stream = NULL;
1261 if(This->hwnd) {
1262 DestroyWindow(This->hwnd);
1263 This->hwnd = NULL;
1266 nsIWebBrowserChrome_Release(NSWBCHROME(This));