2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
41 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define APPSTARTUP_TOPIC "app-startup"
45 #define PR_UINT32_MAX 0xffffffff
47 struct nsStringContainer {
54 struct nsCStringContainer {
61 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
62 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
63 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
64 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
65 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
66 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
67 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
68 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
69 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
70 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
71 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
73 static HINSTANCE hXPCOM = NULL;
75 static nsIServiceManager *pServMgr = NULL;
76 static nsIComponentManager *pCompMgr = NULL;
78 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
80 static ATOM nscontainer_class;
82 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
87 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
89 if(msg == WM_CREATE) {
90 This = *(NSContainer**)lParam;
91 SetPropW(hwnd, wszTHIS, This);
93 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
98 TRACE("(%p)->(WM_SIZE)\n", This);
100 nsres = nsIBaseWindow_SetSize(This->window,
101 LOWORD(lParam), HIWORD(lParam), TRUE);
103 WARN("SetSize failed: %08lx\n", nsres);
106 return DefWindowProcW(hwnd, msg, wParam, lParam);
110 static void register_nscontainer_class(void)
112 static WNDCLASSEXW wndclass = {
116 0, 0, NULL, NULL, NULL, NULL, NULL,
120 wndclass.hInstance = hInst;
121 nscontainer_class = RegisterClassExW(&wndclass);
124 static BOOL get_mozilla_path(PRUnichar *gre_path)
126 DWORD res, type, i, size = MAX_PATH;
127 HKEY mozilla_key, hkey;
131 static const WCHAR wszGreKey[] =
132 {'S','o','f','t','w','a','r','e','\\',
133 'm','o','z','i','l','l','a','.','o','r','g','\\',
136 static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0};
138 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key);
139 if(res != ERROR_SUCCESS) {
140 TRACE("Could not open key %s\n", debugstr_w(wszGreKey));
144 for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) {
145 RegOpenKeyW(mozilla_key, key_name, &hkey);
146 res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size);
147 if(res == ERROR_SUCCESS)
152 RegCloseKey(mozilla_key);
156 static BOOL get_mozctl_path(PRUnichar *gre_path)
159 DWORD res, type, size = MAX_PATH;
161 static const WCHAR wszMozCtlKey[] =
162 {'S','o','f','t','w','a','r','e','\\','M','o','z','i','l','l','a',0};
163 static const WCHAR wszBinDirectoryPath[] =
164 {'B','i','n','D','i','r','e','c','t','o','r','y','P','a','t','h',0};
165 static const WCHAR wszMozCtlClsidKey[] =
166 {'C','L','S','I','D','\\',
167 '{','1','3','3','9','B','5','4','C','-','3','4','5','3','-','1','1','D','2',
168 '-','9','3','B','9','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',
169 'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
171 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszMozCtlKey, &hkey);
172 if(res == ERROR_SUCCESS) {
173 res = RegQueryValueExW(hkey, wszBinDirectoryPath, NULL, &type, (LPBYTE)gre_path, &size);
174 if(res == ERROR_SUCCESS)
177 ERR("Could not get value %s\n", debugstr_w(wszBinDirectoryPath));
180 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszMozCtlClsidKey, &hkey);
181 if(res == ERROR_SUCCESS) {
182 res = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)gre_path, &size);
183 if(res == ERROR_SUCCESS) {
185 if((ptr = strrchrW(gre_path, '\\')))
189 ERR("Could not get value of %s\n", debugstr_w(wszMozCtlClsidKey));
193 TRACE("Could not find Mozilla ActiveX Control\n");
198 static BOOL get_wine_gecko_path(PRUnichar *gre_path)
201 DWORD res, type, size = MAX_PATH;
203 static const WCHAR wszMshtmlKey[] = {
204 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
205 '\\','M','S','H','T','M','L',0};
206 static const WCHAR wszGeckoPath[] =
207 {'G','e','c','k','o','P','a','t','h',0};
209 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
210 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
211 if(res != ERROR_SUCCESS)
214 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
215 if(res != ERROR_SUCCESS || type != REG_SZ)
221 static void set_profile(void)
224 PRBool exists = FALSE;
227 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
229 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
230 &IID_nsIProfile, (void**)&profile);
231 if(NS_FAILED(nsres)) {
232 ERR("Could not get profile service: %08lx\n", nsres);
236 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
238 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
240 ERR("CreateNewProfile failed: %08lx\n", nsres);
243 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
245 ERR("SetCurrentProfile failed: %08lx\n", nsres);
247 nsIProfile_Release(profile);
250 static BOOL load_gecko(void)
253 nsIObserver *pStartNotif;
254 nsIComponentRegistrar *registrar = NULL;
257 PRUnichar gre_path[MAX_PATH];
258 WCHAR path_env[MAX_PATH];
261 static BOOL tried_load = FALSE;
262 static const WCHAR wszPATH[] = {'P','A','T','H',0};
263 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
268 return pCompMgr != NULL;
271 if(!get_wine_gecko_path(gre_path) && !get_mozctl_path(gre_path)
272 && !get_mozilla_path(gre_path)) {
273 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
277 TRACE("found path %s\n", debugstr_w(gre_path));
279 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
280 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
281 len = strlenW(path_env);
282 path_env[len++] = ';';
283 strcpyW(path_env+len, gre_path);
284 SetEnvironmentVariableW(wszPATH, path_env);
286 hXPCOM = LoadLibraryW(strXPCOM);
288 ERR("Could not load XPCOM: %ld\n", GetLastError());
292 #define NS_DLSYM(func) \
293 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
295 ERR("Could not GetProcAddress(" #func ") failed\n")
297 NS_DLSYM(NS_InitXPCOM2);
298 NS_DLSYM(NS_ShutdownXPCOM);
299 NS_DLSYM(NS_GetComponentRegistrar);
300 NS_DLSYM(NS_StringContainerInit);
301 NS_DLSYM(NS_CStringContainerInit);
302 NS_DLSYM(NS_StringContainerFinish);
303 NS_DLSYM(NS_CStringContainerFinish);
304 NS_DLSYM(NS_StringSetData);
305 NS_DLSYM(NS_CStringSetData);
306 NS_DLSYM(NS_NewLocalFile);
307 NS_DLSYM(NS_CStringGetData);
311 NS_StringContainerInit(&path);
312 NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
313 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
314 NS_StringContainerFinish(&path);
315 if(NS_FAILED(nsres)) {
316 ERR("NS_NewLocalFile failed: %08lx\n", nsres);
321 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
322 if(NS_FAILED(nsres)) {
323 ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
328 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
330 ERR("Could not get nsIComponentManager: %08lx\n", nsres);
332 nsres = NS_GetComponentRegistrar(®istrar);
333 if(NS_SUCCEEDED(nsres)) {
334 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
336 ERR("AutoRegister(NULL) failed: %08lx\n", nsres);
338 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
340 ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);
342 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);
362 register_nsservice(registrar, pServMgr);
363 nsIComponentRegistrar_Release(registrar);
369 nsACString *nsACString_Create(void)
372 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsACString));
373 NS_CStringContainerInit(ret);
377 void nsACString_SetData(nsACString *str, const char *data)
379 NS_CStringSetData(str, data, PR_UINT32_MAX);
382 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
384 return NS_CStringGetData(str, data, termited);
387 void nsACString_Destroy(nsACString *str)
389 NS_CStringContainerFinish(str);
390 HeapFree(GetProcessHeap(), 0, str);
393 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
395 nsIStringInputStream *ret;
401 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
402 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
404 if(NS_FAILED(nsres)) {
405 ERR("Could not get nsIStringInputStream\n");
409 nsres = nsIStringInputStream_SetData(ret, data, data_len);
410 if(NS_FAILED(nsres)) {
411 ERR("AdoptData failed: %08lx\n", nsres);
412 nsIStringInputStream_Release(ret);
416 return (nsIInputStream*)ret;
424 nsIComponentManager_Release(pCompMgr);
427 nsIServiceManager_Release(pServMgr);
433 /**********************************************************
434 * nsIWebBrowserChrome interface
437 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
439 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
440 nsIIDRef riid, nsQIResult result)
442 NSContainer *This = NSWBCHROME_THIS(iface);
445 if(IsEqualGUID(&IID_nsISupports, riid)) {
446 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
447 *result = NSWBCHROME(This);
448 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
449 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
450 *result = NSWBCHROME(This);
451 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
452 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
453 *result = NSCML(This);
454 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
455 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
456 *result = NSURICL(This);
457 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
458 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
459 *result = NSEMBWNDS(This);
460 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
461 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
462 *result = NSIFACEREQ(This);
466 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
470 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
471 return NS_NOINTERFACE;
474 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
476 NSContainer *This = NSWBCHROME_THIS(iface);
477 LONG ref = InterlockedIncrement(&This->ref);
479 TRACE("(%p) ref=%ld\n", This, ref);
484 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
486 NSContainer *This = NSWBCHROME_THIS(iface);
487 LONG ref = InterlockedDecrement(&This->ref);
489 TRACE("(%p) ref=%ld\n", This, ref);
493 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
494 HeapFree(GetProcessHeap(), 0, This);
500 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
501 PRUint32 statusType, const PRUnichar *status)
503 NSContainer *This = NSWBCHROME_THIS(iface);
504 TRACE("(%p)->(%ld %s)\n", This, statusType, debugstr_w(status));
505 return NS_ERROR_NOT_IMPLEMENTED;
508 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
509 nsIWebBrowser **aWebBrowser)
511 NSContainer *This = NSWBCHROME_THIS(iface);
513 TRACE("(%p)->(%p)\n", This, aWebBrowser);
516 return NS_ERROR_INVALID_ARG;
519 nsIWebBrowser_AddRef(This->webbrowser);
520 *aWebBrowser = This->webbrowser;
524 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
525 nsIWebBrowser *aWebBrowser)
527 NSContainer *This = NSWBCHROME_THIS(iface);
529 TRACE("(%p)->(%p)\n", This, aWebBrowser);
531 if(aWebBrowser != This->webbrowser)
532 ERR("Wrong nsWebBrowser!\n");
537 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
538 PRUint32 *aChromeFlags)
540 NSContainer *This = NSWBCHROME_THIS(iface);
541 WARN("(%p)->(%p)\n", This, aChromeFlags);
542 return NS_ERROR_NOT_IMPLEMENTED;
545 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
546 PRUint32 aChromeFlags)
548 NSContainer *This = NSWBCHROME_THIS(iface);
549 WARN("(%p)->(%08lx)\n", This, aChromeFlags);
550 return NS_ERROR_NOT_IMPLEMENTED;
553 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
555 NSContainer *This = NSWBCHROME_THIS(iface);
556 TRACE("(%p)\n", This);
557 return NS_ERROR_NOT_IMPLEMENTED;
560 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
561 PRInt32 aCX, PRInt32 aCY)
563 NSContainer *This = NSWBCHROME_THIS(iface);
564 WARN("(%p)->(%ld %ld)\n", This, aCX, aCY);
565 return NS_ERROR_NOT_IMPLEMENTED;
568 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
570 NSContainer *This = NSWBCHROME_THIS(iface);
571 WARN("(%p)\n", This);
572 return NS_ERROR_NOT_IMPLEMENTED;
575 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
577 NSContainer *This = NSWBCHROME_THIS(iface);
578 WARN("(%p)->(%p)\n", This, _retval);
579 return NS_ERROR_NOT_IMPLEMENTED;
582 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
585 NSContainer *This = NSWBCHROME_THIS(iface);
586 WARN("(%p)->(%08lx)\n", This, aStatus);
587 return NS_ERROR_NOT_IMPLEMENTED;
590 #undef NSWBCHROME_THIS
592 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
593 nsWebBrowserChrome_QueryInterface,
594 nsWebBrowserChrome_AddRef,
595 nsWebBrowserChrome_Release,
596 nsWebBrowserChrome_SetStatus,
597 nsWebBrowserChrome_GetWebBrowser,
598 nsWebBrowserChrome_SetWebBrowser,
599 nsWebBrowserChrome_GetChromeFlags,
600 nsWebBrowserChrome_SetChromeFlags,
601 nsWebBrowserChrome_DestroyBrowserWindow,
602 nsWebBrowserChrome_SizeBrowserTo,
603 nsWebBrowserChrome_ShowAsModal,
604 nsWebBrowserChrome_IsWindowModal,
605 nsWebBrowserChrome_ExitModalEventLoop
608 /**********************************************************
609 * nsIContextMenuListener interface
612 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
614 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
615 nsIIDRef riid, nsQIResult result)
617 NSContainer *This = NSCML_THIS(iface);
618 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
621 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
623 NSContainer *This = NSCML_THIS(iface);
624 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
627 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
629 NSContainer *This = NSCML_THIS(iface);
630 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
633 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
634 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
636 NSContainer *This = NSCML_THIS(iface);
637 nsIDOMMouseEvent *event;
639 DWORD dwID = CONTEXT_MENU_DEFAULT;
642 TRACE("(%p)->(%08lx %p %p)\n", This, aContextFlags, aEvent, aNode);
644 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
645 if(NS_FAILED(nsres)) {
646 ERR("Could not get nsIDOMMouseEvent interface: %08lx\n", nsres);
650 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
651 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
652 nsIDOMMouseEvent_Release(event);
654 switch(aContextFlags) {
656 case CONTEXT_DOCUMENT:
658 dwID = CONTEXT_MENU_DEFAULT;
661 case CONTEXT_IMAGE|CONTEXT_LINK:
662 dwID = CONTEXT_MENU_IMAGE;
665 dwID = CONTEXT_MENU_ANCHOR;
668 dwID = CONTEXT_MENU_CONTROL;
671 FIXME("aContextFlags=%08lx\n", aContextFlags);
674 HTMLDocument_ShowContextMenu(This->doc, dwID, &pt);
681 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
682 nsContextMenuListener_QueryInterface,
683 nsContextMenuListener_AddRef,
684 nsContextMenuListener_Release,
685 nsContextMenuListener_OnShowContextMenu
688 /**********************************************************
689 * nsIURIContentListener interface
692 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
694 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
695 nsIIDRef riid, nsQIResult result)
697 NSContainer *This = NSURICL_THIS(iface);
698 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
701 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
703 NSContainer *This = NSURICL_THIS(iface);
704 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
707 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
709 NSContainer *This = NSURICL_THIS(iface);
710 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
713 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
714 nsIURI *aURI, PRBool *_retval)
716 NSContainer *This = NSURICL_THIS(iface);
717 nsIWineURI *wine_uri;
718 nsACString *spec_str = nsACString_Create();
722 nsIURI_GetSpec(aURI, spec_str);
723 nsACString_GetData(spec_str, &spec, NULL);
725 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
727 nsACString_Destroy(spec_str);
729 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
730 if(NS_SUCCEEDED(nsres)) {
731 nsIWineURI_SetNSContainer(wine_uri, This);
732 nsIWineURI_Release(wine_uri);
734 WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
737 return NS_ERROR_NOT_IMPLEMENTED;
740 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
741 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
742 nsIStreamListener **aContentHandler, PRBool *_retval)
744 NSContainer *This = NSURICL_THIS(iface);
745 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
746 aRequest, aContentHandler, _retval);
747 return NS_ERROR_NOT_IMPLEMENTED;
750 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
751 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
753 NSContainer *This = NSURICL_THIS(iface);
755 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
757 /* FIXME: Should we do something here? */
762 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
763 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
766 NSContainer *This = NSURICL_THIS(iface);
767 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
768 aDesiredContentType, _retval);
769 return NS_ERROR_NOT_IMPLEMENTED;
772 static nsresult NSAPI nsURIContentListener_GetLoadCookie(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_SetLoadCookie(nsIURIContentListener *iface,
781 nsISupports *aLoadCookie)
783 NSContainer *This = NSURICL_THIS(iface);
784 WARN("(%p)->(%p)\n", This, aLoadCookie);
785 return NS_ERROR_NOT_IMPLEMENTED;
788 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
789 nsIURIContentListener **aParentContentListener)
791 NSContainer *This = NSURICL_THIS(iface);
792 WARN("(%p)->(%p)\n", This, aParentContentListener);
793 return NS_ERROR_NOT_IMPLEMENTED;
796 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
797 nsIURIContentListener *aParentContentListener)
799 NSContainer *This = NSURICL_THIS(iface);
800 WARN("(%p)->(%p)\n", This, aParentContentListener);
801 return NS_ERROR_NOT_IMPLEMENTED;
806 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
807 nsURIContentListener_QueryInterface,
808 nsURIContentListener_AddRef,
809 nsURIContentListener_Release,
810 nsURIContentListener_OnStartURIOpen,
811 nsURIContentListener_DoContent,
812 nsURIContentListener_IsPreferred,
813 nsURIContentListener_CanHandleContent,
814 nsURIContentListener_GetLoadCookie,
815 nsURIContentListener_SetLoadCookie,
816 nsURIContentListener_GetParentContentListener,
817 nsURIContentListener_SetParentContentListener
820 /**********************************************************
821 * nsIEmbeddinSiteWindow interface
824 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
826 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
827 nsIIDRef riid, nsQIResult result)
829 NSContainer *This = NSEMBWNDS_THIS(iface);
830 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
833 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
835 NSContainer *This = NSEMBWNDS_THIS(iface);
836 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
839 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
841 NSContainer *This = NSEMBWNDS_THIS(iface);
842 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
845 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
846 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
848 NSContainer *This = NSEMBWNDS_THIS(iface);
849 WARN("(%p)->(%08lx %ld %ld %ld %ld)\n", This, flags, x, y, cx, cy);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
854 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
856 NSContainer *This = NSEMBWNDS_THIS(iface);
857 WARN("(%p)->(%08lx %p %p %p %p)\n", This, flags, x, y, cx, cy);
858 return NS_ERROR_NOT_IMPLEMENTED;
861 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
863 NSContainer *This = NSEMBWNDS_THIS(iface);
864 WARN("(%p)\n", This);
865 return NS_ERROR_NOT_IMPLEMENTED;
868 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
871 NSContainer *This = NSEMBWNDS_THIS(iface);
872 WARN("(%p)->(%p)\n", This, aVisibility);
873 return NS_ERROR_NOT_IMPLEMENTED;
876 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
879 NSContainer *This = NSEMBWNDS_THIS(iface);
880 WARN("(%p)->(%x)\n", This, aVisibility);
881 return NS_ERROR_NOT_IMPLEMENTED;
884 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
887 NSContainer *This = NSEMBWNDS_THIS(iface);
888 WARN("(%p)->(%p)\n", This, aTitle);
889 return NS_ERROR_NOT_IMPLEMENTED;
892 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
893 const PRUnichar *aTitle)
895 NSContainer *This = NSEMBWNDS_THIS(iface);
896 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
897 return NS_ERROR_NOT_IMPLEMENTED;
900 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
903 NSContainer *This = NSEMBWNDS_THIS(iface);
905 TRACE("(%p)->(%p)\n", This, aSiteWindow);
907 *aSiteWindow = This->hwnd;
911 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
912 nsEmbeddingSiteWindow_QueryInterface,
913 nsEmbeddingSiteWindow_AddRef,
914 nsEmbeddingSiteWindow_Release,
915 nsEmbeddingSiteWindow_SetDimensions,
916 nsEmbeddingSiteWindow_GetDimensions,
917 nsEmbeddingSiteWindow_SetFocus,
918 nsEmbeddingSiteWindow_GetVisibility,
919 nsEmbeddingSiteWindow_SetVisibility,
920 nsEmbeddingSiteWindow_GetTitle,
921 nsEmbeddingSiteWindow_SetTitle,
922 nsEmbeddingSiteWindow_GetSiteWindow
925 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
927 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
928 nsIIDRef riid, nsQIResult result)
930 NSContainer *This = NSIFACEREQ_THIS(iface);
931 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
934 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
936 NSContainer *This = NSIFACEREQ_THIS(iface);
937 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
940 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
942 NSContainer *This = NSIFACEREQ_THIS(iface);
943 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
946 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
947 nsIIDRef riid, nsQIResult result)
949 NSContainer *This = NSIFACEREQ_THIS(iface);
951 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
952 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
953 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
956 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
959 #undef NSIFACEREQ_THIS
961 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
962 nsInterfaceRequestor_QueryInterface,
963 nsInterfaceRequestor_AddRef,
964 nsInterfaceRequestor_Release,
965 nsInterfaceRequestor_GetInterface
968 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
970 nsIWebBrowserSetup *wbsetup;
977 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
979 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
980 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
981 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
982 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
983 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
987 ret->load_call = FALSE;
990 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
991 ret->parent = parent;
993 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
994 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
996 ERR("Creating WebBrowser failed: %08lx\n", nsres);
998 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1000 ERR("SetContainerWindow failed: %08lx\n", nsres);
1002 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1003 (void**)&ret->window);
1004 if(NS_FAILED(nsres))
1005 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1007 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1009 if(NS_SUCCEEDED(nsres)) {
1010 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1011 nsIWebBrowserSetup_Release(wbsetup);
1012 if(NS_FAILED(nsres))
1013 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08lx\n", nsres);
1015 ERR("Could not get nsIWebBrowserSetup interface\n");
1018 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1019 (void**)&ret->navigation);
1020 if(NS_FAILED(nsres))
1021 ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
1023 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1024 (void**)&ret->focus);
1025 if(NS_FAILED(nsres))
1026 ERR("Could not get nsIWebBrowserFocus interface: %08lx\n", nsres);
1029 nsres = nsIWebBrowserStream_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserStream,
1030 (void**)&ret->stream);
1031 if(NS_FAILED(nsres))
1032 ERR("Could not get nsIWebBrowserStream interface: %08lx\n", nsres);
1037 if(!nscontainer_class)
1038 register_nscontainer_class();
1040 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1041 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1042 GetDesktopWindow(), NULL, hInst, ret);
1044 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1045 if(NS_SUCCEEDED(nsres)) {
1046 nsres = nsIBaseWindow_Create(ret->window);
1047 if(NS_FAILED(nsres))
1048 WARN("Creating window failed: %08lx\n", nsres);
1050 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1051 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1053 ERR("InitWindow failed: %08lx\n", nsres);
1056 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1057 if(NS_FAILED(nsres))
1058 ERR("SetParentURIContentListener failed: %08lx\n", nsres);
1063 void NSContainer_Release(NSContainer *This)
1065 nsIBaseWindow *base_window;
1068 TRACE("(%p)\n", This);
1070 ShowWindow(This->hwnd, SW_HIDE);
1071 SetParent(This->hwnd, NULL);
1073 nsres = nsIWebBrowser_QueryInterface(This->webbrowser, &IID_nsIBaseWindow,
1074 (void**)&base_window);
1075 if(NS_SUCCEEDED(nsres)) {
1076 nsIBaseWindow_SetVisibility(base_window, FALSE);
1077 nsIBaseWindow_Destroy(base_window);
1078 nsIBaseWindow_Release(base_window);
1080 ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
1083 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1085 nsIWebBrowser_Release(This->webbrowser);
1086 This->webbrowser = NULL;
1088 nsIWebNavigation_Release(This->navigation);
1089 This->navigation = NULL;
1091 nsIBaseWindow_Release(This->window);
1092 This->window = NULL;
1095 nsIWebBrowserStream_Release(This->stream);
1096 This->stream = NULL;
1100 DestroyWindow(This->hwnd);
1104 nsIWebBrowserChrome_Release(NSWBCHROME(This));