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"
51 #define NS_XMLHTTPREQUEST_CONTRACTID "@mozilla.org/xmlextras/xmlhttprequest;1"
52 #define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1"
54 #define PR_UINT32_MAX 0xffffffff
56 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
57 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
59 typedef UINT32 PRUint32
;
61 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
62 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
63 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
64 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
65 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
66 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
67 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
68 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
69 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
70 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,cpp_bool
,nsIFile
**);
71 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,cpp_bool
*);
72 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,cpp_bool
*);
73 static void* (CDECL
*NS_Alloc
)(SIZE_T
);
74 static void (CDECL
*NS_Free
)(void*);
76 static HINSTANCE xul_handle
= NULL
;
78 static nsIServiceManager
*pServMgr
= NULL
;
79 static nsIComponentManager
*pCompMgr
= NULL
;
80 static nsICategoryManager
*cat_mgr
;
81 static nsIFile
*profile_directory
, *plugin_directory
;
83 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
85 static ATOM nscontainer_class
;
86 static WCHAR gecko_path
[MAX_PATH
];
87 static unsigned gecko_path_len
;
89 nsresult
create_nsfile(const PRUnichar
*path
, nsIFile
**ret
)
94 nsAString_InitDepend(&str
, path
);
95 nsres
= NS_NewLocalFile(&str
, FALSE
, ret
);
96 nsAString_Finish(&str
);
99 WARN("NS_NewLocalFile failed: %08x\n", nsres
);
104 nsISimpleEnumerator nsISimpleEnumerator_iface
;
107 } nsSingletonEnumerator
;
109 static inline nsSingletonEnumerator
*impl_from_nsISimpleEnumerator(nsISimpleEnumerator
*iface
)
111 return CONTAINING_RECORD(iface
, nsSingletonEnumerator
, nsISimpleEnumerator_iface
);
114 static nsresult NSAPI
nsSingletonEnumerator_QueryInterface(nsISimpleEnumerator
*iface
, nsIIDRef riid
, void **ppv
)
116 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
118 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
119 TRACE("(%p)->(IID_nsISupports %p)\n", This
, ppv
);
120 *ppv
= &This
->nsISimpleEnumerator_iface
;
121 }else if(IsEqualGUID(&IID_nsISimpleEnumerator
, riid
)) {
122 TRACE("(%p)->(IID_nsISimpleEnumerator %p)\n", This
, ppv
);
123 *ppv
= &This
->nsISimpleEnumerator_iface
;
125 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
127 return NS_NOINTERFACE
;
130 nsISupports_AddRef((nsISupports
*)*ppv
);
134 static nsrefcnt NSAPI
nsSingletonEnumerator_AddRef(nsISimpleEnumerator
*iface
)
136 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
137 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
139 TRACE("(%p) ref=%d\n", This
, ref
);
144 static nsrefcnt NSAPI
nsSingletonEnumerator_Release(nsISimpleEnumerator
*iface
)
146 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
147 nsrefcnt ref
= InterlockedDecrement(&This
->ref
);
149 TRACE("(%p) ref=%d\n", This
, ref
);
153 nsISupports_Release(This
->value
);
160 static nsresult NSAPI
nsSingletonEnumerator_HasMoreElements(nsISimpleEnumerator
*iface
, cpp_bool
*_retval
)
162 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
164 TRACE("(%p)->()\n", This
);
166 *_retval
= This
->value
!= NULL
;
170 static nsresult NSAPI
nsSingletonEnumerator_GetNext(nsISimpleEnumerator
*iface
, nsISupports
**_retval
)
172 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
174 TRACE("(%p)->()\n", This
);
177 return NS_ERROR_UNEXPECTED
;
179 *_retval
= This
->value
;
184 static const nsISimpleEnumeratorVtbl nsSingletonEnumeratorVtbl
= {
185 nsSingletonEnumerator_QueryInterface
,
186 nsSingletonEnumerator_AddRef
,
187 nsSingletonEnumerator_Release
,
188 nsSingletonEnumerator_HasMoreElements
,
189 nsSingletonEnumerator_GetNext
192 static nsISimpleEnumerator
*create_singleton_enumerator(nsISupports
*value
)
194 nsSingletonEnumerator
*ret
;
196 ret
= heap_alloc(sizeof(*ret
));
200 ret
->nsISimpleEnumerator_iface
.lpVtbl
= &nsSingletonEnumeratorVtbl
;
204 nsISupports_AddRef(value
);
206 return &ret
->nsISimpleEnumerator_iface
;
209 static nsresult NSAPI
nsDirectoryServiceProvider2_QueryInterface(nsIDirectoryServiceProvider2
*iface
,
210 nsIIDRef riid
, void **result
)
212 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
213 TRACE("(IID_nsISupports %p)\n", result
);
215 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
216 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
218 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider2
, riid
)) {
219 TRACE("(IID_nsIDirectoryServiceProvider2 %p)\n", result
);
222 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
224 return NS_NOINTERFACE
;
227 nsISupports_AddRef((nsISupports
*)*result
);
231 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_AddRef(nsIDirectoryServiceProvider2
*iface
)
236 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_Release(nsIDirectoryServiceProvider2
*iface
)
241 static nsresult
create_profile_directory(void)
243 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
245 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
250 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
252 ERR("SHGetFolderPath failed: %08x\n", hres
);
253 return NS_ERROR_FAILURE
;
256 strcatW(path
, wine_geckoW
);
257 nsres
= create_nsfile(path
, &profile_directory
);
261 nsres
= nsIFile_Exists(profile_directory
, &exists
);
262 if(NS_FAILED(nsres
)) {
263 ERR("Exists failed: %08x\n", nsres
);
268 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
270 ERR("Create failed: %08x\n", nsres
);
276 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFile(nsIDirectoryServiceProvider2
*iface
,
277 const char *prop
, cpp_bool
*persistent
, nsIFile
**_retval
)
279 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
281 if(!strcmp(prop
, "ProfD")) {
282 if(!profile_directory
) {
285 nsres
= create_profile_directory();
290 assert(profile_directory
!= NULL
);
291 return nsIFile_Clone(profile_directory
, _retval
);
295 return NS_ERROR_FAILURE
;
298 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFiles(nsIDirectoryServiceProvider2
*iface
,
299 const char *prop
, nsISimpleEnumerator
**_retval
)
301 TRACE("(%s %p)\n", debugstr_a(prop
), _retval
);
303 if(!strcmp(prop
, "APluginsDL")) {
304 WCHAR plugin_path
[MAX_PATH
];
309 if(!plugin_directory
) {
310 static const WCHAR gecko_pluginW
[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
312 len
= GetSystemDirectoryW(plugin_path
, (sizeof(plugin_path
)-sizeof(gecko_pluginW
))/sizeof(WCHAR
)+1);
314 return NS_ERROR_UNEXPECTED
;
316 strcpyW(plugin_path
+len
, gecko_pluginW
);
317 nsres
= create_nsfile(plugin_path
, &plugin_directory
);
318 if(NS_FAILED(nsres
)) {
324 nsres
= nsIFile_Clone(plugin_directory
, &file
);
328 *_retval
= create_singleton_enumerator((nsISupports
*)file
);
329 nsIFile_Release(file
);
331 return NS_ERROR_OUT_OF_MEMORY
;
337 return NS_ERROR_FAILURE
;
340 static const nsIDirectoryServiceProvider2Vtbl nsDirectoryServiceProvider2Vtbl
= {
341 nsDirectoryServiceProvider2_QueryInterface
,
342 nsDirectoryServiceProvider2_AddRef
,
343 nsDirectoryServiceProvider2_Release
,
344 nsDirectoryServiceProvider2_GetFile
,
345 nsDirectoryServiceProvider2_GetFiles
348 static nsIDirectoryServiceProvider2 nsDirectoryServiceProvider2
=
349 { &nsDirectoryServiceProvider2Vtbl
};
351 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
356 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
358 if(msg
== WM_CREATE
) {
359 This
= *(NSContainer
**)lParam
;
360 SetPropW(hwnd
, wszTHIS
, This
);
362 This
= GetPropW(hwnd
, wszTHIS
);
367 TRACE("(%p)->(WM_SIZE)\n", This
);
369 nsres
= nsIBaseWindow_SetSize(This
->window
,
370 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
372 WARN("SetSize failed: %08x\n", nsres
);
375 case WM_PARENTNOTIFY
:
376 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
381 nsIWebBrowserFocus_Activate(This
->focus
);
385 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
389 static void register_nscontainer_class(void)
391 static WNDCLASSEXW wndclass
= {
395 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
399 wndclass
.hInstance
= hInst
;
400 nscontainer_class
= RegisterClassExW(&wndclass
);
403 static BOOL
install_wine_gecko(void)
405 PROCESS_INFORMATION pi
;
412 static const WCHAR controlW
[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
413 static const WCHAR argsW
[] =
414 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
416 len
= GetSystemDirectoryW(app
, MAX_PATH
-sizeof(controlW
)/sizeof(WCHAR
));
417 memcpy(app
+len
, controlW
, sizeof(controlW
));
419 args
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(controlW
) + sizeof(argsW
));
423 memcpy(args
, app
, len
*sizeof(WCHAR
) + sizeof(controlW
));
424 memcpy(args
+ len
+ sizeof(controlW
)/sizeof(WCHAR
)-1, argsW
, sizeof(argsW
));
426 TRACE("starting %s\n", debugstr_w(args
));
428 memset(&si
, 0, sizeof(si
));
430 ret
= CreateProcessW(app
, args
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
433 CloseHandle(pi
.hThread
);
434 WaitForSingleObject(pi
.hProcess
, INFINITE
);
435 CloseHandle(pi
.hProcess
);
441 static void set_environment(LPCWSTR gre_path
)
443 size_t len
, gre_path_len
;
445 WCHAR
*path
, buf
[20];
448 static const WCHAR pathW
[] = {'P','A','T','H',0};
449 static const WCHAR warnW
[] = {'w','a','r','n',0};
450 static const WCHAR xpcom_debug_breakW
[] =
451 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
452 static const WCHAR nspr_log_modulesW
[] =
453 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
454 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
456 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
460 else if(WARN_ON(gecko
))
462 else if(ERR_ON(gecko
))
465 sprintfW(buf
, debug_formatW
, debug_level
);
466 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
468 len
= GetEnvironmentVariableW(pathW
, NULL
, 0);
469 gre_path_len
= strlenW(gre_path
);
470 path
= heap_alloc((len
+gre_path_len
+1)*sizeof(WCHAR
));
473 GetEnvironmentVariableW(pathW
, path
, len
);
475 /* We have to modify PATH as xul.dll loads other DLLs from this directory. */
476 if(!(ptr
= strstrW(path
, gre_path
))
477 || (ptr
> path
&& *(ptr
-1) != ';')
478 || (ptr
[gre_path_len
] && ptr
[gre_path_len
] != ';')) {
481 strcpyW(path
+len
, gre_path
);
482 SetEnvironmentVariableW(pathW
, path
);
487 static BOOL
load_xul(const PRUnichar
*gre_path
)
489 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
490 WCHAR file_name
[MAX_PATH
];
492 strcpyW(file_name
, gre_path
);
493 strcatW(file_name
, xul_dllW
);
495 TRACE("(%s)\n", debugstr_w(file_name
));
497 set_environment(gre_path
);
499 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
501 WARN("Could not load XUL: %d\n", GetLastError());
505 #define NS_DLSYM(func) \
506 func = (void *)GetProcAddress(xul_handle, #func); \
508 ERR("Could not GetProcAddress(" #func ") failed\n")
510 NS_DLSYM(NS_InitXPCOM2
);
511 NS_DLSYM(NS_ShutdownXPCOM
);
512 NS_DLSYM(NS_GetComponentRegistrar
);
513 NS_DLSYM(NS_StringContainerInit2
);
514 NS_DLSYM(NS_CStringContainerInit2
);
515 NS_DLSYM(NS_StringContainerFinish
);
516 NS_DLSYM(NS_CStringContainerFinish
);
517 NS_DLSYM(NS_StringSetData
);
518 NS_DLSYM(NS_CStringSetData
);
519 NS_DLSYM(NS_NewLocalFile
);
520 NS_DLSYM(NS_StringGetData
);
521 NS_DLSYM(NS_CStringGetData
);
524 NS_DLSYM(ccref_incr
);
525 NS_DLSYM(ccref_decr
);
526 NS_DLSYM(ccref_init
);
528 NS_DLSYM(describe_cc_node
);
529 NS_DLSYM(note_cc_edge
);
536 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
538 WCHAR file_name
[MAX_PATH
];
543 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
545 strcpyW(file_name
, gre_path
);
546 strcatW(file_name
, wszVersion
);
548 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
549 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
550 if(hfile
== INVALID_HANDLE_VALUE
) {
551 ERR("Could not open VERSION file\n");
555 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
559 TRACE("%s\n", debugstr_a(version
));
561 if(strcmp(version
, version_string
)) {
562 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
563 debugstr_a(version_string
));
570 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
571 const char *version
, const char *version_string
)
573 DWORD res
, type
, size
= MAX_PATH
;
574 HKEY hkey
= mshtml_key
;
576 static const WCHAR wszGeckoPath
[] =
577 {'G','e','c','k','o','P','a','t','h',0};
580 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
581 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
582 if(res
!= ERROR_SUCCESS
)
586 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
587 if(hkey
!= mshtml_key
)
589 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
592 if(!check_version(gre_path
, version_string
))
595 return load_xul(gre_path
);
598 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
604 static const WCHAR wszMshtmlKey
[] = {
605 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
606 '\\','M','S','H','T','M','L',0};
608 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
609 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
610 if(res
!= ERROR_SUCCESS
)
613 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
619 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
623 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
625 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
628 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
632 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
634 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
637 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
641 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
643 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
646 static void set_lang(nsIPrefBranch
*pref
)
649 DWORD res
, size
, type
;
652 static const WCHAR international_keyW
[] =
653 {'S','o','f','t','w','a','r','e',
654 '\\','M','i','c','r','o','s','o','f','t',
655 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
656 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
658 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
659 if(res
!= ERROR_SUCCESS
)
662 size
= sizeof(langs
);
663 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
665 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
668 TRACE("Setting lang %s\n", debugstr_a(langs
));
670 set_string_pref(pref
, "intl.accept_languages", langs
);
673 static void set_preferences(void)
678 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
679 &IID_nsIPrefBranch
, (void**)&pref
);
680 if(NS_FAILED(nsres
)) {
681 ERR("Could not get preference service: %08x\n", nsres
);
686 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
687 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
688 set_int_pref(pref
, "layout.spellcheckDefault", 0);
690 nsIPrefBranch_Release(pref
);
693 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
695 nsIComponentRegistrar
*registrar
= NULL
;
700 nsres
= create_nsfile(gre_path
, &gre_dir
);
701 if(NS_FAILED(nsres
)) {
702 FreeLibrary(xul_handle
);
706 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
707 if(NS_FAILED(nsres
)) {
708 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
709 FreeLibrary(xul_handle
);
713 strcpyW(gecko_path
, gre_path
);
714 for(ptr
= gecko_path
; *ptr
; ptr
++) {
718 gecko_path_len
= ptr
-gecko_path
;
720 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
722 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
724 nsres
= NS_GetComponentRegistrar(®istrar
);
725 if(NS_SUCCEEDED(nsres
))
726 init_nsio(pCompMgr
, registrar
);
728 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
730 init_mutation(pCompMgr
);
733 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_CATEGORYMANAGER_CONTRACTID
,
734 &IID_nsICategoryManager
, (void**)&cat_mgr
);
736 ERR("Could not get category manager service: %08x\n", nsres
);
739 register_nsservice(registrar
, pServMgr
);
740 nsIComponentRegistrar_Release(registrar
);
748 static CRITICAL_SECTION cs_load_gecko
;
749 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
751 0, 0, &cs_load_gecko
,
752 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
753 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
755 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
757 BOOL
load_gecko(void)
759 PRUnichar gre_path
[MAX_PATH
];
762 static DWORD loading_thread
;
766 /* load_gecko may be called recursively */
767 if(loading_thread
== GetCurrentThreadId())
768 return pCompMgr
!= NULL
;
770 EnterCriticalSection(&cs_load_gecko
);
772 if(!loading_thread
) {
773 loading_thread
= GetCurrentThreadId();
775 if(load_wine_gecko(gre_path
)
776 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
777 ret
= init_xpcom(gre_path
);
779 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
781 ret
= pCompMgr
!= NULL
;
784 LeaveCriticalSection(&cs_load_gecko
);
789 void *nsalloc(size_t size
)
791 return NS_Alloc(size
);
794 void nsfree(void *mem
)
799 BOOL
nsACString_Init(nsACString
*str
, const char *data
)
801 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
805 * Initializes nsACString with data owned by caller.
806 * Caller must ensure that data is valid during lifetime of string object.
808 void nsACString_InitDepend(nsACString
*str
, const char *data
)
810 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
813 void nsACString_SetData(nsACString
*str
, const char *data
)
815 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
818 UINT32
nsACString_GetData(const nsACString
*str
, const char **data
)
820 return NS_CStringGetData(str
, data
, NULL
);
823 void nsACString_Finish(nsACString
*str
)
825 NS_CStringContainerFinish(str
);
828 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
830 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
834 * Initializes nsAString with data owned by caller.
835 * Caller must ensure that data is valid during lifetime of string object.
837 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
839 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
842 UINT32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
844 return NS_StringGetData(str
, data
, NULL
);
847 void nsAString_Finish(nsAString
*str
)
849 NS_StringContainerFinish(str
);
852 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
854 const PRUnichar
*str
;
856 if(NS_FAILED(nsres
)) {
857 ERR("failed: %08x\n", nsres
);
858 nsAString_Finish(nsstr
);
862 nsAString_GetData(nsstr
, &str
);
863 TRACE("ret %s\n", debugstr_w(str
));
865 *p
= SysAllocString(str
);
867 return E_OUTOFMEMORY
;
872 nsAString_Finish(nsstr
);
876 nsICommandParams
*create_nscommand_params(void)
878 nsICommandParams
*ret
= NULL
;
884 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
885 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
888 ERR("Could not get nsICommandParams\n");
893 nsIWritableVariant
*create_nsvariant(void)
895 nsIWritableVariant
*ret
= NULL
;
901 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
902 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
904 ERR("Could not get nsIVariant\n");
909 char *get_nscategory_entry(const char *category
, const char *entry
)
914 nsres
= nsICategoryManager_GetCategoryEntry(cat_mgr
, category
, entry
, &ret
);
915 return NS_SUCCEEDED(nsres
) ? ret
: NULL
;
918 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
920 nsIInterfaceRequestor
*iface_req
;
923 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
927 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
928 nsIInterfaceRequestor_Release(iface_req
);
933 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
935 nsIDOMNodeList
*node_list
= NULL
;
936 cpp_bool has_children
= FALSE
;
937 nsIContent
*nscontent
;
941 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
943 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
944 if(NS_FAILED(nsres
)) {
945 ERR("GetType failed: %08x\n", nsres
);
949 if(type
!= DOCUMENT_NODE
) {
950 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
951 if(NS_FAILED(nsres
)) {
952 ERR("Could not get nsIContent interface: %08x\n", nsres
);
959 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
962 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
965 nsres
= nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
967 case DOCUMENT_NODE
: {
969 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
970 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
971 nsIDocument_Release(nsdoc
);
974 case DOCUMENT_TYPE_NODE
:
975 nsIContentSerializer_AppendDoctype(serializer
, nscontent
, str
);
977 case DOCUMENT_FRAGMENT_NODE
:
980 FIXME("Unhandled type %u\n", type
);
985 nsIDOMNode
*child_node
;
987 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
988 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
990 for(i
=0; i
<child_cnt
; i
++) {
991 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
992 if(NS_SUCCEEDED(nsres
)) {
993 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
994 nsIDOMNode_Release(child_node
);
996 ERR("Item failed: %08x\n", nsres
);
1000 nsIDOMNodeList_Release(node_list
);
1003 if(type
== ELEMENT_NODE
)
1004 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
1006 if(type
!= DOCUMENT_NODE
)
1007 nsIContent_Release(nscontent
);
1011 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
1013 nsIContentSerializer
*serializer
;
1017 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1018 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
1019 (void**)&serializer
);
1020 if(NS_FAILED(nsres
)) {
1021 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1025 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1026 if(NS_FAILED(nsres
))
1027 ERR("Init failed: %08x\n", nsres
);
1029 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1030 if(SUCCEEDED(hres
)) {
1031 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1032 if(NS_FAILED(nsres
))
1033 ERR("Flush failed: %08x\n", nsres
);
1036 nsIContentSerializer_Release(serializer
);
1040 void get_editor_controller(NSContainer
*This
)
1042 nsIEditingSession
*editing_session
= NULL
;
1043 nsIControllerContext
*ctrlctx
;
1047 nsIEditor_Release(This
->editor
);
1048 This
->editor
= NULL
;
1051 if(This
->editor_controller
) {
1052 nsIController_Release(This
->editor_controller
);
1053 This
->editor_controller
= NULL
;
1056 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1057 (void**)&editing_session
);
1058 if(NS_FAILED(nsres
)) {
1059 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1063 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1064 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
1065 nsIEditingSession_Release(editing_session
);
1066 if(NS_FAILED(nsres
)) {
1067 ERR("Could not get editor: %08x\n", nsres
);
1071 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1072 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1073 if(NS_SUCCEEDED(nsres
)) {
1074 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1075 if(NS_FAILED(nsres
))
1076 ERR("SetCommandContext failed: %08x\n", nsres
);
1077 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1078 (void**)&This
->editor_controller
);
1079 nsIControllerContext_Release(ctrlctx
);
1080 if(NS_FAILED(nsres
))
1081 ERR("Could not get nsIController interface: %08x\n", nsres
);
1083 ERR("Could not create edit controller: %08x\n", nsres
);
1087 void close_gecko(void)
1092 init_mutation(NULL
);
1094 if(profile_directory
) {
1095 nsIFile_Release(profile_directory
);
1096 profile_directory
= NULL
;
1099 if(plugin_directory
) {
1100 nsIFile_Release(plugin_directory
);
1101 plugin_directory
= NULL
;
1105 nsIComponentManager_Release(pCompMgr
);
1108 nsIServiceManager_Release(pServMgr
);
1111 nsICategoryManager_Release(cat_mgr
);
1113 /* Gecko doesn't really support being unloaded */
1114 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1116 DeleteCriticalSection(&cs_load_gecko
);
1119 BOOL
is_gecko_path(const char *path
)
1124 buf
= heap_strdupUtoW(path
);
1125 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1128 for(ptr
= buf
; *ptr
; ptr
++) {
1133 UrlUnescapeW(buf
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1134 buf
[gecko_path_len
] = 0;
1136 ret
= !strcmpiW(buf
, gecko_path
);
1141 void set_viewer_zoom(NSContainer
*nscontainer
, float factor
)
1143 nsIContentViewer
*content_viewer
;
1144 nsIDocShell
*doc_shell
;
1147 TRACE("Setting to %f\n", factor
);
1149 nsres
= get_nsinterface((nsISupports
*)nscontainer
->navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
1150 assert(nsres
== NS_OK
);
1152 nsres
= nsIDocShell_GetContentViewer(doc_shell
, &content_viewer
);
1153 assert(nsres
== NS_OK
&& content_viewer
);
1154 nsIDocShell_Release(doc_shell
);
1156 nsres
= nsIContentViewer_SetFullZoom(content_viewer
, factor
);
1157 if(NS_FAILED(nsres
))
1158 ERR("SetFullZoom failed: %08x\n", nsres
);
1160 nsIContentViewer_Release(content_viewer
);
1163 struct nsWeakReference
{
1164 nsIWeakReference nsIWeakReference_iface
;
1168 NSContainer
*nscontainer
;
1171 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1173 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1176 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1177 nsIIDRef riid
, void **result
)
1179 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1181 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1182 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1183 *result
= &This
->nsIWeakReference_iface
;
1184 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1185 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1186 *result
= &This
->nsIWeakReference_iface
;
1188 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1190 return NS_NOINTERFACE
;
1193 nsISupports_AddRef((nsISupports
*)*result
);
1197 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1199 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1200 LONG ref
= InterlockedIncrement(&This
->ref
);
1202 TRACE("(%p) ref=%d\n", This
, ref
);
1207 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1209 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1210 LONG ref
= InterlockedIncrement(&This
->ref
);
1212 TRACE("(%p) ref=%d\n", This
, ref
);
1215 assert(!This
->nscontainer
);
1222 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1223 const nsIID
*riid
, void **result
)
1225 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1227 if(!This
->nscontainer
)
1228 return NS_ERROR_NULL_POINTER
;
1230 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1233 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1234 nsWeakReference_QueryInterface
,
1235 nsWeakReference_AddRef
,
1236 nsWeakReference_Release
,
1237 nsWeakReference_QueryReferent
1240 /**********************************************************
1241 * nsIWebBrowserChrome interface
1244 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1246 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1249 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1250 nsIIDRef riid
, void **result
)
1252 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1255 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1256 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1257 *result
= &This
->nsIWebBrowserChrome_iface
;
1258 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1259 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1260 *result
= &This
->nsIWebBrowserChrome_iface
;
1261 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1262 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1263 *result
= &This
->nsIContextMenuListener_iface
;
1264 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1265 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1266 *result
= &This
->nsIURIContentListener_iface
;
1267 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1268 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1269 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1270 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1271 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1272 *result
= &This
->nsITooltipListener_iface
;
1273 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1274 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1275 *result
= &This
->nsIInterfaceRequestor_iface
;
1276 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1277 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1278 *result
= &This
->nsISupportsWeakReference_iface
;
1282 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1286 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1287 return NS_NOINTERFACE
;
1290 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1292 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1293 LONG ref
= InterlockedIncrement(&This
->ref
);
1295 TRACE("(%p) ref=%d\n", This
, ref
);
1300 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1302 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1303 LONG ref
= InterlockedDecrement(&This
->ref
);
1305 TRACE("(%p) ref=%d\n", This
, ref
);
1309 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1310 if(This
->weak_reference
) {
1311 This
->weak_reference
->nscontainer
= NULL
;
1312 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1320 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1321 UINT32 statusType
, const PRUnichar
*status
)
1323 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1324 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1328 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1329 nsIWebBrowser
**aWebBrowser
)
1331 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1333 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1336 return NS_ERROR_INVALID_ARG
;
1338 if(This
->webbrowser
)
1339 nsIWebBrowser_AddRef(This
->webbrowser
);
1340 *aWebBrowser
= This
->webbrowser
;
1344 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1345 nsIWebBrowser
*aWebBrowser
)
1347 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1349 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1351 if(aWebBrowser
!= This
->webbrowser
)
1352 ERR("Wrong nsWebBrowser!\n");
1357 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1358 UINT32
*aChromeFlags
)
1360 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1361 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1362 return NS_ERROR_NOT_IMPLEMENTED
;
1365 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1366 UINT32 aChromeFlags
)
1368 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1369 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1370 return NS_ERROR_NOT_IMPLEMENTED
;
1373 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1375 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1376 TRACE("(%p)\n", This
);
1377 return NS_ERROR_NOT_IMPLEMENTED
;
1380 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1383 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1384 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1385 return NS_ERROR_NOT_IMPLEMENTED
;
1388 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1390 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1391 WARN("(%p)\n", This
);
1392 return NS_ERROR_NOT_IMPLEMENTED
;
1395 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1397 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1398 WARN("(%p)->(%p)\n", This
, _retval
);
1399 return NS_ERROR_NOT_IMPLEMENTED
;
1402 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1405 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1406 WARN("(%p)->(%08x)\n", This
, aStatus
);
1407 return NS_ERROR_NOT_IMPLEMENTED
;
1410 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1411 nsWebBrowserChrome_QueryInterface
,
1412 nsWebBrowserChrome_AddRef
,
1413 nsWebBrowserChrome_Release
,
1414 nsWebBrowserChrome_SetStatus
,
1415 nsWebBrowserChrome_GetWebBrowser
,
1416 nsWebBrowserChrome_SetWebBrowser
,
1417 nsWebBrowserChrome_GetChromeFlags
,
1418 nsWebBrowserChrome_SetChromeFlags
,
1419 nsWebBrowserChrome_DestroyBrowserWindow
,
1420 nsWebBrowserChrome_SizeBrowserTo
,
1421 nsWebBrowserChrome_ShowAsModal
,
1422 nsWebBrowserChrome_IsWindowModal
,
1423 nsWebBrowserChrome_ExitModalEventLoop
1426 /**********************************************************
1427 * nsIContextMenuListener interface
1430 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1432 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1435 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1436 nsIIDRef riid
, void **result
)
1438 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1439 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1442 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1444 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1445 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1448 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1450 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1451 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1454 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1455 UINT32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1457 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1458 nsIDOMMouseEvent
*event
;
1461 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1465 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1467 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, aNode
, aEvent
, NULL
);
1469 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1470 if(NS_FAILED(nsres
)) {
1471 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1475 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1476 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1477 nsIDOMMouseEvent_Release(event
);
1479 switch(aContextFlags
) {
1481 case CONTEXT_DOCUMENT
:
1482 case CONTEXT_TEXT
: {
1483 nsISelection
*selection
;
1485 nsres
= nsIDOMHTMLDocument_GetSelection(This
->doc
->basedoc
.doc_node
->nsdoc
, &selection
);
1486 if(NS_SUCCEEDED(nsres
) && selection
) {
1487 cpp_bool is_collapsed
;
1489 /* FIXME: Check if the click was inside selection. */
1490 nsres
= nsISelection_GetIsCollapsed(selection
, &is_collapsed
);
1491 nsISelection_Release(selection
);
1492 if(NS_SUCCEEDED(nsres
) && !is_collapsed
)
1493 dwID
= CONTEXT_MENU_TEXTSELECT
;
1498 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1499 dwID
= CONTEXT_MENU_IMAGE
;
1502 dwID
= CONTEXT_MENU_ANCHOR
;
1505 dwID
= CONTEXT_MENU_CONTROL
;
1508 FIXME("aContextFlags=%08x\n", aContextFlags
);
1511 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1513 return NS_ERROR_FAILURE
;
1515 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1520 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1521 nsContextMenuListener_QueryInterface
,
1522 nsContextMenuListener_AddRef
,
1523 nsContextMenuListener_Release
,
1524 nsContextMenuListener_OnShowContextMenu
1527 /**********************************************************
1528 * nsIURIContentListener interface
1531 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1533 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1536 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1537 nsIIDRef riid
, void **result
)
1539 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1540 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1543 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1545 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1546 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1549 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1551 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1552 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1555 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1556 nsIURI
*aURI
, cpp_bool
*_retval
)
1558 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1559 nsACString spec_str
;
1563 nsACString_Init(&spec_str
, NULL
);
1564 nsIURI_GetSpec(aURI
, &spec_str
);
1565 nsACString_GetData(&spec_str
, &spec
);
1567 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1569 nsACString_Finish(&spec_str
);
1571 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1572 if(NS_FAILED(nsres
))
1575 return !*_retval
&& This
->content_listener
1576 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1580 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1581 const nsACString
*aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1582 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1584 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1586 TRACE("(%p)->(%p %x %p %p %p)\n", This
, aContentType
, aIsContentPreferred
,
1587 aRequest
, aContentHandler
, _retval
);
1589 return This
->content_listener
1590 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1591 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1592 : NS_ERROR_NOT_IMPLEMENTED
;
1595 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1596 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1598 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1600 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1602 /* FIXME: Should we do something here? */
1605 return This
->content_listener
1606 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1607 aDesiredContentType
, _retval
)
1611 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1612 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1615 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1617 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1618 aDesiredContentType
, _retval
);
1620 return This
->content_listener
1621 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1622 aIsContentPreferred
, aDesiredContentType
, _retval
)
1623 : NS_ERROR_NOT_IMPLEMENTED
;
1626 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1627 nsISupports
**aLoadCookie
)
1629 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1631 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1633 return This
->content_listener
1634 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1635 : NS_ERROR_NOT_IMPLEMENTED
;
1638 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1639 nsISupports
*aLoadCookie
)
1641 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1643 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1645 return This
->content_listener
1646 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1647 : NS_ERROR_NOT_IMPLEMENTED
;
1650 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1651 nsIURIContentListener
**aParentContentListener
)
1653 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1655 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1657 if(This
->content_listener
)
1658 nsIURIContentListener_AddRef(This
->content_listener
);
1660 *aParentContentListener
= This
->content_listener
;
1664 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1665 nsIURIContentListener
*aParentContentListener
)
1667 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1669 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1671 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1674 if(This
->content_listener
)
1675 nsIURIContentListener_Release(This
->content_listener
);
1677 This
->content_listener
= aParentContentListener
;
1678 if(This
->content_listener
)
1679 nsIURIContentListener_AddRef(This
->content_listener
);
1684 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1685 nsURIContentListener_QueryInterface
,
1686 nsURIContentListener_AddRef
,
1687 nsURIContentListener_Release
,
1688 nsURIContentListener_OnStartURIOpen
,
1689 nsURIContentListener_DoContent
,
1690 nsURIContentListener_IsPreferred
,
1691 nsURIContentListener_CanHandleContent
,
1692 nsURIContentListener_GetLoadCookie
,
1693 nsURIContentListener_SetLoadCookie
,
1694 nsURIContentListener_GetParentContentListener
,
1695 nsURIContentListener_SetParentContentListener
1698 /**********************************************************
1699 * nsIEmbeddinSiteWindow interface
1702 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1704 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1707 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1708 nsIIDRef riid
, void **result
)
1710 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1711 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1714 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1716 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1717 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1720 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1722 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1723 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1726 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1727 UINT32 flags
, LONG x
, LONG y
, LONG cx
, LONG cy
)
1729 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1730 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1731 return NS_ERROR_NOT_IMPLEMENTED
;
1734 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1735 UINT32 flags
, LONG
*x
, LONG
*y
, LONG
*cx
, LONG
*cy
)
1737 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1740 TRACE("(%p)->(%x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1742 if(!GetWindowRect(This
->hwnd
, &r
)) {
1743 ERR("GetWindowRect failed\n");
1744 return NS_ERROR_FAILURE
;
1752 *cx
= r
.right
-r
.left
;
1754 *cy
= r
.bottom
-r
.top
;
1758 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1760 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1762 TRACE("(%p)\n", This
);
1764 return nsIBaseWindow_SetFocus(This
->window
);
1767 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1768 cpp_bool
*aVisibility
)
1770 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1772 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1774 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1778 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1779 cpp_bool aVisibility
)
1781 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1783 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1788 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1791 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1792 WARN("(%p)->(%p)\n", This
, aTitle
);
1793 return NS_ERROR_NOT_IMPLEMENTED
;
1796 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1797 const PRUnichar
*aTitle
)
1799 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1800 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1801 return NS_ERROR_NOT_IMPLEMENTED
;
1804 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1807 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1809 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1811 *aSiteWindow
= This
->hwnd
;
1815 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1816 nsEmbeddingSiteWindow_QueryInterface
,
1817 nsEmbeddingSiteWindow_AddRef
,
1818 nsEmbeddingSiteWindow_Release
,
1819 nsEmbeddingSiteWindow_SetDimensions
,
1820 nsEmbeddingSiteWindow_GetDimensions
,
1821 nsEmbeddingSiteWindow_SetFocus
,
1822 nsEmbeddingSiteWindow_GetVisibility
,
1823 nsEmbeddingSiteWindow_SetVisibility
,
1824 nsEmbeddingSiteWindow_GetTitle
,
1825 nsEmbeddingSiteWindow_SetTitle
,
1826 nsEmbeddingSiteWindow_GetSiteWindow
1829 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1831 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1834 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1837 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1838 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1841 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1843 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1844 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1847 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1849 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1850 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1853 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1854 LONG aXCoord
, LONG aYCoord
, const PRUnichar
*aTipText
)
1856 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1859 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1864 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1866 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1869 hide_tooltip(This
->doc
);
1874 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1875 nsTooltipListener_QueryInterface
,
1876 nsTooltipListener_AddRef
,
1877 nsTooltipListener_Release
,
1878 nsTooltipListener_OnShowTooltip
,
1879 nsTooltipListener_OnHideTooltip
1882 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1884 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1887 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1888 nsIIDRef riid
, void **result
)
1890 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1891 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1894 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1896 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1897 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1900 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1902 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1903 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1906 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1907 nsIIDRef riid
, void **result
)
1909 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1911 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1912 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1913 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1916 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1919 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1920 nsInterfaceRequestor_QueryInterface
,
1921 nsInterfaceRequestor_AddRef
,
1922 nsInterfaceRequestor_Release
,
1923 nsInterfaceRequestor_GetInterface
1926 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1928 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1931 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1932 nsIIDRef riid
, void **result
)
1934 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1935 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1938 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1940 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1941 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1944 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1946 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1947 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1950 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1951 nsIWeakReference
**_retval
)
1953 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1955 TRACE("(%p)->(%p)\n", This
, _retval
);
1957 if(!This
->weak_reference
) {
1958 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1959 if(!This
->weak_reference
)
1960 return NS_ERROR_OUT_OF_MEMORY
;
1962 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1963 This
->weak_reference
->ref
= 1;
1964 This
->weak_reference
->nscontainer
= This
;
1967 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1968 nsIWeakReference_AddRef(*_retval
);
1972 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1973 nsSupportsWeakReference_QueryInterface
,
1974 nsSupportsWeakReference_AddRef
,
1975 nsSupportsWeakReference_Release
,
1976 nsSupportsWeakReference_GetWeakReference
1979 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1981 nsIWebBrowserSetup
*wbsetup
;
1982 nsIScrollable
*scrollable
;
1985 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1986 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1987 if(NS_FAILED(nsres
)) {
1988 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1992 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1993 if(NS_FAILED(nsres
)) {
1994 ERR("SetContainerWindow failed: %08x\n", nsres
);
1998 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1999 (void**)&nscontainer
->window
);
2000 if(NS_FAILED(nsres
)) {
2001 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
2005 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
2007 if(NS_SUCCEEDED(nsres
)) {
2008 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
2009 nsIWebBrowserSetup_Release(wbsetup
);
2010 if(NS_FAILED(nsres
)) {
2011 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
2015 ERR("Could not get nsIWebBrowserSetup interface\n");
2019 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
2020 (void**)&nscontainer
->navigation
);
2021 if(NS_FAILED(nsres
)) {
2022 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
2026 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
2027 (void**)&nscontainer
->focus
);
2028 if(NS_FAILED(nsres
)) {
2029 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
2033 if(!nscontainer_class
) {
2034 register_nscontainer_class();
2035 if(!nscontainer_class
)
2039 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
2040 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
2041 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
2042 if(!nscontainer
->hwnd
) {
2043 WARN("Could not create window\n");
2047 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
2048 if(NS_SUCCEEDED(nsres
)) {
2049 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
2050 if(NS_FAILED(nsres
)) {
2051 WARN("Creating window failed: %08x\n", nsres
);
2055 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
2056 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
2058 ERR("InitWindow failed: %08x\n", nsres
);
2062 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
2063 &nscontainer
->nsIURIContentListener_iface
);
2064 if(NS_FAILED(nsres
))
2065 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
2067 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
2068 if(NS_SUCCEEDED(nsres
)) {
2069 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2070 ScrollOrientation_Y
, Scrollbar_Always
);
2071 if(NS_FAILED(nsres
))
2072 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2074 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2075 ScrollOrientation_X
, Scrollbar_Auto
);
2076 if(NS_FAILED(nsres
))
2077 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2079 nsIScrollable_Release(scrollable
);
2081 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2087 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2093 return CLASS_E_CLASSNOTAVAILABLE
;
2095 ret
= heap_alloc_zero(sizeof(NSContainer
));
2097 return E_OUTOFMEMORY
;
2099 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2100 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2101 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2102 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2103 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2104 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2105 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2110 hres
= init_nscontainer(ret
);
2114 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2118 void NSContainer_Release(NSContainer
*This
)
2120 TRACE("(%p)\n", This
);
2124 ShowWindow(This
->hwnd
, SW_HIDE
);
2125 SetParent(This
->hwnd
, NULL
);
2127 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2128 nsIBaseWindow_Destroy(This
->window
);
2130 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2132 nsIWebBrowser_Release(This
->webbrowser
);
2133 This
->webbrowser
= NULL
;
2135 nsIWebNavigation_Release(This
->navigation
);
2136 This
->navigation
= NULL
;
2138 nsIBaseWindow_Release(This
->window
);
2139 This
->window
= NULL
;
2141 nsIWebBrowserFocus_Release(This
->focus
);
2144 if(This
->editor_controller
) {
2145 nsIController_Release(This
->editor_controller
);
2146 This
->editor_controller
= NULL
;
2150 nsIEditor_Release(This
->editor
);
2151 This
->editor
= NULL
;
2154 if(This
->content_listener
) {
2155 nsIURIContentListener_Release(This
->content_listener
);
2156 This
->content_listener
= NULL
;
2160 DestroyWindow(This
->hwnd
);
2164 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
2167 nsIXMLHttpRequest
*create_nsxhr(nsIDOMWindow
*nswindow
)
2169 nsIScriptSecurityManager
*secman
;
2170 nsIPrincipal
*nspri
;
2171 nsIGlobalObject
*nsglo
;
2172 nsIXMLHttpRequest
*nsxhr
;
2175 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
,
2176 NS_SCRIPTSECURITYMANAGER_CONTRACTID
,
2177 &IID_nsIScriptSecurityManager
, (void**)&secman
);
2178 if(NS_FAILED(nsres
)) {
2179 ERR("Could not get sec manager service: %08x\n", nsres
);
2183 nsres
= nsIScriptSecurityManager_GetSystemPrincipal(secman
, &nspri
);
2184 nsIScriptSecurityManager_Release(secman
);
2185 if(NS_FAILED(nsres
)) {
2186 ERR("GetSystemPrincipal failed: %08x\n", nsres
);
2190 nsres
= nsIDOMWindow_QueryInterface(nswindow
, &IID_nsIGlobalObject
, (void **)&nsglo
);
2191 assert(nsres
== NS_OK
);
2193 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
2194 NS_XMLHTTPREQUEST_CONTRACTID
, NULL
, &IID_nsIXMLHttpRequest
,
2196 if(NS_FAILED(nsres
)) {
2197 ERR("Could not get nsIXMLHttpRequest: %08x\n", nsres
);
2198 nsISupports_Release(nspri
);
2199 nsIGlobalObject_Release(nsglo
);
2203 nsres
= nsIXMLHttpRequest_Init(nsxhr
, nspri
, NULL
, nsglo
, NULL
, NULL
);
2205 nsISupports_Release(nspri
);
2206 nsIGlobalObject_Release(nsglo
);
2207 if(NS_FAILED(nsres
)) {
2208 ERR("nsIXMLHttpRequest_Init failed: %08x\n", nsres
);
2209 nsIXMLHttpRequest_Release(nsxhr
);