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};
157 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMozCtlKey
, &hkey
);
158 if(res
!= ERROR_SUCCESS
) {
159 TRACE("Could not open key %s\n", debugstr_w(wszMozCtlKey
));
163 res
= RegQueryValueExW(hkey
, wszBinDirectoryPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
164 if(res
!= ERROR_SUCCESS
) {
165 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath
));
172 static BOOL
load_gecko()
175 nsIObserver
*pStartNotif
;
178 PRUnichar gre_path
[MAX_PATH
];
179 WCHAR path_env
[MAX_PATH
];
182 static BOOL tried_load
= FALSE
;
183 static const WCHAR wszPATH
[] = {'P','A','T','H',0};
184 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
189 return pCompMgr
!= NULL
;
192 if(!get_mozctl_path(gre_path
) && !get_mozilla_path(gre_path
)) {
193 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
197 TRACE("found path %s\n", debugstr_w(gre_path
));
199 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
200 GetEnvironmentVariableW(wszPATH
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
201 len
= strlenW(path_env
);
202 path_env
[len
++] = ';';
203 strcpyW(path_env
+len
, gre_path
);
204 SetEnvironmentVariableW(wszPATH
, path_env
);
206 hXPCOM
= LoadLibraryW(strXPCOM
);
208 ERR("Could not load XPCOM: %ld\n", GetLastError());
212 #define NS_DLSYM(func) \
213 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
215 ERR("Could not GetProcAddress(" #func ") failed\n")
217 NS_DLSYM(NS_InitXPCOM2
);
218 NS_DLSYM(NS_ShutdownXPCOM
);
219 NS_DLSYM(NS_StringContainerInit
);
220 NS_DLSYM(NS_CStringContainerInit
);
221 NS_DLSYM(NS_StringContainerFinish
);
222 NS_DLSYM(NS_CStringContainerFinish
);
223 NS_DLSYM(NS_StringSetData
);
224 NS_DLSYM(NS_CStringSetData
);
225 NS_DLSYM(NS_NewLocalFile
);
226 NS_DLSYM(NS_CStringGetData
);
230 NS_StringContainerInit(&path
);
231 NS_StringSetData(&path
, gre_path
, PR_UINT32_MAX
);
232 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
233 NS_StringContainerFinish(&path
);
234 if(NS_FAILED(nsres
)) {
235 ERR("NS_NewLocalFile failed: %08lx\n", nsres
);
240 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
241 if(NS_FAILED(nsres
)) {
242 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres
);
247 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
249 ERR("Could not get nsIComponentManager: %08lx\n", nsres
);
251 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
252 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
253 if(NS_SUCCEEDED(nsres
)) {
254 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
256 ERR("Observe failed: %08lx\n", nsres
);
258 nsIObserver_Release(pStartNotif
);
260 ERR("could not get appstartup-notifier: %08lx\n", nsres
);
266 nsACString
*nsACString_Create(void)
269 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString
));
270 NS_CStringContainerInit(ret
);
274 void nsACString_SetData(nsACString
*str
, const char *data
)
276 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
279 static PRUint32
nsACString_GetData(nsACString
*str
, const char **data
, PRBool
*termited
)
281 return NS_CStringGetData(str
, data
, termited
);
284 void nsACString_Destroy(nsACString
*str
)
286 NS_CStringContainerFinish(str
);
287 HeapFree(GetProcessHeap(), 0, str
);
295 nsIComponentManager_Release(pCompMgr
);
298 nsIServiceManager_Release(pServMgr
);
304 nsIURI
*get_nsIURI(LPCWSTR url
)
313 nsres
= nsIServiceManager_GetServiceByContactID(pServMgr
, NS_IOSERVICE_CONTRACTID
,
314 &IID_nsIIOService
, (void**)&pIOService
);
316 ERR("Failed to create nsIOService: %08lx\n", nsres
);
319 len
= WideCharToMultiByte(CP_ACP
, 0, url
, -1, NULL
, -1, NULL
, NULL
);
320 urla
= HeapAlloc(GetProcessHeap(), 0, len
);
321 WideCharToMultiByte(CP_ACP
, 0, url
, -1, urla
, -1, NULL
, NULL
);
323 acstr
= nsACString_Create();
324 nsACString_SetData(acstr
, urla
);
326 nsres
= nsIIOService_NewURI(pIOService
, acstr
, NULL
, NULL
, &ret
);
328 FIXME("NewURI failed: %08lx\n", nsres
);
330 nsACString_Destroy(acstr
);
331 HeapFree(GetProcessHeap(), 0, urla
);
336 /**********************************************************
337 * nsIWebBrowserChrome interface
340 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
342 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
343 nsIIDRef riid
, nsQIResult result
)
345 NSContainer
*This
= NSWBCHROME_THIS(iface
);
348 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
349 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
350 *result
= NSWBCHROME(This
);
351 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
352 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
353 *result
= NSWBCHROME(This
);
354 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
355 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
356 *result
= NSCML(This
);
362 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
363 return NS_NOINTERFACE
;
366 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
368 NSContainer
*This
= NSWBCHROME_THIS(iface
);
369 TRACE("(%p)\n", This
);
370 return 2; /* Should we implement ref conunting here? */
373 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
375 NSContainer
*This
= NSWBCHROME_THIS(iface
);
376 TRACE("(%p)\n", This
);
380 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
381 PRUint32 statusType
, const PRUnichar
*status
)
383 NSContainer
*This
= NSWBCHROME_THIS(iface
);
384 TRACE("(%p)->(%ld %s)\n", This
, statusType
, debugstr_w(status
));
385 return NS_ERROR_NOT_IMPLEMENTED
;
388 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
389 nsIWebBrowser
**aWebBrowser
)
391 NSContainer
*This
= NSWBCHROME_THIS(iface
);
393 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
396 return NS_ERROR_INVALID_ARG
;
398 *aWebBrowser
= This
->webbrowser
;
402 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
403 nsIWebBrowser
*aWebBrowser
)
405 NSContainer
*This
= NSWBCHROME_THIS(iface
);
407 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
409 if(aWebBrowser
!= This
->webbrowser
)
410 ERR("Wrong nsWebBrowser!\n");
415 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
416 PRUint32
*aChromeFlags
)
418 NSContainer
*This
= NSWBCHROME_THIS(iface
);
419 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
420 return NS_ERROR_NOT_IMPLEMENTED
;
423 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
424 PRUint32 aChromeFlags
)
426 NSContainer
*This
= NSWBCHROME_THIS(iface
);
427 WARN("(%p)->(%08lx)\n", This
, aChromeFlags
);
428 return NS_ERROR_NOT_IMPLEMENTED
;
431 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
433 NSContainer
*This
= NSWBCHROME_THIS(iface
);
434 TRACE("(%p)\n", This
);
435 return NS_ERROR_NOT_IMPLEMENTED
;
438 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
439 PRInt32 aCX
, PRInt32 aCY
)
441 NSContainer
*This
= NSWBCHROME_THIS(iface
);
442 WARN("(%p)->(%ld %ld)\n", This
, aCX
, aCY
);
443 return NS_ERROR_NOT_IMPLEMENTED
;
446 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
448 NSContainer
*This
= NSWBCHROME_THIS(iface
);
449 WARN("(%p)\n", This
);
450 return NS_ERROR_NOT_IMPLEMENTED
;
453 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
455 NSContainer
*This
= NSWBCHROME_THIS(iface
);
456 WARN("(%p)->(%p)\n", This
, _retval
);
457 return NS_ERROR_NOT_IMPLEMENTED
;
460 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
463 NSContainer
*This
= NSWBCHROME_THIS(iface
);
464 WARN("(%p)->(%08lx)\n", This
, aStatus
);
465 return NS_ERROR_NOT_IMPLEMENTED
;
468 #undef NSWBCHROME_THIS
470 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
471 nsWebBrowserChrome_QueryInterface
,
472 nsWebBrowserChrome_AddRef
,
473 nsWebBrowserChrome_Release
,
474 nsWebBrowserChrome_SetStatus
,
475 nsWebBrowserChrome_GetWebBrowser
,
476 nsWebBrowserChrome_SetWebBrowser
,
477 nsWebBrowserChrome_GetChromeFlags
,
478 nsWebBrowserChrome_SetChromeFlags
,
479 nsWebBrowserChrome_DestroyBrowserWindow
,
480 nsWebBrowserChrome_SizeBrowserTo
,
481 nsWebBrowserChrome_ShowAsModal
,
482 nsWebBrowserChrome_IsWindowModal
,
483 nsWebBrowserChrome_ExitModalEventLoop
486 /**********************************************************
487 * nsIContextMenuListener interface
490 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
492 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
493 nsIIDRef riid
, nsQIResult result
)
495 NSContainer
*This
= NSCML_THIS(iface
);
496 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
499 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
501 NSContainer
*This
= NSCML_THIS(iface
);
502 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
505 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
507 NSContainer
*This
= NSCML_THIS(iface
);
508 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
511 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
512 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
514 NSContainer
*This
= NSCML_THIS(iface
);
515 nsIDOMMouseEvent
*event
;
517 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
520 TRACE("(%p)->(%08lx %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
522 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
523 if(NS_FAILED(nsres
)) {
524 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres
);
528 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
529 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
530 nsIDOMMouseEvent_Release(event
);
532 switch(aContextFlags
) {
534 case CONTEXT_DOCUMENT
:
536 dwID
= CONTEXT_MENU_DEFAULT
;
539 case CONTEXT_IMAGE
|CONTEXT_LINK
:
540 dwID
= CONTEXT_MENU_IMAGE
;
543 dwID
= CONTEXT_MENU_ANCHOR
;
546 dwID
= CONTEXT_MENU_CONTROL
;
549 FIXME("aContextFlags=%08lx\n", aContextFlags
);
552 HTMLDocument_ShowContextMenu(This
->doc
, dwID
, &pt
);
559 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
560 nsContextMenuListener_QueryInterface
,
561 nsContextMenuListener_AddRef
,
562 nsContextMenuListener_Release
,
563 nsContextMenuListener_OnShowContextMenu
566 /**********************************************************
567 * nsIURIContentListener interface
570 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
572 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
573 nsIIDRef riid
, nsQIResult result
)
575 NSContainer
*This
= NSURICL_THIS(iface
);
576 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
579 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
581 NSContainer
*This
= NSURICL_THIS(iface
);
582 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
585 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
587 NSContainer
*This
= NSURICL_THIS(iface
);
588 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
591 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
, nsIURI
*aURI
,
594 NSContainer
*This
= NSURICL_THIS(iface
);
597 nsACString
*spec_str
= nsACString_Create();
599 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
601 nsres
= nsIURI_GetSpec(aURI
, spec_str
);
602 if(NS_SUCCEEDED(nsres
)) {
603 const char *spec
= NULL
;
607 nsACString_GetData(spec_str
, &spec
, NULL
);
609 len
= MultiByteToWideChar(CP_ACP
, 0, spec
, -1, NULL
, 0);
610 specw
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
611 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, specw
, -1);
613 if(strcmpW(This
->url
, specw
)) /* hack */
614 do_load
= HTMLDocument_OnLoad(This
->doc
, specw
);
616 HeapFree(GetProcessHeap(), 0, specw
);
618 ERR("GetSpec failed: %08lx\n", nsres
);
621 nsACString_Destroy(spec_str
);
628 return NS_ERROR_NOT_IMPLEMENTED
;
631 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
632 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
633 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
635 NSContainer
*This
= NSURICL_THIS(iface
);
636 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
637 aRequest
, aContentHandler
, _retval
);
638 return NS_ERROR_NOT_IMPLEMENTED
;
641 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
642 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
644 NSContainer
*This
= NSURICL_THIS(iface
);
646 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
648 /* FIXME: Should we do something here? */
653 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
654 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
657 NSContainer
*This
= NSURICL_THIS(iface
);
658 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
659 aDesiredContentType
, _retval
);
660 return NS_ERROR_NOT_IMPLEMENTED
;
663 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
664 nsISupports
**aLoadCookie
)
666 NSContainer
*This
= NSURICL_THIS(iface
);
667 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
668 return NS_ERROR_NOT_IMPLEMENTED
;
671 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
672 nsISupports
*aLoadCookie
)
674 NSContainer
*This
= NSURICL_THIS(iface
);
675 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
676 return NS_ERROR_NOT_IMPLEMENTED
;
679 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
680 nsIURIContentListener
**aParentContentListener
)
682 NSContainer
*This
= NSURICL_THIS(iface
);
683 WARN("(%p)->(%p)\n", This
, aParentContentListener
);
684 return NS_ERROR_NOT_IMPLEMENTED
;
687 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
688 nsIURIContentListener
*aParentContentListener
)
690 NSContainer
*This
= NSURICL_THIS(iface
);
691 WARN("(%p)->(%p)\n", This
, aParentContentListener
);
692 return NS_ERROR_NOT_IMPLEMENTED
;
697 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
698 nsURIContentListener_QueryInterface
,
699 nsURIContentListener_AddRef
,
700 nsURIContentListener_Release
,
701 nsURIContentListener_OnStartURIOpen
,
702 nsURIContentListener_DoContent
,
703 nsURIContentListener_IsPreferred
,
704 nsURIContentListener_CanHandleContent
,
705 nsURIContentListener_GetLoadCookie
,
706 nsURIContentListener_SetLoadCookie
,
707 nsURIContentListener_GetParentContentListener
,
708 nsURIContentListener_SetParentContentListener
711 void HTMLDocument_NSContainer_Init(HTMLDocument
*This
)
713 nsIWebBrowserSetup
*wbsetup
;
716 This
->nscontainer
= NULL
;
721 This
->nscontainer
= HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer
));
723 This
->nscontainer
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
724 This
->nscontainer
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
725 This
->nscontainer
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
727 This
->nscontainer
->doc
= This
;
729 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
730 NULL
, &IID_nsIWebBrowser
, (void**)&This
->nscontainer
->webbrowser
);
732 ERR("Creating WebBrowser failed: %08lx\n", nsres
);
734 nsres
= nsIWebBrowser_SetContainerWindow(This
->nscontainer
->webbrowser
,
735 NSWBCHROME(This
->nscontainer
));
737 ERR("SetContainerWindow failed: %08lx\n", nsres
);
739 nsres
= nsIWebBrowser_QueryInterface(This
->nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
740 (void**)&This
->nscontainer
->window
);
742 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres
);
744 nsres
= nsIWebBrowser_QueryInterface(This
->nscontainer
->webbrowser
,
745 &IID_nsIWebBrowserSetup
, (void**)&wbsetup
);
746 if(NS_SUCCEEDED(nsres
)) {
747 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, TRUE
);
749 ERR("SetProperty failed: %08lx\n", nsres
);
750 nsIWebBrowserSetup_Release(wbsetup
);
752 ERR("Could not get nsIWebBrowserSetup interface\n");
755 nsres
= nsIWebBrowser_QueryInterface(This
->nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
756 (void**)&This
->nscontainer
->navigation
);
758 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres
);
760 nsres
= nsIWebBrowserFocus_QueryInterface(This
->nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
761 (void**)&This
->nscontainer
->focus
);
763 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres
);
766 nsres
= nsIWebBrowserStream_QueryInterface(This
->nscontainer
->webbrowser
, &IID_nsIWebBrowserStream
,
767 (void**)&This
->nscontainer
->stream
);
769 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres
);
771 This
->nscontainer
->stream
= NULL
;
774 if(!nscontainer_class
)
775 register_nscontainer_class();
777 This
->nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
778 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
779 GetDesktopWindow(), NULL
, hInst
, This
);
781 nsres
= nsIBaseWindow_InitWindow(This
->nscontainer
->window
, This
->nscontainer
->hwnd
, NULL
,
783 if(NS_SUCCEEDED(nsres
)) {
784 nsres
= nsIBaseWindow_Create(This
->nscontainer
->window
);
786 WARN("Creating window failed: %08lx\n", nsres
);
788 nsIBaseWindow_SetVisibility(This
->nscontainer
->window
, FALSE
);
789 nsIBaseWindow_SetEnabled(This
->nscontainer
->window
, FALSE
);
791 ERR("InitWindow failed: %08lx\n", nsres
);
794 nsres
= nsIWebBrowser_SetParentURIContentListener(This
->nscontainer
->webbrowser
,
795 NSURICL(This
->nscontainer
));
797 ERR("SetParentURIContentListener failed: %08lx\n", nsres
);
799 This
->nscontainer
->url
= NULL
;
802 void HTMLDocument_NSContainer_Destroy(HTMLDocument
*This
)
804 TRACE("(%p)\n", This
);
806 nsIWebBrowser_Release(This
->nscontainer
->webbrowser
);
807 nsIWebNavigation_Release(This
->nscontainer
->navigation
);
808 nsIBaseWindow_Release(This
->nscontainer
->window
);
810 if(This
->nscontainer
->stream
)
811 nsIWebBrowserStream_Release(This
->nscontainer
->stream
);
813 HeapFree(GetProcessHeap(), 0, This
->nscontainer
);
815 if(This
->nscontainer
->url
)
816 CoTaskMemFree(This
->nscontainer
->url
);