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.
117 TRACE("WM_RESETFOCUS_HACK\n");
119 if(This->reset_focus) {
120 SetFocus(This->reset_focus);
121 This->reset_focus = NULL;
123 This->doc->focus = FALSE;
127 return DefWindowProcW(hwnd, msg, wParam, lParam);
131 static void register_nscontainer_class(void)
133 static WNDCLASSEXW wndclass = {
137 0, 0, NULL, NULL, NULL, NULL, NULL,
141 wndclass.hInstance = hInst;
142 nscontainer_class = RegisterClassExW(&wndclass);
145 static BOOL load_xpcom(const PRUnichar *gre_path)
147 WCHAR path_env[MAX_PATH];
150 static const WCHAR wszPATH[] = {'P','A','T','H',0};
151 static const WCHAR strXPCOM[] = {'x','p','c','o','m','.','d','l','l',0};
153 TRACE("(%s)\n", debugstr_w(gre_path));
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
157 len = strlenW(path_env);
158 path_env[len++] = ';';
159 strcpyW(path_env+len, gre_path);
160 SetEnvironmentVariableW(wszPATH, path_env);
162 hXPCOM = LoadLibraryW(strXPCOM);
164 WARN("Could not load XPCOM: %d\n", GetLastError());
168 #define NS_DLSYM(func) \
169 func = (void *)GetProcAddress(hXPCOM, #func); \
171 ERR("Could not GetProcAddress(" #func ") failed\n")
173 NS_DLSYM(NS_InitXPCOM2);
174 NS_DLSYM(NS_ShutdownXPCOM);
175 NS_DLSYM(NS_GetComponentRegistrar);
176 NS_DLSYM(NS_StringContainerInit);
177 NS_DLSYM(NS_CStringContainerInit);
178 NS_DLSYM(NS_StringContainerFinish);
179 NS_DLSYM(NS_CStringContainerFinish);
180 NS_DLSYM(NS_StringSetData);
181 NS_DLSYM(NS_CStringSetData);
182 NS_DLSYM(NS_NewLocalFile);
183 NS_DLSYM(NS_StringGetData);
184 NS_DLSYM(NS_CStringGetData);
191 static BOOL check_version(LPCWSTR gre_path, const char *version_string)
193 WCHAR file_name[MAX_PATH];
198 static const WCHAR wszVersion[] = {'\\','V','E','R','S','I','O','N',0};
200 strcpyW(file_name, gre_path);
201 strcatW(file_name, wszVersion);
203 hfile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
204 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
205 if(hfile == INVALID_HANDLE_VALUE) {
206 ERR("Could not open VERSION file\n");
210 ReadFile(hfile, version, sizeof(version), &read, NULL);
214 TRACE("%s\n", debugstr_a(version));
216 if(strcmp(version, version_string)) {
217 ERR("Unexpected version %s, expected %s\n", debugstr_a(version),
218 debugstr_a(version_string));
225 static BOOL load_wine_gecko_v(PRUnichar *gre_path, HKEY mshtml_key,
226 const char *version, const char *version_string)
228 DWORD res, type, size = MAX_PATH;
229 HKEY hkey = mshtml_key;
231 static const WCHAR wszGeckoPath[] =
232 {'G','e','c','k','o','P','a','t','h',0};
235 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
236 res = RegOpenKeyA(mshtml_key, version, &hkey);
237 if(res != ERROR_SUCCESS)
241 res = RegQueryValueExW(hkey, wszGeckoPath, NULL, &type, (LPBYTE)gre_path, &size);
242 if(hkey != mshtml_key)
244 if(res != ERROR_SUCCESS || type != REG_SZ)
247 if(!check_version(gre_path, version_string))
250 return load_xpcom(gre_path);
253 static BOOL load_wine_gecko(PRUnichar *gre_path)
259 static const WCHAR wszMshtmlKey[] = {
260 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
261 '\\','M','S','H','T','M','L',0};
263 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
264 res = RegOpenKeyW(HKEY_CURRENT_USER, wszMshtmlKey, &hkey);
265 if(res != ERROR_SUCCESS)
268 ret = load_wine_gecko_v(gre_path, hkey, GECKO_VERSION, GECKO_VERSION_STRING);
274 static void set_lang(nsIPrefBranch *pref)
277 DWORD res, size, type;
281 static const WCHAR international_keyW[] =
282 {'S','o','f','t','w','a','r','e',
283 '\\','M','i','c','r','o','s','o','f','t',
284 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
285 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
287 res = RegOpenKeyW(HKEY_CURRENT_USER, international_keyW, &hkey);
288 if(res != ERROR_SUCCESS)
291 size = sizeof(langs);
292 res = RegQueryValueExA(hkey, "AcceptLanguage", 0, &type, (LPBYTE)langs, &size);
294 if(res != ERROR_SUCCESS || type != REG_SZ)
297 TRACE("Setting lang %s\n", debugstr_a(langs));
299 nsres = nsIPrefBranch_SetCharPref(pref, "intl.accept_languages", langs);
301 ERR("SetCharPref failed: %08x\n", nsres);
304 static void set_bool_pref(nsIPrefBranch *pref, const char *pref_name, BOOL val)
308 nsres = nsIPrefBranch_SetBoolPref(pref, pref_name, val);
310 ERR("Could not set pref %s\n", debugstr_a(pref_name));
313 static void set_profile(void)
317 PRBool exists = FALSE;
320 static const WCHAR wszMSHTML[] = {'M','S','H','T','M','L',0};
322 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PROFILE_CONTRACTID,
323 &IID_nsIProfile, (void**)&profile);
324 if(NS_FAILED(nsres)) {
325 ERR("Could not get profile service: %08x\n", nsres);
329 nsres = nsIProfile_ProfileExists(profile, wszMSHTML, &exists);
331 nsres = nsIProfile_CreateNewProfile(profile, wszMSHTML, NULL, NULL, FALSE);
333 ERR("CreateNewProfile failed: %08x\n", nsres);
336 nsres = nsIProfile_SetCurrentProfile(profile, wszMSHTML);
338 ERR("SetCurrentProfile failed: %08x\n", nsres);
340 nsIProfile_Release(profile);
342 nsres = nsIServiceManager_GetServiceByContractID(pServMgr, NS_PREFERENCES_CONTRACTID,
343 &IID_nsIPrefBranch, (void**)&pref);
344 if(NS_FAILED(nsres)) {
345 ERR("Could not get preference service: %08x\n", nsres);
350 set_bool_pref(pref, "security.warn_entering_secure", FALSE);
351 set_bool_pref(pref, "security.warn_submit_insecure", FALSE);
353 nsIPrefBranch_Release(pref);
356 static BOOL init_xpcom(const PRUnichar *gre_path)
359 nsIObserver *pStartNotif;
360 nsIComponentRegistrar *registrar = NULL;
364 nsAString_Init(&path, gre_path);
365 nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
366 nsAString_Finish(&path);
367 if(NS_FAILED(nsres)) {
368 ERR("NS_NewLocalFile failed: %08x\n", nsres);
373 nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
374 if(NS_FAILED(nsres)) {
375 ERR("NS_InitXPCOM2 failed: %08x\n", nsres);
380 nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
382 ERR("Could not get nsIComponentManager: %08x\n", nsres);
384 nsres = NS_GetComponentRegistrar(®istrar);
385 if(NS_SUCCEEDED(nsres)) {
386 nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
388 ERR("AutoRegister(NULL) failed: %08x\n", nsres);
390 nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
392 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres);
394 init_nsio(pCompMgr, registrar);
396 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres);
399 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
400 NULL, &IID_nsIObserver, (void**)&pStartNotif);
401 if(NS_SUCCEEDED(nsres)) {
402 nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
404 ERR("Observe failed: %08x\n", nsres);
406 nsIObserver_Release(pStartNotif);
408 ERR("could not get appstartup-notifier: %08x\n", nsres);
413 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
414 NULL, &IID_nsIMemory, (void**)&nsmem);
416 ERR("Could not get nsIMemory: %08x\n", nsres);
419 register_nsservice(registrar, pServMgr);
420 nsIComponentRegistrar_Release(registrar);
426 static CRITICAL_SECTION cs_load_gecko;
427 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
429 0, 0, &cs_load_gecko,
430 { &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
431 0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
433 static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
435 BOOL load_gecko(BOOL silent)
437 PRUnichar gre_path[MAX_PATH];
440 static LONG loading_thread;
444 /* load_gecko may be called recursively */
445 if(loading_thread == GetCurrentThreadId())
446 return pCompMgr != NULL;
448 EnterCriticalSection(&cs_load_gecko);
450 if(!loading_thread) {
451 loading_thread = GetCurrentThreadId();
453 if(load_wine_gecko(gre_path)
454 || (install_wine_gecko(silent) && load_wine_gecko(gre_path)))
455 ret = init_xpcom(gre_path);
457 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
459 ret = pCompMgr != NULL;
462 LeaveCriticalSection(&cs_load_gecko);
467 void *nsalloc(size_t size)
469 return nsIMemory_Alloc(nsmem, size);
472 void nsfree(void *mem)
474 nsIMemory_Free(nsmem, mem);
477 void nsACString_Init(nsACString *str, const char *data)
479 NS_CStringContainerInit(str);
481 nsACString_SetData(str, data);
484 void nsACString_SetData(nsACString *str, const char *data)
486 NS_CStringSetData(str, data, PR_UINT32_MAX);
489 PRUint32 nsACString_GetData(const nsACString *str, const char **data)
491 return NS_CStringGetData(str, data, NULL);
494 void nsACString_Finish(nsACString *str)
496 NS_CStringContainerFinish(str);
499 void nsAString_Init(nsAString *str, const PRUnichar *data)
501 NS_StringContainerInit(str);
503 nsAString_SetData(str, data);
506 void nsAString_SetData(nsAString *str, const PRUnichar *data)
508 NS_StringSetData(str, data, PR_UINT32_MAX);
511 PRUint32 nsAString_GetData(const nsAString *str, const PRUnichar **data)
513 return NS_StringGetData(str, data, NULL);
516 void nsAString_Finish(nsAString *str)
518 NS_StringContainerFinish(str);
521 nsIInputStream *create_nsstream(const char *data, PRInt32 data_len)
523 nsIStringInputStream *ret;
529 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
530 NS_STRINGSTREAM_CONTRACTID, NULL, &IID_nsIStringInputStream,
532 if(NS_FAILED(nsres)) {
533 ERR("Could not get nsIStringInputStream\n");
537 nsres = nsIStringInputStream_SetData(ret, data, data_len);
538 if(NS_FAILED(nsres)) {
539 ERR("AdoptData failed: %08x\n", nsres);
540 nsIStringInputStream_Release(ret);
544 return (nsIInputStream*)ret;
547 nsIMutableArray *create_nsarray(void)
549 nsIMutableArray *ret;
555 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
556 NS_ARRAY_CONTRACTID, NULL, &IID_nsIMutableArray,
558 if(NS_FAILED(nsres)) {
559 ERR("Could not get nsIArray: %08x\n", nsres);
566 nsIWritableVariant *create_nsvariant(void)
568 nsIWritableVariant *ret;
574 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
575 NS_VARIANT_CONTRACTID, NULL, &IID_nsIWritableVariant,
577 if(NS_FAILED(nsres)) {
578 ERR("Could not get nsIWritableVariant: %08x\n", nsres);
585 nsICommandParams *create_nscommand_params(void)
587 nsICommandParams *ret = NULL;
593 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
594 NS_COMMANDPARAMS_CONTRACTID, NULL, &IID_nsICommandParams,
597 ERR("Could not get nsICommandParams\n");
602 nsresult get_nsinterface(nsISupports *iface, REFIID riid, void **ppv)
604 nsIInterfaceRequestor *iface_req;
607 nsres = nsISupports_QueryInterface(iface, &IID_nsIInterfaceRequestor, (void**)&iface_req);
611 nsres = nsIInterfaceRequestor_GetInterface(iface_req, riid, ppv);
612 nsIInterfaceRequestor_Release(iface_req);
617 static void nsnode_to_nsstring_rec(nsIContentSerializer *serializer, nsIDOMNode *nsnode, nsAString *str)
619 nsIDOMNodeList *node_list = NULL;
620 PRBool has_children = FALSE;
624 nsIDOMNode_HasChildNodes(nsnode, &has_children);
626 nsres = nsIDOMNode_GetNodeType(nsnode, &type);
627 if(NS_FAILED(nsres)) {
628 ERR("GetType failed: %08x\n", nsres);
634 nsIDOMElement *nselem;
635 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
636 nsIContentSerializer_AppendElementStart(serializer, nselem, has_children, str);
637 nsIDOMElement_Release(nselem);
642 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&nstext);
643 nsIContentSerializer_AppendText(serializer, nstext, 0, -1, str);
644 nsIDOMText_Release(nstext);
648 nsIDOMComment *nscomment;
649 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMComment, (void**)&nscomment);
650 nsres = nsIContentSerializer_AppendComment(serializer, nscomment, 0, -1, str);
653 case DOCUMENT_NODE: {
654 nsIDOMDocument *nsdoc;
655 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMDocument, (void**)&nsdoc);
656 nsIContentSerializer_AppendDocumentStart(serializer, nsdoc, str);
657 nsIDOMDocument_Release(nsdoc);
660 case DOCUMENT_FRAGMENT_NODE:
663 FIXME("Unhandled type %u\n", type);
667 PRUint32 child_cnt, i;
668 nsIDOMNode *child_node;
670 nsIDOMNode_GetChildNodes(nsnode, &node_list);
671 nsIDOMNodeList_GetLength(node_list, &child_cnt);
673 for(i=0; i<child_cnt; i++) {
674 nsres = nsIDOMNodeList_Item(node_list, i, &child_node);
675 if(NS_SUCCEEDED(nsres)) {
676 nsnode_to_nsstring_rec(serializer, child_node, str);
677 nsIDOMNode_Release(child_node);
679 ERR("Item failed: %08x\n", nsres);
683 nsIDOMNodeList_Release(node_list);
686 if(type == ELEMENT_NODE) {
687 nsIDOMElement *nselem;
688 nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
689 nsIContentSerializer_AppendElementEnd(serializer, nselem, str);
690 nsIDOMElement_Release(nselem);
694 void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
696 nsIContentSerializer *serializer;
700 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
701 NS_HTMLSERIALIZER_CONTRACTID, NULL, &IID_nsIContentSerializer,
702 (void**)&serializer);
703 if(NS_FAILED(nsres)) {
704 ERR("Could not get nsIContentSerializer: %08x\n", nsres);
708 nsres = nsIContentSerializer_Init(serializer, 0, 100, NULL, FALSE);
710 ERR("Init failed: %08x\n", nsres);
712 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
713 nsnode_to_nsstring_rec(serializer, nsnode, str);
714 nsIDOMNode_Release(nsnode);
716 nsres = nsIContentSerializer_Flush(serializer, str);
718 ERR("Flush failed: %08x\n", nsres);
720 nsIContentSerializer_Release(serializer);
723 void get_editor_controller(NSContainer *This)
725 nsIEditingSession *editing_session = NULL;
726 nsIControllerContext *ctrlctx;
730 nsIEditor_Release(This->editor);
734 if(This->editor_controller) {
735 nsIController_Release(This->editor_controller);
736 This->editor_controller = NULL;
739 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
740 (void**)&editing_session);
741 if(NS_FAILED(nsres)) {
742 ERR("Could not get nsIEditingSession: %08x\n", nsres);
746 nsres = nsIEditingSession_GetEditorForWindow(editing_session,
747 This->doc->window->nswindow, &This->editor);
748 nsIEditingSession_Release(editing_session);
749 if(NS_FAILED(nsres)) {
750 ERR("Could not get editor: %08x\n", nsres);
754 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
755 NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
756 if(NS_SUCCEEDED(nsres)) {
757 nsres = nsIControllerContext_SetCommandContext(ctrlctx, (nsISupports *)This->editor);
759 ERR("SetCommandContext failed: %08x\n", nsres);
760 nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
761 (void**)&This->editor_controller);
762 nsIControllerContext_Release(ctrlctx);
764 ERR("Could not get nsIController interface: %08x\n", nsres);
766 ERR("Could not create edit controller: %08x\n", nsres);
770 void set_ns_editmode(NSContainer *This)
772 nsIEditingSession *editing_session = NULL;
773 nsIURIContentListener *listener = NULL;
774 nsIDOMWindow *dom_window = NULL;
777 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsIEditingSession,
778 (void**)&editing_session);
779 if(NS_FAILED(nsres)) {
780 ERR("Could not get nsIEditingSession: %08x\n", nsres);
784 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
785 if(NS_FAILED(nsres)) {
786 ERR("Could not get content DOM window: %08x\n", nsres);
787 nsIEditingSession_Release(editing_session);
791 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
792 nsIEditingSession_Release(editing_session);
793 nsIDOMWindow_Release(dom_window);
794 if(NS_FAILED(nsres)) {
795 ERR("MakeWindowEditable failed: %08x\n", nsres);
799 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
800 * It seams to be a bug in Gecko. To workaround it we set our content
801 * listener again and Gecko's one as its parent.
803 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
804 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
805 nsIURIContentListener_Release(listener);
806 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
809 void close_gecko(void)
814 nsIComponentManager_Release(pCompMgr);
817 nsIServiceManager_Release(pServMgr);
820 nsIMemory_Release(nsmem);
826 /**********************************************************
827 * nsIWebBrowserChrome interface
830 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
832 static nsresult NSAPI nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome *iface,
833 nsIIDRef riid, nsQIResult result)
835 NSContainer *This = NSWBCHROME_THIS(iface);
838 if(IsEqualGUID(&IID_nsISupports, riid)) {
839 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
840 *result = NSWBCHROME(This);
841 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome, riid)) {
842 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This, result);
843 *result = NSWBCHROME(This);
844 }else if(IsEqualGUID(&IID_nsIContextMenuListener, riid)) {
845 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This, result);
846 *result = NSCML(This);
847 }else if(IsEqualGUID(&IID_nsIURIContentListener, riid)) {
848 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This, result);
849 *result = NSURICL(This);
850 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow, riid)) {
851 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This, result);
852 *result = NSEMBWNDS(This);
853 }else if(IsEqualGUID(&IID_nsITooltipListener, riid)) {
854 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This, result);
855 *result = NSTOOLTIP(This);
856 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor, riid)) {
857 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This, result);
858 *result = NSIFACEREQ(This);
859 }else if(IsEqualGUID(&IID_nsIWeakReference, riid)) {
860 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This, result);
861 *result = NSWEAKREF(This);
862 }else if(IsEqualGUID(&IID_nsISupportsWeakReference, riid)) {
863 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This, result);
864 *result = NSSUPWEAKREF(This);
868 nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
872 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
873 return NS_NOINTERFACE;
876 static nsrefcnt NSAPI nsWebBrowserChrome_AddRef(nsIWebBrowserChrome *iface)
878 NSContainer *This = NSWBCHROME_THIS(iface);
879 LONG ref = InterlockedIncrement(&This->ref);
881 TRACE("(%p) ref=%d\n", This, ref);
886 static nsrefcnt NSAPI nsWebBrowserChrome_Release(nsIWebBrowserChrome *iface)
888 NSContainer *This = NSWBCHROME_THIS(iface);
889 LONG ref = InterlockedDecrement(&This->ref);
891 TRACE("(%p) ref=%d\n", This, ref);
895 nsIWebBrowserChrome_Release(NSWBCHROME(This->parent));
902 static nsresult NSAPI nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome *iface,
903 PRUint32 statusType, const PRUnichar *status)
905 NSContainer *This = NSWBCHROME_THIS(iface);
906 TRACE("(%p)->(%d %s)\n", This, statusType, debugstr_w(status));
907 return NS_ERROR_NOT_IMPLEMENTED;
910 static nsresult NSAPI nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome *iface,
911 nsIWebBrowser **aWebBrowser)
913 NSContainer *This = NSWBCHROME_THIS(iface);
915 TRACE("(%p)->(%p)\n", This, aWebBrowser);
918 return NS_ERROR_INVALID_ARG;
921 nsIWebBrowser_AddRef(This->webbrowser);
922 *aWebBrowser = This->webbrowser;
926 static nsresult NSAPI nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome *iface,
927 nsIWebBrowser *aWebBrowser)
929 NSContainer *This = NSWBCHROME_THIS(iface);
931 TRACE("(%p)->(%p)\n", This, aWebBrowser);
933 if(aWebBrowser != This->webbrowser)
934 ERR("Wrong nsWebBrowser!\n");
939 static nsresult NSAPI nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome *iface,
940 PRUint32 *aChromeFlags)
942 NSContainer *This = NSWBCHROME_THIS(iface);
943 WARN("(%p)->(%p)\n", This, aChromeFlags);
944 return NS_ERROR_NOT_IMPLEMENTED;
947 static nsresult NSAPI nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome *iface,
948 PRUint32 aChromeFlags)
950 NSContainer *This = NSWBCHROME_THIS(iface);
951 WARN("(%p)->(%08x)\n", This, aChromeFlags);
952 return NS_ERROR_NOT_IMPLEMENTED;
955 static nsresult NSAPI nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome *iface)
957 NSContainer *This = NSWBCHROME_THIS(iface);
958 TRACE("(%p)\n", This);
959 return NS_ERROR_NOT_IMPLEMENTED;
962 static nsresult NSAPI nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome *iface,
963 PRInt32 aCX, PRInt32 aCY)
965 NSContainer *This = NSWBCHROME_THIS(iface);
966 WARN("(%p)->(%d %d)\n", This, aCX, aCY);
967 return NS_ERROR_NOT_IMPLEMENTED;
970 static nsresult NSAPI nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome *iface)
972 NSContainer *This = NSWBCHROME_THIS(iface);
973 WARN("(%p)\n", This);
974 return NS_ERROR_NOT_IMPLEMENTED;
977 static nsresult NSAPI nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome *iface, PRBool *_retval)
979 NSContainer *This = NSWBCHROME_THIS(iface);
980 WARN("(%p)->(%p)\n", This, _retval);
981 return NS_ERROR_NOT_IMPLEMENTED;
984 static nsresult NSAPI nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome *iface,
987 NSContainer *This = NSWBCHROME_THIS(iface);
988 WARN("(%p)->(%08x)\n", This, aStatus);
989 return NS_ERROR_NOT_IMPLEMENTED;
992 #undef NSWBCHROME_THIS
994 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl = {
995 nsWebBrowserChrome_QueryInterface,
996 nsWebBrowserChrome_AddRef,
997 nsWebBrowserChrome_Release,
998 nsWebBrowserChrome_SetStatus,
999 nsWebBrowserChrome_GetWebBrowser,
1000 nsWebBrowserChrome_SetWebBrowser,
1001 nsWebBrowserChrome_GetChromeFlags,
1002 nsWebBrowserChrome_SetChromeFlags,
1003 nsWebBrowserChrome_DestroyBrowserWindow,
1004 nsWebBrowserChrome_SizeBrowserTo,
1005 nsWebBrowserChrome_ShowAsModal,
1006 nsWebBrowserChrome_IsWindowModal,
1007 nsWebBrowserChrome_ExitModalEventLoop
1010 /**********************************************************
1011 * nsIContextMenuListener interface
1014 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1016 static nsresult NSAPI nsContextMenuListener_QueryInterface(nsIContextMenuListener *iface,
1017 nsIIDRef riid, nsQIResult result)
1019 NSContainer *This = NSCML_THIS(iface);
1020 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1023 static nsrefcnt NSAPI nsContextMenuListener_AddRef(nsIContextMenuListener *iface)
1025 NSContainer *This = NSCML_THIS(iface);
1026 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1029 static nsrefcnt NSAPI nsContextMenuListener_Release(nsIContextMenuListener *iface)
1031 NSContainer *This = NSCML_THIS(iface);
1032 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1035 static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener *iface,
1036 PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
1038 NSContainer *This = NSCML_THIS(iface);
1039 nsIDOMMouseEvent *event;
1041 DWORD dwID = CONTEXT_MENU_DEFAULT;
1044 TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
1046 nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
1047 if(NS_FAILED(nsres)) {
1048 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
1052 nsIDOMMouseEvent_GetScreenX(event, &pt.x);
1053 nsIDOMMouseEvent_GetScreenY(event, &pt.y);
1054 nsIDOMMouseEvent_Release(event);
1056 switch(aContextFlags) {
1058 case CONTEXT_DOCUMENT:
1060 dwID = CONTEXT_MENU_DEFAULT;
1063 case CONTEXT_IMAGE|CONTEXT_LINK:
1064 dwID = CONTEXT_MENU_IMAGE;
1067 dwID = CONTEXT_MENU_ANCHOR;
1070 dwID = CONTEXT_MENU_CONTROL;
1073 FIXME("aContextFlags=%08x\n", aContextFlags);
1076 show_context_menu(This->doc, dwID, &pt, (IDispatch*)HTMLDOMNODE(get_node(This->doc, aNode)));
1083 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl = {
1084 nsContextMenuListener_QueryInterface,
1085 nsContextMenuListener_AddRef,
1086 nsContextMenuListener_Release,
1087 nsContextMenuListener_OnShowContextMenu
1090 /**********************************************************
1091 * nsIURIContentListener interface
1094 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1096 static nsresult NSAPI nsURIContentListener_QueryInterface(nsIURIContentListener *iface,
1097 nsIIDRef riid, nsQIResult result)
1099 NSContainer *This = NSURICL_THIS(iface);
1100 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1103 static nsrefcnt NSAPI nsURIContentListener_AddRef(nsIURIContentListener *iface)
1105 NSContainer *This = NSURICL_THIS(iface);
1106 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1109 static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
1111 NSContainer *This = NSURICL_THIS(iface);
1112 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1115 static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
1116 nsIURI *aURI, PRBool *_retval)
1118 NSContainer *This = NSURICL_THIS(iface);
1119 nsIWineURI *wine_uri;
1120 nsACString spec_str;
1124 nsACString_Init(&spec_str, NULL);
1125 nsIURI_GetSpec(aURI, &spec_str);
1126 nsACString_GetData(&spec_str, &spec);
1128 TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
1130 nsACString_Finish(&spec_str);
1132 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1133 if(NS_FAILED(nsres)) {
1134 WARN("Could not get nsIWineURI interface: %08x\n", nsres);
1135 return NS_ERROR_NOT_IMPLEMENTED;
1138 nsIWineURI_SetNSContainer(wine_uri, This);
1139 nsIWineURI_SetIsDocumentURI(wine_uri, TRUE);
1141 if(This->bscallback && This->bscallback->mon) {
1145 hres = IMoniker_GetDisplayName(This->bscallback->mon, NULL, 0, &wine_url);
1146 if(SUCCEEDED(hres)) {
1147 nsIWineURI_SetWineURL(wine_uri, wine_url);
1148 CoTaskMemFree(wine_url);
1150 WARN("GetDisplayName failed: %08x\n", hres);
1154 nsIWineURI_Release(wine_uri);
1157 return This->content_listener
1158 ? nsIURIContentListener_OnStartURIOpen(This->content_listener, aURI, _retval)
1162 static nsresult NSAPI nsURIContentListener_DoContent(nsIURIContentListener *iface,
1163 const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest,
1164 nsIStreamListener **aContentHandler, PRBool *_retval)
1166 NSContainer *This = NSURICL_THIS(iface);
1168 TRACE("(%p)->(%s %x %p %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1169 aRequest, aContentHandler, _retval);
1171 return This->content_listener
1172 ? nsIURIContentListener_DoContent(This->content_listener, aContentType,
1173 aIsContentPreferred, aRequest, aContentHandler, _retval)
1174 : NS_ERROR_NOT_IMPLEMENTED;
1177 static nsresult NSAPI nsURIContentListener_IsPreferred(nsIURIContentListener *iface,
1178 const char *aContentType, char **aDesiredContentType, PRBool *_retval)
1180 NSContainer *This = NSURICL_THIS(iface);
1182 TRACE("(%p)->(%s %p %p)\n", This, debugstr_a(aContentType), aDesiredContentType, _retval);
1184 /* FIXME: Should we do something here? */
1187 return This->content_listener
1188 ? nsIURIContentListener_IsPreferred(This->content_listener, aContentType,
1189 aDesiredContentType, _retval)
1193 static nsresult NSAPI nsURIContentListener_CanHandleContent(nsIURIContentListener *iface,
1194 const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType,
1197 NSContainer *This = NSURICL_THIS(iface);
1199 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_a(aContentType), aIsContentPreferred,
1200 aDesiredContentType, _retval);
1202 return This->content_listener
1203 ? nsIURIContentListener_CanHandleContent(This->content_listener, aContentType,
1204 aIsContentPreferred, aDesiredContentType, _retval)
1205 : NS_ERROR_NOT_IMPLEMENTED;
1208 static nsresult NSAPI nsURIContentListener_GetLoadCookie(nsIURIContentListener *iface,
1209 nsISupports **aLoadCookie)
1211 NSContainer *This = NSURICL_THIS(iface);
1213 WARN("(%p)->(%p)\n", This, aLoadCookie);
1215 return This->content_listener
1216 ? nsIURIContentListener_GetLoadCookie(This->content_listener, aLoadCookie)
1217 : NS_ERROR_NOT_IMPLEMENTED;
1220 static nsresult NSAPI nsURIContentListener_SetLoadCookie(nsIURIContentListener *iface,
1221 nsISupports *aLoadCookie)
1223 NSContainer *This = NSURICL_THIS(iface);
1225 WARN("(%p)->(%p)\n", This, aLoadCookie);
1227 return This->content_listener
1228 ? nsIURIContentListener_SetLoadCookie(This->content_listener, aLoadCookie)
1229 : NS_ERROR_NOT_IMPLEMENTED;
1232 static nsresult NSAPI nsURIContentListener_GetParentContentListener(nsIURIContentListener *iface,
1233 nsIURIContentListener **aParentContentListener)
1235 NSContainer *This = NSURICL_THIS(iface);
1237 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1239 if(This->content_listener)
1240 nsIURIContentListener_AddRef(This->content_listener);
1242 *aParentContentListener = This->content_listener;
1246 static nsresult NSAPI nsURIContentListener_SetParentContentListener(nsIURIContentListener *iface,
1247 nsIURIContentListener *aParentContentListener)
1249 NSContainer *This = NSURICL_THIS(iface);
1251 TRACE("(%p)->(%p)\n", This, aParentContentListener);
1253 if(aParentContentListener == NSURICL(This))
1256 if(This->content_listener)
1257 nsIURIContentListener_Release(This->content_listener);
1259 This->content_listener = aParentContentListener;
1260 if(This->content_listener)
1261 nsIURIContentListener_AddRef(This->content_listener);
1268 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl = {
1269 nsURIContentListener_QueryInterface,
1270 nsURIContentListener_AddRef,
1271 nsURIContentListener_Release,
1272 nsURIContentListener_OnStartURIOpen,
1273 nsURIContentListener_DoContent,
1274 nsURIContentListener_IsPreferred,
1275 nsURIContentListener_CanHandleContent,
1276 nsURIContentListener_GetLoadCookie,
1277 nsURIContentListener_SetLoadCookie,
1278 nsURIContentListener_GetParentContentListener,
1279 nsURIContentListener_SetParentContentListener
1282 /**********************************************************
1283 * nsIEmbeddinSiteWindow interface
1286 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1288 static nsresult NSAPI nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow *iface,
1289 nsIIDRef riid, nsQIResult result)
1291 NSContainer *This = NSEMBWNDS_THIS(iface);
1292 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1295 static nsrefcnt NSAPI nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow *iface)
1297 NSContainer *This = NSEMBWNDS_THIS(iface);
1298 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1301 static nsrefcnt NSAPI nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow *iface)
1303 NSContainer *This = NSEMBWNDS_THIS(iface);
1304 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1307 static nsresult NSAPI nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow *iface,
1308 PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
1310 NSContainer *This = NSEMBWNDS_THIS(iface);
1311 WARN("(%p)->(%08x %d %d %d %d)\n", This, flags, x, y, cx, cy);
1312 return NS_ERROR_NOT_IMPLEMENTED;
1315 static nsresult NSAPI nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow *iface,
1316 PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
1318 NSContainer *This = NSEMBWNDS_THIS(iface);
1319 WARN("(%p)->(%08x %p %p %p %p)\n", This, flags, x, y, cx, cy);
1320 return NS_ERROR_NOT_IMPLEMENTED;
1323 static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *iface)
1325 NSContainer *This = NSEMBWNDS_THIS(iface);
1327 TRACE("(%p)\n", This);
1329 if(This->reset_focus)
1330 PostMessageW(This->hwnd, WM_RESETFOCUS_HACK, 0, 0);
1332 return nsIBaseWindow_SetFocus(This->window);
1335 static nsresult NSAPI nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow *iface,
1336 PRBool *aVisibility)
1338 NSContainer *This = NSEMBWNDS_THIS(iface);
1340 TRACE("(%p)->(%p)\n", This, aVisibility);
1342 *aVisibility = This->doc && This->doc->hwnd && IsWindowVisible(This->doc->hwnd);
1346 static nsresult NSAPI nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow *iface,
1349 NSContainer *This = NSEMBWNDS_THIS(iface);
1351 TRACE("(%p)->(%x)\n", This, aVisibility);
1356 static nsresult NSAPI nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow *iface,
1359 NSContainer *This = NSEMBWNDS_THIS(iface);
1360 WARN("(%p)->(%p)\n", This, aTitle);
1361 return NS_ERROR_NOT_IMPLEMENTED;
1364 static nsresult NSAPI nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow *iface,
1365 const PRUnichar *aTitle)
1367 NSContainer *This = NSEMBWNDS_THIS(iface);
1368 WARN("(%p)->(%s)\n", This, debugstr_w(aTitle));
1369 return NS_ERROR_NOT_IMPLEMENTED;
1372 static nsresult NSAPI nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow *iface,
1375 NSContainer *This = NSEMBWNDS_THIS(iface);
1377 TRACE("(%p)->(%p)\n", This, aSiteWindow);
1379 *aSiteWindow = This->hwnd;
1383 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl = {
1384 nsEmbeddingSiteWindow_QueryInterface,
1385 nsEmbeddingSiteWindow_AddRef,
1386 nsEmbeddingSiteWindow_Release,
1387 nsEmbeddingSiteWindow_SetDimensions,
1388 nsEmbeddingSiteWindow_GetDimensions,
1389 nsEmbeddingSiteWindow_SetFocus,
1390 nsEmbeddingSiteWindow_GetVisibility,
1391 nsEmbeddingSiteWindow_SetVisibility,
1392 nsEmbeddingSiteWindow_GetTitle,
1393 nsEmbeddingSiteWindow_SetTitle,
1394 nsEmbeddingSiteWindow_GetSiteWindow
1397 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1399 static nsresult NSAPI nsTooltipListener_QueryInterface(nsITooltipListener *iface, nsIIDRef riid,
1402 NSContainer *This = NSTOOLTIP_THIS(iface);
1403 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1406 static nsrefcnt NSAPI nsTooltipListener_AddRef(nsITooltipListener *iface)
1408 NSContainer *This = NSTOOLTIP_THIS(iface);
1409 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1412 static nsrefcnt NSAPI nsTooltipListener_Release(nsITooltipListener *iface)
1414 NSContainer *This = NSTOOLTIP_THIS(iface);
1415 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1418 static nsresult NSAPI nsTooltipListener_OnShowTooltip(nsITooltipListener *iface,
1419 PRInt32 aXCoord, PRInt32 aYCoord, const PRUnichar *aTipText)
1421 NSContainer *This = NSTOOLTIP_THIS(iface);
1423 show_tooltip(This->doc, aXCoord, aYCoord, aTipText);
1428 static nsresult NSAPI nsTooltipListener_OnHideTooltip(nsITooltipListener *iface)
1430 NSContainer *This = NSTOOLTIP_THIS(iface);
1432 hide_tooltip(This->doc);
1437 #undef NSTOOLTIM_THIS
1439 static const nsITooltipListenerVtbl nsTooltipListenerVtbl = {
1440 nsTooltipListener_QueryInterface,
1441 nsTooltipListener_AddRef,
1442 nsTooltipListener_Release,
1443 nsTooltipListener_OnShowTooltip,
1444 nsTooltipListener_OnHideTooltip
1447 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1449 static nsresult NSAPI nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor *iface,
1450 nsIIDRef riid, nsQIResult result)
1452 NSContainer *This = NSIFACEREQ_THIS(iface);
1453 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1456 static nsrefcnt NSAPI nsInterfaceRequestor_AddRef(nsIInterfaceRequestor *iface)
1458 NSContainer *This = NSIFACEREQ_THIS(iface);
1459 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1462 static nsrefcnt NSAPI nsInterfaceRequestor_Release(nsIInterfaceRequestor *iface)
1464 NSContainer *This = NSIFACEREQ_THIS(iface);
1465 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1468 static nsresult NSAPI nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor *iface,
1469 nsIIDRef riid, nsQIResult result)
1471 NSContainer *This = NSIFACEREQ_THIS(iface);
1473 if(IsEqualGUID(&IID_nsIDOMWindow, riid)) {
1474 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This, result);
1475 return nsIWebBrowser_GetContentDOMWindow(This->webbrowser, (nsIDOMWindow**)result);
1478 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1481 #undef NSIFACEREQ_THIS
1483 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl = {
1484 nsInterfaceRequestor_QueryInterface,
1485 nsInterfaceRequestor_AddRef,
1486 nsInterfaceRequestor_Release,
1487 nsInterfaceRequestor_GetInterface
1490 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1492 static nsresult NSAPI nsWeakReference_QueryInterface(nsIWeakReference *iface,
1493 nsIIDRef riid, nsQIResult result)
1495 NSContainer *This = NSWEAKREF_THIS(iface);
1496 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1499 static nsrefcnt NSAPI nsWeakReference_AddRef(nsIWeakReference *iface)
1501 NSContainer *This = NSWEAKREF_THIS(iface);
1502 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1505 static nsrefcnt NSAPI nsWeakReference_Release(nsIWeakReference *iface)
1507 NSContainer *This = NSWEAKREF_THIS(iface);
1508 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1511 static nsresult NSAPI nsWeakReference_QueryReferent(nsIWeakReference *iface,
1512 const nsIID *riid, void **result)
1514 NSContainer *This = NSWEAKREF_THIS(iface);
1515 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1518 #undef NSWEAKREF_THIS
1520 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl = {
1521 nsWeakReference_QueryInterface,
1522 nsWeakReference_AddRef,
1523 nsWeakReference_Release,
1524 nsWeakReference_QueryReferent
1527 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1529 static nsresult NSAPI nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference *iface,
1530 nsIIDRef riid, nsQIResult result)
1532 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1533 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This), riid, result);
1536 static nsrefcnt NSAPI nsSupportsWeakReference_AddRef(nsISupportsWeakReference *iface)
1538 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1539 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
1542 static nsrefcnt NSAPI nsSupportsWeakReference_Release(nsISupportsWeakReference *iface)
1544 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1545 return nsIWebBrowserChrome_Release(NSWBCHROME(This));
1548 static nsresult NSAPI nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference *iface,
1549 nsIWeakReference **_retval)
1551 NSContainer *This = NSSUPWEAKREF_THIS(iface);
1553 TRACE("(%p)->(%p)\n", This, _retval);
1555 nsIWeakReference_AddRef(NSWEAKREF(This));
1556 *_retval = NSWEAKREF(This);
1560 #undef NSWEAKREF_THIS
1562 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
1563 nsSupportsWeakReference_QueryInterface,
1564 nsSupportsWeakReference_AddRef,
1565 nsSupportsWeakReference_Release,
1566 nsSupportsWeakReference_GetWeakReference
1570 NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
1572 nsIWebBrowserSetup *wbsetup;
1573 nsIScrollable *scrollable;
1577 if(!load_gecko(FALSE))
1580 ret = heap_alloc(sizeof(NSContainer));
1582 ret->lpWebBrowserChromeVtbl = &nsWebBrowserChromeVtbl;
1583 ret->lpContextMenuListenerVtbl = &nsContextMenuListenerVtbl;
1584 ret->lpURIContentListenerVtbl = &nsURIContentListenerVtbl;
1585 ret->lpEmbeddingSiteWindowVtbl = &nsEmbeddingSiteWindowVtbl;
1586 ret->lpTooltipListenerVtbl = &nsTooltipListenerVtbl;
1587 ret->lpInterfaceRequestorVtbl = &nsInterfaceRequestorVtbl;
1588 ret->lpWeakReferenceVtbl = &nsWeakReferenceVtbl;
1589 ret->lpSupportsWeakReferenceVtbl = &nsSupportsWeakReferenceVtbl;
1593 ret->bscallback = NULL;
1594 ret->content_listener = NULL;
1595 ret->editor_controller = NULL;
1597 ret->reset_focus = NULL;
1600 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
1601 ret->parent = parent;
1603 nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
1604 NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
1605 if(NS_FAILED(nsres))
1606 ERR("Creating WebBrowser failed: %08x\n", nsres);
1608 nsres = nsIWebBrowser_SetContainerWindow(ret->webbrowser, NSWBCHROME(ret));
1609 if(NS_FAILED(nsres))
1610 ERR("SetContainerWindow failed: %08x\n", nsres);
1612 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
1613 (void**)&ret->window);
1614 if(NS_FAILED(nsres))
1615 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres);
1617 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserSetup,
1619 if(NS_SUCCEEDED(nsres)) {
1620 nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, FALSE);
1621 nsIWebBrowserSetup_Release(wbsetup);
1622 if(NS_FAILED(nsres))
1623 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres);
1625 ERR("Could not get nsIWebBrowserSetup interface\n");
1628 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
1629 (void**)&ret->navigation);
1630 if(NS_FAILED(nsres))
1631 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres);
1633 nsres = nsIWebBrowserFocus_QueryInterface(ret->webbrowser, &IID_nsIWebBrowserFocus,
1634 (void**)&ret->focus);
1635 if(NS_FAILED(nsres))
1636 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres);
1638 if(!nscontainer_class)
1639 register_nscontainer_class();
1641 ret->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
1642 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
1643 GetDesktopWindow(), NULL, hInst, ret);
1645 nsres = nsIBaseWindow_InitWindow(ret->window, ret->hwnd, NULL, 0, 0, 100, 100);
1646 if(NS_SUCCEEDED(nsres)) {
1647 nsres = nsIBaseWindow_Create(ret->window);
1648 if(NS_FAILED(nsres))
1649 WARN("Creating window failed: %08x\n", nsres);
1651 nsIBaseWindow_SetVisibility(ret->window, FALSE);
1652 nsIBaseWindow_SetEnabled(ret->window, FALSE);
1654 ERR("InitWindow failed: %08x\n", nsres);
1657 nsres = nsIWebBrowser_SetParentURIContentListener(ret->webbrowser, NSURICL(ret));
1658 if(NS_FAILED(nsres))
1659 ERR("SetParentURIContentListener failed: %08x\n", nsres);
1663 nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
1664 if(NS_SUCCEEDED(nsres)) {
1665 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1666 ScrollOrientation_Y, Scrollbar_Always);
1667 if(NS_FAILED(nsres))
1668 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
1670 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
1671 ScrollOrientation_X, Scrollbar_Auto);
1672 if(NS_FAILED(nsres))
1673 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
1675 nsIScrollable_Release(scrollable);
1677 ERR("Could not get nsIScrollable: %08x\n", nsres);
1683 void NSContainer_Release(NSContainer *This)
1685 TRACE("(%p)\n", This);
1687 ShowWindow(This->hwnd, SW_HIDE);
1688 SetParent(This->hwnd, NULL);
1690 nsIBaseWindow_SetVisibility(This->window, FALSE);
1691 nsIBaseWindow_Destroy(This->window);
1693 nsIWebBrowser_SetContainerWindow(This->webbrowser, NULL);
1695 nsIWebBrowser_Release(This->webbrowser);
1696 This->webbrowser = NULL;
1698 nsIWebNavigation_Release(This->navigation);
1699 This->navigation = NULL;
1701 nsIBaseWindow_Release(This->window);
1702 This->window = NULL;
1704 nsIWebBrowserFocus_Release(This->focus);
1707 if(This->editor_controller) {
1708 nsIController_Release(This->editor_controller);
1709 This->editor_controller = NULL;
1713 nsIEditor_Release(This->editor);
1714 This->editor = NULL;
1717 if(This->content_listener) {
1718 nsIURIContentListener_Release(This->content_listener);
1719 This->content_listener = NULL;
1723 DestroyWindow(This->hwnd);
1727 nsIWebBrowserChrome_Release(NSWBCHROME(This));