2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
41 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
43 #define APPSTARTUP_TOPIC "app-startup"
45 #define PR_UINT32_MAX 0xffffffff
47 struct nsStringContainer {
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_CStringGetData)(nsACString*,const char**,PRBool*);
66 static HINSTANCE hXPCOM = NULL;
68 static nsIServiceManager *pServMgr = NULL;
69 static nsIComponentManager *pCompMgr = NULL;
70 static nsIIOService *pIOService = 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 = *(HTMLDocument**)lParam;
85 SetPropW(hwnd, wszTHIS, This);
87 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
92 TRACE("(%p)->(WM_SIZE)\n", This);
94 nsres = nsIBaseWindow_SetSize(This->nscontainer->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()
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_CStringGetData);
305 NS_StringContainerInit(&path);
306 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
307 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
308 NS_StringContainerFinish(&path);
309 if(NS_FAILED(nsres)) {
310 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
315 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
316 if(NS_FAILED(nsres)) {
317 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
322 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
324 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
326 nsres = NS_GetComponentRegistrar(®istrar);
327 if(NS_SUCCEEDED(nsres)) {
328 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
330 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
332 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
334 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
336 ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
339 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
340 NULL, &IID_nsIObserver, (void**)&pStartNotif);
341 if(NS_SUCCEEDED(nsres)) {
342 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
344 ERR("Observe failed: %08lx\n", nsres);
346 nsIObserver_Release(pStartNotif);
348 ERR("could not get appstartup-notifier: %08lx\n", nsres);
352 register_nsservice(registrar);
353 nsIComponentRegistrar_Release(registrar);
361 nsACString *nsACString_Create(void)
364 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
365 NS_CStringContainerInit(ret);
369 void nsACString_SetData(nsACString *str, const char *data)
371 NS_CStringSetData(str, data, PR_UINT32_MAX);
374 static PRUint32 nsACString_GetData(nsACString *str, const char **data, PRBool *termited)
376 return NS_CStringGetData(str, data, termited);
379 void nsACString_Destroy(nsACString *str)
381 NS_CStringContainerFinish(str);
382 HeapFree(GetProcessHeap(), 0, str);
390 nsIComponentManager_Release(pCompMgr);
393 nsIServiceManager_Release(pServMgr);
399 nsIURI *get_nsIURI(LPCWSTR url)
408 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_IOSERVICE_CONTRACTID,
409 &IID_nsIIOService, (void**)&pIOService);
411 ERR("Failed to create nsIOService: %08lx\n", nsres);
414 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
415 urla = HeapAlloc(GetProcessHeap(), 0, len);
416 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
418 acstr = nsACString_Create();
419 nsACString_SetData(acstr, urla);
421 nsres = nsIIOService_NewURI(pIOService, acstr, NULL, NULL, &ret);
423 FIXME("NewURI failed: %08lx\n", nsres);
425 nsACString_Destroy(acstr);
426 HeapFree(GetProcessHeap(), 0, urla);
431 /**********************************************************
432 * nsIWebBrowserChrome interface
435 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
437 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
438 nsIIDRef riid, nsQIResult result)
440 NSContainer *This = NSWBCHROME_THIS(iface);
443 if(IsEqualGUID(&IID_nsISupports, riid)) {
444 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
445 *result = NSWBCHROME(This);
446 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
447 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
448 *result = NSWBCHROME(This);
449 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
450 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
451 *result = NSCML(This);
452 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
453 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
454 *result = NSURICL(This);
455 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
456 TRACE("(%p)->(IIS_nsIEmbeddingSiteWindow %p)\n", This, result);
457 *result = NSEMBWNDS(This);
463 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
464 return NS_NOINTERFACE;
467 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
469 NSContainer *This = NSWBCHROME_THIS(iface);
470 TRACE("(%p)\n", This);
471 return 2; /* Should we implement ref conunting here? */
474 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
476 NSContainer *This = NSWBCHROME_THIS(iface);
477 TRACE("(%p)\n", This);
481 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
482 PRUint32 statusType, const PRUnichar *status)
484 NSContainer *This = NSWBCHROME_THIS(iface);
485 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
486 return NS_ERROR_NOT_IMPLEMENTED;
489 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
490 nsIWebBrowser **aWebBrowser)
492 NSContainer *This = NSWBCHROME_THIS(iface);
494 TRACE("(%p)->(%p)\n", This, aWebBrowser);
497 return NS_ERROR_INVALID_ARG;
499 *aWebBrowser = This->webbrowser;
503 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
504 nsIWebBrowser *aWebBrowser)
506 NSContainer *This = NSWBCHROME_THIS(iface);
508 TRACE("(%p)->(%p)\n", This, aWebBrowser);
510 if(aWebBrowser != This->webbrowser)
511 ERR("Wrong nsWebBrowser!\n");
516 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
517 PRUint32 *aChromeFlags)
519 NSContainer *This = NSWBCHROME_THIS(iface);
520 WARN("(%p)->(%p)\n", This, aChromeFlags);
521 return NS_ERROR_NOT_IMPLEMENTED;
524 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
525 PRUint32 aChromeFlags)
527 NSContainer *This = NSWBCHROME_THIS(iface);
528 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
529 return NS_ERROR_NOT_IMPLEMENTED;
532 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
534 NSContainer *This = NSWBCHROME_THIS(iface);
535 TRACE("(%p)\n", This);
536 return NS_ERROR_NOT_IMPLEMENTED;
539 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
540 PRInt32 aCX, PRInt32 aCY)
542 NSContainer *This = NSWBCHROME_THIS(iface);
543 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
544 return NS_ERROR_NOT_IMPLEMENTED;
547 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
549 NSContainer *This = NSWBCHROME_THIS(iface);
550 WARN("(%p)\n", This);
551 return NS_ERROR_NOT_IMPLEMENTED;
554 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
556 NSContainer *This = NSWBCHROME_THIS(iface);
557 WARN("(%p)->(%p)\n", This, _retval);
558 return NS_ERROR_NOT_IMPLEMENTED;
561 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
564 NSContainer *This = NSWBCHROME_THIS(iface);
565 WARN("(%p)->(%08lx)\n", This, aStatus);
566 return NS_ERROR_NOT_IMPLEMENTED;
569 #undef NSWBCHROME_THIS
571 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
572 nsWebBrowserChrome_QueryInterface,
573 nsWebBrowserChrome_AddRef,
574 nsWebBrowserChrome_Release,
575 nsWebBrowserChrome_SetStatus,
576 nsWebBrowserChrome_GetWebBrowser,
577 nsWebBrowserChrome_SetWebBrowser,
578 nsWebBrowserChrome_GetChromeFlags,
579 nsWebBrowserChrome_SetChromeFlags,
580 nsWebBrowserChrome_DestroyBrowserWindow,
581 nsWebBrowserChrome_SizeBrowserTo,
582 nsWebBrowserChrome_ShowAsModal,
583 nsWebBrowserChrome_IsWindowModal,
584 nsWebBrowserChrome_ExitModalEventLoop
587 /**********************************************************
588 * nsIContextMenuListener interface
591 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
593 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
594 nsIIDRef riid, nsQIResult result)
596 NSContainer *This = NSCML_THIS(iface);
597 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
600 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
602 NSContainer *This = NSCML_THIS(iface);
603 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
606 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
608 NSContainer *This = NSCML_THIS(iface);
609 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
612 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
613 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
615 NSContainer *This = NSCML_THIS(iface);
616 nsIDOMMouseEvent *event;
618 DWORD dwID = CONTEXT_MENU_DEFAULT;
621 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
623 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
624 if(NS_FAILED(nsres)) {
625 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
629 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
630 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
631 nsIDOMMouseEvent_Release(event);
633 switch(aContextFlags) {
635 case CONTEXT_DOCUMENT:
637 dwID = CONTEXT_MENU_DEFAULT;
640 case CONTEXT_IMAGE|CONTEXT_LINK:
641 dwID = CONTEXT_MENU_IMAGE;
644 dwID = CONTEXT_MENU_ANCHOR;
647 dwID = CONTEXT_MENU_CONTROL;
650 FIXME("aContextFlags=%08lx\n", aContextFlags);
653 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
660 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
661 nsContextMenuListener_QueryInterface,
662 nsContextMenuListener_AddRef,
663 nsContextMenuListener_Release,
664 nsContextMenuListener_OnShowContextMenu
667 /**********************************************************
668 * nsIURIContentListener interface
671 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
673 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
674 nsIIDRef riid, nsQIResult result)
676 NSContainer *This = NSURICL_THIS(iface);
677 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
680 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
682 NSContainer *This = NSURICL_THIS(iface);
683 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
686 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
688 NSContainer *This = NSURICL_THIS(iface);
689 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
692 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface, nsIURI *aURI,
695 NSContainer *This = NSURICL_THIS(iface);
698 nsACString *spec_str = nsACString_Create();
700 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
702 nsres = nsIURI_GetSpec(aURI, spec_str);
703 if(NS_SUCCEEDED(nsres)) {
704 const char *spec = NULL;
708 nsACString_GetData(spec_str, &spec, NULL);
710 len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
711 specw = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
712 MultiByteToWideChar(CP_ACP, 0, spec, -1, specw, -1);
714 if(strcmpW(This->url, specw)) /* hack */
715 do_load = HTMLDocument_OnLoad(This->doc, specw);
717 HeapFree(GetProcessHeap(), 0, specw);
719 ERR("GetSpec failed: %08lx\n", nsres);
722 nsACString_Destroy(spec_str);
729 return NS_ERROR_NOT_IMPLEMENTED;
732 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
733 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
734 nsIStreamListener **aContentHandler, PRBool *_retval)
736 NSContainer *This = NSURICL_THIS(iface);
737 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
738 aRequest, aContentHandler, _retval);
739 return NS_ERROR_NOT_IMPLEMENTED;
742 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
743 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
745 NSContainer *This = NSURICL_THIS(iface);
747 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
749 /* FIXME: Should we do something here? */
754 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
755 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
758 NSContainer *This = NSURICL_THIS(iface);
759 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
760 aDesiredContentType, _retval);
761 return NS_ERROR_NOT_IMPLEMENTED;
764 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
765 nsISupports **aLoadCookie)
767 NSContainer *This = NSURICL_THIS(iface);
768 WARN("(%p)->(%p)\n", This, aLoadCookie);
769 return NS_ERROR_NOT_IMPLEMENTED;
772 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
773 nsISupports *aLoadCookie)
775 NSContainer *This = NSURICL_THIS(iface);
776 WARN("(%p)->(%p)\n", This, aLoadCookie);
777 return NS_ERROR_NOT_IMPLEMENTED;
780 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
781 nsIURIContentListener **aParentContentListener)
783 NSContainer *This = NSURICL_THIS(iface);
784 WARN("(%p)->(%p)\n", This, aParentContentListener);
785 return NS_ERROR_NOT_IMPLEMENTED;
788 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
789 nsIURIContentListener *aParentContentListener)
791 NSContainer *This = NSURICL_THIS(iface);
792 WARN("(%p)->(%p)\n", This, aParentContentListener);
793 return NS_ERROR_NOT_IMPLEMENTED;
798 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
799 nsURIContentListener_QueryInterface,
800 nsURIContentListener_AddRef,
801 nsURIContentListener_Release,
802 nsURIContentListener_OnStartURIOpen,
803 nsURIContentListener_DoContent,
804 nsURIContentListener_IsPreferred,
805 nsURIContentListener_CanHandleContent,
806 nsURIContentListener_GetLoadCookie,
807 nsURIContentListener_SetLoadCookie,
808 nsURIContentListener_GetParentContentListener,
809 nsURIContentListener_SetParentContentListener
812 /**********************************************************
813 * nsIEmbeddinSiteWindow interface
816 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
818 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
819 nsIIDRef riid, nsQIResult result)
821 NSContainer *This = NSEMBWNDS_THIS(iface);
822 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
825 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
827 NSContainer *This = NSEMBWNDS_THIS(iface);
828 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
831 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
833 NSContainer *This = NSEMBWNDS_THIS(iface);
834 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
837 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
838 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
840 NSContainer *This = NSEMBWNDS_THIS(iface);
841 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
842 return NS_ERROR_NOT_IMPLEMENTED;
845 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
846 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
848 NSContainer *This = NSEMBWNDS_THIS(iface);
849 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
855 NSContainer *This = NSEMBWNDS_THIS(iface);
856 WARN("(%p)\n", This);
857 return NS_ERROR_NOT_IMPLEMENTED;
860 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
863 NSContainer *This = NSEMBWNDS_THIS(iface);
864 WARN("(%p)->(%p)\n", This, aVisibility);
865 return NS_ERROR_NOT_IMPLEMENTED;
868 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
871 NSContainer *This = NSEMBWNDS_THIS(iface);
872 WARN("(%p)->(%x)\n", This, aVisibility);
873 return NS_ERROR_NOT_IMPLEMENTED;
876 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
879 NSContainer *This = NSEMBWNDS_THIS(iface);
880 WARN("(%p)->(%p)\n", This, aTitle);
881 return NS_ERROR_NOT_IMPLEMENTED;
884 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
885 const PRUnichar *aTitle)
887 NSContainer *This = NSEMBWNDS_THIS(iface);
888 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
889 return NS_ERROR_NOT_IMPLEMENTED;
892 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
895 NSContainer *This = NSEMBWNDS_THIS(iface);
897 TRACE("(%p)->(%p)\n", This, aSiteWindow);
899 *aSiteWindow = This->hwnd;
903 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
904 nsEmbeddingSiteWindow_QueryInterface,
905 nsEmbeddingSiteWindow_AddRef,
906 nsEmbeddingSiteWindow_Release,
907 nsEmbeddingSiteWindow_SetDimensions,
908 nsEmbeddingSiteWindow_GetDimensions,
909 nsEmbeddingSiteWindow_SetFocus,
910 nsEmbeddingSiteWindow_GetVisibility,
911 nsEmbeddingSiteWindow_SetVisibility,
912 nsEmbeddingSiteWindow_GetTitle,
913 nsEmbeddingSiteWindow_SetTitle,
914 nsEmbeddingSiteWindow_GetSiteWindow
917 void HTMLDocument_NSContainer_Init(HTMLDocument *This)
919 nsIWebBrowserSetup *wbsetup;
922 This->nscontainer = NULL;
927 This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
929 This->nscontainer->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
930 This->nscontainer->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
931 This->nscontainer->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
932 This->nscontainer->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
934 This->nscontainer->doc = This;
936 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
937 NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
939 ERR("Creating WebBrowser failed: %08lx\n", nsres);
941 nsres = nsIWebBrowser_SetContainerWindow(This->nscontainer->webbrowser,
942 NSWBCHROME(This->nscontainer));
944 ERR("SetContainerWindow failed: %08lx\n", nsres);
946 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
947 (void**)&This->nscontainer->window);
949 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
951 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
952 &IID_nsIWebBrowserSetup, (void**)&wbsetup);
953 if(NS_SUCCEEDED(nsres)) {
954 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
955 nsIWebBrowserSetup_Release(wbsetup);
957 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
959 ERR("Could not get nsIWebBrowserSetup interface\n");
962 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
963 (void**)&This->nscontainer->navigation);
965 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
967 nsres = nsIWebBrowserFocus_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserFocus,
968 (void**)&This->nscontainer->focus);
970 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
973 nsres = nsIWebBrowserStream_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebBrowserStream,
974 (void**)&This->nscontainer->stream);
976 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
978 This->nscontainer->stream = NULL;
981 if(!nscontainer_class)
982 register_nscontainer_class();
984 This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
985 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
986 GetDesktopWindow(), NULL, hInst, This);
988 nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
990 if(NS_SUCCEEDED(nsres)) {
991 nsres = nsIBaseWindow_Create(This->nscontainer->window);
993 WARN("Creating window failed: %08lx\n", nsres);
995 nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
996 nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
998 ERR("InitWindow failed: %08lx\n", nsres);
1001 nsres = nsIWebBrowser_SetParentURIContentListener(This->nscontainer->webbrowser,
1002 NSURICL(This->nscontainer));
1003 if(NS_FAILED(nsres))
1004 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1006 This->nscontainer->url = NULL;
1009 void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
1011 TRACE("(%p)\n", This);
1013 nsIWebBrowser_Release(This->nscontainer->webbrowser);
1014 nsIWebNavigation_Release(This->nscontainer->navigation);
1015 nsIBaseWindow_Release(This->nscontainer->window);
1017 if(This->nscontainer->stream)
1018 nsIWebBrowserStream_Release(This->nscontainer->stream);
1020 HeapFree(GetProcessHeap(), 0, This->nscontainer);
1022 if(This->nscontainer->url)
1023 CoTaskMemFree(This->nscontainer->url);