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
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 WINE_DECLARE_DEBUG_CHANNEL(gecko
);
42 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
43 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
44 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
45 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
46 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
47 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define PR_UINT32_MAX 0xffffffff
52 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
53 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
55 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
56 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
57 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
58 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
59 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
60 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
61 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
62 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
63 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
64 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
65 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
66 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
68 static HINSTANCE xul_handle
= NULL
;
70 static nsIServiceManager
*pServMgr
= NULL
;
71 static nsIComponentManager
*pCompMgr
= NULL
;
72 static nsIMemory
*nsmem
= NULL
;
73 static nsIFile
*profile_directory
;
75 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
77 static ATOM nscontainer_class
;
78 static WCHAR gecko_path
[MAX_PATH
];
79 static unsigned gecko_path_len
;
81 static nsresult NSAPI
nsDirectoryServiceProvider_QueryInterface(nsIDirectoryServiceProvider
*iface
,
82 nsIIDRef riid
, void **result
)
84 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
85 TRACE("(IID_nsISupports %p)\n", result
);
87 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
88 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
91 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
93 return NS_NOINTERFACE
;
96 nsISupports_AddRef((nsISupports
*)*result
);
100 static nsrefcnt NSAPI
nsDirectoryServiceProvider_AddRef(nsIDirectoryServiceProvider
*iface
)
105 static nsrefcnt NSAPI
nsDirectoryServiceProvider_Release(nsIDirectoryServiceProvider
*iface
)
110 static nsresult
create_profile_directory(void)
112 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
114 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
120 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_DEFAULT
, path
);
122 ERR("SHGetFolderPath failed: %08x\n", hres
);
123 return NS_ERROR_FAILURE
;
126 strcatW(path
, wine_geckoW
);
127 nsAString_InitDepend(&str
, path
);
128 nsres
= NS_NewLocalFile(&str
, FALSE
, &profile_directory
);
129 nsAString_Finish(&str
);
130 if(NS_FAILED(nsres
)) {
131 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
135 nsres
= nsIFile_Exists(profile_directory
, &exists
);
136 if(NS_FAILED(nsres
)) {
137 ERR("Exists failed: %08x\n", nsres
);
142 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
144 ERR("Create failed: %08x\n", nsres
);
150 static nsresult NSAPI
nsDirectoryServiceProvider_GetFile(nsIDirectoryServiceProvider
*iface
,
151 const char *prop
, PRBool
*persistent
, nsIFile
**_retval
)
153 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
155 if(!strcmp(prop
, "ProfD")) {
156 if(!profile_directory
) {
159 nsres
= create_profile_directory();
164 return nsIFile_Clone(profile_directory
, _retval
);
167 return NS_ERROR_FAILURE
;
170 static const nsIDirectoryServiceProviderVtbl nsDirectoryServiceProviderVtbl
= {
171 nsDirectoryServiceProvider_QueryInterface
,
172 nsDirectoryServiceProvider_AddRef
,
173 nsDirectoryServiceProvider_Release
,
174 nsDirectoryServiceProvider_GetFile
177 static nsIDirectoryServiceProvider nsDirectoryServiceProvider
=
178 { &nsDirectoryServiceProviderVtbl
};
180 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
185 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
187 if(msg
== WM_CREATE
) {
188 This
= *(NSContainer
**)lParam
;
189 SetPropW(hwnd
, wszTHIS
, This
);
191 This
= GetPropW(hwnd
, wszTHIS
);
196 TRACE("(%p)->(WM_SIZE)\n", This
);
198 nsres
= nsIBaseWindow_SetSize(This
->window
,
199 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
201 WARN("SetSize failed: %08x\n", nsres
);
204 case WM_PARENTNOTIFY
:
205 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
210 nsIWebBrowserFocus_Activate(This
->focus
);
214 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
218 static void register_nscontainer_class(void)
220 static WNDCLASSEXW wndclass
= {
224 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
228 wndclass
.hInstance
= hInst
;
229 nscontainer_class
= RegisterClassExW(&wndclass
);
232 static BOOL
install_wine_gecko(BOOL silent
)
234 PROCESS_INFORMATION pi
;
241 static const WCHAR controlW
[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
242 static const WCHAR argsW
[] =
243 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
245 len
= GetSystemDirectoryW(app
, MAX_PATH
-sizeof(controlW
)/sizeof(WCHAR
));
246 memcpy(app
+len
, controlW
, sizeof(controlW
));
248 args
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(controlW
) + sizeof(argsW
));
252 memcpy(args
, app
, len
*sizeof(WCHAR
) + sizeof(controlW
));
253 memcpy(args
+ len
+ sizeof(controlW
)/sizeof(WCHAR
)-1, argsW
, sizeof(argsW
));
255 TRACE("starting %s\n", debugstr_w(args
));
257 memset(&si
, 0, sizeof(si
));
259 ret
= CreateProcessW(app
, args
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
262 CloseHandle(pi
.hThread
);
263 WaitForSingleObject(pi
.hProcess
, INFINITE
);
264 CloseHandle(pi
.hProcess
);
270 static void set_environment(LPCWSTR gre_path
)
272 WCHAR path_env
[MAX_PATH
], buf
[20];
273 int len
, debug_level
= 0;
275 static const WCHAR pathW
[] = {'P','A','T','H',0};
276 static const WCHAR warnW
[] = {'w','a','r','n',0};
277 static const WCHAR xpcom_debug_breakW
[] =
278 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
279 static const WCHAR nspr_log_modulesW
[] =
280 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
281 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
282 static const WCHAR moz_plugin_pathW
[] = {'M','O','Z','_','P','L','U','G','I','N','_','P','A','T','H',0};
283 static const WCHAR gecko_pluginW
[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
285 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
286 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
287 len
= strlenW(path_env
);
288 path_env
[len
++] = ';';
289 strcpyW(path_env
+len
, gre_path
);
290 SetEnvironmentVariableW(pathW
, path_env
);
292 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
296 else if(WARN_ON(gecko
))
298 else if(ERR_ON(gecko
))
301 sprintfW(buf
, debug_formatW
, debug_level
);
302 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
304 len
= GetSystemDirectoryW(path_env
, (sizeof(path_env
)-sizeof(gecko_pluginW
))/sizeof(WCHAR
)+1);
306 strcpyW(path_env
+len
, gecko_pluginW
);
307 SetEnvironmentVariableW(moz_plugin_pathW
, path_env
);
311 static BOOL
load_xul(const PRUnichar
*gre_path
)
313 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
314 WCHAR file_name
[MAX_PATH
];
316 strcpyW(file_name
, gre_path
);
317 strcatW(file_name
, xul_dllW
);
319 TRACE("(%s)\n", debugstr_w(file_name
));
321 set_environment(gre_path
);
323 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
325 WARN("Could not load XUL: %d\n", GetLastError());
329 #define NS_DLSYM(func) \
330 func = (void *)GetProcAddress(xul_handle, #func "_P"); \
332 ERR("Could not GetProcAddress(" #func ") failed\n")
334 NS_DLSYM(NS_InitXPCOM2
);
335 NS_DLSYM(NS_ShutdownXPCOM
);
336 NS_DLSYM(NS_GetComponentRegistrar
);
337 NS_DLSYM(NS_StringContainerInit2
);
338 NS_DLSYM(NS_CStringContainerInit2
);
339 NS_DLSYM(NS_StringContainerFinish
);
340 NS_DLSYM(NS_CStringContainerFinish
);
341 NS_DLSYM(NS_StringSetData
);
342 NS_DLSYM(NS_CStringSetData
);
343 NS_DLSYM(NS_NewLocalFile
);
344 NS_DLSYM(NS_StringGetData
);
345 NS_DLSYM(NS_CStringGetData
);
352 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
354 WCHAR file_name
[MAX_PATH
];
359 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
361 strcpyW(file_name
, gre_path
);
362 strcatW(file_name
, wszVersion
);
364 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
365 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
366 if(hfile
== INVALID_HANDLE_VALUE
) {
367 ERR("Could not open VERSION file\n");
371 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
375 TRACE("%s\n", debugstr_a(version
));
377 if(strcmp(version
, version_string
)) {
378 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
379 debugstr_a(version_string
));
386 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
387 const char *version
, const char *version_string
)
389 DWORD res
, type
, size
= MAX_PATH
;
390 HKEY hkey
= mshtml_key
;
392 static const WCHAR wszGeckoPath
[] =
393 {'G','e','c','k','o','P','a','t','h',0};
396 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
397 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
398 if(res
!= ERROR_SUCCESS
)
402 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
403 if(hkey
!= mshtml_key
)
405 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
408 if(!check_version(gre_path
, version_string
))
411 return load_xul(gre_path
);
414 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
420 static const WCHAR wszMshtmlKey
[] = {
421 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
422 '\\','M','S','H','T','M','L',0};
424 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
425 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
426 if(res
!= ERROR_SUCCESS
)
429 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
435 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
439 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
441 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
444 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
448 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
450 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
453 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
457 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
459 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
462 static void set_lang(nsIPrefBranch
*pref
)
465 DWORD res
, size
, type
;
468 static const WCHAR international_keyW
[] =
469 {'S','o','f','t','w','a','r','e',
470 '\\','M','i','c','r','o','s','o','f','t',
471 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
472 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
474 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
475 if(res
!= ERROR_SUCCESS
)
478 size
= sizeof(langs
);
479 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
481 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
484 TRACE("Setting lang %s\n", debugstr_a(langs
));
486 set_string_pref(pref
, "intl.accept_languages", langs
);
489 static void set_preferences(void)
494 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
495 &IID_nsIPrefBranch
, (void**)&pref
);
496 if(NS_FAILED(nsres
)) {
497 ERR("Could not get preference service: %08x\n", nsres
);
502 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
503 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
504 set_int_pref(pref
, "layout.spellcheckDefault", 0);
506 nsIPrefBranch_Release(pref
);
509 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
511 nsIComponentRegistrar
*registrar
= NULL
;
517 nsAString_InitDepend(&path
, gre_path
);
518 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
519 nsAString_Finish(&path
);
520 if(NS_FAILED(nsres
)) {
521 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
522 FreeLibrary(xul_handle
);
526 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, &nsDirectoryServiceProvider
);
527 if(NS_FAILED(nsres
)) {
528 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
529 FreeLibrary(xul_handle
);
533 strcpyW(gecko_path
, gre_path
);
534 for(ptr
= gecko_path
; *ptr
; ptr
++) {
538 gecko_path_len
= ptr
-gecko_path
;
540 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
542 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
544 nsres
= NS_GetComponentRegistrar(®istrar
);
545 if(NS_SUCCEEDED(nsres
))
546 init_nsio(pCompMgr
, registrar
);
548 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
550 init_mutation(pCompMgr
);
553 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
554 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
556 ERR("Could not get nsIMemory: %08x\n", nsres
);
559 register_nsservice(registrar
, pServMgr
);
560 nsIComponentRegistrar_Release(registrar
);
566 static CRITICAL_SECTION cs_load_gecko
;
567 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
569 0, 0, &cs_load_gecko
,
570 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
571 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
573 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
575 BOOL
load_gecko(BOOL silent
)
577 PRUnichar gre_path
[MAX_PATH
];
580 static DWORD loading_thread
;
584 /* load_gecko may be called recursively */
585 if(loading_thread
== GetCurrentThreadId())
586 return pCompMgr
!= NULL
;
588 EnterCriticalSection(&cs_load_gecko
);
590 if(!loading_thread
) {
591 loading_thread
= GetCurrentThreadId();
593 if(load_wine_gecko(gre_path
)
594 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
595 ret
= init_xpcom(gre_path
);
597 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
599 ret
= pCompMgr
!= NULL
;
602 LeaveCriticalSection(&cs_load_gecko
);
607 void *nsalloc(size_t size
)
609 return nsIMemory_Alloc(nsmem
, size
);
612 void nsfree(void *mem
)
614 nsIMemory_Free(nsmem
, mem
);
617 static BOOL
nsACString_Init(nsACString
*str
, const char *data
)
619 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
623 * Initializes nsACString with data owned by caller.
624 * Caller must ensure that data is valid during lifetime of string object.
626 void nsACString_InitDepend(nsACString
*str
, const char *data
)
628 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
631 void nsACString_SetData(nsACString
*str
, const char *data
)
633 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
636 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
638 return NS_CStringGetData(str
, data
, NULL
);
641 void nsACString_Finish(nsACString
*str
)
643 NS_CStringContainerFinish(str
);
646 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
648 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
652 * Initializes nsAString with data owned by caller.
653 * Caller must ensure that data is valid during lifetime of string object.
655 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
657 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
660 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
662 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
665 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
667 return NS_StringGetData(str
, data
, NULL
);
670 void nsAString_Finish(nsAString
*str
)
672 NS_StringContainerFinish(str
);
675 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
677 const PRUnichar
*str
;
679 if(NS_FAILED(nsres
)) {
680 ERR("failed: %08x\n", nsres
);
681 nsAString_Finish(nsstr
);
685 nsAString_GetData(nsstr
, &str
);
686 TRACE("ret %s\n", debugstr_w(str
));
688 *p
= SysAllocString(str
);
690 return E_OUTOFMEMORY
;
695 nsAString_Finish(nsstr
);
699 nsICommandParams
*create_nscommand_params(void)
701 nsICommandParams
*ret
= NULL
;
707 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
708 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
711 ERR("Could not get nsICommandParams\n");
716 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
718 nsIInterfaceRequestor
*iface_req
;
721 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
725 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
726 nsIInterfaceRequestor_Release(iface_req
);
731 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
733 nsIDOMNodeList
*node_list
= NULL
;
734 PRBool has_children
= FALSE
;
735 nsIContent
*nscontent
;
739 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
741 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
742 if(NS_FAILED(nsres
)) {
743 ERR("GetType failed: %08x\n", nsres
);
747 if(type
!= DOCUMENT_NODE
) {
748 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
749 if(NS_FAILED(nsres
)) {
750 ERR("Could not get nsIContent interface: %08x\n", nsres
);
757 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
760 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
763 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
765 case DOCUMENT_NODE
: {
767 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
768 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
769 nsIDocument_Release(nsdoc
);
772 case DOCUMENT_TYPE_NODE
:
773 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
775 case DOCUMENT_FRAGMENT_NODE
:
778 FIXME("Unhandled type %u\n", type
);
782 PRUint32 child_cnt
, i
;
783 nsIDOMNode
*child_node
;
785 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
786 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
788 for(i
=0; i
<child_cnt
; i
++) {
789 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
790 if(NS_SUCCEEDED(nsres
)) {
791 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
792 nsIDOMNode_Release(child_node
);
794 ERR("Item failed: %08x\n", nsres
);
798 nsIDOMNodeList_Release(node_list
);
801 if(type
== ELEMENT_NODE
)
802 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
804 if(type
!= DOCUMENT_NODE
)
805 nsIContent_Release(nscontent
);
809 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
811 nsIContentSerializer
*serializer
;
815 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
816 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
817 (void**)&serializer
);
818 if(NS_FAILED(nsres
)) {
819 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
823 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
825 ERR("Init failed: %08x\n", nsres
);
827 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
828 if(SUCCEEDED(hres
)) {
829 nsres
= nsIContentSerializer_Flush(serializer
, str
);
831 ERR("Flush failed: %08x\n", nsres
);
834 nsIContentSerializer_Release(serializer
);
838 void get_editor_controller(NSContainer
*This
)
840 nsIEditingSession
*editing_session
= NULL
;
841 nsIControllerContext
*ctrlctx
;
845 nsIEditor_Release(This
->editor
);
849 if(This
->editor_controller
) {
850 nsIController_Release(This
->editor_controller
);
851 This
->editor_controller
= NULL
;
854 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
855 (void**)&editing_session
);
856 if(NS_FAILED(nsres
)) {
857 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
861 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
862 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
863 nsIEditingSession_Release(editing_session
);
864 if(NS_FAILED(nsres
)) {
865 ERR("Could not get editor: %08x\n", nsres
);
869 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
870 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
871 if(NS_SUCCEEDED(nsres
)) {
872 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
874 ERR("SetCommandContext failed: %08x\n", nsres
);
875 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
876 (void**)&This
->editor_controller
);
877 nsIControllerContext_Release(ctrlctx
);
879 ERR("Could not get nsIController interface: %08x\n", nsres
);
881 ERR("Could not create edit controller: %08x\n", nsres
);
885 void close_gecko(void)
892 if(profile_directory
) {
893 nsIFile_Release(profile_directory
);
894 profile_directory
= NULL
;
898 nsIComponentManager_Release(pCompMgr
);
901 nsIServiceManager_Release(pServMgr
);
904 nsIMemory_Release(nsmem
);
906 /* Gecko doesn't really support being unloaded */
907 /* if (hXPCOM) FreeLibrary(hXPCOM); */
909 DeleteCriticalSection(&cs_load_gecko
);
912 BOOL
is_gecko_path(const char *path
)
917 buf
= heap_strdupAtoW(path
);
918 if(strlenW(buf
) < gecko_path_len
)
921 buf
[gecko_path_len
] = 0;
922 for(ptr
= buf
; *ptr
; ptr
++) {
927 ret
= !strcmpiW(buf
, gecko_path
);
932 struct nsWeakReference
{
933 nsIWeakReference nsIWeakReference_iface
;
937 NSContainer
*nscontainer
;
940 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
942 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
945 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
946 nsIIDRef riid
, void **result
)
948 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
950 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
951 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
952 *result
= &This
->nsIWeakReference_iface
;
953 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
954 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
955 *result
= &This
->nsIWeakReference_iface
;
957 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
959 return NS_NOINTERFACE
;
962 nsISupports_AddRef((nsISupports
*)*result
);
966 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
968 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
969 LONG ref
= InterlockedIncrement(&This
->ref
);
971 TRACE("(%p) ref=%d\n", This
, ref
);
976 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
978 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
979 LONG ref
= InterlockedIncrement(&This
->ref
);
981 TRACE("(%p) ref=%d\n", This
, ref
);
984 assert(!This
->nscontainer
);
991 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
992 const nsIID
*riid
, void **result
)
994 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
996 if(!This
->nscontainer
)
997 return NS_ERROR_NULL_POINTER
;
999 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1002 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1003 nsWeakReference_QueryInterface
,
1004 nsWeakReference_AddRef
,
1005 nsWeakReference_Release
,
1006 nsWeakReference_QueryReferent
1009 /**********************************************************
1010 * nsIWebBrowserChrome interface
1013 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1015 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1018 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1019 nsIIDRef riid
, void **result
)
1021 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1024 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1025 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1026 *result
= &This
->nsIWebBrowserChrome_iface
;
1027 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1028 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1029 *result
= &This
->nsIWebBrowserChrome_iface
;
1030 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1031 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1032 *result
= &This
->nsIContextMenuListener_iface
;
1033 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1034 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1035 *result
= &This
->nsIURIContentListener_iface
;
1036 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1037 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1038 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1039 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1040 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1041 *result
= &This
->nsITooltipListener_iface
;
1042 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1043 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1044 *result
= &This
->nsIInterfaceRequestor_iface
;
1045 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1046 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1047 *result
= &This
->nsISupportsWeakReference_iface
;
1051 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1055 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1056 return NS_NOINTERFACE
;
1059 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1061 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1062 LONG ref
= InterlockedIncrement(&This
->ref
);
1064 TRACE("(%p) ref=%d\n", This
, ref
);
1069 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1071 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1072 LONG ref
= InterlockedDecrement(&This
->ref
);
1074 TRACE("(%p) ref=%d\n", This
, ref
);
1078 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1079 if(This
->weak_reference
) {
1080 This
->weak_reference
->nscontainer
= NULL
;
1081 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1089 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1090 PRUint32 statusType
, const PRUnichar
*status
)
1092 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1093 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1097 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1098 nsIWebBrowser
**aWebBrowser
)
1100 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1102 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1105 return NS_ERROR_INVALID_ARG
;
1107 if(This
->webbrowser
)
1108 nsIWebBrowser_AddRef(This
->webbrowser
);
1109 *aWebBrowser
= This
->webbrowser
;
1113 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1114 nsIWebBrowser
*aWebBrowser
)
1116 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1118 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1120 if(aWebBrowser
!= This
->webbrowser
)
1121 ERR("Wrong nsWebBrowser!\n");
1126 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1127 PRUint32
*aChromeFlags
)
1129 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1130 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1131 return NS_ERROR_NOT_IMPLEMENTED
;
1134 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1135 PRUint32 aChromeFlags
)
1137 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1138 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1139 return NS_ERROR_NOT_IMPLEMENTED
;
1142 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1144 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1145 TRACE("(%p)\n", This
);
1146 return NS_ERROR_NOT_IMPLEMENTED
;
1149 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1150 PRInt32 aCX
, PRInt32 aCY
)
1152 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1153 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1154 return NS_ERROR_NOT_IMPLEMENTED
;
1157 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1159 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1160 WARN("(%p)\n", This
);
1161 return NS_ERROR_NOT_IMPLEMENTED
;
1164 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
1166 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1167 WARN("(%p)->(%p)\n", This
, _retval
);
1168 return NS_ERROR_NOT_IMPLEMENTED
;
1171 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1174 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1175 WARN("(%p)->(%08x)\n", This
, aStatus
);
1176 return NS_ERROR_NOT_IMPLEMENTED
;
1179 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1180 nsWebBrowserChrome_QueryInterface
,
1181 nsWebBrowserChrome_AddRef
,
1182 nsWebBrowserChrome_Release
,
1183 nsWebBrowserChrome_SetStatus
,
1184 nsWebBrowserChrome_GetWebBrowser
,
1185 nsWebBrowserChrome_SetWebBrowser
,
1186 nsWebBrowserChrome_GetChromeFlags
,
1187 nsWebBrowserChrome_SetChromeFlags
,
1188 nsWebBrowserChrome_DestroyBrowserWindow
,
1189 nsWebBrowserChrome_SizeBrowserTo
,
1190 nsWebBrowserChrome_ShowAsModal
,
1191 nsWebBrowserChrome_IsWindowModal
,
1192 nsWebBrowserChrome_ExitModalEventLoop
1195 /**********************************************************
1196 * nsIContextMenuListener interface
1199 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1201 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1204 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1205 nsIIDRef riid
, void **result
)
1207 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1208 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1211 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1213 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1214 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1217 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1219 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1220 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1223 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1224 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1226 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1227 nsIDOMMouseEvent
*event
;
1230 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1234 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1236 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
);
1238 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1239 if(NS_FAILED(nsres
)) {
1240 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1244 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1245 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1246 nsIDOMMouseEvent_Release(event
);
1248 switch(aContextFlags
) {
1250 case CONTEXT_DOCUMENT
:
1252 dwID
= CONTEXT_MENU_DEFAULT
;
1255 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1256 dwID
= CONTEXT_MENU_IMAGE
;
1259 dwID
= CONTEXT_MENU_ANCHOR
;
1262 dwID
= CONTEXT_MENU_CONTROL
;
1265 FIXME("aContextFlags=%08x\n", aContextFlags
);
1268 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1270 return NS_ERROR_FAILURE
;
1272 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1276 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1277 nsContextMenuListener_QueryInterface
,
1278 nsContextMenuListener_AddRef
,
1279 nsContextMenuListener_Release
,
1280 nsContextMenuListener_OnShowContextMenu
1283 /**********************************************************
1284 * nsIURIContentListener interface
1287 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1289 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1292 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1293 nsIIDRef riid
, void **result
)
1295 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1296 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1299 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1301 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1302 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1305 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1307 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1308 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1311 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1312 nsIURI
*aURI
, PRBool
*_retval
)
1314 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1315 nsACString spec_str
;
1319 nsACString_Init(&spec_str
, NULL
);
1320 nsIURI_GetSpec(aURI
, &spec_str
);
1321 nsACString_GetData(&spec_str
, &spec
);
1323 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1325 nsACString_Finish(&spec_str
);
1327 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1328 if(NS_FAILED(nsres
))
1331 return !*_retval
&& This
->content_listener
1332 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1336 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1337 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1338 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1340 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1342 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1343 aRequest
, aContentHandler
, _retval
);
1345 return This
->content_listener
1346 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1347 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1348 : NS_ERROR_NOT_IMPLEMENTED
;
1351 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1352 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1354 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1356 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1358 /* FIXME: Should we do something here? */
1361 return This
->content_listener
1362 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1363 aDesiredContentType
, _retval
)
1367 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1368 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1371 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1373 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1374 aDesiredContentType
, _retval
);
1376 return This
->content_listener
1377 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1378 aIsContentPreferred
, aDesiredContentType
, _retval
)
1379 : NS_ERROR_NOT_IMPLEMENTED
;
1382 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1383 nsISupports
**aLoadCookie
)
1385 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1387 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1389 return This
->content_listener
1390 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1391 : NS_ERROR_NOT_IMPLEMENTED
;
1394 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1395 nsISupports
*aLoadCookie
)
1397 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1399 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1401 return This
->content_listener
1402 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1403 : NS_ERROR_NOT_IMPLEMENTED
;
1406 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1407 nsIURIContentListener
**aParentContentListener
)
1409 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1411 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1413 if(This
->content_listener
)
1414 nsIURIContentListener_AddRef(This
->content_listener
);
1416 *aParentContentListener
= This
->content_listener
;
1420 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1421 nsIURIContentListener
*aParentContentListener
)
1423 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1425 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1427 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1430 if(This
->content_listener
)
1431 nsIURIContentListener_Release(This
->content_listener
);
1433 This
->content_listener
= aParentContentListener
;
1434 if(This
->content_listener
)
1435 nsIURIContentListener_AddRef(This
->content_listener
);
1440 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1441 nsURIContentListener_QueryInterface
,
1442 nsURIContentListener_AddRef
,
1443 nsURIContentListener_Release
,
1444 nsURIContentListener_OnStartURIOpen
,
1445 nsURIContentListener_DoContent
,
1446 nsURIContentListener_IsPreferred
,
1447 nsURIContentListener_CanHandleContent
,
1448 nsURIContentListener_GetLoadCookie
,
1449 nsURIContentListener_SetLoadCookie
,
1450 nsURIContentListener_GetParentContentListener
,
1451 nsURIContentListener_SetParentContentListener
1454 /**********************************************************
1455 * nsIEmbeddinSiteWindow interface
1458 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1460 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1463 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1464 nsIIDRef riid
, void **result
)
1466 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1467 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1470 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1472 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1473 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1476 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1478 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1479 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1482 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1483 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1485 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1486 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1487 return NS_ERROR_NOT_IMPLEMENTED
;
1490 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1491 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1493 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1494 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1495 return NS_ERROR_NOT_IMPLEMENTED
;
1498 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1500 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1502 TRACE("(%p)\n", This
);
1504 return nsIBaseWindow_SetFocus(This
->window
);
1507 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1508 PRBool
*aVisibility
)
1510 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1512 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1514 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1518 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1521 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1523 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1528 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1531 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1532 WARN("(%p)->(%p)\n", This
, aTitle
);
1533 return NS_ERROR_NOT_IMPLEMENTED
;
1536 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1537 const PRUnichar
*aTitle
)
1539 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1540 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1541 return NS_ERROR_NOT_IMPLEMENTED
;
1544 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1547 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1549 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1551 *aSiteWindow
= This
->hwnd
;
1555 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1556 nsEmbeddingSiteWindow_QueryInterface
,
1557 nsEmbeddingSiteWindow_AddRef
,
1558 nsEmbeddingSiteWindow_Release
,
1559 nsEmbeddingSiteWindow_SetDimensions
,
1560 nsEmbeddingSiteWindow_GetDimensions
,
1561 nsEmbeddingSiteWindow_SetFocus
,
1562 nsEmbeddingSiteWindow_GetVisibility
,
1563 nsEmbeddingSiteWindow_SetVisibility
,
1564 nsEmbeddingSiteWindow_GetTitle
,
1565 nsEmbeddingSiteWindow_SetTitle
,
1566 nsEmbeddingSiteWindow_GetSiteWindow
1569 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1571 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1574 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1577 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1578 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1581 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1583 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1584 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1587 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1589 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1590 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1593 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1594 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1596 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1599 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1604 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1606 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1609 hide_tooltip(This
->doc
);
1614 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1615 nsTooltipListener_QueryInterface
,
1616 nsTooltipListener_AddRef
,
1617 nsTooltipListener_Release
,
1618 nsTooltipListener_OnShowTooltip
,
1619 nsTooltipListener_OnHideTooltip
1622 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1624 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1627 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1628 nsIIDRef riid
, void **result
)
1630 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1631 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1634 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1636 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1637 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1640 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1642 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1643 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1646 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1647 nsIIDRef riid
, void **result
)
1649 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1651 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1652 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1653 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1656 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1659 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1660 nsInterfaceRequestor_QueryInterface
,
1661 nsInterfaceRequestor_AddRef
,
1662 nsInterfaceRequestor_Release
,
1663 nsInterfaceRequestor_GetInterface
1666 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1668 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1671 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1672 nsIIDRef riid
, void **result
)
1674 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1675 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1678 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1680 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1681 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1684 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1686 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1687 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1690 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1691 nsIWeakReference
**_retval
)
1693 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1695 TRACE("(%p)->(%p)\n", This
, _retval
);
1697 if(!This
->weak_reference
) {
1698 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1699 if(!This
->weak_reference
)
1700 return NS_ERROR_OUT_OF_MEMORY
;
1702 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1703 This
->weak_reference
->ref
= 1;
1704 This
->weak_reference
->nscontainer
= This
;
1707 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1708 nsIWeakReference_AddRef(*_retval
);
1712 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1713 nsSupportsWeakReference_QueryInterface
,
1714 nsSupportsWeakReference_AddRef
,
1715 nsSupportsWeakReference_Release
,
1716 nsSupportsWeakReference_GetWeakReference
1719 nsresult
create_chrome_window(nsIWebBrowserChrome
*parent
, nsIWebBrowserChrome
**ret
)
1721 NSContainer
*new_container
;
1724 if(parent
->lpVtbl
!= &nsWebBrowserChromeVtbl
)
1725 return NS_ERROR_UNEXPECTED
;
1727 hres
= create_nscontainer(NULL
, impl_from_nsIWebBrowserChrome(parent
), &new_container
);
1729 return NS_ERROR_FAILURE
;
1731 *ret
= &new_container
->nsIWebBrowserChrome_iface
;
1735 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1737 nsIWebBrowserSetup
*wbsetup
;
1738 nsIScrollable
*scrollable
;
1741 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1742 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1743 if(NS_FAILED(nsres
)) {
1744 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1748 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1749 if(NS_FAILED(nsres
)) {
1750 ERR("SetContainerWindow failed: %08x\n", nsres
);
1754 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1755 (void**)&nscontainer
->window
);
1756 if(NS_FAILED(nsres
)) {
1757 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1761 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
1763 if(NS_SUCCEEDED(nsres
)) {
1764 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1765 nsIWebBrowserSetup_Release(wbsetup
);
1766 if(NS_FAILED(nsres
)) {
1767 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1771 ERR("Could not get nsIWebBrowserSetup interface\n");
1775 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
1776 (void**)&nscontainer
->navigation
);
1777 if(NS_FAILED(nsres
)) {
1778 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1782 nsres
= nsIWebBrowserFocus_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
1783 (void**)&nscontainer
->focus
);
1784 if(NS_FAILED(nsres
)) {
1785 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1789 if(!nscontainer_class
) {
1790 register_nscontainer_class();
1791 if(!nscontainer_class
)
1795 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1796 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1797 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
1798 if(!nscontainer
->hwnd
) {
1799 WARN("Could not create window\n");
1803 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
1804 if(NS_SUCCEEDED(nsres
)) {
1805 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
1806 if(NS_FAILED(nsres
)) {
1807 WARN("Creating window failed: %08x\n", nsres
);
1811 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
1812 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
1814 ERR("InitWindow failed: %08x\n", nsres
);
1818 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
1819 &nscontainer
->nsIURIContentListener_iface
);
1820 if(NS_FAILED(nsres
))
1821 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1823 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1824 if(NS_SUCCEEDED(nsres
)) {
1825 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1826 ScrollOrientation_Y
, Scrollbar_Always
);
1827 if(NS_FAILED(nsres
))
1828 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1830 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1831 ScrollOrientation_X
, Scrollbar_Auto
);
1832 if(NS_FAILED(nsres
))
1833 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1835 nsIScrollable_Release(scrollable
);
1837 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1843 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
*parent
, NSContainer
**_ret
)
1848 if(!load_gecko(TRUE
))
1849 return CLASS_E_CLASSNOTAVAILABLE
;
1851 ret
= heap_alloc_zero(sizeof(NSContainer
));
1853 return E_OUTOFMEMORY
;
1855 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
1856 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
1857 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
1858 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
1859 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
1860 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
1861 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
1867 nsIWebBrowserChrome_AddRef(&parent
->nsIWebBrowserChrome_iface
);
1868 ret
->parent
= parent
;
1870 hres
= init_nscontainer(ret
);
1874 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
1878 void NSContainer_Release(NSContainer
*This
)
1880 TRACE("(%p)\n", This
);
1884 ShowWindow(This
->hwnd
, SW_HIDE
);
1885 SetParent(This
->hwnd
, NULL
);
1887 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1888 nsIBaseWindow_Destroy(This
->window
);
1890 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1892 nsIWebBrowser_Release(This
->webbrowser
);
1893 This
->webbrowser
= NULL
;
1895 nsIWebNavigation_Release(This
->navigation
);
1896 This
->navigation
= NULL
;
1898 nsIBaseWindow_Release(This
->window
);
1899 This
->window
= NULL
;
1901 nsIWebBrowserFocus_Release(This
->focus
);
1904 if(This
->editor_controller
) {
1905 nsIController_Release(This
->editor_controller
);
1906 This
->editor_controller
= NULL
;
1910 nsIEditor_Release(This
->editor
);
1911 This
->editor
= NULL
;
1914 if(This
->content_listener
) {
1915 nsIURIContentListener_Release(This
->content_listener
);
1916 This
->content_listener
= NULL
;
1920 DestroyWindow(This
->hwnd
);
1924 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);