2008-03-25 02:10:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2012-10-02 15:46:20 +02:00
|
|
|
#include <assert.h>
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "activscp.h"
|
2008-04-17 02:31:00 +02:00
|
|
|
#include "activdbg.h"
|
2014-10-09 16:08:47 +02:00
|
|
|
#include "shlwapi.h"
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
2012-10-16 17:07:29 +02:00
|
|
|
#include "htmlscript.h"
|
2012-10-02 15:46:20 +02:00
|
|
|
#include "pluginhost.h"
|
|
|
|
#include "htmlevent.h"
|
2012-07-27 10:51:24 +02:00
|
|
|
#include "binding.h"
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
#ifdef _WIN64
|
2012-07-26 11:37:48 +02:00
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
#define CTXARG_T DWORDLONG
|
|
|
|
#define IActiveScriptSiteDebugVtbl IActiveScriptSiteDebug64Vtbl
|
2012-07-26 11:37:48 +02:00
|
|
|
|
|
|
|
#define IActiveScriptParse_Release IActiveScriptParse64_Release
|
|
|
|
#define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
|
|
|
|
#define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
|
2012-10-04 14:59:25 +02:00
|
|
|
#define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
|
|
|
|
#define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
|
2012-07-26 11:37:48 +02:00
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
#else
|
2012-07-26 11:37:48 +02:00
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
#define CTXARG_T DWORD
|
|
|
|
#define IActiveScriptSiteDebugVtbl IActiveScriptSiteDebug32Vtbl
|
2012-07-26 11:37:48 +02:00
|
|
|
|
|
|
|
#define IActiveScriptParse_Release IActiveScriptParse32_Release
|
|
|
|
#define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
|
|
|
|
#define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
|
2012-10-04 14:59:25 +02:00
|
|
|
#define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
|
|
|
|
#define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
|
2012-07-26 11:37:48 +02:00
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-01 19:18:35 +01:00
|
|
|
/* See jscript.h in jscript.dll. */
|
|
|
|
#define SCRIPTLANGUAGEVERSION_HTML 0x400
|
|
|
|
#define SCRIPTLANGUAGEVERSION_ES5 0x102
|
|
|
|
|
2009-09-09 21:31:32 +02:00
|
|
|
struct ScriptHost {
|
2011-01-04 01:56:46 +01:00
|
|
|
IActiveScriptSite IActiveScriptSite_iface;
|
|
|
|
IActiveScriptSiteInterruptPoll IActiveScriptSiteInterruptPoll_iface;
|
|
|
|
IActiveScriptSiteWindow IActiveScriptSiteWindow_iface;
|
2012-09-26 14:37:34 +02:00
|
|
|
IActiveScriptSiteUIControl IActiveScriptSiteUIControl_iface;
|
2011-01-04 01:56:46 +01:00
|
|
|
IActiveScriptSiteDebug IActiveScriptSiteDebug_iface;
|
2010-12-27 01:43:10 +01:00
|
|
|
IServiceProvider IServiceProvider_iface;
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IActiveScript *script;
|
2008-03-28 19:00:59 +01:00
|
|
|
IActiveScriptParse *parse;
|
2012-10-04 14:59:25 +02:00
|
|
|
IActiveScriptParseProcedure2 *parse_proc;
|
2008-03-28 19:00:34 +01:00
|
|
|
|
|
|
|
SCRIPTSTATE script_state;
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
HTMLInnerWindow *window;
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
GUID guid;
|
|
|
|
struct list entry;
|
2009-09-09 21:31:32 +02:00
|
|
|
};
|
2008-03-25 02:10:47 +01:00
|
|
|
|
2016-07-19 18:37:11 +02:00
|
|
|
static ScriptHost *get_elem_script_host(HTMLInnerWindow*,HTMLScriptElement*);
|
|
|
|
|
2018-03-01 19:18:35 +01:00
|
|
|
static BOOL set_script_prop(ScriptHost *script_host, DWORD property, VARIANT *val)
|
2009-08-31 02:15:09 +02:00
|
|
|
{
|
|
|
|
IActiveScriptProperty *script_prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptProperty,
|
|
|
|
(void**)&script_prop);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not get IActiveScriptProperty iface: %08x\n", hres);
|
2018-03-01 19:18:35 +01:00
|
|
|
return FALSE;
|
2009-08-31 02:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
|
|
|
|
IActiveScriptProperty_Release(script_prop);
|
2018-03-01 19:18:35 +01:00
|
|
|
if(FAILED(hres)) {
|
2009-08-31 02:15:09 +02:00
|
|
|
WARN("SetProperty(%x) failed: %08x\n", property, hres);
|
2018-03-01 19:18:35 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2009-08-31 02:15:09 +02:00
|
|
|
}
|
|
|
|
|
2008-03-28 19:00:59 +01:00
|
|
|
static BOOL init_script_engine(ScriptHost *script_host)
|
|
|
|
{
|
2018-03-01 19:18:10 +01:00
|
|
|
compat_mode_t compat_mode;
|
2008-03-28 19:00:59 +01:00
|
|
|
IObjectSafety *safety;
|
|
|
|
SCRIPTSTATE state;
|
2018-03-01 19:18:10 +01:00
|
|
|
DWORD supported_opts=0, enabled_opts=0, script_mode;
|
2009-08-31 02:15:09 +02:00
|
|
|
VARIANT var;
|
2008-03-28 19:00:59 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptParse, (void**)&script_host->parse);
|
|
|
|
if(FAILED(hres)) {
|
2016-07-11 22:25:24 +02:00
|
|
|
WARN("Could not get IActiveScriptParse: %08x\n", hres);
|
2008-03-28 19:00:59 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script_host->script, &IID_IObjectSafety, (void**)&safety);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
FIXME("Could not get IObjectSafety: %08x\n", hres);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported_opts, &enabled_opts);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
FIXME("GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
}else if(!(supported_opts & INTERFACE_USES_DISPEX)) {
|
|
|
|
FIXME("INTERFACE_USES_DISPEX is not supported\n");
|
|
|
|
}else {
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
|
|
|
|
if(FAILED(hres))
|
|
|
|
FIXME("SetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
|
|
|
IObjectSafety_Release(safety);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-03-01 19:18:10 +01:00
|
|
|
compat_mode = lock_document_mode(script_host->window->doc);
|
|
|
|
script_mode = compat_mode < COMPAT_MODE_IE8 ? SCRIPTLANGUAGEVERSION_5_7 : SCRIPTLANGUAGEVERSION_5_8;
|
2018-03-01 19:18:35 +01:00
|
|
|
if(IsEqualGUID(&script_host->guid, &CLSID_JScript)) {
|
|
|
|
if(compat_mode >= COMPAT_MODE_IE9)
|
|
|
|
script_mode = SCRIPTLANGUAGEVERSION_ES5;
|
|
|
|
script_mode |= SCRIPTLANGUAGEVERSION_HTML;
|
|
|
|
}
|
2009-08-31 02:15:09 +02:00
|
|
|
V_VT(&var) = VT_I4;
|
2018-03-01 19:18:10 +01:00
|
|
|
V_I4(&var) = script_mode;
|
2018-03-01 19:18:35 +01:00
|
|
|
if(!set_script_prop(script_host, SCRIPTPROP_INVOKEVERSIONING, &var) && (script_mode & SCRIPTLANGUAGEVERSION_HTML)) {
|
|
|
|
/* If this failed, we're most likely using native jscript. */
|
|
|
|
WARN("Failed to set script mode to HTML version.\n");
|
|
|
|
V_I4(&var) = compat_mode < COMPAT_MODE_IE8 ? SCRIPTLANGUAGEVERSION_5_7 : SCRIPTLANGUAGEVERSION_5_8;
|
|
|
|
set_script_prop(script_host, SCRIPTPROP_INVOKEVERSIONING, &var);
|
|
|
|
}
|
2008-03-28 19:00:59 +01:00
|
|
|
|
2009-08-31 02:15:09 +02:00
|
|
|
V_VT(&var) = VT_BOOL;
|
|
|
|
V_BOOL(&var) = VARIANT_TRUE;
|
|
|
|
set_script_prop(script_host, SCRIPTPROP_HACK_TRIDENTEVENTSINK, &var);
|
2008-03-28 19:00:59 +01:00
|
|
|
|
2012-07-26 11:37:48 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(script_host->parse);
|
2008-03-28 19:00:59 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("InitNew failed: %08x\n", hres);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
hres = IActiveScript_SetScriptSite(script_host->script, &script_host->IActiveScriptSite_iface);
|
2008-03-28 19:00:59 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("SetScriptSite failed: %08x\n", hres);
|
|
|
|
IActiveScript_Close(script_host->script);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IActiveScript_GetScriptState(script_host->script, &state);
|
|
|
|
if(FAILED(hres))
|
|
|
|
WARN("GetScriptState failed: %08x\n", hres);
|
|
|
|
else if(state != SCRIPTSTATE_INITIALIZED)
|
|
|
|
FIXME("state = %x\n", state);
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptState(script_host->script, SCRIPTSTATE_STARTED);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Starting script failed: %08x\n", hres);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-24 23:29:19 +01:00
|
|
|
hres = IActiveScript_AddNamedItem(script_host->script, L"window",
|
2008-03-28 19:00:59 +01:00
|
|
|
SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
|
2009-08-31 02:15:09 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
V_VT(&var) = VT_BOOL;
|
|
|
|
V_BOOL(&var) = VARIANT_TRUE;
|
|
|
|
set_script_prop(script_host, SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION, &var);
|
|
|
|
}else {
|
2008-03-28 19:00:59 +01:00
|
|
|
WARN("AddNamedItem failed: %08x\n", hres);
|
2009-08-31 02:15:09 +02:00
|
|
|
}
|
2008-03-28 19:00:59 +01:00
|
|
|
|
2008-04-17 22:53:52 +02:00
|
|
|
hres = IActiveScript_QueryInterface(script_host->script, &IID_IActiveScriptParseProcedure2,
|
|
|
|
(void**)&script_host->parse_proc);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
/* FIXME: QI for IActiveScriptParseProcedure */
|
|
|
|
WARN("Could not get IActiveScriptParseProcedure iface: %08x\n", hres);
|
|
|
|
}
|
2008-03-28 19:00:59 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_script_engine(ScriptHost *This)
|
|
|
|
{
|
|
|
|
if(!This->script)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(This->script_state) {
|
|
|
|
case SCRIPTSTATE_CONNECTED:
|
|
|
|
IActiveScript_SetScriptState(This->script, SCRIPTSTATE_DISCONNECTED);
|
|
|
|
|
|
|
|
case SCRIPTSTATE_STARTED:
|
|
|
|
case SCRIPTSTATE_DISCONNECTED:
|
|
|
|
case SCRIPTSTATE_INITIALIZED:
|
|
|
|
IActiveScript_Close(This->script);
|
|
|
|
|
|
|
|
default:
|
2008-04-17 22:53:52 +02:00
|
|
|
if(This->parse_proc) {
|
2012-10-04 14:59:25 +02:00
|
|
|
IActiveScriptParseProcedure2_Release(This->parse_proc);
|
2008-04-17 22:53:52 +02:00
|
|
|
This->parse_proc = NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-28 19:00:59 +01:00
|
|
|
if(This->parse) {
|
2012-07-26 11:37:48 +02:00
|
|
|
IActiveScriptParse_Release(This->parse);
|
2008-03-28 19:00:59 +01:00
|
|
|
This->parse = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IActiveScript_Release(This->script);
|
|
|
|
This->script = NULL;
|
|
|
|
This->script_state = SCRIPTSTATE_UNINITIALIZED;
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
void connect_scripts(HTMLInnerWindow *window)
|
2008-03-28 19:01:15 +01:00
|
|
|
{
|
|
|
|
ScriptHost *iter;
|
|
|
|
|
2009-09-09 21:30:41 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
|
2008-03-28 19:01:15 +01:00
|
|
|
if(iter->script_state == SCRIPTSTATE_STARTED)
|
|
|
|
IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
static inline ScriptHost *impl_from_IActiveScriptSite(IActiveScriptSite *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSite_iface);
|
|
|
|
}
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-04 01:56:46 +01:00
|
|
|
*ppv = &This->IActiveScriptSite_iface;
|
2008-03-25 02:10:47 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptSite %p)\n", This, ppv);
|
2011-01-04 01:56:46 +01:00
|
|
|
*ppv = &This->IActiveScriptSite_iface;
|
2008-03-28 19:01:37 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IActiveScriptSiteInterruptPoll, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptSiteInterruprtPoll %p)\n", This, ppv);
|
2011-01-04 01:56:46 +01:00
|
|
|
*ppv = &This->IActiveScriptSiteInterruptPoll_iface;
|
2008-03-29 18:34:49 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IActiveScriptSiteWindow, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptSiteWindow %p)\n", This, ppv);
|
2011-01-04 01:56:46 +01:00
|
|
|
*ppv = &This->IActiveScriptSiteWindow_iface;
|
2012-09-26 14:37:34 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IActiveScriptSiteUIControl, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptSiteUIControl %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IActiveScriptSiteUIControl_iface;
|
2010-08-25 20:20:29 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IActiveScriptSiteDebug, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IActiveScriptSiteDebug %p)\n", This, ppv);
|
2011-01-04 01:56:46 +01:00
|
|
|
*ppv = &This->IActiveScriptSiteDebug_iface;
|
2009-09-29 00:11:06 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
|
2010-12-27 01:43:10 +01:00
|
|
|
*ppv = &This->IServiceProvider_iface;
|
2008-11-12 06:08:17 +01:00
|
|
|
}else if(IsEqualGUID(&IID_ICanHandleException, riid)) {
|
|
|
|
TRACE("(%p)->(IID_ICanHandleException not supported %p)\n", This, ppv);
|
|
|
|
return E_NOINTERFACE;
|
2008-03-25 02:10:47 +01:00
|
|
|
}else {
|
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
2008-03-28 19:00:59 +01:00
|
|
|
release_script_engine(This);
|
2009-09-09 21:30:41 +02:00
|
|
|
if(This->window)
|
2008-03-25 02:10:47 +01:00
|
|
|
list_remove(&This->entry);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-29 18:35:02 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, plcid);
|
|
|
|
|
|
|
|
*plcid = GetUserDefaultLCID();
|
|
|
|
return S_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
|
|
|
|
DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-29 18:35:15 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %p %p)\n", This, debugstr_w(pstrName), dwReturnMask, ppiunkItem, ppti);
|
|
|
|
|
|
|
|
if(dwReturnMask != SCRIPTINFO_IUNKNOWN) {
|
|
|
|
FIXME("Unsupported mask %x\n", dwReturnMask);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppiunkItem = NULL;
|
|
|
|
|
2020-11-24 23:29:19 +01:00
|
|
|
if(wcscmp(pstrName, L"window"))
|
2008-03-29 18:35:15 +01:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2012-06-26 12:33:48 +02:00
|
|
|
if(!This->window)
|
2008-03-29 18:35:15 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/* FIXME: Return proxy object */
|
2012-06-26 12:33:48 +02:00
|
|
|
*ppiunkItem = (IUnknown*)&This->window->base.IHTMLWindow2_iface;
|
2008-03-29 18:35:15 +01:00
|
|
|
IUnknown_AddRef(*ppiunkItem);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
FIXME("(%p)->(%p)\n", This, pbstrVersion);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
|
|
|
|
const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
FIXME("(%p)->(%p %p)\n", This, pvarResult, pexcepinfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-28 19:00:34 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%x)\n", This, ssScriptState);
|
|
|
|
|
|
|
|
This->script_state = ssScriptState;
|
|
|
|
return S_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
FIXME("(%p)->(%p)\n", This, pscripterror);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-29 21:39:23 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSite(iface);
|
2008-03-29 21:39:23 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
|
|
|
|
ActiveScriptSite_QueryInterface,
|
|
|
|
ActiveScriptSite_AddRef,
|
|
|
|
ActiveScriptSite_Release,
|
|
|
|
ActiveScriptSite_GetLCID,
|
|
|
|
ActiveScriptSite_GetItemInfo,
|
|
|
|
ActiveScriptSite_GetDocVersionString,
|
|
|
|
ActiveScriptSite_OnScriptTerminate,
|
|
|
|
ActiveScriptSite_OnStateChange,
|
|
|
|
ActiveScriptSite_OnScriptError,
|
|
|
|
ActiveScriptSite_OnEnterScript,
|
|
|
|
ActiveScriptSite_OnLeaveScript
|
|
|
|
};
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
static inline ScriptHost *impl_from_IActiveScriptSiteInterruptPoll(IActiveScriptSiteInterruptPoll *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteInterruptPoll_iface);
|
|
|
|
}
|
2008-03-28 19:01:37 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteInterruptPoll_QueryInterface(IActiveScriptSiteInterruptPoll *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
|
|
|
|
return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
|
2008-03-28 19:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteInterruptPoll_AddRef(IActiveScriptSiteInterruptPoll *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
|
|
|
|
return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
|
2008-03-28 19:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteInterruptPoll_Release(IActiveScriptSiteInterruptPoll *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
|
|
|
|
return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
|
2008-03-28 19:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteInterruptPoll_QueryContinue(IActiveScriptSiteInterruptPoll *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteInterruptPoll(iface);
|
2008-04-23 16:47:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-03-28 19:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptSiteInterruptPollVtbl ActiveScriptSiteInterruptPollVtbl = {
|
|
|
|
ActiveScriptSiteInterruptPoll_QueryInterface,
|
|
|
|
ActiveScriptSiteInterruptPoll_AddRef,
|
|
|
|
ActiveScriptSiteInterruptPoll_Release,
|
|
|
|
ActiveScriptSiteInterruptPoll_QueryContinue
|
|
|
|
};
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
static inline ScriptHost *impl_from_IActiveScriptSiteWindow(IActiveScriptSiteWindow *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteWindow_iface);
|
|
|
|
}
|
2008-03-29 18:34:49 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteWindow_QueryInterface(IActiveScriptSiteWindow *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
|
|
|
|
return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
|
2008-03-29 18:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteWindow_AddRef(IActiveScriptSiteWindow *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
|
|
|
|
return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
|
2008-03-29 18:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteWindow_Release(IActiveScriptSiteWindow *iface)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
|
|
|
|
return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
|
2008-03-29 18:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow *iface, HWND *phwnd)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
|
2012-09-26 14:37:16 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, phwnd);
|
|
|
|
|
2019-03-14 14:12:48 +01:00
|
|
|
if(!This->window || !This->window->base.outer_window)
|
2012-09-26 14:37:16 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2019-03-14 14:12:48 +01:00
|
|
|
*phwnd = This->window->base.outer_window->browser->doc->hwnd;
|
2012-09-26 14:37:16 +02:00
|
|
|
return S_OK;
|
2008-03-29 18:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL fEnable)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
|
2008-03-29 18:34:49 +01:00
|
|
|
FIXME("(%p)->(%x)\n", This, fEnable);
|
2012-09-26 14:37:16 +02:00
|
|
|
return S_OK;
|
2008-03-29 18:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = {
|
|
|
|
ActiveScriptSiteWindow_QueryInterface,
|
|
|
|
ActiveScriptSiteWindow_AddRef,
|
|
|
|
ActiveScriptSiteWindow_Release,
|
|
|
|
ActiveScriptSiteWindow_GetWindow,
|
|
|
|
ActiveScriptSiteWindow_EnableModeless
|
|
|
|
};
|
|
|
|
|
2012-09-26 14:37:34 +02:00
|
|
|
static inline ScriptHost *impl_from_IActiveScriptSiteUIControl(IActiveScriptSiteUIControl *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteUIControl_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteUIControl_QueryInterface(IActiveScriptSiteUIControl *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
|
|
|
|
return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteUIControl_AddRef(IActiveScriptSiteUIControl *iface)
|
|
|
|
{
|
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
|
|
|
|
return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSiteUIControl_Release(IActiveScriptSiteUIControl *iface)
|
|
|
|
{
|
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
|
|
|
|
return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSiteUIControl_GetUIBehavior(IActiveScriptSiteUIControl *iface, SCRIPTUICITEM UicItem,
|
|
|
|
SCRIPTUICHANDLING *pUicHandling)
|
|
|
|
{
|
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteUIControl(iface);
|
|
|
|
|
|
|
|
WARN("(%p)->(%d %p) semi-stub\n", This, UicItem, pUicHandling);
|
|
|
|
|
|
|
|
*pUicHandling = SCRIPTUICHANDLING_ALLOW;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptSiteUIControlVtbl ActiveScriptSiteUIControlVtbl = {
|
|
|
|
ActiveScriptSiteUIControl_QueryInterface,
|
|
|
|
ActiveScriptSiteUIControl_AddRef,
|
|
|
|
ActiveScriptSiteUIControl_Release,
|
|
|
|
ActiveScriptSiteUIControl_GetUIBehavior
|
|
|
|
};
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
static inline ScriptHost *impl_from_IActiveScriptSiteDebug(IActiveScriptSiteDebug *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteDebug_iface);
|
|
|
|
}
|
2008-04-17 02:31:00 +02:00
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSiteDebug_QueryInterface(IActiveScriptSiteDebug *iface,
|
2008-04-17 02:31:00 +02:00
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
|
|
|
return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
|
2008-04-17 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static ULONG WINAPI ActiveScriptSiteDebug_AddRef(IActiveScriptSiteDebug *iface)
|
2008-04-17 02:31:00 +02:00
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
|
|
|
return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
|
2008-04-17 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static ULONG WINAPI ActiveScriptSiteDebug_Release(IActiveScriptSiteDebug *iface)
|
2008-04-17 02:31:00 +02:00
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
|
|
|
return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
|
2008-04-17 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSiteDebug_GetDocumentContextFromPosition(IActiveScriptSiteDebug *iface,
|
|
|
|
CTXARG_T dwSourceContext, ULONG uCharacterOffset, ULONG uNumChars, IDebugDocumentContext **ppsc)
|
2008-04-17 02:31:00 +02:00
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
2010-08-25 20:20:29 +02:00
|
|
|
FIXME("(%p)->(%s %u %u %p)\n", This, wine_dbgstr_longlong(dwSourceContext), uCharacterOffset,
|
|
|
|
uNumChars, ppsc);
|
2008-04-17 02:31:00 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSiteDebug_GetApplication(IActiveScriptSiteDebug *iface, IDebugApplication **ppda)
|
2008-04-17 02:31:00 +02:00
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
2008-04-17 02:31:00 +02:00
|
|
|
FIXME("(%p)->(%p)\n", This, ppda);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSiteDebug_GetRootApplicationNode(IActiveScriptSiteDebug *iface,
|
2008-04-17 02:31:00 +02:00
|
|
|
IDebugApplicationNode **ppdanRoot)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
2008-04-17 02:31:00 +02:00
|
|
|
FIXME("(%p)->(%p)\n", This, ppdanRoot);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSiteDebug_OnScriptErrorDebug(IActiveScriptSiteDebug *iface,
|
2008-04-17 02:31:00 +02:00
|
|
|
IActiveScriptErrorDebug *pErrorDebug, BOOL *pfEnterDebugger, BOOL *pfCallOnScriptErrorWhenContinuing)
|
|
|
|
{
|
2011-01-04 01:56:46 +01:00
|
|
|
ScriptHost *This = impl_from_IActiveScriptSiteDebug(iface);
|
2008-04-17 02:31:00 +02:00
|
|
|
FIXME("(%p)->(%p %p %p)\n", This, pErrorDebug, pfEnterDebugger, pfCallOnScriptErrorWhenContinuing);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:20:29 +02:00
|
|
|
static const IActiveScriptSiteDebugVtbl ActiveScriptSiteDebugVtbl = {
|
|
|
|
ActiveScriptSiteDebug_QueryInterface,
|
|
|
|
ActiveScriptSiteDebug_AddRef,
|
|
|
|
ActiveScriptSiteDebug_Release,
|
|
|
|
ActiveScriptSiteDebug_GetDocumentContextFromPosition,
|
|
|
|
ActiveScriptSiteDebug_GetApplication,
|
|
|
|
ActiveScriptSiteDebug_GetRootApplicationNode,
|
|
|
|
ActiveScriptSiteDebug_OnScriptErrorDebug
|
2008-04-17 02:31:00 +02:00
|
|
|
};
|
|
|
|
|
2010-12-27 01:43:10 +01:00
|
|
|
static inline ScriptHost *impl_from_IServiceProvider(IServiceProvider *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptHost, IServiceProvider_iface);
|
|
|
|
}
|
2009-09-29 00:11:06 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI ASServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-27 01:43:10 +01:00
|
|
|
ScriptHost *This = impl_from_IServiceProvider(iface);
|
2011-01-04 01:56:46 +01:00
|
|
|
return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, ppv);
|
2009-09-29 00:11:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ASServiceProvider_AddRef(IServiceProvider *iface)
|
|
|
|
{
|
2010-12-27 01:43:10 +01:00
|
|
|
ScriptHost *This = impl_from_IServiceProvider(iface);
|
2011-01-04 01:56:46 +01:00
|
|
|
return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
|
2009-09-29 00:11:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ASServiceProvider_Release(IServiceProvider *iface)
|
|
|
|
{
|
2010-12-27 01:43:10 +01:00
|
|
|
ScriptHost *This = impl_from_IServiceProvider(iface);
|
2011-01-04 01:56:46 +01:00
|
|
|
return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
|
2009-09-29 00:11:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ASServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-27 01:43:10 +01:00
|
|
|
ScriptHost *This = impl_from_IServiceProvider(iface);
|
2009-09-30 23:59:28 +02:00
|
|
|
|
|
|
|
if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
|
|
|
|
TRACE("(%p)->(SID_SInternetHostSecurityManager)\n", This);
|
|
|
|
|
2012-07-11 13:51:18 +02:00
|
|
|
if(!This->window || !This->window->doc)
|
2009-09-30 23:59:28 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2012-07-11 13:51:18 +02:00
|
|
|
return IInternetHostSecurityManager_QueryInterface(&This->window->doc->IInternetHostSecurityManager_iface,
|
2011-01-03 01:01:38 +01:00
|
|
|
riid, ppv);
|
2009-09-30 23:59:28 +02:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:24:02 +01:00
|
|
|
if(IsEqualGUID(&SID_SContainerDispatch, guidService)) {
|
|
|
|
TRACE("(%p)->(SID_SContainerDispatch)\n", This);
|
|
|
|
|
|
|
|
if(!This->window || !This->window->doc)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
return IHTMLDocument2_QueryInterface(&This->window->doc->basedoc.IHTMLDocument2_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
2009-09-29 00:11:06 +02:00
|
|
|
FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IServiceProviderVtbl ASServiceProviderVtbl = {
|
|
|
|
ASServiceProvider_QueryInterface,
|
|
|
|
ASServiceProvider_AddRef,
|
|
|
|
ASServiceProvider_Release,
|
|
|
|
ASServiceProvider_QueryService
|
|
|
|
};
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
static ScriptHost *create_script_host(HTMLInnerWindow *window, const GUID *guid)
|
2008-03-25 02:10:47 +01:00
|
|
|
{
|
|
|
|
ScriptHost *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
ret = heap_alloc_zero(sizeof(*ret));
|
2012-10-19 11:57:30 +02:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2011-01-04 01:56:46 +01:00
|
|
|
ret->IActiveScriptSite_iface.lpVtbl = &ActiveScriptSiteVtbl;
|
|
|
|
ret->IActiveScriptSiteInterruptPoll_iface.lpVtbl = &ActiveScriptSiteInterruptPollVtbl;
|
|
|
|
ret->IActiveScriptSiteWindow_iface.lpVtbl = &ActiveScriptSiteWindowVtbl;
|
2012-09-26 14:37:34 +02:00
|
|
|
ret->IActiveScriptSiteUIControl_iface.lpVtbl = &ActiveScriptSiteUIControlVtbl;
|
2011-01-04 01:56:46 +01:00
|
|
|
ret->IActiveScriptSiteDebug_iface.lpVtbl = &ActiveScriptSiteDebugVtbl;
|
|
|
|
ret->IServiceProvider_iface.lpVtbl = &ASServiceProviderVtbl;
|
2008-03-25 02:10:47 +01:00
|
|
|
ret->ref = 1;
|
2009-09-09 21:30:41 +02:00
|
|
|
ret->window = window;
|
2008-03-29 18:34:49 +01:00
|
|
|
ret->script_state = SCRIPTSTATE_UNINITIALIZED;
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
ret->guid = *guid;
|
2009-09-09 21:30:41 +02:00
|
|
|
list_add_tail(&window->script_hosts, &ret->entry);
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
hres = CoCreateInstance(&ret->guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IActiveScript, (void**)&ret->script);
|
2008-03-28 19:00:59 +01:00
|
|
|
if(FAILED(hres))
|
2008-03-25 02:10:47 +01:00
|
|
|
WARN("Could not load script engine: %08x\n", hres);
|
2008-03-28 19:00:59 +01:00
|
|
|
else if(!init_script_engine(ret))
|
|
|
|
release_script_engine(ret);
|
2008-03-25 02:10:47 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-10-20 15:10:30 +02:00
|
|
|
static void dispatch_script_readystatechange_event(HTMLScriptElement *script)
|
|
|
|
{
|
|
|
|
DOMEvent *event;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2021-03-25 19:28:21 +01:00
|
|
|
if(script->readystate != READYSTATE_LOADED ||
|
|
|
|
dispex_compat_mode(&script->element.node.event_target.dispex) < COMPAT_MODE_IE10) {
|
|
|
|
hres = create_document_event(script->element.node.doc, EVENTID_READYSTATECHANGE, &event);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
dispatch_event(&script->element.node.event_target, event);
|
|
|
|
IDOMEvent_Release(&event->IDOMEvent_iface);
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 15:10:30 +02:00
|
|
|
|
2021-03-25 19:28:21 +01:00
|
|
|
if(script->readystate == READYSTATE_LOADED) {
|
|
|
|
hres = create_document_event(script->element.node.doc, EVENTID_LOAD, &event);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
dispatch_event(&script->element.node.event_target, event);
|
|
|
|
IDOMEvent_Release(&event->IDOMEvent_iface);
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 15:10:30 +02:00
|
|
|
}
|
|
|
|
|
2014-12-24 13:10:21 +01:00
|
|
|
typedef struct {
|
|
|
|
task_t header;
|
|
|
|
HTMLScriptElement *elem;
|
|
|
|
} fire_readystatechange_task_t;
|
|
|
|
|
|
|
|
static void fire_readystatechange_proc(task_t *_task)
|
|
|
|
{
|
|
|
|
fire_readystatechange_task_t *task = (fire_readystatechange_task_t*)_task;
|
|
|
|
|
|
|
|
if(!task->elem->pending_readystatechange_event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
task->elem->pending_readystatechange_event = FALSE;
|
2017-10-20 15:10:30 +02:00
|
|
|
dispatch_script_readystatechange_event(task->elem);
|
2014-12-24 13:10:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fire_readystatechange_task_destr(task_t *_task)
|
|
|
|
{
|
|
|
|
fire_readystatechange_task_t *task = (fire_readystatechange_task_t*)_task;
|
|
|
|
|
|
|
|
IHTMLScriptElement_Release(&task->elem->IHTMLScriptElement_iface);
|
|
|
|
}
|
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
static void set_script_elem_readystate(HTMLScriptElement *script_elem, READYSTATE readystate)
|
|
|
|
{
|
|
|
|
script_elem->readystate = readystate;
|
|
|
|
|
2021-03-25 19:28:21 +01:00
|
|
|
if(readystate != READYSTATE_LOADED &&
|
|
|
|
dispex_compat_mode(&script_elem->element.node.event_target.dispex) >= COMPAT_MODE_IE11)
|
|
|
|
return;
|
|
|
|
|
2014-12-24 13:10:21 +01:00
|
|
|
if(readystate != READYSTATE_INTERACTIVE) {
|
|
|
|
if(!script_elem->element.node.doc->window->parser_callback_cnt) {
|
|
|
|
fire_readystatechange_task_t *task;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(script_elem->pending_readystatechange_event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
task = heap_alloc(sizeof(*task));
|
|
|
|
if(!task)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IHTMLScriptElement_AddRef(&script_elem->IHTMLScriptElement_iface);
|
|
|
|
task->elem = script_elem;
|
|
|
|
|
|
|
|
hres = push_task(&task->header, fire_readystatechange_proc, fire_readystatechange_task_destr,
|
|
|
|
script_elem->element.node.doc->window->task_magic);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
script_elem->pending_readystatechange_event = TRUE;
|
|
|
|
}else {
|
|
|
|
script_elem->pending_readystatechange_event = FALSE;
|
2017-10-20 15:10:30 +02:00
|
|
|
dispatch_script_readystatechange_event(script_elem);
|
2014-12-24 13:10:21 +01:00
|
|
|
}
|
|
|
|
}
|
2014-10-09 16:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_elem_text(ScriptHost *script_host, HTMLScriptElement *script_elem, LPCWSTR text)
|
2008-03-29 21:39:34 +01:00
|
|
|
{
|
|
|
|
EXCEPINFO excepinfo;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(text));
|
|
|
|
|
|
|
|
VariantInit(&var);
|
|
|
|
memset(&excepinfo, 0, sizeof(excepinfo));
|
2009-10-28 22:54:48 +01:00
|
|
|
TRACE(">>>\n");
|
2020-11-24 23:29:19 +01:00
|
|
|
hres = IActiveScriptParse_ParseScriptText(script_host->parse, text, L"window", NULL, L"</SCRIPT>",
|
2008-03-29 21:39:34 +01:00
|
|
|
0, 0, SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE,
|
|
|
|
&var, &excepinfo);
|
2009-10-28 22:54:48 +01:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
TRACE("<<<\n");
|
|
|
|
else
|
|
|
|
WARN("<<< %08x\n", hres);
|
2008-03-29 21:39:34 +01:00
|
|
|
}
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
typedef struct {
|
|
|
|
BSCallback bsc;
|
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
HTMLScriptElement *script_elem;
|
|
|
|
DWORD scheme;
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
DWORD size;
|
|
|
|
char *buf;
|
|
|
|
} ScriptBSC;
|
|
|
|
|
2016-07-19 18:36:47 +02:00
|
|
|
static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret)
|
|
|
|
{
|
|
|
|
UINT cp = CP_UTF8;
|
|
|
|
WCHAR *text;
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
if(!bsc->bsc.read) {
|
2016-07-19 18:36:47 +02:00
|
|
|
text = heap_alloc(sizeof(WCHAR));
|
|
|
|
if(!text)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
*text = 0;
|
|
|
|
*ret = text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(bsc->bsc.bom) {
|
|
|
|
case BOM_UTF16:
|
2019-10-21 06:22:36 +02:00
|
|
|
if(bsc->bsc.read % sizeof(WCHAR)) {
|
2016-07-19 18:36:47 +02:00
|
|
|
FIXME("The buffer is not a valid utf16 string\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
text = heap_alloc(bsc->bsc.read+sizeof(WCHAR));
|
2016-07-19 18:36:47 +02:00
|
|
|
if(!text)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
memcpy(text, bsc->buf, bsc->bsc.read);
|
|
|
|
text[bsc->bsc.read/sizeof(WCHAR)] = 0;
|
2016-07-19 18:36:47 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* FIXME: Try to use charset from HTTP headers first */
|
2016-07-19 18:37:11 +02:00
|
|
|
cp = get_document_charset(bsc->script_elem->element.node.doc);
|
2016-07-19 18:36:47 +02:00
|
|
|
/* fall through */
|
|
|
|
case BOM_UTF8: {
|
|
|
|
DWORD len;
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
len = MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.read, NULL, 0);
|
2016-07-19 18:36:47 +02:00
|
|
|
text = heap_alloc((len+1)*sizeof(WCHAR));
|
|
|
|
if(!text)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.read, text, len);
|
2016-07-19 18:36:47 +02:00
|
|
|
text[len] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = text;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-19 18:37:11 +02:00
|
|
|
static void script_file_available(ScriptBSC *bsc)
|
|
|
|
{
|
|
|
|
HTMLScriptElement *script_elem = bsc->script_elem;
|
|
|
|
HTMLInnerWindow *window = bsc->bsc.window;
|
|
|
|
ScriptHost *script_host;
|
2016-07-19 18:40:36 +02:00
|
|
|
nsIDOMNode *parent;
|
|
|
|
nsresult nsres;
|
2016-07-19 18:37:11 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-19 18:39:47 +02:00
|
|
|
assert(window != NULL);
|
|
|
|
|
|
|
|
hres = get_binding_text(bsc, &script_elem->src_text);
|
2016-07-19 18:37:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2016-07-19 18:40:36 +02:00
|
|
|
script_host = get_elem_script_host(window, script_elem);
|
|
|
|
if(!script_host)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(window->parser_callback_cnt) {
|
|
|
|
script_queue_entry_t *queue;
|
|
|
|
|
|
|
|
TRACE("Adding to queue\n");
|
|
|
|
|
|
|
|
queue = heap_alloc(sizeof(*queue));
|
|
|
|
if(!queue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IHTMLScriptElement_AddRef(&script_elem->IHTMLScriptElement_iface);
|
|
|
|
queue->script = script_elem;
|
|
|
|
|
|
|
|
list_add_tail(&window->script_queue, &queue->entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 23:28:15 +01:00
|
|
|
nsres = nsIDOMElement_GetParentNode(script_elem->element.dom_element, &parent);
|
2016-07-19 18:40:36 +02:00
|
|
|
if(NS_FAILED(nsres) || !parent) {
|
|
|
|
TRACE("No parent, not executing\n");
|
|
|
|
script_elem->parse_on_bind = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNode_Release(parent);
|
|
|
|
|
2016-07-19 18:37:11 +02:00
|
|
|
script_host = get_elem_script_host(window, script_elem);
|
2016-07-19 18:39:47 +02:00
|
|
|
if(!script_host)
|
2016-07-19 18:37:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
script_elem->parsed = TRUE;
|
2016-07-19 18:40:36 +02:00
|
|
|
if(script_host->parse)
|
|
|
|
parse_elem_text(script_host, script_elem, script_elem->src_text);
|
2016-07-19 18:37:11 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
static inline ScriptBSC *impl_from_BSCallback(BSCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptBSC, bsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ScriptBSC_destroy(BSCallback *bsc)
|
|
|
|
{
|
|
|
|
ScriptBSC *This = impl_from_BSCallback(bsc);
|
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
if(This->script_elem) {
|
|
|
|
IHTMLScriptElement_Release(&This->script_elem->IHTMLScriptElement_iface);
|
|
|
|
This->script_elem = NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
heap_free(This->buf);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_init_bindinfo(BSCallback *bsc)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_start_binding(BSCallback *bsc)
|
|
|
|
{
|
2014-10-09 16:08:47 +02:00
|
|
|
ScriptBSC *This = impl_from_BSCallback(bsc);
|
|
|
|
|
2016-07-19 18:42:06 +02:00
|
|
|
This->script_elem->binding = &This->bsc;
|
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
/* FIXME: We should find a better to decide if 'loading' state is supposed to be used by the protocol. */
|
|
|
|
if(This->scheme == URL_SCHEME_HTTPS || This->scheme == URL_SCHEME_HTTP)
|
|
|
|
set_script_elem_readystate(This->script_elem, READYSTATE_LOADING);
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_stop_binding(BSCallback *bsc, HRESULT result)
|
|
|
|
{
|
|
|
|
ScriptBSC *This = impl_from_BSCallback(bsc);
|
|
|
|
|
2016-07-19 18:37:11 +02:00
|
|
|
if(SUCCEEDED(result) && !This->script_elem)
|
|
|
|
result = E_UNEXPECTED;
|
2014-10-09 16:08:01 +02:00
|
|
|
|
2016-07-19 18:42:06 +02:00
|
|
|
assert(FAILED(result) || This->script_elem->binding == &This->bsc);
|
|
|
|
This->script_elem->binding = NULL;
|
|
|
|
|
2016-07-19 18:40:47 +02:00
|
|
|
if(This->script_elem->readystate == READYSTATE_LOADING)
|
|
|
|
set_script_elem_readystate(This->script_elem, READYSTATE_LOADED);
|
2016-07-19 18:37:11 +02:00
|
|
|
|
2016-07-19 18:40:47 +02:00
|
|
|
if(SUCCEEDED(result)) {
|
2016-07-19 18:37:11 +02:00
|
|
|
script_file_available(This);
|
2014-10-09 16:08:47 +02:00
|
|
|
}else {
|
2014-10-09 16:08:01 +02:00
|
|
|
FIXME("binding failed %08x\n", result);
|
|
|
|
heap_free(This->buf);
|
|
|
|
This->buf = NULL;
|
|
|
|
This->size = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
IHTMLScriptElement_Release(&This->script_elem->IHTMLScriptElement_iface);
|
|
|
|
This->script_elem = NULL;
|
2014-10-09 16:08:01 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_read_data(BSCallback *bsc, IStream *stream)
|
|
|
|
{
|
|
|
|
ScriptBSC *This = impl_from_BSCallback(bsc);
|
2019-10-21 06:22:36 +02:00
|
|
|
DWORD read;
|
2014-10-09 16:08:01 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!This->buf) {
|
|
|
|
This->buf = heap_alloc(128);
|
|
|
|
if(!This->buf)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
This->size = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2019-10-21 06:22:36 +02:00
|
|
|
if(This->bsc.read >= This->size) {
|
2016-08-10 22:25:24 +02:00
|
|
|
void *new_buf;
|
|
|
|
new_buf = heap_realloc(This->buf, This->size << 1);
|
|
|
|
if(!new_buf)
|
|
|
|
return E_OUTOFMEMORY;
|
2014-10-09 16:08:01 +02:00
|
|
|
This->size <<= 1;
|
|
|
|
This->buf = new_buf;
|
|
|
|
}
|
|
|
|
|
2019-10-21 06:22:36 +02:00
|
|
|
hres = read_stream(&This->bsc, stream, This->buf+This->bsc.read, This->size-This->bsc.read, &read);
|
2014-10-09 16:08:01 +02:00
|
|
|
}while(hres == S_OK);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_on_progress(BSCallback *bsc, ULONG status_code, LPCWSTR status_text)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_on_response(BSCallback *bsc, DWORD response_code,
|
|
|
|
LPCWSTR response_headers)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ScriptBSC_beginning_transaction(BSCallback *bsc, WCHAR **additional_headers)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const BSCallbackVtbl ScriptBSCVtbl = {
|
|
|
|
ScriptBSC_destroy,
|
|
|
|
ScriptBSC_init_bindinfo,
|
|
|
|
ScriptBSC_start_binding,
|
|
|
|
ScriptBSC_stop_binding,
|
|
|
|
ScriptBSC_read_data,
|
|
|
|
ScriptBSC_on_progress,
|
|
|
|
ScriptBSC_on_response,
|
|
|
|
ScriptBSC_beginning_transaction
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-19 18:42:06 +02:00
|
|
|
HRESULT load_script(HTMLScriptElement *script_elem, const WCHAR *src, BOOL async)
|
2014-10-09 16:08:01 +02:00
|
|
|
{
|
2016-07-19 18:40:04 +02:00
|
|
|
HTMLInnerWindow *window;
|
2014-10-09 16:08:01 +02:00
|
|
|
ScriptBSC *bsc;
|
2014-10-09 16:08:31 +02:00
|
|
|
IMoniker *mon;
|
2016-07-19 18:40:04 +02:00
|
|
|
IUri *uri;
|
2014-10-09 16:08:01 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-19 18:40:04 +02:00
|
|
|
static const WCHAR wine_schemaW[] = {'w','i','n','e',':'};
|
|
|
|
|
2019-06-13 08:34:29 +02:00
|
|
|
if(lstrlenW(src) > ARRAY_SIZE(wine_schemaW) && !memcmp(src, wine_schemaW, sizeof(wine_schemaW)))
|
2018-08-23 23:31:15 +02:00
|
|
|
src += ARRAY_SIZE(wine_schemaW);
|
2016-07-19 18:40:04 +02:00
|
|
|
|
2016-07-19 18:42:06 +02:00
|
|
|
TRACE("(%p %s %x)\n", script_elem, debugstr_w(src), async);
|
2016-07-19 18:40:04 +02:00
|
|
|
|
|
|
|
if(!script_elem->element.node.doc || !(window = script_elem->element.node.doc->window)) {
|
|
|
|
ERR("no window\n");
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = create_uri(src, 0, &uri);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2014-10-09 16:08:31 +02:00
|
|
|
hres = CreateURLMonikerEx2(NULL, uri, &mon, URL_MK_UNIFORM);
|
2016-11-10 08:44:37 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
IUri_Release(uri);
|
2014-10-09 16:08:31 +02:00
|
|
|
return hres;
|
2016-11-10 08:44:37 +01:00
|
|
|
}
|
2014-10-09 16:08:31 +02:00
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
bsc = heap_alloc_zero(sizeof(*bsc));
|
2014-10-09 16:08:31 +02:00
|
|
|
if(!bsc) {
|
|
|
|
IMoniker_Release(mon);
|
2016-11-10 08:44:37 +01:00
|
|
|
IUri_Release(uri);
|
2014-10-09 16:08:01 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2014-10-09 16:08:31 +02:00
|
|
|
}
|
2014-10-09 16:08:01 +02:00
|
|
|
|
2016-07-19 18:42:06 +02:00
|
|
|
init_bscallback(&bsc->bsc, &ScriptBSCVtbl, mon, async ? BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA : 0);
|
2014-10-09 16:08:31 +02:00
|
|
|
IMoniker_Release(mon);
|
2014-10-09 16:08:01 +02:00
|
|
|
|
2014-10-09 16:08:47 +02:00
|
|
|
hres = IUri_GetScheme(uri, &bsc->scheme);
|
2016-11-10 08:44:37 +01:00
|
|
|
IUri_Release(uri);
|
2014-10-09 16:08:47 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
bsc->scheme = URL_SCHEME_UNKNOWN;
|
|
|
|
|
|
|
|
IHTMLScriptElement_AddRef(&script_elem->IHTMLScriptElement_iface);
|
|
|
|
bsc->script_elem = script_elem;
|
|
|
|
|
2014-10-09 16:08:01 +02:00
|
|
|
hres = start_binding(window, &bsc->bsc, NULL);
|
|
|
|
|
|
|
|
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
|
2016-07-19 18:36:47 +02:00
|
|
|
return hres;
|
2014-10-09 16:08:01 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 15:45:40 +02:00
|
|
|
static void parse_inline_script(ScriptHost *script_host, HTMLScriptElement *script_elem)
|
2008-03-29 21:39:34 +01:00
|
|
|
{
|
|
|
|
const PRUnichar *text;
|
|
|
|
nsAString text_str;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsAString_Init(&text_str, NULL);
|
2012-10-02 15:45:40 +02:00
|
|
|
nsres = nsIDOMHTMLScriptElement_GetText(script_elem->nsscript, &text_str);
|
|
|
|
nsAString_GetData(&text_str, &text);
|
2008-03-29 21:39:34 +01:00
|
|
|
|
2016-07-19 18:41:06 +02:00
|
|
|
set_script_elem_readystate(script_elem, READYSTATE_INTERACTIVE);
|
|
|
|
|
2012-10-02 15:45:40 +02:00
|
|
|
if(NS_FAILED(nsres)) {
|
2008-03-29 21:39:34 +01:00
|
|
|
ERR("GetText failed: %08x\n", nsres);
|
2012-10-02 15:45:40 +02:00
|
|
|
}else if(*text) {
|
2014-10-09 16:08:47 +02:00
|
|
|
parse_elem_text(script_host, script_elem, text);
|
2008-03-29 21:39:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Finish(&text_str);
|
|
|
|
}
|
|
|
|
|
2016-07-19 18:40:36 +02:00
|
|
|
static BOOL parse_script_elem(ScriptHost *script_host, HTMLScriptElement *script_elem)
|
2008-03-29 21:39:34 +01:00
|
|
|
{
|
2012-10-02 15:44:56 +02:00
|
|
|
nsAString src_str, event_str;
|
2016-07-19 18:40:36 +02:00
|
|
|
BOOL is_complete = FALSE;
|
2008-03-29 21:39:34 +01:00
|
|
|
const PRUnichar *src;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2012-10-02 15:44:56 +02:00
|
|
|
nsAString_Init(&event_str, NULL);
|
2012-10-02 15:45:40 +02:00
|
|
|
nsres = nsIDOMHTMLScriptElement_GetEvent(script_elem->nsscript, &event_str);
|
2012-10-02 15:44:56 +02:00
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *event;
|
2008-03-29 21:39:34 +01:00
|
|
|
|
2012-10-02 15:44:56 +02:00
|
|
|
nsAString_GetData(&event_str, &event);
|
|
|
|
if(*event) {
|
|
|
|
TRACE("deferring event %s script evaluation\n", debugstr_w(event));
|
|
|
|
nsAString_Finish(&event_str);
|
2016-07-19 18:40:36 +02:00
|
|
|
return FALSE;
|
2012-10-02 15:44:56 +02:00
|
|
|
}
|
|
|
|
}else {
|
2014-05-27 11:28:56 +02:00
|
|
|
ERR("GetEvent failed: %08x\n", nsres);
|
2012-10-02 15:44:56 +02:00
|
|
|
}
|
|
|
|
nsAString_Finish(&event_str);
|
|
|
|
|
|
|
|
nsAString_Init(&src_str, NULL);
|
2012-10-02 15:45:40 +02:00
|
|
|
nsres = nsIDOMHTMLScriptElement_GetSrc(script_elem->nsscript, &src_str);
|
2008-03-29 21:39:34 +01:00
|
|
|
nsAString_GetData(&src_str, &src);
|
|
|
|
|
2012-10-02 15:45:40 +02:00
|
|
|
if(NS_FAILED(nsres)) {
|
2008-03-29 21:39:34 +01:00
|
|
|
ERR("GetSrc failed: %08x\n", nsres);
|
2012-10-02 15:45:40 +02:00
|
|
|
}else if(*src) {
|
2016-07-19 18:42:06 +02:00
|
|
|
load_script(script_elem, src, FALSE);
|
2016-07-19 18:40:36 +02:00
|
|
|
is_complete = script_elem->parsed;
|
2012-10-02 15:45:40 +02:00
|
|
|
}else {
|
|
|
|
parse_inline_script(script_host, script_elem);
|
2016-07-19 18:40:36 +02:00
|
|
|
is_complete = TRUE;
|
2012-10-02 15:45:40 +02:00
|
|
|
}
|
2008-03-29 21:39:34 +01:00
|
|
|
|
|
|
|
nsAString_Finish(&src_str);
|
2014-10-09 16:08:47 +02:00
|
|
|
|
2016-07-19 18:40:36 +02:00
|
|
|
return is_complete;
|
2008-03-29 21:39:34 +01:00
|
|
|
}
|
|
|
|
|
2012-09-10 10:34:52 +02:00
|
|
|
static GUID get_default_script_guid(HTMLInnerWindow *window)
|
|
|
|
{
|
|
|
|
/* If not specified, we should use very first script host that was created for the page (or JScript if none) */
|
|
|
|
return list_empty(&window->script_hosts)
|
|
|
|
? CLSID_JScript
|
|
|
|
: LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry)->guid;
|
|
|
|
}
|
|
|
|
|
2008-03-25 02:10:47 +01:00
|
|
|
static BOOL get_guid_from_type(LPCWSTR type, GUID *guid)
|
|
|
|
{
|
|
|
|
/* FIXME: Handle more types */
|
2020-11-24 23:29:19 +01:00
|
|
|
if(!wcsicmp(type, L"text/javascript") || !wcsicmp(type, L"text/jscript")) {
|
2008-03-25 02:10:47 +01:00
|
|
|
*guid = CLSID_JScript;
|
2020-11-24 23:29:19 +01:00
|
|
|
}else if(!wcsicmp(type, L"text/vbscript")) {
|
2011-09-02 12:03:17 +02:00
|
|
|
*guid = CLSID_VBScript;
|
2008-03-25 02:10:47 +01:00
|
|
|
}else {
|
|
|
|
FIXME("Unknown type %s\n", debugstr_w(type));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_guid_from_language(LPCWSTR type, GUID *guid)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CLSIDFromProgID(type, guid);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: Check CATID_ActiveScriptParse */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-13 11:03:27 +02:00
|
|
|
static BOOL get_script_guid(HTMLInnerWindow *window, nsIDOMHTMLScriptElement *nsscript, GUID *guid)
|
2008-03-25 02:10:47 +01:00
|
|
|
{
|
2018-02-12 01:28:00 +01:00
|
|
|
nsIDOMElement *nselem;
|
2014-05-27 11:28:56 +02:00
|
|
|
const PRUnichar *language;
|
|
|
|
nsAString val_str;
|
2008-03-25 02:10:47 +01:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsAString_Init(&val_str, NULL);
|
|
|
|
|
|
|
|
nsres = nsIDOMHTMLScriptElement_GetType(nsscript, &val_str);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *type;
|
|
|
|
|
|
|
|
nsAString_GetData(&val_str, &type);
|
|
|
|
if(*type) {
|
|
|
|
ret = get_guid_from_type(type, guid);
|
|
|
|
nsAString_Finish(&val_str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
ERR("GetType failed: %08x\n", nsres);
|
|
|
|
}
|
|
|
|
|
2018-02-12 01:28:00 +01:00
|
|
|
nsres = nsIDOMHTMLScriptElement_QueryInterface(nsscript, &IID_nsIDOMElement, (void**)&nselem);
|
2014-10-02 11:56:18 +02:00
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
2020-11-24 00:49:06 +01:00
|
|
|
nsres = get_elem_attr_value(nselem, L"language", &val_str, &language);
|
2018-02-12 01:28:00 +01:00
|
|
|
nsIDOMElement_Release(nselem);
|
2008-03-25 02:10:47 +01:00
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
if(*language) {
|
|
|
|
ret = get_guid_from_language(language, guid);
|
|
|
|
}else {
|
2012-09-10 10:34:52 +02:00
|
|
|
*guid = get_default_script_guid(window);
|
2008-03-25 02:10:47 +01:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
2014-05-27 11:28:56 +02:00
|
|
|
nsAString_Finish(&val_str);
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
static ScriptHost *get_script_host(HTMLInnerWindow *window, const GUID *guid)
|
2008-03-25 02:10:47 +01:00
|
|
|
{
|
|
|
|
ScriptHost *iter;
|
|
|
|
|
2009-09-09 21:30:41 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
|
2008-04-18 20:16:35 +02:00
|
|
|
if(IsEqualGUID(guid, &iter->guid))
|
2008-03-25 02:10:47 +01:00
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2009-09-09 21:30:41 +02:00
|
|
|
return create_script_host(window, guid);
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
2012-10-02 15:46:20 +02:00
|
|
|
static ScriptHost *get_elem_script_host(HTMLInnerWindow *window, HTMLScriptElement *script_elem)
|
2008-03-25 02:10:47 +01:00
|
|
|
{
|
2008-04-18 20:16:35 +02:00
|
|
|
GUID guid;
|
2008-03-29 21:39:34 +01:00
|
|
|
|
2012-10-02 15:45:40 +02:00
|
|
|
if(!get_script_guid(window, script_elem->nsscript, &guid)) {
|
2008-04-18 20:16:35 +02:00
|
|
|
WARN("Could not find script GUID\n");
|
2012-10-02 15:46:20 +02:00
|
|
|
return NULL;
|
2008-04-18 20:16:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-12 16:09:57 +01:00
|
|
|
if(IsEqualGUID(&CLSID_JScript, &guid) && (!window->doc->browser || window->doc->browser->script_mode != SCRIPTMODE_ACTIVESCRIPT)) {
|
2011-07-23 12:51:06 +02:00
|
|
|
TRACE("Ignoring JScript\n");
|
2012-10-02 15:46:20 +02:00
|
|
|
return NULL;
|
2011-07-23 12:51:06 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 15:46:20 +02:00
|
|
|
return get_script_host(window, &guid);
|
|
|
|
}
|
|
|
|
|
2016-07-19 18:41:06 +02:00
|
|
|
void doc_insert_script(HTMLInnerWindow *window, HTMLScriptElement *script_elem, BOOL from_parser)
|
2012-10-02 15:46:20 +02:00
|
|
|
{
|
|
|
|
ScriptHost *script_host;
|
2016-07-19 18:40:36 +02:00
|
|
|
BOOL is_complete = FALSE;
|
2012-10-02 15:46:20 +02:00
|
|
|
|
|
|
|
script_host = get_elem_script_host(window, script_elem);
|
2008-03-29 21:39:34 +01:00
|
|
|
if(!script_host)
|
|
|
|
return;
|
|
|
|
|
2016-07-19 18:40:36 +02:00
|
|
|
if(script_host->parse) {
|
|
|
|
if(script_elem->src_text) {
|
2016-07-19 18:41:06 +02:00
|
|
|
if(from_parser)
|
|
|
|
set_script_elem_readystate(script_elem, READYSTATE_INTERACTIVE);
|
2016-07-19 18:40:36 +02:00
|
|
|
script_elem->parsed = TRUE;
|
|
|
|
parse_elem_text(script_host, script_elem, script_elem->src_text);
|
|
|
|
is_complete = TRUE;
|
2016-07-19 18:42:06 +02:00
|
|
|
}else if(!script_elem->binding) {
|
2016-07-19 18:40:36 +02:00
|
|
|
is_complete = parse_script_elem(script_host, script_elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_complete)
|
|
|
|
set_script_elem_readystate(script_elem, READYSTATE_COMPLETE);
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
IDispatch *script_parse_event(HTMLInnerWindow *window, LPCWSTR text)
|
2008-04-18 20:16:35 +02:00
|
|
|
{
|
|
|
|
ScriptHost *script_host;
|
2012-08-13 11:03:27 +02:00
|
|
|
GUID guid;
|
2008-04-18 20:16:35 +02:00
|
|
|
const WCHAR *ptr;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-08-13 11:03:27 +02:00
|
|
|
TRACE("%s\n", debugstr_w(text));
|
|
|
|
|
2019-06-13 08:34:29 +02:00
|
|
|
for(ptr = text; iswalnum(*ptr); ptr++);
|
2008-04-18 20:16:35 +02:00
|
|
|
if(*ptr == ':') {
|
|
|
|
LPWSTR language;
|
|
|
|
BOOL b;
|
|
|
|
|
|
|
|
language = heap_alloc((ptr-text+1)*sizeof(WCHAR));
|
2012-10-19 11:57:30 +02:00
|
|
|
if(!language)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-18 20:16:35 +02:00
|
|
|
memcpy(language, text, (ptr-text)*sizeof(WCHAR));
|
|
|
|
language[ptr-text] = 0;
|
|
|
|
|
|
|
|
b = get_guid_from_language(language, &guid);
|
|
|
|
|
|
|
|
heap_free(language);
|
|
|
|
|
|
|
|
if(!b) {
|
|
|
|
WARN("Could not find language\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
}else {
|
|
|
|
ptr = text;
|
2012-09-10 10:34:52 +02:00
|
|
|
guid = get_default_script_guid(window);
|
2008-04-18 20:16:35 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
if(IsEqualGUID(&CLSID_JScript, &guid)
|
2019-03-12 16:09:57 +01:00
|
|
|
&& (!window->doc->browser || window->doc->browser->script_mode != SCRIPTMODE_ACTIVESCRIPT)) {
|
2011-07-23 12:51:06 +02:00
|
|
|
TRACE("Ignoring JScript\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-16 22:08:20 +02:00
|
|
|
script_host = get_script_host(window, &guid);
|
2008-04-18 20:16:35 +02:00
|
|
|
if(!script_host || !script_host->parse_proc)
|
|
|
|
return NULL;
|
|
|
|
|
2020-11-24 23:29:19 +01:00
|
|
|
hres = IActiveScriptParseProcedure2_ParseProcedureText(script_host->parse_proc, ptr, NULL, L"",
|
|
|
|
NULL, NULL, L"\"", 0 /* FIXME */, 0,
|
2008-04-18 20:16:35 +02:00
|
|
|
SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("ParseProcedureText failed: %08x\n", hres);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("ret %p\n", disp);
|
|
|
|
return disp;
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
HRESULT exec_script(HTMLInnerWindow *window, const WCHAR *code, const WCHAR *lang, VARIANT *ret)
|
2010-11-09 13:36:24 +01:00
|
|
|
{
|
|
|
|
ScriptHost *script_host;
|
|
|
|
EXCEPINFO ei;
|
|
|
|
GUID guid;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!get_guid_from_language(lang, &guid)) {
|
|
|
|
WARN("Could not find script GUID\n");
|
|
|
|
return CO_E_CLASSSTRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
script_host = get_script_host(window, &guid);
|
|
|
|
if(!script_host) {
|
|
|
|
FIXME("No script host\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!script_host->parse) {
|
|
|
|
FIXME("script_host->parse == NULL\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
TRACE(">>>\n");
|
2020-11-24 23:29:19 +01:00
|
|
|
hres = IActiveScriptParse_ParseScriptText(script_host->parse, code, NULL, NULL, L"\"", 0, 0, SCRIPTTEXT_ISVISIBLE, ret, &ei);
|
2010-11-09 13:36:24 +01:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
TRACE("<<<\n");
|
|
|
|
else
|
|
|
|
WARN("<<< %08x\n", hres);
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2009-09-09 21:31:32 +02:00
|
|
|
IDispatch *get_script_disp(ScriptHost *script_host)
|
|
|
|
{
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!script_host->script)
|
|
|
|
return NULL;
|
|
|
|
|
2020-11-24 23:29:19 +01:00
|
|
|
hres = IActiveScript_GetScriptDispatch(script_host->script, L"window", &disp);
|
2009-09-09 21:31:32 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return disp;
|
|
|
|
}
|
|
|
|
|
2015-05-14 13:25:09 +02:00
|
|
|
static EventTarget *find_event_target(HTMLDocumentNode *doc, HTMLScriptElement *script_elem)
|
2012-10-02 15:46:20 +02:00
|
|
|
{
|
2015-05-14 13:25:09 +02:00
|
|
|
EventTarget *event_target = NULL;
|
2012-10-02 15:46:20 +02:00
|
|
|
const PRUnichar *target_id;
|
|
|
|
nsAString target_id_str;
|
|
|
|
nsresult nsres;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
nsAString_Init(&target_id_str, NULL);
|
|
|
|
nsres = nsIDOMHTMLScriptElement_GetHtmlFor(script_elem->nsscript, &target_id_str);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("GetScriptFor failed: %08x\n", nsres);
|
|
|
|
nsAString_Finish(&target_id_str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_GetData(&target_id_str, &target_id);
|
2013-10-01 15:43:52 +02:00
|
|
|
if(!*target_id) {
|
|
|
|
FIXME("Empty for attribute\n");
|
2020-11-24 23:29:19 +01:00
|
|
|
}else if(!wcscmp(target_id, L"document")) {
|
2015-05-14 13:25:09 +02:00
|
|
|
event_target = &doc->node.event_target;
|
2015-04-17 16:35:24 +02:00
|
|
|
htmldoc_addref(&doc->basedoc);
|
2020-11-24 23:29:19 +01:00
|
|
|
}else if(!wcscmp(target_id, L"window")) {
|
2015-04-17 16:35:24 +02:00
|
|
|
if(doc->window) {
|
2015-05-14 13:25:09 +02:00
|
|
|
event_target = &doc->window->event_target;
|
|
|
|
IDispatchEx_AddRef(&event_target->dispex.IDispatchEx_iface);
|
2015-04-17 16:35:24 +02:00
|
|
|
}
|
2012-10-02 15:46:20 +02:00
|
|
|
}else {
|
2013-10-01 15:43:52 +02:00
|
|
|
HTMLElement *target_elem;
|
|
|
|
|
|
|
|
hres = get_doc_elem_by_id(doc, target_id, &target_elem);
|
|
|
|
if(SUCCEEDED(hres) && target_elem) {
|
2015-05-14 13:25:09 +02:00
|
|
|
event_target = &target_elem->node.event_target;
|
2013-10-01 15:43:52 +02:00
|
|
|
}
|
2012-10-02 15:46:20 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 13:25:09 +02:00
|
|
|
nsAString_Finish(&target_id_str);
|
|
|
|
return event_target;
|
2012-10-02 15:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL parse_event_str(WCHAR *event, const WCHAR **args)
|
|
|
|
{
|
|
|
|
WCHAR *ptr;
|
|
|
|
|
2012-10-03 17:26:28 +02:00
|
|
|
TRACE("%s\n", debugstr_w(event));
|
|
|
|
|
2019-06-13 08:34:29 +02:00
|
|
|
for(ptr = event; iswalnum(*ptr); ptr++);
|
2012-10-02 15:46:20 +02:00
|
|
|
if(!*ptr) {
|
|
|
|
*args = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ptr != '(')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*ptr++ = 0;
|
|
|
|
*args = ptr;
|
2019-06-13 08:34:29 +02:00
|
|
|
while(iswalnum(*ptr) || iswspace(*ptr) || *ptr == ',')
|
2012-10-02 15:46:20 +02:00
|
|
|
ptr++;
|
|
|
|
|
2012-10-03 17:26:28 +02:00
|
|
|
if(*ptr != ')')
|
2012-10-02 15:46:20 +02:00
|
|
|
return FALSE;
|
2012-10-03 17:26:28 +02:00
|
|
|
|
2012-10-02 15:46:20 +02:00
|
|
|
*ptr++ = 0;
|
|
|
|
return !*ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IDispatch *parse_event_elem(HTMLDocumentNode *doc, HTMLScriptElement *script_elem, WCHAR **ret_event)
|
|
|
|
{
|
|
|
|
ScriptHost *script_host;
|
|
|
|
WCHAR *event = NULL;
|
|
|
|
const WCHAR *args;
|
|
|
|
nsAString nsstr;
|
|
|
|
IDispatch *disp;
|
|
|
|
nsresult nsres;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(script_elem->parsed)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
script_host = get_elem_script_host(doc->window, script_elem);
|
|
|
|
if(!script_host || !script_host->parse_proc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nsAString_Init(&nsstr, NULL);
|
|
|
|
nsres = nsIDOMHTMLScriptElement_GetEvent(script_elem->nsscript, &nsstr);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *event_val;
|
|
|
|
|
|
|
|
nsAString_GetData(&nsstr, &event_val);
|
|
|
|
event = heap_strdupW(event_val);
|
|
|
|
}
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(!event)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!parse_event_str(event, &args)) {
|
|
|
|
WARN("parsing %s failed\n", debugstr_w(event));
|
|
|
|
heap_free(event);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Init(&nsstr, NULL);
|
|
|
|
nsres = nsIDOMHTMLScriptElement_GetText(script_elem->nsscript, &nsstr);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *text;
|
|
|
|
|
|
|
|
nsAString_GetData(&nsstr, &text);
|
2012-10-04 14:59:25 +02:00
|
|
|
hres = IActiveScriptParseProcedure2_ParseProcedureText(script_host->parse_proc, text, args,
|
2020-11-24 23:29:19 +01:00
|
|
|
L"", NULL, NULL, L"</SCRIPT>", 0, 0,
|
2012-10-02 15:46:20 +02:00
|
|
|
SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
|
|
|
|
if(FAILED(hres))
|
|
|
|
disp = NULL;
|
|
|
|
}else {
|
|
|
|
ERR("GetText failed: %08x\n", nsres);
|
|
|
|
disp = NULL;
|
|
|
|
}
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(!disp) {
|
|
|
|
heap_free(event);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_event = event;
|
|
|
|
return disp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bind_event_scripts(HTMLDocumentNode *doc)
|
|
|
|
{
|
|
|
|
HTMLPluginContainer *plugin_container;
|
|
|
|
nsIDOMHTMLScriptElement *nsscript;
|
|
|
|
HTMLScriptElement *script_elem;
|
2015-05-14 13:25:09 +02:00
|
|
|
EventTarget *event_target;
|
2012-10-02 15:46:20 +02:00
|
|
|
nsIDOMNodeList *node_list;
|
|
|
|
nsIDOMNode *script_node;
|
|
|
|
nsAString selector_str;
|
|
|
|
IDispatch *event_disp;
|
2013-01-23 18:44:42 +01:00
|
|
|
UINT32 length, i;
|
2012-10-02 15:46:20 +02:00
|
|
|
WCHAR *event;
|
|
|
|
nsresult nsres;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("%p\n", doc);
|
|
|
|
|
|
|
|
if(!doc->nsdoc)
|
|
|
|
return;
|
|
|
|
|
2020-11-24 00:49:06 +01:00
|
|
|
nsAString_InitDepend(&selector_str, L"script[event]");
|
2014-11-03 12:39:59 +01:00
|
|
|
nsres = nsIDOMHTMLDocument_QuerySelectorAll(doc->nsdoc, &selector_str, &node_list);
|
2012-10-02 15:46:20 +02:00
|
|
|
nsAString_Finish(&selector_str);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("QuerySelectorAll failed: %08x\n", nsres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!node_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsres = nsIDOMNodeList_GetLength(node_list, &length);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
for(i=0; i < length; i++) {
|
|
|
|
nsres = nsIDOMNodeList_Item(node_list, i, &script_node);
|
|
|
|
if(NS_FAILED(nsres) || !script_node) {
|
|
|
|
ERR("Item(%d) failed: %08x\n", i, nsres);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_QueryInterface(script_node, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
nsIDOMNode_Release(script_node);
|
|
|
|
|
2018-02-19 14:49:39 +01:00
|
|
|
hres = script_elem_from_nsscript(nsscript, &script_elem);
|
2012-10-02 15:46:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
event_disp = parse_event_elem(doc, script_elem, &event);
|
|
|
|
if(event_disp) {
|
2015-05-14 13:25:09 +02:00
|
|
|
event_target = find_event_target(doc, script_elem);
|
2012-10-02 15:46:20 +02:00
|
|
|
if(event_target) {
|
2015-05-14 13:25:09 +02:00
|
|
|
hres = IDispatchEx_QueryInterface(&event_target->dispex.IDispatchEx_iface, &IID_HTMLPluginContainer,
|
|
|
|
(void**)&plugin_container);
|
2012-10-19 11:57:30 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2012-10-03 17:26:28 +02:00
|
|
|
bind_activex_event(doc, plugin_container, event, event_disp);
|
2012-10-02 15:46:20 +02:00
|
|
|
else
|
2015-05-14 13:25:09 +02:00
|
|
|
bind_target_event(doc, event_target, event, event_disp);
|
2012-10-02 15:46:20 +02:00
|
|
|
|
2015-05-14 13:25:09 +02:00
|
|
|
IDispatchEx_Release(&event_target->dispex.IDispatchEx_iface);
|
|
|
|
if(plugin_container)
|
|
|
|
node_release(&plugin_container->element.node);
|
2012-10-02 15:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(event);
|
|
|
|
IDispatch_Release(event_disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNodeList_Release(node_list);
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
BOOL find_global_prop(HTMLInnerWindow *window, BSTR name, DWORD flags, ScriptHost **ret_host, DISPID *ret_id)
|
2009-09-09 21:31:32 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
IDispatch *disp;
|
|
|
|
ScriptHost *iter;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
|
|
|
|
disp = get_script_disp(iter);
|
|
|
|
if(!disp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2009-12-06 22:10:07 +01:00
|
|
|
hres = IDispatchEx_GetDispID(dispex, name, flags & (~fdexNameEnsure), ret_id);
|
2009-09-09 21:31:32 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
FIXME("No IDispatchEx\n");
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
*ret_host = iter;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-24 18:19:46 +02:00
|
|
|
static BOOL is_jscript_available(void)
|
|
|
|
{
|
|
|
|
static BOOL available, checked;
|
|
|
|
|
|
|
|
if(!checked) {
|
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hres = CoGetClassObject(&CLSID_JScript, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
available = TRUE;
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}else {
|
|
|
|
available = FALSE;
|
|
|
|
}
|
|
|
|
checked = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return available;
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:09:57 +01:00
|
|
|
static BOOL use_gecko_script(IUri *uri)
|
|
|
|
{
|
|
|
|
BSTR display_uri;
|
|
|
|
DWORD zone;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IUri_GetDisplayUri(uri, &display_uri);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hres = IInternetSecurityManager_MapUrlToZone(get_security_manager(), display_uri, &zone, 0);
|
|
|
|
SysFreeString(display_uri);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not map %s to zone: %08x\n", debugstr_w(display_uri), hres);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("zone %d\n", zone);
|
|
|
|
return zone == URLZONE_UNTRUSTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_browser_script_mode(GeckoBrowser *browser, IUri *uri)
|
2008-09-24 18:19:46 +02:00
|
|
|
{
|
|
|
|
nsIWebBrowserSetup *setup;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2019-03-12 16:09:57 +01:00
|
|
|
if(!is_jscript_available()) {
|
2008-09-24 18:19:46 +02:00
|
|
|
TRACE("jscript.dll not available\n");
|
2019-03-12 16:09:57 +01:00
|
|
|
browser->script_mode = SCRIPTMODE_GECKO;
|
2008-09-24 18:19:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:09:57 +01:00
|
|
|
browser->script_mode = use_gecko_script(uri) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT;
|
2008-09-24 18:19:46 +02:00
|
|
|
|
2019-03-12 16:09:57 +01:00
|
|
|
nsres = nsIWebBrowser_QueryInterface(browser->webbrowser, &IID_nsIWebBrowserSetup, (void**)&setup);
|
2008-09-24 18:19:46 +02:00
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT,
|
2019-03-12 16:09:57 +01:00
|
|
|
browser->script_mode == SCRIPTMODE_GECKO);
|
2012-10-09 11:26:18 +02:00
|
|
|
|
|
|
|
if(NS_SUCCEEDED(nsres))
|
|
|
|
nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_DISABLE_NOSCRIPT, TRUE);
|
|
|
|
|
2008-09-24 18:19:46 +02:00
|
|
|
nsIWebBrowserSetup_Release(setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("JavaScript setup failed: %08x\n", nsres);
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:06:09 +02:00
|
|
|
void release_script_hosts(HTMLInnerWindow *window)
|
2008-03-25 02:10:47 +01:00
|
|
|
{
|
2012-10-16 17:08:25 +02:00
|
|
|
script_queue_entry_t *queue_iter;
|
2008-03-25 02:10:47 +01:00
|
|
|
ScriptHost *iter;
|
|
|
|
|
2012-10-16 17:08:25 +02:00
|
|
|
while(!list_empty(&window->script_queue)) {
|
|
|
|
queue_iter = LIST_ENTRY(list_head(&window->script_queue), script_queue_entry_t, entry);
|
|
|
|
|
|
|
|
list_remove(&queue_iter->entry);
|
|
|
|
IHTMLScriptElement_Release(&queue_iter->script->IHTMLScriptElement_iface);
|
|
|
|
heap_free(queue_iter);
|
|
|
|
}
|
|
|
|
|
2009-09-09 21:30:41 +02:00
|
|
|
while(!list_empty(&window->script_hosts)) {
|
|
|
|
iter = LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry);
|
2008-03-27 19:08:07 +01:00
|
|
|
|
2008-03-28 19:00:59 +01:00
|
|
|
release_script_engine(iter);
|
2008-03-27 19:08:07 +01:00
|
|
|
list_remove(&iter->entry);
|
2009-09-09 21:30:41 +02:00
|
|
|
iter->window = NULL;
|
2012-07-26 11:37:48 +02:00
|
|
|
IActiveScriptSite_Release(&iter->IActiveScriptSite_iface);
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
}
|