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_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
42 #define APPSTARTUP_TOPIC "app-startup"
44 #define PR_UINT32_MAX 0xffffffff
46 struct nsStringContainer {
53 struct nsCStringContainer {
60 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
61 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
62 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
63 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
64 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
65 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
66 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
67 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
68 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
69 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
70 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
72 static HINSTANCE hXPCOM = NULL;
74 static nsIServiceManager *pServMgr = NULL;
75 static nsIComponentManager *pCompMgr = NULL;
77 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
79 static ATOM nscontainer_class;
81 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
86 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
88 if(msg == WM_CREATE) {
89 This = *(HTMLDocument**)lParam;
90 SetPropW(hwnd, wszTHIS, This);
92 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
97 TRACE("(%p)->(WM_SIZE)\n", This);
99 nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
100 LOWORD(lParam), HIWORD(lParam), TRUE);
102 WARN("SetSize failed: %08lx\n", nsres);
105 return DefWindowProcW(hwnd, msg, wParam, lParam);
109 static void register_nscontainer_class(void)
111 static WNDCLASSEXW wndclass = {
115 0, 0, NULL, NULL, NULL, NULL, NULL,
119 wndclass.hInstance = hInst;
120 nscontainer_class = RegisterClassExW(&wndclass);
123 static BOOL get_mozilla_path(PRUnichar *gre_path)
125 DWORD res, type, i, size = MAX_PATH;
126 HKEY mozilla_key, hkey;
130 static const WCHAR wszGreKey[] =
131 {'S','o','f','t','w','a','r','e','\\',
132 'm','o','z','i','l','l','a','.','o','r','g','\\',
135 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
137 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
138 if(res != ERROR_SUCCESS) {
139 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
143 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
144 RegOpenKeyW(mozilla_key, key_name, &hkey);
145 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
146 if(res == ERROR_SUCCESS)
151 RegCloseKey(mozilla_key);
155 static BOOL get_mozctl_path(PRUnichar *gre_path)
158 DWORD res, type, size = MAX_PATH;
160 static const WCHAR wszMozCtlKey[] =
161 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
162 static const WCHAR wszBinDirectoryPath[] =
163 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
164 static const WCHAR wszMozCtlClsidKey[] =
165 {'C','L','S','I','D','\\',
166 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
167 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
168 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
170 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
171 if(res == ERROR_SUCCESS) {
172 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
173 if(res == ERROR_SUCCESS)
176 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
179 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
180 if(res == ERROR_SUCCESS) {
181 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
182 if(res == ERROR_SUCCESS) {
184 if((ptr = strrchrW(gre_path, '\\')))
188 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
192 TRACE("Could not find Mozilla ActiveX Control\n");
197 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
200 DWORD res, type, size = MAX_PATH;
202 static const WCHAR wszMshtmlKey[] = {
203 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
204 '\\','M','S','H','T','M','L',0};
205 static const WCHAR wszGeckoPath[] =
206 {'G','e','c','k','o','P','a','t','h',0};
208 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
209 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
210 if(res != ERROR_SUCCESS)
213 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
214 if(res != ERROR_SUCCESS || type != REG_SZ)
220 static void set_profile(void)
223 PRBool exists = FALSE;
226 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
228 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
229 &IID_nsIProfile, (void**)&profile);
230 if(NS_FAILED(nsres)) {
231 ERR("Could not get profile service: %08lx\n", nsres);
235 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
237 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
239 ERR("CreateNewProfile failed: %08lx\n", nsres);
242 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
244 ERR("SetCurrentProfile failed: %08lx\n", nsres);
246 nsIProfile_Release(profile);
249 static BOOL load_gecko(void)
252 nsIObserver *pStartNotif;
253 nsIComponentRegistrar *registrar = NULL;
256 PRUnichar gre_path[MAX_PATH];
257 WCHAR path_env[MAX_PATH];
260 static BOOL tried_load = FALSE;
261 static const WCHAR wszPATH[] = {'P','A','T','H',0};
262 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
267 return pCompMgr != NULL;
270 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
271 && !get_mozilla_path(gre_path)) {
272 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
276 TRACE("found path %s\n", debugstr_w(gre_path));
278 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
279 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
280 len = strlenW(path_env);
281 path_env[len++] = ';';
282 strcpyW(path_env+len, gre_path);
283 SetEnvironmentVariableW(wszPATH, path_env);
285 hXPCOM = LoadLibraryW(strXPCOM);
287 ERR("Could not load XPCOM: %ld\n", GetLastError());
291 #define NS_DLSYM(func) \
292 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
294 ERR("Could not GetProcAddress(" #func ") failed\n")
296 NS_DLSYM(NS_InitXPCOM2);
297 NS_DLSYM(NS_ShutdownXPCOM);
298 NS_DLSYM(NS_GetComponentRegistrar);
299 NS_DLSYM(NS_StringContainerInit);
300 NS_DLSYM(NS_CStringContainerInit);
301 NS_DLSYM(NS_StringContainerFinish);
302 NS_DLSYM(NS_CStringContainerFinish);
303 NS_DLSYM(NS_StringSetData);
304 NS_DLSYM(NS_CStringSetData);
305 NS_DLSYM(NS_NewLocalFile);
306 NS_DLSYM(NS_CStringGetData);
310 NS_StringContainerInit(&path);
311 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
312 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
313 NS_StringContainerFinish(&path);
314 if(NS_FAILED(nsres)) {
315 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
320 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
321 if(NS_FAILED(nsres)) {
322 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
327 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
329 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
331 nsres = NS_GetComponentRegistrar(®istrar);
332 if(NS_SUCCEEDED(nsres)) {
333 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
335 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
337 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
339 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
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);
349 ERR("Observe failed: %08lx\n", nsres);
351 nsIObserver_Release(pStartNotif);
353 ERR("could not get appstartup-notifier: %08lx\n", nsres);
359 register_nsservice(registrar);
360 init_nsio(pCompMgr, registrar);
361 nsIComponentRegistrar_Release(registrar);
367 nsACString *nsACString_Create(void)
370 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
371 NS_CStringContainerInit(ret);
375 void nsACString_SetData(nsACString *str, const char *data)
377 NS_CStringSetData(str, data, PR_UINT32_MAX);
380 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
382 return NS_CStringGetData(str, data, termited);
385 void nsACString_Destroy(nsACString *str)
387 NS_CStringContainerFinish(str);
388 HeapFree(GetProcessHeap(), 0, str);
396 nsIComponentManager_Release(pCompMgr);
399 nsIServiceManager_Release(pServMgr);
405 /**********************************************************
406 * nsIWebBrowserChrome interface
409 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
411 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
412 nsIIDRef riid, nsQIResult result)
414 NSContainer *This = NSWBCHROME_THIS(iface);
417 if(IsEqualGUID(&IID_nsISupports, riid)) {
418 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
419 *result = NSWBCHROME(This);
420 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
421 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
422 *result = NSWBCHROME(This);
423 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
424 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
425 *result = NSCML(This);
426 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
427 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
428 *result = NSURICL(This);
429 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
430 TRACE("(%p)->(IIS_nsIEmbeddingSiteWindow %p)\n", This, result);
431 *result = NSEMBWNDS(This);
437 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
438 return NS_NOINTERFACE;
441 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
443 NSContainer *This = NSWBCHROME_THIS(iface);
444 TRACE("(%p)\n", This);
445 return 2; /* Should we implement ref conunting here? */
448 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
450 NSContainer *This = NSWBCHROME_THIS(iface);
451 TRACE("(%p)\n", This);
455 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
456 PRUint32 statusType, const PRUnichar *status)
458 NSContainer *This = NSWBCHROME_THIS(iface);
459 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
460 return NS_ERROR_NOT_IMPLEMENTED;
463 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
464 nsIWebBrowser **aWebBrowser)
466 NSContainer *This = NSWBCHROME_THIS(iface);
468 TRACE("(%p)->(%p)\n", This, aWebBrowser);
471 return NS_ERROR_INVALID_ARG;
473 *aWebBrowser = This->webbrowser;
477 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
478 nsIWebBrowser *aWebBrowser)
480 NSContainer *This = NSWBCHROME_THIS(iface);
482 TRACE("(%p)->(%p)\n", This, aWebBrowser);
484 if(aWebBrowser != This->webbrowser)
485 ERR("Wrong nsWebBrowser!\n");
490 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
491 PRUint32 *aChromeFlags)
493 NSContainer *This = NSWBCHROME_THIS(iface);
494 WARN("(%p)->(%p)\n", This, aChromeFlags);
495 return NS_ERROR_NOT_IMPLEMENTED;
498 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
499 PRUint32 aChromeFlags)
501 NSContainer *This = NSWBCHROME_THIS(iface);
502 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
503 return NS_ERROR_NOT_IMPLEMENTED;
506 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
508 NSContainer *This = NSWBCHROME_THIS(iface);
509 TRACE("(%p)\n", This);
510 return NS_ERROR_NOT_IMPLEMENTED;
513 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
514 PRInt32 aCX, PRInt32 aCY)
516 NSContainer *This = NSWBCHROME_THIS(iface);
517 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
518 return NS_ERROR_NOT_IMPLEMENTED;
521 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
523 NSContainer *This = NSWBCHROME_THIS(iface);
524 WARN("(%p)\n", This);
525 return NS_ERROR_NOT_IMPLEMENTED;
528 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
530 NSContainer *This = NSWBCHROME_THIS(iface);
531 WARN("(%p)->(%p)\n", This, _retval);
532 return NS_ERROR_NOT_IMPLEMENTED;
535 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
538 NSContainer *This = NSWBCHROME_THIS(iface);
539 WARN("(%p)->(%08lx)\n", This, aStatus);
540 return NS_ERROR_NOT_IMPLEMENTED;
543 #undef NSWBCHROME_THIS
545 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
546 nsWebBrowserChrome_QueryInterface,
547 nsWebBrowserChrome_AddRef,
548 nsWebBrowserChrome_Release,
549 nsWebBrowserChrome_SetStatus,
550 nsWebBrowserChrome_GetWebBrowser,
551 nsWebBrowserChrome_SetWebBrowser,
552 nsWebBrowserChrome_GetChromeFlags,
553 nsWebBrowserChrome_SetChromeFlags,
554 nsWebBrowserChrome_DestroyBrowserWindow,
555 nsWebBrowserChrome_SizeBrowserTo,
556 nsWebBrowserChrome_ShowAsModal,
557 nsWebBrowserChrome_IsWindowModal,
558 nsWebBrowserChrome_ExitModalEventLoop
561 /**********************************************************
562 * nsIContextMenuListener interface
565 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
567 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
568 nsIIDRef riid, nsQIResult result)
570 NSContainer *This = NSCML_THIS(iface);
571 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
574 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
576 NSContainer *This = NSCML_THIS(iface);
577 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
580 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
582 NSContainer *This = NSCML_THIS(iface);
583 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
586 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
587 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
589 NSContainer *This = NSCML_THIS(iface);
590 nsIDOMMouseEvent *event;
592 DWORD dwID = CONTEXT_MENU_DEFAULT;
595 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
597 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
598 if(NS_FAILED(nsres)) {
599 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
603 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
604 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
605 nsIDOMMouseEvent_Release(event);
607 switch(aContextFlags) {
609 case CONTEXT_DOCUMENT:
611 dwID = CONTEXT_MENU_DEFAULT;
614 case CONTEXT_IMAGE|CONTEXT_LINK:
615 dwID = CONTEXT_MENU_IMAGE;
618 dwID = CONTEXT_MENU_ANCHOR;
621 dwID = CONTEXT_MENU_CONTROL;
624 FIXME("aContextFlags=%08lx\n", aContextFlags);
627 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
634 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
635 nsContextMenuListener_QueryInterface,
636 nsContextMenuListener_AddRef,
637 nsContextMenuListener_Release,
638 nsContextMenuListener_OnShowContextMenu
641 /**********************************************************
642 * nsIURIContentListener interface
645 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
647 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
648 nsIIDRef riid, nsQIResult result)
650 NSContainer *This = NSURICL_THIS(iface);
651 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
654 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
656 NSContainer *This = NSURICL_THIS(iface);
657 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
660 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
662 NSContainer *This = NSURICL_THIS(iface);
663 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
666 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface, nsIURI *aURI,
669 NSContainer *This = NSURICL_THIS(iface);
672 nsACString *spec_str = nsACString_Create();
674 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
676 nsres = nsIURI_GetSpec(aURI, spec_str);
677 if(NS_SUCCEEDED(nsres)) {
678 const char *spec = NULL;
682 nsACString_GetData(spec_str, &spec, NULL);
684 len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
685 specw = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
686 MultiByteToWideChar(CP_ACP, 0, spec, -1, specw, -1);
688 if(strcmpW(This->url, specw)) /* hack */
689 do_load = HTMLDocument_OnLoad(This->doc, specw);
691 HeapFree(GetProcessHeap(), 0, specw);
693 ERR("GetSpec failed: %08lx\n", nsres);
696 nsACString_Destroy(spec_str);
703 return NS_ERROR_NOT_IMPLEMENTED;
706 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
707 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
708 nsIStreamListener **aContentHandler, PRBool *_retval)
710 NSContainer *This = NSURICL_THIS(iface);
711 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
712 aRequest, aContentHandler, _retval);
713 return NS_ERROR_NOT_IMPLEMENTED;
716 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
717 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
719 NSContainer *This = NSURICL_THIS(iface);
721 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
723 /* FIXME: Should we do something here? */
728 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
729 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
732 NSContainer *This = NSURICL_THIS(iface);
733 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
734 aDesiredContentType, _retval);
735 return NS_ERROR_NOT_IMPLEMENTED;
738 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
739 nsISupports **aLoadCookie)
741 NSContainer *This = NSURICL_THIS(iface);
742 WARN("(%p)->(%p)\n", This, aLoadCookie);
743 return NS_ERROR_NOT_IMPLEMENTED;
746 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
747 nsISupports *aLoadCookie)
749 NSContainer *This = NSURICL_THIS(iface);
750 WARN("(%p)->(%p)\n", This, aLoadCookie);
751 return NS_ERROR_NOT_IMPLEMENTED;
754 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
755 nsIURIContentListener **aParentContentListener)
757 NSContainer *This = NSURICL_THIS(iface);
758 WARN("(%p)->(%p)\n", This, aParentContentListener);
759 return NS_ERROR_NOT_IMPLEMENTED;
762 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
763 nsIURIContentListener *aParentContentListener)
765 NSContainer *This = NSURICL_THIS(iface);
766 WARN("(%p)->(%p)\n", This, aParentContentListener);
767 return NS_ERROR_NOT_IMPLEMENTED;
772 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
773 nsURIContentListener_QueryInterface,
774 nsURIContentListener_AddRef,
775 nsURIContentListener_Release,
776 nsURIContentListener_OnStartURIOpen,
777 nsURIContentListener_DoContent,
778 nsURIContentListener_IsPreferred,
779 nsURIContentListener_CanHandleContent,
780 nsURIContentListener_GetLoadCookie,
781 nsURIContentListener_SetLoadCookie,
782 nsURIContentListener_GetParentContentListener,
783 nsURIContentListener_SetParentContentListener
786 /**********************************************************
787 * nsIEmbeddinSiteWindow interface
790 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
792 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
793 nsIIDRef riid, nsQIResult result)
795 NSContainer *This = NSEMBWNDS_THIS(iface);
796 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
799 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
801 NSContainer *This = NSEMBWNDS_THIS(iface);
802 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
805 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
807 NSContainer *This = NSEMBWNDS_THIS(iface);
808 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
811 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
812 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
814 NSContainer *This = NSEMBWNDS_THIS(iface);
815 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
816 return NS_ERROR_NOT_IMPLEMENTED;
819 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
820 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
822 NSContainer *This = NSEMBWNDS_THIS(iface);
823 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
824 return NS_ERROR_NOT_IMPLEMENTED;
827 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
829 NSContainer *This = NSEMBWNDS_THIS(iface);
830 WARN("(%p)\n", This);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
837 NSContainer *This = NSEMBWNDS_THIS(iface);
838 WARN("(%p)->(%p)\n", This, aVisibility);
839 return NS_ERROR_NOT_IMPLEMENTED;
842 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
845 NSContainer *This = NSEMBWNDS_THIS(iface);
846 WARN("(%p)->(%x)\n", This, aVisibility);
847 return NS_ERROR_NOT_IMPLEMENTED;
850 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
853 NSContainer *This = NSEMBWNDS_THIS(iface);
854 WARN("(%p)->(%p)\n", This, aTitle);
855 return NS_ERROR_NOT_IMPLEMENTED;
858 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
859 const PRUnichar *aTitle)
861 NSContainer *This = NSEMBWNDS_THIS(iface);
862 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
863 return NS_ERROR_NOT_IMPLEMENTED;
866 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
869 NSContainer *This = NSEMBWNDS_THIS(iface);
871 TRACE("(%p)->(%p)\n", This, aSiteWindow);
873 *aSiteWindow = This->hwnd;
877 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
878 nsEmbeddingSiteWindow_QueryInterface,
879 nsEmbeddingSiteWindow_AddRef,
880 nsEmbeddingSiteWindow_Release,
881 nsEmbeddingSiteWindow_SetDimensions,
882 nsEmbeddingSiteWindow_GetDimensions,
883 nsEmbeddingSiteWindow_SetFocus,
884 nsEmbeddingSiteWindow_GetVisibility,
885 nsEmbeddingSiteWindow_SetVisibility,
886 nsEmbeddingSiteWindow_GetTitle,
887 nsEmbeddingSiteWindow_SetTitle,
888 nsEmbeddingSiteWindow_GetSiteWindow
891 void HTMLDocument_NSContainer_Init(HTMLDocument *This)
893 nsIWebBrowserSetup *wbsetup;
896 This->nscontainer = NULL;
901 This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
903 This->nscontainer->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
904 This->nscontainer->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
905 This->nscontainer->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
906 This->nscontainer->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
908 This->nscontainer->doc = This;
910 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
911 NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
913 ERR("Creating WebBrowser failed: %08lx\n", nsres);
915 nsres = nsIWebBrowser_SetContainerWindow(This->nscontainer->webbrowser,
916 NSWBCHROME(This->nscontainer));
918 ERR("SetContainerWindow failed: %08lx\n", nsres);
920 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
921 (void**)&This->nscontainer->window);
923 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
925 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
926 &IID_nsIWebBrowserSetup, (void**)&wbsetup);
927 if(NS_SUCCEEDED(nsres)) {
928 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
929 nsIWebBrowserSetup_Release(wbsetup);
931 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
933 ERR("Could not get nsIWebBrowserSetup interface\n");
936 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
937 (void**)&This->nscontainer->navigation);
939 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
941 nsres = nsIWebBrowserFocus_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserFocus,
942 (void**)&This->nscontainer->focus);
944 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
947 nsres = nsIWebBrowserStream_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserStream,
948 (void**)&This->nscontainer->stream);
950 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
952 This->nscontainer->stream = NULL;
955 if(!nscontainer_class)
956 register_nscontainer_class();
958 This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
959 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
960 GetDesktopWindow(), NULL, hInst, This);
962 nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
964 if(NS_SUCCEEDED(nsres)) {
965 nsres = nsIBaseWindow_Create(This->nscontainer->window);
967 WARN("Creating window failed: %08lx\n", nsres);
969 nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
970 nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
972 ERR("InitWindow failed: %08lx\n", nsres);
975 nsres = nsIWebBrowser_SetParentURIContentListener(This->nscontainer->webbrowser,
976 NSURICL(This->nscontainer));
978 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
980 This->nscontainer->url = NULL;
983 void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
985 TRACE("(%p)\n", This);
987 nsIWebBrowser_Release(This->nscontainer->webbrowser);
988 nsIWebNavigation_Release(This->nscontainer->navigation);
989 nsIBaseWindow_Release(This->nscontainer->window);
991 if(This->nscontainer->stream)
992 nsIWebBrowserStream_Release(This->nscontainer->stream);
994 HeapFree(GetProcessHeap(), 0, This->nscontainer);
996 if(This->nscontainer->url)
997 CoTaskMemFree(This->nscontainer->url);