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
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 WINE_DECLARE_DEBUG_CHANNEL(gecko
);
43 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
44 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
45 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
46 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
47 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
48 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
49 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
51 #define NS_CATEGORYMANAGER_CONTRACTID "@mozilla.org/categorymanager;1"
53 #define PR_UINT32_MAX 0xffffffff
55 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
56 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
58 typedef UINT32 PRUint32
;
60 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
61 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
62 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
63 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
64 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
65 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
66 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
67 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
68 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
69 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,cpp_bool
,nsIFile
**);
70 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,cpp_bool
*);
71 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,cpp_bool
*);
73 static HINSTANCE xul_handle
= NULL
;
75 static nsIServiceManager
*pServMgr
= NULL
;
76 static nsIComponentManager
*pCompMgr
= NULL
;
77 static nsICategoryManager
*cat_mgr
;
78 static nsIMemory
*nsmem
= NULL
;
79 static nsIFile
*profile_directory
, *plugin_directory
;
81 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
83 static ATOM nscontainer_class
;
84 static WCHAR gecko_path
[MAX_PATH
];
85 static unsigned gecko_path_len
;
87 nsresult
create_nsfile(const PRUnichar
*path
, nsIFile
**ret
)
92 nsAString_InitDepend(&str
, path
);
93 nsres
= NS_NewLocalFile(&str
, FALSE
, ret
);
94 nsAString_Finish(&str
);
97 WARN("NS_NewLocalFile failed: %08x\n", nsres
);
102 nsISimpleEnumerator nsISimpleEnumerator_iface
;
105 } nsSingletonEnumerator
;
107 static inline nsSingletonEnumerator
*impl_from_nsISimpleEnumerator(nsISimpleEnumerator
*iface
)
109 return CONTAINING_RECORD(iface
, nsSingletonEnumerator
, nsISimpleEnumerator_iface
);
112 static nsresult NSAPI
nsSingletonEnumerator_QueryInterface(nsISimpleEnumerator
*iface
, nsIIDRef riid
, void **ppv
)
114 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
116 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
117 TRACE("(%p)->(IID_nsISupports %p)\n", This
, ppv
);
118 *ppv
= &This
->nsISimpleEnumerator_iface
;
119 }else if(IsEqualGUID(&IID_nsISimpleEnumerator
, riid
)) {
120 TRACE("(%p)->(IID_nsISimpleEnumerator %p)\n", This
, ppv
);
121 *ppv
= &This
->nsISimpleEnumerator_iface
;
123 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
125 return NS_NOINTERFACE
;
128 nsISupports_AddRef((nsISupports
*)*ppv
);
132 static nsrefcnt NSAPI
nsSingletonEnumerator_AddRef(nsISimpleEnumerator
*iface
)
134 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
135 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
137 TRACE("(%p) ref=%d\n", This
, ref
);
142 static nsrefcnt NSAPI
nsSingletonEnumerator_Release(nsISimpleEnumerator
*iface
)
144 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
145 nsrefcnt ref
= InterlockedDecrement(&This
->ref
);
147 TRACE("(%p) ref=%d\n", This
, ref
);
151 nsISupports_Release(This
->value
);
158 static nsresult NSAPI
nsSingletonEnumerator_HasMoreElements(nsISimpleEnumerator
*iface
, cpp_bool
*_retval
)
160 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
162 TRACE("(%p)->()\n", This
);
164 *_retval
= This
->value
!= NULL
;
168 static nsresult NSAPI
nsSingletonEnumerator_GetNext(nsISimpleEnumerator
*iface
, nsISupports
**_retval
)
170 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
172 TRACE("(%p)->()\n", This
);
175 return NS_ERROR_UNEXPECTED
;
177 *_retval
= This
->value
;
182 static const nsISimpleEnumeratorVtbl nsSingletonEnumeratorVtbl
= {
183 nsSingletonEnumerator_QueryInterface
,
184 nsSingletonEnumerator_AddRef
,
185 nsSingletonEnumerator_Release
,
186 nsSingletonEnumerator_HasMoreElements
,
187 nsSingletonEnumerator_GetNext
190 static nsISimpleEnumerator
*create_singleton_enumerator(nsISupports
*value
)
192 nsSingletonEnumerator
*ret
;
194 ret
= heap_alloc(sizeof(*ret
));
198 ret
->nsISimpleEnumerator_iface
.lpVtbl
= &nsSingletonEnumeratorVtbl
;
202 nsISupports_AddRef(value
);
204 return &ret
->nsISimpleEnumerator_iface
;
207 static nsresult NSAPI
nsDirectoryServiceProvider2_QueryInterface(nsIDirectoryServiceProvider2
*iface
,
208 nsIIDRef riid
, void **result
)
210 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
211 TRACE("(IID_nsISupports %p)\n", result
);
213 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
214 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
216 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider2
, riid
)) {
217 TRACE("(IID_nsIDirectoryServiceProvider2 %p)\n", result
);
220 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
222 return NS_NOINTERFACE
;
225 nsISupports_AddRef((nsISupports
*)*result
);
229 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_AddRef(nsIDirectoryServiceProvider2
*iface
)
234 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_Release(nsIDirectoryServiceProvider2
*iface
)
239 static nsresult
create_profile_directory(void)
241 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
243 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
248 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
250 ERR("SHGetFolderPath failed: %08x\n", hres
);
251 return NS_ERROR_FAILURE
;
254 strcatW(path
, wine_geckoW
);
255 nsres
= create_nsfile(path
, &profile_directory
);
259 nsres
= nsIFile_Exists(profile_directory
, &exists
);
260 if(NS_FAILED(nsres
)) {
261 ERR("Exists failed: %08x\n", nsres
);
266 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
268 ERR("Create failed: %08x\n", nsres
);
274 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFile(nsIDirectoryServiceProvider2
*iface
,
275 const char *prop
, cpp_bool
*persistent
, nsIFile
**_retval
)
277 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
279 if(!strcmp(prop
, "ProfD")) {
280 if(!profile_directory
) {
283 nsres
= create_profile_directory();
288 assert(profile_directory
!= NULL
);
289 return nsIFile_Clone(profile_directory
, _retval
);
293 return NS_ERROR_FAILURE
;
296 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFiles(nsIDirectoryServiceProvider2
*iface
,
297 const char *prop
, nsISimpleEnumerator
**_retval
)
299 TRACE("(%s %p)\n", debugstr_a(prop
), _retval
);
301 if(!strcmp(prop
, "APluginsDL")) {
302 WCHAR plugin_path
[MAX_PATH
];
307 if(!plugin_directory
) {
308 static const WCHAR gecko_pluginW
[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
310 len
= GetSystemDirectoryW(plugin_path
, (sizeof(plugin_path
)-sizeof(gecko_pluginW
))/sizeof(WCHAR
)+1);
312 return NS_ERROR_UNEXPECTED
;
314 strcpyW(plugin_path
+len
, gecko_pluginW
);
315 nsres
= create_nsfile(plugin_path
, &plugin_directory
);
316 if(NS_FAILED(nsres
)) {
322 nsres
= nsIFile_Clone(plugin_directory
, &file
);
326 *_retval
= create_singleton_enumerator((nsISupports
*)file
);
327 nsIFile_Release(file
);
329 return NS_ERROR_OUT_OF_MEMORY
;
335 return NS_ERROR_FAILURE
;
338 static const nsIDirectoryServiceProvider2Vtbl nsDirectoryServiceProvider2Vtbl
= {
339 nsDirectoryServiceProvider2_QueryInterface
,
340 nsDirectoryServiceProvider2_AddRef
,
341 nsDirectoryServiceProvider2_Release
,
342 nsDirectoryServiceProvider2_GetFile
,
343 nsDirectoryServiceProvider2_GetFiles
346 static nsIDirectoryServiceProvider2 nsDirectoryServiceProvider2
=
347 { &nsDirectoryServiceProvider2Vtbl
};
349 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
354 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
356 if(msg
== WM_CREATE
) {
357 This
= *(NSContainer
**)lParam
;
358 SetPropW(hwnd
, wszTHIS
, This
);
360 This
= GetPropW(hwnd
, wszTHIS
);
365 TRACE("(%p)->(WM_SIZE)\n", This
);
367 nsres
= nsIBaseWindow_SetSize(This
->window
,
368 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
370 WARN("SetSize failed: %08x\n", nsres
);
373 case WM_PARENTNOTIFY
:
374 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
379 nsIWebBrowserFocus_Activate(This
->focus
);
383 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
387 static void register_nscontainer_class(void)
389 static WNDCLASSEXW wndclass
= {
393 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
397 wndclass
.hInstance
= hInst
;
398 nscontainer_class
= RegisterClassExW(&wndclass
);
401 static BOOL
install_wine_gecko(void)
403 PROCESS_INFORMATION pi
;
410 static const WCHAR controlW
[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
411 static const WCHAR argsW
[] =
412 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
414 len
= GetSystemDirectoryW(app
, MAX_PATH
-sizeof(controlW
)/sizeof(WCHAR
));
415 memcpy(app
+len
, controlW
, sizeof(controlW
));
417 args
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(controlW
) + sizeof(argsW
));
421 memcpy(args
, app
, len
*sizeof(WCHAR
) + sizeof(controlW
));
422 memcpy(args
+ len
+ sizeof(controlW
)/sizeof(WCHAR
)-1, argsW
, sizeof(argsW
));
424 TRACE("starting %s\n", debugstr_w(args
));
426 memset(&si
, 0, sizeof(si
));
428 ret
= CreateProcessW(app
, args
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
431 CloseHandle(pi
.hThread
);
432 WaitForSingleObject(pi
.hProcess
, INFINITE
);
433 CloseHandle(pi
.hProcess
);
439 static void set_environment(LPCWSTR gre_path
)
441 WCHAR path_env
[MAX_PATH
], buf
[20];
442 int len
, debug_level
= 0;
444 static const WCHAR pathW
[] = {'P','A','T','H',0};
445 static const WCHAR warnW
[] = {'w','a','r','n',0};
446 static const WCHAR xpcom_debug_breakW
[] =
447 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
448 static const WCHAR nspr_log_modulesW
[] =
449 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
450 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
452 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
453 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
454 len
= strlenW(path_env
);
455 path_env
[len
++] = ';';
456 strcpyW(path_env
+len
, gre_path
);
457 SetEnvironmentVariableW(pathW
, path_env
);
459 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
463 else if(WARN_ON(gecko
))
465 else if(ERR_ON(gecko
))
468 sprintfW(buf
, debug_formatW
, debug_level
);
469 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
472 static BOOL
load_xul(const PRUnichar
*gre_path
)
474 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
475 WCHAR file_name
[MAX_PATH
];
477 strcpyW(file_name
, gre_path
);
478 strcatW(file_name
, xul_dllW
);
480 TRACE("(%s)\n", debugstr_w(file_name
));
482 set_environment(gre_path
);
484 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
486 WARN("Could not load XUL: %d\n", GetLastError());
490 #define NS_DLSYM(func) \
491 func = (void *)GetProcAddress(xul_handle, #func); \
493 ERR("Could not GetProcAddress(" #func ") failed\n")
495 NS_DLSYM(NS_InitXPCOM2
);
496 NS_DLSYM(NS_ShutdownXPCOM
);
497 NS_DLSYM(NS_GetComponentRegistrar
);
498 NS_DLSYM(NS_StringContainerInit2
);
499 NS_DLSYM(NS_CStringContainerInit2
);
500 NS_DLSYM(NS_StringContainerFinish
);
501 NS_DLSYM(NS_CStringContainerFinish
);
502 NS_DLSYM(NS_StringSetData
);
503 NS_DLSYM(NS_CStringSetData
);
504 NS_DLSYM(NS_NewLocalFile
);
505 NS_DLSYM(NS_StringGetData
);
506 NS_DLSYM(NS_CStringGetData
);
510 #define NS_DLSYM(func) \
511 func = (void *)GetProcAddress(xul_handle, #func); \
513 ERR("Could not GetProcAddress(" #func ") failed\n")
515 NS_DLSYM(ccref_incr
);
516 NS_DLSYM(ccref_decr
);
517 NS_DLSYM(ccref_init
);
518 NS_DLSYM(ccref_unmark_if_purple
);
520 NS_DLSYM(describe_cc_node
);
521 NS_DLSYM(note_cc_edge
);
528 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
530 WCHAR file_name
[MAX_PATH
];
535 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
537 strcpyW(file_name
, gre_path
);
538 strcatW(file_name
, wszVersion
);
540 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
541 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
542 if(hfile
== INVALID_HANDLE_VALUE
) {
543 ERR("Could not open VERSION file\n");
547 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
551 TRACE("%s\n", debugstr_a(version
));
553 if(strcmp(version
, version_string
)) {
554 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
555 debugstr_a(version_string
));
562 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
563 const char *version
, const char *version_string
)
565 DWORD res
, type
, size
= MAX_PATH
;
566 HKEY hkey
= mshtml_key
;
568 static const WCHAR wszGeckoPath
[] =
569 {'G','e','c','k','o','P','a','t','h',0};
572 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
573 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
574 if(res
!= ERROR_SUCCESS
)
578 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
579 if(hkey
!= mshtml_key
)
581 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
584 if(!check_version(gre_path
, version_string
))
587 return load_xul(gre_path
);
590 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
596 static const WCHAR wszMshtmlKey
[] = {
597 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
598 '\\','M','S','H','T','M','L',0};
600 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
601 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
602 if(res
!= ERROR_SUCCESS
)
605 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
611 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
615 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
617 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
620 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
624 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
626 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
629 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
633 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
635 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
638 static void set_lang(nsIPrefBranch
*pref
)
641 DWORD res
, size
, type
;
644 static const WCHAR international_keyW
[] =
645 {'S','o','f','t','w','a','r','e',
646 '\\','M','i','c','r','o','s','o','f','t',
647 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
648 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
650 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
651 if(res
!= ERROR_SUCCESS
)
654 size
= sizeof(langs
);
655 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
657 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
660 TRACE("Setting lang %s\n", debugstr_a(langs
));
662 set_string_pref(pref
, "intl.accept_languages", langs
);
665 static void set_preferences(void)
670 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
671 &IID_nsIPrefBranch
, (void**)&pref
);
672 if(NS_FAILED(nsres
)) {
673 ERR("Could not get preference service: %08x\n", nsres
);
678 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
679 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
680 set_int_pref(pref
, "layout.spellcheckDefault", 0);
682 nsIPrefBranch_Release(pref
);
685 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
687 nsIComponentRegistrar
*registrar
= NULL
;
692 nsres
= create_nsfile(gre_path
, &gre_dir
);
693 if(NS_FAILED(nsres
)) {
694 FreeLibrary(xul_handle
);
698 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
699 if(NS_FAILED(nsres
)) {
700 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
701 FreeLibrary(xul_handle
);
705 strcpyW(gecko_path
, gre_path
);
706 for(ptr
= gecko_path
; *ptr
; ptr
++) {
710 gecko_path_len
= ptr
-gecko_path
;
712 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
714 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
716 nsres
= NS_GetComponentRegistrar(®istrar
);
717 if(NS_SUCCEEDED(nsres
))
718 init_nsio(pCompMgr
, registrar
);
720 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
722 init_mutation(pCompMgr
);
725 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
726 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
728 ERR("Could not get nsIMemory: %08x\n", nsres
);
730 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_CATEGORYMANAGER_CONTRACTID
,
731 &IID_nsICategoryManager
, (void**)&cat_mgr
);
733 ERR("Could not get category manager service: %08x\n", nsres
);
736 register_nsservice(registrar
, pServMgr
);
737 nsIComponentRegistrar_Release(registrar
);
745 static CRITICAL_SECTION cs_load_gecko
;
746 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
748 0, 0, &cs_load_gecko
,
749 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
750 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
752 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
754 BOOL
load_gecko(void)
756 PRUnichar gre_path
[MAX_PATH
];
759 static DWORD loading_thread
;
763 /* load_gecko may be called recursively */
764 if(loading_thread
== GetCurrentThreadId())
765 return pCompMgr
!= NULL
;
767 EnterCriticalSection(&cs_load_gecko
);
769 if(!loading_thread
) {
770 loading_thread
= GetCurrentThreadId();
772 if(load_wine_gecko(gre_path
)
773 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
774 ret
= init_xpcom(gre_path
);
776 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
778 ret
= pCompMgr
!= NULL
;
781 LeaveCriticalSection(&cs_load_gecko
);
786 void *nsalloc(size_t size
)
788 return nsIMemory_Alloc(nsmem
, size
);
791 void nsfree(void *mem
)
793 nsIMemory_Free(nsmem
, mem
);
796 static BOOL
nsACString_Init(nsACString
*str
, const char *data
)
798 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
802 * Initializes nsACString with data owned by caller.
803 * Caller must ensure that data is valid during lifetime of string object.
805 void nsACString_InitDepend(nsACString
*str
, const char *data
)
807 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
810 void nsACString_SetData(nsACString
*str
, const char *data
)
812 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
815 UINT32
nsACString_GetData(const nsACString
*str
, const char **data
)
817 return NS_CStringGetData(str
, data
, NULL
);
820 void nsACString_Finish(nsACString
*str
)
822 NS_CStringContainerFinish(str
);
825 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
827 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
831 * Initializes nsAString with data owned by caller.
832 * Caller must ensure that data is valid during lifetime of string object.
834 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
836 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
839 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
841 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
844 UINT32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
846 return NS_StringGetData(str
, data
, NULL
);
849 void nsAString_Finish(nsAString
*str
)
851 NS_StringContainerFinish(str
);
854 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
856 const PRUnichar
*str
;
858 if(NS_FAILED(nsres
)) {
859 ERR("failed: %08x\n", nsres
);
860 nsAString_Finish(nsstr
);
864 nsAString_GetData(nsstr
, &str
);
865 TRACE("ret %s\n", debugstr_w(str
));
867 *p
= SysAllocString(str
);
869 return E_OUTOFMEMORY
;
874 nsAString_Finish(nsstr
);
878 nsICommandParams
*create_nscommand_params(void)
880 nsICommandParams
*ret
= NULL
;
886 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
887 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
890 ERR("Could not get nsICommandParams\n");
895 nsIWritableVariant
*create_nsvariant(void)
897 nsIWritableVariant
*ret
= NULL
;
903 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
904 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
906 ERR("Could not get nsIVariant\n");
911 char *get_nscategory_entry(const char *category
, const char *entry
)
916 nsres
= nsICategoryManager_GetCategoryEntry(cat_mgr
, category
, entry
, &ret
);
917 return NS_SUCCEEDED(nsres
) ? ret
: NULL
;
920 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
922 nsIInterfaceRequestor
*iface_req
;
925 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
929 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
930 nsIInterfaceRequestor_Release(iface_req
);
935 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
937 nsIDOMNodeList
*node_list
= NULL
;
938 cpp_bool has_children
= FALSE
;
939 nsIContent
*nscontent
;
943 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
945 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
946 if(NS_FAILED(nsres
)) {
947 ERR("GetType failed: %08x\n", nsres
);
951 if(type
!= DOCUMENT_NODE
) {
952 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
953 if(NS_FAILED(nsres
)) {
954 ERR("Could not get nsIContent interface: %08x\n", nsres
);
961 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
964 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
967 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
969 case DOCUMENT_NODE
: {
971 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
972 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
973 nsIDocument_Release(nsdoc
);
976 case DOCUMENT_TYPE_NODE
:
977 nsIContentSerializer_AppendDoctype(serializer
, nscontent
, str
);
979 case DOCUMENT_FRAGMENT_NODE
:
982 FIXME("Unhandled type %u\n", type
);
987 nsIDOMNode
*child_node
;
989 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
990 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
992 for(i
=0; i
<child_cnt
; i
++) {
993 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
994 if(NS_SUCCEEDED(nsres
)) {
995 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
996 nsIDOMNode_Release(child_node
);
998 ERR("Item failed: %08x\n", nsres
);
1002 nsIDOMNodeList_Release(node_list
);
1005 if(type
== ELEMENT_NODE
)
1006 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
1008 if(type
!= DOCUMENT_NODE
)
1009 nsIContent_Release(nscontent
);
1013 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
1015 nsIContentSerializer
*serializer
;
1019 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1020 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
1021 (void**)&serializer
);
1022 if(NS_FAILED(nsres
)) {
1023 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1027 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1028 if(NS_FAILED(nsres
))
1029 ERR("Init failed: %08x\n", nsres
);
1031 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1032 if(SUCCEEDED(hres
)) {
1033 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1034 if(NS_FAILED(nsres
))
1035 ERR("Flush failed: %08x\n", nsres
);
1038 nsIContentSerializer_Release(serializer
);
1042 void get_editor_controller(NSContainer
*This
)
1044 nsIEditingSession
*editing_session
= NULL
;
1045 nsIControllerContext
*ctrlctx
;
1049 nsIEditor_Release(This
->editor
);
1050 This
->editor
= NULL
;
1053 if(This
->editor_controller
) {
1054 nsIController_Release(This
->editor_controller
);
1055 This
->editor_controller
= NULL
;
1058 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1059 (void**)&editing_session
);
1060 if(NS_FAILED(nsres
)) {
1061 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1065 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1066 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
1067 nsIEditingSession_Release(editing_session
);
1068 if(NS_FAILED(nsres
)) {
1069 ERR("Could not get editor: %08x\n", nsres
);
1073 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1074 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1075 if(NS_SUCCEEDED(nsres
)) {
1076 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1077 if(NS_FAILED(nsres
))
1078 ERR("SetCommandContext failed: %08x\n", nsres
);
1079 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1080 (void**)&This
->editor_controller
);
1081 nsIControllerContext_Release(ctrlctx
);
1082 if(NS_FAILED(nsres
))
1083 ERR("Could not get nsIController interface: %08x\n", nsres
);
1085 ERR("Could not create edit controller: %08x\n", nsres
);
1089 void close_gecko(void)
1094 init_mutation(NULL
);
1096 if(profile_directory
) {
1097 nsIFile_Release(profile_directory
);
1098 profile_directory
= NULL
;
1101 if(plugin_directory
) {
1102 nsIFile_Release(plugin_directory
);
1103 plugin_directory
= NULL
;
1107 nsIComponentManager_Release(pCompMgr
);
1110 nsIServiceManager_Release(pServMgr
);
1113 nsICategoryManager_Release(cat_mgr
);
1116 nsIMemory_Release(nsmem
);
1118 /* Gecko doesn't really support being unloaded */
1119 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1121 DeleteCriticalSection(&cs_load_gecko
);
1124 BOOL
is_gecko_path(const char *path
)
1129 buf
= heap_strdupUtoW(path
);
1130 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1133 for(ptr
= buf
; *ptr
; ptr
++) {
1138 UrlUnescapeW(buf
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1139 buf
[gecko_path_len
] = 0;
1141 ret
= !strcmpiW(buf
, gecko_path
);
1146 struct nsWeakReference
{
1147 nsIWeakReference nsIWeakReference_iface
;
1151 NSContainer
*nscontainer
;
1154 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1156 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1159 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1160 nsIIDRef riid
, void **result
)
1162 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1164 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1165 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1166 *result
= &This
->nsIWeakReference_iface
;
1167 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1168 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1169 *result
= &This
->nsIWeakReference_iface
;
1171 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1173 return NS_NOINTERFACE
;
1176 nsISupports_AddRef((nsISupports
*)*result
);
1180 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1182 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1183 LONG ref
= InterlockedIncrement(&This
->ref
);
1185 TRACE("(%p) ref=%d\n", This
, ref
);
1190 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1192 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1193 LONG ref
= InterlockedIncrement(&This
->ref
);
1195 TRACE("(%p) ref=%d\n", This
, ref
);
1198 assert(!This
->nscontainer
);
1205 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1206 const nsIID
*riid
, void **result
)
1208 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1210 if(!This
->nscontainer
)
1211 return NS_ERROR_NULL_POINTER
;
1213 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1216 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1217 nsWeakReference_QueryInterface
,
1218 nsWeakReference_AddRef
,
1219 nsWeakReference_Release
,
1220 nsWeakReference_QueryReferent
1223 /**********************************************************
1224 * nsIWebBrowserChrome interface
1227 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1229 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1232 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1233 nsIIDRef riid
, void **result
)
1235 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1238 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1239 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1240 *result
= &This
->nsIWebBrowserChrome_iface
;
1241 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1242 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1243 *result
= &This
->nsIWebBrowserChrome_iface
;
1244 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1245 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1246 *result
= &This
->nsIContextMenuListener_iface
;
1247 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1248 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1249 *result
= &This
->nsIURIContentListener_iface
;
1250 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1251 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1252 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1253 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1254 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1255 *result
= &This
->nsITooltipListener_iface
;
1256 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1257 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1258 *result
= &This
->nsIInterfaceRequestor_iface
;
1259 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1260 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1261 *result
= &This
->nsISupportsWeakReference_iface
;
1265 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1269 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1270 return NS_NOINTERFACE
;
1273 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1275 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1276 LONG ref
= InterlockedIncrement(&This
->ref
);
1278 TRACE("(%p) ref=%d\n", This
, ref
);
1283 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1285 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1286 LONG ref
= InterlockedDecrement(&This
->ref
);
1288 TRACE("(%p) ref=%d\n", This
, ref
);
1292 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1293 if(This
->weak_reference
) {
1294 This
->weak_reference
->nscontainer
= NULL
;
1295 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1303 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1304 UINT32 statusType
, const PRUnichar
*status
)
1306 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1307 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1311 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1312 nsIWebBrowser
**aWebBrowser
)
1314 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1316 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1319 return NS_ERROR_INVALID_ARG
;
1321 if(This
->webbrowser
)
1322 nsIWebBrowser_AddRef(This
->webbrowser
);
1323 *aWebBrowser
= This
->webbrowser
;
1327 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1328 nsIWebBrowser
*aWebBrowser
)
1330 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1332 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1334 if(aWebBrowser
!= This
->webbrowser
)
1335 ERR("Wrong nsWebBrowser!\n");
1340 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1341 UINT32
*aChromeFlags
)
1343 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1344 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1345 return NS_ERROR_NOT_IMPLEMENTED
;
1348 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1349 UINT32 aChromeFlags
)
1351 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1352 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1353 return NS_ERROR_NOT_IMPLEMENTED
;
1356 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1358 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1359 TRACE("(%p)\n", This
);
1360 return NS_ERROR_NOT_IMPLEMENTED
;
1363 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1366 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1367 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1368 return NS_ERROR_NOT_IMPLEMENTED
;
1371 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1373 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1374 WARN("(%p)\n", This
);
1375 return NS_ERROR_NOT_IMPLEMENTED
;
1378 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1380 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1381 WARN("(%p)->(%p)\n", This
, _retval
);
1382 return NS_ERROR_NOT_IMPLEMENTED
;
1385 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1388 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1389 WARN("(%p)->(%08x)\n", This
, aStatus
);
1390 return NS_ERROR_NOT_IMPLEMENTED
;
1393 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1394 nsWebBrowserChrome_QueryInterface
,
1395 nsWebBrowserChrome_AddRef
,
1396 nsWebBrowserChrome_Release
,
1397 nsWebBrowserChrome_SetStatus
,
1398 nsWebBrowserChrome_GetWebBrowser
,
1399 nsWebBrowserChrome_SetWebBrowser
,
1400 nsWebBrowserChrome_GetChromeFlags
,
1401 nsWebBrowserChrome_SetChromeFlags
,
1402 nsWebBrowserChrome_DestroyBrowserWindow
,
1403 nsWebBrowserChrome_SizeBrowserTo
,
1404 nsWebBrowserChrome_ShowAsModal
,
1405 nsWebBrowserChrome_IsWindowModal
,
1406 nsWebBrowserChrome_ExitModalEventLoop
1409 /**********************************************************
1410 * nsIContextMenuListener interface
1413 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1415 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1418 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1419 nsIIDRef riid
, void **result
)
1421 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1422 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1425 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1427 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1428 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1431 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1433 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1434 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1437 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1438 UINT32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1440 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1441 nsIDOMMouseEvent
*event
;
1444 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1448 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1450 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
, NULL
);
1452 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1453 if(NS_FAILED(nsres
)) {
1454 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1458 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1459 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1460 nsIDOMMouseEvent_Release(event
);
1462 switch(aContextFlags
) {
1464 case CONTEXT_DOCUMENT
:
1466 dwID
= CONTEXT_MENU_DEFAULT
;
1469 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1470 dwID
= CONTEXT_MENU_IMAGE
;
1473 dwID
= CONTEXT_MENU_ANCHOR
;
1476 dwID
= CONTEXT_MENU_CONTROL
;
1479 FIXME("aContextFlags=%08x\n", aContextFlags
);
1482 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1484 return NS_ERROR_FAILURE
;
1486 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1491 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1492 nsContextMenuListener_QueryInterface
,
1493 nsContextMenuListener_AddRef
,
1494 nsContextMenuListener_Release
,
1495 nsContextMenuListener_OnShowContextMenu
1498 /**********************************************************
1499 * nsIURIContentListener interface
1502 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1504 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1507 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1508 nsIIDRef riid
, void **result
)
1510 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1511 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1514 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1516 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1517 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1520 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1522 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1523 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1526 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1527 nsIURI
*aURI
, cpp_bool
*_retval
)
1529 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1530 nsACString spec_str
;
1534 nsACString_Init(&spec_str
, NULL
);
1535 nsIURI_GetSpec(aURI
, &spec_str
);
1536 nsACString_GetData(&spec_str
, &spec
);
1538 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1540 nsACString_Finish(&spec_str
);
1542 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1543 if(NS_FAILED(nsres
))
1546 return !*_retval
&& This
->content_listener
1547 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1551 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1552 const char *aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1553 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1555 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1557 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1558 aRequest
, aContentHandler
, _retval
);
1560 return This
->content_listener
1561 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1562 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1563 : NS_ERROR_NOT_IMPLEMENTED
;
1566 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1567 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1569 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1571 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1573 /* FIXME: Should we do something here? */
1576 return This
->content_listener
1577 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1578 aDesiredContentType
, _retval
)
1582 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1583 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1586 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1588 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1589 aDesiredContentType
, _retval
);
1591 return This
->content_listener
1592 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1593 aIsContentPreferred
, aDesiredContentType
, _retval
)
1594 : NS_ERROR_NOT_IMPLEMENTED
;
1597 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1598 nsISupports
**aLoadCookie
)
1600 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1602 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1604 return This
->content_listener
1605 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1606 : NS_ERROR_NOT_IMPLEMENTED
;
1609 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1610 nsISupports
*aLoadCookie
)
1612 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1614 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1616 return This
->content_listener
1617 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1618 : NS_ERROR_NOT_IMPLEMENTED
;
1621 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1622 nsIURIContentListener
**aParentContentListener
)
1624 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1626 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1628 if(This
->content_listener
)
1629 nsIURIContentListener_AddRef(This
->content_listener
);
1631 *aParentContentListener
= This
->content_listener
;
1635 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1636 nsIURIContentListener
*aParentContentListener
)
1638 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1640 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1642 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1645 if(This
->content_listener
)
1646 nsIURIContentListener_Release(This
->content_listener
);
1648 This
->content_listener
= aParentContentListener
;
1649 if(This
->content_listener
)
1650 nsIURIContentListener_AddRef(This
->content_listener
);
1655 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1656 nsURIContentListener_QueryInterface
,
1657 nsURIContentListener_AddRef
,
1658 nsURIContentListener_Release
,
1659 nsURIContentListener_OnStartURIOpen
,
1660 nsURIContentListener_DoContent
,
1661 nsURIContentListener_IsPreferred
,
1662 nsURIContentListener_CanHandleContent
,
1663 nsURIContentListener_GetLoadCookie
,
1664 nsURIContentListener_SetLoadCookie
,
1665 nsURIContentListener_GetParentContentListener
,
1666 nsURIContentListener_SetParentContentListener
1669 /**********************************************************
1670 * nsIEmbeddinSiteWindow interface
1673 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1675 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1678 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1679 nsIIDRef riid
, void **result
)
1681 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1682 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1685 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1687 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1688 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1691 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1693 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1694 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1697 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1698 UINT32 flags
, LONG x
, LONG y
, LONG cx
, LONG cy
)
1700 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1701 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1702 return NS_ERROR_NOT_IMPLEMENTED
;
1705 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1706 UINT32 flags
, LONG
*x
, LONG
*y
, LONG
*cx
, LONG
*cy
)
1708 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1709 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1710 return NS_ERROR_NOT_IMPLEMENTED
;
1713 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1715 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1717 TRACE("(%p)\n", This
);
1719 return nsIBaseWindow_SetFocus(This
->window
);
1722 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1723 cpp_bool
*aVisibility
)
1725 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1727 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1729 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1733 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1734 cpp_bool aVisibility
)
1736 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1738 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1743 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1746 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1747 WARN("(%p)->(%p)\n", This
, aTitle
);
1748 return NS_ERROR_NOT_IMPLEMENTED
;
1751 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1752 const PRUnichar
*aTitle
)
1754 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1755 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1756 return NS_ERROR_NOT_IMPLEMENTED
;
1759 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1762 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1764 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1766 *aSiteWindow
= This
->hwnd
;
1770 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1771 nsEmbeddingSiteWindow_QueryInterface
,
1772 nsEmbeddingSiteWindow_AddRef
,
1773 nsEmbeddingSiteWindow_Release
,
1774 nsEmbeddingSiteWindow_SetDimensions
,
1775 nsEmbeddingSiteWindow_GetDimensions
,
1776 nsEmbeddingSiteWindow_SetFocus
,
1777 nsEmbeddingSiteWindow_GetVisibility
,
1778 nsEmbeddingSiteWindow_SetVisibility
,
1779 nsEmbeddingSiteWindow_GetTitle
,
1780 nsEmbeddingSiteWindow_SetTitle
,
1781 nsEmbeddingSiteWindow_GetSiteWindow
1784 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1786 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1789 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1792 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1793 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1796 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1798 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1799 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1802 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1804 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1805 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1808 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1809 LONG aXCoord
, LONG aYCoord
, const PRUnichar
*aTipText
)
1811 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1814 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1819 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1821 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1824 hide_tooltip(This
->doc
);
1829 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1830 nsTooltipListener_QueryInterface
,
1831 nsTooltipListener_AddRef
,
1832 nsTooltipListener_Release
,
1833 nsTooltipListener_OnShowTooltip
,
1834 nsTooltipListener_OnHideTooltip
1837 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1839 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1842 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1843 nsIIDRef riid
, void **result
)
1845 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1846 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1849 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1851 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1852 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1855 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1857 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1858 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1861 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1862 nsIIDRef riid
, void **result
)
1864 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1866 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1867 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1868 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1871 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1874 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1875 nsInterfaceRequestor_QueryInterface
,
1876 nsInterfaceRequestor_AddRef
,
1877 nsInterfaceRequestor_Release
,
1878 nsInterfaceRequestor_GetInterface
1881 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1883 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1886 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1887 nsIIDRef riid
, void **result
)
1889 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1890 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1893 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1895 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1896 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1899 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1901 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1902 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1905 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1906 nsIWeakReference
**_retval
)
1908 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1910 TRACE("(%p)->(%p)\n", This
, _retval
);
1912 if(!This
->weak_reference
) {
1913 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1914 if(!This
->weak_reference
)
1915 return NS_ERROR_OUT_OF_MEMORY
;
1917 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1918 This
->weak_reference
->ref
= 1;
1919 This
->weak_reference
->nscontainer
= This
;
1922 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1923 nsIWeakReference_AddRef(*_retval
);
1927 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1928 nsSupportsWeakReference_QueryInterface
,
1929 nsSupportsWeakReference_AddRef
,
1930 nsSupportsWeakReference_Release
,
1931 nsSupportsWeakReference_GetWeakReference
1934 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1936 nsIWebBrowserSetup
*wbsetup
;
1937 nsIScrollable
*scrollable
;
1940 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1941 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1942 if(NS_FAILED(nsres
)) {
1943 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1947 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1948 if(NS_FAILED(nsres
)) {
1949 ERR("SetContainerWindow failed: %08x\n", nsres
);
1953 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1954 (void**)&nscontainer
->window
);
1955 if(NS_FAILED(nsres
)) {
1956 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1960 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
1962 if(NS_SUCCEEDED(nsres
)) {
1963 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1964 nsIWebBrowserSetup_Release(wbsetup
);
1965 if(NS_FAILED(nsres
)) {
1966 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1970 ERR("Could not get nsIWebBrowserSetup interface\n");
1974 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
1975 (void**)&nscontainer
->navigation
);
1976 if(NS_FAILED(nsres
)) {
1977 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1981 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
1982 (void**)&nscontainer
->focus
);
1983 if(NS_FAILED(nsres
)) {
1984 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1988 if(!nscontainer_class
) {
1989 register_nscontainer_class();
1990 if(!nscontainer_class
)
1994 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1995 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1996 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
1997 if(!nscontainer
->hwnd
) {
1998 WARN("Could not create window\n");
2002 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
2003 if(NS_SUCCEEDED(nsres
)) {
2004 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
2005 if(NS_FAILED(nsres
)) {
2006 WARN("Creating window failed: %08x\n", nsres
);
2010 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
2011 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
2013 ERR("InitWindow failed: %08x\n", nsres
);
2017 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
2018 &nscontainer
->nsIURIContentListener_iface
);
2019 if(NS_FAILED(nsres
))
2020 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
2022 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
2023 if(NS_SUCCEEDED(nsres
)) {
2024 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2025 ScrollOrientation_Y
, Scrollbar_Always
);
2026 if(NS_FAILED(nsres
))
2027 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2029 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2030 ScrollOrientation_X
, Scrollbar_Auto
);
2031 if(NS_FAILED(nsres
))
2032 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2034 nsIScrollable_Release(scrollable
);
2036 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2042 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2048 return CLASS_E_CLASSNOTAVAILABLE
;
2050 ret
= heap_alloc_zero(sizeof(NSContainer
));
2052 return E_OUTOFMEMORY
;
2054 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2055 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2056 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2057 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2058 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2059 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2060 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2065 hres
= init_nscontainer(ret
);
2069 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2073 void NSContainer_Release(NSContainer
*This
)
2075 TRACE("(%p)\n", This
);
2079 ShowWindow(This
->hwnd
, SW_HIDE
);
2080 SetParent(This
->hwnd
, NULL
);
2082 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2083 nsIBaseWindow_Destroy(This
->window
);
2085 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2087 nsIWebBrowser_Release(This
->webbrowser
);
2088 This
->webbrowser
= NULL
;
2090 nsIWebNavigation_Release(This
->navigation
);
2091 This
->navigation
= NULL
;
2093 nsIBaseWindow_Release(This
->window
);
2094 This
->window
= NULL
;
2096 nsIWebBrowserFocus_Release(This
->focus
);
2099 if(This
->editor_controller
) {
2100 nsIController_Release(This
->editor_controller
);
2101 This
->editor_controller
= NULL
;
2105 nsIEditor_Release(This
->editor
);
2106 This
->editor
= NULL
;
2109 if(This
->content_listener
) {
2110 nsIURIContentListener_Release(This
->content_listener
);
2111 This
->content_listener
= NULL
;
2115 DestroyWindow(This
->hwnd
);
2119 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);