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"
49 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
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
*,cpp_bool
,nsIFile
**);
66 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,cpp_bool
*);
67 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,cpp_bool
*);
69 static HINSTANCE xul_handle
= NULL
;
71 static nsIServiceManager
*pServMgr
= NULL
;
72 static nsIComponentManager
*pCompMgr
= NULL
;
73 static nsIMemory
*nsmem
= NULL
;
74 static nsIFile
*profile_directory
, *plugin_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 nsresult
create_nsfile(const PRUnichar
*path
, nsIFile
**ret
)
87 nsAString_InitDepend(&str
, path
);
88 nsres
= NS_NewLocalFile(&str
, FALSE
, ret
);
89 nsAString_Finish(&str
);
92 WARN("NS_NewLocalFile failed: %08x\n", nsres
);
97 nsISimpleEnumerator nsISimpleEnumerator_iface
;
100 } nsSingletonEnumerator
;
102 static inline nsSingletonEnumerator
*impl_from_nsISimpleEnumerator(nsISimpleEnumerator
*iface
)
104 return CONTAINING_RECORD(iface
, nsSingletonEnumerator
, nsISimpleEnumerator_iface
);
107 static nsresult NSAPI
nsSingletonEnumerator_QueryInterface(nsISimpleEnumerator
*iface
, nsIIDRef riid
, void **ppv
)
109 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
111 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
112 TRACE("(%p)->(IID_nsISupports %p)\n", This
, ppv
);
113 *ppv
= &This
->nsISimpleEnumerator_iface
;
114 }else if(IsEqualGUID(&IID_nsISimpleEnumerator
, riid
)) {
115 TRACE("(%p)->(IID_nsISimpleEnumerator %p)\n", This
, ppv
);
116 *ppv
= &This
->nsISimpleEnumerator_iface
;
118 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
120 return NS_NOINTERFACE
;
123 nsISupports_AddRef((nsISupports
*)*ppv
);
127 static nsrefcnt NSAPI
nsSingletonEnumerator_AddRef(nsISimpleEnumerator
*iface
)
129 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
130 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
132 TRACE("(%p) ref=%d\n", This
, ref
);
137 static nsrefcnt NSAPI
nsSingletonEnumerator_Release(nsISimpleEnumerator
*iface
)
139 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
140 nsrefcnt ref
= InterlockedDecrement(&This
->ref
);
142 TRACE("(%p) ref=%d\n", This
, ref
);
146 nsISupports_Release(This
->value
);
153 static nsresult NSAPI
nsSingletonEnumerator_HasMoreElements(nsISimpleEnumerator
*iface
, cpp_bool
*_retval
)
155 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
157 TRACE("(%p)->()\n", This
);
159 *_retval
= This
->value
!= NULL
;
163 static nsresult NSAPI
nsSingletonEnumerator_GetNext(nsISimpleEnumerator
*iface
, nsISupports
**_retval
)
165 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
167 TRACE("(%p)->()\n", This
);
170 return NS_ERROR_UNEXPECTED
;
172 *_retval
= This
->value
;
177 static const nsISimpleEnumeratorVtbl nsSingletonEnumeratorVtbl
= {
178 nsSingletonEnumerator_QueryInterface
,
179 nsSingletonEnumerator_AddRef
,
180 nsSingletonEnumerator_Release
,
181 nsSingletonEnumerator_HasMoreElements
,
182 nsSingletonEnumerator_GetNext
185 static nsISimpleEnumerator
*create_singleton_enumerator(nsISupports
*value
)
187 nsSingletonEnumerator
*ret
;
189 ret
= heap_alloc(sizeof(*ret
));
193 ret
->nsISimpleEnumerator_iface
.lpVtbl
= &nsSingletonEnumeratorVtbl
;
197 nsISupports_AddRef(value
);
199 return &ret
->nsISimpleEnumerator_iface
;
202 static nsresult NSAPI
nsDirectoryServiceProvider2_QueryInterface(nsIDirectoryServiceProvider2
*iface
,
203 nsIIDRef riid
, void **result
)
205 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
206 TRACE("(IID_nsISupports %p)\n", result
);
208 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
209 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
211 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider2
, riid
)) {
212 TRACE("(IID_nsIDirectoryServiceProvider2 %p)\n", result
);
215 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
217 return NS_NOINTERFACE
;
220 nsISupports_AddRef((nsISupports
*)*result
);
224 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_AddRef(nsIDirectoryServiceProvider2
*iface
)
229 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_Release(nsIDirectoryServiceProvider2
*iface
)
234 static nsresult
create_profile_directory(void)
236 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
238 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
243 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
245 ERR("SHGetFolderPath failed: %08x\n", hres
);
246 return NS_ERROR_FAILURE
;
249 strcatW(path
, wine_geckoW
);
250 nsres
= create_nsfile(path
, &profile_directory
);
254 nsres
= nsIFile_Exists(profile_directory
, &exists
);
255 if(NS_FAILED(nsres
)) {
256 ERR("Exists failed: %08x\n", nsres
);
261 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
263 ERR("Create failed: %08x\n", nsres
);
269 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFile(nsIDirectoryServiceProvider2
*iface
,
270 const char *prop
, cpp_bool
*persistent
, nsIFile
**_retval
)
272 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
274 if(!strcmp(prop
, "ProfD")) {
275 if(!profile_directory
) {
278 nsres
= create_profile_directory();
283 assert(profile_directory
!= NULL
);
284 return nsIFile_Clone(profile_directory
, _retval
);
287 return NS_ERROR_FAILURE
;
290 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFiles(nsIDirectoryServiceProvider2
*iface
,
291 const char *prop
, nsISimpleEnumerator
**_retval
)
293 TRACE("(%s %p)\n", debugstr_a(prop
), _retval
);
295 if(!strcmp(prop
, "APluginsDL")) {
296 WCHAR plugin_path
[MAX_PATH
];
301 if(!plugin_directory
) {
302 static const WCHAR gecko_pluginW
[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
304 len
= GetSystemDirectoryW(plugin_path
, (sizeof(plugin_path
)-sizeof(gecko_pluginW
))/sizeof(WCHAR
)+1);
306 return NS_ERROR_UNEXPECTED
;
308 strcpyW(plugin_path
+len
, gecko_pluginW
);
309 nsres
= create_nsfile(plugin_path
, &plugin_directory
);
314 nsres
= nsIFile_Clone(plugin_directory
, &file
);
318 *_retval
= create_singleton_enumerator((nsISupports
*)file
);
319 nsIFile_Release(file
);
321 return NS_ERROR_OUT_OF_MEMORY
;
326 return NS_ERROR_FAILURE
;
329 static const nsIDirectoryServiceProvider2Vtbl nsDirectoryServiceProvider2Vtbl
= {
330 nsDirectoryServiceProvider2_QueryInterface
,
331 nsDirectoryServiceProvider2_AddRef
,
332 nsDirectoryServiceProvider2_Release
,
333 nsDirectoryServiceProvider2_GetFile
,
334 nsDirectoryServiceProvider2_GetFiles
337 static nsIDirectoryServiceProvider2 nsDirectoryServiceProvider2
=
338 { &nsDirectoryServiceProvider2Vtbl
};
340 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
345 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
347 if(msg
== WM_CREATE
) {
348 This
= *(NSContainer
**)lParam
;
349 SetPropW(hwnd
, wszTHIS
, This
);
351 This
= GetPropW(hwnd
, wszTHIS
);
356 TRACE("(%p)->(WM_SIZE)\n", This
);
358 nsres
= nsIBaseWindow_SetSize(This
->window
,
359 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
361 WARN("SetSize failed: %08x\n", nsres
);
364 case WM_PARENTNOTIFY
:
365 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
370 nsIWebBrowserFocus_Activate(This
->focus
);
374 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
378 static void register_nscontainer_class(void)
380 static WNDCLASSEXW wndclass
= {
384 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
388 wndclass
.hInstance
= hInst
;
389 nscontainer_class
= RegisterClassExW(&wndclass
);
392 static BOOL
install_wine_gecko(void)
394 PROCESS_INFORMATION pi
;
401 static const WCHAR controlW
[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
402 static const WCHAR argsW
[] =
403 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
405 len
= GetSystemDirectoryW(app
, MAX_PATH
-sizeof(controlW
)/sizeof(WCHAR
));
406 memcpy(app
+len
, controlW
, sizeof(controlW
));
408 args
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(controlW
) + sizeof(argsW
));
412 memcpy(args
, app
, len
*sizeof(WCHAR
) + sizeof(controlW
));
413 memcpy(args
+ len
+ sizeof(controlW
)/sizeof(WCHAR
)-1, argsW
, sizeof(argsW
));
415 TRACE("starting %s\n", debugstr_w(args
));
417 memset(&si
, 0, sizeof(si
));
419 ret
= CreateProcessW(app
, args
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
422 CloseHandle(pi
.hThread
);
423 WaitForSingleObject(pi
.hProcess
, INFINITE
);
424 CloseHandle(pi
.hProcess
);
430 static void set_environment(LPCWSTR gre_path
)
432 WCHAR path_env
[MAX_PATH
], buf
[20];
433 int len
, debug_level
= 0;
435 static const WCHAR pathW
[] = {'P','A','T','H',0};
436 static const WCHAR warnW
[] = {'w','a','r','n',0};
437 static const WCHAR xpcom_debug_breakW
[] =
438 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
439 static const WCHAR nspr_log_modulesW
[] =
440 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
441 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
443 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
444 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
445 len
= strlenW(path_env
);
446 path_env
[len
++] = ';';
447 strcpyW(path_env
+len
, gre_path
);
448 SetEnvironmentVariableW(pathW
, path_env
);
450 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
454 else if(WARN_ON(gecko
))
456 else if(ERR_ON(gecko
))
459 sprintfW(buf
, debug_formatW
, debug_level
);
460 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
463 static BOOL
load_xul(const PRUnichar
*gre_path
)
465 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
466 WCHAR file_name
[MAX_PATH
];
468 strcpyW(file_name
, gre_path
);
469 strcatW(file_name
, xul_dllW
);
471 TRACE("(%s)\n", debugstr_w(file_name
));
473 set_environment(gre_path
);
475 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
477 WARN("Could not load XUL: %d\n", GetLastError());
481 #define NS_DLSYM(func) \
482 func = (void *)GetProcAddress(xul_handle, #func "_P"); \
484 ERR("Could not GetProcAddress(" #func ") failed\n")
486 NS_DLSYM(NS_InitXPCOM2
);
487 NS_DLSYM(NS_ShutdownXPCOM
);
488 NS_DLSYM(NS_GetComponentRegistrar
);
489 NS_DLSYM(NS_StringContainerInit2
);
490 NS_DLSYM(NS_CStringContainerInit2
);
491 NS_DLSYM(NS_StringContainerFinish
);
492 NS_DLSYM(NS_CStringContainerFinish
);
493 NS_DLSYM(NS_StringSetData
);
494 NS_DLSYM(NS_CStringSetData
);
495 NS_DLSYM(NS_NewLocalFile
);
496 NS_DLSYM(NS_StringGetData
);
497 NS_DLSYM(NS_CStringGetData
);
501 #define NS_DLSYM(func) \
502 func = (void *)GetProcAddress(xul_handle, #func); \
504 ERR("Could not GetProcAddress(" #func ") failed\n")
506 NS_DLSYM(ccref_incr
);
507 NS_DLSYM(ccref_decr
);
508 NS_DLSYM(ccref_init
);
509 NS_DLSYM(ccref_unmark_if_purple
);
511 NS_DLSYM(describe_cc_node
);
512 NS_DLSYM(note_cc_edge
);
519 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
521 WCHAR file_name
[MAX_PATH
];
526 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
528 strcpyW(file_name
, gre_path
);
529 strcatW(file_name
, wszVersion
);
531 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
532 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
533 if(hfile
== INVALID_HANDLE_VALUE
) {
534 ERR("Could not open VERSION file\n");
538 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
542 TRACE("%s\n", debugstr_a(version
));
544 if(strcmp(version
, version_string
)) {
545 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
546 debugstr_a(version_string
));
553 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
554 const char *version
, const char *version_string
)
556 DWORD res
, type
, size
= MAX_PATH
;
557 HKEY hkey
= mshtml_key
;
559 static const WCHAR wszGeckoPath
[] =
560 {'G','e','c','k','o','P','a','t','h',0};
563 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
564 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
565 if(res
!= ERROR_SUCCESS
)
569 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
570 if(hkey
!= mshtml_key
)
572 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
575 if(!check_version(gre_path
, version_string
))
578 return load_xul(gre_path
);
581 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
587 static const WCHAR wszMshtmlKey
[] = {
588 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
589 '\\','M','S','H','T','M','L',0};
591 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
592 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
593 if(res
!= ERROR_SUCCESS
)
596 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
602 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
606 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
608 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
611 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
615 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
617 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
620 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
624 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
626 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
629 static void set_lang(nsIPrefBranch
*pref
)
632 DWORD res
, size
, type
;
635 static const WCHAR international_keyW
[] =
636 {'S','o','f','t','w','a','r','e',
637 '\\','M','i','c','r','o','s','o','f','t',
638 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
639 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
641 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
642 if(res
!= ERROR_SUCCESS
)
645 size
= sizeof(langs
);
646 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
648 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
651 TRACE("Setting lang %s\n", debugstr_a(langs
));
653 set_string_pref(pref
, "intl.accept_languages", langs
);
656 static void set_preferences(void)
661 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
662 &IID_nsIPrefBranch
, (void**)&pref
);
663 if(NS_FAILED(nsres
)) {
664 ERR("Could not get preference service: %08x\n", nsres
);
669 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
670 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
671 set_int_pref(pref
, "layout.spellcheckDefault", 0);
673 nsIPrefBranch_Release(pref
);
676 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
678 nsIComponentRegistrar
*registrar
= NULL
;
683 nsres
= create_nsfile(gre_path
, &gre_dir
);
684 if(NS_FAILED(nsres
)) {
685 FreeLibrary(xul_handle
);
689 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
690 if(NS_FAILED(nsres
)) {
691 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
692 FreeLibrary(xul_handle
);
696 strcpyW(gecko_path
, gre_path
);
697 for(ptr
= gecko_path
; *ptr
; ptr
++) {
701 gecko_path_len
= ptr
-gecko_path
;
703 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
705 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
707 nsres
= NS_GetComponentRegistrar(®istrar
);
708 if(NS_SUCCEEDED(nsres
))
709 init_nsio(pCompMgr
, registrar
);
711 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
713 init_mutation(pCompMgr
);
716 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
717 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
719 ERR("Could not get nsIMemory: %08x\n", nsres
);
722 register_nsservice(registrar
, pServMgr
);
723 nsIComponentRegistrar_Release(registrar
);
731 static CRITICAL_SECTION cs_load_gecko
;
732 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
734 0, 0, &cs_load_gecko
,
735 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
736 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
738 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
740 BOOL
load_gecko(void)
742 PRUnichar gre_path
[MAX_PATH
];
745 static DWORD loading_thread
;
749 /* load_gecko may be called recursively */
750 if(loading_thread
== GetCurrentThreadId())
751 return pCompMgr
!= NULL
;
753 EnterCriticalSection(&cs_load_gecko
);
755 if(!loading_thread
) {
756 loading_thread
= GetCurrentThreadId();
758 if(load_wine_gecko(gre_path
)
759 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
760 ret
= init_xpcom(gre_path
);
762 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
764 ret
= pCompMgr
!= NULL
;
767 LeaveCriticalSection(&cs_load_gecko
);
772 void *nsalloc(size_t size
)
774 return nsIMemory_Alloc(nsmem
, size
);
777 void nsfree(void *mem
)
779 nsIMemory_Free(nsmem
, mem
);
782 static BOOL
nsACString_Init(nsACString
*str
, const char *data
)
784 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
788 * Initializes nsACString with data owned by caller.
789 * Caller must ensure that data is valid during lifetime of string object.
791 void nsACString_InitDepend(nsACString
*str
, const char *data
)
793 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
796 void nsACString_SetData(nsACString
*str
, const char *data
)
798 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
801 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
803 return NS_CStringGetData(str
, data
, NULL
);
806 void nsACString_Finish(nsACString
*str
)
808 NS_CStringContainerFinish(str
);
811 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
813 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
817 * Initializes nsAString with data owned by caller.
818 * Caller must ensure that data is valid during lifetime of string object.
820 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
822 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
825 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
827 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
830 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
832 return NS_StringGetData(str
, data
, NULL
);
835 void nsAString_Finish(nsAString
*str
)
837 NS_StringContainerFinish(str
);
840 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
842 const PRUnichar
*str
;
844 if(NS_FAILED(nsres
)) {
845 ERR("failed: %08x\n", nsres
);
846 nsAString_Finish(nsstr
);
850 nsAString_GetData(nsstr
, &str
);
851 TRACE("ret %s\n", debugstr_w(str
));
853 *p
= SysAllocString(str
);
855 return E_OUTOFMEMORY
;
860 nsAString_Finish(nsstr
);
864 nsICommandParams
*create_nscommand_params(void)
866 nsICommandParams
*ret
= NULL
;
872 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
873 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
876 ERR("Could not get nsICommandParams\n");
881 nsIWritableVariant
*create_nsvariant(void)
883 nsIWritableVariant
*ret
= NULL
;
889 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
890 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
892 ERR("Could not get nsIVariant\n");
897 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
899 nsIInterfaceRequestor
*iface_req
;
902 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
906 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
907 nsIInterfaceRequestor_Release(iface_req
);
912 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
914 nsIDOMNodeList
*node_list
= NULL
;
915 cpp_bool has_children
= FALSE
;
916 nsIContent
*nscontent
;
920 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
922 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
923 if(NS_FAILED(nsres
)) {
924 ERR("GetType failed: %08x\n", nsres
);
928 if(type
!= DOCUMENT_NODE
) {
929 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
930 if(NS_FAILED(nsres
)) {
931 ERR("Could not get nsIContent interface: %08x\n", nsres
);
938 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
941 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
944 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
946 case DOCUMENT_NODE
: {
948 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
949 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
950 nsIDocument_Release(nsdoc
);
953 case DOCUMENT_TYPE_NODE
:
954 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
956 case DOCUMENT_FRAGMENT_NODE
:
959 FIXME("Unhandled type %u\n", type
);
963 PRUint32 child_cnt
, i
;
964 nsIDOMNode
*child_node
;
966 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
967 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
969 for(i
=0; i
<child_cnt
; i
++) {
970 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
971 if(NS_SUCCEEDED(nsres
)) {
972 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
973 nsIDOMNode_Release(child_node
);
975 ERR("Item failed: %08x\n", nsres
);
979 nsIDOMNodeList_Release(node_list
);
982 if(type
== ELEMENT_NODE
)
983 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
985 if(type
!= DOCUMENT_NODE
)
986 nsIContent_Release(nscontent
);
990 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
992 nsIContentSerializer
*serializer
;
996 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
997 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
998 (void**)&serializer
);
999 if(NS_FAILED(nsres
)) {
1000 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1004 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1005 if(NS_FAILED(nsres
))
1006 ERR("Init failed: %08x\n", nsres
);
1008 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1009 if(SUCCEEDED(hres
)) {
1010 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1011 if(NS_FAILED(nsres
))
1012 ERR("Flush failed: %08x\n", nsres
);
1015 nsIContentSerializer_Release(serializer
);
1019 void get_editor_controller(NSContainer
*This
)
1021 nsIEditingSession
*editing_session
= NULL
;
1022 nsIControllerContext
*ctrlctx
;
1026 nsIEditor_Release(This
->editor
);
1027 This
->editor
= NULL
;
1030 if(This
->editor_controller
) {
1031 nsIController_Release(This
->editor_controller
);
1032 This
->editor_controller
= NULL
;
1035 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1036 (void**)&editing_session
);
1037 if(NS_FAILED(nsres
)) {
1038 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1042 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1043 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
1044 nsIEditingSession_Release(editing_session
);
1045 if(NS_FAILED(nsres
)) {
1046 ERR("Could not get editor: %08x\n", nsres
);
1050 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1051 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1052 if(NS_SUCCEEDED(nsres
)) {
1053 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1054 if(NS_FAILED(nsres
))
1055 ERR("SetCommandContext failed: %08x\n", nsres
);
1056 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1057 (void**)&This
->editor_controller
);
1058 nsIControllerContext_Release(ctrlctx
);
1059 if(NS_FAILED(nsres
))
1060 ERR("Could not get nsIController interface: %08x\n", nsres
);
1062 ERR("Could not create edit controller: %08x\n", nsres
);
1066 void close_gecko(void)
1071 init_mutation(NULL
);
1073 if(profile_directory
) {
1074 nsIFile_Release(profile_directory
);
1075 profile_directory
= NULL
;
1078 if(plugin_directory
) {
1079 nsIFile_Release(plugin_directory
);
1080 plugin_directory
= NULL
;
1084 nsIComponentManager_Release(pCompMgr
);
1087 nsIServiceManager_Release(pServMgr
);
1090 nsIMemory_Release(nsmem
);
1092 /* Gecko doesn't really support being unloaded */
1093 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1095 DeleteCriticalSection(&cs_load_gecko
);
1098 BOOL
is_gecko_path(const char *path
)
1103 buf
= heap_strdupUtoW(path
);
1104 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1107 buf
[gecko_path_len
] = 0;
1108 for(ptr
= buf
; *ptr
; ptr
++) {
1113 ret
= !strcmpiW(buf
, gecko_path
);
1118 struct nsWeakReference
{
1119 nsIWeakReference nsIWeakReference_iface
;
1123 NSContainer
*nscontainer
;
1126 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1128 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1131 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1132 nsIIDRef riid
, void **result
)
1134 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1136 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1137 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1138 *result
= &This
->nsIWeakReference_iface
;
1139 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1140 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1141 *result
= &This
->nsIWeakReference_iface
;
1143 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1145 return NS_NOINTERFACE
;
1148 nsISupports_AddRef((nsISupports
*)*result
);
1152 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1154 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1155 LONG ref
= InterlockedIncrement(&This
->ref
);
1157 TRACE("(%p) ref=%d\n", This
, ref
);
1162 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1164 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1165 LONG ref
= InterlockedIncrement(&This
->ref
);
1167 TRACE("(%p) ref=%d\n", This
, ref
);
1170 assert(!This
->nscontainer
);
1177 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1178 const nsIID
*riid
, void **result
)
1180 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1182 if(!This
->nscontainer
)
1183 return NS_ERROR_NULL_POINTER
;
1185 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1188 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1189 nsWeakReference_QueryInterface
,
1190 nsWeakReference_AddRef
,
1191 nsWeakReference_Release
,
1192 nsWeakReference_QueryReferent
1195 /**********************************************************
1196 * nsIWebBrowserChrome interface
1199 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1201 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1204 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1205 nsIIDRef riid
, void **result
)
1207 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1210 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1211 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1212 *result
= &This
->nsIWebBrowserChrome_iface
;
1213 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1214 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1215 *result
= &This
->nsIWebBrowserChrome_iface
;
1216 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1217 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1218 *result
= &This
->nsIContextMenuListener_iface
;
1219 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1220 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1221 *result
= &This
->nsIURIContentListener_iface
;
1222 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1223 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1224 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1225 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1226 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1227 *result
= &This
->nsITooltipListener_iface
;
1228 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1229 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1230 *result
= &This
->nsIInterfaceRequestor_iface
;
1231 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1232 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1233 *result
= &This
->nsISupportsWeakReference_iface
;
1237 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1241 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1242 return NS_NOINTERFACE
;
1245 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1247 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1248 LONG ref
= InterlockedIncrement(&This
->ref
);
1250 TRACE("(%p) ref=%d\n", This
, ref
);
1255 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1257 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1258 LONG ref
= InterlockedDecrement(&This
->ref
);
1260 TRACE("(%p) ref=%d\n", This
, ref
);
1264 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1265 if(This
->weak_reference
) {
1266 This
->weak_reference
->nscontainer
= NULL
;
1267 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1275 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1276 PRUint32 statusType
, const PRUnichar
*status
)
1278 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1279 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1283 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1284 nsIWebBrowser
**aWebBrowser
)
1286 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1288 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1291 return NS_ERROR_INVALID_ARG
;
1293 if(This
->webbrowser
)
1294 nsIWebBrowser_AddRef(This
->webbrowser
);
1295 *aWebBrowser
= This
->webbrowser
;
1299 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1300 nsIWebBrowser
*aWebBrowser
)
1302 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1304 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1306 if(aWebBrowser
!= This
->webbrowser
)
1307 ERR("Wrong nsWebBrowser!\n");
1312 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1313 PRUint32
*aChromeFlags
)
1315 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1316 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1317 return NS_ERROR_NOT_IMPLEMENTED
;
1320 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1321 PRUint32 aChromeFlags
)
1323 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1324 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1325 return NS_ERROR_NOT_IMPLEMENTED
;
1328 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1330 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1331 TRACE("(%p)\n", This
);
1332 return NS_ERROR_NOT_IMPLEMENTED
;
1335 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1336 PRInt32 aCX
, PRInt32 aCY
)
1338 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1339 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1340 return NS_ERROR_NOT_IMPLEMENTED
;
1343 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1345 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1346 WARN("(%p)\n", This
);
1347 return NS_ERROR_NOT_IMPLEMENTED
;
1350 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1352 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1353 WARN("(%p)->(%p)\n", This
, _retval
);
1354 return NS_ERROR_NOT_IMPLEMENTED
;
1357 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1360 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1361 WARN("(%p)->(%08x)\n", This
, aStatus
);
1362 return NS_ERROR_NOT_IMPLEMENTED
;
1365 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1366 nsWebBrowserChrome_QueryInterface
,
1367 nsWebBrowserChrome_AddRef
,
1368 nsWebBrowserChrome_Release
,
1369 nsWebBrowserChrome_SetStatus
,
1370 nsWebBrowserChrome_GetWebBrowser
,
1371 nsWebBrowserChrome_SetWebBrowser
,
1372 nsWebBrowserChrome_GetChromeFlags
,
1373 nsWebBrowserChrome_SetChromeFlags
,
1374 nsWebBrowserChrome_DestroyBrowserWindow
,
1375 nsWebBrowserChrome_SizeBrowserTo
,
1376 nsWebBrowserChrome_ShowAsModal
,
1377 nsWebBrowserChrome_IsWindowModal
,
1378 nsWebBrowserChrome_ExitModalEventLoop
1381 /**********************************************************
1382 * nsIContextMenuListener interface
1385 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1387 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1390 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1391 nsIIDRef riid
, void **result
)
1393 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1394 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1397 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1399 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1400 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1403 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1405 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1406 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1409 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1410 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1412 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1413 nsIDOMMouseEvent
*event
;
1416 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1420 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1422 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
, NULL
);
1424 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1425 if(NS_FAILED(nsres
)) {
1426 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1430 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1431 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1432 nsIDOMMouseEvent_Release(event
);
1434 switch(aContextFlags
) {
1436 case CONTEXT_DOCUMENT
:
1438 dwID
= CONTEXT_MENU_DEFAULT
;
1441 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1442 dwID
= CONTEXT_MENU_IMAGE
;
1445 dwID
= CONTEXT_MENU_ANCHOR
;
1448 dwID
= CONTEXT_MENU_CONTROL
;
1451 FIXME("aContextFlags=%08x\n", aContextFlags
);
1454 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1456 return NS_ERROR_FAILURE
;
1458 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1463 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1464 nsContextMenuListener_QueryInterface
,
1465 nsContextMenuListener_AddRef
,
1466 nsContextMenuListener_Release
,
1467 nsContextMenuListener_OnShowContextMenu
1470 /**********************************************************
1471 * nsIURIContentListener interface
1474 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1476 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1479 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1480 nsIIDRef riid
, void **result
)
1482 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1483 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1486 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1488 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1489 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1492 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1494 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1495 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1498 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1499 nsIURI
*aURI
, cpp_bool
*_retval
)
1501 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1502 nsACString spec_str
;
1506 nsACString_Init(&spec_str
, NULL
);
1507 nsIURI_GetSpec(aURI
, &spec_str
);
1508 nsACString_GetData(&spec_str
, &spec
);
1510 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1512 nsACString_Finish(&spec_str
);
1514 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1515 if(NS_FAILED(nsres
))
1518 return !*_retval
&& This
->content_listener
1519 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1523 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1524 const char *aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1525 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1527 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1529 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1530 aRequest
, aContentHandler
, _retval
);
1532 return This
->content_listener
1533 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1534 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1535 : NS_ERROR_NOT_IMPLEMENTED
;
1538 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1539 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1541 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1543 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1545 /* FIXME: Should we do something here? */
1548 return This
->content_listener
1549 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1550 aDesiredContentType
, _retval
)
1554 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1555 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1558 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1560 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1561 aDesiredContentType
, _retval
);
1563 return This
->content_listener
1564 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1565 aIsContentPreferred
, aDesiredContentType
, _retval
)
1566 : NS_ERROR_NOT_IMPLEMENTED
;
1569 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1570 nsISupports
**aLoadCookie
)
1572 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1574 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1576 return This
->content_listener
1577 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1578 : NS_ERROR_NOT_IMPLEMENTED
;
1581 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1582 nsISupports
*aLoadCookie
)
1584 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1586 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1588 return This
->content_listener
1589 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1590 : NS_ERROR_NOT_IMPLEMENTED
;
1593 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1594 nsIURIContentListener
**aParentContentListener
)
1596 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1598 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1600 if(This
->content_listener
)
1601 nsIURIContentListener_AddRef(This
->content_listener
);
1603 *aParentContentListener
= This
->content_listener
;
1607 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1608 nsIURIContentListener
*aParentContentListener
)
1610 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1612 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1614 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1617 if(This
->content_listener
)
1618 nsIURIContentListener_Release(This
->content_listener
);
1620 This
->content_listener
= aParentContentListener
;
1621 if(This
->content_listener
)
1622 nsIURIContentListener_AddRef(This
->content_listener
);
1627 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1628 nsURIContentListener_QueryInterface
,
1629 nsURIContentListener_AddRef
,
1630 nsURIContentListener_Release
,
1631 nsURIContentListener_OnStartURIOpen
,
1632 nsURIContentListener_DoContent
,
1633 nsURIContentListener_IsPreferred
,
1634 nsURIContentListener_CanHandleContent
,
1635 nsURIContentListener_GetLoadCookie
,
1636 nsURIContentListener_SetLoadCookie
,
1637 nsURIContentListener_GetParentContentListener
,
1638 nsURIContentListener_SetParentContentListener
1641 /**********************************************************
1642 * nsIEmbeddinSiteWindow interface
1645 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1647 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1650 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1651 nsIIDRef riid
, void **result
)
1653 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1654 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1657 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1659 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1660 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1663 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1665 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1666 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1669 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1670 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1672 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1673 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1674 return NS_ERROR_NOT_IMPLEMENTED
;
1677 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1678 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1680 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1681 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1682 return NS_ERROR_NOT_IMPLEMENTED
;
1685 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1687 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1689 TRACE("(%p)\n", This
);
1691 return nsIBaseWindow_SetFocus(This
->window
);
1694 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1695 cpp_bool
*aVisibility
)
1697 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1699 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1701 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1705 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1706 cpp_bool aVisibility
)
1708 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1710 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1715 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1718 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1719 WARN("(%p)->(%p)\n", This
, aTitle
);
1720 return NS_ERROR_NOT_IMPLEMENTED
;
1723 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1724 const PRUnichar
*aTitle
)
1726 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1727 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1728 return NS_ERROR_NOT_IMPLEMENTED
;
1731 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1734 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1736 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1738 *aSiteWindow
= This
->hwnd
;
1742 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1743 nsEmbeddingSiteWindow_QueryInterface
,
1744 nsEmbeddingSiteWindow_AddRef
,
1745 nsEmbeddingSiteWindow_Release
,
1746 nsEmbeddingSiteWindow_SetDimensions
,
1747 nsEmbeddingSiteWindow_GetDimensions
,
1748 nsEmbeddingSiteWindow_SetFocus
,
1749 nsEmbeddingSiteWindow_GetVisibility
,
1750 nsEmbeddingSiteWindow_SetVisibility
,
1751 nsEmbeddingSiteWindow_GetTitle
,
1752 nsEmbeddingSiteWindow_SetTitle
,
1753 nsEmbeddingSiteWindow_GetSiteWindow
1756 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1758 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1761 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1764 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1765 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1768 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1770 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1771 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1774 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1776 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1777 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1780 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1781 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1783 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1786 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1791 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1793 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1796 hide_tooltip(This
->doc
);
1801 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1802 nsTooltipListener_QueryInterface
,
1803 nsTooltipListener_AddRef
,
1804 nsTooltipListener_Release
,
1805 nsTooltipListener_OnShowTooltip
,
1806 nsTooltipListener_OnHideTooltip
1809 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1811 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1814 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1815 nsIIDRef riid
, void **result
)
1817 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1818 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1821 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1823 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1824 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1827 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1829 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1830 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1833 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1834 nsIIDRef riid
, void **result
)
1836 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1838 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1839 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1840 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1843 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1846 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1847 nsInterfaceRequestor_QueryInterface
,
1848 nsInterfaceRequestor_AddRef
,
1849 nsInterfaceRequestor_Release
,
1850 nsInterfaceRequestor_GetInterface
1853 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1855 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1858 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1859 nsIIDRef riid
, void **result
)
1861 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1862 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1865 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1867 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1868 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1871 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1873 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1874 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1877 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1878 nsIWeakReference
**_retval
)
1880 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1882 TRACE("(%p)->(%p)\n", This
, _retval
);
1884 if(!This
->weak_reference
) {
1885 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1886 if(!This
->weak_reference
)
1887 return NS_ERROR_OUT_OF_MEMORY
;
1889 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1890 This
->weak_reference
->ref
= 1;
1891 This
->weak_reference
->nscontainer
= This
;
1894 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1895 nsIWeakReference_AddRef(*_retval
);
1899 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1900 nsSupportsWeakReference_QueryInterface
,
1901 nsSupportsWeakReference_AddRef
,
1902 nsSupportsWeakReference_Release
,
1903 nsSupportsWeakReference_GetWeakReference
1906 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1908 nsIWebBrowserSetup
*wbsetup
;
1909 nsIScrollable
*scrollable
;
1912 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1913 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1914 if(NS_FAILED(nsres
)) {
1915 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1919 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1920 if(NS_FAILED(nsres
)) {
1921 ERR("SetContainerWindow failed: %08x\n", nsres
);
1925 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1926 (void**)&nscontainer
->window
);
1927 if(NS_FAILED(nsres
)) {
1928 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1932 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
1934 if(NS_SUCCEEDED(nsres
)) {
1935 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1936 nsIWebBrowserSetup_Release(wbsetup
);
1937 if(NS_FAILED(nsres
)) {
1938 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1942 ERR("Could not get nsIWebBrowserSetup interface\n");
1946 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
1947 (void**)&nscontainer
->navigation
);
1948 if(NS_FAILED(nsres
)) {
1949 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1953 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
1954 (void**)&nscontainer
->focus
);
1955 if(NS_FAILED(nsres
)) {
1956 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1960 if(!nscontainer_class
) {
1961 register_nscontainer_class();
1962 if(!nscontainer_class
)
1966 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1967 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1968 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
1969 if(!nscontainer
->hwnd
) {
1970 WARN("Could not create window\n");
1974 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
1975 if(NS_SUCCEEDED(nsres
)) {
1976 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
1977 if(NS_FAILED(nsres
)) {
1978 WARN("Creating window failed: %08x\n", nsres
);
1982 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
1983 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
1985 ERR("InitWindow failed: %08x\n", nsres
);
1989 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
1990 &nscontainer
->nsIURIContentListener_iface
);
1991 if(NS_FAILED(nsres
))
1992 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1994 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1995 if(NS_SUCCEEDED(nsres
)) {
1996 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1997 ScrollOrientation_Y
, Scrollbar_Always
);
1998 if(NS_FAILED(nsres
))
1999 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2001 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2002 ScrollOrientation_X
, Scrollbar_Auto
);
2003 if(NS_FAILED(nsres
))
2004 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2006 nsIScrollable_Release(scrollable
);
2008 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2014 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2020 return CLASS_E_CLASSNOTAVAILABLE
;
2022 ret
= heap_alloc_zero(sizeof(NSContainer
));
2024 return E_OUTOFMEMORY
;
2026 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2027 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2028 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2029 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2030 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2031 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2032 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2037 hres
= init_nscontainer(ret
);
2041 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2045 void NSContainer_Release(NSContainer
*This
)
2047 TRACE("(%p)\n", This
);
2051 ShowWindow(This
->hwnd
, SW_HIDE
);
2052 SetParent(This
->hwnd
, NULL
);
2054 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2055 nsIBaseWindow_Destroy(This
->window
);
2057 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2059 nsIWebBrowser_Release(This
->webbrowser
);
2060 This
->webbrowser
= NULL
;
2062 nsIWebNavigation_Release(This
->navigation
);
2063 This
->navigation
= NULL
;
2065 nsIBaseWindow_Release(This
->window
);
2066 This
->window
= NULL
;
2068 nsIWebBrowserFocus_Release(This
->focus
);
2071 if(This
->editor_controller
) {
2072 nsIController_Release(This
->editor_controller
);
2073 This
->editor_controller
= NULL
;
2077 nsIEditor_Release(This
->editor
);
2078 This
->editor
= NULL
;
2081 if(This
->content_listener
) {
2082 nsIURIContentListener_Release(This
->content_listener
);
2083 This
->content_listener
= NULL
;
2087 DestroyWindow(This
->hwnd
);
2091 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);