mshtml: Added wrapper of nsIOService.
[wine/multimedia.git] / dlls / mshtml / nsembed.c
blob004901ea005516f15e182fd7a8c560c64a76e3b4
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
42 #define APPSTARTUP_TOPIC "app-startup"
44 #define PR_UINT32_MAX 0xffffffff
46 struct nsStringContainer {
47 void *v;
48 void *d1;
49 PRUint32 d2;
50 void *d3;
53 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
54 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
55 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
56 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
57 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
58 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
59 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
60 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
61 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
62 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
63 static PRUint32 (*NS_CStringGetData)(nsACString*,const char**,PRBool*);
65 static HINSTANCE hXPCOM = NULL;
67 static nsIServiceManager *pServMgr = NULL;
68 static nsIComponentManager *pCompMgr = NULL;
70 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
72 static ATOM nscontainer_class;
74 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
76 HTMLDocument *This;
77 nsresult nsres;
79 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
81 if(msg == WM_CREATE) {
82 This = *(HTMLDocument**)lParam;
83 SetPropW(hwnd, wszTHIS, This);
84 }else {
85 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
88 switch(msg) {
89 case WM_SIZE:
90 TRACE("(%p)->(WM_SIZE)\n", This);
92 nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
93 LOWORD(lParam), HIWORD(lParam), TRUE);
94 if(NS_FAILED(nsres))
95 WARN("SetSize failed: %08lx\n", nsres);
98 return DefWindowProcW(hwnd, msg, wParam, lParam);
102 static void register_nscontainer_class(void)
104 static WNDCLASSEXW wndclass = {
105 sizeof(WNDCLASSEXW),
106 CS_DBLCLKS,
107 nsembed_proc,
108 0, 0, NULL, NULL, NULL, NULL, NULL,
109 wszNsContainer,
110 NULL,
112 wndclass.hInstance = hInst;
113 nscontainer_class = RegisterClassExW(&wndclass);
116 static BOOL get_mozilla_path(PRUnichar *gre_path)
118 DWORD res, type, i, size = MAX_PATH;
119 HKEY mozilla_key, hkey;
120 WCHAR key_name[100];
121 BOOL ret = FALSE;
123 static const WCHAR wszGreKey[] =
124 {'S','o','f','t','w','a','r','e','\\',
125 'm','o','z','i','l','l','a','.','o','r','g','\\',
126 'G','R','E',0};
128 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
130 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
131 if(res != ERROR_SUCCESS) {
132 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
133 return FALSE;
136 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
137 RegOpenKeyW(mozilla_key, key_name, &hkey);
138 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
139 if(res == ERROR_SUCCESS)
140 ret = TRUE;
141 RegCloseKey(hkey);
144 RegCloseKey(mozilla_key);
145 return ret;
148 static BOOL get_mozctl_path(PRUnichar *gre_path)
150 HKEY hkey;
151 DWORD res, type, size = MAX_PATH;
153 static const WCHAR wszMozCtlKey[] =
154 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
155 static const WCHAR wszBinDirectoryPath[] =
156 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
157 static const WCHAR wszMozCtlClsidKey[] =
158 {'C','L','S','I','D','\\',
159 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
160 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
161 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
163 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
164 if(res == ERROR_SUCCESS) {
165 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
166 if(res == ERROR_SUCCESS)
167 return TRUE;
168 else
169 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
172 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
173 if(res == ERROR_SUCCESS) {
174 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
175 if(res == ERROR_SUCCESS) {
176 WCHAR *ptr;
177 if((ptr = strrchrW(gre_path, '\\')))
178 ptr[1] = 0;
179 return TRUE;
180 }else {
181 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
185 TRACE("Could not find Mozilla ActiveX Control\n");
187 return FALSE;
190 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
192 HKEY hkey;
193 DWORD res, type, size = MAX_PATH;
195 static const WCHAR wszMshtmlKey[] = {
196 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
197 '\\','M','S','H','T','M','L',0};
198 static const WCHAR wszGeckoPath[] =
199 {'G','e','c','k','o','P','a','t','h',0};
201 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
202 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
203 if(res != ERROR_SUCCESS)
204 return FALSE;
206 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
207 if(res != ERROR_SUCCESS || type != REG_SZ)
208 return FALSE;
210 return TRUE;
213 static void set_profile(void)
215 nsIProfile *profile;
216 PRBool exists = FALSE;
217 nsresult nsres;
219 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
221 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
222 &IID_nsIProfile, (void**)&profile);
223 if(NS_FAILED(nsres)) {
224 ERR("Could not get profile service: %08lx\n", nsres);
225 return;
228 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
229 if(!exists) {
230 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
231 if(NS_FAILED(nsres))
232 ERR("CreateNewProfile failed: %08lx\n", nsres);
235 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
236 if(NS_FAILED(nsres))
237 ERR("SetCurrentProfile failed: %08lx\n", nsres);
239 nsIProfile_Release(profile);
242 static BOOL load_gecko(void)
244 nsresult nsres;
245 nsIObserver *pStartNotif;
246 nsIComponentRegistrar *registrar = NULL;
247 nsAString path;
248 nsIFile *gre_dir;
249 PRUnichar gre_path[MAX_PATH];
250 WCHAR path_env[MAX_PATH];
251 int len;
253 static BOOL tried_load = FALSE;
254 static const WCHAR wszPATH[] = {'P','A','T','H',0};
255 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
257 TRACE("()\n");
259 if(tried_load)
260 return pCompMgr != NULL;
261 tried_load = TRUE;
263 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
264 && !get_mozilla_path(gre_path)) {
265 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
266 return FALSE;
269 TRACE("found path %s\n", debugstr_w(gre_path));
271 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
272 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
273 len = strlenW(path_env);
274 path_env[len++] = ';';
275 strcpyW(path_env+len, gre_path);
276 SetEnvironmentVariableW(wszPATH, path_env);
278 hXPCOM = LoadLibraryW(strXPCOM);
279 if(!hXPCOM) {
280 ERR("Could not load XPCOM: %ld\n", GetLastError());
281 return FALSE;
284 #define NS_DLSYM(func) \
285 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
286 if(!func) \
287 ERR("Could not GetProcAddress(" #func ") failed\n")
289 NS_DLSYM(NS_InitXPCOM2);
290 NS_DLSYM(NS_ShutdownXPCOM);
291 NS_DLSYM(NS_GetComponentRegistrar);
292 NS_DLSYM(NS_StringContainerInit);
293 NS_DLSYM(NS_CStringContainerInit);
294 NS_DLSYM(NS_StringContainerFinish);
295 NS_DLSYM(NS_CStringContainerFinish);
296 NS_DLSYM(NS_StringSetData);
297 NS_DLSYM(NS_CStringSetData);
298 NS_DLSYM(NS_NewLocalFile);
299 NS_DLSYM(NS_CStringGetData);
301 #undef NS_DLSYM
303 NS_StringContainerInit(&path);
304 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
305 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
306 NS_StringContainerFinish(&path);
307 if(NS_FAILED(nsres)) {
308 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
309 FreeLibrary(hXPCOM);
310 return FALSE;
313 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
314 if(NS_FAILED(nsres)) {
315 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
316 FreeLibrary(hXPCOM);
317 return FALSE;
320 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
321 if(NS_FAILED(nsres))
322 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
324 nsres = NS_GetComponentRegistrar(&registrar);
325 if(NS_SUCCEEDED(nsres)) {
326 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
327 if(NS_FAILED(nsres))
328 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
330 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
331 if(NS_FAILED(nsres))
332 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
333 }else {
334 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
337 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
338 NULL, &IID_nsIObserver, (void**)&pStartNotif);
339 if(NS_SUCCEEDED(nsres)) {
340 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
341 if(NS_FAILED(nsres))
342 ERR("Observe failed: %08lx\n", nsres);
344 nsIObserver_Release(pStartNotif);
345 }else {
346 ERR("could not get appstartup-notifier: %08lx\n", nsres);
349 set_profile();
351 if(registrar) {
352 register_nsservice(registrar);
353 init_nsio(pCompMgr, registrar);
354 nsIComponentRegistrar_Release(registrar);
357 return TRUE;
360 nsACString *nsACString_Create(void)
362 nsACString *ret;
363 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
364 NS_CStringContainerInit(ret);
365 return ret;
368 void nsACString_SetData(nsACString *str, const char *data)
370 NS_CStringSetData(str, data, PR_UINT32_MAX);
373 static PRUint32 nsACString_GetData(nsACString *str, const char **data, PRBool *termited)
375 return NS_CStringGetData(str, data, termited);
378 void nsACString_Destroy(nsACString *str)
380 NS_CStringContainerFinish(str);
381 HeapFree(GetProcessHeap(), 0, str);
384 void close_gecko()
386 TRACE("()\n");
388 if(pCompMgr)
389 nsIComponentManager_Release(pCompMgr);
391 if(pServMgr)
392 nsIServiceManager_Release(pServMgr);
394 if(hXPCOM)
395 FreeLibrary(hXPCOM);
398 /**********************************************************
399 * nsIWebBrowserChrome interface
402 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
404 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
405 nsIIDRef riid, nsQIResult result)
407 NSContainer *This = NSWBCHROME_THIS(iface);
409 *result = NULL;
410 if(IsEqualGUID(&IID_nsISupports, riid)) {
411 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
412 *result = NSWBCHROME(This);
413 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
414 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
415 *result = NSWBCHROME(This);
416 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
417 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
418 *result = NSCML(This);
419 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
420 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
421 *result = NSURICL(This);
422 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
423 TRACE("(%p)->(IIS_nsIEmbeddingSiteWindow %p)\n", This, result);
424 *result = NSEMBWNDS(This);
427 if(*result)
428 return NS_OK;
430 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
431 return NS_NOINTERFACE;
434 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
436 NSContainer *This = NSWBCHROME_THIS(iface);
437 TRACE("(%p)\n", This);
438 return 2; /* Should we implement ref conunting here? */
441 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
443 NSContainer *This = NSWBCHROME_THIS(iface);
444 TRACE("(%p)\n", This);
445 return 1;
448 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
449 PRUint32 statusType, const PRUnichar *status)
451 NSContainer *This = NSWBCHROME_THIS(iface);
452 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
453 return NS_ERROR_NOT_IMPLEMENTED;
456 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
457 nsIWebBrowser **aWebBrowser)
459 NSContainer *This = NSWBCHROME_THIS(iface);
461 TRACE("(%p)->(%p)\n", This, aWebBrowser);
463 if(!aWebBrowser)
464 return NS_ERROR_INVALID_ARG;
466 *aWebBrowser = This->webbrowser;
467 return S_OK;
470 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
471 nsIWebBrowser *aWebBrowser)
473 NSContainer *This = NSWBCHROME_THIS(iface);
475 TRACE("(%p)->(%p)\n", This, aWebBrowser);
477 if(aWebBrowser != This->webbrowser)
478 ERR("Wrong nsWebBrowser!\n");
480 return NS_OK;
483 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
484 PRUint32 *aChromeFlags)
486 NSContainer *This = NSWBCHROME_THIS(iface);
487 WARN("(%p)->(%p)\n", This, aChromeFlags);
488 return NS_ERROR_NOT_IMPLEMENTED;
491 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
492 PRUint32 aChromeFlags)
494 NSContainer *This = NSWBCHROME_THIS(iface);
495 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
496 return NS_ERROR_NOT_IMPLEMENTED;
499 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
501 NSContainer *This = NSWBCHROME_THIS(iface);
502 TRACE("(%p)\n", This);
503 return NS_ERROR_NOT_IMPLEMENTED;
506 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
507 PRInt32 aCX, PRInt32 aCY)
509 NSContainer *This = NSWBCHROME_THIS(iface);
510 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
511 return NS_ERROR_NOT_IMPLEMENTED;
514 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
516 NSContainer *This = NSWBCHROME_THIS(iface);
517 WARN("(%p)\n", This);
518 return NS_ERROR_NOT_IMPLEMENTED;
521 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
523 NSContainer *This = NSWBCHROME_THIS(iface);
524 WARN("(%p)->(%p)\n", This, _retval);
525 return NS_ERROR_NOT_IMPLEMENTED;
528 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
529 nsresult aStatus)
531 NSContainer *This = NSWBCHROME_THIS(iface);
532 WARN("(%p)->(%08lx)\n", This, aStatus);
533 return NS_ERROR_NOT_IMPLEMENTED;
536 #undef NSWBCHROME_THIS
538 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
539 nsWebBrowserChrome_QueryInterface,
540 nsWebBrowserChrome_AddRef,
541 nsWebBrowserChrome_Release,
542 nsWebBrowserChrome_SetStatus,
543 nsWebBrowserChrome_GetWebBrowser,
544 nsWebBrowserChrome_SetWebBrowser,
545 nsWebBrowserChrome_GetChromeFlags,
546 nsWebBrowserChrome_SetChromeFlags,
547 nsWebBrowserChrome_DestroyBrowserWindow,
548 nsWebBrowserChrome_SizeBrowserTo,
549 nsWebBrowserChrome_ShowAsModal,
550 nsWebBrowserChrome_IsWindowModal,
551 nsWebBrowserChrome_ExitModalEventLoop
554 /**********************************************************
555 * nsIContextMenuListener interface
558 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
560 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
561 nsIIDRef riid, nsQIResult result)
563 NSContainer *This = NSCML_THIS(iface);
564 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
567 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
569 NSContainer *This = NSCML_THIS(iface);
570 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
573 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
575 NSContainer *This = NSCML_THIS(iface);
576 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
579 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
580 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
582 NSContainer *This = NSCML_THIS(iface);
583 nsIDOMMouseEvent *event;
584 POINT pt;
585 DWORD dwID = CONTEXT_MENU_DEFAULT;
586 nsresult nsres;
588 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
590 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
591 if(NS_FAILED(nsres)) {
592 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
593 return nsres;
596 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
597 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
598 nsIDOMMouseEvent_Release(event);
600 switch(aContextFlags) {
601 case CONTEXT_NONE:
602 case CONTEXT_DOCUMENT:
603 case CONTEXT_TEXT:
604 dwID = CONTEXT_MENU_DEFAULT;
605 break;
606 case CONTEXT_IMAGE:
607 case CONTEXT_IMAGE|CONTEXT_LINK:
608 dwID = CONTEXT_MENU_IMAGE;
609 break;
610 case CONTEXT_LINK:
611 dwID = CONTEXT_MENU_ANCHOR;
612 break;
613 case CONTEXT_INPUT:
614 dwID = CONTEXT_MENU_CONTROL;
615 break;
616 default:
617 FIXME("aContextFlags=%08lx\n", aContextFlags);
620 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
622 return NS_OK;
625 #undef NSCML_THIS
627 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
628 nsContextMenuListener_QueryInterface,
629 nsContextMenuListener_AddRef,
630 nsContextMenuListener_Release,
631 nsContextMenuListener_OnShowContextMenu
634 /**********************************************************
635 * nsIURIContentListener interface
638 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
640 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
641 nsIIDRef riid, nsQIResult result)
643 NSContainer *This = NSURICL_THIS(iface);
644 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
647 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
649 NSContainer *This = NSURICL_THIS(iface);
650 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
653 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
655 NSContainer *This = NSURICL_THIS(iface);
656 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
659 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface, nsIURI *aURI,
660 PRBool *_retval)
662 NSContainer *This = NSURICL_THIS(iface);
663 BOOL do_load = TRUE;
664 nsresult nsres;
665 nsACString *spec_str = nsACString_Create();
667 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
669 nsres = nsIURI_GetSpec(aURI, spec_str);
670 if(NS_SUCCEEDED(nsres)) {
671 const char *spec = NULL;
672 LPWSTR specw;
673 int len;
675 nsACString_GetData(spec_str, &spec, NULL);
677 len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
678 specw = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
679 MultiByteToWideChar(CP_ACP, 0, spec, -1, specw, -1);
681 if(strcmpW(This->url, specw)) /* hack */
682 do_load = HTMLDocument_OnLoad(This->doc, specw);
684 HeapFree(GetProcessHeap(), 0, specw);
685 }else {
686 ERR("GetSpec failed: %08lx\n", nsres);
689 nsACString_Destroy(spec_str);
691 if(!do_load) {
692 *_retval = TRUE;
693 return NS_OK;
696 return NS_ERROR_NOT_IMPLEMENTED;
699 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
700 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
701 nsIStreamListener **aContentHandler, PRBool *_retval)
703 NSContainer *This = NSURICL_THIS(iface);
704 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
705 aRequest, aContentHandler, _retval);
706 return NS_ERROR_NOT_IMPLEMENTED;
709 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
710 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
712 NSContainer *This = NSURICL_THIS(iface);
714 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
716 /* FIXME: Should we do something here? */
717 *_retval = TRUE;
718 return NS_OK;
721 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
722 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
723 PRBool *_retval)
725 NSContainer *This = NSURICL_THIS(iface);
726 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
727 aDesiredContentType, _retval);
728 return NS_ERROR_NOT_IMPLEMENTED;
731 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
732 nsISupports **aLoadCookie)
734 NSContainer *This = NSURICL_THIS(iface);
735 WARN("(%p)->(%p)\n", This, aLoadCookie);
736 return NS_ERROR_NOT_IMPLEMENTED;
739 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
740 nsISupports *aLoadCookie)
742 NSContainer *This = NSURICL_THIS(iface);
743 WARN("(%p)->(%p)\n", This, aLoadCookie);
744 return NS_ERROR_NOT_IMPLEMENTED;
747 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
748 nsIURIContentListener **aParentContentListener)
750 NSContainer *This = NSURICL_THIS(iface);
751 WARN("(%p)->(%p)\n", This, aParentContentListener);
752 return NS_ERROR_NOT_IMPLEMENTED;
755 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
756 nsIURIContentListener *aParentContentListener)
758 NSContainer *This = NSURICL_THIS(iface);
759 WARN("(%p)->(%p)\n", This, aParentContentListener);
760 return NS_ERROR_NOT_IMPLEMENTED;
763 #undef NSURICL_THIS
765 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
766 nsURIContentListener_QueryInterface,
767 nsURIContentListener_AddRef,
768 nsURIContentListener_Release,
769 nsURIContentListener_OnStartURIOpen,
770 nsURIContentListener_DoContent,
771 nsURIContentListener_IsPreferred,
772 nsURIContentListener_CanHandleContent,
773 nsURIContentListener_GetLoadCookie,
774 nsURIContentListener_SetLoadCookie,
775 nsURIContentListener_GetParentContentListener,
776 nsURIContentListener_SetParentContentListener
779 /**********************************************************
780 * nsIEmbeddinSiteWindow interface
783 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
785 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
786 nsIIDRef riid, nsQIResult result)
788 NSContainer *This = NSEMBWNDS_THIS(iface);
789 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
792 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
794 NSContainer *This = NSEMBWNDS_THIS(iface);
795 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
798 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
800 NSContainer *This = NSEMBWNDS_THIS(iface);
801 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
804 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
805 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
807 NSContainer *This = NSEMBWNDS_THIS(iface);
808 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
809 return NS_ERROR_NOT_IMPLEMENTED;
812 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
813 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
815 NSContainer *This = NSEMBWNDS_THIS(iface);
816 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
817 return NS_ERROR_NOT_IMPLEMENTED;
820 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
822 NSContainer *This = NSEMBWNDS_THIS(iface);
823 WARN("(%p)\n", This);
824 return NS_ERROR_NOT_IMPLEMENTED;
827 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
828 PRBool *aVisibility)
830 NSContainer *This = NSEMBWNDS_THIS(iface);
831 WARN("(%p)->(%p)\n", This, aVisibility);
832 return NS_ERROR_NOT_IMPLEMENTED;
835 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
836 PRBool aVisibility)
838 NSContainer *This = NSEMBWNDS_THIS(iface);
839 WARN("(%p)->(%x)\n", This, aVisibility);
840 return NS_ERROR_NOT_IMPLEMENTED;
843 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
844 PRUnichar **aTitle)
846 NSContainer *This = NSEMBWNDS_THIS(iface);
847 WARN("(%p)->(%p)\n", This, aTitle);
848 return NS_ERROR_NOT_IMPLEMENTED;
851 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
852 const PRUnichar *aTitle)
854 NSContainer *This = NSEMBWNDS_THIS(iface);
855 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
856 return NS_ERROR_NOT_IMPLEMENTED;
859 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
860 void **aSiteWindow)
862 NSContainer *This = NSEMBWNDS_THIS(iface);
864 TRACE("(%p)->(%p)\n", This, aSiteWindow);
866 *aSiteWindow = This->hwnd;
867 return NS_OK;
870 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
871 nsEmbeddingSiteWindow_QueryInterface,
872 nsEmbeddingSiteWindow_AddRef,
873 nsEmbeddingSiteWindow_Release,
874 nsEmbeddingSiteWindow_SetDimensions,
875 nsEmbeddingSiteWindow_GetDimensions,
876 nsEmbeddingSiteWindow_SetFocus,
877 nsEmbeddingSiteWindow_GetVisibility,
878 nsEmbeddingSiteWindow_SetVisibility,
879 nsEmbeddingSiteWindow_GetTitle,
880 nsEmbeddingSiteWindow_SetTitle,
881 nsEmbeddingSiteWindow_GetSiteWindow
884 void HTMLDocument_NSContainer_Init(HTMLDocument *This)
886 nsIWebBrowserSetup *wbsetup;
887 nsresult nsres;
889 This->nscontainer = NULL;
891 if(!load_gecko())
892 return;
894 This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
896 This->nscontainer->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
897 This->nscontainer->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
898 This->nscontainer->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
899 This->nscontainer->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
901 This->nscontainer->doc = This;
903 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
904 NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
905 if(NS_FAILED(nsres))
906 ERR("Creating WebBrowser failed: %08lx\n", nsres);
908 nsres = nsIWebBrowser_SetContainerWindow(This->nscontainer->webbrowser,
909 NSWBCHROME(This->nscontainer));
910 if(NS_FAILED(nsres))
911 ERR("SetContainerWindow failed: %08lx\n", nsres);
913 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
914 (void**)&This->nscontainer->window);
915 if(NS_FAILED(nsres))
916 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
918 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
919 &IID_nsIWebBrowserSetup, (void**)&wbsetup);
920 if(NS_SUCCEEDED(nsres)) {
921 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
922 nsIWebBrowserSetup_Release(wbsetup);
923 if(NS_FAILED(nsres))
924 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
925 }else {
926 ERR("Could not get nsIWebBrowserSetup interface\n");
929 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
930 (void**)&This->nscontainer->navigation);
931 if(NS_FAILED(nsres))
932 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
934 nsres = nsIWebBrowserFocus_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserFocus,
935 (void**)&This->nscontainer->focus);
936 if(NS_FAILED(nsres))
937 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
939 #if 0
940 nsres = nsIWebBrowserStream_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserStream,
941 (void**)&This->nscontainer->stream);
942 if(NS_FAILED(nsres))
943 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
944 #else
945 This->nscontainer->stream = NULL;
946 #endif
948 if(!nscontainer_class)
949 register_nscontainer_class();
951 This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
952 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
953 GetDesktopWindow(), NULL, hInst, This);
955 nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
956 0, 0, 100, 100);
957 if(NS_SUCCEEDED(nsres)) {
958 nsres = nsIBaseWindow_Create(This->nscontainer->window);
959 if(NS_FAILED(nsres))
960 WARN("Creating window failed: %08lx\n", nsres);
962 nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
963 nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
964 }else {
965 ERR("InitWindow failed: %08lx\n", nsres);
968 nsres = nsIWebBrowser_SetParentURIContentListener(This->nscontainer->webbrowser,
969 NSURICL(This->nscontainer));
970 if(NS_FAILED(nsres))
971 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
973 This->nscontainer->url = NULL;
976 void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
978 TRACE("(%p)\n", This);
980 nsIWebBrowser_Release(This->nscontainer->webbrowser);
981 nsIWebNavigation_Release(This->nscontainer->navigation);
982 nsIBaseWindow_Release(This->nscontainer->window);
984 if(This->nscontainer->stream)
985 nsIWebBrowserStream_Release(This->nscontainer->stream);
987 HeapFree(GetProcessHeap(), 0, This->nscontainer);
989 if(This->nscontainer->url)
990 CoTaskMemFree(This->nscontainer->url);