configure: Make the libjpeg soname check depend on the header check.
[wine/dibdrv.git] / dlls / mshtml / nsembed.c
blob6b4e918eb94eacaca5d12d70b17a14b7fdfeee0a
1 /*
2 * Copyright 2005-2007 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
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"
41 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
44 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
45 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
47 #define APPSTARTUP_TOPIC "app-startup"
49 #define PR_UINT32_MAX 0xffffffff
51 struct nsCStringContainer {
52 void *v;
53 void *d1;
54 PRUint32 d2;
55 void *d3;
58 static nsresult (*NS_InitXPCOM2)(nsIServiceManager**,void*,void*);
59 static nsresult (*NS_ShutdownXPCOM)(nsIServiceManager*);
60 static nsresult (*NS_GetComponentRegistrar)(nsIComponentRegistrar**);
61 static nsresult (*NS_StringContainerInit)(nsStringContainer*);
62 static nsresult (*NS_CStringContainerInit)(nsCStringContainer*);
63 static nsresult (*NS_StringContainerFinish)(nsStringContainer*);
64 static nsresult (*NS_CStringContainerFinish)(nsCStringContainer*);
65 static nsresult (*NS_StringSetData)(nsAString*,const PRUnichar*,PRUint32);
66 static nsresult (*NS_CStringSetData)(nsACString*,const char*,PRUint32);
67 static nsresult (*NS_NewLocalFile)(const nsAString*,PRBool,nsIFile**);
68 static PRUint32 (*NS_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
69 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
71 static HINSTANCE hXPCOM = NULL;
73 static nsIServiceManager *pServMgr = NULL;
74 static nsIComponentManager *pCompMgr = NULL;
75 static nsIMemory *nsmem = NULL;
77 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
79 static ATOM nscontainer_class;
81 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
83 NSContainer *This;
84 nsresult nsres;
86 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
88 if(msg == WM_CREATE) {
89 This = *(NSContainer**)lParam;
90 SetPropW(hwnd, wszTHIS, This);
91 }else {
92 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
95 switch(msg) {
96 case WM_SIZE:
97 TRACE("(%p)->(WM_SIZE)\n", This);
99 nsres = nsIBaseWindow_SetSize(This->window,
100 LOWORD(lParam), HIWORD(lParam), TRUE);
101 if(NS_FAILED(nsres))
102 WARN("SetSize failed: %08x\n", nsres);
105 return DefWindowProcW(hwnd, msg, wParam, lParam);
109 static void register_nscontainer_class(void)
111 static WNDCLASSEXW wndclass = {
112 sizeof(WNDCLASSEXW),
113 CS_DBLCLKS,
114 nsembed_proc,
115 0, 0, NULL, NULL, NULL, NULL, NULL,
116 wszNsContainer,
117 NULL,
119 wndclass.hInstance = hInst;
120 nscontainer_class = RegisterClassExW(&wndclass);
123 static BOOL load_xpcom(const PRUnichar *gre_path)
125 WCHAR path_env[MAX_PATH];
126 int len;
128 static const WCHAR wszPATH[] = {'P','A','T','H',0};
129 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
131 TRACE("(%s)\n", debugstr_w(gre_path));
133 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
134 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
135 len = strlenW(path_env);
136 path_env[len++] = ';';
137 strcpyW(path_env+len, gre_path);
138 SetEnvironmentVariableW(wszPATH, path_env);
140 hXPCOM = LoadLibraryW(strXPCOM);
141 if(!hXPCOM) {
142 WARN("Could not load XPCOM: %d\n", GetLastError());
143 return FALSE;
146 #define NS_DLSYM(func) \
147 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
148 if(!func) \
149 ERR("Could not GetProcAddress(" #func ") failed\n")
151 NS_DLSYM(NS_InitXPCOM2);
152 NS_DLSYM(NS_ShutdownXPCOM);
153 NS_DLSYM(NS_GetComponentRegistrar);
154 NS_DLSYM(NS_StringContainerInit);
155 NS_DLSYM(NS_CStringContainerInit);
156 NS_DLSYM(NS_StringContainerFinish);
157 NS_DLSYM(NS_CStringContainerFinish);
158 NS_DLSYM(NS_StringSetData);
159 NS_DLSYM(NS_CStringSetData);
160 NS_DLSYM(NS_NewLocalFile);
161 NS_DLSYM(NS_StringGetData);
162 NS_DLSYM(NS_CStringGetData);
164 #undef NS_DLSYM
166 return TRUE;
169 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
171 WCHAR file_name[MAX_PATH];
172 char version[128];
173 DWORD read=0;
174 HANDLE hfile;
176 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
178 strcpyW(file_name, gre_path);
179 strcatW(file_name, wszVersion);
181 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
182 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
183 if(hfile == INVALID_HANDLE_VALUE) {
184 ERR("Could not open VERSION file\n");
185 return FALSE;
188 ReadFile(hfile, version, sizeof(version), &read, NULL);
189 version[read] = 0;
190 CloseHandle(hfile);
192 TRACE("%s\n", debugstr_a(version));
194 if(strcmp(version, version_string)) {
195 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
196 debugstr_a(version_string));
197 return FALSE;
200 return TRUE;
203 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
204 const char *version, const char *version_string)
206 DWORD res, type, size = MAX_PATH;
207 HKEY hkey = mshtml_key;
209 static const WCHAR wszGeckoPath[] =
210 {'G','e','c','k','o','P','a','t','h',0};
212 if(version) {
213 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
214 res = RegOpenKeyA(mshtml_key, version, &hkey);
215 if(res != ERROR_SUCCESS)
216 return FALSE;
219 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
220 if(hkey != mshtml_key)
221 RegCloseKey(hkey);
222 if(res != ERROR_SUCCESS || type != REG_SZ)
223 return FALSE;
225 if(!check_version(gre_path, version_string))
226 return FALSE;
228 return load_xpcom(gre_path);
231 static BOOL load_wine_gecko(PRUnichar *gre_path)
233 HKEY hkey;
234 DWORD res;
235 BOOL ret;
237 static const WCHAR wszMshtmlKey[] = {
238 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
239 '\\','M','S','H','T','M','L',0};
241 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
242 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
243 if(res != ERROR_SUCCESS)
244 return FALSE;
246 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING)
247 || load_wine_gecko_v(gre_path, hkey, "0.0.1", "Wine Gecko 0.0.1\n")
248 || load_wine_gecko_v(gre_path, hkey, NULL, "Wine Gecko 0.0.1\n");
250 RegCloseKey(hkey);
251 return ret;
254 static void set_profile(void)
256 nsIProfile *profile;
257 PRBool exists = FALSE;
258 nsresult nsres;
260 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
262 nsres = nsIServiceManager_GetServiceByContactID(pServMgr, NS_PROFILE_CONTRACTID,
263 &IID_nsIProfile, (void**)&profile);
264 if(NS_FAILED(nsres)) {
265 ERR("Could not get profile service: %08x\n", nsres);
266 return;
269 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
270 if(!exists) {
271 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
272 if(NS_FAILED(nsres))
273 ERR("CreateNewProfile failed: %08x\n", nsres);
276 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
277 if(NS_FAILED(nsres))
278 ERR("SetCurrentProfile failed: %08x\n", nsres);
280 nsIProfile_Release(profile);
283 static BOOL init_xpcom(const PRUnichar *gre_path)
285 nsresult nsres;
286 nsIObserver *pStartNotif;
287 nsIComponentRegistrar *registrar = NULL;
288 nsAString path;
289 nsIFile *gre_dir;
291 nsAString_Init(&path, gre_path);
292 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
293 nsAString_Finish(&path);
294 if(NS_FAILED(nsres)) {
295 ERR("NS_NewLocalFile failed: %08x\n", nsres);
296 FreeLibrary(hXPCOM);
297 return FALSE;
300 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
301 if(NS_FAILED(nsres)) {
302 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
303 FreeLibrary(hXPCOM);
304 return FALSE;
307 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
308 if(NS_FAILED(nsres))
309 ERR("Could not get nsIComponentManager: %08x\n", nsres);
311 nsres = NS_GetComponentRegistrar(&registrar);
312 if(NS_SUCCEEDED(nsres)) {
313 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
314 if(NS_FAILED(nsres))
315 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
317 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
318 if(NS_FAILED(nsres))
319 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
321 init_nsio(pCompMgr, registrar);
322 }else {
323 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
326 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
327 NULL, &IID_nsIObserver, (void**)&pStartNotif);
328 if(NS_SUCCEEDED(nsres)) {
329 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
330 if(NS_FAILED(nsres))
331 ERR("Observe failed: %08x\n", nsres);
333 nsIObserver_Release(pStartNotif);
334 }else {
335 ERR("could not get appstartup-notifier: %08x\n", nsres);
338 set_profile();
340 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
341 NULL, &IID_nsIMemory, (void**)&nsmem);
342 if(NS_FAILED(nsres))
343 ERR("Could not get nsIMemory: %08x\n", nsres);
345 if(registrar) {
346 register_nsservice(registrar, pServMgr);
347 nsIComponentRegistrar_Release(registrar);
350 return TRUE;
353 static CRITICAL_SECTION cs_load_gecko;
354 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
356 0, 0, &cs_load_gecko,
357 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
358 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
360 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
362 static BOOL load_gecko(void)
364 PRUnichar gre_path[MAX_PATH];
365 BOOL ret = FALSE;
367 static LONG loading_thread;
369 TRACE("()\n");
371 /* load_gecko may be called recursively */
372 if(loading_thread == GetCurrentThreadId())
373 return pCompMgr != NULL;
375 EnterCriticalSection(&cs_load_gecko);
377 if(!loading_thread) {
378 loading_thread = GetCurrentThreadId();
380 if(load_wine_gecko(gre_path)
381 || (install_wine_gecko() && load_wine_gecko(gre_path)))
382 ret = init_xpcom(gre_path);
383 else
384 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
385 }else {
386 ret = pCompMgr != NULL;
389 LeaveCriticalSection(&cs_load_gecko);
391 return ret;
394 void *nsalloc(size_t size)
396 return nsIMemory_Alloc(nsmem, size);
399 void nsfree(void *mem)
401 nsIMemory_Free(nsmem, mem);
404 void nsACString_Init(nsACString *str, const char *data)
406 NS_CStringContainerInit(str);
407 if(data)
408 nsACString_SetData(str, data);
411 void nsACString_SetData(nsACString *str, const char *data)
413 NS_CStringSetData(str, data, PR_UINT32_MAX);
416 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
418 return NS_CStringGetData(str, data, termited);
421 void nsACString_Finish(nsACString *str)
423 NS_CStringContainerFinish(str);
426 void nsAString_Init(nsAString *str, const PRUnichar *data)
428 NS_StringContainerInit(str);
429 if(data)
430 NS_StringSetData(str, data, PR_UINT32_MAX);
433 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
435 return NS_StringGetData(str, data, termited);
438 void nsAString_Finish(nsAString *str)
440 NS_StringContainerFinish(str);
443 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
445 nsIStringInputStream *ret;
446 nsresult nsres;
448 if(!pCompMgr)
449 return NULL;
451 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
452 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
453 (void**)&ret);
454 if(NS_FAILED(nsres)) {
455 ERR("Could not get nsIStringInputStream\n");
456 return NULL;
459 nsres = nsIStringInputStream_SetData(ret, data, data_len);
460 if(NS_FAILED(nsres)) {
461 ERR("AdoptData failed: %08x\n", nsres);
462 nsIStringInputStream_Release(ret);
463 return NULL;
466 return (nsIInputStream*)ret;
469 nsICommandParams *create_nscommand_params(void)
471 nsICommandParams *ret = NULL;
472 nsresult nsres;
474 if(!pCompMgr)
475 return NULL;
477 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
478 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
479 (void**)&ret);
480 if(NS_FAILED(nsres))
481 ERR("Could not get nsICommandParams\n");
483 return ret;
486 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
488 nsIDOMNodeList *node_list = NULL;
489 PRBool has_children = FALSE;
490 PRUint16 type;
491 nsresult nsres;
493 nsIDOMNode_HasChildNodes(nsnode, &has_children);
495 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
496 if(NS_FAILED(nsres)) {
497 ERR("GetType failed: %08x\n", nsres);
498 return;
501 switch(type) {
502 case ELEMENT_NODE: {
503 nsIDOMElement *nselem;
504 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
505 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
506 nsIDOMElement_Release(nselem);
507 break;
509 case TEXT_NODE: {
510 nsIDOMText *nstext;
511 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
512 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
513 nsIDOMText_Release(nstext);
514 break;
516 case COMMENT_NODE: {
517 nsIDOMComment *nscomment;
518 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMComment, (void**)&nscomment);
519 nsres = nsIContentSerializer_AppendComment(serializer, nscomment, 0, -1, str);
520 break;
522 case DOCUMENT_NODE: {
523 nsIDOMDocument *nsdoc;
524 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
525 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
526 nsIDOMDocument_Release(nsdoc);
527 break;
529 case DOCUMENT_FRAGMENT_NODE:
530 break;
531 default:
532 FIXME("Unhandled type %u\n", type);
535 if(has_children) {
536 PRUint32 child_cnt, i;
537 nsIDOMNode *child_node;
539 nsIDOMNode_GetChildNodes(nsnode, &node_list);
540 nsIDOMNodeList_GetLength(node_list, &child_cnt);
542 for(i=0; i<child_cnt; i++) {
543 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
544 if(NS_SUCCEEDED(nsres)) {
545 nsnode_to_nsstring_rec(serializer, child_node, str);
546 nsIDOMNode_Release(child_node);
547 }else {
548 ERR("Item failed: %08x\n", nsres);
552 nsIDOMNodeList_Release(node_list);
555 if(type == ELEMENT_NODE) {
556 nsIDOMElement *nselem;
557 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
558 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
559 nsIDOMElement_Release(nselem);
563 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
565 nsIContentSerializer *serializer;
566 nsIDOMNode *nsnode;
567 nsresult nsres;
569 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
570 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
571 (void**)&serializer);
572 if(NS_FAILED(nsres)) {
573 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
574 return;
577 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
578 if(NS_FAILED(nsres))
579 ERR("Init failed: %08x\n", nsres);
581 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
582 nsnode_to_nsstring_rec(serializer, nsnode, str);
583 nsIDOMNode_Release(nsnode);
585 nsres = nsIContentSerializer_Flush(serializer, str);
586 if(NS_FAILED(nsres))
587 ERR("Flush failed: %08x\n", nsres);
589 nsIContentSerializer_Release(serializer);
592 nsIController *get_editor_controller(NSContainer *This)
594 nsIController *ret = NULL;
595 nsIEditingSession *editing_session = NULL;
596 nsIInterfaceRequestor *iface_req;
597 nsIControllerContext *ctrlctx;
598 nsIEditor *editor = NULL;
599 nsresult nsres;
601 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
602 &IID_nsIInterfaceRequestor, (void**)&iface_req);
603 if(NS_FAILED(nsres)) {
604 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
605 return NULL;
608 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIEditingSession,
609 (void**)&editing_session);
610 nsIInterfaceRequestor_Release(iface_req);
611 if(NS_FAILED(nsres)) {
612 ERR("Could not get nsIEditingSession: %08x\n", nsres);
613 return NULL;
616 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
617 This->doc->window->nswindow, &editor);
618 nsIEditingSession_Release(editing_session);
619 if(NS_FAILED(nsres)) {
620 ERR("Could not get editor: %08x\n", nsres);
621 return NULL;
624 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
625 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
626 if(NS_SUCCEEDED(nsres)) {
627 nsres = nsIControllerContext_SetCommandContext(ctrlctx, editor);
628 if(NS_FAILED(nsres))
629 ERR("SetCommandContext failed: %08x\n", nsres);
630 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
631 (void**)&ret);
632 nsIControllerContext_Release(ctrlctx);
633 if(NS_FAILED(nsres))
634 ERR("Could not get nsIController interface: %08x\n", nsres);
635 }else {
636 ERR("Could not create edit controller: %08x\n", nsres);
639 nsISupports_Release(editor);
641 return ret;
644 void set_ns_editmode(NSContainer *This)
646 nsIInterfaceRequestor *iface_req;
647 nsIEditingSession *editing_session = NULL;
648 nsIURIContentListener *listener = NULL;
649 nsIDOMWindow *dom_window = NULL;
650 nsresult nsres;
652 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
653 &IID_nsIInterfaceRequestor, (void**)&iface_req);
654 if(NS_FAILED(nsres)) {
655 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
656 return;
659 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIEditingSession,
660 (void**)&editing_session);
661 nsIInterfaceRequestor_Release(iface_req);
662 if(NS_FAILED(nsres)) {
663 ERR("Could not get nsIEditingSession: %08x\n", nsres);
664 return;
667 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
668 if(NS_FAILED(nsres)) {
669 ERR("Could not get content DOM window: %08x\n", nsres);
670 nsIEditingSession_Release(editing_session);
671 return;
674 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
675 nsIEditingSession_Release(editing_session);
676 nsIDOMWindow_Release(dom_window);
677 if(NS_FAILED(nsres)) {
678 ERR("MakeWindowEditable failed: %08x\n", nsres);
679 return;
682 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
683 * It seams to be a bug in Gecko. To workaround it we set our content
684 * listener again and Gecko's one as its parent.
686 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
687 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
688 nsIURIContentListener_Release(listener);
689 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
692 void close_gecko(void)
694 TRACE("()\n");
696 if(pCompMgr)
697 nsIComponentManager_Release(pCompMgr);
699 if(pServMgr)
700 nsIServiceManager_Release(pServMgr);
702 if(nsmem)
703 nsIMemory_Release(nsmem);
705 if(hXPCOM)
706 FreeLibrary(hXPCOM);
709 /**********************************************************
710 * nsIWebBrowserChrome interface
713 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
715 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
716 nsIIDRef riid, nsQIResult result)
718 NSContainer *This = NSWBCHROME_THIS(iface);
720 *result = NULL;
721 if(IsEqualGUID(&IID_nsISupports, riid)) {
722 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
723 *result = NSWBCHROME(This);
724 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
725 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
726 *result = NSWBCHROME(This);
727 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
728 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
729 *result = NSCML(This);
730 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
731 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
732 *result = NSURICL(This);
733 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
734 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
735 *result = NSEMBWNDS(This);
736 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
737 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
738 *result = NSTOOLTIP(This);
739 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
740 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
741 *result = NSIFACEREQ(This);
742 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
743 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
744 *result = NSWEAKREF(This);
745 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
746 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
747 *result = NSSUPWEAKREF(This);
750 if(*result) {
751 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
752 return NS_OK;
755 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
756 return NS_NOINTERFACE;
759 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
761 NSContainer *This = NSWBCHROME_THIS(iface);
762 LONG ref = InterlockedIncrement(&This->ref);
764 TRACE("(%p) ref=%d\n", This, ref);
766 return ref;
769 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
771 NSContainer *This = NSWBCHROME_THIS(iface);
772 LONG ref = InterlockedDecrement(&This->ref);
774 TRACE("(%p) ref=%d\n", This, ref);
776 if(!ref) {
777 if(This->parent)
778 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
779 mshtml_free(This);
782 return ref;
785 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
786 PRUint32 statusType, const PRUnichar *status)
788 NSContainer *This = NSWBCHROME_THIS(iface);
789 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
790 return NS_ERROR_NOT_IMPLEMENTED;
793 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
794 nsIWebBrowser **aWebBrowser)
796 NSContainer *This = NSWBCHROME_THIS(iface);
798 TRACE("(%p)->(%p)\n", This, aWebBrowser);
800 if(!aWebBrowser)
801 return NS_ERROR_INVALID_ARG;
803 if(This->webbrowser)
804 nsIWebBrowser_AddRef(This->webbrowser);
805 *aWebBrowser = This->webbrowser;
806 return S_OK;
809 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
810 nsIWebBrowser *aWebBrowser)
812 NSContainer *This = NSWBCHROME_THIS(iface);
814 TRACE("(%p)->(%p)\n", This, aWebBrowser);
816 if(aWebBrowser != This->webbrowser)
817 ERR("Wrong nsWebBrowser!\n");
819 return NS_OK;
822 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
823 PRUint32 *aChromeFlags)
825 NSContainer *This = NSWBCHROME_THIS(iface);
826 WARN("(%p)->(%p)\n", This, aChromeFlags);
827 return NS_ERROR_NOT_IMPLEMENTED;
830 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
831 PRUint32 aChromeFlags)
833 NSContainer *This = NSWBCHROME_THIS(iface);
834 WARN("(%p)->(%08x)\n", This, aChromeFlags);
835 return NS_ERROR_NOT_IMPLEMENTED;
838 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
840 NSContainer *This = NSWBCHROME_THIS(iface);
841 TRACE("(%p)\n", This);
842 return NS_ERROR_NOT_IMPLEMENTED;
845 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
846 PRInt32 aCX, PRInt32 aCY)
848 NSContainer *This = NSWBCHROME_THIS(iface);
849 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
855 NSContainer *This = NSWBCHROME_THIS(iface);
856 WARN("(%p)\n", This);
857 return NS_ERROR_NOT_IMPLEMENTED;
860 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
862 NSContainer *This = NSWBCHROME_THIS(iface);
863 WARN("(%p)->(%p)\n", This, _retval);
864 return NS_ERROR_NOT_IMPLEMENTED;
867 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
868 nsresult aStatus)
870 NSContainer *This = NSWBCHROME_THIS(iface);
871 WARN("(%p)->(%08x)\n", This, aStatus);
872 return NS_ERROR_NOT_IMPLEMENTED;
875 #undef NSWBCHROME_THIS
877 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
878 nsWebBrowserChrome_QueryInterface,
879 nsWebBrowserChrome_AddRef,
880 nsWebBrowserChrome_Release,
881 nsWebBrowserChrome_SetStatus,
882 nsWebBrowserChrome_GetWebBrowser,
883 nsWebBrowserChrome_SetWebBrowser,
884 nsWebBrowserChrome_GetChromeFlags,
885 nsWebBrowserChrome_SetChromeFlags,
886 nsWebBrowserChrome_DestroyBrowserWindow,
887 nsWebBrowserChrome_SizeBrowserTo,
888 nsWebBrowserChrome_ShowAsModal,
889 nsWebBrowserChrome_IsWindowModal,
890 nsWebBrowserChrome_ExitModalEventLoop
893 /**********************************************************
894 * nsIContextMenuListener interface
897 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
899 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
900 nsIIDRef riid, nsQIResult result)
902 NSContainer *This = NSCML_THIS(iface);
903 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
906 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
908 NSContainer *This = NSCML_THIS(iface);
909 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
912 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
914 NSContainer *This = NSCML_THIS(iface);
915 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
918 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
919 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
921 NSContainer *This = NSCML_THIS(iface);
922 nsIDOMMouseEvent *event;
923 POINT pt;
924 DWORD dwID = CONTEXT_MENU_DEFAULT;
925 nsresult nsres;
927 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
929 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
930 if(NS_FAILED(nsres)) {
931 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
932 return nsres;
935 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
936 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
937 nsIDOMMouseEvent_Release(event);
939 switch(aContextFlags) {
940 case CONTEXT_NONE:
941 case CONTEXT_DOCUMENT:
942 case CONTEXT_TEXT:
943 dwID = CONTEXT_MENU_DEFAULT;
944 break;
945 case CONTEXT_IMAGE:
946 case CONTEXT_IMAGE|CONTEXT_LINK:
947 dwID = CONTEXT_MENU_IMAGE;
948 break;
949 case CONTEXT_LINK:
950 dwID = CONTEXT_MENU_ANCHOR;
951 break;
952 case CONTEXT_INPUT:
953 dwID = CONTEXT_MENU_CONTROL;
954 break;
955 default:
956 FIXME("aContextFlags=%08x\n", aContextFlags);
959 show_context_menu(This->doc, dwID, &pt);
961 return NS_OK;
964 #undef NSCML_THIS
966 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
967 nsContextMenuListener_QueryInterface,
968 nsContextMenuListener_AddRef,
969 nsContextMenuListener_Release,
970 nsContextMenuListener_OnShowContextMenu
973 /**********************************************************
974 * nsIURIContentListener interface
977 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
979 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
980 nsIIDRef riid, nsQIResult result)
982 NSContainer *This = NSURICL_THIS(iface);
983 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
986 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
988 NSContainer *This = NSURICL_THIS(iface);
989 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
992 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
994 NSContainer *This = NSURICL_THIS(iface);
995 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
998 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
999 nsIURI *aURI, PRBool *_retval)
1001 NSContainer *This = NSURICL_THIS(iface);
1002 nsIWineURI *wine_uri;
1003 nsACString spec_str;
1004 const char *spec;
1005 nsresult nsres;
1007 nsACString_Init(&spec_str, NULL);
1008 nsIURI_GetSpec(aURI, &spec_str);
1009 nsACString_GetData(&spec_str, &spec, NULL);
1011 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1013 nsACString_Finish(&spec_str);
1015 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1016 if(NS_FAILED(nsres)) {
1017 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
1018 return NS_ERROR_NOT_IMPLEMENTED;
1021 nsIWineURI_SetNSContainer(wine_uri, This);
1022 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
1024 if(This->bscallback && This->bscallback->mon) {
1025 LPWSTR wine_url;
1026 HRESULT hres;
1028 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
1029 if(SUCCEEDED(hres)) {
1030 nsIWineURI_SetWineURL(wine_uri, wine_url);
1031 CoTaskMemFree(wine_url);
1032 }else {
1033 WARN("GetDisplayName failed: %08x\n", hres);
1037 nsIWineURI_Release(wine_uri);
1039 *_retval = FALSE;
1040 return This->content_listener
1041 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1042 : NS_OK;
1045 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1046 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1047 nsIStreamListener **aContentHandler, PRBool *_retval)
1049 NSContainer *This = NSURICL_THIS(iface);
1051 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1052 aRequest, aContentHandler, _retval);
1054 return This->content_listener
1055 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1056 aIsContentPreferred, aRequest, aContentHandler, _retval)
1057 : NS_ERROR_NOT_IMPLEMENTED;
1060 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1061 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1063 NSContainer *This = NSURICL_THIS(iface);
1065 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1067 /* FIXME: Should we do something here? */
1068 *_retval = TRUE;
1070 return This->content_listener
1071 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1072 aDesiredContentType, _retval)
1073 : NS_OK;
1076 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1077 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1078 PRBool *_retval)
1080 NSContainer *This = NSURICL_THIS(iface);
1082 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1083 aDesiredContentType, _retval);
1085 return This->content_listener
1086 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1087 aIsContentPreferred, aDesiredContentType, _retval)
1088 : NS_ERROR_NOT_IMPLEMENTED;
1091 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1092 nsISupports **aLoadCookie)
1094 NSContainer *This = NSURICL_THIS(iface);
1096 WARN("(%p)->(%p)\n", This, aLoadCookie);
1098 return This->content_listener
1099 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1100 : NS_ERROR_NOT_IMPLEMENTED;
1103 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1104 nsISupports *aLoadCookie)
1106 NSContainer *This = NSURICL_THIS(iface);
1108 WARN("(%p)->(%p)\n", This, aLoadCookie);
1110 return This->content_listener
1111 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1112 : NS_ERROR_NOT_IMPLEMENTED;
1115 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1116 nsIURIContentListener **aParentContentListener)
1118 NSContainer *This = NSURICL_THIS(iface);
1120 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1122 if(This->content_listener)
1123 nsIURIContentListener_AddRef(This->content_listener);
1125 *aParentContentListener = This->content_listener;
1126 return NS_OK;
1129 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1130 nsIURIContentListener *aParentContentListener)
1132 NSContainer *This = NSURICL_THIS(iface);
1134 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1136 if(aParentContentListener == NSURICL(This))
1137 return NS_OK;
1139 if(This->content_listener)
1140 nsIURIContentListener_Release(This->content_listener);
1142 This->content_listener = aParentContentListener;
1143 if(This->content_listener)
1144 nsIURIContentListener_AddRef(This->content_listener);
1146 return NS_OK;
1149 #undef NSURICL_THIS
1151 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1152 nsURIContentListener_QueryInterface,
1153 nsURIContentListener_AddRef,
1154 nsURIContentListener_Release,
1155 nsURIContentListener_OnStartURIOpen,
1156 nsURIContentListener_DoContent,
1157 nsURIContentListener_IsPreferred,
1158 nsURIContentListener_CanHandleContent,
1159 nsURIContentListener_GetLoadCookie,
1160 nsURIContentListener_SetLoadCookie,
1161 nsURIContentListener_GetParentContentListener,
1162 nsURIContentListener_SetParentContentListener
1165 /**********************************************************
1166 * nsIEmbeddinSiteWindow interface
1169 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1171 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1172 nsIIDRef riid, nsQIResult result)
1174 NSContainer *This = NSEMBWNDS_THIS(iface);
1175 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1178 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1180 NSContainer *This = NSEMBWNDS_THIS(iface);
1181 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1184 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1186 NSContainer *This = NSEMBWNDS_THIS(iface);
1187 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1190 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1191 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1193 NSContainer *This = NSEMBWNDS_THIS(iface);
1194 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1195 return NS_ERROR_NOT_IMPLEMENTED;
1198 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1199 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1201 NSContainer *This = NSEMBWNDS_THIS(iface);
1202 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1203 return NS_ERROR_NOT_IMPLEMENTED;
1206 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1208 NSContainer *This = NSEMBWNDS_THIS(iface);
1210 TRACE("(%p)\n", This);
1212 return nsIBaseWindow_SetFocus(This->window);
1215 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1216 PRBool *aVisibility)
1218 NSContainer *This = NSEMBWNDS_THIS(iface);
1220 TRACE("(%p)->(%p)\n", This, aVisibility);
1222 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1223 return NS_OK;
1226 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1227 PRBool aVisibility)
1229 NSContainer *This = NSEMBWNDS_THIS(iface);
1231 TRACE("(%p)->(%x)\n", This, aVisibility);
1233 return NS_OK;
1236 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1237 PRUnichar **aTitle)
1239 NSContainer *This = NSEMBWNDS_THIS(iface);
1240 WARN("(%p)->(%p)\n", This, aTitle);
1241 return NS_ERROR_NOT_IMPLEMENTED;
1244 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1245 const PRUnichar *aTitle)
1247 NSContainer *This = NSEMBWNDS_THIS(iface);
1248 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1249 return NS_ERROR_NOT_IMPLEMENTED;
1252 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1253 void **aSiteWindow)
1255 NSContainer *This = NSEMBWNDS_THIS(iface);
1257 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1259 *aSiteWindow = This->hwnd;
1260 return NS_OK;
1263 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1264 nsEmbeddingSiteWindow_QueryInterface,
1265 nsEmbeddingSiteWindow_AddRef,
1266 nsEmbeddingSiteWindow_Release,
1267 nsEmbeddingSiteWindow_SetDimensions,
1268 nsEmbeddingSiteWindow_GetDimensions,
1269 nsEmbeddingSiteWindow_SetFocus,
1270 nsEmbeddingSiteWindow_GetVisibility,
1271 nsEmbeddingSiteWindow_SetVisibility,
1272 nsEmbeddingSiteWindow_GetTitle,
1273 nsEmbeddingSiteWindow_SetTitle,
1274 nsEmbeddingSiteWindow_GetSiteWindow
1277 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1279 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1280 nsQIResult result)
1282 NSContainer *This = NSTOOLTIP_THIS(iface);
1283 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1286 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1288 NSContainer *This = NSTOOLTIP_THIS(iface);
1289 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1292 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1294 NSContainer *This = NSTOOLTIP_THIS(iface);
1295 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1298 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1299 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1301 NSContainer *This = NSTOOLTIP_THIS(iface);
1303 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1305 return NS_OK;
1308 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1310 NSContainer *This = NSTOOLTIP_THIS(iface);
1312 hide_tooltip(This->doc);
1314 return NS_OK;
1317 #undef NSTOOLTIM_THIS
1319 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1320 nsTooltipListener_QueryInterface,
1321 nsTooltipListener_AddRef,
1322 nsTooltipListener_Release,
1323 nsTooltipListener_OnShowTooltip,
1324 nsTooltipListener_OnHideTooltip
1327 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1329 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1330 nsIIDRef riid, nsQIResult result)
1332 NSContainer *This = NSIFACEREQ_THIS(iface);
1333 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1336 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1338 NSContainer *This = NSIFACEREQ_THIS(iface);
1339 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1342 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1344 NSContainer *This = NSIFACEREQ_THIS(iface);
1345 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1348 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1349 nsIIDRef riid, nsQIResult result)
1351 NSContainer *This = NSIFACEREQ_THIS(iface);
1353 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1354 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1355 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1358 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1361 #undef NSIFACEREQ_THIS
1363 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1364 nsInterfaceRequestor_QueryInterface,
1365 nsInterfaceRequestor_AddRef,
1366 nsInterfaceRequestor_Release,
1367 nsInterfaceRequestor_GetInterface
1370 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1372 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1373 nsIIDRef riid, nsQIResult result)
1375 NSContainer *This = NSWEAKREF_THIS(iface);
1376 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1379 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1381 NSContainer *This = NSWEAKREF_THIS(iface);
1382 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1385 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1387 NSContainer *This = NSWEAKREF_THIS(iface);
1388 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1391 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1392 const nsIID *riid, void **result)
1394 NSContainer *This = NSWEAKREF_THIS(iface);
1395 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1398 #undef NSWEAKREF_THIS
1400 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1401 nsWeakReference_QueryInterface,
1402 nsWeakReference_AddRef,
1403 nsWeakReference_Release,
1404 nsWeakReference_QueryReferent
1407 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1409 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1410 nsIIDRef riid, nsQIResult result)
1412 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1413 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1416 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1418 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1419 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1422 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1424 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1425 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1428 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1429 nsIWeakReference **_retval)
1431 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1433 TRACE("(%p)->(%p)\n", This, _retval);
1435 nsIWeakReference_AddRef(NSWEAKREF(This));
1436 *_retval = NSWEAKREF(This);
1437 return NS_OK;
1440 #undef NSWEAKREF_THIS
1442 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1443 nsSupportsWeakReference_QueryInterface,
1444 nsSupportsWeakReference_AddRef,
1445 nsSupportsWeakReference_Release,
1446 nsSupportsWeakReference_GetWeakReference
1450 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1452 nsIWebBrowserSetup *wbsetup;
1453 nsIScrollable *scrollable;
1454 NSContainer *ret;
1455 nsresult nsres;
1457 if(!load_gecko())
1458 return NULL;
1460 ret = mshtml_alloc(sizeof(NSContainer));
1462 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1463 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1464 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1465 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1466 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1467 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1468 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1469 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1471 ret->doc = doc;
1472 ret->ref = 1;
1473 ret->bscallback = NULL;
1474 ret->content_listener = NULL;
1475 ret->editor_controller = NULL;
1477 if(parent)
1478 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1479 ret->parent = parent;
1481 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1482 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1483 if(NS_FAILED(nsres))
1484 ERR("Creating WebBrowser failed: %08x\n", nsres);
1486 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1487 if(NS_FAILED(nsres))
1488 ERR("SetContainerWindow failed: %08x\n", nsres);
1490 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1491 (void**)&ret->window);
1492 if(NS_FAILED(nsres))
1493 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1495 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1496 (void**)&wbsetup);
1497 if(NS_SUCCEEDED(nsres)) {
1498 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
1499 nsIWebBrowserSetup_Release(wbsetup);
1500 if(NS_FAILED(nsres))
1501 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1502 }else {
1503 ERR("Could not get nsIWebBrowserSetup interface\n");
1506 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1507 (void**)&ret->navigation);
1508 if(NS_FAILED(nsres))
1509 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1511 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1512 (void**)&ret->focus);
1513 if(NS_FAILED(nsres))
1514 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1516 if(!nscontainer_class)
1517 register_nscontainer_class();
1519 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1520 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1521 GetDesktopWindow(), NULL, hInst, ret);
1523 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1524 if(NS_SUCCEEDED(nsres)) {
1525 nsres = nsIBaseWindow_Create(ret->window);
1526 if(NS_FAILED(nsres))
1527 WARN("Creating window failed: %08x\n", nsres);
1529 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1530 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1531 }else {
1532 ERR("InitWindow failed: %08x\n", nsres);
1535 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1536 if(NS_FAILED(nsres))
1537 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1539 init_nsevents(ret);
1541 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1542 if(NS_SUCCEEDED(nsres)) {
1543 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1544 ScrollOrientation_Y, Scrollbar_Always);
1545 if(NS_FAILED(nsres))
1546 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1548 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1549 ScrollOrientation_X, Scrollbar_Auto);
1550 if(NS_FAILED(nsres))
1551 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1553 nsIScrollable_Release(scrollable);
1554 }else {
1555 ERR("Could not get nsIScrollable: %08x\n", nsres);
1558 return ret;
1561 void NSContainer_Release(NSContainer *This)
1563 TRACE("(%p)\n", This);
1565 ShowWindow(This->hwnd, SW_HIDE);
1566 SetParent(This->hwnd, NULL);
1568 nsIBaseWindow_SetVisibility(This->window, FALSE);
1569 nsIBaseWindow_Destroy(This->window);
1571 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1573 nsIWebBrowser_Release(This->webbrowser);
1574 This->webbrowser = NULL;
1576 nsIWebNavigation_Release(This->navigation);
1577 This->navigation = NULL;
1579 nsIBaseWindow_Release(This->window);
1580 This->window = NULL;
1582 nsIWebBrowserFocus_Release(This->focus);
1583 This->focus = NULL;
1585 if(This->editor_controller) {
1586 nsIController_Release(This->editor_controller);
1587 This->editor_controller = NULL;
1590 if(This->content_listener) {
1591 nsIURIContentListener_Release(This->content_listener);
1592 This->content_listener = NULL;
1595 if(This->hwnd) {
1596 DestroyWindow(This->hwnd);
1597 This->hwnd = NULL;
1600 nsIWebBrowserChrome_Release(NSWBCHROME(This));