2 * Copyright 2005 Jacek Caban
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
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_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
42 #define APPSTARTUP_TOPIC "app-startup"
44 #define PR_UINT32_MAX 0xffffffff
46 typedef struct nsACString {
52 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
53 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
54 static nsresult (*NS_StringContainerInit)(nsString*);
55 static nsresult (*NS_CStringContainerInit)(nsACString*);
56 static nsresult (*NS_StringContainerFinish)(nsString*);
57 static nsresult (*NS_CStringContainerFinish)(nsACString*);
58 static nsresult (*NS_StringSetData)(nsString*,const PRUnichar*,PRUint32);
59 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
60 static nsresult (*NS_NewLocalFile)(const nsString*,PRBool,nsIFile**);
61 static PRUint32 (*NS_CStringGetData)(nsACString*,const char**,PRBool*);
63 static HINSTANCE hXPCOM = NULL;
65 static nsIServiceManager *pServMgr = NULL;
66 static nsIComponentManager *pCompMgr = NULL;
67 static nsIIOService *pIOService = NULL;
69 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
71 static ATOM nscontainer_class;
73 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
78 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
80 if(msg == WM_CREATE) {
81 This = *(HTMLDocument**)lParam;
82 SetPropW(hwnd, wszTHIS, This);
84 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
89 TRACE("(%p)->(WM_SIZE)\n", This);
91 nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
92 LOWORD(lParam), HIWORD(lParam), TRUE);
94 WARN("SetSize failed: %08lx\n", nsres);
97 return DefWindowProcW(hwnd, msg, wParam, lParam);
101 static void register_nscontainer_class(void)
103 static WNDCLASSEXW wndclass = {
107 0, 0, NULL, NULL, NULL, NULL, NULL,
111 wndclass.hInstance = hInst;
112 nscontainer_class = RegisterClassExW(&wndclass);
115 static BOOL get_mozilla_path(PRUnichar *gre_path)
117 DWORD res, type, i, size = MAX_PATH;
118 HKEY mozilla_key, hkey;
122 static const WCHAR wszGreKey[] =
123 {'S','o','f','t','w','a','r','e','\\',
124 'm','o','z','i','l','l','a','.','o','r','g','\\',
127 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
129 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
130 if(res != ERROR_SUCCESS) {
131 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
135 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
136 RegOpenKeyW(mozilla_key, key_name, &hkey);
137 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
138 if(res == ERROR_SUCCESS)
143 RegCloseKey(mozilla_key);
147 static BOOL get_mozctl_path(PRUnichar *gre_path)
150 DWORD res, type, size = MAX_PATH;
152 static const WCHAR wszMozCtlKey[] =
153 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
154 static const WCHAR wszBinDirectoryPath[] =
155 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
156 static const WCHAR wszMozCtlClsidKey[] =
157 {'C','L','S','I','D','\\',
158 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
159 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
160 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
162 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
163 if(res == ERROR_SUCCESS) {
164 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
165 if(res == ERROR_SUCCESS)
168 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
171 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
172 if(res == ERROR_SUCCESS) {
173 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
174 if(res == ERROR_SUCCESS) {
176 if((ptr = strrchrW(gre_path, '\\')))
180 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
184 TRACE("Could not find Mozilla ActiveX Control\n");
189 static BOOL load_gecko()
192 nsIObserver *pStartNotif;
195 PRUnichar gre_path[MAX_PATH];
196 WCHAR path_env[MAX_PATH];
199 static BOOL tried_load = FALSE;
200 static const WCHAR wszPATH[] = {'P','A','T','H',0};
201 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
206 return pCompMgr != NULL;
209 if(!get_mozctl_path(gre_path) && !get_mozilla_path(gre_path)) {
210 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
214 TRACE("found path %s\n", debugstr_w(gre_path));
216 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
217 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
218 len = strlenW(path_env);
219 path_env[len++] = ';';
220 strcpyW(path_env+len, gre_path);
221 SetEnvironmentVariableW(wszPATH, path_env);
223 hXPCOM = LoadLibraryW(strXPCOM);
225 ERR("Could not load XPCOM: %ld\n", GetLastError());
229 #define NS_DLSYM(func) \
230 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
232 ERR("Could not GetProcAddress(" #func ") failed\n")
234 NS_DLSYM(NS_InitXPCOM2);
235 NS_DLSYM(NS_ShutdownXPCOM);
236 NS_DLSYM(NS_StringContainerInit);
237 NS_DLSYM(NS_CStringContainerInit);
238 NS_DLSYM(NS_StringContainerFinish);
239 NS_DLSYM(NS_CStringContainerFinish);
240 NS_DLSYM(NS_StringSetData);
241 NS_DLSYM(NS_CStringSetData);
242 NS_DLSYM(NS_NewLocalFile);
243 NS_DLSYM(NS_CStringGetData);
247 NS_StringContainerInit(&path);
248 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
249 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
250 NS_StringContainerFinish(&path);
251 if(NS_FAILED(nsres)) {
252 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
257 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
258 if(NS_FAILED(nsres)) {
259 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
264 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
266 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
268 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
269 NULL, &IID_nsIObserver, (void**)&pStartNotif);
270 if(NS_SUCCEEDED(nsres)) {
271 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
273 ERR("Observe failed: %08lx\n", nsres);
275 nsIObserver_Release(pStartNotif);
277 ERR("could not get appstartup-notifier: %08lx\n", nsres);
283 nsACString *nsACString_Create(void)
286 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
287 NS_CStringContainerInit(ret);
291 void nsACString_SetData(nsACString *str, const char *data)
293 NS_CStringSetData(str, data, PR_UINT32_MAX);
296 static PRUint32 nsACString_GetData(nsACString *str, const char **data, PRBool *termited)
298 return NS_CStringGetData(str, data, termited);
301 void nsACString_Destroy(nsACString *str)
303 NS_CStringContainerFinish(str);
304 HeapFree(GetProcessHeap(), 0, str);
312 nsIComponentManager_Release(pCompMgr);
315 nsIServiceManager_Release(pServMgr);
321 nsIURI *get_nsIURI(LPCWSTR url)
330 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_IOSERVICE_CONTRACTID,
331 &IID_nsIIOService, (void**)&pIOService);
333 ERR("Failed to create nsIOService: %08lx\n", nsres);
336 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
337 urla = HeapAlloc(GetProcessHeap(), 0, len);
338 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
340 acstr = nsACString_Create();
341 nsACString_SetData(acstr, urla);
343 nsres = nsIIOService_NewURI(pIOService, acstr, NULL, NULL, &ret);
345 FIXME("NewURI failed: %08lx\n", nsres);
347 nsACString_Destroy(acstr);
348 HeapFree(GetProcessHeap(), 0, urla);
353 /**********************************************************
354 * nsIWebBrowserChrome interface
357 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
359 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
360 nsIIDRef riid, nsQIResult result)
362 NSContainer *This = NSWBCHROME_THIS(iface);
365 if(IsEqualGUID(&IID_nsISupports, riid)) {
366 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
367 *result = NSWBCHROME(This);
368 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
369 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
370 *result = NSWBCHROME(This);
371 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
372 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
373 *result = NSCML(This);
379 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
380 return NS_NOINTERFACE;
383 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
385 NSContainer *This = NSWBCHROME_THIS(iface);
386 TRACE("(%p)\n", This);
387 return 2; /* Should we implement ref conunting here? */
390 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
392 NSContainer *This = NSWBCHROME_THIS(iface);
393 TRACE("(%p)\n", This);
397 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
398 PRUint32 statusType, const PRUnichar *status)
400 NSContainer *This = NSWBCHROME_THIS(iface);
401 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
402 return NS_ERROR_NOT_IMPLEMENTED;
405 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
406 nsIWebBrowser **aWebBrowser)
408 NSContainer *This = NSWBCHROME_THIS(iface);
410 TRACE("(%p)->(%p)\n", This, aWebBrowser);
413 return NS_ERROR_INVALID_ARG;
415 *aWebBrowser = This->webbrowser;
419 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
420 nsIWebBrowser *aWebBrowser)
422 NSContainer *This = NSWBCHROME_THIS(iface);
424 TRACE("(%p)->(%p)\n", This, aWebBrowser);
426 if(aWebBrowser != This->webbrowser)
427 ERR("Wrong nsWebBrowser!\n");
432 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
433 PRUint32 *aChromeFlags)
435 NSContainer *This = NSWBCHROME_THIS(iface);
436 WARN("(%p)->(%p)\n", This, aChromeFlags);
437 return NS_ERROR_NOT_IMPLEMENTED;
440 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
441 PRUint32 aChromeFlags)
443 NSContainer *This = NSWBCHROME_THIS(iface);
444 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
445 return NS_ERROR_NOT_IMPLEMENTED;
448 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
450 NSContainer *This = NSWBCHROME_THIS(iface);
451 TRACE("(%p)\n", This);
452 return NS_ERROR_NOT_IMPLEMENTED;
455 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
456 PRInt32 aCX, PRInt32 aCY)
458 NSContainer *This = NSWBCHROME_THIS(iface);
459 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
460 return NS_ERROR_NOT_IMPLEMENTED;
463 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
465 NSContainer *This = NSWBCHROME_THIS(iface);
466 WARN("(%p)\n", This);
467 return NS_ERROR_NOT_IMPLEMENTED;
470 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
472 NSContainer *This = NSWBCHROME_THIS(iface);
473 WARN("(%p)->(%p)\n", This, _retval);
474 return NS_ERROR_NOT_IMPLEMENTED;
477 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
480 NSContainer *This = NSWBCHROME_THIS(iface);
481 WARN("(%p)->(%08lx)\n", This, aStatus);
482 return NS_ERROR_NOT_IMPLEMENTED;
485 #undef NSWBCHROME_THIS
487 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
488 nsWebBrowserChrome_QueryInterface,
489 nsWebBrowserChrome_AddRef,
490 nsWebBrowserChrome_Release,
491 nsWebBrowserChrome_SetStatus,
492 nsWebBrowserChrome_GetWebBrowser,
493 nsWebBrowserChrome_SetWebBrowser,
494 nsWebBrowserChrome_GetChromeFlags,
495 nsWebBrowserChrome_SetChromeFlags,
496 nsWebBrowserChrome_DestroyBrowserWindow,
497 nsWebBrowserChrome_SizeBrowserTo,
498 nsWebBrowserChrome_ShowAsModal,
499 nsWebBrowserChrome_IsWindowModal,
500 nsWebBrowserChrome_ExitModalEventLoop
503 /**********************************************************
504 * nsIContextMenuListener interface
507 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
509 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
510 nsIIDRef riid, nsQIResult result)
512 NSContainer *This = NSCML_THIS(iface);
513 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
516 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
518 NSContainer *This = NSCML_THIS(iface);
519 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
522 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
524 NSContainer *This = NSCML_THIS(iface);
525 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
528 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
529 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
531 NSContainer *This = NSCML_THIS(iface);
532 nsIDOMMouseEvent *event;
534 DWORD dwID = CONTEXT_MENU_DEFAULT;
537 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
539 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
540 if(NS_FAILED(nsres)) {
541 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
545 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
546 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
547 nsIDOMMouseEvent_Release(event);
549 switch(aContextFlags) {
551 case CONTEXT_DOCUMENT:
553 dwID = CONTEXT_MENU_DEFAULT;
556 case CONTEXT_IMAGE|CONTEXT_LINK:
557 dwID = CONTEXT_MENU_IMAGE;
560 dwID = CONTEXT_MENU_ANCHOR;
563 dwID = CONTEXT_MENU_CONTROL;
566 FIXME("aContextFlags=%08lx\n", aContextFlags);
569 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
576 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
577 nsContextMenuListener_QueryInterface,
578 nsContextMenuListener_AddRef,
579 nsContextMenuListener_Release,
580 nsContextMenuListener_OnShowContextMenu
583 /**********************************************************
584 * nsIURIContentListener interface
587 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
589 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
590 nsIIDRef riid, nsQIResult result)
592 NSContainer *This = NSURICL_THIS(iface);
593 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
596 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
598 NSContainer *This = NSURICL_THIS(iface);
599 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
602 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
604 NSContainer *This = NSURICL_THIS(iface);
605 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
608 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface, nsIURI *aURI,
611 NSContainer *This = NSURICL_THIS(iface);
614 nsACString *spec_str = nsACString_Create();
616 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
618 nsres = nsIURI_GetSpec(aURI, spec_str);
619 if(NS_SUCCEEDED(nsres)) {
620 const char *spec = NULL;
624 nsACString_GetData(spec_str, &spec, NULL);
626 len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
627 specw = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
628 MultiByteToWideChar(CP_ACP, 0, spec, -1, specw, -1);
630 if(strcmpW(This->url, specw)) /* hack */
631 do_load = HTMLDocument_OnLoad(This->doc, specw);
633 HeapFree(GetProcessHeap(), 0, specw);
635 ERR("GetSpec failed: %08lx\n", nsres);
638 nsACString_Destroy(spec_str);
645 return NS_ERROR_NOT_IMPLEMENTED;
648 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
649 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
650 nsIStreamListener **aContentHandler, PRBool *_retval)
652 NSContainer *This = NSURICL_THIS(iface);
653 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
654 aRequest, aContentHandler, _retval);
655 return NS_ERROR_NOT_IMPLEMENTED;
658 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
659 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
661 NSContainer *This = NSURICL_THIS(iface);
663 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
665 /* FIXME: Should we do something here? */
670 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
671 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
674 NSContainer *This = NSURICL_THIS(iface);
675 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
676 aDesiredContentType, _retval);
677 return NS_ERROR_NOT_IMPLEMENTED;
680 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
681 nsISupports **aLoadCookie)
683 NSContainer *This = NSURICL_THIS(iface);
684 WARN("(%p)->(%p)\n", This, aLoadCookie);
685 return NS_ERROR_NOT_IMPLEMENTED;
688 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
689 nsISupports *aLoadCookie)
691 NSContainer *This = NSURICL_THIS(iface);
692 WARN("(%p)->(%p)\n", This, aLoadCookie);
693 return NS_ERROR_NOT_IMPLEMENTED;
696 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
697 nsIURIContentListener **aParentContentListener)
699 NSContainer *This = NSURICL_THIS(iface);
700 WARN("(%p)->(%p)\n", This, aParentContentListener);
701 return NS_ERROR_NOT_IMPLEMENTED;
704 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
705 nsIURIContentListener *aParentContentListener)
707 NSContainer *This = NSURICL_THIS(iface);
708 WARN("(%p)->(%p)\n", This, aParentContentListener);
709 return NS_ERROR_NOT_IMPLEMENTED;
714 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
715 nsURIContentListener_QueryInterface,
716 nsURIContentListener_AddRef,
717 nsURIContentListener_Release,
718 nsURIContentListener_OnStartURIOpen,
719 nsURIContentListener_DoContent,
720 nsURIContentListener_IsPreferred,
721 nsURIContentListener_CanHandleContent,
722 nsURIContentListener_GetLoadCookie,
723 nsURIContentListener_SetLoadCookie,
724 nsURIContentListener_GetParentContentListener,
725 nsURIContentListener_SetParentContentListener
728 void HTMLDocument_NSContainer_Init(HTMLDocument *This)
730 nsIWebBrowserSetup *wbsetup;
733 This->nscontainer = NULL;
738 This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
740 This->nscontainer->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
741 This->nscontainer->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
742 This->nscontainer->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
744 This->nscontainer->doc = This;
746 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
747 NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
749 ERR("Creating WebBrowser failed: %08lx\n", nsres);
751 nsres = nsIWebBrowser_SetContainerWindow(This->nscontainer->webbrowser,
752 NSWBCHROME(This->nscontainer));
754 ERR("SetContainerWindow failed: %08lx\n", nsres);
756 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
757 (void**)&This->nscontainer->window);
759 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
761 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
762 &IID_nsIWebBrowserSetup, (void**)&wbsetup);
763 if(NS_SUCCEEDED(nsres)) {
764 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
766 ERR("SetProperty failed: %08lx\n", nsres);
767 nsIWebBrowserSetup_Release(wbsetup);
769 ERR("Could not get nsIWebBrowserSetup interface\n");
772 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
773 (void**)&This->nscontainer->navigation);
775 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
777 nsres = nsIWebBrowserFocus_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserFocus,
778 (void**)&This->nscontainer->focus);
780 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
783 nsres = nsIWebBrowserStream_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserStream,
784 (void**)&This->nscontainer->stream);
786 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
788 This->nscontainer->stream = NULL;
791 if(!nscontainer_class)
792 register_nscontainer_class();
794 This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
795 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
796 GetDesktopWindow(), NULL, hInst, This);
798 nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
800 if(NS_SUCCEEDED(nsres)) {
801 nsres = nsIBaseWindow_Create(This->nscontainer->window);
803 WARN("Creating window failed: %08lx\n", nsres);
805 nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
806 nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
808 ERR("InitWindow failed: %08lx\n", nsres);
811 nsres = nsIWebBrowser_SetParentURIContentListener(This->nscontainer->webbrowser,
812 NSURICL(This->nscontainer));
814 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
816 This->nscontainer->url = NULL;
819 void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
821 TRACE("(%p)\n", This);
823 nsIWebBrowser_Release(This->nscontainer->webbrowser);
824 nsIWebNavigation_Release(This->nscontainer->navigation);
825 nsIBaseWindow_Release(This->nscontainer->window);
827 if(This->nscontainer->stream)
828 nsIWebBrowserStream_Release(This->nscontainer->stream);
830 HeapFree(GetProcessHeap(), 0, This->nscontainer);
832 if(This->nscontainer->url)
833 CoTaskMemFree(This->nscontainer->url);