mshtml: Set nsURI's moniker in OnStartURILoad.
[wine/multimedia.git] / dlls / mshtml / nsembed.c
blob39f454d0721d553a3e38325c6314feafaf3348c1
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 load_xpcom(PRUnichar *gre_path)
122 WCHAR path_env[MAX_PATH];
123 int len;
125 static const WCHAR wszPATH[] = {'P','A','T','H',0};
126 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
128 TRACE("(%s)\n", debugstr_w(gre_path));
130 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
131 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
132 len = strlenW(path_env);
133 path_env[len++] = ';';
134 strcpyW(path_env+len, gre_path);
135 SetEnvironmentVariableW(wszPATH, path_env);
137 hXPCOM = LoadLibraryW(strXPCOM);
138 if(!hXPCOM) {
139 WARN("Could not load XPCOM: %ld\n", GetLastError());
140 return FALSE;
143 #define NS_DLSYM(func) \
144 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
145 if(!func) \
146 ERR("Could not GetProcAddress(" #func ") failed\n")
148 NS_DLSYM(NS_InitXPCOM2);
149 NS_DLSYM(NS_ShutdownXPCOM);
150 NS_DLSYM(NS_GetComponentRegistrar);
151 NS_DLSYM(NS_StringContainerInit);
152 NS_DLSYM(NS_CStringContainerInit);
153 NS_DLSYM(NS_StringContainerFinish);
154 NS_DLSYM(NS_CStringContainerFinish);
155 NS_DLSYM(NS_StringSetData);
156 NS_DLSYM(NS_CStringSetData);
157 NS_DLSYM(NS_NewLocalFile);
158 NS_DLSYM(NS_StringGetData);
159 NS_DLSYM(NS_CStringGetData);
161 #undef NS_DLSYM
163 return TRUE;
166 static BOOL load_mozilla(PRUnichar *gre_path)
168 DWORD res, type, i, size = MAX_PATH;
169 HKEY mozilla_key, hkey;
170 WCHAR key_name[100];
171 BOOL ret = FALSE;
173 static const WCHAR wszGreKey[] =
174 {'S','o','f','t','w','a','r','e','\\',
175 'm','o','z','i','l','l','a','.','o','r','g','\\',
176 'G','R','E',0};
178 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
180 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
181 if(res != ERROR_SUCCESS) {
182 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
183 return FALSE;
186 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
187 RegOpenKeyW(mozilla_key, key_name, &hkey);
188 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
189 if(res == ERROR_SUCCESS)
190 ret = TRUE;
191 RegCloseKey(hkey);
194 RegCloseKey(mozilla_key);
195 return ret ? load_xpcom(gre_path) : FALSE;
198 static BOOL load_mozctl(PRUnichar *gre_path)
200 HKEY hkey;
201 DWORD res, type, size = MAX_PATH;
203 static const WCHAR wszMozCtlKey[] =
204 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
205 static const WCHAR wszBinDirectoryPath[] =
206 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
207 static const WCHAR wszMozCtlClsidKey[] =
208 {'C','L','S','I','D','\\',
209 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
210 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
211 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
213 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
214 if(res == ERROR_SUCCESS) {
215 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
216 if(res == ERROR_SUCCESS)
217 return load_xpcom(gre_path);
218 else
219 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
222 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
223 if(res == ERROR_SUCCESS) {
224 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
225 if(res == ERROR_SUCCESS) {
226 WCHAR *ptr;
227 if((ptr = strrchrW(gre_path, '\\')))
228 ptr[1] = 0;
229 load_xpcom(gre_path);
230 }else {
231 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
235 TRACE("Could not find Mozilla ActiveX Control\n");
237 return FALSE;
240 static BOOL load_wine_gecko(PRUnichar *gre_path)
242 HKEY hkey;
243 DWORD res, type, size = MAX_PATH;
245 static const WCHAR wszMshtmlKey[] = {
246 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
247 '\\','M','S','H','T','M','L',0};
248 static const WCHAR wszGeckoPath[] =
249 {'G','e','c','k','o','P','a','t','h',0};
251 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
252 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
253 if(res != ERROR_SUCCESS)
254 return FALSE;
256 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
257 if(res != ERROR_SUCCESS || type != REG_SZ)
258 return FALSE;
260 return load_xpcom(gre_path);
263 static void set_profile(void)
265 nsIProfile *profile;
266 PRBool exists = FALSE;
267 nsresult nsres;
269 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
271 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
272 &IID_nsIProfile, (void**)&profile);
273 if(NS_FAILED(nsres)) {
274 ERR("Could not get profile service: %08lx\n", nsres);
275 return;
278 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
279 if(!exists) {
280 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
281 if(NS_FAILED(nsres))
282 ERR("CreateNewProfile failed: %08lx\n", nsres);
285 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
286 if(NS_FAILED(nsres))
287 ERR("SetCurrentProfile failed: %08lx\n", nsres);
289 nsIProfile_Release(profile);
292 static BOOL load_gecko(void)
294 nsresult nsres;
295 nsIObserver *pStartNotif;
296 nsIComponentRegistrar *registrar = NULL;
297 nsAString path;
298 nsIFile *gre_dir;
299 PRUnichar gre_path[MAX_PATH];
301 static BOOL tried_load = FALSE;
303 TRACE("()\n");
305 if(tried_load)
306 return pCompMgr != NULL;
307 tried_load = TRUE;
309 if(!load_wine_gecko(gre_path) && !load_mozctl(gre_path) && !load_mozilla(gre_path)) {
310 install_wine_gecko();
311 if(!load_wine_gecko(gre_path)) {
312 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
313 return FALSE;
317 NS_StringContainerInit(&path);
318 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
319 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
320 NS_StringContainerFinish(&path);
321 if(NS_FAILED(nsres)) {
322 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
323 FreeLibrary(hXPCOM);
324 return FALSE;
327 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
328 if(NS_FAILED(nsres)) {
329 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
330 FreeLibrary(hXPCOM);
331 return FALSE;
334 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
335 if(NS_FAILED(nsres))
336 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
338 nsres = NS_GetComponentRegistrar(&registrar);
339 if(NS_SUCCEEDED(nsres)) {
340 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
341 if(NS_FAILED(nsres))
342 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
344 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
345 if(NS_FAILED(nsres))
346 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
348 init_nsio(pCompMgr, registrar);
349 }else {
350 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
353 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
354 NULL, &IID_nsIObserver, (void**)&pStartNotif);
355 if(NS_SUCCEEDED(nsres)) {
356 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
357 if(NS_FAILED(nsres))
358 ERR("Observe failed: %08lx\n", nsres);
360 nsIObserver_Release(pStartNotif);
361 }else {
362 ERR("could not get appstartup-notifier: %08lx\n", nsres);
365 set_profile();
367 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
368 NULL, &IID_nsIMemory, (void**)&nsmem);
369 if(NS_FAILED(nsres))
370 ERR("Could not get nsIMemory: %08lx\n", nsres);
372 if(registrar) {
373 register_nsservice(registrar, pServMgr);
374 nsIComponentRegistrar_Release(registrar);
377 return TRUE;
380 void *nsalloc(size_t size)
382 return nsIMemory_Alloc(nsmem, size);
385 void nsfree(void *mem)
387 nsIMemory_Free(nsmem, mem);
390 void nsACString_Init(nsACString *str, const char *data)
392 NS_CStringContainerInit(str);
393 if(data)
394 NS_CStringSetData(str, data, PR_UINT32_MAX);
397 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
399 return NS_CStringGetData(str, data, termited);
402 void nsACString_Finish(nsACString *str)
404 NS_CStringContainerFinish(str);
407 void nsAString_Init(nsAString *str, const PRUnichar *data)
409 NS_StringContainerInit(str);
410 if(data)
411 NS_StringSetData(str, data, PR_UINT32_MAX);
414 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
416 return NS_StringGetData(str, data, termited);
419 void nsAString_Finish(nsAString *str)
421 NS_StringContainerFinish(str);
424 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
426 nsIStringInputStream *ret;
427 nsresult nsres;
429 if(!pCompMgr)
430 return NULL;
432 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
433 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
434 (void**)&ret);
435 if(NS_FAILED(nsres)) {
436 ERR("Could not get nsIStringInputStream\n");
437 return NULL;
440 nsres = nsIStringInputStream_SetData(ret, data, data_len);
441 if(NS_FAILED(nsres)) {
442 ERR("AdoptData failed: %08lx\n", nsres);
443 nsIStringInputStream_Release(ret);
444 return NULL;
447 return (nsIInputStream*)ret;
450 void close_gecko()
452 TRACE("()\n");
454 if(pCompMgr)
455 nsIComponentManager_Release(pCompMgr);
457 if(pServMgr)
458 nsIServiceManager_Release(pServMgr);
460 if(nsmem)
461 nsIMemory_Release(nsmem);
463 if(hXPCOM)
464 FreeLibrary(hXPCOM);
467 /**********************************************************
468 * nsIWebBrowserChrome interface
471 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
473 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
474 nsIIDRef riid, nsQIResult result)
476 NSContainer *This = NSWBCHROME_THIS(iface);
478 *result = NULL;
479 if(IsEqualGUID(&IID_nsISupports, riid)) {
480 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
481 *result = NSWBCHROME(This);
482 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
483 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
484 *result = NSWBCHROME(This);
485 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
486 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
487 *result = NSCML(This);
488 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
489 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
490 *result = NSURICL(This);
491 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
492 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
493 *result = NSEMBWNDS(This);
494 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
495 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
496 *result = NSTOOLTIP(This);
497 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
498 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
499 *result = NSIFACEREQ(This);
500 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
501 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
502 *result = NSWEAKREF(This);
503 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
504 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
505 *result = NSSUPWEAKREF(This);
508 if(*result) {
509 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
510 return NS_OK;
513 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
514 return NS_NOINTERFACE;
517 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
519 NSContainer *This = NSWBCHROME_THIS(iface);
520 LONG ref = InterlockedIncrement(&This->ref);
522 TRACE("(%p) ref=%ld\n", This, ref);
524 return ref;
527 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
529 NSContainer *This = NSWBCHROME_THIS(iface);
530 LONG ref = InterlockedDecrement(&This->ref);
532 TRACE("(%p) ref=%ld\n", This, ref);
534 if(!ref) {
535 if(This->parent)
536 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
537 mshtml_free(This);
540 return ref;
543 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
544 PRUint32 statusType, const PRUnichar *status)
546 NSContainer *This = NSWBCHROME_THIS(iface);
547 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
548 return NS_ERROR_NOT_IMPLEMENTED;
551 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
552 nsIWebBrowser **aWebBrowser)
554 NSContainer *This = NSWBCHROME_THIS(iface);
556 TRACE("(%p)->(%p)\n", This, aWebBrowser);
558 if(!aWebBrowser)
559 return NS_ERROR_INVALID_ARG;
561 if(This->webbrowser)
562 nsIWebBrowser_AddRef(This->webbrowser);
563 *aWebBrowser = This->webbrowser;
564 return S_OK;
567 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
568 nsIWebBrowser *aWebBrowser)
570 NSContainer *This = NSWBCHROME_THIS(iface);
572 TRACE("(%p)->(%p)\n", This, aWebBrowser);
574 if(aWebBrowser != This->webbrowser)
575 ERR("Wrong nsWebBrowser!\n");
577 return NS_OK;
580 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
581 PRUint32 *aChromeFlags)
583 NSContainer *This = NSWBCHROME_THIS(iface);
584 WARN("(%p)->(%p)\n", This, aChromeFlags);
585 return NS_ERROR_NOT_IMPLEMENTED;
588 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
589 PRUint32 aChromeFlags)
591 NSContainer *This = NSWBCHROME_THIS(iface);
592 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
593 return NS_ERROR_NOT_IMPLEMENTED;
596 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
598 NSContainer *This = NSWBCHROME_THIS(iface);
599 TRACE("(%p)\n", This);
600 return NS_ERROR_NOT_IMPLEMENTED;
603 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
604 PRInt32 aCX, PRInt32 aCY)
606 NSContainer *This = NSWBCHROME_THIS(iface);
607 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
608 return NS_ERROR_NOT_IMPLEMENTED;
611 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
613 NSContainer *This = NSWBCHROME_THIS(iface);
614 WARN("(%p)\n", This);
615 return NS_ERROR_NOT_IMPLEMENTED;
618 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
620 NSContainer *This = NSWBCHROME_THIS(iface);
621 WARN("(%p)->(%p)\n", This, _retval);
622 return NS_ERROR_NOT_IMPLEMENTED;
625 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
626 nsresult aStatus)
628 NSContainer *This = NSWBCHROME_THIS(iface);
629 WARN("(%p)->(%08lx)\n", This, aStatus);
630 return NS_ERROR_NOT_IMPLEMENTED;
633 #undef NSWBCHROME_THIS
635 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
636 nsWebBrowserChrome_QueryInterface,
637 nsWebBrowserChrome_AddRef,
638 nsWebBrowserChrome_Release,
639 nsWebBrowserChrome_SetStatus,
640 nsWebBrowserChrome_GetWebBrowser,
641 nsWebBrowserChrome_SetWebBrowser,
642 nsWebBrowserChrome_GetChromeFlags,
643 nsWebBrowserChrome_SetChromeFlags,
644 nsWebBrowserChrome_DestroyBrowserWindow,
645 nsWebBrowserChrome_SizeBrowserTo,
646 nsWebBrowserChrome_ShowAsModal,
647 nsWebBrowserChrome_IsWindowModal,
648 nsWebBrowserChrome_ExitModalEventLoop
651 /**********************************************************
652 * nsIContextMenuListener interface
655 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
657 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
658 nsIIDRef riid, nsQIResult result)
660 NSContainer *This = NSCML_THIS(iface);
661 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
664 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
666 NSContainer *This = NSCML_THIS(iface);
667 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
670 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
672 NSContainer *This = NSCML_THIS(iface);
673 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
676 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
677 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
679 NSContainer *This = NSCML_THIS(iface);
680 nsIDOMMouseEvent *event;
681 POINT pt;
682 DWORD dwID = CONTEXT_MENU_DEFAULT;
683 nsresult nsres;
685 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
687 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
688 if(NS_FAILED(nsres)) {
689 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
690 return nsres;
693 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
694 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
695 nsIDOMMouseEvent_Release(event);
697 switch(aContextFlags) {
698 case CONTEXT_NONE:
699 case CONTEXT_DOCUMENT:
700 case CONTEXT_TEXT:
701 dwID = CONTEXT_MENU_DEFAULT;
702 break;
703 case CONTEXT_IMAGE:
704 case CONTEXT_IMAGE|CONTEXT_LINK:
705 dwID = CONTEXT_MENU_IMAGE;
706 break;
707 case CONTEXT_LINK:
708 dwID = CONTEXT_MENU_ANCHOR;
709 break;
710 case CONTEXT_INPUT:
711 dwID = CONTEXT_MENU_CONTROL;
712 break;
713 default:
714 FIXME("aContextFlags=%08lx\n", aContextFlags);
717 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
719 return NS_OK;
722 #undef NSCML_THIS
724 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
725 nsContextMenuListener_QueryInterface,
726 nsContextMenuListener_AddRef,
727 nsContextMenuListener_Release,
728 nsContextMenuListener_OnShowContextMenu
731 /**********************************************************
732 * nsIURIContentListener interface
735 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
737 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
738 nsIIDRef riid, nsQIResult result)
740 NSContainer *This = NSURICL_THIS(iface);
741 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
744 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
746 NSContainer *This = NSURICL_THIS(iface);
747 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
750 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
752 NSContainer *This = NSURICL_THIS(iface);
753 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
756 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
757 nsIURI *aURI, PRBool *_retval)
759 NSContainer *This = NSURICL_THIS(iface);
760 nsIWineURI *wine_uri;
761 nsACString spec_str;
762 const char *spec;
763 nsresult nsres;
765 nsACString_Init(&spec_str, NULL);
766 nsIURI_GetSpec(aURI, &spec_str);
767 nsACString_GetData(&spec_str, &spec, NULL);
769 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
771 nsACString_Finish(&spec_str);
773 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
774 if(NS_FAILED(nsres)) {
775 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
776 return NS_ERROR_NOT_IMPLEMENTED;
779 nsIWineURI_SetNSContainer(wine_uri, This);
781 if(This->bscallback && This->bscallback->mon) {
782 LPWSTR url;
783 HRESULT hres;
785 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &url);
786 if(SUCCEEDED(hres)) {
787 IMoniker *mon = NULL;
789 hres = CreateURLMoniker(NULL, url, &mon);
790 if(SUCCEEDED(hres)) {
791 nsIWineURI_SetMoniker(wine_uri, mon);
792 IMoniker_Release(mon);
793 }else {
794 WARN("CreateURLMoniker failed: %08lx\n", hres);
796 }else {
797 WARN("GetDisplayName failed: %08lx\n", hres);
801 nsIWineURI_Release(wine_uri);
803 return NS_ERROR_NOT_IMPLEMENTED;
806 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
807 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
808 nsIStreamListener **aContentHandler, PRBool *_retval)
810 NSContainer *This = NSURICL_THIS(iface);
811 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
812 aRequest, aContentHandler, _retval);
813 return NS_ERROR_NOT_IMPLEMENTED;
816 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
817 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
819 NSContainer *This = NSURICL_THIS(iface);
821 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
823 /* FIXME: Should we do something here? */
824 *_retval = TRUE;
825 return NS_OK;
828 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
829 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
830 PRBool *_retval)
832 NSContainer *This = NSURICL_THIS(iface);
833 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
834 aDesiredContentType, _retval);
835 return NS_ERROR_NOT_IMPLEMENTED;
838 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
839 nsISupports **aLoadCookie)
841 NSContainer *This = NSURICL_THIS(iface);
842 WARN("(%p)->(%p)\n", This, aLoadCookie);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
847 nsISupports *aLoadCookie)
849 NSContainer *This = NSURICL_THIS(iface);
850 WARN("(%p)->(%p)\n", This, aLoadCookie);
851 return NS_ERROR_NOT_IMPLEMENTED;
854 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
855 nsIURIContentListener **aParentContentListener)
857 NSContainer *This = NSURICL_THIS(iface);
858 WARN("(%p)->(%p)\n", This, aParentContentListener);
859 return NS_ERROR_NOT_IMPLEMENTED;
862 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
863 nsIURIContentListener *aParentContentListener)
865 NSContainer *This = NSURICL_THIS(iface);
866 WARN("(%p)->(%p)\n", This, aParentContentListener);
867 return NS_ERROR_NOT_IMPLEMENTED;
870 #undef NSURICL_THIS
872 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
873 nsURIContentListener_QueryInterface,
874 nsURIContentListener_AddRef,
875 nsURIContentListener_Release,
876 nsURIContentListener_OnStartURIOpen,
877 nsURIContentListener_DoContent,
878 nsURIContentListener_IsPreferred,
879 nsURIContentListener_CanHandleContent,
880 nsURIContentListener_GetLoadCookie,
881 nsURIContentListener_SetLoadCookie,
882 nsURIContentListener_GetParentContentListener,
883 nsURIContentListener_SetParentContentListener
886 /**********************************************************
887 * nsIEmbeddinSiteWindow interface
890 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
892 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
893 nsIIDRef riid, nsQIResult result)
895 NSContainer *This = NSEMBWNDS_THIS(iface);
896 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
899 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
901 NSContainer *This = NSEMBWNDS_THIS(iface);
902 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
905 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
907 NSContainer *This = NSEMBWNDS_THIS(iface);
908 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
911 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
912 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
914 NSContainer *This = NSEMBWNDS_THIS(iface);
915 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
916 return NS_ERROR_NOT_IMPLEMENTED;
919 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
920 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
922 NSContainer *This = NSEMBWNDS_THIS(iface);
923 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
924 return NS_ERROR_NOT_IMPLEMENTED;
927 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
929 NSContainer *This = NSEMBWNDS_THIS(iface);
930 WARN("(%p)\n", This);
931 return NS_ERROR_NOT_IMPLEMENTED;
934 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
935 PRBool *aVisibility)
937 NSContainer *This = NSEMBWNDS_THIS(iface);
938 WARN("(%p)->(%p)\n", This, aVisibility);
939 return NS_ERROR_NOT_IMPLEMENTED;
942 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
943 PRBool aVisibility)
945 NSContainer *This = NSEMBWNDS_THIS(iface);
946 WARN("(%p)->(%x)\n", This, aVisibility);
947 return NS_ERROR_NOT_IMPLEMENTED;
950 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
951 PRUnichar **aTitle)
953 NSContainer *This = NSEMBWNDS_THIS(iface);
954 WARN("(%p)->(%p)\n", This, aTitle);
955 return NS_ERROR_NOT_IMPLEMENTED;
958 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
959 const PRUnichar *aTitle)
961 NSContainer *This = NSEMBWNDS_THIS(iface);
962 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
963 return NS_ERROR_NOT_IMPLEMENTED;
966 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
967 void **aSiteWindow)
969 NSContainer *This = NSEMBWNDS_THIS(iface);
971 TRACE("(%p)->(%p)\n", This, aSiteWindow);
973 *aSiteWindow = This->hwnd;
974 return NS_OK;
977 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
978 nsEmbeddingSiteWindow_QueryInterface,
979 nsEmbeddingSiteWindow_AddRef,
980 nsEmbeddingSiteWindow_Release,
981 nsEmbeddingSiteWindow_SetDimensions,
982 nsEmbeddingSiteWindow_GetDimensions,
983 nsEmbeddingSiteWindow_SetFocus,
984 nsEmbeddingSiteWindow_GetVisibility,
985 nsEmbeddingSiteWindow_SetVisibility,
986 nsEmbeddingSiteWindow_GetTitle,
987 nsEmbeddingSiteWindow_SetTitle,
988 nsEmbeddingSiteWindow_GetSiteWindow
991 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
993 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
994 nsQIResult result)
996 NSContainer *This = NSTOOLTIP_THIS(iface);
997 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1000 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1002 NSContainer *This = NSTOOLTIP_THIS(iface);
1003 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1006 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1008 NSContainer *This = NSTOOLTIP_THIS(iface);
1009 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1012 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1013 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1015 NSContainer *This = NSTOOLTIP_THIS(iface);
1017 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1019 return NS_OK;
1022 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1024 NSContainer *This = NSTOOLTIP_THIS(iface);
1026 hide_tooltip(This->doc);
1028 return NS_OK;
1031 #undef NSTOOLTIM_THIS
1033 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1034 nsTooltipListener_QueryInterface,
1035 nsTooltipListener_AddRef,
1036 nsTooltipListener_Release,
1037 nsTooltipListener_OnShowTooltip,
1038 nsTooltipListener_OnHideTooltip
1041 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1043 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1044 nsIIDRef riid, nsQIResult result)
1046 NSContainer *This = NSIFACEREQ_THIS(iface);
1047 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1050 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1052 NSContainer *This = NSIFACEREQ_THIS(iface);
1053 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1056 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1058 NSContainer *This = NSIFACEREQ_THIS(iface);
1059 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1062 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1063 nsIIDRef riid, nsQIResult result)
1065 NSContainer *This = NSIFACEREQ_THIS(iface);
1067 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1068 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1069 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1072 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1075 #undef NSIFACEREQ_THIS
1077 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1078 nsInterfaceRequestor_QueryInterface,
1079 nsInterfaceRequestor_AddRef,
1080 nsInterfaceRequestor_Release,
1081 nsInterfaceRequestor_GetInterface
1084 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1086 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1087 nsIIDRef riid, nsQIResult result)
1089 NSContainer *This = NSWEAKREF_THIS(iface);
1090 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1093 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1095 NSContainer *This = NSWEAKREF_THIS(iface);
1096 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1099 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1101 NSContainer *This = NSWEAKREF_THIS(iface);
1102 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1105 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1106 const nsIID *riid, void **result)
1108 NSContainer *This = NSWEAKREF_THIS(iface);
1109 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1112 #undef NSWEAKREF_THIS
1114 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1115 nsWeakReference_QueryInterface,
1116 nsWeakReference_AddRef,
1117 nsWeakReference_Release,
1118 nsWeakReference_QueryReferent
1121 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1123 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1124 nsIIDRef riid, nsQIResult result)
1126 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1127 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1130 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1132 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1133 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1136 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1138 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1139 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1142 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1143 nsIWeakReference **_retval)
1145 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1147 TRACE("(%p)->(%p)\n", This, _retval);
1149 nsIWeakReference_AddRef(NSWEAKREF(This));
1150 *_retval = NSWEAKREF(This);
1151 return NS_OK;
1154 #undef NSWEAKREF_THIS
1156 const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1157 nsSupportsWeakReference_QueryInterface,
1158 nsSupportsWeakReference_AddRef,
1159 nsSupportsWeakReference_Release,
1160 nsSupportsWeakReference_GetWeakReference
1164 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1166 nsIWebBrowserSetup *wbsetup;
1167 NSContainer *ret;
1168 nsresult nsres;
1170 if(!load_gecko())
1171 return NULL;
1173 ret = mshtml_alloc(sizeof(NSContainer));
1175 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1176 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1177 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1178 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1179 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1180 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1181 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1182 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1185 ret->doc = doc;
1186 ret->ref = 1;
1187 ret->bscallback = NULL;
1189 if(parent)
1190 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1191 ret->parent = parent;
1193 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1194 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1195 if(NS_FAILED(nsres))
1196 ERR("Creating WebBrowser failed: %08lx\n", nsres);
1198 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1199 if(NS_FAILED(nsres))
1200 ERR("SetContainerWindow failed: %08lx\n", nsres);
1202 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1203 (void**)&ret->window);
1204 if(NS_FAILED(nsres))
1205 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1207 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1208 (void**)&wbsetup);
1209 if(NS_SUCCEEDED(nsres)) {
1210 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1211 nsIWebBrowserSetup_Release(wbsetup);
1212 if(NS_FAILED(nsres))
1213 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1214 }else {
1215 ERR("Could not get nsIWebBrowserSetup interface\n");
1218 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1219 (void**)&ret->navigation);
1220 if(NS_FAILED(nsres))
1221 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1223 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1224 (void**)&ret->focus);
1225 if(NS_FAILED(nsres))
1226 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1228 if(!nscontainer_class)
1229 register_nscontainer_class();
1231 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1232 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1233 GetDesktopWindow(), NULL, hInst, ret);
1235 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1236 if(NS_SUCCEEDED(nsres)) {
1237 nsres = nsIBaseWindow_Create(ret->window);
1238 if(NS_FAILED(nsres))
1239 WARN("Creating window failed: %08lx\n", nsres);
1241 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1242 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1243 }else {
1244 ERR("InitWindow failed: %08lx\n", nsres);
1247 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1248 if(NS_FAILED(nsres))
1249 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1251 return ret;
1254 void NSContainer_Release(NSContainer *This)
1256 TRACE("(%p)\n", This);
1258 ShowWindow(This->hwnd, SW_HIDE);
1259 SetParent(This->hwnd, NULL);
1261 nsIBaseWindow_SetVisibility(This->window, FALSE);
1262 nsIBaseWindow_Destroy(This->window);
1264 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1266 nsIWebBrowser_Release(This->webbrowser);
1267 This->webbrowser = NULL;
1269 nsIWebNavigation_Release(This->navigation);
1270 This->navigation = NULL;
1272 nsIBaseWindow_Release(This->window);
1273 This->window = NULL;
1275 nsIWebBrowserFocus_Release(This->focus);
1276 This->focus = NULL;
1278 if(This->hwnd) {
1279 DestroyWindow(This->hwnd);
1280 This->hwnd = NULL;
1283 nsIWebBrowserChrome_Release(NSWBCHROME(This));