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"
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 nsStringContainer {
54 struct nsCStringContainer {
61 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
62 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
63 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
64 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
65 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
66 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
67 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
68 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
69 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
70 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
71 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
73 static HINSTANCE hXPCOM = NULL;
75 static nsIServiceManager *pServMgr = NULL;
76 static nsIComponentManager *pCompMgr = NULL;
78 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
80 static ATOM nscontainer_class;
82 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
87 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
89 if(msg == WM_CREATE) {
90 This = *(HTMLDocument**)lParam;
91 SetPropW(hwnd, wszTHIS, This);
93 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
98 TRACE("(%p)->(WM_SIZE)\n", This);
100 nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
101 LOWORD(lParam), HIWORD(lParam), TRUE);
103 WARN("SetSize failed: %08lx\n", nsres);
106 return DefWindowProcW(hwnd, msg, wParam, lParam);
110 static void register_nscontainer_class(void)
112 static WNDCLASSEXW wndclass = {
116 0, 0, NULL, NULL, NULL, NULL, NULL,
120 wndclass.hInstance = hInst;
121 nscontainer_class = RegisterClassExW(&wndclass);
124 static BOOL get_mozilla_path(PRUnichar *gre_path)
126 DWORD res, type, i, size = MAX_PATH;
127 HKEY mozilla_key, hkey;
131 static const WCHAR wszGreKey[] =
132 {'S','o','f','t','w','a','r','e','\\',
133 'm','o','z','i','l','l','a','.','o','r','g','\\',
136 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
138 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
139 if(res != ERROR_SUCCESS) {
140 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
144 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
145 RegOpenKeyW(mozilla_key, key_name, &hkey);
146 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
147 if(res == ERROR_SUCCESS)
152 RegCloseKey(mozilla_key);
156 static BOOL get_mozctl_path(PRUnichar *gre_path)
159 DWORD res, type, size = MAX_PATH;
161 static const WCHAR wszMozCtlKey[] =
162 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
163 static const WCHAR wszBinDirectoryPath[] =
164 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
165 static const WCHAR wszMozCtlClsidKey[] =
166 {'C','L','S','I','D','\\',
167 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
168 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
169 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
171 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
172 if(res == ERROR_SUCCESS) {
173 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
174 if(res == ERROR_SUCCESS)
177 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
180 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
181 if(res == ERROR_SUCCESS) {
182 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
183 if(res == ERROR_SUCCESS) {
185 if((ptr = strrchrW(gre_path, '\\')))
189 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
193 TRACE("Could not find Mozilla ActiveX Control\n");
198 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
201 DWORD res, type, size = MAX_PATH;
203 static const WCHAR wszMshtmlKey[] = {
204 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
205 '\\','M','S','H','T','M','L',0};
206 static const WCHAR wszGeckoPath[] =
207 {'G','e','c','k','o','P','a','t','h',0};
209 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
210 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
211 if(res != ERROR_SUCCESS)
214 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
215 if(res != ERROR_SUCCESS || type != REG_SZ)
221 static void set_profile(void)
224 PRBool exists = FALSE;
227 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
229 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
230 &IID_nsIProfile, (void**)&profile);
231 if(NS_FAILED(nsres)) {
232 ERR("Could not get profile service: %08lx\n", nsres);
236 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
238 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
240 ERR("CreateNewProfile failed: %08lx\n", nsres);
243 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
245 ERR("SetCurrentProfile failed: %08lx\n", nsres);
247 nsIProfile_Release(profile);
250 static BOOL load_gecko(void)
253 nsIObserver *pStartNotif;
254 nsIComponentRegistrar *registrar = NULL;
257 PRUnichar gre_path[MAX_PATH];
258 WCHAR path_env[MAX_PATH];
261 static BOOL tried_load = FALSE;
262 static const WCHAR wszPATH[] = {'P','A','T','H',0};
263 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
268 return pCompMgr != NULL;
271 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
272 && !get_mozilla_path(gre_path)) {
273 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
277 TRACE("found path %s\n", debugstr_w(gre_path));
279 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
280 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
281 len = strlenW(path_env);
282 path_env[len++] = ';';
283 strcpyW(path_env+len, gre_path);
284 SetEnvironmentVariableW(wszPATH, path_env);
286 hXPCOM = LoadLibraryW(strXPCOM);
288 ERR("Could not load XPCOM: %ld\n", GetLastError());
292 #define NS_DLSYM(func) \
293 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
295 ERR("Could not GetProcAddress(" #func ") failed\n")
297 NS_DLSYM(NS_InitXPCOM2);
298 NS_DLSYM(NS_ShutdownXPCOM);
299 NS_DLSYM(NS_GetComponentRegistrar);
300 NS_DLSYM(NS_StringContainerInit);
301 NS_DLSYM(NS_CStringContainerInit);
302 NS_DLSYM(NS_StringContainerFinish);
303 NS_DLSYM(NS_CStringContainerFinish);
304 NS_DLSYM(NS_StringSetData);
305 NS_DLSYM(NS_CStringSetData);
306 NS_DLSYM(NS_NewLocalFile);
307 NS_DLSYM(NS_CStringGetData);
311 NS_StringContainerInit(&path);
312 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
313 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
314 NS_StringContainerFinish(&path);
315 if(NS_FAILED(nsres)) {
316 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
321 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
322 if(NS_FAILED(nsres)) {
323 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
328 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
330 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
332 nsres = NS_GetComponentRegistrar(®istrar);
333 if(NS_SUCCEEDED(nsres)) {
334 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
336 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
338 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
340 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
342 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
345 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
346 NULL, &IID_nsIObserver, (void**)&pStartNotif);
347 if(NS_SUCCEEDED(nsres)) {
348 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
350 ERR("Observe failed: %08lx\n", nsres);
352 nsIObserver_Release(pStartNotif);
354 ERR("could not get appstartup-notifier: %08lx\n", nsres);
360 register_nsservice(registrar);
361 init_nsio(pCompMgr, registrar);
362 nsIComponentRegistrar_Release(registrar);
368 nsACString *nsACString_Create(void)
371 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
372 NS_CStringContainerInit(ret);
376 void nsACString_SetData(nsACString *str, const char *data)
378 NS_CStringSetData(str, data, PR_UINT32_MAX);
381 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
383 return NS_CStringGetData(str, data, termited);
386 void nsACString_Destroy(nsACString *str)
388 NS_CStringContainerFinish(str);
389 HeapFree(GetProcessHeap(), 0, str);
392 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
394 nsIStringInputStream *ret;
400 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
401 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
403 if(NS_FAILED(nsres)) {
404 ERR("Could not get nsIStringInputStream\n");
408 nsres = nsIStringInputStream_SetData(ret, data, data_len);
409 if(NS_FAILED(nsres)) {
410 ERR("AdoptData failed: %08lx\n", nsres);
411 nsIStringInputStream_Release(ret);
415 return (nsIInputStream*)ret;
423 nsIComponentManager_Release(pCompMgr);
426 nsIServiceManager_Release(pServMgr);
432 /**********************************************************
433 * nsIWebBrowserChrome interface
436 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
438 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
439 nsIIDRef riid, nsQIResult result)
441 NSContainer *This = NSWBCHROME_THIS(iface);
444 if(IsEqualGUID(&IID_nsISupports, riid)) {
445 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
446 *result = NSWBCHROME(This);
447 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
448 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
449 *result = NSWBCHROME(This);
450 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
451 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
452 *result = NSCML(This);
453 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
454 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
455 *result = NSURICL(This);
456 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
457 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
458 *result = NSEMBWNDS(This);
462 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
466 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
467 return NS_NOINTERFACE;
470 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
472 NSContainer *This = NSWBCHROME_THIS(iface);
473 LONG ref = InterlockedIncrement(&This->ref);
475 TRACE("(%p) ref=%ld\n", This, ref);
480 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
482 NSContainer *This = NSWBCHROME_THIS(iface);
483 LONG ref = InterlockedDecrement(&This->ref);
485 TRACE("(%p) ref=%ld\n", This, ref);
488 HeapFree(GetProcessHeap(), 0, This);
493 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
494 PRUint32 statusType, const PRUnichar *status)
496 NSContainer *This = NSWBCHROME_THIS(iface);
497 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
498 return NS_ERROR_NOT_IMPLEMENTED;
501 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
502 nsIWebBrowser **aWebBrowser)
504 NSContainer *This = NSWBCHROME_THIS(iface);
506 TRACE("(%p)->(%p)\n", This, aWebBrowser);
509 return NS_ERROR_INVALID_ARG;
512 nsIWebBrowser_AddRef(This->webbrowser);
513 *aWebBrowser = This->webbrowser;
517 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
518 nsIWebBrowser *aWebBrowser)
520 NSContainer *This = NSWBCHROME_THIS(iface);
522 TRACE("(%p)->(%p)\n", This, aWebBrowser);
524 if(aWebBrowser != This->webbrowser)
525 ERR("Wrong nsWebBrowser!\n");
530 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
531 PRUint32 *aChromeFlags)
533 NSContainer *This = NSWBCHROME_THIS(iface);
534 WARN("(%p)->(%p)\n", This, aChromeFlags);
535 return NS_ERROR_NOT_IMPLEMENTED;
538 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
539 PRUint32 aChromeFlags)
541 NSContainer *This = NSWBCHROME_THIS(iface);
542 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
543 return NS_ERROR_NOT_IMPLEMENTED;
546 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
548 NSContainer *This = NSWBCHROME_THIS(iface);
549 TRACE("(%p)\n", This);
550 return NS_ERROR_NOT_IMPLEMENTED;
553 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
554 PRInt32 aCX, PRInt32 aCY)
556 NSContainer *This = NSWBCHROME_THIS(iface);
557 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
558 return NS_ERROR_NOT_IMPLEMENTED;
561 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
563 NSContainer *This = NSWBCHROME_THIS(iface);
564 WARN("(%p)\n", This);
565 return NS_ERROR_NOT_IMPLEMENTED;
568 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
570 NSContainer *This = NSWBCHROME_THIS(iface);
571 WARN("(%p)->(%p)\n", This, _retval);
572 return NS_ERROR_NOT_IMPLEMENTED;
575 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
578 NSContainer *This = NSWBCHROME_THIS(iface);
579 WARN("(%p)->(%08lx)\n", This, aStatus);
580 return NS_ERROR_NOT_IMPLEMENTED;
583 #undef NSWBCHROME_THIS
585 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
586 nsWebBrowserChrome_QueryInterface,
587 nsWebBrowserChrome_AddRef,
588 nsWebBrowserChrome_Release,
589 nsWebBrowserChrome_SetStatus,
590 nsWebBrowserChrome_GetWebBrowser,
591 nsWebBrowserChrome_SetWebBrowser,
592 nsWebBrowserChrome_GetChromeFlags,
593 nsWebBrowserChrome_SetChromeFlags,
594 nsWebBrowserChrome_DestroyBrowserWindow,
595 nsWebBrowserChrome_SizeBrowserTo,
596 nsWebBrowserChrome_ShowAsModal,
597 nsWebBrowserChrome_IsWindowModal,
598 nsWebBrowserChrome_ExitModalEventLoop
601 /**********************************************************
602 * nsIContextMenuListener interface
605 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
607 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
608 nsIIDRef riid, nsQIResult result)
610 NSContainer *This = NSCML_THIS(iface);
611 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
614 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
616 NSContainer *This = NSCML_THIS(iface);
617 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
620 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
622 NSContainer *This = NSCML_THIS(iface);
623 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
626 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
627 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
629 NSContainer *This = NSCML_THIS(iface);
630 nsIDOMMouseEvent *event;
632 DWORD dwID = CONTEXT_MENU_DEFAULT;
635 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
637 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
638 if(NS_FAILED(nsres)) {
639 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
643 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
644 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
645 nsIDOMMouseEvent_Release(event);
647 switch(aContextFlags) {
649 case CONTEXT_DOCUMENT:
651 dwID = CONTEXT_MENU_DEFAULT;
654 case CONTEXT_IMAGE|CONTEXT_LINK:
655 dwID = CONTEXT_MENU_IMAGE;
658 dwID = CONTEXT_MENU_ANCHOR;
661 dwID = CONTEXT_MENU_CONTROL;
664 FIXME("aContextFlags=%08lx\n", aContextFlags);
667 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
674 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
675 nsContextMenuListener_QueryInterface,
676 nsContextMenuListener_AddRef,
677 nsContextMenuListener_Release,
678 nsContextMenuListener_OnShowContextMenu
681 /**********************************************************
682 * nsIURIContentListener interface
685 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
687 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
688 nsIIDRef riid, nsQIResult result)
690 NSContainer *This = NSURICL_THIS(iface);
691 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
694 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
696 NSContainer *This = NSURICL_THIS(iface);
697 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
700 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
702 NSContainer *This = NSURICL_THIS(iface);
703 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
706 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
707 nsIURI *aURI, PRBool *_retval)
709 NSContainer *This = NSURICL_THIS(iface);
710 nsIWineURI *wine_uri;
711 nsACString *spec_str = nsACString_Create();
715 nsIURI_GetSpec(aURI, spec_str);
716 nsACString_GetData(spec_str, &spec, NULL);
718 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
720 nsACString_Destroy(spec_str);
722 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
723 if(NS_SUCCEEDED(nsres)) {
724 nsIWineURI_SetNSContainer(wine_uri, This);
725 nsIWineURI_Release(wine_uri);
727 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
730 return NS_ERROR_NOT_IMPLEMENTED;
733 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
734 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
735 nsIStreamListener **aContentHandler, PRBool *_retval)
737 NSContainer *This = NSURICL_THIS(iface);
738 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
739 aRequest, aContentHandler, _retval);
740 return NS_ERROR_NOT_IMPLEMENTED;
743 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
744 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
746 NSContainer *This = NSURICL_THIS(iface);
748 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
750 /* FIXME: Should we do something here? */
755 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
756 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
759 NSContainer *This = NSURICL_THIS(iface);
760 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
761 aDesiredContentType, _retval);
762 return NS_ERROR_NOT_IMPLEMENTED;
765 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
766 nsISupports **aLoadCookie)
768 NSContainer *This = NSURICL_THIS(iface);
769 WARN("(%p)->(%p)\n", This, aLoadCookie);
770 return NS_ERROR_NOT_IMPLEMENTED;
773 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
774 nsISupports *aLoadCookie)
776 NSContainer *This = NSURICL_THIS(iface);
777 WARN("(%p)->(%p)\n", This, aLoadCookie);
778 return NS_ERROR_NOT_IMPLEMENTED;
781 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
782 nsIURIContentListener **aParentContentListener)
784 NSContainer *This = NSURICL_THIS(iface);
785 WARN("(%p)->(%p)\n", This, aParentContentListener);
786 return NS_ERROR_NOT_IMPLEMENTED;
789 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
790 nsIURIContentListener *aParentContentListener)
792 NSContainer *This = NSURICL_THIS(iface);
793 WARN("(%p)->(%p)\n", This, aParentContentListener);
794 return NS_ERROR_NOT_IMPLEMENTED;
799 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
800 nsURIContentListener_QueryInterface,
801 nsURIContentListener_AddRef,
802 nsURIContentListener_Release,
803 nsURIContentListener_OnStartURIOpen,
804 nsURIContentListener_DoContent,
805 nsURIContentListener_IsPreferred,
806 nsURIContentListener_CanHandleContent,
807 nsURIContentListener_GetLoadCookie,
808 nsURIContentListener_SetLoadCookie,
809 nsURIContentListener_GetParentContentListener,
810 nsURIContentListener_SetParentContentListener
813 /**********************************************************
814 * nsIEmbeddinSiteWindow interface
817 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
819 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
820 nsIIDRef riid, nsQIResult result)
822 NSContainer *This = NSEMBWNDS_THIS(iface);
823 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
826 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
828 NSContainer *This = NSEMBWNDS_THIS(iface);
829 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
832 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
834 NSContainer *This = NSEMBWNDS_THIS(iface);
835 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
838 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
839 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
841 NSContainer *This = NSEMBWNDS_THIS(iface);
842 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
847 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
849 NSContainer *This = NSEMBWNDS_THIS(iface);
850 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
851 return NS_ERROR_NOT_IMPLEMENTED;
854 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
856 NSContainer *This = NSEMBWNDS_THIS(iface);
857 WARN("(%p)\n", This);
858 return NS_ERROR_NOT_IMPLEMENTED;
861 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
864 NSContainer *This = NSEMBWNDS_THIS(iface);
865 WARN("(%p)->(%p)\n", This, aVisibility);
866 return NS_ERROR_NOT_IMPLEMENTED;
869 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
872 NSContainer *This = NSEMBWNDS_THIS(iface);
873 WARN("(%p)->(%x)\n", This, aVisibility);
874 return NS_ERROR_NOT_IMPLEMENTED;
877 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
880 NSContainer *This = NSEMBWNDS_THIS(iface);
881 WARN("(%p)->(%p)\n", This, aTitle);
882 return NS_ERROR_NOT_IMPLEMENTED;
885 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
886 const PRUnichar *aTitle)
888 NSContainer *This = NSEMBWNDS_THIS(iface);
889 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
890 return NS_ERROR_NOT_IMPLEMENTED;
893 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
896 NSContainer *This = NSEMBWNDS_THIS(iface);
898 TRACE("(%p)->(%p)\n", This, aSiteWindow);
900 *aSiteWindow = This->hwnd;
904 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
905 nsEmbeddingSiteWindow_QueryInterface,
906 nsEmbeddingSiteWindow_AddRef,
907 nsEmbeddingSiteWindow_Release,
908 nsEmbeddingSiteWindow_SetDimensions,
909 nsEmbeddingSiteWindow_GetDimensions,
910 nsEmbeddingSiteWindow_SetFocus,
911 nsEmbeddingSiteWindow_GetVisibility,
912 nsEmbeddingSiteWindow_SetVisibility,
913 nsEmbeddingSiteWindow_GetTitle,
914 nsEmbeddingSiteWindow_SetTitle,
915 nsEmbeddingSiteWindow_GetSiteWindow
918 void NSContainer_Create(HTMLDocument *doc)
920 nsIWebBrowserSetup *wbsetup;
927 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
929 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
930 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
931 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
932 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
936 ret->load_call = FALSE;
938 doc->nscontainer = ret;
940 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
941 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
943 ERR("Creating WebBrowser failed: %08lx\n", nsres);
945 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
947 ERR("SetContainerWindow failed: %08lx\n", nsres);
949 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
950 (void**)&ret->window);
952 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
954 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
956 if(NS_SUCCEEDED(nsres)) {
957 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
958 nsIWebBrowserSetup_Release(wbsetup);
960 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
962 ERR("Could not get nsIWebBrowserSetup interface\n");
965 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
966 (void**)&ret->navigation);
968 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
970 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
971 (void**)&ret->focus);
973 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
976 nsres = nsIWebBrowserStream_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserStream,
977 (void**)&ret->stream);
979 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
984 if(!nscontainer_class)
985 register_nscontainer_class();
987 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
988 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
989 GetDesktopWindow(), NULL, hInst, doc);
991 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
992 if(NS_SUCCEEDED(nsres)) {
993 nsres = nsIBaseWindow_Create(ret->window);
995 WARN("Creating window failed: %08lx\n", nsres);
997 nsIBaseWindow_SetVisibility(ret->window, FALSE);
998 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1000 ERR("InitWindow failed: %08lx\n", nsres);
1003 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1004 if(NS_FAILED(nsres))
1005 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1008 void NSContainer_Release(NSContainer *This)
1010 nsIBaseWindow *base_window;
1013 TRACE("(%p)\n", This);
1015 ShowWindow(This->hwnd, SW_HIDE);
1016 SetParent(This->hwnd, NULL);
1018 nsres = nsIWebBrowser_QueryInterface(This->webbrowser, &IID_nsIBaseWindow,
1019 (void**)&base_window);
1020 if(NS_SUCCEEDED(nsres)) {
1021 nsIBaseWindow_SetVisibility(base_window, FALSE);
1022 nsIBaseWindow_Destroy(base_window);
1023 nsIBaseWindow_Release(base_window);
1025 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1028 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1030 nsIWebBrowser_Release(This->webbrowser);
1031 This->webbrowser = NULL;
1033 nsIWebNavigation_Release(This->navigation);
1034 This->navigation = NULL;
1036 nsIBaseWindow_Release(This->window);
1037 This->window = NULL;
1040 nsIWebBrowserStream_Release(This->stream);
1041 This->stream = NULL;
1045 DestroyWindow(This->hwnd);
1049 nsIWebBrowserChrome_Release(NSWBCHROME(This));