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
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 WINE_DECLARE_DEBUG_CHANNEL(gecko
);
41 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
42 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
43 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
44 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
45 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
46 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
47 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
49 #define APPSTARTUP_TOPIC "app-startup"
51 #define PR_UINT32_MAX 0xffffffff
53 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
54 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
56 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
57 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
58 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
59 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
60 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
61 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
62 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
63 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
64 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
65 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
66 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
67 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
69 static HINSTANCE hXPCOM
= NULL
;
71 static nsIServiceManager
*pServMgr
= NULL
;
72 static nsIComponentManager
*pCompMgr
= NULL
;
73 static nsIMemory
*nsmem
= NULL
;
74 static nsIFile
*profile_directory
;
76 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
78 static ATOM nscontainer_class
;
79 static WCHAR gecko_path
[MAX_PATH
];
80 static unsigned gecko_path_len
;
82 static nsresult NSAPI
nsDirectoryServiceProvider_QueryInterface(nsIDirectoryServiceProvider
*iface
,
83 nsIIDRef riid
, void **result
)
85 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
86 TRACE("(IID_nsISupports %p)\n", result
);
88 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
89 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
92 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
94 return NS_NOINTERFACE
;
97 nsISupports_AddRef((nsISupports
*)*result
);
101 static nsrefcnt NSAPI
nsDirectoryServiceProvider_AddRef(nsIDirectoryServiceProvider
*iface
)
106 static nsrefcnt NSAPI
nsDirectoryServiceProvider_Release(nsIDirectoryServiceProvider
*iface
)
111 static nsresult
create_profile_directory(void)
113 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
115 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
121 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_DEFAULT
, path
);
123 ERR("SHGetFolderPath failed: %08x\n", hres
);
124 return NS_ERROR_FAILURE
;
127 strcatW(path
, wine_geckoW
);
128 nsAString_InitDepend(&str
, path
);
129 nsres
= NS_NewLocalFile(&str
, FALSE
, &profile_directory
);
130 nsAString_Finish(&str
);
131 if(NS_FAILED(nsres
)) {
132 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
136 nsres
= nsIFile_Exists(profile_directory
, &exists
);
137 if(NS_FAILED(nsres
)) {
138 ERR("Exists failed: %08x\n", nsres
);
143 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
145 ERR("Create failed: %08x\n", nsres
);
151 static nsresult NSAPI
nsDirectoryServiceProvider_GetFile(nsIDirectoryServiceProvider
*iface
,
152 const char *prop
, PRBool
*persistent
, nsIFile
**_retval
)
154 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
156 if(!strcmp(prop
, "ProfD")) {
157 if(!profile_directory
) {
160 nsres
= create_profile_directory();
165 return nsIFile_Clone(profile_directory
, _retval
);
168 return NS_ERROR_FAILURE
;
171 #undef NSWEAKREF_THIS
173 static const nsIDirectoryServiceProviderVtbl nsDirectoryServiceProviderVtbl
= {
174 nsDirectoryServiceProvider_QueryInterface
,
175 nsDirectoryServiceProvider_AddRef
,
176 nsDirectoryServiceProvider_Release
,
177 nsDirectoryServiceProvider_GetFile
180 static nsIDirectoryServiceProvider nsDirectoryServiceProvider
=
181 { &nsDirectoryServiceProviderVtbl
};
183 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
188 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
190 if(msg
== WM_CREATE
) {
191 This
= *(NSContainer
**)lParam
;
192 SetPropW(hwnd
, wszTHIS
, This
);
194 This
= GetPropW(hwnd
, wszTHIS
);
199 TRACE("(%p)->(WM_SIZE)\n", This
);
201 nsres
= nsIBaseWindow_SetSize(This
->window
,
202 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
204 WARN("SetSize failed: %08x\n", nsres
);
207 case WM_PARENTNOTIFY
:
208 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
213 nsIWebBrowserFocus_Activate(This
->focus
);
217 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
221 static void register_nscontainer_class(void)
223 static WNDCLASSEXW wndclass
= {
227 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
231 wndclass
.hInstance
= hInst
;
232 nscontainer_class
= RegisterClassExW(&wndclass
);
235 static void set_environment(LPCWSTR gre_path
)
237 WCHAR path_env
[MAX_PATH
], buf
[20];
238 int len
, debug_level
= 0;
240 static const WCHAR pathW
[] = {'P','A','T','H',0};
241 static const WCHAR warnW
[] = {'w','a','r','n',0};
242 static const WCHAR xpcom_debug_breakW
[] =
243 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
244 static const WCHAR nspr_log_modulesW
[] =
245 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
246 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
248 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
249 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
250 len
= strlenW(path_env
);
251 path_env
[len
++] = ';';
252 strcpyW(path_env
+len
, gre_path
);
253 SetEnvironmentVariableW(pathW
, path_env
);
255 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
259 else if(WARN_ON(gecko
))
261 else if(ERR_ON(gecko
))
264 sprintfW(buf
, debug_formatW
, debug_level
);
265 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
268 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
270 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
272 TRACE("(%s)\n", debugstr_w(gre_path
));
274 set_environment(gre_path
);
276 hXPCOM
= LoadLibraryW(strXPCOM
);
278 WARN("Could not load XPCOM: %d\n", GetLastError());
282 #define NS_DLSYM(func) \
283 func = (void *)GetProcAddress(hXPCOM, #func); \
285 ERR("Could not GetProcAddress(" #func ") failed\n")
287 NS_DLSYM(NS_InitXPCOM2
);
288 NS_DLSYM(NS_ShutdownXPCOM
);
289 NS_DLSYM(NS_GetComponentRegistrar
);
290 NS_DLSYM(NS_StringContainerInit2
);
291 NS_DLSYM(NS_CStringContainerInit2
);
292 NS_DLSYM(NS_StringContainerFinish
);
293 NS_DLSYM(NS_CStringContainerFinish
);
294 NS_DLSYM(NS_StringSetData
);
295 NS_DLSYM(NS_CStringSetData
);
296 NS_DLSYM(NS_NewLocalFile
);
297 NS_DLSYM(NS_StringGetData
);
298 NS_DLSYM(NS_CStringGetData
);
305 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
307 WCHAR file_name
[MAX_PATH
];
312 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
314 strcpyW(file_name
, gre_path
);
315 strcatW(file_name
, wszVersion
);
317 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
318 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
319 if(hfile
== INVALID_HANDLE_VALUE
) {
320 ERR("Could not open VERSION file\n");
324 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
328 TRACE("%s\n", debugstr_a(version
));
330 if(strcmp(version
, version_string
)) {
331 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
332 debugstr_a(version_string
));
339 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
340 const char *version
, const char *version_string
)
342 DWORD res
, type
, size
= MAX_PATH
;
343 HKEY hkey
= mshtml_key
;
345 static const WCHAR wszGeckoPath
[] =
346 {'G','e','c','k','o','P','a','t','h',0};
349 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
350 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
351 if(res
!= ERROR_SUCCESS
)
355 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
356 if(hkey
!= mshtml_key
)
358 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
361 if(!check_version(gre_path
, version_string
))
364 return load_xpcom(gre_path
);
367 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
373 static const WCHAR wszMshtmlKey
[] = {
374 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
375 '\\','M','S','H','T','M','L',0};
377 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
378 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
379 if(res
!= ERROR_SUCCESS
)
382 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
388 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
392 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
394 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
397 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
401 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
403 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
406 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
410 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
412 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
415 static void set_lang(nsIPrefBranch
*pref
)
418 DWORD res
, size
, type
;
421 static const WCHAR international_keyW
[] =
422 {'S','o','f','t','w','a','r','e',
423 '\\','M','i','c','r','o','s','o','f','t',
424 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
425 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
427 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
428 if(res
!= ERROR_SUCCESS
)
431 size
= sizeof(langs
);
432 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
434 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
437 TRACE("Setting lang %s\n", debugstr_a(langs
));
439 set_string_pref(pref
, "intl.accept_languages", langs
);
442 static void set_proxy(nsIPrefBranch
*pref
)
447 DWORD enabled
= 0, res
, size
, type
;
450 static const WCHAR proxy_keyW
[] =
451 {'S','o','f','t','w','a','r','e',
452 '\\','M','i','c','r','o','s','o','f','t',
453 '\\','W','i','n','d','o','w','s',
454 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
455 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
457 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
458 if(res
!= ERROR_SUCCESS
)
461 size
= sizeof(enabled
);
462 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
463 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
469 size
= sizeof(proxy
);
470 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
472 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
475 proxy_port
= strchr(proxy
, ':');
480 proxy_port_num
= atoi(proxy_port
+ 1);
481 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
483 set_string_pref(pref
, "network.proxy.http", proxy
);
484 set_string_pref(pref
, "network.proxy.ssl", proxy
);
486 set_int_pref(pref
, "network.proxy.type", 1);
487 set_int_pref(pref
, "network.proxy.http_port", proxy_port_num
);
488 set_int_pref(pref
, "network.proxy.ssl_port", proxy_port_num
);
491 static void set_preferences(void)
496 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
497 &IID_nsIPrefBranch
, (void**)&pref
);
498 if(NS_FAILED(nsres
)) {
499 ERR("Could not get preference service: %08x\n", nsres
);
505 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
506 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
507 set_int_pref(pref
, "layout.spellcheckDefault", 0);
509 nsIPrefBranch_Release(pref
);
512 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
515 nsIObserver
*pStartNotif
;
516 nsIComponentRegistrar
*registrar
= NULL
;
521 nsAString_InitDepend(&path
, gre_path
);
522 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
523 nsAString_Finish(&path
);
524 if(NS_FAILED(nsres
)) {
525 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
530 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, &nsDirectoryServiceProvider
);
531 if(NS_FAILED(nsres
)) {
532 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
537 strcpyW(gecko_path
, gre_path
);
538 for(ptr
= gecko_path
; *ptr
; ptr
++) {
542 gecko_path_len
= ptr
-gecko_path
;
544 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
546 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
548 nsres
= NS_GetComponentRegistrar(®istrar
);
549 if(NS_SUCCEEDED(nsres
))
550 init_nsio(pCompMgr
, registrar
);
552 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
554 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
555 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
556 if(NS_SUCCEEDED(nsres
)) {
557 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
559 ERR("Observe failed: %08x\n", nsres
);
561 nsIObserver_Release(pStartNotif
);
563 ERR("could not get appstartup-notifier: %08x\n", nsres
);
568 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
569 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
571 ERR("Could not get nsIMemory: %08x\n", nsres
);
574 register_nsservice(registrar
, pServMgr
);
575 nsIComponentRegistrar_Release(registrar
);
581 static CRITICAL_SECTION cs_load_gecko
;
582 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
584 0, 0, &cs_load_gecko
,
585 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
586 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
588 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
590 BOOL
load_gecko(BOOL silent
)
592 PRUnichar gre_path
[MAX_PATH
];
595 static DWORD loading_thread
;
599 /* load_gecko may be called recursively */
600 if(loading_thread
== GetCurrentThreadId())
601 return pCompMgr
!= NULL
;
603 EnterCriticalSection(&cs_load_gecko
);
605 if(!loading_thread
) {
606 loading_thread
= GetCurrentThreadId();
608 if(load_wine_gecko(gre_path
)
609 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
610 ret
= init_xpcom(gre_path
);
612 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
614 ret
= pCompMgr
!= NULL
;
617 LeaveCriticalSection(&cs_load_gecko
);
622 void *nsalloc(size_t size
)
624 return nsIMemory_Alloc(nsmem
, size
);
627 void nsfree(void *mem
)
629 nsIMemory_Free(nsmem
, mem
);
632 static BOOL
nsACString_Init(nsACString
*str
, const char *data
)
634 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
638 * Initializes nsACString with data owned by caller.
639 * Caller must ensure that data is valid during lifetime of string object.
641 void nsACString_InitDepend(nsACString
*str
, const char *data
)
643 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
646 void nsACString_SetData(nsACString
*str
, const char *data
)
648 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
651 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
653 return NS_CStringGetData(str
, data
, NULL
);
656 void nsACString_Finish(nsACString
*str
)
658 NS_CStringContainerFinish(str
);
661 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
663 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
667 * Initializes nsAString with data owned by caller.
668 * Caller must ensure that data is valid during lifetime of string object.
670 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
672 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
675 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
677 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
680 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
682 return NS_StringGetData(str
, data
, NULL
);
685 void nsAString_Finish(nsAString
*str
)
687 NS_StringContainerFinish(str
);
690 nsICommandParams
*create_nscommand_params(void)
692 nsICommandParams
*ret
= NULL
;
698 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
699 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
702 ERR("Could not get nsICommandParams\n");
707 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
709 nsIInterfaceRequestor
*iface_req
;
712 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
716 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
717 nsIInterfaceRequestor_Release(iface_req
);
722 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
724 nsIDOMNodeList
*node_list
= NULL
;
725 PRBool has_children
= FALSE
;
726 nsIContent
*nscontent
;
730 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
732 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
733 if(NS_FAILED(nsres
)) {
734 ERR("GetType failed: %08x\n", nsres
);
738 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
739 if(NS_FAILED(nsres
)) {
740 ERR("Could not get nsIDontent interface: %08x\n", nsres
);
746 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
749 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
752 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
754 case DOCUMENT_NODE
: {
756 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
757 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
758 nsIDocument_Release(nsdoc
);
761 case DOCUMENT_TYPE_NODE
:
762 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
764 case DOCUMENT_FRAGMENT_NODE
:
767 FIXME("Unhandled type %u\n", type
);
771 PRUint32 child_cnt
, i
;
772 nsIDOMNode
*child_node
;
774 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
775 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
777 for(i
=0; i
<child_cnt
; i
++) {
778 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
779 if(NS_SUCCEEDED(nsres
)) {
780 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
781 nsIDOMNode_Release(child_node
);
783 ERR("Item failed: %08x\n", nsres
);
787 nsIDOMNodeList_Release(node_list
);
790 if(type
== ELEMENT_NODE
)
791 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
793 nsIContent_Release(nscontent
);
797 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
799 nsIContentSerializer
*serializer
;
803 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
804 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
805 (void**)&serializer
);
806 if(NS_FAILED(nsres
)) {
807 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
811 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
813 ERR("Init failed: %08x\n", nsres
);
815 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
816 if(SUCCEEDED(hres
)) {
817 nsres
= nsIContentSerializer_Flush(serializer
, str
);
819 ERR("Flush failed: %08x\n", nsres
);
822 nsIContentSerializer_Release(serializer
);
826 void get_editor_controller(NSContainer
*This
)
828 nsIEditingSession
*editing_session
= NULL
;
829 nsIControllerContext
*ctrlctx
;
833 nsIEditor_Release(This
->editor
);
837 if(This
->editor_controller
) {
838 nsIController_Release(This
->editor_controller
);
839 This
->editor_controller
= NULL
;
842 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
843 (void**)&editing_session
);
844 if(NS_FAILED(nsres
)) {
845 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
849 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
850 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
851 nsIEditingSession_Release(editing_session
);
852 if(NS_FAILED(nsres
)) {
853 ERR("Could not get editor: %08x\n", nsres
);
857 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
858 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
859 if(NS_SUCCEEDED(nsres
)) {
860 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
862 ERR("SetCommandContext failed: %08x\n", nsres
);
863 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
864 (void**)&This
->editor_controller
);
865 nsIControllerContext_Release(ctrlctx
);
867 ERR("Could not get nsIController interface: %08x\n", nsres
);
869 ERR("Could not create edit controller: %08x\n", nsres
);
873 void close_gecko(void)
879 if(profile_directory
) {
880 nsIFile_Release(profile_directory
);
881 profile_directory
= NULL
;
885 nsIComponentManager_Release(pCompMgr
);
888 nsIServiceManager_Release(pServMgr
);
891 nsIMemory_Release(nsmem
);
893 /* Gecko doesn't really support being unloaded */
894 /* if (hXPCOM) FreeLibrary(hXPCOM); */
897 BOOL
is_gecko_path(const char *path
)
902 buf
= heap_strdupAtoW(path
);
903 if(strlenW(buf
) < gecko_path_len
)
906 buf
[gecko_path_len
] = 0;
907 for(ptr
= buf
; *ptr
; ptr
++) {
912 ret
= !strcmpiW(buf
, gecko_path
);
917 /**********************************************************
918 * nsIWebBrowserChrome interface
921 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
923 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
924 nsIIDRef riid
, void **result
)
926 NSContainer
*This
= NSWBCHROME_THIS(iface
);
929 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
930 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
931 *result
= NSWBCHROME(This
);
932 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
933 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
934 *result
= NSWBCHROME(This
);
935 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
936 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
937 *result
= NSCML(This
);
938 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
939 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
940 *result
= NSURICL(This
);
941 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
942 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
943 *result
= NSEMBWNDS(This
);
944 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
945 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
946 *result
= NSTOOLTIP(This
);
947 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
948 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
949 *result
= NSIFACEREQ(This
);
950 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
951 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
952 *result
= NSWEAKREF(This
);
953 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
954 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
955 *result
= NSSUPWEAKREF(This
);
959 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
963 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
964 return NS_NOINTERFACE
;
967 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
969 NSContainer
*This
= NSWBCHROME_THIS(iface
);
970 LONG ref
= InterlockedIncrement(&This
->ref
);
972 TRACE("(%p) ref=%d\n", This
, ref
);
977 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
979 NSContainer
*This
= NSWBCHROME_THIS(iface
);
980 LONG ref
= InterlockedDecrement(&This
->ref
);
982 TRACE("(%p) ref=%d\n", This
, ref
);
986 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
993 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
994 PRUint32 statusType
, const PRUnichar
*status
)
996 NSContainer
*This
= NSWBCHROME_THIS(iface
);
997 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1001 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1002 nsIWebBrowser
**aWebBrowser
)
1004 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1006 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1009 return NS_ERROR_INVALID_ARG
;
1011 if(This
->webbrowser
)
1012 nsIWebBrowser_AddRef(This
->webbrowser
);
1013 *aWebBrowser
= This
->webbrowser
;
1017 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1018 nsIWebBrowser
*aWebBrowser
)
1020 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1022 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1024 if(aWebBrowser
!= This
->webbrowser
)
1025 ERR("Wrong nsWebBrowser!\n");
1030 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1031 PRUint32
*aChromeFlags
)
1033 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1034 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1035 return NS_ERROR_NOT_IMPLEMENTED
;
1038 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1039 PRUint32 aChromeFlags
)
1041 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1042 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1043 return NS_ERROR_NOT_IMPLEMENTED
;
1046 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1048 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1049 TRACE("(%p)\n", This
);
1050 return NS_ERROR_NOT_IMPLEMENTED
;
1053 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1054 PRInt32 aCX
, PRInt32 aCY
)
1056 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1057 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1058 return NS_ERROR_NOT_IMPLEMENTED
;
1061 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1063 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1064 WARN("(%p)\n", This
);
1065 return NS_ERROR_NOT_IMPLEMENTED
;
1068 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
1070 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1071 WARN("(%p)->(%p)\n", This
, _retval
);
1072 return NS_ERROR_NOT_IMPLEMENTED
;
1075 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1078 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1079 WARN("(%p)->(%08x)\n", This
, aStatus
);
1080 return NS_ERROR_NOT_IMPLEMENTED
;
1083 #undef NSWBCHROME_THIS
1085 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1086 nsWebBrowserChrome_QueryInterface
,
1087 nsWebBrowserChrome_AddRef
,
1088 nsWebBrowserChrome_Release
,
1089 nsWebBrowserChrome_SetStatus
,
1090 nsWebBrowserChrome_GetWebBrowser
,
1091 nsWebBrowserChrome_SetWebBrowser
,
1092 nsWebBrowserChrome_GetChromeFlags
,
1093 nsWebBrowserChrome_SetChromeFlags
,
1094 nsWebBrowserChrome_DestroyBrowserWindow
,
1095 nsWebBrowserChrome_SizeBrowserTo
,
1096 nsWebBrowserChrome_ShowAsModal
,
1097 nsWebBrowserChrome_IsWindowModal
,
1098 nsWebBrowserChrome_ExitModalEventLoop
1101 /**********************************************************
1102 * nsIContextMenuListener interface
1105 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1107 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1108 nsIIDRef riid
, void **result
)
1110 NSContainer
*This
= NSCML_THIS(iface
);
1111 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1114 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1116 NSContainer
*This
= NSCML_THIS(iface
);
1117 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1120 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1122 NSContainer
*This
= NSCML_THIS(iface
);
1123 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1126 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1127 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1129 NSContainer
*This
= NSCML_THIS(iface
);
1130 nsIDOMMouseEvent
*event
;
1132 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1135 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1137 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
);
1139 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1140 if(NS_FAILED(nsres
)) {
1141 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1145 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1146 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1147 nsIDOMMouseEvent_Release(event
);
1149 switch(aContextFlags
) {
1151 case CONTEXT_DOCUMENT
:
1153 dwID
= CONTEXT_MENU_DEFAULT
;
1156 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1157 dwID
= CONTEXT_MENU_IMAGE
;
1160 dwID
= CONTEXT_MENU_ANCHOR
;
1163 dwID
= CONTEXT_MENU_CONTROL
;
1166 FIXME("aContextFlags=%08x\n", aContextFlags
);
1169 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
)));
1176 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1177 nsContextMenuListener_QueryInterface
,
1178 nsContextMenuListener_AddRef
,
1179 nsContextMenuListener_Release
,
1180 nsContextMenuListener_OnShowContextMenu
1183 /**********************************************************
1184 * nsIURIContentListener interface
1187 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1189 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1190 nsIIDRef riid
, void **result
)
1192 NSContainer
*This
= NSURICL_THIS(iface
);
1193 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1196 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1198 NSContainer
*This
= NSURICL_THIS(iface
);
1199 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1202 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1204 NSContainer
*This
= NSURICL_THIS(iface
);
1205 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1208 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1209 nsIURI
*aURI
, PRBool
*_retval
)
1211 NSContainer
*This
= NSURICL_THIS(iface
);
1212 nsACString spec_str
;
1216 nsACString_Init(&spec_str
, NULL
);
1217 nsIURI_GetSpec(aURI
, &spec_str
);
1218 nsACString_GetData(&spec_str
, &spec
);
1220 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1222 nsACString_Finish(&spec_str
);
1224 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1225 if(NS_FAILED(nsres
))
1228 return !*_retval
&& This
->content_listener
1229 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1233 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1234 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1235 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1237 NSContainer
*This
= NSURICL_THIS(iface
);
1239 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1240 aRequest
, aContentHandler
, _retval
);
1242 return This
->content_listener
1243 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1244 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1245 : NS_ERROR_NOT_IMPLEMENTED
;
1248 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1249 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1251 NSContainer
*This
= NSURICL_THIS(iface
);
1253 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1255 /* FIXME: Should we do something here? */
1258 return This
->content_listener
1259 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1260 aDesiredContentType
, _retval
)
1264 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1265 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1268 NSContainer
*This
= NSURICL_THIS(iface
);
1270 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1271 aDesiredContentType
, _retval
);
1273 return This
->content_listener
1274 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1275 aIsContentPreferred
, aDesiredContentType
, _retval
)
1276 : NS_ERROR_NOT_IMPLEMENTED
;
1279 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1280 nsISupports
**aLoadCookie
)
1282 NSContainer
*This
= NSURICL_THIS(iface
);
1284 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1286 return This
->content_listener
1287 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1288 : NS_ERROR_NOT_IMPLEMENTED
;
1291 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1292 nsISupports
*aLoadCookie
)
1294 NSContainer
*This
= NSURICL_THIS(iface
);
1296 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1298 return This
->content_listener
1299 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1300 : NS_ERROR_NOT_IMPLEMENTED
;
1303 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1304 nsIURIContentListener
**aParentContentListener
)
1306 NSContainer
*This
= NSURICL_THIS(iface
);
1308 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1310 if(This
->content_listener
)
1311 nsIURIContentListener_AddRef(This
->content_listener
);
1313 *aParentContentListener
= This
->content_listener
;
1317 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1318 nsIURIContentListener
*aParentContentListener
)
1320 NSContainer
*This
= NSURICL_THIS(iface
);
1322 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1324 if(aParentContentListener
== NSURICL(This
))
1327 if(This
->content_listener
)
1328 nsIURIContentListener_Release(This
->content_listener
);
1330 This
->content_listener
= aParentContentListener
;
1331 if(This
->content_listener
)
1332 nsIURIContentListener_AddRef(This
->content_listener
);
1339 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1340 nsURIContentListener_QueryInterface
,
1341 nsURIContentListener_AddRef
,
1342 nsURIContentListener_Release
,
1343 nsURIContentListener_OnStartURIOpen
,
1344 nsURIContentListener_DoContent
,
1345 nsURIContentListener_IsPreferred
,
1346 nsURIContentListener_CanHandleContent
,
1347 nsURIContentListener_GetLoadCookie
,
1348 nsURIContentListener_SetLoadCookie
,
1349 nsURIContentListener_GetParentContentListener
,
1350 nsURIContentListener_SetParentContentListener
1353 /**********************************************************
1354 * nsIEmbeddinSiteWindow interface
1357 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1359 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1360 nsIIDRef riid
, void **result
)
1362 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1363 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1366 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1368 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1369 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1372 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1374 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1375 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1378 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1379 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1381 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1382 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1383 return NS_ERROR_NOT_IMPLEMENTED
;
1386 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1387 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1389 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1390 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1391 return NS_ERROR_NOT_IMPLEMENTED
;
1394 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1396 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1398 TRACE("(%p)\n", This
);
1400 return nsIBaseWindow_SetFocus(This
->window
);
1403 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1404 PRBool
*aVisibility
)
1406 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1408 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1410 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1414 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1417 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1419 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1424 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1427 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1428 WARN("(%p)->(%p)\n", This
, aTitle
);
1429 return NS_ERROR_NOT_IMPLEMENTED
;
1432 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1433 const PRUnichar
*aTitle
)
1435 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1436 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1437 return NS_ERROR_NOT_IMPLEMENTED
;
1440 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1443 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1445 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1447 *aSiteWindow
= This
->hwnd
;
1451 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1452 nsEmbeddingSiteWindow_QueryInterface
,
1453 nsEmbeddingSiteWindow_AddRef
,
1454 nsEmbeddingSiteWindow_Release
,
1455 nsEmbeddingSiteWindow_SetDimensions
,
1456 nsEmbeddingSiteWindow_GetDimensions
,
1457 nsEmbeddingSiteWindow_SetFocus
,
1458 nsEmbeddingSiteWindow_GetVisibility
,
1459 nsEmbeddingSiteWindow_SetVisibility
,
1460 nsEmbeddingSiteWindow_GetTitle
,
1461 nsEmbeddingSiteWindow_SetTitle
,
1462 nsEmbeddingSiteWindow_GetSiteWindow
1465 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1467 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1470 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1471 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1474 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1476 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1477 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1480 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1482 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1483 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1486 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1487 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1489 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1492 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1497 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1499 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1502 hide_tooltip(This
->doc
);
1507 #undef NSTOOLTIM_THIS
1509 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1510 nsTooltipListener_QueryInterface
,
1511 nsTooltipListener_AddRef
,
1512 nsTooltipListener_Release
,
1513 nsTooltipListener_OnShowTooltip
,
1514 nsTooltipListener_OnHideTooltip
1517 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1519 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1520 nsIIDRef riid
, void **result
)
1522 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1523 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1526 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1528 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1529 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1532 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1534 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1535 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1538 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1539 nsIIDRef riid
, void **result
)
1541 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1543 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1544 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1545 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1548 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1551 #undef NSIFACEREQ_THIS
1553 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1554 nsInterfaceRequestor_QueryInterface
,
1555 nsInterfaceRequestor_AddRef
,
1556 nsInterfaceRequestor_Release
,
1557 nsInterfaceRequestor_GetInterface
1560 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1562 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1563 nsIIDRef riid
, void **result
)
1565 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1566 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1569 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1571 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1572 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1575 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1577 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1578 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1581 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1582 const nsIID
*riid
, void **result
)
1584 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1585 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1588 #undef NSWEAKREF_THIS
1590 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1591 nsWeakReference_QueryInterface
,
1592 nsWeakReference_AddRef
,
1593 nsWeakReference_Release
,
1594 nsWeakReference_QueryReferent
1597 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1599 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1600 nsIIDRef riid
, void **result
)
1602 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1603 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1606 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1608 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1609 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1612 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1614 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1615 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1618 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1619 nsIWeakReference
**_retval
)
1621 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1623 TRACE("(%p)->(%p)\n", This
, _retval
);
1625 nsIWeakReference_AddRef(NSWEAKREF(This
));
1626 *_retval
= NSWEAKREF(This
);
1630 #undef NSWEAKREF_THIS
1632 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1633 nsSupportsWeakReference_QueryInterface
,
1634 nsSupportsWeakReference_AddRef
,
1635 nsSupportsWeakReference_Release
,
1636 nsSupportsWeakReference_GetWeakReference
1640 NSContainer
*NSContainer_Create(HTMLDocumentObj
*doc
, NSContainer
*parent
)
1642 nsIWebBrowserSetup
*wbsetup
;
1643 nsIScrollable
*scrollable
;
1647 if(!load_gecko(TRUE
))
1650 ret
= heap_alloc_zero(sizeof(NSContainer
));
1652 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1653 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1654 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1655 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1656 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1657 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1658 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1659 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1664 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1665 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1666 if(NS_FAILED(nsres
)) {
1667 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1673 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1674 ret
->parent
= parent
;
1676 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1677 if(NS_FAILED(nsres
))
1678 ERR("SetContainerWindow failed: %08x\n", nsres
);
1680 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1681 (void**)&ret
->window
);
1682 if(NS_FAILED(nsres
))
1683 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1685 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1687 if(NS_SUCCEEDED(nsres
)) {
1688 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1689 nsIWebBrowserSetup_Release(wbsetup
);
1690 if(NS_FAILED(nsres
))
1691 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1693 ERR("Could not get nsIWebBrowserSetup interface\n");
1696 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1697 (void**)&ret
->navigation
);
1698 if(NS_FAILED(nsres
))
1699 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1701 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1702 (void**)&ret
->focus
);
1703 if(NS_FAILED(nsres
))
1704 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1706 if(!nscontainer_class
)
1707 register_nscontainer_class();
1709 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1710 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1711 GetDesktopWindow(), NULL
, hInst
, ret
);
1713 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1714 if(NS_SUCCEEDED(nsres
)) {
1715 nsres
= nsIBaseWindow_Create(ret
->window
);
1716 if(NS_FAILED(nsres
))
1717 WARN("Creating window failed: %08x\n", nsres
);
1719 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1720 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1722 ERR("InitWindow failed: %08x\n", nsres
);
1725 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1726 if(NS_FAILED(nsres
))
1727 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1729 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1730 if(NS_SUCCEEDED(nsres
)) {
1731 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1732 ScrollOrientation_Y
, Scrollbar_Always
);
1733 if(NS_FAILED(nsres
))
1734 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1736 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1737 ScrollOrientation_X
, Scrollbar_Auto
);
1738 if(NS_FAILED(nsres
))
1739 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1741 nsIScrollable_Release(scrollable
);
1743 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1749 void NSContainer_Release(NSContainer
*This
)
1751 TRACE("(%p)\n", This
);
1755 ShowWindow(This
->hwnd
, SW_HIDE
);
1756 SetParent(This
->hwnd
, NULL
);
1758 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1759 nsIBaseWindow_Destroy(This
->window
);
1761 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1763 nsIWebBrowser_Release(This
->webbrowser
);
1764 This
->webbrowser
= NULL
;
1766 nsIWebNavigation_Release(This
->navigation
);
1767 This
->navigation
= NULL
;
1769 nsIBaseWindow_Release(This
->window
);
1770 This
->window
= NULL
;
1772 nsIWebBrowserFocus_Release(This
->focus
);
1775 if(This
->editor_controller
) {
1776 nsIController_Release(This
->editor_controller
);
1777 This
->editor_controller
= NULL
;
1781 nsIEditor_Release(This
->editor
);
1782 This
->editor
= NULL
;
1785 if(This
->content_listener
) {
1786 nsIURIContentListener_Release(This
->content_listener
);
1787 This
->content_listener
= NULL
;
1791 DestroyWindow(This
->hwnd
);
1795 nsIWebBrowserChrome_Release(NSWBCHROME(This
));