msi: Add support for storing strings with embedded nulls in the string table.
[wine.git] / dlls / mshtml / script.c
blob90f9ba09c4cfec6ca3c0b6a82492eb42a4fabd2d
1 /*
2 * Copyright 2008 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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <assert.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "activscp.h"
31 #include "activdbg.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlscript.h"
37 #include "pluginhost.h"
38 #include "htmlevent.h"
39 #include "binding.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
43 #ifdef _WIN64
45 #define CTXARG_T DWORDLONG
46 #define IActiveScriptSiteDebugVtbl IActiveScriptSiteDebug64Vtbl
48 #define IActiveScriptParse_Release IActiveScriptParse64_Release
49 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
50 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
51 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
52 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
54 #else
56 #define CTXARG_T DWORD
57 #define IActiveScriptSiteDebugVtbl IActiveScriptSiteDebug32Vtbl
59 #define IActiveScriptParse_Release IActiveScriptParse32_Release
60 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
61 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
62 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
63 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
65 #endif
67 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
68 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
69 static const WCHAR script_endW[] = {'<','/','S','C','R','I','P','T','>',0};
70 static const WCHAR emptyW[] = {0};
72 struct ScriptHost {
73 IActiveScriptSite IActiveScriptSite_iface;
74 IActiveScriptSiteInterruptPoll IActiveScriptSiteInterruptPoll_iface;
75 IActiveScriptSiteWindow IActiveScriptSiteWindow_iface;
76 IActiveScriptSiteUIControl IActiveScriptSiteUIControl_iface;
77 IActiveScriptSiteDebug IActiveScriptSiteDebug_iface;
78 IServiceProvider IServiceProvider_iface;
80 LONG ref;
82 IActiveScript *script;
83 IActiveScriptParse *parse;
84 IActiveScriptParseProcedure2 *parse_proc;
86 SCRIPTSTATE script_state;
88 HTMLInnerWindow *window;
90 GUID guid;
91 struct list entry;
94 static void set_script_prop(ScriptHost *script_host, DWORD property, VARIANT *val)
96 IActiveScriptProperty *script_prop;
97 HRESULT hres;
99 hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptProperty,
100 (void**)&script_prop);
101 if(FAILED(hres)) {
102 WARN("Could not get IActiveScriptProperty iface: %08x\n", hres);
103 return;
106 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
107 IActiveScriptProperty_Release(script_prop);
108 if(FAILED(hres))
109 WARN("SetProperty(%x) failed: %08x\n", property, hres);
112 static BOOL init_script_engine(ScriptHost *script_host)
114 IObjectSafety *safety;
115 SCRIPTSTATE state;
116 DWORD supported_opts=0, enabled_opts=0;
117 VARIANT var;
118 HRESULT hres;
120 hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptParse, (void**)&script_host->parse);
121 if(FAILED(hres)) {
122 WARN("Could not get IActiveScriptHost: %08x\n", hres);
123 return FALSE;
126 hres = IActiveScript_QueryInterface(script_host->script, &IID_IObjectSafety, (void**)&safety);
127 if(FAILED(hres)) {
128 FIXME("Could not get IObjectSafety: %08x\n", hres);
129 return FALSE;
132 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported_opts, &enabled_opts);
133 if(FAILED(hres)) {
134 FIXME("GetInterfaceSafetyOptions failed: %08x\n", hres);
135 }else if(!(supported_opts & INTERFACE_USES_DISPEX)) {
136 FIXME("INTERFACE_USES_DISPEX is not supported\n");
137 }else {
138 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
139 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
140 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
141 if(FAILED(hres))
142 FIXME("SetInterfaceSafetyOptions failed: %08x\n", hres);
145 IObjectSafety_Release(safety);
146 if(FAILED(hres))
147 return FALSE;
149 V_VT(&var) = VT_I4;
150 V_I4(&var) = 1;
151 set_script_prop(script_host, SCRIPTPROP_INVOKEVERSIONING, &var);
153 V_VT(&var) = VT_BOOL;
154 V_BOOL(&var) = VARIANT_TRUE;
155 set_script_prop(script_host, SCRIPTPROP_HACK_TRIDENTEVENTSINK, &var);
157 hres = IActiveScriptParse_InitNew(script_host->parse);
158 if(FAILED(hres)) {
159 WARN("InitNew failed: %08x\n", hres);
160 return FALSE;
163 hres = IActiveScript_SetScriptSite(script_host->script, &script_host->IActiveScriptSite_iface);
164 if(FAILED(hres)) {
165 WARN("SetScriptSite failed: %08x\n", hres);
166 IActiveScript_Close(script_host->script);
167 return FALSE;
170 hres = IActiveScript_GetScriptState(script_host->script, &state);
171 if(FAILED(hres))
172 WARN("GetScriptState failed: %08x\n", hres);
173 else if(state != SCRIPTSTATE_INITIALIZED)
174 FIXME("state = %x\n", state);
176 hres = IActiveScript_SetScriptState(script_host->script, SCRIPTSTATE_STARTED);
177 if(FAILED(hres)) {
178 WARN("Starting script failed: %08x\n", hres);
179 return FALSE;
182 hres = IActiveScript_AddNamedItem(script_host->script, windowW,
183 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
184 if(SUCCEEDED(hres)) {
185 V_VT(&var) = VT_BOOL;
186 V_BOOL(&var) = VARIANT_TRUE;
187 set_script_prop(script_host, SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION, &var);
188 }else {
189 WARN("AddNamedItem failed: %08x\n", hres);
192 hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptParseProcedure2,
193 (void**)&script_host->parse_proc);
194 if(FAILED(hres)) {
195 /* FIXME: QI for IActiveScriptParseProcedure */
196 WARN("Could not get IActiveScriptParseProcedure iface: %08x\n", hres);
199 return TRUE;
202 static void release_script_engine(ScriptHost *This)
204 if(!This->script)
205 return;
207 switch(This->script_state) {
208 case SCRIPTSTATE_CONNECTED:
209 IActiveScript_SetScriptState(This->script, SCRIPTSTATE_DISCONNECTED);
211 case SCRIPTSTATE_STARTED:
212 case SCRIPTSTATE_DISCONNECTED:
213 case SCRIPTSTATE_INITIALIZED:
214 IActiveScript_Close(This->script);
216 default:
217 if(This->parse_proc) {
218 IActiveScriptParseProcedure2_Release(This->parse_proc);
219 This->parse_proc = NULL;
222 if(This->parse) {
223 IActiveScriptParse_Release(This->parse);
224 This->parse = NULL;
228 IActiveScript_Release(This->script);
229 This->script = NULL;
230 This->script_state = SCRIPTSTATE_UNINITIALIZED;
233 void connect_scripts(HTMLInnerWindow *window)
235 ScriptHost *iter;
237 LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
238 if(iter->script_state == SCRIPTSTATE_STARTED)
239 IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED);
243 static inline ScriptHost *impl_from_IActiveScriptSite(IActiveScriptSite *iface)
245 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSite_iface);
248 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
250 ScriptHost *This = impl_from_IActiveScriptSite(iface);
252 *ppv = NULL;
254 if(IsEqualGUID(&IID_IUnknown, riid)) {
255 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
256 *ppv = &This->IActiveScriptSite_iface;
257 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
258 TRACE("(%p)->(IID_IActiveScriptSite %p)\n", This, ppv);
259 *ppv = &This->IActiveScriptSite_iface;
260 }else if(IsEqualGUID(&IID_IActiveScriptSiteInterruptPoll, riid)) {
261 TRACE("(%p)->(IID_IActiveScriptSiteInterruprtPoll %p)\n", This, ppv);
262 *ppv = &This->IActiveScriptSiteInterruptPoll_iface;
263 }else if(IsEqualGUID(&IID_IActiveScriptSiteWindow, riid)) {
264 TRACE("(%p)->(IID_IActiveScriptSiteWindow %p)\n", This, ppv);
265 *ppv = &This->IActiveScriptSiteWindow_iface;
266 }else if(IsEqualGUID(&IID_IActiveScriptSiteUIControl, riid)) {
267 TRACE("(%p)->(IID_IActiveScriptSiteUIControl %p)\n", This, ppv);
268 *ppv = &This->IActiveScriptSiteUIControl_iface;
269 }else if(IsEqualGUID(&IID_IActiveScriptSiteDebug, riid)) {
270 TRACE("(%p)->(IID_IActiveScriptSiteDebug %p)\n", This, ppv);
271 *ppv = &This->IActiveScriptSiteDebug_iface;
272 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
273 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
274 *ppv = &This->IServiceProvider_iface;
275 }else if(IsEqualGUID(&IID_ICanHandleException, riid)) {
276 TRACE("(%p)->(IID_ICanHandleException not supported %p)\n", This, ppv);
277 return E_NOINTERFACE;
278 }else {
279 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
280 return E_NOINTERFACE;
283 IUnknown_AddRef((IUnknown*)*ppv);
284 return S_OK;
287 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
289 ScriptHost *This = impl_from_IActiveScriptSite(iface);
290 LONG ref = InterlockedIncrement(&This->ref);
292 TRACE("(%p) ref=%d\n", This, ref);
294 return ref;
297 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
299 ScriptHost *This = impl_from_IActiveScriptSite(iface);
300 LONG ref = InterlockedDecrement(&This->ref);
302 TRACE("(%p) ref=%d\n", This, ref);
304 if(!ref) {
305 release_script_engine(This);
306 if(This->window)
307 list_remove(&This->entry);
308 heap_free(This);
311 return ref;
314 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
316 ScriptHost *This = impl_from_IActiveScriptSite(iface);
318 TRACE("(%p)->(%p)\n", This, plcid);
320 *plcid = GetUserDefaultLCID();
321 return S_OK;
324 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
325 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
327 ScriptHost *This = impl_from_IActiveScriptSite(iface);
329 TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_w(pstrName), dwReturnMask, ppiunkItem, ppti);
331 if(dwReturnMask != SCRIPTINFO_IUNKNOWN) {
332 FIXME("Unsupported mask %x\n", dwReturnMask);
333 return E_NOTIMPL;
336 *ppiunkItem = NULL;
338 if(strcmpW(pstrName, windowW))
339 return DISP_E_MEMBERNOTFOUND;
341 if(!This->window)
342 return E_FAIL;
344 /* FIXME: Return proxy object */
345 *ppiunkItem = (IUnknown*)&This->window->base.IHTMLWindow2_iface;
346 IUnknown_AddRef(*ppiunkItem);
348 return S_OK;
351 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
353 ScriptHost *This = impl_from_IActiveScriptSite(iface);
354 FIXME("(%p)->(%p)\n", This, pbstrVersion);
355 return E_NOTIMPL;
358 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
359 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
361 ScriptHost *This = impl_from_IActiveScriptSite(iface);
362 FIXME("(%p)->(%p %p)\n", This, pvarResult, pexcepinfo);
363 return E_NOTIMPL;
366 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
368 ScriptHost *This = impl_from_IActiveScriptSite(iface);
370 TRACE("(%p)->(%x)\n", This, ssScriptState);
372 This->script_state = ssScriptState;
373 return S_OK;
376 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
378 ScriptHost *This = impl_from_IActiveScriptSite(iface);
379 FIXME("(%p)->(%p)\n", This, pscripterror);
380 return E_NOTIMPL;
383 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
385 ScriptHost *This = impl_from_IActiveScriptSite(iface);
387 TRACE("(%p)->()\n", This);
389 return S_OK;
392 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
394 ScriptHost *This = impl_from_IActiveScriptSite(iface);
396 TRACE("(%p)->()\n", This);
398 return S_OK;
401 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
402 ActiveScriptSite_QueryInterface,
403 ActiveScriptSite_AddRef,
404 ActiveScriptSite_Release,
405 ActiveScriptSite_GetLCID,
406 ActiveScriptSite_GetItemInfo,
407 ActiveScriptSite_GetDocVersionString,
408 ActiveScriptSite_OnScriptTerminate,
409 ActiveScriptSite_OnStateChange,
410 ActiveScriptSite_OnScriptError,
411 ActiveScriptSite_OnEnterScript,
412 ActiveScriptSite_OnLeaveScript
415 static inline ScriptHost *impl_from_IActiveScriptSiteInterruptPoll(IActiveScriptSiteInterruptPoll *iface)
417 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteInterruptPoll_iface);
420 static HRESULT WINAPI ActiveScriptSiteInterruptPoll_QueryInterface(IActiveScriptSiteInterruptPoll *iface,
421 REFIID riid, void **ppv)
423 ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
424 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
427 static ULONG WINAPI ActiveScriptSiteInterruptPoll_AddRef(IActiveScriptSiteInterruptPoll *iface)
429 ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
430 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
433 static ULONG WINAPI ActiveScriptSiteInterruptPoll_Release(IActiveScriptSiteInterruptPoll *iface)
435 ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
436 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
439 static HRESULT WINAPI ActiveScriptSiteInterruptPoll_QueryContinue(IActiveScriptSiteInterruptPoll *iface)
441 ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
443 TRACE("(%p)\n", This);
445 return S_OK;
448 static const IActiveScriptSiteInterruptPollVtbl ActiveScriptSiteInterruptPollVtbl = {
449 ActiveScriptSiteInterruptPoll_QueryInterface,
450 ActiveScriptSiteInterruptPoll_AddRef,
451 ActiveScriptSiteInterruptPoll_Release,
452 ActiveScriptSiteInterruptPoll_QueryContinue
455 static inline ScriptHost *impl_from_IActiveScriptSiteWindow(IActiveScriptSiteWindow *iface)
457 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteWindow_iface);
460 static HRESULT WINAPI ActiveScriptSiteWindow_QueryInterface(IActiveScriptSiteWindow *iface,
461 REFIID riid, void **ppv)
463 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
464 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
467 static ULONG WINAPI ActiveScriptSiteWindow_AddRef(IActiveScriptSiteWindow *iface)
469 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
470 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
473 static ULONG WINAPI ActiveScriptSiteWindow_Release(IActiveScriptSiteWindow *iface)
475 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
476 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
479 static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow *iface, HWND *phwnd)
481 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
483 TRACE("(%p)->(%p)\n", This, phwnd);
485 if(!This->window || !This->window->base.outer_window || !This->window->base.outer_window->doc_obj)
486 return E_UNEXPECTED;
488 *phwnd = This->window->base.outer_window->doc_obj->hwnd;
489 return S_OK;
492 static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL fEnable)
494 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
495 FIXME("(%p)->(%x)\n", This, fEnable);
496 return S_OK;
499 static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = {
500 ActiveScriptSiteWindow_QueryInterface,
501 ActiveScriptSiteWindow_AddRef,
502 ActiveScriptSiteWindow_Release,
503 ActiveScriptSiteWindow_GetWindow,
504 ActiveScriptSiteWindow_EnableModeless
507 static inline ScriptHost *impl_from_IActiveScriptSiteUIControl(IActiveScriptSiteUIControl *iface)
509 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteUIControl_iface);
512 static HRESULT WINAPI ActiveScriptSiteUIControl_QueryInterface(IActiveScriptSiteUIControl *iface, REFIID riid, void **ppv)
514 ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
515 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
518 static ULONG WINAPI ActiveScriptSiteUIControl_AddRef(IActiveScriptSiteUIControl *iface)
520 ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
521 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
524 static ULONG WINAPI ActiveScriptSiteUIControl_Release(IActiveScriptSiteUIControl *iface)
526 ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
527 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
530 static HRESULT WINAPI ActiveScriptSiteUIControl_GetUIBehavior(IActiveScriptSiteUIControl *iface, SCRIPTUICITEM UicItem,
531 SCRIPTUICHANDLING *pUicHandling)
533 ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
535 WARN("(%p)->(%d %p) semi-stub\n", This, UicItem, pUicHandling);
537 *pUicHandling = SCRIPTUICHANDLING_ALLOW;
538 return S_OK;
541 static const IActiveScriptSiteUIControlVtbl ActiveScriptSiteUIControlVtbl = {
542 ActiveScriptSiteUIControl_QueryInterface,
543 ActiveScriptSiteUIControl_AddRef,
544 ActiveScriptSiteUIControl_Release,
545 ActiveScriptSiteUIControl_GetUIBehavior
548 static inline ScriptHost *impl_from_IActiveScriptSiteDebug(IActiveScriptSiteDebug *iface)
550 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteDebug_iface);
553 static HRESULT WINAPI ActiveScriptSiteDebug_QueryInterface(IActiveScriptSiteDebug *iface,
554 REFIID riid, void **ppv)
556 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
557 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
560 static ULONG WINAPI ActiveScriptSiteDebug_AddRef(IActiveScriptSiteDebug *iface)
562 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
563 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
566 static ULONG WINAPI ActiveScriptSiteDebug_Release(IActiveScriptSiteDebug *iface)
568 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
569 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
572 static HRESULT WINAPI ActiveScriptSiteDebug_GetDocumentContextFromPosition(IActiveScriptSiteDebug *iface,
573 CTXARG_T dwSourceContext, ULONG uCharacterOffset, ULONG uNumChars, IDebugDocumentContext **ppsc)
575 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
576 FIXME("(%p)->(%s %u %u %p)\n", This, wine_dbgstr_longlong(dwSourceContext), uCharacterOffset,
577 uNumChars, ppsc);
578 return E_NOTIMPL;
581 static HRESULT WINAPI ActiveScriptSiteDebug_GetApplication(IActiveScriptSiteDebug *iface, IDebugApplication **ppda)
583 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
584 FIXME("(%p)->(%p)\n", This, ppda);
585 return E_NOTIMPL;
588 static HRESULT WINAPI ActiveScriptSiteDebug_GetRootApplicationNode(IActiveScriptSiteDebug *iface,
589 IDebugApplicationNode **ppdanRoot)
591 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
592 FIXME("(%p)->(%p)\n", This, ppdanRoot);
593 return E_NOTIMPL;
596 static HRESULT WINAPI ActiveScriptSiteDebug_OnScriptErrorDebug(IActiveScriptSiteDebug *iface,
597 IActiveScriptErrorDebug *pErrorDebug, BOOL *pfEnterDebugger, BOOL *pfCallOnScriptErrorWhenContinuing)
599 ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
600 FIXME("(%p)->(%p %p %p)\n", This, pErrorDebug, pfEnterDebugger, pfCallOnScriptErrorWhenContinuing);
601 return E_NOTIMPL;
604 static const IActiveScriptSiteDebugVtbl ActiveScriptSiteDebugVtbl = {
605 ActiveScriptSiteDebug_QueryInterface,
606 ActiveScriptSiteDebug_AddRef,
607 ActiveScriptSiteDebug_Release,
608 ActiveScriptSiteDebug_GetDocumentContextFromPosition,
609 ActiveScriptSiteDebug_GetApplication,
610 ActiveScriptSiteDebug_GetRootApplicationNode,
611 ActiveScriptSiteDebug_OnScriptErrorDebug
614 static inline ScriptHost *impl_from_IServiceProvider(IServiceProvider *iface)
616 return CONTAINING_RECORD(iface, ScriptHost, IServiceProvider_iface);
619 static HRESULT WINAPI ASServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
621 ScriptHost *This = impl_from_IServiceProvider(iface);
622 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
625 static ULONG WINAPI ASServiceProvider_AddRef(IServiceProvider *iface)
627 ScriptHost *This = impl_from_IServiceProvider(iface);
628 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
631 static ULONG WINAPI ASServiceProvider_Release(IServiceProvider *iface)
633 ScriptHost *This = impl_from_IServiceProvider(iface);
634 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
637 static HRESULT WINAPI ASServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
638 REFIID riid, void **ppv)
640 ScriptHost *This = impl_from_IServiceProvider(iface);
642 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
643 TRACE("(%p)->(SID_SInternetHostSecurityManager)\n", This);
645 if(!This->window || !This->window->doc)
646 return E_NOINTERFACE;
648 return IInternetHostSecurityManager_QueryInterface(&This->window->doc->IInternetHostSecurityManager_iface,
649 riid, ppv);
652 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
653 return E_NOINTERFACE;
656 static const IServiceProviderVtbl ASServiceProviderVtbl = {
657 ASServiceProvider_QueryInterface,
658 ASServiceProvider_AddRef,
659 ASServiceProvider_Release,
660 ASServiceProvider_QueryService
663 static ScriptHost *create_script_host(HTMLInnerWindow *window, const GUID *guid)
665 ScriptHost *ret;
666 HRESULT hres;
668 ret = heap_alloc_zero(sizeof(*ret));
669 if(!ret)
670 return NULL;
672 ret->IActiveScriptSite_iface.lpVtbl = &ActiveScriptSiteVtbl;
673 ret->IActiveScriptSiteInterruptPoll_iface.lpVtbl = &ActiveScriptSiteInterruptPollVtbl;
674 ret->IActiveScriptSiteWindow_iface.lpVtbl = &ActiveScriptSiteWindowVtbl;
675 ret->IActiveScriptSiteUIControl_iface.lpVtbl = &ActiveScriptSiteUIControlVtbl;
676 ret->IActiveScriptSiteDebug_iface.lpVtbl = &ActiveScriptSiteDebugVtbl;
677 ret->IServiceProvider_iface.lpVtbl = &ASServiceProviderVtbl;
678 ret->ref = 1;
679 ret->window = window;
680 ret->script_state = SCRIPTSTATE_UNINITIALIZED;
682 ret->guid = *guid;
683 list_add_tail(&window->script_hosts, &ret->entry);
685 hres = CoCreateInstance(&ret->guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
686 &IID_IActiveScript, (void**)&ret->script);
687 if(FAILED(hres))
688 WARN("Could not load script engine: %08x\n", hres);
689 else if(!init_script_engine(ret))
690 release_script_engine(ret);
692 return ret;
695 static void parse_text(ScriptHost *script_host, LPCWSTR text)
697 EXCEPINFO excepinfo;
698 VARIANT var;
699 HRESULT hres;
701 TRACE("%s\n", debugstr_w(text));
703 VariantInit(&var);
704 memset(&excepinfo, 0, sizeof(excepinfo));
705 TRACE(">>>\n");
706 hres = IActiveScriptParse_ParseScriptText(script_host->parse, text, windowW, NULL, script_endW,
707 0, 0, SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE,
708 &var, &excepinfo);
709 if(SUCCEEDED(hres))
710 TRACE("<<<\n");
711 else
712 WARN("<<< %08x\n", hres);
716 static void parse_extern_script(ScriptHost *script_host, LPCWSTR src)
718 IMoniker *mon;
719 WCHAR *text;
720 HRESULT hres;
722 static const WCHAR wine_schemaW[] = {'w','i','n','e',':'};
724 if(strlenW(src) > sizeof(wine_schemaW)/sizeof(WCHAR) && !memcmp(src, wine_schemaW, sizeof(wine_schemaW)))
725 src += sizeof(wine_schemaW)/sizeof(WCHAR);
727 hres = CreateURLMoniker(NULL, src, &mon);
728 if(FAILED(hres))
729 return;
731 hres = bind_mon_to_wstr(script_host->window, mon, &text);
732 IMoniker_Release(mon);
733 if(FAILED(hres))
734 return;
736 parse_text(script_host, text);
738 heap_free(text);
741 static void parse_inline_script(ScriptHost *script_host, HTMLScriptElement *script_elem)
743 const PRUnichar *text;
744 nsAString text_str;
745 nsresult nsres;
747 nsAString_Init(&text_str, NULL);
748 nsres = nsIDOMHTMLScriptElement_GetText(script_elem->nsscript, &text_str);
749 nsAString_GetData(&text_str, &text);
751 if(NS_FAILED(nsres)) {
752 ERR("GetText failed: %08x\n", nsres);
753 }else if(*text) {
754 script_elem->parsed = TRUE;
755 parse_text(script_host, text);
758 nsAString_Finish(&text_str);
761 static void parse_script_elem(ScriptHost *script_host, HTMLScriptElement *script_elem)
763 nsAString src_str, event_str;
764 const PRUnichar *src;
765 nsresult nsres;
767 nsAString_Init(&event_str, NULL);
768 nsres = nsIDOMHTMLScriptElement_GetEvent(script_elem->nsscript, &event_str);
769 if(NS_SUCCEEDED(nsres)) {
770 const PRUnichar *event;
772 nsAString_GetData(&event_str, &event);
773 if(*event) {
774 TRACE("deferring event %s script evaluation\n", debugstr_w(event));
775 nsAString_Finish(&event_str);
776 return;
778 }else {
779 ERR("GetAttribute(event) failed: %08x\n", nsres);
781 nsAString_Finish(&event_str);
783 nsAString_Init(&src_str, NULL);
784 nsres = nsIDOMHTMLScriptElement_GetSrc(script_elem->nsscript, &src_str);
785 nsAString_GetData(&src_str, &src);
787 if(NS_FAILED(nsres)) {
788 ERR("GetSrc failed: %08x\n", nsres);
789 }else if(*src) {
790 script_elem->parsed = TRUE;
791 parse_extern_script(script_host, src);
792 }else {
793 parse_inline_script(script_host, script_elem);
796 nsAString_Finish(&src_str);
799 static GUID get_default_script_guid(HTMLInnerWindow *window)
801 /* If not specified, we should use very first script host that was created for the page (or JScript if none) */
802 return list_empty(&window->script_hosts)
803 ? CLSID_JScript
804 : LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry)->guid;
807 static BOOL get_guid_from_type(LPCWSTR type, GUID *guid)
809 const WCHAR text_javascriptW[] =
810 {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
811 const WCHAR text_vbscriptW[] =
812 {'t','e','x','t','/','v','b','s','c','r','i','p','t',0};
814 /* FIXME: Handle more types */
815 if(!strcmpiW(type, text_javascriptW)) {
816 *guid = CLSID_JScript;
817 }else if(!strcmpiW(type, text_vbscriptW)) {
818 *guid = CLSID_VBScript;
819 }else {
820 FIXME("Unknown type %s\n", debugstr_w(type));
821 return FALSE;
824 return TRUE;
827 static BOOL get_guid_from_language(LPCWSTR type, GUID *guid)
829 HRESULT hres;
831 hres = CLSIDFromProgID(type, guid);
832 if(FAILED(hres))
833 return FALSE;
835 /* FIXME: Check CATID_ActiveScriptParse */
837 return TRUE;
840 static BOOL get_script_guid(HTMLInnerWindow *window, nsIDOMHTMLScriptElement *nsscript, GUID *guid)
842 nsAString attr_str, val_str;
843 BOOL ret = FALSE;
844 nsresult nsres;
846 static const PRUnichar languageW[] = {'l','a','n','g','u','a','g','e',0};
848 nsAString_Init(&val_str, NULL);
850 nsres = nsIDOMHTMLScriptElement_GetType(nsscript, &val_str);
851 if(NS_SUCCEEDED(nsres)) {
852 const PRUnichar *type;
854 nsAString_GetData(&val_str, &type);
855 if(*type) {
856 ret = get_guid_from_type(type, guid);
857 nsAString_Finish(&val_str);
858 return ret;
860 }else {
861 ERR("GetType failed: %08x\n", nsres);
864 nsAString_InitDepend(&attr_str, languageW);
865 nsres = nsIDOMHTMLScriptElement_GetAttribute(nsscript, &attr_str, &val_str);
866 nsAString_Finish(&attr_str);
867 if(NS_SUCCEEDED(nsres)) {
868 const PRUnichar *language;
870 nsAString_GetData(&val_str, &language);
872 if(*language) {
873 ret = get_guid_from_language(language, guid);
874 }else {
875 *guid = get_default_script_guid(window);
876 ret = TRUE;
878 }else {
879 ERR("GetAttribute(language) failed: %08x\n", nsres);
882 nsAString_Finish(&val_str);
884 return ret;
887 static ScriptHost *get_script_host(HTMLInnerWindow *window, const GUID *guid)
889 ScriptHost *iter;
891 LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
892 if(IsEqualGUID(guid, &iter->guid))
893 return iter;
896 return create_script_host(window, guid);
899 static ScriptHost *get_elem_script_host(HTMLInnerWindow *window, HTMLScriptElement *script_elem)
901 GUID guid;
903 if(!get_script_guid(window, script_elem->nsscript, &guid)) {
904 WARN("Could not find script GUID\n");
905 return NULL;
908 if(IsEqualGUID(&CLSID_JScript, &guid)
909 && (!window->base.outer_window || window->base.outer_window->scriptmode != SCRIPTMODE_ACTIVESCRIPT)) {
910 TRACE("Ignoring JScript\n");
911 return NULL;
914 return get_script_host(window, &guid);
917 void doc_insert_script(HTMLInnerWindow *window, HTMLScriptElement *script_elem)
919 ScriptHost *script_host;
921 if(script_elem->parsed)
922 return;
924 script_host = get_elem_script_host(window, script_elem);
925 if(!script_host)
926 return;
928 if(script_host->parse)
929 parse_script_elem(script_host, script_elem);
932 IDispatch *script_parse_event(HTMLInnerWindow *window, LPCWSTR text)
934 ScriptHost *script_host;
935 GUID guid;
936 const WCHAR *ptr;
937 IDispatch *disp;
938 HRESULT hres;
940 static const WCHAR delimiterW[] = {'\"',0};
942 TRACE("%s\n", debugstr_w(text));
944 for(ptr = text; isalnumW(*ptr); ptr++);
945 if(*ptr == ':') {
946 LPWSTR language;
947 BOOL b;
949 language = heap_alloc((ptr-text+1)*sizeof(WCHAR));
950 if(!language)
951 return NULL;
953 memcpy(language, text, (ptr-text)*sizeof(WCHAR));
954 language[ptr-text] = 0;
956 b = get_guid_from_language(language, &guid);
958 heap_free(language);
960 if(!b) {
961 WARN("Could not find language\n");
962 return NULL;
965 ptr++;
966 }else {
967 ptr = text;
968 guid = get_default_script_guid(window);
971 if(IsEqualGUID(&CLSID_JScript, &guid)
972 && (!window->base.outer_window || window->base.outer_window->scriptmode != SCRIPTMODE_ACTIVESCRIPT)) {
973 TRACE("Ignoring JScript\n");
974 return NULL;
977 script_host = get_script_host(window, &guid);
978 if(!script_host || !script_host->parse_proc)
979 return NULL;
981 hres = IActiveScriptParseProcedure2_ParseProcedureText(script_host->parse_proc, ptr, NULL, emptyW,
982 NULL, NULL, delimiterW, 0 /* FIXME */, 0,
983 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
984 if(FAILED(hres)) {
985 WARN("ParseProcedureText failed: %08x\n", hres);
986 return NULL;
989 TRACE("ret %p\n", disp);
990 return disp;
993 HRESULT exec_script(HTMLInnerWindow *window, const WCHAR *code, const WCHAR *lang, VARIANT *ret)
995 ScriptHost *script_host;
996 EXCEPINFO ei;
997 GUID guid;
998 HRESULT hres;
1000 static const WCHAR delimW[] = {'"',0};
1002 if(!get_guid_from_language(lang, &guid)) {
1003 WARN("Could not find script GUID\n");
1004 return CO_E_CLASSSTRING;
1007 script_host = get_script_host(window, &guid);
1008 if(!script_host) {
1009 FIXME("No script host\n");
1010 return E_FAIL;
1013 if(!script_host->parse) {
1014 FIXME("script_host->parse == NULL\n");
1015 return E_FAIL;
1018 memset(&ei, 0, sizeof(ei));
1019 TRACE(">>>\n");
1020 hres = IActiveScriptParse_ParseScriptText(script_host->parse, code, NULL, NULL, delimW, 0, 0, SCRIPTTEXT_ISVISIBLE, ret, &ei);
1021 if(SUCCEEDED(hres))
1022 TRACE("<<<\n");
1023 else
1024 WARN("<<< %08x\n", hres);
1026 return hres;
1029 IDispatch *get_script_disp(ScriptHost *script_host)
1031 IDispatch *disp;
1032 HRESULT hres;
1034 if(!script_host->script)
1035 return NULL;
1037 hres = IActiveScript_GetScriptDispatch(script_host->script, windowW, &disp);
1038 if(FAILED(hres))
1039 return NULL;
1041 return disp;
1044 static HTMLElement *find_event_target(HTMLDocumentNode *doc, HTMLScriptElement *script_elem)
1046 const PRUnichar *target_id;
1047 nsAString target_id_str;
1048 HTMLElement *elem;
1049 nsresult nsres;
1050 HRESULT hres;
1052 nsAString_Init(&target_id_str, NULL);
1053 nsres = nsIDOMHTMLScriptElement_GetHtmlFor(script_elem->nsscript, &target_id_str);
1054 if(NS_FAILED(nsres)) {
1055 ERR("GetScriptFor failed: %08x\n", nsres);
1056 nsAString_Finish(&target_id_str);
1057 return NULL;
1060 nsAString_GetData(&target_id_str, &target_id);
1061 if(!*target_id || !strcmpW(target_id, documentW) || !strcmpW(target_id, windowW)) {
1062 FIXME("for %s not supported\n", debugstr_w(target_id));
1063 elem = NULL;
1064 }else {
1065 hres = get_doc_elem_by_id(doc, target_id, &elem);
1066 if(FAILED(hres))
1067 elem = NULL;
1069 nsAString_Finish(&target_id_str);
1071 return elem;
1074 static BOOL parse_event_str(WCHAR *event, const WCHAR **args)
1076 WCHAR *ptr;
1078 TRACE("%s\n", debugstr_w(event));
1080 for(ptr = event; isalnumW(*ptr); ptr++);
1081 if(!*ptr) {
1082 *args = NULL;
1083 return TRUE;
1086 if(*ptr != '(')
1087 return FALSE;
1089 *ptr++ = 0;
1090 *args = ptr;
1091 while(isalnumW(*ptr) || isspaceW(*ptr) || *ptr == ',')
1092 ptr++;
1094 if(*ptr != ')')
1095 return FALSE;
1097 *ptr++ = 0;
1098 return !*ptr;
1101 static IDispatch *parse_event_elem(HTMLDocumentNode *doc, HTMLScriptElement *script_elem, WCHAR **ret_event)
1103 ScriptHost *script_host;
1104 WCHAR *event = NULL;
1105 const WCHAR *args;
1106 nsAString nsstr;
1107 IDispatch *disp;
1108 nsresult nsres;
1109 HRESULT hres;
1111 if(script_elem->parsed)
1112 return NULL;
1114 script_host = get_elem_script_host(doc->window, script_elem);
1115 if(!script_host || !script_host->parse_proc)
1116 return NULL;
1118 nsAString_Init(&nsstr, NULL);
1119 nsres = nsIDOMHTMLScriptElement_GetEvent(script_elem->nsscript, &nsstr);
1120 if(NS_SUCCEEDED(nsres)) {
1121 const PRUnichar *event_val;
1123 nsAString_GetData(&nsstr, &event_val);
1124 event = heap_strdupW(event_val);
1126 nsAString_Finish(&nsstr);
1127 if(!event)
1128 return NULL;
1130 if(!parse_event_str(event, &args)) {
1131 WARN("parsing %s failed\n", debugstr_w(event));
1132 heap_free(event);
1133 return NULL;
1136 nsAString_Init(&nsstr, NULL);
1137 nsres = nsIDOMHTMLScriptElement_GetText(script_elem->nsscript, &nsstr);
1138 if(NS_SUCCEEDED(nsres)) {
1139 const PRUnichar *text;
1141 nsAString_GetData(&nsstr, &text);
1142 hres = IActiveScriptParseProcedure2_ParseProcedureText(script_host->parse_proc, text, args,
1143 emptyW, NULL, NULL, script_endW, 0, 0,
1144 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
1145 if(FAILED(hres))
1146 disp = NULL;
1147 }else {
1148 ERR("GetText failed: %08x\n", nsres);
1149 disp = NULL;
1151 nsAString_Finish(&nsstr);
1152 if(!disp) {
1153 heap_free(event);
1154 return NULL;
1157 *ret_event = event;
1158 return disp;
1161 void bind_event_scripts(HTMLDocumentNode *doc)
1163 HTMLPluginContainer *plugin_container;
1164 nsIDOMHTMLScriptElement *nsscript;
1165 HTMLScriptElement *script_elem;
1166 HTMLElement *event_target;
1167 nsIDOMNodeList *node_list;
1168 nsIDOMNode *script_node;
1169 nsAString selector_str;
1170 IDispatch *event_disp;
1171 PRUint32 length, i;
1172 WCHAR *event;
1173 nsresult nsres;
1174 HRESULT hres;
1176 static const PRUnichar selectorW[] = {'s','c','r','i','p','t','[','e','v','e','n','t',']',0};
1178 TRACE("%p\n", doc);
1180 if(!doc->nsdoc)
1181 return;
1183 nsAString_InitDepend(&selector_str, selectorW);
1184 nsres = nsIDOMNodeSelector_QuerySelectorAll(doc->nsnode_selector, &selector_str, &node_list);
1185 nsAString_Finish(&selector_str);
1186 if(NS_FAILED(nsres)) {
1187 ERR("QuerySelectorAll failed: %08x\n", nsres);
1188 return;
1191 if(!node_list)
1192 return;
1194 nsres = nsIDOMNodeList_GetLength(node_list, &length);
1195 assert(nsres == NS_OK);
1197 for(i=0; i < length; i++) {
1198 nsres = nsIDOMNodeList_Item(node_list, i, &script_node);
1199 if(NS_FAILED(nsres) || !script_node) {
1200 ERR("Item(%d) failed: %08x\n", i, nsres);
1201 continue;
1204 nsres = nsIDOMNode_QueryInterface(script_node, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
1205 assert(nsres == NS_OK);
1206 nsIDOMNode_Release(script_node);
1208 hres = script_elem_from_nsscript(doc, nsscript, &script_elem);
1209 if(FAILED(hres))
1210 continue;
1212 event_disp = parse_event_elem(doc, script_elem, &event);
1213 if(event_disp) {
1214 event_target = find_event_target(doc, script_elem);
1215 if(event_target) {
1216 hres = IHTMLElement_QueryInterface(&event_target->IHTMLElement_iface, &IID_HTMLPluginContainer,
1217 (void**)&plugin_container);
1219 if(SUCCEEDED(hres))
1220 bind_activex_event(doc, plugin_container, event, event_disp);
1221 else
1222 bind_elem_event(doc, event_target, event, event_disp);
1224 IHTMLElement_Release(&event_target->IHTMLElement_iface);
1227 heap_free(event);
1228 IDispatch_Release(event_disp);
1231 IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface);
1234 nsIDOMNodeList_Release(node_list);
1237 BOOL find_global_prop(HTMLInnerWindow *window, BSTR name, DWORD flags, ScriptHost **ret_host, DISPID *ret_id)
1239 IDispatchEx *dispex;
1240 IDispatch *disp;
1241 ScriptHost *iter;
1242 HRESULT hres;
1244 LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
1245 disp = get_script_disp(iter);
1246 if(!disp)
1247 continue;
1249 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1250 if(SUCCEEDED(hres)) {
1251 hres = IDispatchEx_GetDispID(dispex, name, flags & (~fdexNameEnsure), ret_id);
1252 IDispatchEx_Release(dispex);
1253 }else {
1254 FIXME("No IDispatchEx\n");
1255 hres = E_NOTIMPL;
1258 IDispatch_Release(disp);
1259 if(SUCCEEDED(hres)) {
1260 *ret_host = iter;
1261 return TRUE;
1265 return FALSE;
1268 static BOOL is_jscript_available(void)
1270 static BOOL available, checked;
1272 if(!checked) {
1273 IUnknown *unk;
1274 HRESULT hres = CoGetClassObject(&CLSID_JScript, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1276 if(SUCCEEDED(hres)) {
1277 available = TRUE;
1278 IUnknown_Release(unk);
1279 }else {
1280 available = FALSE;
1282 checked = TRUE;
1285 return available;
1288 void set_script_mode(HTMLOuterWindow *window, SCRIPTMODE mode)
1290 nsIWebBrowserSetup *setup;
1291 nsresult nsres;
1293 if(mode == SCRIPTMODE_ACTIVESCRIPT && !is_jscript_available()) {
1294 TRACE("jscript.dll not available\n");
1295 window->scriptmode = SCRIPTMODE_GECKO;
1296 return;
1299 window->scriptmode = mode;
1301 if(!window->doc_obj->nscontainer || !window->doc_obj->nscontainer->webbrowser)
1302 return;
1304 nsres = nsIWebBrowser_QueryInterface(window->doc_obj->nscontainer->webbrowser,
1305 &IID_nsIWebBrowserSetup, (void**)&setup);
1306 if(NS_SUCCEEDED(nsres)) {
1307 nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT,
1308 window->scriptmode == SCRIPTMODE_GECKO);
1310 if(NS_SUCCEEDED(nsres))
1311 nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_DISABLE_NOSCRIPT, TRUE);
1313 nsIWebBrowserSetup_Release(setup);
1316 if(NS_FAILED(nsres))
1317 ERR("JavaScript setup failed: %08x\n", nsres);
1320 void release_script_hosts(HTMLInnerWindow *window)
1322 script_queue_entry_t *queue_iter;
1323 ScriptHost *iter;
1325 while(!list_empty(&window->script_queue)) {
1326 queue_iter = LIST_ENTRY(list_head(&window->script_queue), script_queue_entry_t, entry);
1328 list_remove(&queue_iter->entry);
1329 IHTMLScriptElement_Release(&queue_iter->script->IHTMLScriptElement_iface);
1330 heap_free(queue_iter);
1333 while(!list_empty(&window->script_hosts)) {
1334 iter = LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry);
1336 release_script_engine(iter);
1337 list_remove(&iter->entry);
1338 iter->window = NULL;
1339 IActiveScriptSite_Release(&iter->IActiveScriptSite_iface);