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"
53 #define PR_UINT32_MAX 0xffffffff
55 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
56 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
58 typedef UINT32 PRUint32
;
60 static nsresult (CDECL
*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
61 static nsresult (CDECL
*NS_ShutdownXPCOM
)(nsIServiceManager
*);
62 static nsresult (CDECL
*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
63 static nsresult (CDECL
*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
64 static nsresult (CDECL
*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
65 static nsresult (CDECL
*NS_StringContainerFinish
)(nsStringContainer
*);
66 static nsresult (CDECL
*NS_CStringContainerFinish
)(nsCStringContainer
*);
67 static nsresult (CDECL
*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
68 static nsresult (CDECL
*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
69 static nsresult (CDECL
*NS_NewLocalFile
)(const nsAString
*,cpp_bool
,nsIFile
**);
70 static PRUint32 (CDECL
*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,cpp_bool
*);
71 static PRUint32 (CDECL
*NS_CStringGetData
)(const nsACString
*,const char**,cpp_bool
*);
72 static cpp_bool (CDECL
*NS_StringGetIsVoid
)(const nsAString
*);
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
);
522 NS_DLSYM(NS_StringGetIsVoid
);
525 NS_DLSYM(ccref_incr
);
526 NS_DLSYM(ccref_decr
);
527 NS_DLSYM(ccref_init
);
529 NS_DLSYM(describe_cc_node
);
530 NS_DLSYM(note_cc_edge
);
537 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
539 WCHAR file_name
[MAX_PATH
];
544 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
546 strcpyW(file_name
, gre_path
);
547 strcatW(file_name
, wszVersion
);
549 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
550 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
551 if(hfile
== INVALID_HANDLE_VALUE
) {
552 ERR("Could not open VERSION file\n");
556 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
560 TRACE("%s\n", debugstr_a(version
));
562 if(strcmp(version
, version_string
)) {
563 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
564 debugstr_a(version_string
));
571 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
572 const char *version
, const char *version_string
)
574 DWORD res
, type
, size
= MAX_PATH
;
575 HKEY hkey
= mshtml_key
;
577 static const WCHAR wszGeckoPath
[] =
578 {'G','e','c','k','o','P','a','t','h',0};
581 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
582 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
583 if(res
!= ERROR_SUCCESS
)
587 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
588 if(hkey
!= mshtml_key
)
590 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
593 if(!check_version(gre_path
, version_string
))
596 return load_xul(gre_path
);
599 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
605 static const WCHAR wszMshtmlKey
[] = {
606 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
607 '\\','M','S','H','T','M','L',0};
609 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
610 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
611 if(res
!= ERROR_SUCCESS
)
614 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
620 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
624 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
626 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
629 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
633 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
635 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
638 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
642 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
644 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
647 static void set_lang(nsIPrefBranch
*pref
)
650 DWORD res
, size
, type
;
653 static const WCHAR international_keyW
[] =
654 {'S','o','f','t','w','a','r','e',
655 '\\','M','i','c','r','o','s','o','f','t',
656 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
657 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
659 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
660 if(res
!= ERROR_SUCCESS
)
663 size
= sizeof(langs
);
664 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
666 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
669 TRACE("Setting lang %s\n", debugstr_a(langs
));
671 set_string_pref(pref
, "intl.accept_languages", langs
);
674 static void set_preferences(void)
679 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
680 &IID_nsIPrefBranch
, (void**)&pref
);
681 if(NS_FAILED(nsres
)) {
682 ERR("Could not get preference service: %08x\n", nsres
);
687 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
688 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
689 set_int_pref(pref
, "layout.spellcheckDefault", 0);
691 nsIPrefBranch_Release(pref
);
694 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
696 nsIComponentRegistrar
*registrar
= NULL
;
701 nsres
= create_nsfile(gre_path
, &gre_dir
);
702 if(NS_FAILED(nsres
)) {
703 FreeLibrary(xul_handle
);
707 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
708 if(NS_FAILED(nsres
)) {
709 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
710 FreeLibrary(xul_handle
);
714 strcpyW(gecko_path
, gre_path
);
715 for(ptr
= gecko_path
; *ptr
; ptr
++) {
719 gecko_path_len
= ptr
-gecko_path
;
721 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
723 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
726 init_mutation(pCompMgr
);
729 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_CATEGORYMANAGER_CONTRACTID
,
730 &IID_nsICategoryManager
, (void**)&cat_mgr
);
732 ERR("Could not get category manager service: %08x\n", nsres
);
734 nsres
= NS_GetComponentRegistrar(®istrar
);
735 if(NS_SUCCEEDED(nsres
)) {
736 register_nsservice(registrar
, pServMgr
);
737 nsIComponentRegistrar_Release(registrar
);
739 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
747 static CRITICAL_SECTION cs_load_gecko
;
748 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
750 0, 0, &cs_load_gecko
,
751 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
752 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
754 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
756 BOOL
load_gecko(void)
758 PRUnichar gre_path
[MAX_PATH
];
761 static DWORD loading_thread
;
765 /* load_gecko may be called recursively */
766 if(loading_thread
== GetCurrentThreadId())
767 return pCompMgr
!= NULL
;
769 EnterCriticalSection(&cs_load_gecko
);
771 if(!loading_thread
) {
772 loading_thread
= GetCurrentThreadId();
774 if(load_wine_gecko(gre_path
)
775 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
776 ret
= init_xpcom(gre_path
);
778 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
780 ret
= pCompMgr
!= NULL
;
783 LeaveCriticalSection(&cs_load_gecko
);
788 void *nsalloc(size_t size
)
790 return NS_Alloc(size
);
793 void nsfree(void *mem
)
798 BOOL
nsACString_Init(nsACString
*str
, const char *data
)
800 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
804 * Initializes nsACString with data owned by caller.
805 * Caller must ensure that data is valid during lifetime of string object.
807 void nsACString_InitDepend(nsACString
*str
, const char *data
)
809 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
812 void nsACString_SetData(nsACString
*str
, const char *data
)
814 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
817 UINT32
nsACString_GetData(const nsACString
*str
, const char **data
)
819 return NS_CStringGetData(str
, data
, NULL
);
822 void nsACString_Finish(nsACString
*str
)
824 NS_CStringContainerFinish(str
);
827 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
829 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
833 * Initializes nsAString with data owned by caller.
834 * Caller must ensure that data is valid during lifetime of string object.
836 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
838 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
841 UINT32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
843 return NS_StringGetData(str
, data
, NULL
);
846 void nsAString_Finish(nsAString
*str
)
848 NS_StringContainerFinish(str
);
851 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
853 const PRUnichar
*str
;
855 if(NS_FAILED(nsres
)) {
856 ERR("failed: %08x\n", nsres
);
857 nsAString_Finish(nsstr
);
861 nsAString_GetData(nsstr
, &str
);
862 TRACE("ret %s\n", debugstr_w(str
));
864 *p
= SysAllocString(str
);
866 return E_OUTOFMEMORY
;
871 nsAString_Finish(nsstr
);
875 HRESULT
return_nsstr_variant(nsresult nsres
, nsAString
*nsstr
, VARIANT
*p
)
877 const PRUnichar
*str
;
879 if(NS_FAILED(nsres
)) {
880 ERR("failed: %08x\n", nsres
);
881 nsAString_Finish(nsstr
);
885 if(NS_StringGetIsVoid(nsstr
)) {
889 nsAString_GetData(nsstr
, &str
);
890 TRACE("ret %s\n", debugstr_w(str
));
892 V_BSTR(p
) = SysAllocString(str
);
894 nsAString_Finish(nsstr
);
895 return E_OUTOFMEMORY
;
903 nsAString_Finish(nsstr
);
907 nsICommandParams
*create_nscommand_params(void)
909 nsICommandParams
*ret
= NULL
;
915 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
916 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
919 ERR("Could not get nsICommandParams\n");
924 nsIWritableVariant
*create_nsvariant(void)
926 nsIWritableVariant
*ret
= NULL
;
932 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
933 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
935 ERR("Could not get nsIVariant\n");
940 char *get_nscategory_entry(const char *category
, const char *entry
)
945 nsres
= nsICategoryManager_GetCategoryEntry(cat_mgr
, category
, entry
, &ret
);
946 return NS_SUCCEEDED(nsres
) ? ret
: NULL
;
949 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
951 nsIInterfaceRequestor
*iface_req
;
954 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
958 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
959 nsIInterfaceRequestor_Release(iface_req
);
964 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
966 nsIDOMNodeList
*node_list
= NULL
;
967 cpp_bool has_children
= FALSE
;
968 nsIContent
*nscontent
;
972 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
974 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
975 if(NS_FAILED(nsres
)) {
976 ERR("GetType failed: %08x\n", nsres
);
980 if(type
!= DOCUMENT_NODE
) {
981 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
982 if(NS_FAILED(nsres
)) {
983 ERR("Could not get nsIContent interface: %08x\n", nsres
);
990 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
993 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
996 nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
998 case DOCUMENT_NODE
: {
1000 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
1001 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
1002 nsIDocument_Release(nsdoc
);
1005 case DOCUMENT_TYPE_NODE
:
1006 nsIContentSerializer_AppendDoctype(serializer
, nscontent
, str
);
1008 case DOCUMENT_FRAGMENT_NODE
:
1011 FIXME("Unhandled type %u\n", type
);
1015 UINT32 child_cnt
, i
;
1016 nsIDOMNode
*child_node
;
1018 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
1019 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
1021 for(i
=0; i
<child_cnt
; i
++) {
1022 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
1023 if(NS_SUCCEEDED(nsres
)) {
1024 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
1025 nsIDOMNode_Release(child_node
);
1027 ERR("Item failed: %08x\n", nsres
);
1031 nsIDOMNodeList_Release(node_list
);
1034 if(type
== ELEMENT_NODE
)
1035 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
1037 if(type
!= DOCUMENT_NODE
)
1038 nsIContent_Release(nscontent
);
1042 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
1044 nsIContentSerializer
*serializer
;
1048 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1049 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
1050 (void**)&serializer
);
1051 if(NS_FAILED(nsres
)) {
1052 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1056 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1057 if(NS_FAILED(nsres
))
1058 ERR("Init failed: %08x\n", nsres
);
1060 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1061 if(SUCCEEDED(hres
)) {
1062 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1063 if(NS_FAILED(nsres
))
1064 ERR("Flush failed: %08x\n", nsres
);
1067 nsIContentSerializer_Release(serializer
);
1071 void get_editor_controller(NSContainer
*This
)
1073 nsIEditingSession
*editing_session
= NULL
;
1074 nsIControllerContext
*ctrlctx
;
1078 nsIEditor_Release(This
->editor
);
1079 This
->editor
= NULL
;
1082 if(This
->editor_controller
) {
1083 nsIController_Release(This
->editor_controller
);
1084 This
->editor_controller
= NULL
;
1087 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1088 (void**)&editing_session
);
1089 if(NS_FAILED(nsres
)) {
1090 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1094 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1095 This
->doc
->basedoc
.window
->window_proxy
, &This
->editor
);
1096 nsIEditingSession_Release(editing_session
);
1097 if(NS_FAILED(nsres
)) {
1098 ERR("Could not get editor: %08x\n", nsres
);
1102 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1103 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1104 if(NS_SUCCEEDED(nsres
)) {
1105 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1106 if(NS_FAILED(nsres
))
1107 ERR("SetCommandContext failed: %08x\n", nsres
);
1108 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1109 (void**)&This
->editor_controller
);
1110 nsIControllerContext_Release(ctrlctx
);
1111 if(NS_FAILED(nsres
))
1112 ERR("Could not get nsIController interface: %08x\n", nsres
);
1114 ERR("Could not create edit controller: %08x\n", nsres
);
1118 void close_gecko(void)
1123 init_mutation(NULL
);
1125 if(profile_directory
) {
1126 nsIFile_Release(profile_directory
);
1127 profile_directory
= NULL
;
1130 if(plugin_directory
) {
1131 nsIFile_Release(plugin_directory
);
1132 plugin_directory
= NULL
;
1136 nsIComponentManager_Release(pCompMgr
);
1139 nsIServiceManager_Release(pServMgr
);
1142 nsICategoryManager_Release(cat_mgr
);
1144 /* Gecko doesn't really support being unloaded */
1145 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1147 DeleteCriticalSection(&cs_load_gecko
);
1150 BOOL
is_gecko_path(const char *path
)
1155 buf
= heap_strdupUtoW(path
);
1156 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1159 for(ptr
= buf
; *ptr
; ptr
++) {
1164 UrlUnescapeW(buf
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1165 buf
[gecko_path_len
] = 0;
1167 ret
= !strcmpiW(buf
, gecko_path
);
1172 void set_viewer_zoom(NSContainer
*nscontainer
, float factor
)
1174 nsIContentViewer
*content_viewer
;
1175 nsIDocShell
*doc_shell
;
1178 TRACE("Setting to %f\n", factor
);
1180 nsres
= get_nsinterface((nsISupports
*)nscontainer
->navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
1181 assert(nsres
== NS_OK
);
1183 nsres
= nsIDocShell_GetContentViewer(doc_shell
, &content_viewer
);
1184 assert(nsres
== NS_OK
&& content_viewer
);
1185 nsIDocShell_Release(doc_shell
);
1187 nsres
= nsIContentViewer_SetFullZoom(content_viewer
, factor
);
1188 if(NS_FAILED(nsres
))
1189 ERR("SetFullZoom failed: %08x\n", nsres
);
1191 nsIContentViewer_Release(content_viewer
);
1194 struct nsWeakReference
{
1195 nsIWeakReference nsIWeakReference_iface
;
1199 NSContainer
*nscontainer
;
1202 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1204 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1207 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1208 nsIIDRef riid
, void **result
)
1210 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1212 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1213 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1214 *result
= &This
->nsIWeakReference_iface
;
1215 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1216 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1217 *result
= &This
->nsIWeakReference_iface
;
1219 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1221 return NS_NOINTERFACE
;
1224 nsISupports_AddRef((nsISupports
*)*result
);
1228 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1230 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1231 LONG ref
= InterlockedIncrement(&This
->ref
);
1233 TRACE("(%p) ref=%d\n", This
, ref
);
1238 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1240 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1241 LONG ref
= InterlockedDecrement(&This
->ref
);
1243 TRACE("(%p) ref=%d\n", This
, ref
);
1246 assert(!This
->nscontainer
);
1253 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1254 const nsIID
*riid
, void **result
)
1256 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1258 if(!This
->nscontainer
)
1259 return NS_ERROR_NULL_POINTER
;
1261 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1264 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1265 nsWeakReference_QueryInterface
,
1266 nsWeakReference_AddRef
,
1267 nsWeakReference_Release
,
1268 nsWeakReference_QueryReferent
1271 /**********************************************************
1272 * nsIWebBrowserChrome interface
1275 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1277 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1280 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1281 nsIIDRef riid
, void **result
)
1283 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1286 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1287 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1288 *result
= &This
->nsIWebBrowserChrome_iface
;
1289 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1290 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1291 *result
= &This
->nsIWebBrowserChrome_iface
;
1292 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1293 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1294 *result
= &This
->nsIContextMenuListener_iface
;
1295 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1296 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1297 *result
= &This
->nsIURIContentListener_iface
;
1298 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1299 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1300 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1301 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1302 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1303 *result
= &This
->nsITooltipListener_iface
;
1304 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1305 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1306 *result
= &This
->nsIInterfaceRequestor_iface
;
1307 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1308 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1309 *result
= &This
->nsISupportsWeakReference_iface
;
1313 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1317 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1318 return NS_NOINTERFACE
;
1321 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1323 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1324 LONG ref
= InterlockedIncrement(&This
->ref
);
1326 TRACE("(%p) ref=%d\n", This
, ref
);
1331 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1333 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1334 LONG ref
= InterlockedDecrement(&This
->ref
);
1336 TRACE("(%p) ref=%d\n", This
, ref
);
1340 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1341 if(This
->weak_reference
) {
1342 This
->weak_reference
->nscontainer
= NULL
;
1343 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1351 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1352 UINT32 statusType
, const PRUnichar
*status
)
1354 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1355 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1359 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1360 nsIWebBrowser
**aWebBrowser
)
1362 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1364 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1367 return NS_ERROR_INVALID_ARG
;
1369 if(This
->webbrowser
)
1370 nsIWebBrowser_AddRef(This
->webbrowser
);
1371 *aWebBrowser
= This
->webbrowser
;
1375 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1376 nsIWebBrowser
*aWebBrowser
)
1378 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1380 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1382 if(aWebBrowser
!= This
->webbrowser
)
1383 ERR("Wrong nsWebBrowser!\n");
1388 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1389 UINT32
*aChromeFlags
)
1391 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1392 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1393 return NS_ERROR_NOT_IMPLEMENTED
;
1396 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1397 UINT32 aChromeFlags
)
1399 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1400 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1401 return NS_ERROR_NOT_IMPLEMENTED
;
1404 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1406 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1407 TRACE("(%p)\n", This
);
1408 return NS_ERROR_NOT_IMPLEMENTED
;
1411 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1414 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1415 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1416 return NS_ERROR_NOT_IMPLEMENTED
;
1419 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1421 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1422 WARN("(%p)\n", This
);
1423 return NS_ERROR_NOT_IMPLEMENTED
;
1426 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1428 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1429 WARN("(%p)->(%p)\n", This
, _retval
);
1430 return NS_ERROR_NOT_IMPLEMENTED
;
1433 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1436 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1437 WARN("(%p)->(%08x)\n", This
, aStatus
);
1438 return NS_ERROR_NOT_IMPLEMENTED
;
1441 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1442 nsWebBrowserChrome_QueryInterface
,
1443 nsWebBrowserChrome_AddRef
,
1444 nsWebBrowserChrome_Release
,
1445 nsWebBrowserChrome_SetStatus
,
1446 nsWebBrowserChrome_GetWebBrowser
,
1447 nsWebBrowserChrome_SetWebBrowser
,
1448 nsWebBrowserChrome_GetChromeFlags
,
1449 nsWebBrowserChrome_SetChromeFlags
,
1450 nsWebBrowserChrome_DestroyBrowserWindow
,
1451 nsWebBrowserChrome_SizeBrowserTo
,
1452 nsWebBrowserChrome_ShowAsModal
,
1453 nsWebBrowserChrome_IsWindowModal
,
1454 nsWebBrowserChrome_ExitModalEventLoop
1457 /**********************************************************
1458 * nsIContextMenuListener interface
1461 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1463 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1466 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1467 nsIIDRef riid
, void **result
)
1469 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1470 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1473 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1475 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1476 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1479 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1481 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1482 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1485 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1486 UINT32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1488 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1489 nsIDOMMouseEvent
*event
;
1492 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1496 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1498 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1500 return NS_ERROR_FAILURE
;
1502 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, &node
->event_target
, aEvent
);
1504 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1505 assert(NS_SUCCEEDED(nsres
));
1507 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1508 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1509 nsIDOMMouseEvent_Release(event
);
1511 switch(aContextFlags
) {
1513 case CONTEXT_DOCUMENT
:
1514 case CONTEXT_TEXT
: {
1515 nsISelection
*selection
;
1517 nsres
= nsIDOMHTMLDocument_GetSelection(This
->doc
->basedoc
.doc_node
->nsdoc
, &selection
);
1518 if(NS_SUCCEEDED(nsres
) && selection
) {
1519 cpp_bool is_collapsed
;
1521 /* FIXME: Check if the click was inside selection. */
1522 nsres
= nsISelection_GetIsCollapsed(selection
, &is_collapsed
);
1523 nsISelection_Release(selection
);
1524 if(NS_SUCCEEDED(nsres
) && !is_collapsed
)
1525 dwID
= CONTEXT_MENU_TEXTSELECT
;
1530 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1531 dwID
= CONTEXT_MENU_IMAGE
;
1534 dwID
= CONTEXT_MENU_ANCHOR
;
1537 dwID
= CONTEXT_MENU_CONTROL
;
1540 FIXME("aContextFlags=%08x\n", aContextFlags
);
1543 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1548 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1549 nsContextMenuListener_QueryInterface
,
1550 nsContextMenuListener_AddRef
,
1551 nsContextMenuListener_Release
,
1552 nsContextMenuListener_OnShowContextMenu
1555 /**********************************************************
1556 * nsIURIContentListener interface
1559 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1561 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1564 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1565 nsIIDRef riid
, void **result
)
1567 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1568 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1571 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1573 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1574 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1577 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1579 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1580 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1583 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1584 nsIURI
*aURI
, cpp_bool
*_retval
)
1586 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1587 nsACString spec_str
;
1591 nsACString_Init(&spec_str
, NULL
);
1592 nsIURI_GetSpec(aURI
, &spec_str
);
1593 nsACString_GetData(&spec_str
, &spec
);
1595 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1597 nsACString_Finish(&spec_str
);
1599 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1600 if(NS_FAILED(nsres
))
1603 return !*_retval
&& This
->content_listener
1604 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1608 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1609 const nsACString
*aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1610 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1612 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1614 TRACE("(%p)->(%p %x %p %p %p)\n", This
, aContentType
, aIsContentPreferred
,
1615 aRequest
, aContentHandler
, _retval
);
1617 return This
->content_listener
1618 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1619 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1620 : NS_ERROR_NOT_IMPLEMENTED
;
1623 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1624 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1626 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1628 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1630 /* FIXME: Should we do something here? */
1633 return This
->content_listener
1634 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1635 aDesiredContentType
, _retval
)
1639 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1640 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1643 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1645 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1646 aDesiredContentType
, _retval
);
1648 return This
->content_listener
1649 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1650 aIsContentPreferred
, aDesiredContentType
, _retval
)
1651 : NS_ERROR_NOT_IMPLEMENTED
;
1654 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1655 nsISupports
**aLoadCookie
)
1657 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1659 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1661 return This
->content_listener
1662 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1663 : NS_ERROR_NOT_IMPLEMENTED
;
1666 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1667 nsISupports
*aLoadCookie
)
1669 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1671 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1673 return This
->content_listener
1674 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1675 : NS_ERROR_NOT_IMPLEMENTED
;
1678 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1679 nsIURIContentListener
**aParentContentListener
)
1681 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1683 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1685 if(This
->content_listener
)
1686 nsIURIContentListener_AddRef(This
->content_listener
);
1688 *aParentContentListener
= This
->content_listener
;
1692 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1693 nsIURIContentListener
*aParentContentListener
)
1695 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1697 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1699 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1702 if(This
->content_listener
)
1703 nsIURIContentListener_Release(This
->content_listener
);
1705 This
->content_listener
= aParentContentListener
;
1706 if(This
->content_listener
)
1707 nsIURIContentListener_AddRef(This
->content_listener
);
1712 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1713 nsURIContentListener_QueryInterface
,
1714 nsURIContentListener_AddRef
,
1715 nsURIContentListener_Release
,
1716 nsURIContentListener_OnStartURIOpen
,
1717 nsURIContentListener_DoContent
,
1718 nsURIContentListener_IsPreferred
,
1719 nsURIContentListener_CanHandleContent
,
1720 nsURIContentListener_GetLoadCookie
,
1721 nsURIContentListener_SetLoadCookie
,
1722 nsURIContentListener_GetParentContentListener
,
1723 nsURIContentListener_SetParentContentListener
1726 /**********************************************************
1727 * nsIEmbeddinSiteWindow interface
1730 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1732 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1735 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1736 nsIIDRef riid
, void **result
)
1738 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1739 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1742 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1744 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1745 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1748 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1750 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1751 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1754 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1755 UINT32 flags
, LONG x
, LONG y
, LONG cx
, LONG cy
)
1757 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1758 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1759 return NS_ERROR_NOT_IMPLEMENTED
;
1762 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1763 UINT32 flags
, LONG
*x
, LONG
*y
, LONG
*cx
, LONG
*cy
)
1765 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1768 TRACE("(%p)->(%x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1770 if(!GetWindowRect(This
->hwnd
, &r
)) {
1771 ERR("GetWindowRect failed\n");
1772 return NS_ERROR_FAILURE
;
1780 *cx
= r
.right
-r
.left
;
1782 *cy
= r
.bottom
-r
.top
;
1786 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1788 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1790 TRACE("(%p)\n", This
);
1792 return nsIBaseWindow_SetFocus(This
->window
);
1795 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1796 cpp_bool
*aVisibility
)
1798 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1800 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1802 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1806 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1807 cpp_bool aVisibility
)
1809 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1811 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1816 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1819 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1820 WARN("(%p)->(%p)\n", This
, aTitle
);
1821 return NS_ERROR_NOT_IMPLEMENTED
;
1824 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1825 const PRUnichar
*aTitle
)
1827 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1828 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1829 return NS_ERROR_NOT_IMPLEMENTED
;
1832 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1835 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1837 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1839 *aSiteWindow
= This
->hwnd
;
1843 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1844 nsEmbeddingSiteWindow_QueryInterface
,
1845 nsEmbeddingSiteWindow_AddRef
,
1846 nsEmbeddingSiteWindow_Release
,
1847 nsEmbeddingSiteWindow_SetDimensions
,
1848 nsEmbeddingSiteWindow_GetDimensions
,
1849 nsEmbeddingSiteWindow_SetFocus
,
1850 nsEmbeddingSiteWindow_GetVisibility
,
1851 nsEmbeddingSiteWindow_SetVisibility
,
1852 nsEmbeddingSiteWindow_GetTitle
,
1853 nsEmbeddingSiteWindow_SetTitle
,
1854 nsEmbeddingSiteWindow_GetSiteWindow
1857 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1859 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1862 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1865 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1866 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1869 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1871 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1872 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1875 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1877 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1878 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1881 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1882 LONG aXCoord
, LONG aYCoord
, const PRUnichar
*aTipText
)
1884 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1887 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1892 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1894 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1897 hide_tooltip(This
->doc
);
1902 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1903 nsTooltipListener_QueryInterface
,
1904 nsTooltipListener_AddRef
,
1905 nsTooltipListener_Release
,
1906 nsTooltipListener_OnShowTooltip
,
1907 nsTooltipListener_OnHideTooltip
1910 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1912 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1915 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1916 nsIIDRef riid
, void **result
)
1918 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1919 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1922 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1924 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1925 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1928 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1930 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1931 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1934 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1935 nsIIDRef riid
, void **result
)
1937 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1939 if(IsEqualGUID(&IID_mozIDOMWindowProxy
, riid
)) {
1940 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1941 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (mozIDOMWindowProxy
**)result
);
1944 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1947 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1948 nsInterfaceRequestor_QueryInterface
,
1949 nsInterfaceRequestor_AddRef
,
1950 nsInterfaceRequestor_Release
,
1951 nsInterfaceRequestor_GetInterface
1954 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1956 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1959 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1960 nsIIDRef riid
, void **result
)
1962 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1963 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1966 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1968 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1969 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1972 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1974 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1975 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1978 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1979 nsIWeakReference
**_retval
)
1981 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1983 TRACE("(%p)->(%p)\n", This
, _retval
);
1985 if(!This
->weak_reference
) {
1986 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1987 if(!This
->weak_reference
)
1988 return NS_ERROR_OUT_OF_MEMORY
;
1990 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1991 This
->weak_reference
->ref
= 1;
1992 This
->weak_reference
->nscontainer
= This
;
1995 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1996 nsIWeakReference_AddRef(*_retval
);
2000 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
2001 nsSupportsWeakReference_QueryInterface
,
2002 nsSupportsWeakReference_AddRef
,
2003 nsSupportsWeakReference_Release
,
2004 nsSupportsWeakReference_GetWeakReference
2007 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
2009 nsIWebBrowserSetup
*wbsetup
;
2010 nsIScrollable
*scrollable
;
2013 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
2014 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
2015 if(NS_FAILED(nsres
)) {
2016 ERR("Creating WebBrowser failed: %08x\n", nsres
);
2020 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
2021 if(NS_FAILED(nsres
)) {
2022 ERR("SetContainerWindow failed: %08x\n", nsres
);
2026 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
2027 (void**)&nscontainer
->window
);
2028 if(NS_FAILED(nsres
)) {
2029 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
2033 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
2035 if(NS_SUCCEEDED(nsres
)) {
2036 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
2037 nsIWebBrowserSetup_Release(wbsetup
);
2038 if(NS_FAILED(nsres
)) {
2039 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
2043 ERR("Could not get nsIWebBrowserSetup interface\n");
2047 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
2048 (void**)&nscontainer
->navigation
);
2049 if(NS_FAILED(nsres
)) {
2050 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
2054 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
2055 (void**)&nscontainer
->focus
);
2056 if(NS_FAILED(nsres
)) {
2057 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
2061 if(!nscontainer_class
) {
2062 register_nscontainer_class();
2063 if(!nscontainer_class
)
2067 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
2068 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
2069 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
2070 if(!nscontainer
->hwnd
) {
2071 WARN("Could not create window\n");
2075 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
2076 if(NS_SUCCEEDED(nsres
)) {
2077 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
2078 if(NS_FAILED(nsres
)) {
2079 WARN("Creating window failed: %08x\n", nsres
);
2083 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
2084 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
2086 ERR("InitWindow failed: %08x\n", nsres
);
2090 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
2091 &nscontainer
->nsIURIContentListener_iface
);
2092 if(NS_FAILED(nsres
))
2093 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
2095 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
2096 if(NS_SUCCEEDED(nsres
)) {
2097 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2098 ScrollOrientation_Y
, Scrollbar_Always
);
2099 if(NS_FAILED(nsres
))
2100 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2102 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2103 ScrollOrientation_X
, Scrollbar_Auto
);
2104 if(NS_FAILED(nsres
))
2105 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2107 nsIScrollable_Release(scrollable
);
2109 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2115 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2121 return CLASS_E_CLASSNOTAVAILABLE
;
2123 ret
= heap_alloc_zero(sizeof(NSContainer
));
2125 return E_OUTOFMEMORY
;
2127 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2128 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2129 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2130 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2131 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2132 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2133 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2138 hres
= init_nscontainer(ret
);
2142 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2146 void NSContainer_Release(NSContainer
*This
)
2148 TRACE("(%p)\n", This
);
2152 ShowWindow(This
->hwnd
, SW_HIDE
);
2153 SetParent(This
->hwnd
, NULL
);
2155 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2156 nsIBaseWindow_Destroy(This
->window
);
2158 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2160 nsIWebBrowser_Release(This
->webbrowser
);
2161 This
->webbrowser
= NULL
;
2163 nsIWebNavigation_Release(This
->navigation
);
2164 This
->navigation
= NULL
;
2166 nsIBaseWindow_Release(This
->window
);
2167 This
->window
= NULL
;
2169 nsIWebBrowserFocus_Release(This
->focus
);
2172 if(This
->editor_controller
) {
2173 nsIController_Release(This
->editor_controller
);
2174 This
->editor_controller
= NULL
;
2178 nsIEditor_Release(This
->editor
);
2179 This
->editor
= NULL
;
2182 if(This
->content_listener
) {
2183 nsIURIContentListener_Release(This
->content_listener
);
2184 This
->content_listener
= NULL
;
2188 DestroyWindow(This
->hwnd
);
2192 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
2196 * FIXME: nsIScriptObjectPrincipal uses thiscall calling convention, so we need this hack on i386.
2197 * This will be removed after the next Gecko update, that will change calling convention on Gecko side.
2200 extern void *call_thiscall_func
;
2201 __ASM_GLOBAL_FUNC(call_thiscall_func
,
2207 #define nsIScriptObjectPrincipal_GetPrincipal(this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)((this)->lpVtbl->GetPrincipal,this)
2210 nsIXMLHttpRequest
*create_nsxhr(nsIDOMWindow
*nswindow
)
2212 nsIScriptObjectPrincipal
*sop
;
2213 mozIDOMWindow
*inner_window
;
2214 nsIPrincipal
*nspri
;
2215 nsIGlobalObject
*nsglo
;
2216 nsIXMLHttpRequest
*nsxhr
;
2219 nsres
= nsIDOMWindow_GetInnerWindow(nswindow
, &inner_window
);
2220 if(NS_FAILED(nsres
)) {
2221 ERR("Could not get inner window: %08x\n", nsres
);
2225 nsres
= mozIDOMWindow_QueryInterface(inner_window
, &IID_nsIGlobalObject
, (void **)&nsglo
);
2226 mozIDOMWindow_Release(inner_window
);
2227 assert(nsres
== NS_OK
);
2229 nsres
= nsIGlobalObject_QueryInterface(nsglo
, &IID_nsIScriptObjectPrincipal
, (void**)&sop
);
2230 assert(nsres
== NS_OK
);
2232 nspri
= nsIScriptObjectPrincipal_GetPrincipal(sop
);
2233 nsIScriptObjectPrincipal_Release(sop
);
2235 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
2236 NS_XMLHTTPREQUEST_CONTRACTID
, NULL
, &IID_nsIXMLHttpRequest
,
2238 if(NS_SUCCEEDED(nsres
)) {
2239 nsres
= nsIXMLHttpRequest_Init(nsxhr
, nspri
, NULL
, nsglo
, NULL
, NULL
);
2240 if(NS_FAILED(nsres
))
2241 nsIXMLHttpRequest_Release(nsxhr
);
2243 nsISupports_Release(nspri
);
2244 nsIGlobalObject_Release(nsglo
);
2245 if(NS_FAILED(nsres
)) {
2246 ERR("nsIXMLHttpRequest_Init failed: %08x\n", nsres
);