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_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"
50 #define NS_CATEGORYMANAGER_CONTRACTID "@mozilla.org/categorymanager;1"
52 #define PR_UINT32_MAX 0xffffffff
54 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
55 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
57 typedef UINT32 PRUint32
;
59 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
60 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
61 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
62 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
63 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
64 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
65 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
66 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
67 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
68 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,cpp_bool
,nsIFile
**);
69 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,cpp_bool
*);
70 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,cpp_bool
*);
71 static void* (CDECL
*NS_Alloc
)(SIZE_T
);
72 static void (CDECL
*NS_Free
)(void*);
74 static HINSTANCE xul_handle
= NULL
;
76 static nsIServiceManager
*pServMgr
= NULL
;
77 static nsIComponentManager
*pCompMgr
= NULL
;
78 static nsICategoryManager
*cat_mgr
;
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 size_t len
, gre_path_len
;
443 WCHAR
*path
, buf
[20];
446 static const WCHAR pathW
[] = {'P','A','T','H',0};
447 static const WCHAR warnW
[] = {'w','a','r','n',0};
448 static const WCHAR xpcom_debug_breakW
[] =
449 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
450 static const WCHAR nspr_log_modulesW
[] =
451 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
452 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
454 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
458 else if(WARN_ON(gecko
))
460 else if(ERR_ON(gecko
))
463 sprintfW(buf
, debug_formatW
, debug_level
);
464 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
466 len
= GetEnvironmentVariableW(pathW
, NULL
, 0);
467 gre_path_len
= strlenW(gre_path
);
468 path
= heap_alloc((len
+gre_path_len
+1)*sizeof(WCHAR
));
471 GetEnvironmentVariableW(pathW
, path
, len
);
473 /* We have to modify PATH as xul.dll loads other DLLs from this directory. */
474 if(!(ptr
= strstrW(path
, gre_path
))
475 || (ptr
> path
&& *(ptr
-1) != ';')
476 || (ptr
[gre_path_len
] && ptr
[gre_path_len
] != ';')) {
479 strcpyW(path
+len
, gre_path
);
480 SetEnvironmentVariableW(pathW
, path
);
484 static BOOL
load_xul(const PRUnichar
*gre_path
)
486 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
487 WCHAR file_name
[MAX_PATH
];
489 strcpyW(file_name
, gre_path
);
490 strcatW(file_name
, xul_dllW
);
492 TRACE("(%s)\n", debugstr_w(file_name
));
494 set_environment(gre_path
);
496 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
498 WARN("Could not load XUL: %d\n", GetLastError());
502 #define NS_DLSYM(func) \
503 func = (void *)GetProcAddress(xul_handle, #func); \
505 ERR("Could not GetProcAddress(" #func ") failed\n")
507 NS_DLSYM(NS_InitXPCOM2
);
508 NS_DLSYM(NS_ShutdownXPCOM
);
509 NS_DLSYM(NS_GetComponentRegistrar
);
510 NS_DLSYM(NS_StringContainerInit2
);
511 NS_DLSYM(NS_CStringContainerInit2
);
512 NS_DLSYM(NS_StringContainerFinish
);
513 NS_DLSYM(NS_CStringContainerFinish
);
514 NS_DLSYM(NS_StringSetData
);
515 NS_DLSYM(NS_CStringSetData
);
516 NS_DLSYM(NS_NewLocalFile
);
517 NS_DLSYM(NS_StringGetData
);
518 NS_DLSYM(NS_CStringGetData
);
521 NS_DLSYM(ccref_incr
);
522 NS_DLSYM(ccref_decr
);
523 NS_DLSYM(ccref_init
);
525 NS_DLSYM(describe_cc_node
);
526 NS_DLSYM(note_cc_edge
);
533 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
535 WCHAR file_name
[MAX_PATH
];
540 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
542 strcpyW(file_name
, gre_path
);
543 strcatW(file_name
, wszVersion
);
545 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
546 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
547 if(hfile
== INVALID_HANDLE_VALUE
) {
548 ERR("Could not open VERSION file\n");
552 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
556 TRACE("%s\n", debugstr_a(version
));
558 if(strcmp(version
, version_string
)) {
559 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
560 debugstr_a(version_string
));
567 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
568 const char *version
, const char *version_string
)
570 DWORD res
, type
, size
= MAX_PATH
;
571 HKEY hkey
= mshtml_key
;
573 static const WCHAR wszGeckoPath
[] =
574 {'G','e','c','k','o','P','a','t','h',0};
577 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
578 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
579 if(res
!= ERROR_SUCCESS
)
583 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
584 if(hkey
!= mshtml_key
)
586 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
589 if(!check_version(gre_path
, version_string
))
592 return load_xul(gre_path
);
595 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
601 static const WCHAR wszMshtmlKey
[] = {
602 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
603 '\\','M','S','H','T','M','L',0};
605 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
606 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
607 if(res
!= ERROR_SUCCESS
)
610 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
616 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
620 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
622 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
625 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
629 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
631 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
634 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
638 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
640 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
643 static void set_lang(nsIPrefBranch
*pref
)
646 DWORD res
, size
, type
;
649 static const WCHAR international_keyW
[] =
650 {'S','o','f','t','w','a','r','e',
651 '\\','M','i','c','r','o','s','o','f','t',
652 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
653 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
655 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
656 if(res
!= ERROR_SUCCESS
)
659 size
= sizeof(langs
);
660 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
662 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
665 TRACE("Setting lang %s\n", debugstr_a(langs
));
667 set_string_pref(pref
, "intl.accept_languages", langs
);
670 static void set_preferences(void)
675 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
676 &IID_nsIPrefBranch
, (void**)&pref
);
677 if(NS_FAILED(nsres
)) {
678 ERR("Could not get preference service: %08x\n", nsres
);
683 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
684 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
685 set_int_pref(pref
, "layout.spellcheckDefault", 0);
687 nsIPrefBranch_Release(pref
);
690 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
692 nsIComponentRegistrar
*registrar
= NULL
;
697 nsres
= create_nsfile(gre_path
, &gre_dir
);
698 if(NS_FAILED(nsres
)) {
699 FreeLibrary(xul_handle
);
703 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
704 if(NS_FAILED(nsres
)) {
705 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
706 FreeLibrary(xul_handle
);
710 strcpyW(gecko_path
, gre_path
);
711 for(ptr
= gecko_path
; *ptr
; ptr
++) {
715 gecko_path_len
= ptr
-gecko_path
;
717 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
719 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
721 nsres
= NS_GetComponentRegistrar(®istrar
);
722 if(NS_SUCCEEDED(nsres
))
723 init_nsio(pCompMgr
, registrar
);
725 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
727 init_mutation(pCompMgr
);
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 NS_Alloc(size
);
791 void nsfree(void *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 UINT32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
841 return NS_StringGetData(str
, data
, NULL
);
844 void nsAString_Finish(nsAString
*str
)
846 NS_StringContainerFinish(str
);
849 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
851 const PRUnichar
*str
;
853 if(NS_FAILED(nsres
)) {
854 ERR("failed: %08x\n", nsres
);
855 nsAString_Finish(nsstr
);
859 nsAString_GetData(nsstr
, &str
);
860 TRACE("ret %s\n", debugstr_w(str
));
862 *p
= SysAllocString(str
);
864 return E_OUTOFMEMORY
;
869 nsAString_Finish(nsstr
);
873 nsICommandParams
*create_nscommand_params(void)
875 nsICommandParams
*ret
= NULL
;
881 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
882 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
885 ERR("Could not get nsICommandParams\n");
890 nsIWritableVariant
*create_nsvariant(void)
892 nsIWritableVariant
*ret
= NULL
;
898 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
899 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
901 ERR("Could not get nsIVariant\n");
906 char *get_nscategory_entry(const char *category
, const char *entry
)
911 nsres
= nsICategoryManager_GetCategoryEntry(cat_mgr
, category
, entry
, &ret
);
912 return NS_SUCCEEDED(nsres
) ? ret
: NULL
;
915 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
917 nsIInterfaceRequestor
*iface_req
;
920 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
924 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
925 nsIInterfaceRequestor_Release(iface_req
);
930 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
932 nsIDOMNodeList
*node_list
= NULL
;
933 cpp_bool has_children
= FALSE
;
934 nsIContent
*nscontent
;
938 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
940 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
941 if(NS_FAILED(nsres
)) {
942 ERR("GetType failed: %08x\n", nsres
);
946 if(type
!= DOCUMENT_NODE
) {
947 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
948 if(NS_FAILED(nsres
)) {
949 ERR("Could not get nsIContent interface: %08x\n", nsres
);
956 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
959 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
962 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
964 case DOCUMENT_NODE
: {
966 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
967 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
968 nsIDocument_Release(nsdoc
);
971 case DOCUMENT_TYPE_NODE
:
972 nsIContentSerializer_AppendDoctype(serializer
, nscontent
, str
);
974 case DOCUMENT_FRAGMENT_NODE
:
977 FIXME("Unhandled type %u\n", type
);
982 nsIDOMNode
*child_node
;
984 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
985 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
987 for(i
=0; i
<child_cnt
; i
++) {
988 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
989 if(NS_SUCCEEDED(nsres
)) {
990 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
991 nsIDOMNode_Release(child_node
);
993 ERR("Item failed: %08x\n", nsres
);
997 nsIDOMNodeList_Release(node_list
);
1000 if(type
== ELEMENT_NODE
)
1001 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
1003 if(type
!= DOCUMENT_NODE
)
1004 nsIContent_Release(nscontent
);
1008 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
1010 nsIContentSerializer
*serializer
;
1014 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1015 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
1016 (void**)&serializer
);
1017 if(NS_FAILED(nsres
)) {
1018 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1022 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1023 if(NS_FAILED(nsres
))
1024 ERR("Init failed: %08x\n", nsres
);
1026 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1027 if(SUCCEEDED(hres
)) {
1028 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1029 if(NS_FAILED(nsres
))
1030 ERR("Flush failed: %08x\n", nsres
);
1033 nsIContentSerializer_Release(serializer
);
1037 void get_editor_controller(NSContainer
*This
)
1039 nsIEditingSession
*editing_session
= NULL
;
1040 nsIControllerContext
*ctrlctx
;
1044 nsIEditor_Release(This
->editor
);
1045 This
->editor
= NULL
;
1048 if(This
->editor_controller
) {
1049 nsIController_Release(This
->editor_controller
);
1050 This
->editor_controller
= NULL
;
1053 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1054 (void**)&editing_session
);
1055 if(NS_FAILED(nsres
)) {
1056 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1060 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1061 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
1062 nsIEditingSession_Release(editing_session
);
1063 if(NS_FAILED(nsres
)) {
1064 ERR("Could not get editor: %08x\n", nsres
);
1068 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1069 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1070 if(NS_SUCCEEDED(nsres
)) {
1071 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1072 if(NS_FAILED(nsres
))
1073 ERR("SetCommandContext failed: %08x\n", nsres
);
1074 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1075 (void**)&This
->editor_controller
);
1076 nsIControllerContext_Release(ctrlctx
);
1077 if(NS_FAILED(nsres
))
1078 ERR("Could not get nsIController interface: %08x\n", nsres
);
1080 ERR("Could not create edit controller: %08x\n", nsres
);
1084 void close_gecko(void)
1089 init_mutation(NULL
);
1091 if(profile_directory
) {
1092 nsIFile_Release(profile_directory
);
1093 profile_directory
= NULL
;
1096 if(plugin_directory
) {
1097 nsIFile_Release(plugin_directory
);
1098 plugin_directory
= NULL
;
1102 nsIComponentManager_Release(pCompMgr
);
1105 nsIServiceManager_Release(pServMgr
);
1108 nsICategoryManager_Release(cat_mgr
);
1110 /* Gecko doesn't really support being unloaded */
1111 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1113 DeleteCriticalSection(&cs_load_gecko
);
1116 BOOL
is_gecko_path(const char *path
)
1121 buf
= heap_strdupUtoW(path
);
1122 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1125 for(ptr
= buf
; *ptr
; ptr
++) {
1130 UrlUnescapeW(buf
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1131 buf
[gecko_path_len
] = 0;
1133 ret
= !strcmpiW(buf
, gecko_path
);
1138 void set_viewer_zoom(NSContainer
*nscontainer
, float factor
)
1140 nsIContentViewer
*content_viewer
;
1141 nsIDocShell
*doc_shell
;
1144 TRACE("Setting to %f\n", factor
);
1146 nsres
= get_nsinterface((nsISupports
*)nscontainer
->navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
1147 assert(nsres
== NS_OK
);
1149 nsres
= nsIDocShell_GetContentViewer(doc_shell
, &content_viewer
);
1150 assert(nsres
== NS_OK
&& content_viewer
);
1151 nsIDocShell_Release(doc_shell
);
1153 nsres
= nsIContentViewer_SetFullZoom(content_viewer
, factor
);
1154 if(NS_FAILED(nsres
))
1155 ERR("SetFullZoom failed: %08x\n", nsres
);
1157 nsIContentViewer_Release(content_viewer
);
1160 struct nsWeakReference
{
1161 nsIWeakReference nsIWeakReference_iface
;
1165 NSContainer
*nscontainer
;
1168 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1170 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1173 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1174 nsIIDRef riid
, void **result
)
1176 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1178 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1179 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1180 *result
= &This
->nsIWeakReference_iface
;
1181 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1182 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1183 *result
= &This
->nsIWeakReference_iface
;
1185 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1187 return NS_NOINTERFACE
;
1190 nsISupports_AddRef((nsISupports
*)*result
);
1194 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1196 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1197 LONG ref
= InterlockedIncrement(&This
->ref
);
1199 TRACE("(%p) ref=%d\n", This
, ref
);
1204 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1206 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1207 LONG ref
= InterlockedIncrement(&This
->ref
);
1209 TRACE("(%p) ref=%d\n", This
, ref
);
1212 assert(!This
->nscontainer
);
1219 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1220 const nsIID
*riid
, void **result
)
1222 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1224 if(!This
->nscontainer
)
1225 return NS_ERROR_NULL_POINTER
;
1227 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1230 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1231 nsWeakReference_QueryInterface
,
1232 nsWeakReference_AddRef
,
1233 nsWeakReference_Release
,
1234 nsWeakReference_QueryReferent
1237 /**********************************************************
1238 * nsIWebBrowserChrome interface
1241 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1243 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1246 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1247 nsIIDRef riid
, void **result
)
1249 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1252 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1253 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1254 *result
= &This
->nsIWebBrowserChrome_iface
;
1255 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1256 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1257 *result
= &This
->nsIWebBrowserChrome_iface
;
1258 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1259 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1260 *result
= &This
->nsIContextMenuListener_iface
;
1261 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1262 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1263 *result
= &This
->nsIURIContentListener_iface
;
1264 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1265 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1266 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1267 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1268 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1269 *result
= &This
->nsITooltipListener_iface
;
1270 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1271 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1272 *result
= &This
->nsIInterfaceRequestor_iface
;
1273 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1274 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1275 *result
= &This
->nsISupportsWeakReference_iface
;
1279 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1283 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1284 return NS_NOINTERFACE
;
1287 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1289 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1290 LONG ref
= InterlockedIncrement(&This
->ref
);
1292 TRACE("(%p) ref=%d\n", This
, ref
);
1297 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1299 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1300 LONG ref
= InterlockedDecrement(&This
->ref
);
1302 TRACE("(%p) ref=%d\n", This
, ref
);
1306 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1307 if(This
->weak_reference
) {
1308 This
->weak_reference
->nscontainer
= NULL
;
1309 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1317 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1318 UINT32 statusType
, const PRUnichar
*status
)
1320 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1321 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1325 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1326 nsIWebBrowser
**aWebBrowser
)
1328 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1330 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1333 return NS_ERROR_INVALID_ARG
;
1335 if(This
->webbrowser
)
1336 nsIWebBrowser_AddRef(This
->webbrowser
);
1337 *aWebBrowser
= This
->webbrowser
;
1341 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1342 nsIWebBrowser
*aWebBrowser
)
1344 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1346 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1348 if(aWebBrowser
!= This
->webbrowser
)
1349 ERR("Wrong nsWebBrowser!\n");
1354 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1355 UINT32
*aChromeFlags
)
1357 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1358 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1359 return NS_ERROR_NOT_IMPLEMENTED
;
1362 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1363 UINT32 aChromeFlags
)
1365 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1366 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1367 return NS_ERROR_NOT_IMPLEMENTED
;
1370 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1372 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1373 TRACE("(%p)\n", This
);
1374 return NS_ERROR_NOT_IMPLEMENTED
;
1377 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1380 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1381 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1382 return NS_ERROR_NOT_IMPLEMENTED
;
1385 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1387 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1388 WARN("(%p)\n", This
);
1389 return NS_ERROR_NOT_IMPLEMENTED
;
1392 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1394 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1395 WARN("(%p)->(%p)\n", This
, _retval
);
1396 return NS_ERROR_NOT_IMPLEMENTED
;
1399 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1402 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1403 WARN("(%p)->(%08x)\n", This
, aStatus
);
1404 return NS_ERROR_NOT_IMPLEMENTED
;
1407 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1408 nsWebBrowserChrome_QueryInterface
,
1409 nsWebBrowserChrome_AddRef
,
1410 nsWebBrowserChrome_Release
,
1411 nsWebBrowserChrome_SetStatus
,
1412 nsWebBrowserChrome_GetWebBrowser
,
1413 nsWebBrowserChrome_SetWebBrowser
,
1414 nsWebBrowserChrome_GetChromeFlags
,
1415 nsWebBrowserChrome_SetChromeFlags
,
1416 nsWebBrowserChrome_DestroyBrowserWindow
,
1417 nsWebBrowserChrome_SizeBrowserTo
,
1418 nsWebBrowserChrome_ShowAsModal
,
1419 nsWebBrowserChrome_IsWindowModal
,
1420 nsWebBrowserChrome_ExitModalEventLoop
1423 /**********************************************************
1424 * nsIContextMenuListener interface
1427 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1429 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1432 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1433 nsIIDRef riid
, void **result
)
1435 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1436 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1439 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1441 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1442 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1445 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1447 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1448 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1451 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1452 UINT32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1454 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1455 nsIDOMMouseEvent
*event
;
1458 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1462 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1464 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
, NULL
);
1466 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1467 if(NS_FAILED(nsres
)) {
1468 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1472 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1473 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1474 nsIDOMMouseEvent_Release(event
);
1476 switch(aContextFlags
) {
1478 case CONTEXT_DOCUMENT
:
1479 case CONTEXT_TEXT
: {
1480 nsISelection
*selection
;
1482 nsres
= nsIDOMHTMLDocument_GetSelection(This
->doc
->basedoc
.doc_node
->nsdoc
, &selection
);
1483 if(NS_SUCCEEDED(nsres
) && selection
) {
1484 cpp_bool is_collapsed
;
1486 /* FIXME: Check if the click was inside selection. */
1487 nsres
= nsISelection_GetIsCollapsed(selection
, &is_collapsed
);
1488 nsISelection_Release(selection
);
1489 if(NS_SUCCEEDED(nsres
) && !is_collapsed
)
1490 dwID
= CONTEXT_MENU_TEXTSELECT
;
1495 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1496 dwID
= CONTEXT_MENU_IMAGE
;
1499 dwID
= CONTEXT_MENU_ANCHOR
;
1502 dwID
= CONTEXT_MENU_CONTROL
;
1505 FIXME("aContextFlags=%08x\n", aContextFlags
);
1508 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1510 return NS_ERROR_FAILURE
;
1512 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1517 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1518 nsContextMenuListener_QueryInterface
,
1519 nsContextMenuListener_AddRef
,
1520 nsContextMenuListener_Release
,
1521 nsContextMenuListener_OnShowContextMenu
1524 /**********************************************************
1525 * nsIURIContentListener interface
1528 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1530 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1533 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1534 nsIIDRef riid
, void **result
)
1536 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1537 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1540 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1542 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1543 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1546 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1548 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1549 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1552 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1553 nsIURI
*aURI
, cpp_bool
*_retval
)
1555 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1556 nsACString spec_str
;
1560 nsACString_Init(&spec_str
, NULL
);
1561 nsIURI_GetSpec(aURI
, &spec_str
);
1562 nsACString_GetData(&spec_str
, &spec
);
1564 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1566 nsACString_Finish(&spec_str
);
1568 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1569 if(NS_FAILED(nsres
))
1572 return !*_retval
&& This
->content_listener
1573 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1577 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1578 const char *aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1579 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1581 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1583 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1584 aRequest
, aContentHandler
, _retval
);
1586 return This
->content_listener
1587 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1588 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1589 : NS_ERROR_NOT_IMPLEMENTED
;
1592 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1593 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1595 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1597 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1599 /* FIXME: Should we do something here? */
1602 return This
->content_listener
1603 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1604 aDesiredContentType
, _retval
)
1608 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1609 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1612 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1614 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1615 aDesiredContentType
, _retval
);
1617 return This
->content_listener
1618 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1619 aIsContentPreferred
, aDesiredContentType
, _retval
)
1620 : NS_ERROR_NOT_IMPLEMENTED
;
1623 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1624 nsISupports
**aLoadCookie
)
1626 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1628 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1630 return This
->content_listener
1631 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1632 : NS_ERROR_NOT_IMPLEMENTED
;
1635 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1636 nsISupports
*aLoadCookie
)
1638 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1640 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1642 return This
->content_listener
1643 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1644 : NS_ERROR_NOT_IMPLEMENTED
;
1647 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1648 nsIURIContentListener
**aParentContentListener
)
1650 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1652 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1654 if(This
->content_listener
)
1655 nsIURIContentListener_AddRef(This
->content_listener
);
1657 *aParentContentListener
= This
->content_listener
;
1661 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1662 nsIURIContentListener
*aParentContentListener
)
1664 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1666 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1668 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1671 if(This
->content_listener
)
1672 nsIURIContentListener_Release(This
->content_listener
);
1674 This
->content_listener
= aParentContentListener
;
1675 if(This
->content_listener
)
1676 nsIURIContentListener_AddRef(This
->content_listener
);
1681 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1682 nsURIContentListener_QueryInterface
,
1683 nsURIContentListener_AddRef
,
1684 nsURIContentListener_Release
,
1685 nsURIContentListener_OnStartURIOpen
,
1686 nsURIContentListener_DoContent
,
1687 nsURIContentListener_IsPreferred
,
1688 nsURIContentListener_CanHandleContent
,
1689 nsURIContentListener_GetLoadCookie
,
1690 nsURIContentListener_SetLoadCookie
,
1691 nsURIContentListener_GetParentContentListener
,
1692 nsURIContentListener_SetParentContentListener
1695 /**********************************************************
1696 * nsIEmbeddinSiteWindow interface
1699 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1701 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1704 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1705 nsIIDRef riid
, void **result
)
1707 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1708 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1711 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1713 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1714 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1717 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1719 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1720 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1723 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1724 UINT32 flags
, LONG x
, LONG y
, LONG cx
, LONG cy
)
1726 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1727 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1728 return NS_ERROR_NOT_IMPLEMENTED
;
1731 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1732 UINT32 flags
, LONG
*x
, LONG
*y
, LONG
*cx
, LONG
*cy
)
1734 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1737 TRACE("(%p)->(%x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1739 if(!GetWindowRect(This
->hwnd
, &r
)) {
1740 ERR("GetWindowRect failed\n");
1741 return NS_ERROR_FAILURE
;
1749 *cx
= r
.right
-r
.left
;
1751 *cy
= r
.bottom
-r
.top
;
1755 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1757 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1759 TRACE("(%p)\n", This
);
1761 return nsIBaseWindow_SetFocus(This
->window
);
1764 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1765 cpp_bool
*aVisibility
)
1767 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1769 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1771 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1775 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1776 cpp_bool aVisibility
)
1778 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1780 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1785 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1788 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1789 WARN("(%p)->(%p)\n", This
, aTitle
);
1790 return NS_ERROR_NOT_IMPLEMENTED
;
1793 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1794 const PRUnichar
*aTitle
)
1796 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1797 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1798 return NS_ERROR_NOT_IMPLEMENTED
;
1801 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1804 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1806 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1808 *aSiteWindow
= This
->hwnd
;
1812 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1813 nsEmbeddingSiteWindow_QueryInterface
,
1814 nsEmbeddingSiteWindow_AddRef
,
1815 nsEmbeddingSiteWindow_Release
,
1816 nsEmbeddingSiteWindow_SetDimensions
,
1817 nsEmbeddingSiteWindow_GetDimensions
,
1818 nsEmbeddingSiteWindow_SetFocus
,
1819 nsEmbeddingSiteWindow_GetVisibility
,
1820 nsEmbeddingSiteWindow_SetVisibility
,
1821 nsEmbeddingSiteWindow_GetTitle
,
1822 nsEmbeddingSiteWindow_SetTitle
,
1823 nsEmbeddingSiteWindow_GetSiteWindow
1826 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1828 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1831 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1834 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1835 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1838 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1840 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1841 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1844 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1846 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1847 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1850 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1851 LONG aXCoord
, LONG aYCoord
, const PRUnichar
*aTipText
)
1853 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1856 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1861 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1863 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1866 hide_tooltip(This
->doc
);
1871 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1872 nsTooltipListener_QueryInterface
,
1873 nsTooltipListener_AddRef
,
1874 nsTooltipListener_Release
,
1875 nsTooltipListener_OnShowTooltip
,
1876 nsTooltipListener_OnHideTooltip
1879 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1881 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1884 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1885 nsIIDRef riid
, void **result
)
1887 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1888 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1891 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1893 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1894 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1897 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1899 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1900 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1903 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1904 nsIIDRef riid
, void **result
)
1906 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1908 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1909 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1910 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1913 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1916 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1917 nsInterfaceRequestor_QueryInterface
,
1918 nsInterfaceRequestor_AddRef
,
1919 nsInterfaceRequestor_Release
,
1920 nsInterfaceRequestor_GetInterface
1923 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1925 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1928 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1929 nsIIDRef riid
, void **result
)
1931 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1932 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1935 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1937 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1938 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1941 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1943 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1944 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1947 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1948 nsIWeakReference
**_retval
)
1950 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1952 TRACE("(%p)->(%p)\n", This
, _retval
);
1954 if(!This
->weak_reference
) {
1955 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1956 if(!This
->weak_reference
)
1957 return NS_ERROR_OUT_OF_MEMORY
;
1959 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1960 This
->weak_reference
->ref
= 1;
1961 This
->weak_reference
->nscontainer
= This
;
1964 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1965 nsIWeakReference_AddRef(*_retval
);
1969 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1970 nsSupportsWeakReference_QueryInterface
,
1971 nsSupportsWeakReference_AddRef
,
1972 nsSupportsWeakReference_Release
,
1973 nsSupportsWeakReference_GetWeakReference
1976 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1978 nsIWebBrowserSetup
*wbsetup
;
1979 nsIScrollable
*scrollable
;
1982 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1983 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1984 if(NS_FAILED(nsres
)) {
1985 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1989 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1990 if(NS_FAILED(nsres
)) {
1991 ERR("SetContainerWindow failed: %08x\n", nsres
);
1995 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1996 (void**)&nscontainer
->window
);
1997 if(NS_FAILED(nsres
)) {
1998 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
2002 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
2004 if(NS_SUCCEEDED(nsres
)) {
2005 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
2006 nsIWebBrowserSetup_Release(wbsetup
);
2007 if(NS_FAILED(nsres
)) {
2008 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
2012 ERR("Could not get nsIWebBrowserSetup interface\n");
2016 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
2017 (void**)&nscontainer
->navigation
);
2018 if(NS_FAILED(nsres
)) {
2019 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
2023 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
2024 (void**)&nscontainer
->focus
);
2025 if(NS_FAILED(nsres
)) {
2026 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
2030 if(!nscontainer_class
) {
2031 register_nscontainer_class();
2032 if(!nscontainer_class
)
2036 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
2037 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
2038 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
2039 if(!nscontainer
->hwnd
) {
2040 WARN("Could not create window\n");
2044 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
2045 if(NS_SUCCEEDED(nsres
)) {
2046 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
2047 if(NS_FAILED(nsres
)) {
2048 WARN("Creating window failed: %08x\n", nsres
);
2052 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
2053 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
2055 ERR("InitWindow failed: %08x\n", nsres
);
2059 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
2060 &nscontainer
->nsIURIContentListener_iface
);
2061 if(NS_FAILED(nsres
))
2062 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
2064 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
2065 if(NS_SUCCEEDED(nsres
)) {
2066 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2067 ScrollOrientation_Y
, Scrollbar_Always
);
2068 if(NS_FAILED(nsres
))
2069 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2071 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2072 ScrollOrientation_X
, Scrollbar_Auto
);
2073 if(NS_FAILED(nsres
))
2074 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2076 nsIScrollable_Release(scrollable
);
2078 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2084 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2090 return CLASS_E_CLASSNOTAVAILABLE
;
2092 ret
= heap_alloc_zero(sizeof(NSContainer
));
2094 return E_OUTOFMEMORY
;
2096 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2097 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2098 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2099 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2100 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2101 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2102 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2107 hres
= init_nscontainer(ret
);
2111 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2115 void NSContainer_Release(NSContainer
*This
)
2117 TRACE("(%p)\n", This
);
2121 ShowWindow(This
->hwnd
, SW_HIDE
);
2122 SetParent(This
->hwnd
, NULL
);
2124 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2125 nsIBaseWindow_Destroy(This
->window
);
2127 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2129 nsIWebBrowser_Release(This
->webbrowser
);
2130 This
->webbrowser
= NULL
;
2132 nsIWebNavigation_Release(This
->navigation
);
2133 This
->navigation
= NULL
;
2135 nsIBaseWindow_Release(This
->window
);
2136 This
->window
= NULL
;
2138 nsIWebBrowserFocus_Release(This
->focus
);
2141 if(This
->editor_controller
) {
2142 nsIController_Release(This
->editor_controller
);
2143 This
->editor_controller
= NULL
;
2147 nsIEditor_Release(This
->editor
);
2148 This
->editor
= NULL
;
2151 if(This
->content_listener
) {
2152 nsIURIContentListener_Release(This
->content_listener
);
2153 This
->content_listener
= NULL
;
2157 DestroyWindow(This
->hwnd
);
2161 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);