2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define APPSTARTUP_TOPIC "app-startup"
45 #define PR_UINT32_MAX 0xffffffff
47 struct nsCStringContainer {
54 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
55 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
56 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
57 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
58 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
59 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
60 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
61 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
62 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
63 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
64 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
65 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
67 static HINSTANCE hXPCOM = NULL;
69 static nsIServiceManager *pServMgr = NULL;
70 static nsIComponentManager *pCompMgr = NULL;
72 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
74 static ATOM nscontainer_class;
76 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
81 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
83 if(msg == WM_CREATE) {
84 This = *(NSContainer**)lParam;
85 SetPropW(hwnd, wszTHIS, This);
87 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
92 TRACE("(%p)->(WM_SIZE)\n", This);
94 nsres = nsIBaseWindow_SetSize(This->window,
95 LOWORD(lParam), HIWORD(lParam), TRUE);
97 WARN("SetSize failed: %08lx\n", nsres);
100 return DefWindowProcW(hwnd, msg, wParam, lParam);
104 static void register_nscontainer_class(void)
106 static WNDCLASSEXW wndclass = {
110 0, 0, NULL, NULL, NULL, NULL, NULL,
114 wndclass.hInstance = hInst;
115 nscontainer_class = RegisterClassExW(&wndclass);
118 static BOOL get_mozilla_path(PRUnichar *gre_path)
120 DWORD res, type, i, size = MAX_PATH;
121 HKEY mozilla_key, hkey;
125 static const WCHAR wszGreKey[] =
126 {'S','o','f','t','w','a','r','e','\\',
127 'm','o','z','i','l','l','a','.','o','r','g','\\',
130 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
132 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
133 if(res != ERROR_SUCCESS) {
134 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
138 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
139 RegOpenKeyW(mozilla_key, key_name, &hkey);
140 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
141 if(res == ERROR_SUCCESS)
146 RegCloseKey(mozilla_key);
150 static BOOL get_mozctl_path(PRUnichar *gre_path)
153 DWORD res, type, size = MAX_PATH;
155 static const WCHAR wszMozCtlKey[] =
156 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
157 static const WCHAR wszBinDirectoryPath[] =
158 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
159 static const WCHAR wszMozCtlClsidKey[] =
160 {'C','L','S','I','D','\\',
161 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
162 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
163 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
165 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
166 if(res == ERROR_SUCCESS) {
167 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
168 if(res == ERROR_SUCCESS)
171 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
174 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
175 if(res == ERROR_SUCCESS) {
176 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
177 if(res == ERROR_SUCCESS) {
179 if((ptr = strrchrW(gre_path, '\\')))
183 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
187 TRACE("Could not find Mozilla ActiveX Control\n");
192 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
195 DWORD res, type, size = MAX_PATH;
197 static const WCHAR wszMshtmlKey[] = {
198 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
199 '\\','M','S','H','T','M','L',0};
200 static const WCHAR wszGeckoPath[] =
201 {'G','e','c','k','o','P','a','t','h',0};
203 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
204 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
205 if(res != ERROR_SUCCESS)
208 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
209 if(res != ERROR_SUCCESS || type != REG_SZ)
215 static void set_profile(void)
218 PRBool exists = FALSE;
221 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
223 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
224 &IID_nsIProfile, (void**)&profile);
225 if(NS_FAILED(nsres)) {
226 ERR("Could not get profile service: %08lx\n", nsres);
230 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
232 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
234 ERR("CreateNewProfile failed: %08lx\n", nsres);
237 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
239 ERR("SetCurrentProfile failed: %08lx\n", nsres);
241 nsIProfile_Release(profile);
244 static BOOL load_gecko(void)
247 nsIObserver *pStartNotif;
248 nsIComponentRegistrar *registrar = NULL;
251 PRUnichar gre_path[MAX_PATH];
252 WCHAR path_env[MAX_PATH];
255 static BOOL tried_load = FALSE;
256 static const WCHAR wszPATH[] = {'P','A','T','H',0};
257 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
262 return pCompMgr != NULL;
265 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
266 && !get_mozilla_path(gre_path)) {
267 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
271 TRACE("found path %s\n", debugstr_w(gre_path));
273 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
274 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
275 len = strlenW(path_env);
276 path_env[len++] = ';';
277 strcpyW(path_env+len, gre_path);
278 SetEnvironmentVariableW(wszPATH, path_env);
280 hXPCOM = LoadLibraryW(strXPCOM);
282 ERR("Could not load XPCOM: %ld\n", GetLastError());
286 #define NS_DLSYM(func) \
287 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
289 ERR("Could not GetProcAddress(" #func ") failed\n")
291 NS_DLSYM(NS_InitXPCOM2);
292 NS_DLSYM(NS_ShutdownXPCOM);
293 NS_DLSYM(NS_GetComponentRegistrar);
294 NS_DLSYM(NS_StringContainerInit);
295 NS_DLSYM(NS_CStringContainerInit);
296 NS_DLSYM(NS_StringContainerFinish);
297 NS_DLSYM(NS_CStringContainerFinish);
298 NS_DLSYM(NS_StringSetData);
299 NS_DLSYM(NS_CStringSetData);
300 NS_DLSYM(NS_NewLocalFile);
301 NS_DLSYM(NS_StringGetData);
302 NS_DLSYM(NS_CStringGetData);
306 NS_StringContainerInit(&path);
307 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
308 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
309 NS_StringContainerFinish(&path);
310 if(NS_FAILED(nsres)) {
311 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
316 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
317 if(NS_FAILED(nsres)) {
318 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
323 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
325 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
327 nsres = NS_GetComponentRegistrar(®istrar);
328 if(NS_SUCCEEDED(nsres)) {
329 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
331 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
333 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
335 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
337 init_nsio(pCompMgr, registrar);
339 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
342 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
343 NULL, &IID_nsIObserver, (void**)&pStartNotif);
344 if(NS_SUCCEEDED(nsres)) {
345 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
347 ERR("Observe failed: %08lx\n", nsres);
349 nsIObserver_Release(pStartNotif);
351 ERR("could not get appstartup-notifier: %08lx\n", nsres);
357 register_nsservice(registrar, pServMgr);
358 nsIComponentRegistrar_Release(registrar);
364 nsACString *nsACString_Create(void)
367 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
368 NS_CStringContainerInit(ret);
372 void nsACString_SetData(nsACString *str, const char *data)
374 NS_CStringSetData(str, data, PR_UINT32_MAX);
377 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
379 return NS_CStringGetData(str, data, termited);
382 void nsACString_Destroy(nsACString *str)
384 NS_CStringContainerFinish(str);
385 HeapFree(GetProcessHeap(), 0, str);
388 void nsAString_Init(nsAString *str, const PRUnichar *data)
390 NS_StringContainerInit(str);
392 NS_StringSetData(str, data, PR_UINT32_MAX);
395 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
397 return NS_StringGetData(str, data, termited);
400 void nsAString_Finish(nsAString *str)
402 NS_StringContainerFinish(str);
405 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
407 nsIStringInputStream *ret;
413 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
414 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
416 if(NS_FAILED(nsres)) {
417 ERR("Could not get nsIStringInputStream\n");
421 nsres = nsIStringInputStream_SetData(ret, data, data_len);
422 if(NS_FAILED(nsres)) {
423 ERR("AdoptData failed: %08lx\n", nsres);
424 nsIStringInputStream_Release(ret);
428 return (nsIInputStream*)ret;
436 nsIComponentManager_Release(pCompMgr);
439 nsIServiceManager_Release(pServMgr);
445 /**********************************************************
446 * nsIWebBrowserChrome interface
449 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
451 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
452 nsIIDRef riid, nsQIResult result)
454 NSContainer *This = NSWBCHROME_THIS(iface);
457 if(IsEqualGUID(&IID_nsISupports, riid)) {
458 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
459 *result = NSWBCHROME(This);
460 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
461 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
462 *result = NSWBCHROME(This);
463 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
464 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
465 *result = NSCML(This);
466 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
467 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
468 *result = NSURICL(This);
469 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
470 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
471 *result = NSEMBWNDS(This);
472 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
473 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
474 *result = NSIFACEREQ(This);
478 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
482 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
483 return NS_NOINTERFACE;
486 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
488 NSContainer *This = NSWBCHROME_THIS(iface);
489 LONG ref = InterlockedIncrement(&This->ref);
491 TRACE("(%p) ref=%ld\n", This, ref);
496 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
498 NSContainer *This = NSWBCHROME_THIS(iface);
499 LONG ref = InterlockedDecrement(&This->ref);
501 TRACE("(%p) ref=%ld\n", This, ref);
505 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
506 HeapFree(GetProcessHeap(), 0, This);
512 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
513 PRUint32 statusType, const PRUnichar *status)
515 NSContainer *This = NSWBCHROME_THIS(iface);
516 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
517 return NS_ERROR_NOT_IMPLEMENTED;
520 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
521 nsIWebBrowser **aWebBrowser)
523 NSContainer *This = NSWBCHROME_THIS(iface);
525 TRACE("(%p)->(%p)\n", This, aWebBrowser);
528 return NS_ERROR_INVALID_ARG;
531 nsIWebBrowser_AddRef(This->webbrowser);
532 *aWebBrowser = This->webbrowser;
536 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
537 nsIWebBrowser *aWebBrowser)
539 NSContainer *This = NSWBCHROME_THIS(iface);
541 TRACE("(%p)->(%p)\n", This, aWebBrowser);
543 if(aWebBrowser != This->webbrowser)
544 ERR("Wrong nsWebBrowser!\n");
549 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
550 PRUint32 *aChromeFlags)
552 NSContainer *This = NSWBCHROME_THIS(iface);
553 WARN("(%p)->(%p)\n", This, aChromeFlags);
554 return NS_ERROR_NOT_IMPLEMENTED;
557 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
558 PRUint32 aChromeFlags)
560 NSContainer *This = NSWBCHROME_THIS(iface);
561 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
562 return NS_ERROR_NOT_IMPLEMENTED;
565 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
567 NSContainer *This = NSWBCHROME_THIS(iface);
568 TRACE("(%p)\n", This);
569 return NS_ERROR_NOT_IMPLEMENTED;
572 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
573 PRInt32 aCX, PRInt32 aCY)
575 NSContainer *This = NSWBCHROME_THIS(iface);
576 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
577 return NS_ERROR_NOT_IMPLEMENTED;
580 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
582 NSContainer *This = NSWBCHROME_THIS(iface);
583 WARN("(%p)\n", This);
584 return NS_ERROR_NOT_IMPLEMENTED;
587 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
589 NSContainer *This = NSWBCHROME_THIS(iface);
590 WARN("(%p)->(%p)\n", This, _retval);
591 return NS_ERROR_NOT_IMPLEMENTED;
594 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
597 NSContainer *This = NSWBCHROME_THIS(iface);
598 WARN("(%p)->(%08lx)\n", This, aStatus);
599 return NS_ERROR_NOT_IMPLEMENTED;
602 #undef NSWBCHROME_THIS
604 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
605 nsWebBrowserChrome_QueryInterface,
606 nsWebBrowserChrome_AddRef,
607 nsWebBrowserChrome_Release,
608 nsWebBrowserChrome_SetStatus,
609 nsWebBrowserChrome_GetWebBrowser,
610 nsWebBrowserChrome_SetWebBrowser,
611 nsWebBrowserChrome_GetChromeFlags,
612 nsWebBrowserChrome_SetChromeFlags,
613 nsWebBrowserChrome_DestroyBrowserWindow,
614 nsWebBrowserChrome_SizeBrowserTo,
615 nsWebBrowserChrome_ShowAsModal,
616 nsWebBrowserChrome_IsWindowModal,
617 nsWebBrowserChrome_ExitModalEventLoop
620 /**********************************************************
621 * nsIContextMenuListener interface
624 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
626 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
627 nsIIDRef riid, nsQIResult result)
629 NSContainer *This = NSCML_THIS(iface);
630 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
633 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
635 NSContainer *This = NSCML_THIS(iface);
636 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
639 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
641 NSContainer *This = NSCML_THIS(iface);
642 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
645 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
646 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
648 NSContainer *This = NSCML_THIS(iface);
649 nsIDOMMouseEvent *event;
651 DWORD dwID = CONTEXT_MENU_DEFAULT;
654 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
656 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
657 if(NS_FAILED(nsres)) {
658 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
662 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
663 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
664 nsIDOMMouseEvent_Release(event);
666 switch(aContextFlags) {
668 case CONTEXT_DOCUMENT:
670 dwID = CONTEXT_MENU_DEFAULT;
673 case CONTEXT_IMAGE|CONTEXT_LINK:
674 dwID = CONTEXT_MENU_IMAGE;
677 dwID = CONTEXT_MENU_ANCHOR;
680 dwID = CONTEXT_MENU_CONTROL;
683 FIXME("aContextFlags=%08lx\n", aContextFlags);
686 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
693 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
694 nsContextMenuListener_QueryInterface,
695 nsContextMenuListener_AddRef,
696 nsContextMenuListener_Release,
697 nsContextMenuListener_OnShowContextMenu
700 /**********************************************************
701 * nsIURIContentListener interface
704 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
706 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
707 nsIIDRef riid, nsQIResult result)
709 NSContainer *This = NSURICL_THIS(iface);
710 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
713 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
715 NSContainer *This = NSURICL_THIS(iface);
716 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
719 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
721 NSContainer *This = NSURICL_THIS(iface);
722 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
725 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
726 nsIURI *aURI, PRBool *_retval)
728 NSContainer *This = NSURICL_THIS(iface);
729 nsIWineURI *wine_uri;
730 nsACString *spec_str = nsACString_Create();
734 nsIURI_GetSpec(aURI, spec_str);
735 nsACString_GetData(spec_str, &spec, NULL);
737 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
739 nsACString_Destroy(spec_str);
741 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
742 if(NS_SUCCEEDED(nsres)) {
743 nsIWineURI_SetNSContainer(wine_uri, This);
744 nsIWineURI_Release(wine_uri);
746 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
749 return NS_ERROR_NOT_IMPLEMENTED;
752 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
753 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
754 nsIStreamListener **aContentHandler, PRBool *_retval)
756 NSContainer *This = NSURICL_THIS(iface);
757 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
758 aRequest, aContentHandler, _retval);
759 return NS_ERROR_NOT_IMPLEMENTED;
762 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
763 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
765 NSContainer *This = NSURICL_THIS(iface);
767 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
769 /* FIXME: Should we do something here? */
774 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
775 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
778 NSContainer *This = NSURICL_THIS(iface);
779 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
780 aDesiredContentType, _retval);
781 return NS_ERROR_NOT_IMPLEMENTED;
784 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
785 nsISupports **aLoadCookie)
787 NSContainer *This = NSURICL_THIS(iface);
788 WARN("(%p)->(%p)\n", This, aLoadCookie);
789 return NS_ERROR_NOT_IMPLEMENTED;
792 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
793 nsISupports *aLoadCookie)
795 NSContainer *This = NSURICL_THIS(iface);
796 WARN("(%p)->(%p)\n", This, aLoadCookie);
797 return NS_ERROR_NOT_IMPLEMENTED;
800 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
801 nsIURIContentListener **aParentContentListener)
803 NSContainer *This = NSURICL_THIS(iface);
804 WARN("(%p)->(%p)\n", This, aParentContentListener);
805 return NS_ERROR_NOT_IMPLEMENTED;
808 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
809 nsIURIContentListener *aParentContentListener)
811 NSContainer *This = NSURICL_THIS(iface);
812 WARN("(%p)->(%p)\n", This, aParentContentListener);
813 return NS_ERROR_NOT_IMPLEMENTED;
818 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
819 nsURIContentListener_QueryInterface,
820 nsURIContentListener_AddRef,
821 nsURIContentListener_Release,
822 nsURIContentListener_OnStartURIOpen,
823 nsURIContentListener_DoContent,
824 nsURIContentListener_IsPreferred,
825 nsURIContentListener_CanHandleContent,
826 nsURIContentListener_GetLoadCookie,
827 nsURIContentListener_SetLoadCookie,
828 nsURIContentListener_GetParentContentListener,
829 nsURIContentListener_SetParentContentListener
832 /**********************************************************
833 * nsIEmbeddinSiteWindow interface
836 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
838 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
839 nsIIDRef riid, nsQIResult result)
841 NSContainer *This = NSEMBWNDS_THIS(iface);
842 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
845 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
847 NSContainer *This = NSEMBWNDS_THIS(iface);
848 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
851 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
853 NSContainer *This = NSEMBWNDS_THIS(iface);
854 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
857 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
858 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
860 NSContainer *This = NSEMBWNDS_THIS(iface);
861 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
862 return NS_ERROR_NOT_IMPLEMENTED;
865 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
866 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
868 NSContainer *This = NSEMBWNDS_THIS(iface);
869 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
870 return NS_ERROR_NOT_IMPLEMENTED;
873 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
875 NSContainer *This = NSEMBWNDS_THIS(iface);
876 WARN("(%p)\n", This);
877 return NS_ERROR_NOT_IMPLEMENTED;
880 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
883 NSContainer *This = NSEMBWNDS_THIS(iface);
884 WARN("(%p)->(%p)\n", This, aVisibility);
885 return NS_ERROR_NOT_IMPLEMENTED;
888 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
891 NSContainer *This = NSEMBWNDS_THIS(iface);
892 WARN("(%p)->(%x)\n", This, aVisibility);
893 return NS_ERROR_NOT_IMPLEMENTED;
896 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
899 NSContainer *This = NSEMBWNDS_THIS(iface);
900 WARN("(%p)->(%p)\n", This, aTitle);
901 return NS_ERROR_NOT_IMPLEMENTED;
904 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
905 const PRUnichar *aTitle)
907 NSContainer *This = NSEMBWNDS_THIS(iface);
908 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
909 return NS_ERROR_NOT_IMPLEMENTED;
912 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
915 NSContainer *This = NSEMBWNDS_THIS(iface);
917 TRACE("(%p)->(%p)\n", This, aSiteWindow);
919 *aSiteWindow = This->hwnd;
923 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
924 nsEmbeddingSiteWindow_QueryInterface,
925 nsEmbeddingSiteWindow_AddRef,
926 nsEmbeddingSiteWindow_Release,
927 nsEmbeddingSiteWindow_SetDimensions,
928 nsEmbeddingSiteWindow_GetDimensions,
929 nsEmbeddingSiteWindow_SetFocus,
930 nsEmbeddingSiteWindow_GetVisibility,
931 nsEmbeddingSiteWindow_SetVisibility,
932 nsEmbeddingSiteWindow_GetTitle,
933 nsEmbeddingSiteWindow_SetTitle,
934 nsEmbeddingSiteWindow_GetSiteWindow
937 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
939 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
940 nsIIDRef riid, nsQIResult result)
942 NSContainer *This = NSIFACEREQ_THIS(iface);
943 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
946 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
948 NSContainer *This = NSIFACEREQ_THIS(iface);
949 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
952 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
954 NSContainer *This = NSIFACEREQ_THIS(iface);
955 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
958 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
959 nsIIDRef riid, nsQIResult result)
961 NSContainer *This = NSIFACEREQ_THIS(iface);
963 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
964 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
965 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
968 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
971 #undef NSIFACEREQ_THIS
973 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
974 nsInterfaceRequestor_QueryInterface,
975 nsInterfaceRequestor_AddRef,
976 nsInterfaceRequestor_Release,
977 nsInterfaceRequestor_GetInterface
980 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
982 nsIWebBrowserSetup *wbsetup;
989 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
991 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
992 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
993 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
994 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
995 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
999 ret->load_call = FALSE;
1002 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1003 ret->parent = parent;
1005 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1006 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1007 if(NS_FAILED(nsres))
1008 ERR("Creating WebBrowser failed: %08lx\n", nsres);
1010 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1011 if(NS_FAILED(nsres))
1012 ERR("SetContainerWindow failed: %08lx\n", nsres);
1014 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1015 (void**)&ret->window);
1016 if(NS_FAILED(nsres))
1017 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1019 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1021 if(NS_SUCCEEDED(nsres)) {
1022 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1023 nsIWebBrowserSetup_Release(wbsetup);
1024 if(NS_FAILED(nsres))
1025 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1027 ERR("Could not get nsIWebBrowserSetup interface\n");
1030 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1031 (void**)&ret->navigation);
1032 if(NS_FAILED(nsres))
1033 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1035 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1036 (void**)&ret->focus);
1037 if(NS_FAILED(nsres))
1038 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1041 nsres = nsIWebBrowserStream_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserStream,
1042 (void**)&ret->stream);
1043 if(NS_FAILED(nsres))
1044 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
1049 if(!nscontainer_class)
1050 register_nscontainer_class();
1052 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1053 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1054 GetDesktopWindow(), NULL, hInst, ret);
1056 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1057 if(NS_SUCCEEDED(nsres)) {
1058 nsres = nsIBaseWindow_Create(ret->window);
1059 if(NS_FAILED(nsres))
1060 WARN("Creating window failed: %08lx\n", nsres);
1062 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1063 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1065 ERR("InitWindow failed: %08lx\n", nsres);
1068 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1069 if(NS_FAILED(nsres))
1070 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1075 void NSContainer_Release(NSContainer *This)
1077 nsIBaseWindow *base_window;
1080 TRACE("(%p)\n", This);
1082 ShowWindow(This->hwnd, SW_HIDE);
1083 SetParent(This->hwnd, NULL);
1085 nsres = nsIWebBrowser_QueryInterface(This->webbrowser, &IID_nsIBaseWindow,
1086 (void**)&base_window);
1087 if(NS_SUCCEEDED(nsres)) {
1088 nsIBaseWindow_SetVisibility(base_window, FALSE);
1089 nsIBaseWindow_Destroy(base_window);
1090 nsIBaseWindow_Release(base_window);
1092 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1095 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1097 nsIWebBrowser_Release(This->webbrowser);
1098 This->webbrowser = NULL;
1100 nsIWebNavigation_Release(This->navigation);
1101 This->navigation = NULL;
1103 nsIBaseWindow_Release(This->window);
1104 This->window = NULL;
1107 nsIWebBrowserStream_Release(This->stream);
1108 This->stream = NULL;
1112 DestroyWindow(This->hwnd);
1116 nsIWebBrowserChrome_Release(NSWBCHROME(This));