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 void nsACString_Init(nsACString *str, const char *data)
366 NS_CStringContainerInit(str);
368 NS_CStringSetData(str, data, PR_UINT32_MAX);
371 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
373 return NS_CStringGetData(str, data, termited);
376 void nsACString_Finish(nsACString *str)
378 NS_CStringContainerFinish(str);
381 void nsAString_Init(nsAString *str, const PRUnichar *data)
383 NS_StringContainerInit(str);
385 NS_StringSetData(str, data, PR_UINT32_MAX);
388 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
390 return NS_StringGetData(str, data, termited);
393 void nsAString_Finish(nsAString *str)
395 NS_StringContainerFinish(str);
398 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
400 nsIStringInputStream *ret;
406 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
407 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
409 if(NS_FAILED(nsres)) {
410 ERR("Could not get nsIStringInputStream\n");
414 nsres = nsIStringInputStream_SetData(ret, data, data_len);
415 if(NS_FAILED(nsres)) {
416 ERR("AdoptData failed: %08lx\n", nsres);
417 nsIStringInputStream_Release(ret);
421 return (nsIInputStream*)ret;
429 nsIComponentManager_Release(pCompMgr);
432 nsIServiceManager_Release(pServMgr);
438 /**********************************************************
439 * nsIWebBrowserChrome interface
442 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
444 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
445 nsIIDRef riid, nsQIResult result)
447 NSContainer *This = NSWBCHROME_THIS(iface);
450 if(IsEqualGUID(&IID_nsISupports, riid)) {
451 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
452 *result = NSWBCHROME(This);
453 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
454 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
455 *result = NSWBCHROME(This);
456 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
457 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
458 *result = NSCML(This);
459 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
460 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
461 *result = NSURICL(This);
462 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
463 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
464 *result = NSEMBWNDS(This);
465 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
466 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
467 *result = NSIFACEREQ(This);
471 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
475 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
476 return NS_NOINTERFACE;
479 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
481 NSContainer *This = NSWBCHROME_THIS(iface);
482 LONG ref = InterlockedIncrement(&This->ref);
484 TRACE("(%p) ref=%ld\n", This, ref);
489 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
491 NSContainer *This = NSWBCHROME_THIS(iface);
492 LONG ref = InterlockedDecrement(&This->ref);
494 TRACE("(%p) ref=%ld\n", This, ref);
498 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
499 HeapFree(GetProcessHeap(), 0, This);
505 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
506 PRUint32 statusType, const PRUnichar *status)
508 NSContainer *This = NSWBCHROME_THIS(iface);
509 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
510 return NS_ERROR_NOT_IMPLEMENTED;
513 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
514 nsIWebBrowser **aWebBrowser)
516 NSContainer *This = NSWBCHROME_THIS(iface);
518 TRACE("(%p)->(%p)\n", This, aWebBrowser);
521 return NS_ERROR_INVALID_ARG;
524 nsIWebBrowser_AddRef(This->webbrowser);
525 *aWebBrowser = This->webbrowser;
529 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
530 nsIWebBrowser *aWebBrowser)
532 NSContainer *This = NSWBCHROME_THIS(iface);
534 TRACE("(%p)->(%p)\n", This, aWebBrowser);
536 if(aWebBrowser != This->webbrowser)
537 ERR("Wrong nsWebBrowser!\n");
542 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
543 PRUint32 *aChromeFlags)
545 NSContainer *This = NSWBCHROME_THIS(iface);
546 WARN("(%p)->(%p)\n", This, aChromeFlags);
547 return NS_ERROR_NOT_IMPLEMENTED;
550 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
551 PRUint32 aChromeFlags)
553 NSContainer *This = NSWBCHROME_THIS(iface);
554 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
555 return NS_ERROR_NOT_IMPLEMENTED;
558 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
560 NSContainer *This = NSWBCHROME_THIS(iface);
561 TRACE("(%p)\n", This);
562 return NS_ERROR_NOT_IMPLEMENTED;
565 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
566 PRInt32 aCX, PRInt32 aCY)
568 NSContainer *This = NSWBCHROME_THIS(iface);
569 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
570 return NS_ERROR_NOT_IMPLEMENTED;
573 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
575 NSContainer *This = NSWBCHROME_THIS(iface);
576 WARN("(%p)\n", This);
577 return NS_ERROR_NOT_IMPLEMENTED;
580 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
582 NSContainer *This = NSWBCHROME_THIS(iface);
583 WARN("(%p)->(%p)\n", This, _retval);
584 return NS_ERROR_NOT_IMPLEMENTED;
587 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
590 NSContainer *This = NSWBCHROME_THIS(iface);
591 WARN("(%p)->(%08lx)\n", This, aStatus);
592 return NS_ERROR_NOT_IMPLEMENTED;
595 #undef NSWBCHROME_THIS
597 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
598 nsWebBrowserChrome_QueryInterface,
599 nsWebBrowserChrome_AddRef,
600 nsWebBrowserChrome_Release,
601 nsWebBrowserChrome_SetStatus,
602 nsWebBrowserChrome_GetWebBrowser,
603 nsWebBrowserChrome_SetWebBrowser,
604 nsWebBrowserChrome_GetChromeFlags,
605 nsWebBrowserChrome_SetChromeFlags,
606 nsWebBrowserChrome_DestroyBrowserWindow,
607 nsWebBrowserChrome_SizeBrowserTo,
608 nsWebBrowserChrome_ShowAsModal,
609 nsWebBrowserChrome_IsWindowModal,
610 nsWebBrowserChrome_ExitModalEventLoop
613 /**********************************************************
614 * nsIContextMenuListener interface
617 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
619 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
620 nsIIDRef riid, nsQIResult result)
622 NSContainer *This = NSCML_THIS(iface);
623 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
626 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
628 NSContainer *This = NSCML_THIS(iface);
629 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
632 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
634 NSContainer *This = NSCML_THIS(iface);
635 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
638 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
639 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
641 NSContainer *This = NSCML_THIS(iface);
642 nsIDOMMouseEvent *event;
644 DWORD dwID = CONTEXT_MENU_DEFAULT;
647 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
649 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
650 if(NS_FAILED(nsres)) {
651 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
655 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
656 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
657 nsIDOMMouseEvent_Release(event);
659 switch(aContextFlags) {
661 case CONTEXT_DOCUMENT:
663 dwID = CONTEXT_MENU_DEFAULT;
666 case CONTEXT_IMAGE|CONTEXT_LINK:
667 dwID = CONTEXT_MENU_IMAGE;
670 dwID = CONTEXT_MENU_ANCHOR;
673 dwID = CONTEXT_MENU_CONTROL;
676 FIXME("aContextFlags=%08lx\n", aContextFlags);
679 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
686 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
687 nsContextMenuListener_QueryInterface,
688 nsContextMenuListener_AddRef,
689 nsContextMenuListener_Release,
690 nsContextMenuListener_OnShowContextMenu
693 /**********************************************************
694 * nsIURIContentListener interface
697 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
699 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
700 nsIIDRef riid, nsQIResult result)
702 NSContainer *This = NSURICL_THIS(iface);
703 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
706 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
708 NSContainer *This = NSURICL_THIS(iface);
709 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
712 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
714 NSContainer *This = NSURICL_THIS(iface);
715 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
718 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
719 nsIURI *aURI, PRBool *_retval)
721 NSContainer *This = NSURICL_THIS(iface);
722 nsIWineURI *wine_uri;
727 nsACString_Init(&spec_str, NULL);
728 nsIURI_GetSpec(aURI, &spec_str);
729 nsACString_GetData(&spec_str, &spec, NULL);
731 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
733 nsACString_Finish(&spec_str);
735 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
736 if(NS_SUCCEEDED(nsres)) {
737 nsIWineURI_SetNSContainer(wine_uri, This);
738 nsIWineURI_Release(wine_uri);
740 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
743 return NS_ERROR_NOT_IMPLEMENTED;
746 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
747 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
748 nsIStreamListener **aContentHandler, PRBool *_retval)
750 NSContainer *This = NSURICL_THIS(iface);
751 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
752 aRequest, aContentHandler, _retval);
753 return NS_ERROR_NOT_IMPLEMENTED;
756 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
757 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
759 NSContainer *This = NSURICL_THIS(iface);
761 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
763 /* FIXME: Should we do something here? */
768 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
769 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
772 NSContainer *This = NSURICL_THIS(iface);
773 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
774 aDesiredContentType, _retval);
775 return NS_ERROR_NOT_IMPLEMENTED;
778 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
779 nsISupports **aLoadCookie)
781 NSContainer *This = NSURICL_THIS(iface);
782 WARN("(%p)->(%p)\n", This, aLoadCookie);
783 return NS_ERROR_NOT_IMPLEMENTED;
786 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
787 nsISupports *aLoadCookie)
789 NSContainer *This = NSURICL_THIS(iface);
790 WARN("(%p)->(%p)\n", This, aLoadCookie);
791 return NS_ERROR_NOT_IMPLEMENTED;
794 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
795 nsIURIContentListener **aParentContentListener)
797 NSContainer *This = NSURICL_THIS(iface);
798 WARN("(%p)->(%p)\n", This, aParentContentListener);
799 return NS_ERROR_NOT_IMPLEMENTED;
802 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
803 nsIURIContentListener *aParentContentListener)
805 NSContainer *This = NSURICL_THIS(iface);
806 WARN("(%p)->(%p)\n", This, aParentContentListener);
807 return NS_ERROR_NOT_IMPLEMENTED;
812 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
813 nsURIContentListener_QueryInterface,
814 nsURIContentListener_AddRef,
815 nsURIContentListener_Release,
816 nsURIContentListener_OnStartURIOpen,
817 nsURIContentListener_DoContent,
818 nsURIContentListener_IsPreferred,
819 nsURIContentListener_CanHandleContent,
820 nsURIContentListener_GetLoadCookie,
821 nsURIContentListener_SetLoadCookie,
822 nsURIContentListener_GetParentContentListener,
823 nsURIContentListener_SetParentContentListener
826 /**********************************************************
827 * nsIEmbeddinSiteWindow interface
830 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
832 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
833 nsIIDRef riid, nsQIResult result)
835 NSContainer *This = NSEMBWNDS_THIS(iface);
836 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
839 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
841 NSContainer *This = NSEMBWNDS_THIS(iface);
842 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
845 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
847 NSContainer *This = NSEMBWNDS_THIS(iface);
848 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
851 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
852 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
854 NSContainer *This = NSEMBWNDS_THIS(iface);
855 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
856 return NS_ERROR_NOT_IMPLEMENTED;
859 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
860 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
862 NSContainer *This = NSEMBWNDS_THIS(iface);
863 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
864 return NS_ERROR_NOT_IMPLEMENTED;
867 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
869 NSContainer *This = NSEMBWNDS_THIS(iface);
870 WARN("(%p)\n", This);
871 return NS_ERROR_NOT_IMPLEMENTED;
874 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
877 NSContainer *This = NSEMBWNDS_THIS(iface);
878 WARN("(%p)->(%p)\n", This, aVisibility);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
885 NSContainer *This = NSEMBWNDS_THIS(iface);
886 WARN("(%p)->(%x)\n", This, aVisibility);
887 return NS_ERROR_NOT_IMPLEMENTED;
890 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
893 NSContainer *This = NSEMBWNDS_THIS(iface);
894 WARN("(%p)->(%p)\n", This, aTitle);
895 return NS_ERROR_NOT_IMPLEMENTED;
898 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
899 const PRUnichar *aTitle)
901 NSContainer *This = NSEMBWNDS_THIS(iface);
902 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
903 return NS_ERROR_NOT_IMPLEMENTED;
906 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
909 NSContainer *This = NSEMBWNDS_THIS(iface);
911 TRACE("(%p)->(%p)\n", This, aSiteWindow);
913 *aSiteWindow = This->hwnd;
917 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
918 nsEmbeddingSiteWindow_QueryInterface,
919 nsEmbeddingSiteWindow_AddRef,
920 nsEmbeddingSiteWindow_Release,
921 nsEmbeddingSiteWindow_SetDimensions,
922 nsEmbeddingSiteWindow_GetDimensions,
923 nsEmbeddingSiteWindow_SetFocus,
924 nsEmbeddingSiteWindow_GetVisibility,
925 nsEmbeddingSiteWindow_SetVisibility,
926 nsEmbeddingSiteWindow_GetTitle,
927 nsEmbeddingSiteWindow_SetTitle,
928 nsEmbeddingSiteWindow_GetSiteWindow
931 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
933 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
934 nsIIDRef riid, nsQIResult result)
936 NSContainer *This = NSIFACEREQ_THIS(iface);
937 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
940 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
942 NSContainer *This = NSIFACEREQ_THIS(iface);
943 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
946 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
948 NSContainer *This = NSIFACEREQ_THIS(iface);
949 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
952 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
953 nsIIDRef riid, nsQIResult result)
955 NSContainer *This = NSIFACEREQ_THIS(iface);
957 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
958 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
959 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
962 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
965 #undef NSIFACEREQ_THIS
967 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
968 nsInterfaceRequestor_QueryInterface,
969 nsInterfaceRequestor_AddRef,
970 nsInterfaceRequestor_Release,
971 nsInterfaceRequestor_GetInterface
974 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
976 nsIWebBrowserSetup *wbsetup;
983 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
985 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
986 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
987 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
988 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
989 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
993 ret->load_call = FALSE;
996 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
997 ret->parent = parent;
999 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1000 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1001 if(NS_FAILED(nsres))
1002 ERR("Creating WebBrowser failed: %08lx\n", nsres);
1004 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1005 if(NS_FAILED(nsres))
1006 ERR("SetContainerWindow failed: %08lx\n", nsres);
1008 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1009 (void**)&ret->window);
1010 if(NS_FAILED(nsres))
1011 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1013 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1015 if(NS_SUCCEEDED(nsres)) {
1016 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1017 nsIWebBrowserSetup_Release(wbsetup);
1018 if(NS_FAILED(nsres))
1019 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1021 ERR("Could not get nsIWebBrowserSetup interface\n");
1024 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1025 (void**)&ret->navigation);
1026 if(NS_FAILED(nsres))
1027 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1029 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1030 (void**)&ret->focus);
1031 if(NS_FAILED(nsres))
1032 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1035 nsres = nsIWebBrowserStream_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserStream,
1036 (void**)&ret->stream);
1037 if(NS_FAILED(nsres))
1038 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
1043 if(!nscontainer_class)
1044 register_nscontainer_class();
1046 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1047 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1048 GetDesktopWindow(), NULL, hInst, ret);
1050 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1051 if(NS_SUCCEEDED(nsres)) {
1052 nsres = nsIBaseWindow_Create(ret->window);
1053 if(NS_FAILED(nsres))
1054 WARN("Creating window failed: %08lx\n", nsres);
1056 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1057 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1059 ERR("InitWindow failed: %08lx\n", nsres);
1062 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1063 if(NS_FAILED(nsres))
1064 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1069 void NSContainer_Release(NSContainer *This)
1071 nsIBaseWindow *base_window;
1074 TRACE("(%p)\n", This);
1076 ShowWindow(This->hwnd, SW_HIDE);
1077 SetParent(This->hwnd, NULL);
1079 nsres = nsIWebBrowser_QueryInterface(This->webbrowser, &IID_nsIBaseWindow,
1080 (void**)&base_window);
1081 if(NS_SUCCEEDED(nsres)) {
1082 nsIBaseWindow_SetVisibility(base_window, FALSE);
1083 nsIBaseWindow_Destroy(base_window);
1084 nsIBaseWindow_Release(base_window);
1086 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1089 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1091 nsIWebBrowser_Release(This->webbrowser);
1092 This->webbrowser = NULL;
1094 nsIWebNavigation_Release(This->navigation);
1095 This->navigation = NULL;
1097 nsIBaseWindow_Release(This->window);
1098 This->window = NULL;
1101 nsIWebBrowserStream_Release(This->stream);
1102 This->stream = NULL;
1106 DestroyWindow(This->hwnd);
1110 nsIWebBrowserChrome_Release(NSWBCHROME(This));