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
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"
46 #define NS_ARRAY_CONTRACTID "@mozilla.org/array;1"
47 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define APPSTARTUP_TOPIC "app-startup"
52 #define PR_UINT32_MAX 0xffffffff
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_StringGetData)(const nsAString*,const PRUnichar **,PRBool*);
72 static PRUint32 (*NS_CStringGetData)(const nsACString*,const char**,PRBool*);
74 static HINSTANCE hXPCOM = NULL;
76 static nsIServiceManager *pServMgr = NULL;
77 static nsIComponentManager *pCompMgr = NULL;
78 static nsIMemory *nsmem = NULL;
80 static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
82 static ATOM nscontainer_class;
84 #define WM_RESETFOCUS_HACK WM_USER+600
86 static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
91 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
93 if(msg == WM_CREATE) {
94 This = *(NSContainer**)lParam;
95 SetPropW(hwnd, wszTHIS, This);
97 This = (NSContainer*)GetPropW(hwnd, wszTHIS);
102 TRACE("(%p)->(WM_SIZE)\n", This);
104 nsres = nsIBaseWindow_SetSize(This->window,
105 LOWORD(lParam), HIWORD(lParam), TRUE);
107 WARN("SetSize failed: %08x\n", nsres);
110 case WM_RESETFOCUS_HACK:
113 * Gecko grabs focus in edit mode and some apps don't like it.
114 * We should somehow prevent grabbing focus.
116 if(This->reset_focus) {
117 SetFocus(This->reset_focus);
118 This->reset_focus = NULL;
122 return DefWindowProcW(hwnd, msg, wParam, lParam);
126 static void register_nscontainer_class(void)
128 static WNDCLASSEXW wndclass = {
132 0, 0, NULL, NULL, NULL, NULL, NULL,
136 wndclass.hInstance = hInst;
137 nscontainer_class = RegisterClassExW(&wndclass);
140 static BOOL load_xpcom(const PRUnichar *gre_path)
142 WCHAR path_env[MAX_PATH];
145 static const WCHAR wszPATH[] = {'P','A','T','H',0};
146 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
148 TRACE("(%s)\n", debugstr_w(gre_path));
150 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
151 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
152 len = strlenW(path_env);
153 path_env[len++] = ';';
154 strcpyW(path_env+len, gre_path);
155 SetEnvironmentVariableW(wszPATH, path_env);
157 hXPCOM = LoadLibraryW(strXPCOM);
159 WARN("Could not load XPCOM: %d\n", GetLastError());
163 #define NS_DLSYM(func) \
164 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
166 ERR("Could not GetProcAddress(" #func ") failed\n")
168 NS_DLSYM(NS_InitXPCOM2);
169 NS_DLSYM(NS_ShutdownXPCOM);
170 NS_DLSYM(NS_GetComponentRegistrar);
171 NS_DLSYM(NS_StringContainerInit);
172 NS_DLSYM(NS_CStringContainerInit);
173 NS_DLSYM(NS_StringContainerFinish);
174 NS_DLSYM(NS_CStringContainerFinish);
175 NS_DLSYM(NS_StringSetData);
176 NS_DLSYM(NS_CStringSetData);
177 NS_DLSYM(NS_NewLocalFile);
178 NS_DLSYM(NS_StringGetData);
179 NS_DLSYM(NS_CStringGetData);
186 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
188 WCHAR file_name[MAX_PATH];
193 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
195 strcpyW(file_name, gre_path);
196 strcatW(file_name, wszVersion);
198 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
199 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
200 if(hfile == INVALID_HANDLE_VALUE) {
201 ERR("Could not open VERSION file\n");
205 ReadFile(hfile, version, sizeof(version), &read, NULL);
209 TRACE("%s\n", debugstr_a(version));
211 if(strcmp(version, version_string)) {
212 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
213 debugstr_a(version_string));
220 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
221 const char *version, const char *version_string)
223 DWORD res, type, size = MAX_PATH;
224 HKEY hkey = mshtml_key;
226 static const WCHAR wszGeckoPath[] =
227 {'G','e','c','k','o','P','a','t','h',0};
230 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
231 res = RegOpenKeyA(mshtml_key, version, &hkey);
232 if(res != ERROR_SUCCESS)
236 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
237 if(hkey != mshtml_key)
239 if(res != ERROR_SUCCESS || type != REG_SZ)
242 if(!check_version(gre_path, version_string))
245 return load_xpcom(gre_path);
248 static BOOL load_wine_gecko(PRUnichar *gre_path)
254 static const WCHAR wszMshtmlKey[] = {
255 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
256 '\\','M','S','H','T','M','L',0};
258 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
259 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
260 if(res != ERROR_SUCCESS)
263 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING)
264 || load_wine_gecko_v(gre_path, hkey, "0.0.1", "Wine Gecko 0.0.1\n")
265 || load_wine_gecko_v(gre_path, hkey, NULL, "Wine Gecko 0.0.1\n");
271 static void set_lang(nsIPrefBranch *pref)
274 DWORD res, size, type;
278 static const WCHAR international_keyW[] =
279 {'S','o','f','t','w','a','r','e',
280 '\\','M','i','c','r','o','s','o','f','t',
281 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
282 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
284 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
285 if(res != ERROR_SUCCESS)
288 size = sizeof(langs);
289 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
291 if(res != ERROR_SUCCESS || type != REG_SZ)
294 TRACE("Setting lang %s\n", debugstr_a(langs));
296 nsres = nsIPrefBranch_SetCharPref(pref, "intl.accept_languages", langs);
298 ERR("SetCharPref failed: %08x\n", nsres);
301 static void set_profile(void)
305 PRBool exists = FALSE;
308 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
310 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PROFILE_CONTRACTID,
311 &IID_nsIProfile, (void**)&profile);
312 if(NS_FAILED(nsres)) {
313 ERR("Could not get profile service: %08x\n", nsres);
317 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
319 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
321 ERR("CreateNewProfile failed: %08x\n", nsres);
324 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
326 ERR("SetCurrentProfile failed: %08x\n", nsres);
328 nsIProfile_Release(profile);
330 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
331 &IID_nsIPrefBranch, (void**)&pref);
332 if(NS_FAILED(nsres)) {
333 ERR("Could not get preference service: %08x\n", nsres);
339 nsIPrefBranch_Release(pref);
342 static BOOL init_xpcom(const PRUnichar *gre_path)
345 nsIObserver *pStartNotif;
346 nsIComponentRegistrar *registrar = NULL;
350 nsAString_Init(&path, gre_path);
351 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
352 nsAString_Finish(&path);
353 if(NS_FAILED(nsres)) {
354 ERR("NS_NewLocalFile failed: %08x\n", nsres);
359 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
360 if(NS_FAILED(nsres)) {
361 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
366 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
368 ERR("Could not get nsIComponentManager: %08x\n", nsres);
370 nsres = NS_GetComponentRegistrar(®istrar);
371 if(NS_SUCCEEDED(nsres)) {
372 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
374 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
376 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
378 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
380 init_nsio(pCompMgr, registrar);
382 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
385 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
386 NULL, &IID_nsIObserver, (void**)&pStartNotif);
387 if(NS_SUCCEEDED(nsres)) {
388 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
390 ERR("Observe failed: %08x\n", nsres);
392 nsIObserver_Release(pStartNotif);
394 ERR("could not get appstartup-notifier: %08x\n", nsres);
399 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
400 NULL, &IID_nsIMemory, (void**)&nsmem);
402 ERR("Could not get nsIMemory: %08x\n", nsres);
405 register_nsservice(registrar, pServMgr);
406 nsIComponentRegistrar_Release(registrar);
412 static CRITICAL_SECTION cs_load_gecko;
413 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
415 0, 0, &cs_load_gecko,
416 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
417 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
419 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
421 BOOL load_gecko(BOOL silent)
423 PRUnichar gre_path[MAX_PATH];
426 static LONG loading_thread;
430 /* load_gecko may be called recursively */
431 if(loading_thread == GetCurrentThreadId())
432 return pCompMgr != NULL;
434 EnterCriticalSection(&cs_load_gecko);
436 if(!loading_thread) {
437 loading_thread = GetCurrentThreadId();
439 if(load_wine_gecko(gre_path)
440 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
441 ret = init_xpcom(gre_path);
443 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
445 ret = pCompMgr != NULL;
448 LeaveCriticalSection(&cs_load_gecko);
453 void *nsalloc(size_t size)
455 return nsIMemory_Alloc(nsmem, size);
458 void nsfree(void *mem)
460 nsIMemory_Free(nsmem, mem);
463 void nsACString_Init(nsACString *str, const char *data)
465 NS_CStringContainerInit(str);
467 nsACString_SetData(str, data);
470 void nsACString_SetData(nsACString *str, const char *data)
472 NS_CStringSetData(str, data, PR_UINT32_MAX);
475 PRUint32 nsACString_GetData(const nsACString *str, const char **data, PRBool *termited)
477 return NS_CStringGetData(str, data, termited);
480 void nsACString_Finish(nsACString *str)
482 NS_CStringContainerFinish(str);
485 void nsAString_Init(nsAString *str, const PRUnichar *data)
487 NS_StringContainerInit(str);
489 NS_StringSetData(str, data, PR_UINT32_MAX);
492 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data, PRBool *termited)
494 return NS_StringGetData(str, data, termited);
497 void nsAString_Finish(nsAString *str)
499 NS_StringContainerFinish(str);
502 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
504 nsIStringInputStream *ret;
510 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
511 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
513 if(NS_FAILED(nsres)) {
514 ERR("Could not get nsIStringInputStream\n");
518 nsres = nsIStringInputStream_SetData(ret, data, data_len);
519 if(NS_FAILED(nsres)) {
520 ERR("AdoptData failed: %08x\n", nsres);
521 nsIStringInputStream_Release(ret);
525 return (nsIInputStream*)ret;
528 nsIMutableArray *create_nsarray(void)
530 nsIMutableArray *ret;
536 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
537 NS_ARRAY_CONTRACTID, NULL, &IID_nsIMutableArray,
539 if(NS_FAILED(nsres)) {
540 ERR("Could not get nsIArray: %08x\n", nsres);
547 nsIWritableVariant *create_nsvariant(void)
549 nsIWritableVariant *ret;
555 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
556 NS_VARIANT_CONTRACTID, NULL, &IID_nsIWritableVariant,
558 if(NS_FAILED(nsres)) {
559 ERR("Could not get nsIWritableVariant: %08x\n", nsres);
566 nsICommandParams *create_nscommand_params(void)
568 nsICommandParams *ret = NULL;
574 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
575 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
578 ERR("Could not get nsICommandParams\n");
583 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
585 nsIInterfaceRequestor *iface_req;
588 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
592 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
593 nsIInterfaceRequestor_Release(iface_req);
598 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
600 nsIDOMNodeList *node_list = NULL;
601 PRBool has_children = FALSE;
605 nsIDOMNode_HasChildNodes(nsnode, &has_children);
607 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
608 if(NS_FAILED(nsres)) {
609 ERR("GetType failed: %08x\n", nsres);
615 nsIDOMElement *nselem;
616 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
617 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
618 nsIDOMElement_Release(nselem);
623 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
624 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
625 nsIDOMText_Release(nstext);
629 nsIDOMComment *nscomment;
630 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMComment, (void**)&nscomment);
631 nsres = nsIContentSerializer_AppendComment(serializer, nscomment, 0, -1, str);
634 case DOCUMENT_NODE: {
635 nsIDOMDocument *nsdoc;
636 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
637 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
638 nsIDOMDocument_Release(nsdoc);
641 case DOCUMENT_FRAGMENT_NODE:
644 FIXME("Unhandled type %u\n", type);
648 PRUint32 child_cnt, i;
649 nsIDOMNode *child_node;
651 nsIDOMNode_GetChildNodes(nsnode, &node_list);
652 nsIDOMNodeList_GetLength(node_list, &child_cnt);
654 for(i=0; i<child_cnt; i++) {
655 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
656 if(NS_SUCCEEDED(nsres)) {
657 nsnode_to_nsstring_rec(serializer, child_node, str);
658 nsIDOMNode_Release(child_node);
660 ERR("Item failed: %08x\n", nsres);
664 nsIDOMNodeList_Release(node_list);
667 if(type == ELEMENT_NODE) {
668 nsIDOMElement *nselem;
669 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
670 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
671 nsIDOMElement_Release(nselem);
675 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
677 nsIContentSerializer *serializer;
681 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
682 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
683 (void**)&serializer);
684 if(NS_FAILED(nsres)) {
685 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
689 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
691 ERR("Init failed: %08x\n", nsres);
693 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
694 nsnode_to_nsstring_rec(serializer, nsnode, str);
695 nsIDOMNode_Release(nsnode);
697 nsres = nsIContentSerializer_Flush(serializer, str);
699 ERR("Flush failed: %08x\n", nsres);
701 nsIContentSerializer_Release(serializer);
704 void get_editor_controller(NSContainer *This)
706 nsIEditingSession *editing_session = NULL;
707 nsIControllerContext *ctrlctx;
711 nsIEditor_Release(This->editor);
715 if(This->editor_controller) {
716 nsIController_Release(This->editor_controller);
717 This->editor_controller = NULL;
720 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
721 (void**)&editing_session);
722 if(NS_FAILED(nsres)) {
723 ERR("Could not get nsIEditingSession: %08x\n", nsres);
727 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
728 This->doc->window->nswindow, &This->editor);
729 nsIEditingSession_Release(editing_session);
730 if(NS_FAILED(nsres)) {
731 ERR("Could not get editor: %08x\n", nsres);
735 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
736 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
737 if(NS_SUCCEEDED(nsres)) {
738 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
740 ERR("SetCommandContext failed: %08x\n", nsres);
741 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
742 (void**)&This->editor_controller);
743 nsIControllerContext_Release(ctrlctx);
745 ERR("Could not get nsIController interface: %08x\n", nsres);
747 ERR("Could not create edit controller: %08x\n", nsres);
751 void set_ns_editmode(NSContainer *This)
753 nsIEditingSession *editing_session = NULL;
754 nsIURIContentListener *listener = NULL;
755 nsIDOMWindow *dom_window = NULL;
758 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
759 (void**)&editing_session);
760 if(NS_FAILED(nsres)) {
761 ERR("Could not get nsIEditingSession: %08x\n", nsres);
765 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
766 if(NS_FAILED(nsres)) {
767 ERR("Could not get content DOM window: %08x\n", nsres);
768 nsIEditingSession_Release(editing_session);
772 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
773 nsIEditingSession_Release(editing_session);
774 nsIDOMWindow_Release(dom_window);
775 if(NS_FAILED(nsres)) {
776 ERR("MakeWindowEditable failed: %08x\n", nsres);
780 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
781 * It seams to be a bug in Gecko. To workaround it we set our content
782 * listener again and Gecko's one as its parent.
784 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
785 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
786 nsIURIContentListener_Release(listener);
787 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
790 void close_gecko(void)
795 nsIComponentManager_Release(pCompMgr);
798 nsIServiceManager_Release(pServMgr);
801 nsIMemory_Release(nsmem);
807 /**********************************************************
808 * nsIWebBrowserChrome interface
811 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
813 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
814 nsIIDRef riid, nsQIResult result)
816 NSContainer *This = NSWBCHROME_THIS(iface);
819 if(IsEqualGUID(&IID_nsISupports, riid)) {
820 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
821 *result = NSWBCHROME(This);
822 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
823 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
824 *result = NSWBCHROME(This);
825 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
826 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
827 *result = NSCML(This);
828 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
829 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
830 *result = NSURICL(This);
831 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
832 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
833 *result = NSEMBWNDS(This);
834 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
835 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
836 *result = NSTOOLTIP(This);
837 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
838 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
839 *result = NSIFACEREQ(This);
840 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
841 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
842 *result = NSWEAKREF(This);
843 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
844 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
845 *result = NSSUPWEAKREF(This);
849 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
853 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
854 return NS_NOINTERFACE;
857 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
859 NSContainer *This = NSWBCHROME_THIS(iface);
860 LONG ref = InterlockedIncrement(&This->ref);
862 TRACE("(%p) ref=%d\n", This, ref);
867 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
869 NSContainer *This = NSWBCHROME_THIS(iface);
870 LONG ref = InterlockedDecrement(&This->ref);
872 TRACE("(%p) ref=%d\n", This, ref);
876 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
883 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
884 PRUint32 statusType, const PRUnichar *status)
886 NSContainer *This = NSWBCHROME_THIS(iface);
887 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
888 return NS_ERROR_NOT_IMPLEMENTED;
891 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
892 nsIWebBrowser **aWebBrowser)
894 NSContainer *This = NSWBCHROME_THIS(iface);
896 TRACE("(%p)->(%p)\n", This, aWebBrowser);
899 return NS_ERROR_INVALID_ARG;
902 nsIWebBrowser_AddRef(This->webbrowser);
903 *aWebBrowser = This->webbrowser;
907 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
908 nsIWebBrowser *aWebBrowser)
910 NSContainer *This = NSWBCHROME_THIS(iface);
912 TRACE("(%p)->(%p)\n", This, aWebBrowser);
914 if(aWebBrowser != This->webbrowser)
915 ERR("Wrong nsWebBrowser!\n");
920 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
921 PRUint32 *aChromeFlags)
923 NSContainer *This = NSWBCHROME_THIS(iface);
924 WARN("(%p)->(%p)\n", This, aChromeFlags);
925 return NS_ERROR_NOT_IMPLEMENTED;
928 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
929 PRUint32 aChromeFlags)
931 NSContainer *This = NSWBCHROME_THIS(iface);
932 WARN("(%p)->(%08x)\n", This, aChromeFlags);
933 return NS_ERROR_NOT_IMPLEMENTED;
936 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
938 NSContainer *This = NSWBCHROME_THIS(iface);
939 TRACE("(%p)\n", This);
940 return NS_ERROR_NOT_IMPLEMENTED;
943 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
944 PRInt32 aCX, PRInt32 aCY)
946 NSContainer *This = NSWBCHROME_THIS(iface);
947 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
948 return NS_ERROR_NOT_IMPLEMENTED;
951 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
953 NSContainer *This = NSWBCHROME_THIS(iface);
954 WARN("(%p)\n", This);
955 return NS_ERROR_NOT_IMPLEMENTED;
958 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
960 NSContainer *This = NSWBCHROME_THIS(iface);
961 WARN("(%p)->(%p)\n", This, _retval);
962 return NS_ERROR_NOT_IMPLEMENTED;
965 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
968 NSContainer *This = NSWBCHROME_THIS(iface);
969 WARN("(%p)->(%08x)\n", This, aStatus);
970 return NS_ERROR_NOT_IMPLEMENTED;
973 #undef NSWBCHROME_THIS
975 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
976 nsWebBrowserChrome_QueryInterface,
977 nsWebBrowserChrome_AddRef,
978 nsWebBrowserChrome_Release,
979 nsWebBrowserChrome_SetStatus,
980 nsWebBrowserChrome_GetWebBrowser,
981 nsWebBrowserChrome_SetWebBrowser,
982 nsWebBrowserChrome_GetChromeFlags,
983 nsWebBrowserChrome_SetChromeFlags,
984 nsWebBrowserChrome_DestroyBrowserWindow,
985 nsWebBrowserChrome_SizeBrowserTo,
986 nsWebBrowserChrome_ShowAsModal,
987 nsWebBrowserChrome_IsWindowModal,
988 nsWebBrowserChrome_ExitModalEventLoop
991 /**********************************************************
992 * nsIContextMenuListener interface
995 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
997 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
998 nsIIDRef riid, nsQIResult result)
1000 NSContainer *This = NSCML_THIS(iface);
1001 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1004 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1006 NSContainer *This = NSCML_THIS(iface);
1007 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1010 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1012 NSContainer *This = NSCML_THIS(iface);
1013 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1016 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1017 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1019 NSContainer *This = NSCML_THIS(iface);
1020 nsIDOMMouseEvent *event;
1022 DWORD dwID = CONTEXT_MENU_DEFAULT;
1025 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1027 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1028 if(NS_FAILED(nsres)) {
1029 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1033 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1034 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1035 nsIDOMMouseEvent_Release(event);
1037 switch(aContextFlags) {
1039 case CONTEXT_DOCUMENT:
1041 dwID = CONTEXT_MENU_DEFAULT;
1044 case CONTEXT_IMAGE|CONTEXT_LINK:
1045 dwID = CONTEXT_MENU_IMAGE;
1048 dwID = CONTEXT_MENU_ANCHOR;
1051 dwID = CONTEXT_MENU_CONTROL;
1054 FIXME("aContextFlags=%08x\n", aContextFlags);
1057 show_context_menu(This->doc, dwID, &pt, (IDispatch*)HTMLDOMNODE(get_node(This->doc, aNode)));
1064 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1065 nsContextMenuListener_QueryInterface,
1066 nsContextMenuListener_AddRef,
1067 nsContextMenuListener_Release,
1068 nsContextMenuListener_OnShowContextMenu
1071 /**********************************************************
1072 * nsIURIContentListener interface
1075 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1077 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1078 nsIIDRef riid, nsQIResult result)
1080 NSContainer *This = NSURICL_THIS(iface);
1081 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1084 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1086 NSContainer *This = NSURICL_THIS(iface);
1087 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1090 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1092 NSContainer *This = NSURICL_THIS(iface);
1093 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1096 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1097 nsIURI *aURI, PRBool *_retval)
1099 NSContainer *This = NSURICL_THIS(iface);
1100 nsIWineURI *wine_uri;
1101 nsACString spec_str;
1105 nsACString_Init(&spec_str, NULL);
1106 nsIURI_GetSpec(aURI, &spec_str);
1107 nsACString_GetData(&spec_str, &spec, NULL);
1109 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1111 nsACString_Finish(&spec_str);
1113 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1114 if(NS_FAILED(nsres)) {
1115 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
1116 return NS_ERROR_NOT_IMPLEMENTED;
1119 nsIWineURI_SetNSContainer(wine_uri, This);
1120 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
1122 if(This->bscallback && This->bscallback->mon) {
1126 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
1127 if(SUCCEEDED(hres)) {
1128 nsIWineURI_SetWineURL(wine_uri, wine_url);
1129 CoTaskMemFree(wine_url);
1131 WARN("GetDisplayName failed: %08x\n", hres);
1135 nsIWineURI_Release(wine_uri);
1138 return This->content_listener
1139 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1143 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1144 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1145 nsIStreamListener **aContentHandler, PRBool *_retval)
1147 NSContainer *This = NSURICL_THIS(iface);
1149 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1150 aRequest, aContentHandler, _retval);
1152 return This->content_listener
1153 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1154 aIsContentPreferred, aRequest, aContentHandler, _retval)
1155 : NS_ERROR_NOT_IMPLEMENTED;
1158 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1159 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1161 NSContainer *This = NSURICL_THIS(iface);
1163 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1165 /* FIXME: Should we do something here? */
1168 return This->content_listener
1169 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1170 aDesiredContentType, _retval)
1174 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1175 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1178 NSContainer *This = NSURICL_THIS(iface);
1180 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1181 aDesiredContentType, _retval);
1183 return This->content_listener
1184 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1185 aIsContentPreferred, aDesiredContentType, _retval)
1186 : NS_ERROR_NOT_IMPLEMENTED;
1189 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1190 nsISupports **aLoadCookie)
1192 NSContainer *This = NSURICL_THIS(iface);
1194 WARN("(%p)->(%p)\n", This, aLoadCookie);
1196 return This->content_listener
1197 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1198 : NS_ERROR_NOT_IMPLEMENTED;
1201 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1202 nsISupports *aLoadCookie)
1204 NSContainer *This = NSURICL_THIS(iface);
1206 WARN("(%p)->(%p)\n", This, aLoadCookie);
1208 return This->content_listener
1209 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1210 : NS_ERROR_NOT_IMPLEMENTED;
1213 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1214 nsIURIContentListener **aParentContentListener)
1216 NSContainer *This = NSURICL_THIS(iface);
1218 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1220 if(This->content_listener)
1221 nsIURIContentListener_AddRef(This->content_listener);
1223 *aParentContentListener = This->content_listener;
1227 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1228 nsIURIContentListener *aParentContentListener)
1230 NSContainer *This = NSURICL_THIS(iface);
1232 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1234 if(aParentContentListener == NSURICL(This))
1237 if(This->content_listener)
1238 nsIURIContentListener_Release(This->content_listener);
1240 This->content_listener = aParentContentListener;
1241 if(This->content_listener)
1242 nsIURIContentListener_AddRef(This->content_listener);
1249 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1250 nsURIContentListener_QueryInterface,
1251 nsURIContentListener_AddRef,
1252 nsURIContentListener_Release,
1253 nsURIContentListener_OnStartURIOpen,
1254 nsURIContentListener_DoContent,
1255 nsURIContentListener_IsPreferred,
1256 nsURIContentListener_CanHandleContent,
1257 nsURIContentListener_GetLoadCookie,
1258 nsURIContentListener_SetLoadCookie,
1259 nsURIContentListener_GetParentContentListener,
1260 nsURIContentListener_SetParentContentListener
1263 /**********************************************************
1264 * nsIEmbeddinSiteWindow interface
1267 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1269 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1270 nsIIDRef riid, nsQIResult result)
1272 NSContainer *This = NSEMBWNDS_THIS(iface);
1273 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1276 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1278 NSContainer *This = NSEMBWNDS_THIS(iface);
1279 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1282 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1284 NSContainer *This = NSEMBWNDS_THIS(iface);
1285 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1288 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1289 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1291 NSContainer *This = NSEMBWNDS_THIS(iface);
1292 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1297 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1299 NSContainer *This = NSEMBWNDS_THIS(iface);
1300 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1301 return NS_ERROR_NOT_IMPLEMENTED;
1304 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1306 NSContainer *This = NSEMBWNDS_THIS(iface);
1308 TRACE("(%p)\n", This);
1310 if(This->reset_focus)
1311 PostMessageW(This->hwnd, WM_RESETFOCUS_HACK, 0, 0);
1313 return nsIBaseWindow_SetFocus(This->window);
1316 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1317 PRBool *aVisibility)
1319 NSContainer *This = NSEMBWNDS_THIS(iface);
1321 TRACE("(%p)->(%p)\n", This, aVisibility);
1323 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1327 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1330 NSContainer *This = NSEMBWNDS_THIS(iface);
1332 TRACE("(%p)->(%x)\n", This, aVisibility);
1337 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1340 NSContainer *This = NSEMBWNDS_THIS(iface);
1341 WARN("(%p)->(%p)\n", This, aTitle);
1342 return NS_ERROR_NOT_IMPLEMENTED;
1345 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1346 const PRUnichar *aTitle)
1348 NSContainer *This = NSEMBWNDS_THIS(iface);
1349 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1350 return NS_ERROR_NOT_IMPLEMENTED;
1353 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1356 NSContainer *This = NSEMBWNDS_THIS(iface);
1358 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1360 *aSiteWindow = This->hwnd;
1364 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1365 nsEmbeddingSiteWindow_QueryInterface,
1366 nsEmbeddingSiteWindow_AddRef,
1367 nsEmbeddingSiteWindow_Release,
1368 nsEmbeddingSiteWindow_SetDimensions,
1369 nsEmbeddingSiteWindow_GetDimensions,
1370 nsEmbeddingSiteWindow_SetFocus,
1371 nsEmbeddingSiteWindow_GetVisibility,
1372 nsEmbeddingSiteWindow_SetVisibility,
1373 nsEmbeddingSiteWindow_GetTitle,
1374 nsEmbeddingSiteWindow_SetTitle,
1375 nsEmbeddingSiteWindow_GetSiteWindow
1378 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1380 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1383 NSContainer *This = NSTOOLTIP_THIS(iface);
1384 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1387 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1389 NSContainer *This = NSTOOLTIP_THIS(iface);
1390 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1393 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1395 NSContainer *This = NSTOOLTIP_THIS(iface);
1396 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1399 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1400 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1402 NSContainer *This = NSTOOLTIP_THIS(iface);
1404 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1409 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1411 NSContainer *This = NSTOOLTIP_THIS(iface);
1413 hide_tooltip(This->doc);
1418 #undef NSTOOLTIM_THIS
1420 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1421 nsTooltipListener_QueryInterface,
1422 nsTooltipListener_AddRef,
1423 nsTooltipListener_Release,
1424 nsTooltipListener_OnShowTooltip,
1425 nsTooltipListener_OnHideTooltip
1428 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1430 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1431 nsIIDRef riid, nsQIResult result)
1433 NSContainer *This = NSIFACEREQ_THIS(iface);
1434 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1437 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1439 NSContainer *This = NSIFACEREQ_THIS(iface);
1440 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1443 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1445 NSContainer *This = NSIFACEREQ_THIS(iface);
1446 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1449 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1450 nsIIDRef riid, nsQIResult result)
1452 NSContainer *This = NSIFACEREQ_THIS(iface);
1454 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1455 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1456 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1459 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1462 #undef NSIFACEREQ_THIS
1464 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1465 nsInterfaceRequestor_QueryInterface,
1466 nsInterfaceRequestor_AddRef,
1467 nsInterfaceRequestor_Release,
1468 nsInterfaceRequestor_GetInterface
1471 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1473 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1474 nsIIDRef riid, nsQIResult result)
1476 NSContainer *This = NSWEAKREF_THIS(iface);
1477 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1480 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1482 NSContainer *This = NSWEAKREF_THIS(iface);
1483 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1486 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1488 NSContainer *This = NSWEAKREF_THIS(iface);
1489 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1492 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1493 const nsIID *riid, void **result)
1495 NSContainer *This = NSWEAKREF_THIS(iface);
1496 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1499 #undef NSWEAKREF_THIS
1501 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1502 nsWeakReference_QueryInterface,
1503 nsWeakReference_AddRef,
1504 nsWeakReference_Release,
1505 nsWeakReference_QueryReferent
1508 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1510 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1511 nsIIDRef riid, nsQIResult result)
1513 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1514 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1517 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1519 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1520 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1523 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1525 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1526 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1529 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1530 nsIWeakReference **_retval)
1532 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1534 TRACE("(%p)->(%p)\n", This, _retval);
1536 nsIWeakReference_AddRef(NSWEAKREF(This));
1537 *_retval = NSWEAKREF(This);
1541 #undef NSWEAKREF_THIS
1543 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1544 nsSupportsWeakReference_QueryInterface,
1545 nsSupportsWeakReference_AddRef,
1546 nsSupportsWeakReference_Release,
1547 nsSupportsWeakReference_GetWeakReference
1551 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1553 nsIWebBrowserSetup *wbsetup;
1554 nsIScrollable *scrollable;
1558 if(!load_gecko(FALSE))
1561 ret = mshtml_alloc(sizeof(NSContainer));
1563 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1564 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1565 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1566 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1567 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1568 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1569 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1570 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1574 ret->bscallback = NULL;
1575 ret->content_listener = NULL;
1576 ret->editor_controller = NULL;
1578 ret->reset_focus = NULL;
1581 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1582 ret->parent = parent;
1584 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1585 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1586 if(NS_FAILED(nsres))
1587 ERR("Creating WebBrowser failed: %08x\n", nsres);
1589 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1590 if(NS_FAILED(nsres))
1591 ERR("SetContainerWindow failed: %08x\n", nsres);
1593 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1594 (void**)&ret->window);
1595 if(NS_FAILED(nsres))
1596 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1598 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1600 if(NS_SUCCEEDED(nsres)) {
1601 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1602 nsIWebBrowserSetup_Release(wbsetup);
1603 if(NS_FAILED(nsres))
1604 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1606 ERR("Could not get nsIWebBrowserSetup interface\n");
1609 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1610 (void**)&ret->navigation);
1611 if(NS_FAILED(nsres))
1612 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1614 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1615 (void**)&ret->focus);
1616 if(NS_FAILED(nsres))
1617 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1619 if(!nscontainer_class)
1620 register_nscontainer_class();
1622 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1623 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1624 GetDesktopWindow(), NULL, hInst, ret);
1626 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1627 if(NS_SUCCEEDED(nsres)) {
1628 nsres = nsIBaseWindow_Create(ret->window);
1629 if(NS_FAILED(nsres))
1630 WARN("Creating window failed: %08x\n", nsres);
1632 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1633 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1635 ERR("InitWindow failed: %08x\n", nsres);
1638 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1639 if(NS_FAILED(nsres))
1640 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1644 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1645 if(NS_SUCCEEDED(nsres)) {
1646 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1647 ScrollOrientation_Y, Scrollbar_Always);
1648 if(NS_FAILED(nsres))
1649 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1651 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1652 ScrollOrientation_X, Scrollbar_Auto);
1653 if(NS_FAILED(nsres))
1654 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1656 nsIScrollable_Release(scrollable);
1658 ERR("Could not get nsIScrollable: %08x\n", nsres);
1664 void NSContainer_Release(NSContainer *This)
1666 TRACE("(%p)\n", This);
1668 ShowWindow(This->hwnd, SW_HIDE);
1669 SetParent(This->hwnd, NULL);
1671 nsIBaseWindow_SetVisibility(This->window, FALSE);
1672 nsIBaseWindow_Destroy(This->window);
1674 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1676 nsIWebBrowser_Release(This->webbrowser);
1677 This->webbrowser = NULL;
1679 nsIWebNavigation_Release(This->navigation);
1680 This->navigation = NULL;
1682 nsIBaseWindow_Release(This->window);
1683 This->window = NULL;
1685 nsIWebBrowserFocus_Release(This->focus);
1688 if(This->editor_controller) {
1689 nsIController_Release(This->editor_controller);
1690 This->editor_controller = NULL;
1694 nsIEditor_Release(This->editor);
1695 This->editor = NULL;
1698 if(This->content_listener) {
1699 nsIURIContentListener_Release(This->content_listener);
1700 This->content_listener = NULL;
1704 DestroyWindow(This->hwnd);
1708 nsIWebBrowserChrome_Release(NSWBCHROME(This));