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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
41 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
44 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
45 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
46 #define NS_ARRAY_CONTRACTID "@mozilla.org/array;1"
47 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define APPSTARTUP_TOPIC "app-startup"
52 #define PR_UINT32_MAX 0xffffffff
54 struct nsCStringContainer
{
61 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
62 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
63 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
64 static nsresult (*NS_StringContainerInit
)(nsStringContainer
*);
65 static nsresult (*NS_CStringContainerInit
)(nsCStringContainer
*);
66 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
67 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
68 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
69 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
70 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
71 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
72 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
74 static HINSTANCE hXPCOM
= NULL
;
76 static nsIServiceManager
*pServMgr
= NULL
;
77 static nsIComponentManager
*pCompMgr
= NULL
;
78 static nsIMemory
*nsmem
= NULL
;
80 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
82 static ATOM nscontainer_class
;
84 #define WM_RESETFOCUS_HACK WM_USER+600
86 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
91 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
93 if(msg
== WM_CREATE
) {
94 This
= *(NSContainer
**)lParam
;
95 SetPropW(hwnd
, wszTHIS
, This
);
97 This
= GetPropW(hwnd
, wszTHIS
);
102 TRACE("(%p)->(WM_SIZE)\n", This
);
104 nsres
= nsIBaseWindow_SetSize(This
->window
,
105 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
107 WARN("SetSize failed: %08x\n", nsres
);
110 case WM_RESETFOCUS_HACK
:
113 * Gecko grabs focus in edit mode and some apps don't like it.
114 * We should somehow prevent grabbing focus.
117 TRACE("WM_RESETFOCUS_HACK\n");
119 if(This
->reset_focus
) {
120 SetFocus(This
->reset_focus
);
121 This
->reset_focus
= NULL
;
123 This
->doc
->focus
= FALSE
;
127 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
131 static void register_nscontainer_class(void)
133 static WNDCLASSEXW wndclass
= {
137 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
141 wndclass
.hInstance
= hInst
;
142 nscontainer_class
= RegisterClassExW(&wndclass
);
145 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
147 WCHAR path_env
[MAX_PATH
];
150 static const WCHAR wszPATH
[] = {'P','A','T','H',0};
151 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
153 TRACE("(%s)\n", debugstr_w(gre_path
));
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 GetEnvironmentVariableW(wszPATH
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
157 len
= strlenW(path_env
);
158 path_env
[len
++] = ';';
159 strcpyW(path_env
+len
, gre_path
);
160 SetEnvironmentVariableW(wszPATH
, path_env
);
162 hXPCOM
= LoadLibraryW(strXPCOM
);
164 WARN("Could not load XPCOM: %d\n", GetLastError());
168 #define NS_DLSYM(func) \
169 func = (void *)GetProcAddress(hXPCOM, #func); \
171 ERR("Could not GetProcAddress(" #func ") failed\n")
173 NS_DLSYM(NS_InitXPCOM2
);
174 NS_DLSYM(NS_ShutdownXPCOM
);
175 NS_DLSYM(NS_GetComponentRegistrar
);
176 NS_DLSYM(NS_StringContainerInit
);
177 NS_DLSYM(NS_CStringContainerInit
);
178 NS_DLSYM(NS_StringContainerFinish
);
179 NS_DLSYM(NS_CStringContainerFinish
);
180 NS_DLSYM(NS_StringSetData
);
181 NS_DLSYM(NS_CStringSetData
);
182 NS_DLSYM(NS_NewLocalFile
);
183 NS_DLSYM(NS_StringGetData
);
184 NS_DLSYM(NS_CStringGetData
);
191 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
193 WCHAR file_name
[MAX_PATH
];
198 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
200 strcpyW(file_name
, gre_path
);
201 strcatW(file_name
, wszVersion
);
203 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
204 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
205 if(hfile
== INVALID_HANDLE_VALUE
) {
206 ERR("Could not open VERSION file\n");
210 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
214 TRACE("%s\n", debugstr_a(version
));
216 if(strcmp(version
, version_string
)) {
217 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
218 debugstr_a(version_string
));
225 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
226 const char *version
, const char *version_string
)
228 DWORD res
, type
, size
= MAX_PATH
;
229 HKEY hkey
= mshtml_key
;
231 static const WCHAR wszGeckoPath
[] =
232 {'G','e','c','k','o','P','a','t','h',0};
235 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
236 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
237 if(res
!= ERROR_SUCCESS
)
241 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
242 if(hkey
!= mshtml_key
)
244 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
247 if(!check_version(gre_path
, version_string
))
250 return load_xpcom(gre_path
);
253 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
259 static const WCHAR wszMshtmlKey
[] = {
260 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
261 '\\','M','S','H','T','M','L',0};
263 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
264 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
265 if(res
!= ERROR_SUCCESS
)
268 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
274 static void set_lang(nsIPrefBranch
*pref
)
277 DWORD res
, size
, type
;
281 static const WCHAR international_keyW
[] =
282 {'S','o','f','t','w','a','r','e',
283 '\\','M','i','c','r','o','s','o','f','t',
284 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
285 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
287 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
288 if(res
!= ERROR_SUCCESS
)
291 size
= sizeof(langs
);
292 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
294 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
297 TRACE("Setting lang %s\n", debugstr_a(langs
));
299 nsres
= nsIPrefBranch_SetCharPref(pref
, "intl.accept_languages", langs
);
301 ERR("SetCharPref failed: %08x\n", nsres
);
304 static void set_proxy(nsIPrefBranch
*pref
)
309 DWORD enabled
= 0, res
, size
, type
;
313 static const WCHAR proxy_keyW
[] =
314 {'S','o','f','t','w','a','r','e',
315 '\\','M','i','c','r','o','s','o','f','t',
316 '\\','W','i','n','d','o','w','s',
317 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
318 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
320 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
321 if(res
!= ERROR_SUCCESS
)
324 size
= sizeof(enabled
);
325 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
326 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
332 size
= sizeof(proxy
);
333 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
335 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
338 proxy_port
= strchr(proxy
, ':');
343 proxy_port_num
= atoi(proxy_port
+ 1);
344 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
346 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.type", 1);
348 ERR("SetIntPref network.proxy.type failed: %08x\n", nsres
);
349 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.http", proxy
);
351 ERR("SetCharPref network.proxy.http failed: %08x\n", nsres
);
352 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.http_port", proxy_port_num
);
354 ERR("SetIntPref network.proxy.http_port failed: %08x\n", nsres
);
355 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.ssl", proxy
);
357 ERR("SetCharPref network.proxy.ssl failed: %08x\n", nsres
);
358 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.ssl_port", proxy_port_num
);
360 ERR("SetIntPref network.proxy.ssl_port failed: %08x\n", nsres
);
363 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
367 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
369 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
372 static void set_profile(void)
375 PRBool exists
= FALSE
;
378 static const WCHAR wszMSHTML
[] = {'M','S','H','T','M','L',0};
380 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PROFILE_CONTRACTID
,
381 &IID_nsIProfile
, (void**)&profile
);
382 if(NS_FAILED(nsres
)) {
383 ERR("Could not get profile service: %08x\n", nsres
);
387 nsres
= nsIProfile_ProfileExists(profile
, wszMSHTML
, &exists
);
389 nsres
= nsIProfile_CreateNewProfile(profile
, wszMSHTML
, NULL
, NULL
, FALSE
);
391 ERR("CreateNewProfile failed: %08x\n", nsres
);
394 nsres
= nsIProfile_SetCurrentProfile(profile
, wszMSHTML
);
396 ERR("SetCurrentProfile failed: %08x\n", nsres
);
398 nsIProfile_Release(profile
);
401 static void set_preferences(void)
406 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
407 &IID_nsIPrefBranch
, (void**)&pref
);
408 if(NS_FAILED(nsres
)) {
409 ERR("Could not get preference service: %08x\n", nsres
);
415 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
416 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
418 nsIPrefBranch_Release(pref
);
421 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
424 nsIObserver
*pStartNotif
;
425 nsIComponentRegistrar
*registrar
= NULL
;
429 nsAString_Init(&path
, gre_path
);
430 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
431 nsAString_Finish(&path
);
432 if(NS_FAILED(nsres
)) {
433 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
438 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
439 if(NS_FAILED(nsres
)) {
440 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
445 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
447 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
449 nsres
= NS_GetComponentRegistrar(®istrar
);
450 if(NS_SUCCEEDED(nsres
)) {
451 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
453 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
455 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, gre_dir
);
457 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres
);
459 init_nsio(pCompMgr
, registrar
);
461 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
464 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
465 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
466 if(NS_SUCCEEDED(nsres
)) {
467 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
469 ERR("Observe failed: %08x\n", nsres
);
471 nsIObserver_Release(pStartNotif
);
473 ERR("could not get appstartup-notifier: %08x\n", nsres
);
479 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
480 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
482 ERR("Could not get nsIMemory: %08x\n", nsres
);
485 register_nsservice(registrar
, pServMgr
);
486 nsIComponentRegistrar_Release(registrar
);
492 static CRITICAL_SECTION cs_load_gecko
;
493 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
495 0, 0, &cs_load_gecko
,
496 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
497 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
499 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
501 BOOL
load_gecko(BOOL silent
)
503 PRUnichar gre_path
[MAX_PATH
];
506 static DWORD loading_thread
;
510 /* load_gecko may be called recursively */
511 if(loading_thread
== GetCurrentThreadId())
512 return pCompMgr
!= NULL
;
514 EnterCriticalSection(&cs_load_gecko
);
516 if(!loading_thread
) {
517 loading_thread
= GetCurrentThreadId();
519 if(load_wine_gecko(gre_path
)
520 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
521 ret
= init_xpcom(gre_path
);
523 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
525 ret
= pCompMgr
!= NULL
;
528 LeaveCriticalSection(&cs_load_gecko
);
533 void *nsalloc(size_t size
)
535 return nsIMemory_Alloc(nsmem
, size
);
538 void nsfree(void *mem
)
540 nsIMemory_Free(nsmem
, mem
);
543 void nsACString_Init(nsACString
*str
, const char *data
)
545 NS_CStringContainerInit(str
);
547 nsACString_SetData(str
, data
);
550 void nsACString_SetData(nsACString
*str
, const char *data
)
552 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
555 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
557 return NS_CStringGetData(str
, data
, NULL
);
560 void nsACString_Finish(nsACString
*str
)
562 NS_CStringContainerFinish(str
);
565 void nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
567 NS_StringContainerInit(str
);
569 nsAString_SetData(str
, data
);
572 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
574 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
577 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
579 return NS_StringGetData(str
, data
, NULL
);
582 void nsAString_Finish(nsAString
*str
)
584 NS_StringContainerFinish(str
);
587 nsIInputStream
*create_nsstream(const char *data
, PRInt32 data_len
)
589 nsIStringInputStream
*ret
;
595 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
596 NS_STRINGSTREAM_CONTRACTID
, NULL
, &IID_nsIStringInputStream
,
598 if(NS_FAILED(nsres
)) {
599 ERR("Could not get nsIStringInputStream\n");
603 nsres
= nsIStringInputStream_SetData(ret
, data
, data_len
);
604 if(NS_FAILED(nsres
)) {
605 ERR("AdoptData failed: %08x\n", nsres
);
606 nsIStringInputStream_Release(ret
);
610 return (nsIInputStream
*)ret
;
613 nsICommandParams
*create_nscommand_params(void)
615 nsICommandParams
*ret
= NULL
;
621 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
622 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
625 ERR("Could not get nsICommandParams\n");
630 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
632 nsIInterfaceRequestor
*iface_req
;
635 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
639 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
640 nsIInterfaceRequestor_Release(iface_req
);
645 static void nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
647 nsIDOMNodeList
*node_list
= NULL
;
648 PRBool has_children
= FALSE
;
652 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
654 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
655 if(NS_FAILED(nsres
)) {
656 ERR("GetType failed: %08x\n", nsres
);
662 nsIDOMElement
*nselem
;
663 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
664 nsIContentSerializer_AppendElementStart(serializer
, nselem
, has_children
, str
);
665 nsIDOMElement_Release(nselem
);
670 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
671 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
672 nsIDOMText_Release(nstext
);
676 nsIDOMComment
*nscomment
;
677 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
678 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
681 case DOCUMENT_NODE
: {
682 nsIDOMDocument
*nsdoc
;
683 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
684 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
685 nsIDOMDocument_Release(nsdoc
);
688 case DOCUMENT_FRAGMENT_NODE
:
691 FIXME("Unhandled type %u\n", type
);
695 PRUint32 child_cnt
, i
;
696 nsIDOMNode
*child_node
;
698 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
699 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
701 for(i
=0; i
<child_cnt
; i
++) {
702 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
703 if(NS_SUCCEEDED(nsres
)) {
704 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
705 nsIDOMNode_Release(child_node
);
707 ERR("Item failed: %08x\n", nsres
);
711 nsIDOMNodeList_Release(node_list
);
714 if(type
== ELEMENT_NODE
) {
715 nsIDOMElement
*nselem
;
716 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
717 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
718 nsIDOMElement_Release(nselem
);
722 void nsnode_to_nsstring(nsIDOMNode
*nsdoc
, nsAString
*str
)
724 nsIContentSerializer
*serializer
;
728 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
729 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
730 (void**)&serializer
);
731 if(NS_FAILED(nsres
)) {
732 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
736 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
);
738 ERR("Init failed: %08x\n", nsres
);
740 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
741 nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
742 nsIDOMNode_Release(nsnode
);
744 nsres
= nsIContentSerializer_Flush(serializer
, str
);
746 ERR("Flush failed: %08x\n", nsres
);
748 nsIContentSerializer_Release(serializer
);
751 void get_editor_controller(NSContainer
*This
)
753 nsIEditingSession
*editing_session
= NULL
;
754 nsIControllerContext
*ctrlctx
;
758 nsIEditor_Release(This
->editor
);
762 if(This
->editor_controller
) {
763 nsIController_Release(This
->editor_controller
);
764 This
->editor_controller
= NULL
;
767 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
768 (void**)&editing_session
);
769 if(NS_FAILED(nsres
)) {
770 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
774 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
775 This
->doc
->window
->nswindow
, &This
->editor
);
776 nsIEditingSession_Release(editing_session
);
777 if(NS_FAILED(nsres
)) {
778 ERR("Could not get editor: %08x\n", nsres
);
782 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
783 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
784 if(NS_SUCCEEDED(nsres
)) {
785 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
787 ERR("SetCommandContext failed: %08x\n", nsres
);
788 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
789 (void**)&This
->editor_controller
);
790 nsIControllerContext_Release(ctrlctx
);
792 ERR("Could not get nsIController interface: %08x\n", nsres
);
794 ERR("Could not create edit controller: %08x\n", nsres
);
798 void set_ns_editmode(NSContainer
*This
)
800 nsIEditingSession
*editing_session
= NULL
;
801 nsIURIContentListener
*listener
= NULL
;
802 nsIDOMWindow
*dom_window
= NULL
;
805 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
806 (void**)&editing_session
);
807 if(NS_FAILED(nsres
)) {
808 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
812 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, &dom_window
);
813 if(NS_FAILED(nsres
)) {
814 ERR("Could not get content DOM window: %08x\n", nsres
);
815 nsIEditingSession_Release(editing_session
);
819 nsres
= nsIEditingSession_MakeWindowEditable(editing_session
, dom_window
, NULL
, FALSE
);
820 nsIEditingSession_Release(editing_session
);
821 nsIDOMWindow_Release(dom_window
);
822 if(NS_FAILED(nsres
)) {
823 ERR("MakeWindowEditable failed: %08x\n", nsres
);
827 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
828 * It seams to be a bug in Gecko. To workaround it we set our content
829 * listener again and Gecko's one as its parent.
831 nsIWebBrowser_GetParentURIContentListener(This
->webbrowser
, &listener
);
832 nsIURIContentListener_SetParentContentListener(NSURICL(This
), listener
);
833 nsIURIContentListener_Release(listener
);
834 nsIWebBrowser_SetParentURIContentListener(This
->webbrowser
, NSURICL(This
));
837 void update_nsdocument(HTMLDocument
*doc
)
839 nsIDOMHTMLDocument
*nsdoc
;
840 nsIDOMDocument
*nsdomdoc
;
843 if(!doc
->nscontainer
|| !doc
->nscontainer
->navigation
)
846 nsres
= nsIWebNavigation_GetDocument(doc
->nscontainer
->navigation
, &nsdomdoc
);
847 if(NS_FAILED(nsres
) || !nsdomdoc
) {
848 ERR("GetDocument failed: %08x\n", nsres
);
852 nsres
= nsIDOMDocument_QueryInterface(nsdomdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nsdoc
);
853 nsIDOMDocument_Release(nsdomdoc
);
854 if(NS_FAILED(nsres
)) {
855 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres
);
859 if(nsdoc
== doc
->nsdoc
) {
860 nsIDOMHTMLDocument_Release(nsdoc
);
865 nsIDOMHTMLDocument_Release(doc
->nsdoc
);
870 void close_gecko(void)
877 nsIComponentManager_Release(pCompMgr
);
880 nsIServiceManager_Release(pServMgr
);
883 nsIMemory_Release(nsmem
);
889 /**********************************************************
890 * nsIWebBrowserChrome interface
893 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
895 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
896 nsIIDRef riid
, nsQIResult result
)
898 NSContainer
*This
= NSWBCHROME_THIS(iface
);
901 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
902 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
903 *result
= NSWBCHROME(This
);
904 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
905 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
906 *result
= NSWBCHROME(This
);
907 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
908 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
909 *result
= NSCML(This
);
910 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
911 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
912 *result
= NSURICL(This
);
913 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
914 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
915 *result
= NSEMBWNDS(This
);
916 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
917 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
918 *result
= NSTOOLTIP(This
);
919 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
920 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
921 *result
= NSIFACEREQ(This
);
922 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
923 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
924 *result
= NSWEAKREF(This
);
925 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
926 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
927 *result
= NSSUPWEAKREF(This
);
931 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
935 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
936 return NS_NOINTERFACE
;
939 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
941 NSContainer
*This
= NSWBCHROME_THIS(iface
);
942 LONG ref
= InterlockedIncrement(&This
->ref
);
944 TRACE("(%p) ref=%d\n", This
, ref
);
949 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
951 NSContainer
*This
= NSWBCHROME_THIS(iface
);
952 LONG ref
= InterlockedDecrement(&This
->ref
);
954 TRACE("(%p) ref=%d\n", This
, ref
);
957 heap_free(This
->event_vector
);
959 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
966 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
967 PRUint32 statusType
, const PRUnichar
*status
)
969 NSContainer
*This
= NSWBCHROME_THIS(iface
);
971 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
973 /* FIXME: This hack should be removed when we'll load all pages by URLMoniker */
975 update_nsdocument(This
->doc
);
980 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
981 nsIWebBrowser
**aWebBrowser
)
983 NSContainer
*This
= NSWBCHROME_THIS(iface
);
985 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
988 return NS_ERROR_INVALID_ARG
;
991 nsIWebBrowser_AddRef(This
->webbrowser
);
992 *aWebBrowser
= This
->webbrowser
;
996 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
997 nsIWebBrowser
*aWebBrowser
)
999 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1001 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1003 if(aWebBrowser
!= This
->webbrowser
)
1004 ERR("Wrong nsWebBrowser!\n");
1009 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1010 PRUint32
*aChromeFlags
)
1012 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1013 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1014 return NS_ERROR_NOT_IMPLEMENTED
;
1017 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1018 PRUint32 aChromeFlags
)
1020 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1021 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1022 return NS_ERROR_NOT_IMPLEMENTED
;
1025 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1027 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1028 TRACE("(%p)\n", This
);
1029 return NS_ERROR_NOT_IMPLEMENTED
;
1032 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1033 PRInt32 aCX
, PRInt32 aCY
)
1035 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1036 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1037 return NS_ERROR_NOT_IMPLEMENTED
;
1040 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1042 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1043 WARN("(%p)\n", This
);
1044 return NS_ERROR_NOT_IMPLEMENTED
;
1047 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
1049 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1050 WARN("(%p)->(%p)\n", This
, _retval
);
1051 return NS_ERROR_NOT_IMPLEMENTED
;
1054 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1057 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1058 WARN("(%p)->(%08x)\n", This
, aStatus
);
1059 return NS_ERROR_NOT_IMPLEMENTED
;
1062 #undef NSWBCHROME_THIS
1064 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1065 nsWebBrowserChrome_QueryInterface
,
1066 nsWebBrowserChrome_AddRef
,
1067 nsWebBrowserChrome_Release
,
1068 nsWebBrowserChrome_SetStatus
,
1069 nsWebBrowserChrome_GetWebBrowser
,
1070 nsWebBrowserChrome_SetWebBrowser
,
1071 nsWebBrowserChrome_GetChromeFlags
,
1072 nsWebBrowserChrome_SetChromeFlags
,
1073 nsWebBrowserChrome_DestroyBrowserWindow
,
1074 nsWebBrowserChrome_SizeBrowserTo
,
1075 nsWebBrowserChrome_ShowAsModal
,
1076 nsWebBrowserChrome_IsWindowModal
,
1077 nsWebBrowserChrome_ExitModalEventLoop
1080 /**********************************************************
1081 * nsIContextMenuListener interface
1084 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1086 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1087 nsIIDRef riid
, nsQIResult result
)
1089 NSContainer
*This
= NSCML_THIS(iface
);
1090 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1093 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1095 NSContainer
*This
= NSCML_THIS(iface
);
1096 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1099 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1101 NSContainer
*This
= NSCML_THIS(iface
);
1102 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1105 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1106 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1108 NSContainer
*This
= NSCML_THIS(iface
);
1109 nsIDOMMouseEvent
*event
;
1111 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1114 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1116 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1117 if(NS_FAILED(nsres
)) {
1118 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1122 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1123 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1124 nsIDOMMouseEvent_Release(event
);
1126 switch(aContextFlags
) {
1128 case CONTEXT_DOCUMENT
:
1130 dwID
= CONTEXT_MENU_DEFAULT
;
1133 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1134 dwID
= CONTEXT_MENU_IMAGE
;
1137 dwID
= CONTEXT_MENU_ANCHOR
;
1140 dwID
= CONTEXT_MENU_CONTROL
;
1143 FIXME("aContextFlags=%08x\n", aContextFlags
);
1146 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
, aNode
, TRUE
)));
1153 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1154 nsContextMenuListener_QueryInterface
,
1155 nsContextMenuListener_AddRef
,
1156 nsContextMenuListener_Release
,
1157 nsContextMenuListener_OnShowContextMenu
1160 /**********************************************************
1161 * nsIURIContentListener interface
1164 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1166 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1167 nsIIDRef riid
, nsQIResult result
)
1169 NSContainer
*This
= NSURICL_THIS(iface
);
1170 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1173 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1175 NSContainer
*This
= NSURICL_THIS(iface
);
1176 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1179 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1181 NSContainer
*This
= NSURICL_THIS(iface
);
1182 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1185 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1186 nsIURI
*aURI
, PRBool
*_retval
)
1188 NSContainer
*This
= NSURICL_THIS(iface
);
1189 nsIWineURI
*wine_uri
;
1190 nsACString spec_str
;
1194 nsACString_Init(&spec_str
, NULL
);
1195 nsIURI_GetSpec(aURI
, &spec_str
);
1196 nsACString_GetData(&spec_str
, &spec
);
1198 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1200 nsACString_Finish(&spec_str
);
1202 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
1203 if(NS_FAILED(nsres
)) {
1204 WARN("Could not get nsIWineURI interface: %08x\n", nsres
);
1205 return NS_ERROR_NOT_IMPLEMENTED
;
1208 nsIWineURI_SetNSContainer(wine_uri
, This
);
1209 nsIWineURI_SetIsDocumentURI(wine_uri
, TRUE
);
1211 if(This
->bscallback
) {
1212 IMoniker
*mon
= get_channelbsc_mon(This
->bscallback
);
1218 hres
= IMoniker_GetDisplayName(mon
, NULL
, 0, &wine_url
);
1219 if(SUCCEEDED(hres
)) {
1220 nsIWineURI_SetWineURL(wine_uri
, wine_url
);
1221 CoTaskMemFree(wine_url
);
1223 WARN("GetDisplayName failed: %08x\n", hres
);
1226 IMoniker_Release(mon
);
1230 nsIWineURI_Release(wine_uri
);
1233 return This
->content_listener
1234 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1238 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1239 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1240 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1242 NSContainer
*This
= NSURICL_THIS(iface
);
1244 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1245 aRequest
, aContentHandler
, _retval
);
1247 return This
->content_listener
1248 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1249 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1250 : NS_ERROR_NOT_IMPLEMENTED
;
1253 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1254 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1256 NSContainer
*This
= NSURICL_THIS(iface
);
1258 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1260 /* FIXME: Should we do something here? */
1263 return This
->content_listener
1264 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1265 aDesiredContentType
, _retval
)
1269 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1270 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1273 NSContainer
*This
= NSURICL_THIS(iface
);
1275 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1276 aDesiredContentType
, _retval
);
1278 return This
->content_listener
1279 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1280 aIsContentPreferred
, aDesiredContentType
, _retval
)
1281 : NS_ERROR_NOT_IMPLEMENTED
;
1284 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1285 nsISupports
**aLoadCookie
)
1287 NSContainer
*This
= NSURICL_THIS(iface
);
1289 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1291 return This
->content_listener
1292 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1293 : NS_ERROR_NOT_IMPLEMENTED
;
1296 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1297 nsISupports
*aLoadCookie
)
1299 NSContainer
*This
= NSURICL_THIS(iface
);
1301 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1303 return This
->content_listener
1304 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1305 : NS_ERROR_NOT_IMPLEMENTED
;
1308 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1309 nsIURIContentListener
**aParentContentListener
)
1311 NSContainer
*This
= NSURICL_THIS(iface
);
1313 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1315 if(This
->content_listener
)
1316 nsIURIContentListener_AddRef(This
->content_listener
);
1318 *aParentContentListener
= This
->content_listener
;
1322 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1323 nsIURIContentListener
*aParentContentListener
)
1325 NSContainer
*This
= NSURICL_THIS(iface
);
1327 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1329 if(aParentContentListener
== NSURICL(This
))
1332 if(This
->content_listener
)
1333 nsIURIContentListener_Release(This
->content_listener
);
1335 This
->content_listener
= aParentContentListener
;
1336 if(This
->content_listener
)
1337 nsIURIContentListener_AddRef(This
->content_listener
);
1344 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1345 nsURIContentListener_QueryInterface
,
1346 nsURIContentListener_AddRef
,
1347 nsURIContentListener_Release
,
1348 nsURIContentListener_OnStartURIOpen
,
1349 nsURIContentListener_DoContent
,
1350 nsURIContentListener_IsPreferred
,
1351 nsURIContentListener_CanHandleContent
,
1352 nsURIContentListener_GetLoadCookie
,
1353 nsURIContentListener_SetLoadCookie
,
1354 nsURIContentListener_GetParentContentListener
,
1355 nsURIContentListener_SetParentContentListener
1358 /**********************************************************
1359 * nsIEmbeddinSiteWindow interface
1362 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1364 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1365 nsIIDRef riid
, nsQIResult result
)
1367 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1368 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1371 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1373 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1374 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1377 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1379 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1380 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1383 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1384 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1386 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1387 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1388 return NS_ERROR_NOT_IMPLEMENTED
;
1391 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1392 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1394 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1395 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1396 return NS_ERROR_NOT_IMPLEMENTED
;
1399 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1401 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1403 TRACE("(%p)\n", This
);
1405 if(This
->reset_focus
)
1406 PostMessageW(This
->hwnd
, WM_RESETFOCUS_HACK
, 0, 0);
1408 return nsIBaseWindow_SetFocus(This
->window
);
1411 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1412 PRBool
*aVisibility
)
1414 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1416 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1418 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1422 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1425 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1427 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1432 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1435 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1436 WARN("(%p)->(%p)\n", This
, aTitle
);
1437 return NS_ERROR_NOT_IMPLEMENTED
;
1440 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1441 const PRUnichar
*aTitle
)
1443 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1444 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1445 return NS_ERROR_NOT_IMPLEMENTED
;
1448 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1451 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1453 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1455 *aSiteWindow
= This
->hwnd
;
1459 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1460 nsEmbeddingSiteWindow_QueryInterface
,
1461 nsEmbeddingSiteWindow_AddRef
,
1462 nsEmbeddingSiteWindow_Release
,
1463 nsEmbeddingSiteWindow_SetDimensions
,
1464 nsEmbeddingSiteWindow_GetDimensions
,
1465 nsEmbeddingSiteWindow_SetFocus
,
1466 nsEmbeddingSiteWindow_GetVisibility
,
1467 nsEmbeddingSiteWindow_SetVisibility
,
1468 nsEmbeddingSiteWindow_GetTitle
,
1469 nsEmbeddingSiteWindow_SetTitle
,
1470 nsEmbeddingSiteWindow_GetSiteWindow
1473 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1475 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1478 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1479 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1482 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1484 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1485 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1488 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1490 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1491 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1494 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1495 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1497 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1499 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1504 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1506 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1508 hide_tooltip(This
->doc
);
1513 #undef NSTOOLTIM_THIS
1515 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1516 nsTooltipListener_QueryInterface
,
1517 nsTooltipListener_AddRef
,
1518 nsTooltipListener_Release
,
1519 nsTooltipListener_OnShowTooltip
,
1520 nsTooltipListener_OnHideTooltip
1523 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1525 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1526 nsIIDRef riid
, nsQIResult result
)
1528 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1529 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1532 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1534 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1535 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1538 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1540 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1541 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1544 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1545 nsIIDRef riid
, nsQIResult result
)
1547 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1549 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1550 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1551 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1554 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1557 #undef NSIFACEREQ_THIS
1559 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1560 nsInterfaceRequestor_QueryInterface
,
1561 nsInterfaceRequestor_AddRef
,
1562 nsInterfaceRequestor_Release
,
1563 nsInterfaceRequestor_GetInterface
1566 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1568 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1569 nsIIDRef riid
, nsQIResult result
)
1571 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1572 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1575 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1577 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1578 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1581 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1583 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1584 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1587 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1588 const nsIID
*riid
, void **result
)
1590 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1591 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1594 #undef NSWEAKREF_THIS
1596 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1597 nsWeakReference_QueryInterface
,
1598 nsWeakReference_AddRef
,
1599 nsWeakReference_Release
,
1600 nsWeakReference_QueryReferent
1603 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1605 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1606 nsIIDRef riid
, nsQIResult result
)
1608 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1609 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1612 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1614 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1615 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1618 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1620 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1621 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1624 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1625 nsIWeakReference
**_retval
)
1627 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1629 TRACE("(%p)->(%p)\n", This
, _retval
);
1631 nsIWeakReference_AddRef(NSWEAKREF(This
));
1632 *_retval
= NSWEAKREF(This
);
1636 #undef NSWEAKREF_THIS
1638 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1639 nsSupportsWeakReference_QueryInterface
,
1640 nsSupportsWeakReference_AddRef
,
1641 nsSupportsWeakReference_Release
,
1642 nsSupportsWeakReference_GetWeakReference
1646 NSContainer
*NSContainer_Create(HTMLDocument
*doc
, NSContainer
*parent
)
1648 nsIWebBrowserSetup
*wbsetup
;
1649 nsIScrollable
*scrollable
;
1653 if(!load_gecko(FALSE
))
1656 ret
= heap_alloc_zero(sizeof(NSContainer
));
1658 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1659 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1660 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1661 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1662 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1663 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1664 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1665 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1670 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1671 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1672 if(NS_FAILED(nsres
)) {
1673 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1679 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1680 ret
->parent
= parent
;
1682 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1683 if(NS_FAILED(nsres
))
1684 ERR("SetContainerWindow failed: %08x\n", nsres
);
1686 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1687 (void**)&ret
->window
);
1688 if(NS_FAILED(nsres
))
1689 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1691 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1693 if(NS_SUCCEEDED(nsres
)) {
1694 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1695 nsIWebBrowserSetup_Release(wbsetup
);
1696 if(NS_FAILED(nsres
))
1697 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1699 ERR("Could not get nsIWebBrowserSetup interface\n");
1702 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1703 (void**)&ret
->navigation
);
1704 if(NS_FAILED(nsres
))
1705 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1707 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1708 (void**)&ret
->focus
);
1709 if(NS_FAILED(nsres
))
1710 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1712 if(!nscontainer_class
)
1713 register_nscontainer_class();
1715 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1716 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1717 GetDesktopWindow(), NULL
, hInst
, ret
);
1719 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1720 if(NS_SUCCEEDED(nsres
)) {
1721 nsres
= nsIBaseWindow_Create(ret
->window
);
1722 if(NS_FAILED(nsres
))
1723 WARN("Creating window failed: %08x\n", nsres
);
1725 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1726 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1728 ERR("InitWindow failed: %08x\n", nsres
);
1731 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1732 if(NS_FAILED(nsres
))
1733 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1737 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1738 if(NS_SUCCEEDED(nsres
)) {
1739 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1740 ScrollOrientation_Y
, Scrollbar_Always
);
1741 if(NS_FAILED(nsres
))
1742 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1744 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1745 ScrollOrientation_X
, Scrollbar_Auto
);
1746 if(NS_FAILED(nsres
))
1747 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1749 nsIScrollable_Release(scrollable
);
1751 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1757 void NSContainer_Release(NSContainer
*This
)
1759 TRACE("(%p)\n", This
);
1763 ShowWindow(This
->hwnd
, SW_HIDE
);
1764 SetParent(This
->hwnd
, NULL
);
1766 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1767 nsIBaseWindow_Destroy(This
->window
);
1769 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1771 nsIWebBrowser_Release(This
->webbrowser
);
1772 This
->webbrowser
= NULL
;
1774 nsIWebNavigation_Release(This
->navigation
);
1775 This
->navigation
= NULL
;
1777 nsIBaseWindow_Release(This
->window
);
1778 This
->window
= NULL
;
1780 nsIWebBrowserFocus_Release(This
->focus
);
1783 if(This
->editor_controller
) {
1784 nsIController_Release(This
->editor_controller
);
1785 This
->editor_controller
= NULL
;
1789 nsIEditor_Release(This
->editor
);
1790 This
->editor
= NULL
;
1793 if(This
->content_listener
) {
1794 nsIURIContentListener_Release(This
->content_listener
);
1795 This
->content_listener
= NULL
;
1799 DestroyWindow(This
->hwnd
);
1803 nsIWebBrowserChrome_Release(NSWBCHROME(This
));