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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
44 #define APPSTARTUP_TOPIC "app-startup"
46 #define PR_UINT32_MAX 0xffffffff
48 struct nsCStringContainer {
55 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
56 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
57 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
58 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
59 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
60 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
61 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
62 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
63 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
64 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
65 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
66 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
68 static HINSTANCE hXPCOM = NULL;
70 static nsIServiceManager *pServMgr = NULL;
71 static nsIComponentManager *pCompMgr = NULL;
72 static nsIMemory *nsmem = NULL;
74 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
76 static ATOM nscontainer_class;
78 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
83 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
85 if(msg == WM_CREATE) {
86 This = *(NSContainer**)lParam;
87 SetPropW(hwnd, wszTHIS, This);
89 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
94 TRACE("(%p)->(WM_SIZE)\n", This);
96 nsres = nsIBaseWindow_SetSize(This->window,
97 LOWORD(lParam), HIWORD(lParam), TRUE);
99 WARN("SetSize failed: %08lx\n", nsres);
102 return DefWindowProcW(hwnd, msg, wParam, lParam);
106 static void register_nscontainer_class(void)
108 static WNDCLASSEXW wndclass = {
112 0, 0, NULL, NULL, NULL, NULL, NULL,
116 wndclass.hInstance = hInst;
117 nscontainer_class = RegisterClassExW(&wndclass);
120 static BOOL get_mozilla_path(PRUnichar *gre_path)
122 DWORD res, type, i, size = MAX_PATH;
123 HKEY mozilla_key, hkey;
127 static const WCHAR wszGreKey[] =
128 {'S','o','f','t','w','a','r','e','\\',
129 'm','o','z','i','l','l','a','.','o','r','g','\\',
132 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
134 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
135 if(res != ERROR_SUCCESS) {
136 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
140 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
141 RegOpenKeyW(mozilla_key, key_name, &hkey);
142 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
143 if(res == ERROR_SUCCESS)
148 RegCloseKey(mozilla_key);
152 static BOOL get_mozctl_path(PRUnichar *gre_path)
155 DWORD res, type, size = MAX_PATH;
157 static const WCHAR wszMozCtlKey[] =
158 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
159 static const WCHAR wszBinDirectoryPath[] =
160 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
161 static const WCHAR wszMozCtlClsidKey[] =
162 {'C','L','S','I','D','\\',
163 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
164 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
165 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
167 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
168 if(res == ERROR_SUCCESS) {
169 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
170 if(res == ERROR_SUCCESS)
173 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
176 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
177 if(res == ERROR_SUCCESS) {
178 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
179 if(res == ERROR_SUCCESS) {
181 if((ptr = strrchrW(gre_path, '\\')))
185 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
189 TRACE("Could not find Mozilla ActiveX Control\n");
194 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
197 DWORD res, type, size = MAX_PATH;
199 static const WCHAR wszMshtmlKey[] = {
200 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
201 '\\','M','S','H','T','M','L',0};
202 static const WCHAR wszGeckoPath[] =
203 {'G','e','c','k','o','P','a','t','h',0};
205 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
206 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
207 if(res != ERROR_SUCCESS)
210 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
211 if(res != ERROR_SUCCESS || type != REG_SZ)
217 static void set_profile(void)
220 PRBool exists = FALSE;
223 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
225 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
226 &IID_nsIProfile, (void**)&profile);
227 if(NS_FAILED(nsres)) {
228 ERR("Could not get profile service: %08lx\n", nsres);
232 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
234 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
236 ERR("CreateNewProfile failed: %08lx\n", nsres);
239 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
241 ERR("SetCurrentProfile failed: %08lx\n", nsres);
243 nsIProfile_Release(profile);
246 static BOOL load_gecko(void)
249 nsIObserver *pStartNotif;
250 nsIComponentRegistrar *registrar = NULL;
253 PRUnichar gre_path[MAX_PATH];
254 WCHAR path_env[MAX_PATH];
257 static BOOL tried_load = FALSE;
258 static const WCHAR wszPATH[] = {'P','A','T','H',0};
259 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
264 return pCompMgr != NULL;
267 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
268 && !get_mozilla_path(gre_path)) {
269 install_wine_gecko();
270 if(!get_wine_gecko_path(gre_path)) {
271 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_StringGetData);
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 init_nsio(pCompMgr, registrar);
344 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
347 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
348 NULL, &IID_nsIObserver, (void**)&pStartNotif);
349 if(NS_SUCCEEDED(nsres)) {
350 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
352 ERR("Observe failed: %08lx\n", nsres);
354 nsIObserver_Release(pStartNotif);
356 ERR("could not get appstartup-notifier: %08lx\n", nsres);
361 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
362 NULL, &IID_nsIMemory, (void**)&nsmem);
364 ERR("Could not get nsIMemory: %08lx\n", nsres);
367 register_nsservice(registrar, pServMgr);
368 nsIComponentRegistrar_Release(registrar);
374 void *nsalloc(size_t size)
376 return nsIMemory_Alloc(nsmem, size);
379 void nsfree(void *mem)
381 nsIMemory_Free(nsmem, mem);
384 void nsACString_Init(nsACString *str, const char *data)
386 NS_CStringContainerInit(str);
388 NS_CStringSetData(str, data, PR_UINT32_MAX);
391 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
393 return NS_CStringGetData(str, data, termited);
396 void nsACString_Finish(nsACString *str)
398 NS_CStringContainerFinish(str);
401 void nsAString_Init(nsAString *str, const PRUnichar *data)
403 NS_StringContainerInit(str);
405 NS_StringSetData(str, data, PR_UINT32_MAX);
408 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
410 return NS_StringGetData(str, data, termited);
413 void nsAString_Finish(nsAString *str)
415 NS_StringContainerFinish(str);
418 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
420 nsIStringInputStream *ret;
426 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
427 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
429 if(NS_FAILED(nsres)) {
430 ERR("Could not get nsIStringInputStream\n");
434 nsres = nsIStringInputStream_SetData(ret, data, data_len);
435 if(NS_FAILED(nsres)) {
436 ERR("AdoptData failed: %08lx\n", nsres);
437 nsIStringInputStream_Release(ret);
441 return (nsIInputStream*)ret;
449 nsIComponentManager_Release(pCompMgr);
452 nsIServiceManager_Release(pServMgr);
455 nsIMemory_Release(nsmem);
461 /**********************************************************
462 * nsIWebBrowserChrome interface
465 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
467 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
468 nsIIDRef riid, nsQIResult result)
470 NSContainer *This = NSWBCHROME_THIS(iface);
473 if(IsEqualGUID(&IID_nsISupports, riid)) {
474 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
475 *result = NSWBCHROME(This);
476 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
477 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
478 *result = NSWBCHROME(This);
479 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
480 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
481 *result = NSCML(This);
482 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
483 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
484 *result = NSURICL(This);
485 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
486 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
487 *result = NSEMBWNDS(This);
488 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
489 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
490 *result = NSTOOLTIP(This);
491 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
492 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
493 *result = NSIFACEREQ(This);
494 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
495 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
496 *result = NSWEAKREF(This);
497 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
498 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
499 *result = NSSUPWEAKREF(This);
503 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
507 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
508 return NS_NOINTERFACE;
511 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
513 NSContainer *This = NSWBCHROME_THIS(iface);
514 LONG ref = InterlockedIncrement(&This->ref);
516 TRACE("(%p) ref=%ld\n", This, ref);
521 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
523 NSContainer *This = NSWBCHROME_THIS(iface);
524 LONG ref = InterlockedDecrement(&This->ref);
526 TRACE("(%p) ref=%ld\n", This, ref);
530 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
531 HeapFree(GetProcessHeap(), 0, This);
537 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
538 PRUint32 statusType, const PRUnichar *status)
540 NSContainer *This = NSWBCHROME_THIS(iface);
541 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
542 return NS_ERROR_NOT_IMPLEMENTED;
545 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
546 nsIWebBrowser **aWebBrowser)
548 NSContainer *This = NSWBCHROME_THIS(iface);
550 TRACE("(%p)->(%p)\n", This, aWebBrowser);
553 return NS_ERROR_INVALID_ARG;
556 nsIWebBrowser_AddRef(This->webbrowser);
557 *aWebBrowser = This->webbrowser;
561 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
562 nsIWebBrowser *aWebBrowser)
564 NSContainer *This = NSWBCHROME_THIS(iface);
566 TRACE("(%p)->(%p)\n", This, aWebBrowser);
568 if(aWebBrowser != This->webbrowser)
569 ERR("Wrong nsWebBrowser!\n");
574 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
575 PRUint32 *aChromeFlags)
577 NSContainer *This = NSWBCHROME_THIS(iface);
578 WARN("(%p)->(%p)\n", This, aChromeFlags);
579 return NS_ERROR_NOT_IMPLEMENTED;
582 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
583 PRUint32 aChromeFlags)
585 NSContainer *This = NSWBCHROME_THIS(iface);
586 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
587 return NS_ERROR_NOT_IMPLEMENTED;
590 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
592 NSContainer *This = NSWBCHROME_THIS(iface);
593 TRACE("(%p)\n", This);
594 return NS_ERROR_NOT_IMPLEMENTED;
597 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
598 PRInt32 aCX, PRInt32 aCY)
600 NSContainer *This = NSWBCHROME_THIS(iface);
601 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
602 return NS_ERROR_NOT_IMPLEMENTED;
605 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
607 NSContainer *This = NSWBCHROME_THIS(iface);
608 WARN("(%p)\n", This);
609 return NS_ERROR_NOT_IMPLEMENTED;
612 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
614 NSContainer *This = NSWBCHROME_THIS(iface);
615 WARN("(%p)->(%p)\n", This, _retval);
616 return NS_ERROR_NOT_IMPLEMENTED;
619 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
622 NSContainer *This = NSWBCHROME_THIS(iface);
623 WARN("(%p)->(%08lx)\n", This, aStatus);
624 return NS_ERROR_NOT_IMPLEMENTED;
627 #undef NSWBCHROME_THIS
629 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
630 nsWebBrowserChrome_QueryInterface,
631 nsWebBrowserChrome_AddRef,
632 nsWebBrowserChrome_Release,
633 nsWebBrowserChrome_SetStatus,
634 nsWebBrowserChrome_GetWebBrowser,
635 nsWebBrowserChrome_SetWebBrowser,
636 nsWebBrowserChrome_GetChromeFlags,
637 nsWebBrowserChrome_SetChromeFlags,
638 nsWebBrowserChrome_DestroyBrowserWindow,
639 nsWebBrowserChrome_SizeBrowserTo,
640 nsWebBrowserChrome_ShowAsModal,
641 nsWebBrowserChrome_IsWindowModal,
642 nsWebBrowserChrome_ExitModalEventLoop
645 /**********************************************************
646 * nsIContextMenuListener interface
649 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
651 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
652 nsIIDRef riid, nsQIResult result)
654 NSContainer *This = NSCML_THIS(iface);
655 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
658 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
660 NSContainer *This = NSCML_THIS(iface);
661 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
664 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
666 NSContainer *This = NSCML_THIS(iface);
667 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
670 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
671 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
673 NSContainer *This = NSCML_THIS(iface);
674 nsIDOMMouseEvent *event;
676 DWORD dwID = CONTEXT_MENU_DEFAULT;
679 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
681 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
682 if(NS_FAILED(nsres)) {
683 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
687 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
688 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
689 nsIDOMMouseEvent_Release(event);
691 switch(aContextFlags) {
693 case CONTEXT_DOCUMENT:
695 dwID = CONTEXT_MENU_DEFAULT;
698 case CONTEXT_IMAGE|CONTEXT_LINK:
699 dwID = CONTEXT_MENU_IMAGE;
702 dwID = CONTEXT_MENU_ANCHOR;
705 dwID = CONTEXT_MENU_CONTROL;
708 FIXME("aContextFlags=%08lx\n", aContextFlags);
711 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
718 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
719 nsContextMenuListener_QueryInterface,
720 nsContextMenuListener_AddRef,
721 nsContextMenuListener_Release,
722 nsContextMenuListener_OnShowContextMenu
725 /**********************************************************
726 * nsIURIContentListener interface
729 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
731 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
732 nsIIDRef riid, nsQIResult result)
734 NSContainer *This = NSURICL_THIS(iface);
735 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
738 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
740 NSContainer *This = NSURICL_THIS(iface);
741 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
744 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
746 NSContainer *This = NSURICL_THIS(iface);
747 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
750 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
751 nsIURI *aURI, PRBool *_retval)
753 NSContainer *This = NSURICL_THIS(iface);
754 nsIWineURI *wine_uri;
759 nsACString_Init(&spec_str, NULL);
760 nsIURI_GetSpec(aURI, &spec_str);
761 nsACString_GetData(&spec_str, &spec, NULL);
763 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
765 nsACString_Finish(&spec_str);
767 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
768 if(NS_SUCCEEDED(nsres)) {
769 nsIWineURI_SetNSContainer(wine_uri, This);
770 nsIWineURI_Release(wine_uri);
772 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
775 return NS_ERROR_NOT_IMPLEMENTED;
778 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
779 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
780 nsIStreamListener **aContentHandler, PRBool *_retval)
782 NSContainer *This = NSURICL_THIS(iface);
783 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
784 aRequest, aContentHandler, _retval);
785 return NS_ERROR_NOT_IMPLEMENTED;
788 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
789 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
791 NSContainer *This = NSURICL_THIS(iface);
793 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
795 /* FIXME: Should we do something here? */
800 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
801 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
804 NSContainer *This = NSURICL_THIS(iface);
805 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
806 aDesiredContentType, _retval);
807 return NS_ERROR_NOT_IMPLEMENTED;
810 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
811 nsISupports **aLoadCookie)
813 NSContainer *This = NSURICL_THIS(iface);
814 WARN("(%p)->(%p)\n", This, aLoadCookie);
815 return NS_ERROR_NOT_IMPLEMENTED;
818 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
819 nsISupports *aLoadCookie)
821 NSContainer *This = NSURICL_THIS(iface);
822 WARN("(%p)->(%p)\n", This, aLoadCookie);
823 return NS_ERROR_NOT_IMPLEMENTED;
826 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
827 nsIURIContentListener **aParentContentListener)
829 NSContainer *This = NSURICL_THIS(iface);
830 WARN("(%p)->(%p)\n", This, aParentContentListener);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
835 nsIURIContentListener *aParentContentListener)
837 NSContainer *This = NSURICL_THIS(iface);
838 WARN("(%p)->(%p)\n", This, aParentContentListener);
839 return NS_ERROR_NOT_IMPLEMENTED;
844 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
845 nsURIContentListener_QueryInterface,
846 nsURIContentListener_AddRef,
847 nsURIContentListener_Release,
848 nsURIContentListener_OnStartURIOpen,
849 nsURIContentListener_DoContent,
850 nsURIContentListener_IsPreferred,
851 nsURIContentListener_CanHandleContent,
852 nsURIContentListener_GetLoadCookie,
853 nsURIContentListener_SetLoadCookie,
854 nsURIContentListener_GetParentContentListener,
855 nsURIContentListener_SetParentContentListener
858 /**********************************************************
859 * nsIEmbeddinSiteWindow interface
862 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
864 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
865 nsIIDRef riid, nsQIResult result)
867 NSContainer *This = NSEMBWNDS_THIS(iface);
868 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
871 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
873 NSContainer *This = NSEMBWNDS_THIS(iface);
874 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
877 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
879 NSContainer *This = NSEMBWNDS_THIS(iface);
880 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
883 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
884 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
886 NSContainer *This = NSEMBWNDS_THIS(iface);
887 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
888 return NS_ERROR_NOT_IMPLEMENTED;
891 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
892 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
894 NSContainer *This = NSEMBWNDS_THIS(iface);
895 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
896 return NS_ERROR_NOT_IMPLEMENTED;
899 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
901 NSContainer *This = NSEMBWNDS_THIS(iface);
902 WARN("(%p)\n", This);
903 return NS_ERROR_NOT_IMPLEMENTED;
906 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
909 NSContainer *This = NSEMBWNDS_THIS(iface);
910 WARN("(%p)->(%p)\n", This, aVisibility);
911 return NS_ERROR_NOT_IMPLEMENTED;
914 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
917 NSContainer *This = NSEMBWNDS_THIS(iface);
918 WARN("(%p)->(%x)\n", This, aVisibility);
919 return NS_ERROR_NOT_IMPLEMENTED;
922 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
925 NSContainer *This = NSEMBWNDS_THIS(iface);
926 WARN("(%p)->(%p)\n", This, aTitle);
927 return NS_ERROR_NOT_IMPLEMENTED;
930 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
931 const PRUnichar *aTitle)
933 NSContainer *This = NSEMBWNDS_THIS(iface);
934 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
935 return NS_ERROR_NOT_IMPLEMENTED;
938 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
941 NSContainer *This = NSEMBWNDS_THIS(iface);
943 TRACE("(%p)->(%p)\n", This, aSiteWindow);
945 *aSiteWindow = This->hwnd;
949 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
950 nsEmbeddingSiteWindow_QueryInterface,
951 nsEmbeddingSiteWindow_AddRef,
952 nsEmbeddingSiteWindow_Release,
953 nsEmbeddingSiteWindow_SetDimensions,
954 nsEmbeddingSiteWindow_GetDimensions,
955 nsEmbeddingSiteWindow_SetFocus,
956 nsEmbeddingSiteWindow_GetVisibility,
957 nsEmbeddingSiteWindow_SetVisibility,
958 nsEmbeddingSiteWindow_GetTitle,
959 nsEmbeddingSiteWindow_SetTitle,
960 nsEmbeddingSiteWindow_GetSiteWindow
963 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
965 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
968 NSContainer *This = NSTOOLTIP_THIS(iface);
969 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
972 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
974 NSContainer *This = NSTOOLTIP_THIS(iface);
975 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
978 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
980 NSContainer *This = NSTOOLTIP_THIS(iface);
981 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
984 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
985 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
987 NSContainer *This = NSTOOLTIP_THIS(iface);
989 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
994 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
996 NSContainer *This = NSTOOLTIP_THIS(iface);
998 hide_tooltip(This->doc);
1003 #undef NSTOOLTIM_THIS
1005 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1006 nsTooltipListener_QueryInterface,
1007 nsTooltipListener_AddRef,
1008 nsTooltipListener_Release,
1009 nsTooltipListener_OnShowTooltip,
1010 nsTooltipListener_OnHideTooltip
1013 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1015 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1016 nsIIDRef riid, nsQIResult result)
1018 NSContainer *This = NSIFACEREQ_THIS(iface);
1019 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1022 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1024 NSContainer *This = NSIFACEREQ_THIS(iface);
1025 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1028 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1030 NSContainer *This = NSIFACEREQ_THIS(iface);
1031 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1034 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1035 nsIIDRef riid, nsQIResult result)
1037 NSContainer *This = NSIFACEREQ_THIS(iface);
1039 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1040 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1041 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1044 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1047 #undef NSIFACEREQ_THIS
1049 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1050 nsInterfaceRequestor_QueryInterface,
1051 nsInterfaceRequestor_AddRef,
1052 nsInterfaceRequestor_Release,
1053 nsInterfaceRequestor_GetInterface
1056 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1058 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1059 nsIIDRef riid, nsQIResult result)
1061 NSContainer *This = NSWEAKREF_THIS(iface);
1062 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1065 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1067 NSContainer *This = NSWEAKREF_THIS(iface);
1068 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1071 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1073 NSContainer *This = NSWEAKREF_THIS(iface);
1074 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1077 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1078 const nsIID *riid, void **result)
1080 NSContainer *This = NSWEAKREF_THIS(iface);
1081 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1084 #undef NSWEAKREF_THIS
1086 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1087 nsWeakReference_QueryInterface,
1088 nsWeakReference_AddRef,
1089 nsWeakReference_Release,
1090 nsWeakReference_QueryReferent
1093 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1095 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1096 nsIIDRef riid, nsQIResult result)
1098 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1099 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1102 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1104 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1105 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1108 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1110 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1111 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1114 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1115 nsIWeakReference **_retval)
1117 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1119 TRACE("(%p)->(%p)\n", This, _retval);
1121 nsIWeakReference_AddRef(NSWEAKREF(This));
1122 *_retval = NSWEAKREF(This);
1126 #undef NSWEAKREF_THIS
1128 const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1129 nsSupportsWeakReference_QueryInterface,
1130 nsSupportsWeakReference_AddRef,
1131 nsSupportsWeakReference_Release,
1132 nsSupportsWeakReference_GetWeakReference
1136 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1138 nsIWebBrowserSetup *wbsetup;
1145 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
1147 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1148 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1149 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1150 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1151 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1152 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1153 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1154 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1159 ret->bscallback = NULL;
1162 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1163 ret->parent = parent;
1165 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1166 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1167 if(NS_FAILED(nsres))
1168 ERR("Creating WebBrowser failed: %08lx\n", nsres);
1170 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1171 if(NS_FAILED(nsres))
1172 ERR("SetContainerWindow failed: %08lx\n", nsres);
1174 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1175 (void**)&ret->window);
1176 if(NS_FAILED(nsres))
1177 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1179 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1181 if(NS_SUCCEEDED(nsres)) {
1182 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1183 nsIWebBrowserSetup_Release(wbsetup);
1184 if(NS_FAILED(nsres))
1185 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1187 ERR("Could not get nsIWebBrowserSetup interface\n");
1190 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1191 (void**)&ret->navigation);
1192 if(NS_FAILED(nsres))
1193 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1195 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1196 (void**)&ret->focus);
1197 if(NS_FAILED(nsres))
1198 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1200 if(!nscontainer_class)
1201 register_nscontainer_class();
1203 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1204 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1205 GetDesktopWindow(), NULL, hInst, ret);
1207 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1208 if(NS_SUCCEEDED(nsres)) {
1209 nsres = nsIBaseWindow_Create(ret->window);
1210 if(NS_FAILED(nsres))
1211 WARN("Creating window failed: %08lx\n", nsres);
1213 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1214 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1216 ERR("InitWindow failed: %08lx\n", nsres);
1219 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1220 if(NS_FAILED(nsres))
1221 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1226 void NSContainer_Release(NSContainer *This)
1228 TRACE("(%p)\n", This);
1230 ShowWindow(This->hwnd, SW_HIDE);
1231 SetParent(This->hwnd, NULL);
1233 nsIBaseWindow_SetVisibility(This->window, FALSE);
1234 nsIBaseWindow_Destroy(This->window);
1236 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1238 nsIWebBrowser_Release(This->webbrowser);
1239 This->webbrowser = NULL;
1241 nsIWebNavigation_Release(This->navigation);
1242 This->navigation = NULL;
1244 nsIBaseWindow_Release(This->window);
1245 This->window = NULL;
1247 nsIWebBrowserFocus_Release(This->focus);
1251 DestroyWindow(This->hwnd);
1255 nsIWebBrowserChrome_Release(NSWBCHROME(This));