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 void* (CDECL
*NS_Alloc
)(SIZE_T
);
73 static void (CDECL
*NS_Free
)(void*);
75 static HINSTANCE xul_handle
= NULL
;
77 static nsIServiceManager
*pServMgr
= NULL
;
78 static nsIComponentManager
*pCompMgr
= NULL
;
79 static nsICategoryManager
*cat_mgr
;
80 static nsIFile
*profile_directory
, *plugin_directory
;
82 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
84 static ATOM nscontainer_class
;
85 static WCHAR gecko_path
[MAX_PATH
];
86 static unsigned gecko_path_len
;
88 nsresult
create_nsfile(const PRUnichar
*path
, nsIFile
**ret
)
93 nsAString_InitDepend(&str
, path
);
94 nsres
= NS_NewLocalFile(&str
, FALSE
, ret
);
95 nsAString_Finish(&str
);
98 WARN("NS_NewLocalFile failed: %08x\n", nsres
);
103 nsISimpleEnumerator nsISimpleEnumerator_iface
;
106 } nsSingletonEnumerator
;
108 static inline nsSingletonEnumerator
*impl_from_nsISimpleEnumerator(nsISimpleEnumerator
*iface
)
110 return CONTAINING_RECORD(iface
, nsSingletonEnumerator
, nsISimpleEnumerator_iface
);
113 static nsresult NSAPI
nsSingletonEnumerator_QueryInterface(nsISimpleEnumerator
*iface
, nsIIDRef riid
, void **ppv
)
115 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
117 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
118 TRACE("(%p)->(IID_nsISupports %p)\n", This
, ppv
);
119 *ppv
= &This
->nsISimpleEnumerator_iface
;
120 }else if(IsEqualGUID(&IID_nsISimpleEnumerator
, riid
)) {
121 TRACE("(%p)->(IID_nsISimpleEnumerator %p)\n", This
, ppv
);
122 *ppv
= &This
->nsISimpleEnumerator_iface
;
124 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
126 return NS_NOINTERFACE
;
129 nsISupports_AddRef((nsISupports
*)*ppv
);
133 static nsrefcnt NSAPI
nsSingletonEnumerator_AddRef(nsISimpleEnumerator
*iface
)
135 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
136 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
138 TRACE("(%p) ref=%d\n", This
, ref
);
143 static nsrefcnt NSAPI
nsSingletonEnumerator_Release(nsISimpleEnumerator
*iface
)
145 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
146 nsrefcnt ref
= InterlockedDecrement(&This
->ref
);
148 TRACE("(%p) ref=%d\n", This
, ref
);
152 nsISupports_Release(This
->value
);
159 static nsresult NSAPI
nsSingletonEnumerator_HasMoreElements(nsISimpleEnumerator
*iface
, cpp_bool
*_retval
)
161 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
163 TRACE("(%p)->()\n", This
);
165 *_retval
= This
->value
!= NULL
;
169 static nsresult NSAPI
nsSingletonEnumerator_GetNext(nsISimpleEnumerator
*iface
, nsISupports
**_retval
)
171 nsSingletonEnumerator
*This
= impl_from_nsISimpleEnumerator(iface
);
173 TRACE("(%p)->()\n", This
);
176 return NS_ERROR_UNEXPECTED
;
178 *_retval
= This
->value
;
183 static const nsISimpleEnumeratorVtbl nsSingletonEnumeratorVtbl
= {
184 nsSingletonEnumerator_QueryInterface
,
185 nsSingletonEnumerator_AddRef
,
186 nsSingletonEnumerator_Release
,
187 nsSingletonEnumerator_HasMoreElements
,
188 nsSingletonEnumerator_GetNext
191 static nsISimpleEnumerator
*create_singleton_enumerator(nsISupports
*value
)
193 nsSingletonEnumerator
*ret
;
195 ret
= heap_alloc(sizeof(*ret
));
199 ret
->nsISimpleEnumerator_iface
.lpVtbl
= &nsSingletonEnumeratorVtbl
;
203 nsISupports_AddRef(value
);
205 return &ret
->nsISimpleEnumerator_iface
;
208 static nsresult NSAPI
nsDirectoryServiceProvider2_QueryInterface(nsIDirectoryServiceProvider2
*iface
,
209 nsIIDRef riid
, void **result
)
211 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
212 TRACE("(IID_nsISupports %p)\n", result
);
214 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider
, riid
)) {
215 TRACE("(IID_nsIDirectoryServiceProvider %p)\n", result
);
217 }else if(IsEqualGUID(&IID_nsIDirectoryServiceProvider2
, riid
)) {
218 TRACE("(IID_nsIDirectoryServiceProvider2 %p)\n", result
);
221 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
223 return NS_NOINTERFACE
;
226 nsISupports_AddRef((nsISupports
*)*result
);
230 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_AddRef(nsIDirectoryServiceProvider2
*iface
)
235 static nsrefcnt NSAPI
nsDirectoryServiceProvider2_Release(nsIDirectoryServiceProvider2
*iface
)
240 static nsresult
create_profile_directory(void)
242 static const WCHAR wine_geckoW
[] = {'\\','w','i','n','e','_','g','e','c','k','o',0};
244 WCHAR path
[MAX_PATH
+ sizeof(wine_geckoW
)/sizeof(WCHAR
)];
249 hres
= SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
251 ERR("SHGetFolderPath failed: %08x\n", hres
);
252 return NS_ERROR_FAILURE
;
255 strcatW(path
, wine_geckoW
);
256 nsres
= create_nsfile(path
, &profile_directory
);
260 nsres
= nsIFile_Exists(profile_directory
, &exists
);
261 if(NS_FAILED(nsres
)) {
262 ERR("Exists failed: %08x\n", nsres
);
267 nsres
= nsIFile_Create(profile_directory
, 1, 0700);
269 ERR("Create failed: %08x\n", nsres
);
275 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFile(nsIDirectoryServiceProvider2
*iface
,
276 const char *prop
, cpp_bool
*persistent
, nsIFile
**_retval
)
278 TRACE("(%s %p %p)\n", debugstr_a(prop
), persistent
, _retval
);
280 if(!strcmp(prop
, "ProfD")) {
281 if(!profile_directory
) {
284 nsres
= create_profile_directory();
289 assert(profile_directory
!= NULL
);
290 return nsIFile_Clone(profile_directory
, _retval
);
294 return NS_ERROR_FAILURE
;
297 static nsresult NSAPI
nsDirectoryServiceProvider2_GetFiles(nsIDirectoryServiceProvider2
*iface
,
298 const char *prop
, nsISimpleEnumerator
**_retval
)
300 TRACE("(%s %p)\n", debugstr_a(prop
), _retval
);
302 if(!strcmp(prop
, "APluginsDL")) {
303 WCHAR plugin_path
[MAX_PATH
];
308 if(!plugin_directory
) {
309 static const WCHAR gecko_pluginW
[] = {'\\','g','e','c','k','o','\\','p','l','u','g','i','n',0};
311 len
= GetSystemDirectoryW(plugin_path
, (sizeof(plugin_path
)-sizeof(gecko_pluginW
))/sizeof(WCHAR
)+1);
313 return NS_ERROR_UNEXPECTED
;
315 strcpyW(plugin_path
+len
, gecko_pluginW
);
316 nsres
= create_nsfile(plugin_path
, &plugin_directory
);
317 if(NS_FAILED(nsres
)) {
323 nsres
= nsIFile_Clone(plugin_directory
, &file
);
327 *_retval
= create_singleton_enumerator((nsISupports
*)file
);
328 nsIFile_Release(file
);
330 return NS_ERROR_OUT_OF_MEMORY
;
336 return NS_ERROR_FAILURE
;
339 static const nsIDirectoryServiceProvider2Vtbl nsDirectoryServiceProvider2Vtbl
= {
340 nsDirectoryServiceProvider2_QueryInterface
,
341 nsDirectoryServiceProvider2_AddRef
,
342 nsDirectoryServiceProvider2_Release
,
343 nsDirectoryServiceProvider2_GetFile
,
344 nsDirectoryServiceProvider2_GetFiles
347 static nsIDirectoryServiceProvider2 nsDirectoryServiceProvider2
=
348 { &nsDirectoryServiceProvider2Vtbl
};
350 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
355 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
357 if(msg
== WM_CREATE
) {
358 This
= *(NSContainer
**)lParam
;
359 SetPropW(hwnd
, wszTHIS
, This
);
361 This
= GetPropW(hwnd
, wszTHIS
);
366 TRACE("(%p)->(WM_SIZE)\n", This
);
368 nsres
= nsIBaseWindow_SetSize(This
->window
,
369 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
371 WARN("SetSize failed: %08x\n", nsres
);
374 case WM_PARENTNOTIFY
:
375 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
380 nsIWebBrowserFocus_Activate(This
->focus
);
384 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
388 static void register_nscontainer_class(void)
390 static WNDCLASSEXW wndclass
= {
394 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
398 wndclass
.hInstance
= hInst
;
399 nscontainer_class
= RegisterClassExW(&wndclass
);
402 static BOOL
install_wine_gecko(void)
404 PROCESS_INFORMATION pi
;
411 static const WCHAR controlW
[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
412 static const WCHAR argsW
[] =
413 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','g','e','c','k','o',0};
415 len
= GetSystemDirectoryW(app
, MAX_PATH
-sizeof(controlW
)/sizeof(WCHAR
));
416 memcpy(app
+len
, controlW
, sizeof(controlW
));
418 args
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(controlW
) + sizeof(argsW
));
422 memcpy(args
, app
, len
*sizeof(WCHAR
) + sizeof(controlW
));
423 memcpy(args
+ len
+ sizeof(controlW
)/sizeof(WCHAR
)-1, argsW
, sizeof(argsW
));
425 TRACE("starting %s\n", debugstr_w(args
));
427 memset(&si
, 0, sizeof(si
));
429 ret
= CreateProcessW(app
, args
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
432 CloseHandle(pi
.hThread
);
433 WaitForSingleObject(pi
.hProcess
, INFINITE
);
434 CloseHandle(pi
.hProcess
);
440 static void set_environment(LPCWSTR gre_path
)
442 size_t len
, gre_path_len
;
444 WCHAR
*path
, buf
[20];
447 static const WCHAR pathW
[] = {'P','A','T','H',0};
448 static const WCHAR warnW
[] = {'w','a','r','n',0};
449 static const WCHAR xpcom_debug_breakW
[] =
450 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
451 static const WCHAR nspr_log_modulesW
[] =
452 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
453 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
455 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
459 else if(WARN_ON(gecko
))
461 else if(ERR_ON(gecko
))
464 sprintfW(buf
, debug_formatW
, debug_level
);
465 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
467 len
= GetEnvironmentVariableW(pathW
, NULL
, 0);
468 gre_path_len
= strlenW(gre_path
);
469 path
= heap_alloc((len
+gre_path_len
+1)*sizeof(WCHAR
));
472 GetEnvironmentVariableW(pathW
, path
, len
);
474 /* We have to modify PATH as xul.dll loads other DLLs from this directory. */
475 if(!(ptr
= strstrW(path
, gre_path
))
476 || (ptr
> path
&& *(ptr
-1) != ';')
477 || (ptr
[gre_path_len
] && ptr
[gre_path_len
] != ';')) {
480 strcpyW(path
+len
, gre_path
);
481 SetEnvironmentVariableW(pathW
, path
);
486 static BOOL
load_xul(const PRUnichar
*gre_path
)
488 static const WCHAR xul_dllW
[] = {'\\','x','u','l','.','d','l','l',0};
489 WCHAR file_name
[MAX_PATH
];
491 strcpyW(file_name
, gre_path
);
492 strcatW(file_name
, xul_dllW
);
494 TRACE("(%s)\n", debugstr_w(file_name
));
496 set_environment(gre_path
);
498 xul_handle
= LoadLibraryExW(file_name
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
500 WARN("Could not load XUL: %d\n", GetLastError());
504 #define NS_DLSYM(func) \
505 func = (void *)GetProcAddress(xul_handle, #func); \
507 ERR("Could not GetProcAddress(" #func ") failed\n")
509 NS_DLSYM(NS_InitXPCOM2
);
510 NS_DLSYM(NS_ShutdownXPCOM
);
511 NS_DLSYM(NS_GetComponentRegistrar
);
512 NS_DLSYM(NS_StringContainerInit2
);
513 NS_DLSYM(NS_CStringContainerInit2
);
514 NS_DLSYM(NS_StringContainerFinish
);
515 NS_DLSYM(NS_CStringContainerFinish
);
516 NS_DLSYM(NS_StringSetData
);
517 NS_DLSYM(NS_CStringSetData
);
518 NS_DLSYM(NS_NewLocalFile
);
519 NS_DLSYM(NS_StringGetData
);
520 NS_DLSYM(NS_CStringGetData
);
523 NS_DLSYM(ccref_incr
);
524 NS_DLSYM(ccref_decr
);
525 NS_DLSYM(ccref_init
);
527 NS_DLSYM(describe_cc_node
);
528 NS_DLSYM(note_cc_edge
);
535 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
537 WCHAR file_name
[MAX_PATH
];
542 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
544 strcpyW(file_name
, gre_path
);
545 strcatW(file_name
, wszVersion
);
547 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
548 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
549 if(hfile
== INVALID_HANDLE_VALUE
) {
550 ERR("Could not open VERSION file\n");
554 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
558 TRACE("%s\n", debugstr_a(version
));
560 if(strcmp(version
, version_string
)) {
561 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
562 debugstr_a(version_string
));
569 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
570 const char *version
, const char *version_string
)
572 DWORD res
, type
, size
= MAX_PATH
;
573 HKEY hkey
= mshtml_key
;
575 static const WCHAR wszGeckoPath
[] =
576 {'G','e','c','k','o','P','a','t','h',0};
579 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML\<version> */
580 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
581 if(res
!= ERROR_SUCCESS
)
585 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
586 if(hkey
!= mshtml_key
)
588 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
591 if(!check_version(gre_path
, version_string
))
594 return load_xul(gre_path
);
597 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
603 static const WCHAR wszMshtmlKey
[] = {
604 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
605 '\\','M','S','H','T','M','L',0};
607 /* @@ Wine registry key: HKLM\Software\Wine\MSHTML */
608 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszMshtmlKey
, &hkey
);
609 if(res
!= ERROR_SUCCESS
)
612 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
618 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
622 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
624 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
627 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
631 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
633 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
636 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
640 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
642 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
645 static void set_lang(nsIPrefBranch
*pref
)
648 DWORD res
, size
, type
;
651 static const WCHAR international_keyW
[] =
652 {'S','o','f','t','w','a','r','e',
653 '\\','M','i','c','r','o','s','o','f','t',
654 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
655 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
657 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
658 if(res
!= ERROR_SUCCESS
)
661 size
= sizeof(langs
);
662 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
664 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
667 TRACE("Setting lang %s\n", debugstr_a(langs
));
669 set_string_pref(pref
, "intl.accept_languages", langs
);
672 static void set_preferences(void)
677 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
678 &IID_nsIPrefBranch
, (void**)&pref
);
679 if(NS_FAILED(nsres
)) {
680 ERR("Could not get preference service: %08x\n", nsres
);
685 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
686 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
687 set_int_pref(pref
, "layout.spellcheckDefault", 0);
689 nsIPrefBranch_Release(pref
);
692 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
694 nsIComponentRegistrar
*registrar
= NULL
;
699 nsres
= create_nsfile(gre_path
, &gre_dir
);
700 if(NS_FAILED(nsres
)) {
701 FreeLibrary(xul_handle
);
705 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, (nsIDirectoryServiceProvider
*)&nsDirectoryServiceProvider2
);
706 if(NS_FAILED(nsres
)) {
707 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
708 FreeLibrary(xul_handle
);
712 strcpyW(gecko_path
, gre_path
);
713 for(ptr
= gecko_path
; *ptr
; ptr
++) {
717 gecko_path_len
= ptr
-gecko_path
;
719 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
721 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
724 init_mutation(pCompMgr
);
727 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_CATEGORYMANAGER_CONTRACTID
,
728 &IID_nsICategoryManager
, (void**)&cat_mgr
);
730 ERR("Could not get category manager service: %08x\n", nsres
);
732 nsres
= NS_GetComponentRegistrar(®istrar
);
733 if(NS_SUCCEEDED(nsres
)) {
734 register_nsservice(registrar
, pServMgr
);
735 nsIComponentRegistrar_Release(registrar
);
737 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
745 static CRITICAL_SECTION cs_load_gecko
;
746 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
748 0, 0, &cs_load_gecko
,
749 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
750 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
752 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
754 BOOL
load_gecko(void)
756 PRUnichar gre_path
[MAX_PATH
];
759 static DWORD loading_thread
;
763 /* load_gecko may be called recursively */
764 if(loading_thread
== GetCurrentThreadId())
765 return pCompMgr
!= NULL
;
767 EnterCriticalSection(&cs_load_gecko
);
769 if(!loading_thread
) {
770 loading_thread
= GetCurrentThreadId();
772 if(load_wine_gecko(gre_path
)
773 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
774 ret
= init_xpcom(gre_path
);
776 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
778 ret
= pCompMgr
!= NULL
;
781 LeaveCriticalSection(&cs_load_gecko
);
786 void *nsalloc(size_t size
)
788 return NS_Alloc(size
);
791 void nsfree(void *mem
)
796 BOOL
nsACString_Init(nsACString
*str
, const char *data
)
798 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
802 * Initializes nsACString with data owned by caller.
803 * Caller must ensure that data is valid during lifetime of string object.
805 void nsACString_InitDepend(nsACString
*str
, const char *data
)
807 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
810 void nsACString_SetData(nsACString
*str
, const char *data
)
812 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
815 UINT32
nsACString_GetData(const nsACString
*str
, const char **data
)
817 return NS_CStringGetData(str
, data
, NULL
);
820 void nsACString_Finish(nsACString
*str
)
822 NS_CStringContainerFinish(str
);
825 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
827 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
831 * Initializes nsAString with data owned by caller.
832 * Caller must ensure that data is valid during lifetime of string object.
834 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
836 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
839 UINT32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
841 return NS_StringGetData(str
, data
, NULL
);
844 void nsAString_Finish(nsAString
*str
)
846 NS_StringContainerFinish(str
);
849 HRESULT
return_nsstr(nsresult nsres
, nsAString
*nsstr
, BSTR
*p
)
851 const PRUnichar
*str
;
853 if(NS_FAILED(nsres
)) {
854 ERR("failed: %08x\n", nsres
);
855 nsAString_Finish(nsstr
);
859 nsAString_GetData(nsstr
, &str
);
860 TRACE("ret %s\n", debugstr_w(str
));
862 *p
= SysAllocString(str
);
864 return E_OUTOFMEMORY
;
869 nsAString_Finish(nsstr
);
873 nsICommandParams
*create_nscommand_params(void)
875 nsICommandParams
*ret
= NULL
;
881 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
882 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
885 ERR("Could not get nsICommandParams\n");
890 nsIWritableVariant
*create_nsvariant(void)
892 nsIWritableVariant
*ret
= NULL
;
898 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
899 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
, (void**)&ret
);
901 ERR("Could not get nsIVariant\n");
906 char *get_nscategory_entry(const char *category
, const char *entry
)
911 nsres
= nsICategoryManager_GetCategoryEntry(cat_mgr
, category
, entry
, &ret
);
912 return NS_SUCCEEDED(nsres
) ? ret
: NULL
;
915 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
917 nsIInterfaceRequestor
*iface_req
;
920 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
924 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
925 nsIInterfaceRequestor_Release(iface_req
);
930 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
932 nsIDOMNodeList
*node_list
= NULL
;
933 cpp_bool has_children
= FALSE
;
934 nsIContent
*nscontent
;
938 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
940 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
941 if(NS_FAILED(nsres
)) {
942 ERR("GetType failed: %08x\n", nsres
);
946 if(type
!= DOCUMENT_NODE
) {
947 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIContent
, (void**)&nscontent
);
948 if(NS_FAILED(nsres
)) {
949 ERR("Could not get nsIContent interface: %08x\n", nsres
);
956 nsIContentSerializer_AppendElementStart(serializer
, nscontent
, nscontent
, str
);
959 nsIContentSerializer_AppendText(serializer
, nscontent
, 0, -1, str
);
962 nsIContentSerializer_AppendComment(serializer
, nscontent
, 0, -1, str
);
964 case DOCUMENT_NODE
: {
966 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDocument
, (void**)&nsdoc
);
967 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
968 nsIDocument_Release(nsdoc
);
971 case DOCUMENT_TYPE_NODE
:
972 nsIContentSerializer_AppendDoctype(serializer
, nscontent
, str
);
974 case DOCUMENT_FRAGMENT_NODE
:
977 FIXME("Unhandled type %u\n", type
);
982 nsIDOMNode
*child_node
;
984 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
985 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
987 for(i
=0; i
<child_cnt
; i
++) {
988 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
989 if(NS_SUCCEEDED(nsres
)) {
990 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
991 nsIDOMNode_Release(child_node
);
993 ERR("Item failed: %08x\n", nsres
);
997 nsIDOMNodeList_Release(node_list
);
1000 if(type
== ELEMENT_NODE
)
1001 nsIContentSerializer_AppendElementEnd(serializer
, nscontent
, str
);
1003 if(type
!= DOCUMENT_NODE
)
1004 nsIContent_Release(nscontent
);
1008 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
1010 nsIContentSerializer
*serializer
;
1014 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1015 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
1016 (void**)&serializer
);
1017 if(NS_FAILED(nsres
)) {
1018 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
1022 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
1023 if(NS_FAILED(nsres
))
1024 ERR("Init failed: %08x\n", nsres
);
1026 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
1027 if(SUCCEEDED(hres
)) {
1028 nsres
= nsIContentSerializer_Flush(serializer
, str
);
1029 if(NS_FAILED(nsres
))
1030 ERR("Flush failed: %08x\n", nsres
);
1033 nsIContentSerializer_Release(serializer
);
1037 void get_editor_controller(NSContainer
*This
)
1039 nsIEditingSession
*editing_session
= NULL
;
1040 nsIControllerContext
*ctrlctx
;
1044 nsIEditor_Release(This
->editor
);
1045 This
->editor
= NULL
;
1048 if(This
->editor_controller
) {
1049 nsIController_Release(This
->editor_controller
);
1050 This
->editor_controller
= NULL
;
1053 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
1054 (void**)&editing_session
);
1055 if(NS_FAILED(nsres
)) {
1056 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
1060 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
1061 This
->doc
->basedoc
.window
->window_proxy
, &This
->editor
);
1062 nsIEditingSession_Release(editing_session
);
1063 if(NS_FAILED(nsres
)) {
1064 ERR("Could not get editor: %08x\n", nsres
);
1068 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
1069 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
1070 if(NS_SUCCEEDED(nsres
)) {
1071 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
1072 if(NS_FAILED(nsres
))
1073 ERR("SetCommandContext failed: %08x\n", nsres
);
1074 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
1075 (void**)&This
->editor_controller
);
1076 nsIControllerContext_Release(ctrlctx
);
1077 if(NS_FAILED(nsres
))
1078 ERR("Could not get nsIController interface: %08x\n", nsres
);
1080 ERR("Could not create edit controller: %08x\n", nsres
);
1084 void close_gecko(void)
1089 init_mutation(NULL
);
1091 if(profile_directory
) {
1092 nsIFile_Release(profile_directory
);
1093 profile_directory
= NULL
;
1096 if(plugin_directory
) {
1097 nsIFile_Release(plugin_directory
);
1098 plugin_directory
= NULL
;
1102 nsIComponentManager_Release(pCompMgr
);
1105 nsIServiceManager_Release(pServMgr
);
1108 nsICategoryManager_Release(cat_mgr
);
1110 /* Gecko doesn't really support being unloaded */
1111 /* if (hXPCOM) FreeLibrary(hXPCOM); */
1113 DeleteCriticalSection(&cs_load_gecko
);
1116 BOOL
is_gecko_path(const char *path
)
1121 buf
= heap_strdupUtoW(path
);
1122 if(!buf
|| strlenW(buf
) < gecko_path_len
)
1125 for(ptr
= buf
; *ptr
; ptr
++) {
1130 UrlUnescapeW(buf
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1131 buf
[gecko_path_len
] = 0;
1133 ret
= !strcmpiW(buf
, gecko_path
);
1138 void set_viewer_zoom(NSContainer
*nscontainer
, float factor
)
1140 nsIContentViewer
*content_viewer
;
1141 nsIDocShell
*doc_shell
;
1144 TRACE("Setting to %f\n", factor
);
1146 nsres
= get_nsinterface((nsISupports
*)nscontainer
->navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
1147 assert(nsres
== NS_OK
);
1149 nsres
= nsIDocShell_GetContentViewer(doc_shell
, &content_viewer
);
1150 assert(nsres
== NS_OK
&& content_viewer
);
1151 nsIDocShell_Release(doc_shell
);
1153 nsres
= nsIContentViewer_SetFullZoom(content_viewer
, factor
);
1154 if(NS_FAILED(nsres
))
1155 ERR("SetFullZoom failed: %08x\n", nsres
);
1157 nsIContentViewer_Release(content_viewer
);
1160 struct nsWeakReference
{
1161 nsIWeakReference nsIWeakReference_iface
;
1165 NSContainer
*nscontainer
;
1168 static inline nsWeakReference
*impl_from_nsIWeakReference(nsIWeakReference
*iface
)
1170 return CONTAINING_RECORD(iface
, nsWeakReference
, nsIWeakReference_iface
);
1173 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1174 nsIIDRef riid
, void **result
)
1176 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1178 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1179 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1180 *result
= &This
->nsIWeakReference_iface
;
1181 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
1182 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
1183 *result
= &This
->nsIWeakReference_iface
;
1185 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1187 return NS_NOINTERFACE
;
1190 nsISupports_AddRef((nsISupports
*)*result
);
1194 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1196 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1197 LONG ref
= InterlockedIncrement(&This
->ref
);
1199 TRACE("(%p) ref=%d\n", This
, ref
);
1204 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1206 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1207 LONG ref
= InterlockedIncrement(&This
->ref
);
1209 TRACE("(%p) ref=%d\n", This
, ref
);
1212 assert(!This
->nscontainer
);
1219 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1220 const nsIID
*riid
, void **result
)
1222 nsWeakReference
*This
= impl_from_nsIWeakReference(iface
);
1224 if(!This
->nscontainer
)
1225 return NS_ERROR_NULL_POINTER
;
1227 return nsIWebBrowserChrome_QueryInterface(&This
->nscontainer
->nsIWebBrowserChrome_iface
, riid
, result
);
1230 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1231 nsWeakReference_QueryInterface
,
1232 nsWeakReference_AddRef
,
1233 nsWeakReference_Release
,
1234 nsWeakReference_QueryReferent
1237 /**********************************************************
1238 * nsIWebBrowserChrome interface
1241 static inline NSContainer
*impl_from_nsIWebBrowserChrome(nsIWebBrowserChrome
*iface
)
1243 return CONTAINING_RECORD(iface
, NSContainer
, nsIWebBrowserChrome_iface
);
1246 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
1247 nsIIDRef riid
, void **result
)
1249 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1252 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1253 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
1254 *result
= &This
->nsIWebBrowserChrome_iface
;
1255 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
1256 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
1257 *result
= &This
->nsIWebBrowserChrome_iface
;
1258 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
1259 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
1260 *result
= &This
->nsIContextMenuListener_iface
;
1261 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
1262 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
1263 *result
= &This
->nsIURIContentListener_iface
;
1264 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
1265 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
1266 *result
= &This
->nsIEmbeddingSiteWindow_iface
;
1267 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
1268 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
1269 *result
= &This
->nsITooltipListener_iface
;
1270 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
1271 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
1272 *result
= &This
->nsIInterfaceRequestor_iface
;
1273 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
1274 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
1275 *result
= &This
->nsISupportsWeakReference_iface
;
1279 nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1283 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1284 return NS_NOINTERFACE
;
1287 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
1289 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1290 LONG ref
= InterlockedIncrement(&This
->ref
);
1292 TRACE("(%p) ref=%d\n", This
, ref
);
1297 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
1299 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1300 LONG ref
= InterlockedDecrement(&This
->ref
);
1302 TRACE("(%p) ref=%d\n", This
, ref
);
1306 nsIWebBrowserChrome_Release(&This
->parent
->nsIWebBrowserChrome_iface
);
1307 if(This
->weak_reference
) {
1308 This
->weak_reference
->nscontainer
= NULL
;
1309 nsIWeakReference_Release(&This
->weak_reference
->nsIWeakReference_iface
);
1317 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
1318 UINT32 statusType
, const PRUnichar
*status
)
1320 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1321 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1325 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1326 nsIWebBrowser
**aWebBrowser
)
1328 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1330 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1333 return NS_ERROR_INVALID_ARG
;
1335 if(This
->webbrowser
)
1336 nsIWebBrowser_AddRef(This
->webbrowser
);
1337 *aWebBrowser
= This
->webbrowser
;
1341 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1342 nsIWebBrowser
*aWebBrowser
)
1344 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1346 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1348 if(aWebBrowser
!= This
->webbrowser
)
1349 ERR("Wrong nsWebBrowser!\n");
1354 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1355 UINT32
*aChromeFlags
)
1357 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1358 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1359 return NS_ERROR_NOT_IMPLEMENTED
;
1362 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1363 UINT32 aChromeFlags
)
1365 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1366 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1367 return NS_ERROR_NOT_IMPLEMENTED
;
1370 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1372 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1373 TRACE("(%p)\n", This
);
1374 return NS_ERROR_NOT_IMPLEMENTED
;
1377 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1380 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1381 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1382 return NS_ERROR_NOT_IMPLEMENTED
;
1385 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1387 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1388 WARN("(%p)\n", This
);
1389 return NS_ERROR_NOT_IMPLEMENTED
;
1392 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, cpp_bool
*_retval
)
1394 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1395 WARN("(%p)->(%p)\n", This
, _retval
);
1396 return NS_ERROR_NOT_IMPLEMENTED
;
1399 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1402 NSContainer
*This
= impl_from_nsIWebBrowserChrome(iface
);
1403 WARN("(%p)->(%08x)\n", This
, aStatus
);
1404 return NS_ERROR_NOT_IMPLEMENTED
;
1407 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1408 nsWebBrowserChrome_QueryInterface
,
1409 nsWebBrowserChrome_AddRef
,
1410 nsWebBrowserChrome_Release
,
1411 nsWebBrowserChrome_SetStatus
,
1412 nsWebBrowserChrome_GetWebBrowser
,
1413 nsWebBrowserChrome_SetWebBrowser
,
1414 nsWebBrowserChrome_GetChromeFlags
,
1415 nsWebBrowserChrome_SetChromeFlags
,
1416 nsWebBrowserChrome_DestroyBrowserWindow
,
1417 nsWebBrowserChrome_SizeBrowserTo
,
1418 nsWebBrowserChrome_ShowAsModal
,
1419 nsWebBrowserChrome_IsWindowModal
,
1420 nsWebBrowserChrome_ExitModalEventLoop
1423 /**********************************************************
1424 * nsIContextMenuListener interface
1427 static inline NSContainer
*impl_from_nsIContextMenuListener(nsIContextMenuListener
*iface
)
1429 return CONTAINING_RECORD(iface
, NSContainer
, nsIContextMenuListener_iface
);
1432 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1433 nsIIDRef riid
, void **result
)
1435 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1436 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1439 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1441 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1442 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1445 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1447 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1448 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1451 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1452 UINT32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1454 NSContainer
*This
= impl_from_nsIContextMenuListener(iface
);
1455 nsIDOMMouseEvent
*event
;
1458 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1462 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1464 hres
= get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
, &node
);
1466 return NS_ERROR_FAILURE
;
1468 fire_event(This
->doc
->basedoc
.doc_node
/* FIXME */, EVENTID_CONTEXTMENU
, TRUE
, node
, aEvent
, NULL
);
1470 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1471 assert(NS_SUCCEEDED(nsres
));
1473 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1474 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1475 nsIDOMMouseEvent_Release(event
);
1477 switch(aContextFlags
) {
1479 case CONTEXT_DOCUMENT
:
1480 case CONTEXT_TEXT
: {
1481 nsISelection
*selection
;
1483 nsres
= nsIDOMHTMLDocument_GetSelection(This
->doc
->basedoc
.doc_node
->nsdoc
, &selection
);
1484 if(NS_SUCCEEDED(nsres
) && selection
) {
1485 cpp_bool is_collapsed
;
1487 /* FIXME: Check if the click was inside selection. */
1488 nsres
= nsISelection_GetIsCollapsed(selection
, &is_collapsed
);
1489 nsISelection_Release(selection
);
1490 if(NS_SUCCEEDED(nsres
) && !is_collapsed
)
1491 dwID
= CONTEXT_MENU_TEXTSELECT
;
1496 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1497 dwID
= CONTEXT_MENU_IMAGE
;
1500 dwID
= CONTEXT_MENU_ANCHOR
;
1503 dwID
= CONTEXT_MENU_CONTROL
;
1506 FIXME("aContextFlags=%08x\n", aContextFlags
);
1509 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)&node
->IHTMLDOMNode_iface
);
1514 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1515 nsContextMenuListener_QueryInterface
,
1516 nsContextMenuListener_AddRef
,
1517 nsContextMenuListener_Release
,
1518 nsContextMenuListener_OnShowContextMenu
1521 /**********************************************************
1522 * nsIURIContentListener interface
1525 static inline NSContainer
*impl_from_nsIURIContentListener(nsIURIContentListener
*iface
)
1527 return CONTAINING_RECORD(iface
, NSContainer
, nsIURIContentListener_iface
);
1530 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1531 nsIIDRef riid
, void **result
)
1533 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1534 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1537 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1539 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1540 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1543 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1545 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1546 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1549 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1550 nsIURI
*aURI
, cpp_bool
*_retval
)
1552 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1553 nsACString spec_str
;
1557 nsACString_Init(&spec_str
, NULL
);
1558 nsIURI_GetSpec(aURI
, &spec_str
);
1559 nsACString_GetData(&spec_str
, &spec
);
1561 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1563 nsACString_Finish(&spec_str
);
1565 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1566 if(NS_FAILED(nsres
))
1569 return !*_retval
&& This
->content_listener
1570 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1574 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1575 const nsACString
*aContentType
, cpp_bool aIsContentPreferred
, nsIRequest
*aRequest
,
1576 nsIStreamListener
**aContentHandler
, cpp_bool
*_retval
)
1578 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1580 TRACE("(%p)->(%p %x %p %p %p)\n", This
, aContentType
, aIsContentPreferred
,
1581 aRequest
, aContentHandler
, _retval
);
1583 return This
->content_listener
1584 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1585 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1586 : NS_ERROR_NOT_IMPLEMENTED
;
1589 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1590 const char *aContentType
, char **aDesiredContentType
, cpp_bool
*_retval
)
1592 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1594 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1596 /* FIXME: Should we do something here? */
1599 return This
->content_listener
1600 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1601 aDesiredContentType
, _retval
)
1605 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1606 const char *aContentType
, cpp_bool aIsContentPreferred
, char **aDesiredContentType
,
1609 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1611 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1612 aDesiredContentType
, _retval
);
1614 return This
->content_listener
1615 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1616 aIsContentPreferred
, aDesiredContentType
, _retval
)
1617 : NS_ERROR_NOT_IMPLEMENTED
;
1620 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1621 nsISupports
**aLoadCookie
)
1623 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1625 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1627 return This
->content_listener
1628 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1629 : NS_ERROR_NOT_IMPLEMENTED
;
1632 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1633 nsISupports
*aLoadCookie
)
1635 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1637 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1639 return This
->content_listener
1640 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1641 : NS_ERROR_NOT_IMPLEMENTED
;
1644 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1645 nsIURIContentListener
**aParentContentListener
)
1647 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1649 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1651 if(This
->content_listener
)
1652 nsIURIContentListener_AddRef(This
->content_listener
);
1654 *aParentContentListener
= This
->content_listener
;
1658 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1659 nsIURIContentListener
*aParentContentListener
)
1661 NSContainer
*This
= impl_from_nsIURIContentListener(iface
);
1663 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1665 if(aParentContentListener
== &This
->nsIURIContentListener_iface
)
1668 if(This
->content_listener
)
1669 nsIURIContentListener_Release(This
->content_listener
);
1671 This
->content_listener
= aParentContentListener
;
1672 if(This
->content_listener
)
1673 nsIURIContentListener_AddRef(This
->content_listener
);
1678 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1679 nsURIContentListener_QueryInterface
,
1680 nsURIContentListener_AddRef
,
1681 nsURIContentListener_Release
,
1682 nsURIContentListener_OnStartURIOpen
,
1683 nsURIContentListener_DoContent
,
1684 nsURIContentListener_IsPreferred
,
1685 nsURIContentListener_CanHandleContent
,
1686 nsURIContentListener_GetLoadCookie
,
1687 nsURIContentListener_SetLoadCookie
,
1688 nsURIContentListener_GetParentContentListener
,
1689 nsURIContentListener_SetParentContentListener
1692 /**********************************************************
1693 * nsIEmbeddinSiteWindow interface
1696 static inline NSContainer
*impl_from_nsIEmbeddingSiteWindow(nsIEmbeddingSiteWindow
*iface
)
1698 return CONTAINING_RECORD(iface
, NSContainer
, nsIEmbeddingSiteWindow_iface
);
1701 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1702 nsIIDRef riid
, void **result
)
1704 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1705 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1708 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1710 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1711 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1714 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1716 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1717 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1720 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1721 UINT32 flags
, LONG x
, LONG y
, LONG cx
, LONG cy
)
1723 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1724 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1725 return NS_ERROR_NOT_IMPLEMENTED
;
1728 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1729 UINT32 flags
, LONG
*x
, LONG
*y
, LONG
*cx
, LONG
*cy
)
1731 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1734 TRACE("(%p)->(%x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1736 if(!GetWindowRect(This
->hwnd
, &r
)) {
1737 ERR("GetWindowRect failed\n");
1738 return NS_ERROR_FAILURE
;
1746 *cx
= r
.right
-r
.left
;
1748 *cy
= r
.bottom
-r
.top
;
1752 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1754 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1756 TRACE("(%p)\n", This
);
1758 return nsIBaseWindow_SetFocus(This
->window
);
1761 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1762 cpp_bool
*aVisibility
)
1764 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1766 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1768 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1772 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1773 cpp_bool aVisibility
)
1775 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1777 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1782 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1785 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1786 WARN("(%p)->(%p)\n", This
, aTitle
);
1787 return NS_ERROR_NOT_IMPLEMENTED
;
1790 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1791 const PRUnichar
*aTitle
)
1793 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1794 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1795 return NS_ERROR_NOT_IMPLEMENTED
;
1798 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1801 NSContainer
*This
= impl_from_nsIEmbeddingSiteWindow(iface
);
1803 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1805 *aSiteWindow
= This
->hwnd
;
1809 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1810 nsEmbeddingSiteWindow_QueryInterface
,
1811 nsEmbeddingSiteWindow_AddRef
,
1812 nsEmbeddingSiteWindow_Release
,
1813 nsEmbeddingSiteWindow_SetDimensions
,
1814 nsEmbeddingSiteWindow_GetDimensions
,
1815 nsEmbeddingSiteWindow_SetFocus
,
1816 nsEmbeddingSiteWindow_GetVisibility
,
1817 nsEmbeddingSiteWindow_SetVisibility
,
1818 nsEmbeddingSiteWindow_GetTitle
,
1819 nsEmbeddingSiteWindow_SetTitle
,
1820 nsEmbeddingSiteWindow_GetSiteWindow
1823 static inline NSContainer
*impl_from_nsITooltipListener(nsITooltipListener
*iface
)
1825 return CONTAINING_RECORD(iface
, NSContainer
, nsITooltipListener_iface
);
1828 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1831 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1832 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1835 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1837 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1838 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1841 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1843 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1844 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1847 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1848 LONG aXCoord
, LONG aYCoord
, const PRUnichar
*aTipText
)
1850 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1853 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1858 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1860 NSContainer
*This
= impl_from_nsITooltipListener(iface
);
1863 hide_tooltip(This
->doc
);
1868 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1869 nsTooltipListener_QueryInterface
,
1870 nsTooltipListener_AddRef
,
1871 nsTooltipListener_Release
,
1872 nsTooltipListener_OnShowTooltip
,
1873 nsTooltipListener_OnHideTooltip
1876 static inline NSContainer
*impl_from_nsIInterfaceRequestor(nsIInterfaceRequestor
*iface
)
1878 return CONTAINING_RECORD(iface
, NSContainer
, nsIInterfaceRequestor_iface
);
1881 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1882 nsIIDRef riid
, void **result
)
1884 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1885 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1888 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1890 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1891 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1894 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1896 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1897 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1900 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1901 nsIIDRef riid
, void **result
)
1903 NSContainer
*This
= impl_from_nsIInterfaceRequestor(iface
);
1905 if(IsEqualGUID(&IID_mozIDOMWindowProxy
, riid
)) {
1906 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1907 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (mozIDOMWindowProxy
**)result
);
1910 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1913 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1914 nsInterfaceRequestor_QueryInterface
,
1915 nsInterfaceRequestor_AddRef
,
1916 nsInterfaceRequestor_Release
,
1917 nsInterfaceRequestor_GetInterface
1920 static inline NSContainer
*impl_from_nsISupportsWeakReference(nsISupportsWeakReference
*iface
)
1922 return CONTAINING_RECORD(iface
, NSContainer
, nsISupportsWeakReference_iface
);
1925 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1926 nsIIDRef riid
, void **result
)
1928 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1929 return nsIWebBrowserChrome_QueryInterface(&This
->nsIWebBrowserChrome_iface
, riid
, result
);
1932 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1934 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1935 return nsIWebBrowserChrome_AddRef(&This
->nsIWebBrowserChrome_iface
);
1938 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1940 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1941 return nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
1944 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1945 nsIWeakReference
**_retval
)
1947 NSContainer
*This
= impl_from_nsISupportsWeakReference(iface
);
1949 TRACE("(%p)->(%p)\n", This
, _retval
);
1951 if(!This
->weak_reference
) {
1952 This
->weak_reference
= heap_alloc(sizeof(nsWeakReference
));
1953 if(!This
->weak_reference
)
1954 return NS_ERROR_OUT_OF_MEMORY
;
1956 This
->weak_reference
->nsIWeakReference_iface
.lpVtbl
= &nsWeakReferenceVtbl
;
1957 This
->weak_reference
->ref
= 1;
1958 This
->weak_reference
->nscontainer
= This
;
1961 *_retval
= &This
->weak_reference
->nsIWeakReference_iface
;
1962 nsIWeakReference_AddRef(*_retval
);
1966 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1967 nsSupportsWeakReference_QueryInterface
,
1968 nsSupportsWeakReference_AddRef
,
1969 nsSupportsWeakReference_Release
,
1970 nsSupportsWeakReference_GetWeakReference
1973 static HRESULT
init_nscontainer(NSContainer
*nscontainer
)
1975 nsIWebBrowserSetup
*wbsetup
;
1976 nsIScrollable
*scrollable
;
1979 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1980 NULL
, &IID_nsIWebBrowser
, (void**)&nscontainer
->webbrowser
);
1981 if(NS_FAILED(nsres
)) {
1982 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1986 nsres
= nsIWebBrowser_SetContainerWindow(nscontainer
->webbrowser
, &nscontainer
->nsIWebBrowserChrome_iface
);
1987 if(NS_FAILED(nsres
)) {
1988 ERR("SetContainerWindow failed: %08x\n", nsres
);
1992 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIBaseWindow
,
1993 (void**)&nscontainer
->window
);
1994 if(NS_FAILED(nsres
)) {
1995 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1999 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserSetup
,
2001 if(NS_SUCCEEDED(nsres
)) {
2002 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
2003 nsIWebBrowserSetup_Release(wbsetup
);
2004 if(NS_FAILED(nsres
)) {
2005 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
2009 ERR("Could not get nsIWebBrowserSetup interface\n");
2013 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebNavigation
,
2014 (void**)&nscontainer
->navigation
);
2015 if(NS_FAILED(nsres
)) {
2016 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
2020 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIWebBrowserFocus
,
2021 (void**)&nscontainer
->focus
);
2022 if(NS_FAILED(nsres
)) {
2023 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
2027 if(!nscontainer_class
) {
2028 register_nscontainer_class();
2029 if(!nscontainer_class
)
2033 nscontainer
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
2034 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
2035 GetDesktopWindow(), NULL
, hInst
, nscontainer
);
2036 if(!nscontainer
->hwnd
) {
2037 WARN("Could not create window\n");
2041 nsres
= nsIBaseWindow_InitWindow(nscontainer
->window
, nscontainer
->hwnd
, NULL
, 0, 0, 100, 100);
2042 if(NS_SUCCEEDED(nsres
)) {
2043 nsres
= nsIBaseWindow_Create(nscontainer
->window
);
2044 if(NS_FAILED(nsres
)) {
2045 WARN("Creating window failed: %08x\n", nsres
);
2049 nsIBaseWindow_SetVisibility(nscontainer
->window
, FALSE
);
2050 nsIBaseWindow_SetEnabled(nscontainer
->window
, FALSE
);
2052 ERR("InitWindow failed: %08x\n", nsres
);
2056 nsres
= nsIWebBrowser_SetParentURIContentListener(nscontainer
->webbrowser
,
2057 &nscontainer
->nsIURIContentListener_iface
);
2058 if(NS_FAILED(nsres
))
2059 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
2061 nsres
= nsIWebBrowser_QueryInterface(nscontainer
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
2062 if(NS_SUCCEEDED(nsres
)) {
2063 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2064 ScrollOrientation_Y
, Scrollbar_Always
);
2065 if(NS_FAILED(nsres
))
2066 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
2068 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
2069 ScrollOrientation_X
, Scrollbar_Auto
);
2070 if(NS_FAILED(nsres
))
2071 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
2073 nsIScrollable_Release(scrollable
);
2075 ERR("Could not get nsIScrollable: %08x\n", nsres
);
2081 HRESULT
create_nscontainer(HTMLDocumentObj
*doc
, NSContainer
**_ret
)
2087 return CLASS_E_CLASSNOTAVAILABLE
;
2089 ret
= heap_alloc_zero(sizeof(NSContainer
));
2091 return E_OUTOFMEMORY
;
2093 ret
->nsIWebBrowserChrome_iface
.lpVtbl
= &nsWebBrowserChromeVtbl
;
2094 ret
->nsIContextMenuListener_iface
.lpVtbl
= &nsContextMenuListenerVtbl
;
2095 ret
->nsIURIContentListener_iface
.lpVtbl
= &nsURIContentListenerVtbl
;
2096 ret
->nsIEmbeddingSiteWindow_iface
.lpVtbl
= &nsEmbeddingSiteWindowVtbl
;
2097 ret
->nsITooltipListener_iface
.lpVtbl
= &nsTooltipListenerVtbl
;
2098 ret
->nsIInterfaceRequestor_iface
.lpVtbl
= &nsInterfaceRequestorVtbl
;
2099 ret
->nsISupportsWeakReference_iface
.lpVtbl
= &nsSupportsWeakReferenceVtbl
;
2104 hres
= init_nscontainer(ret
);
2108 nsIWebBrowserChrome_Release(&ret
->nsIWebBrowserChrome_iface
);
2112 void NSContainer_Release(NSContainer
*This
)
2114 TRACE("(%p)\n", This
);
2118 ShowWindow(This
->hwnd
, SW_HIDE
);
2119 SetParent(This
->hwnd
, NULL
);
2121 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
2122 nsIBaseWindow_Destroy(This
->window
);
2124 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
2126 nsIWebBrowser_Release(This
->webbrowser
);
2127 This
->webbrowser
= NULL
;
2129 nsIWebNavigation_Release(This
->navigation
);
2130 This
->navigation
= NULL
;
2132 nsIBaseWindow_Release(This
->window
);
2133 This
->window
= NULL
;
2135 nsIWebBrowserFocus_Release(This
->focus
);
2138 if(This
->editor_controller
) {
2139 nsIController_Release(This
->editor_controller
);
2140 This
->editor_controller
= NULL
;
2144 nsIEditor_Release(This
->editor
);
2145 This
->editor
= NULL
;
2148 if(This
->content_listener
) {
2149 nsIURIContentListener_Release(This
->content_listener
);
2150 This
->content_listener
= NULL
;
2154 DestroyWindow(This
->hwnd
);
2158 nsIWebBrowserChrome_Release(&This
->nsIWebBrowserChrome_iface
);
2162 * FIXME: nsIScriptObjectPrincipal uses thiscall calling convention, so we need this hack on i386.
2163 * This will be removed after the next Gecko update, that will change calling convention on Gecko side.
2166 extern void *call_thiscall_func
;
2167 __ASM_GLOBAL_FUNC(call_thiscall_func
,
2173 #define nsIScriptObjectPrincipal_GetPrincipal(this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)((this)->lpVtbl->GetPrincipal,this)
2176 nsIXMLHttpRequest
*create_nsxhr(nsIDOMWindow
*nswindow
)
2178 nsIScriptObjectPrincipal
*sop
;
2179 mozIDOMWindow
*inner_window
;
2180 nsIPrincipal
*nspri
;
2181 nsIGlobalObject
*nsglo
;
2182 nsIXMLHttpRequest
*nsxhr
;
2185 nsres
= nsIDOMWindow_GetInnerWindow(nswindow
, &inner_window
);
2186 if(NS_FAILED(nsres
)) {
2187 ERR("Could not get inner window: %08x\n", nsres
);
2191 nsres
= mozIDOMWindow_QueryInterface(inner_window
, &IID_nsIGlobalObject
, (void **)&nsglo
);
2192 mozIDOMWindow_Release(inner_window
);
2193 assert(nsres
== NS_OK
);
2195 nsres
= nsIGlobalObject_QueryInterface(nsglo
, &IID_nsIScriptObjectPrincipal
, (void**)&sop
);
2196 assert(nsres
== NS_OK
);
2198 nspri
= nsIScriptObjectPrincipal_GetPrincipal(sop
);
2199 nsIScriptObjectPrincipal_Release(sop
);
2201 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
2202 NS_XMLHTTPREQUEST_CONTRACTID
, NULL
, &IID_nsIXMLHttpRequest
,
2204 if(NS_SUCCEEDED(nsres
)) {
2205 nsres
= nsIXMLHttpRequest_Init(nsxhr
, nspri
, NULL
, nsglo
, NULL
, NULL
);
2206 if(NS_FAILED(nsres
))
2207 nsIXMLHttpRequest_Release(nsxhr
);
2209 nsISupports_Release(nspri
);
2210 nsIGlobalObject_Release(nsglo
);
2211 if(NS_FAILED(nsres
)) {
2212 ERR("nsIXMLHttpRequest_Init failed: %08x\n", nsres
);