ReactOS 0.4.16-dev-297-gc569aee
htmlscript.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  HTMLScriptElement
 
struct  script_queue_entry_t
 

Functions

HRESULT script_elem_from_nsscript (HTMLDocumentNode *, nsIDOMHTMLScriptElement *, HTMLScriptElement **) DECLSPEC_HIDDEN
 
void bind_event_scripts (HTMLDocumentNode *) DECLSPEC_HIDDEN
 
void release_script_hosts (HTMLInnerWindow *) DECLSPEC_HIDDEN
 
void connect_scripts (HTMLInnerWindow *) DECLSPEC_HIDDEN
 
void doc_insert_script (HTMLInnerWindow *, HTMLScriptElement *) DECLSPEC_HIDDEN
 
IDispatchscript_parse_event (HTMLInnerWindow *, LPCWSTR) DECLSPEC_HIDDEN
 
HRESULT exec_script (HTMLInnerWindow *, const WCHAR *, const WCHAR *, VARIANT *) DECLSPEC_HIDDEN
 
void set_script_mode (HTMLOuterWindow *, SCRIPTMODE) DECLSPEC_HIDDEN
 
BOOL find_global_prop (HTMLInnerWindow *, BSTR, DWORD, ScriptHost **, DISPID *) DECLSPEC_HIDDEN
 
IDispatchget_script_disp (ScriptHost *) DECLSPEC_HIDDEN
 

Function Documentation

◆ bind_event_scripts()

void bind_event_scripts ( HTMLDocumentNode doc)

Definition at line 1423 of file script.c.

1424{
1425 HTMLPluginContainer *plugin_container;
1426 nsIDOMHTMLScriptElement *nsscript;
1427 HTMLScriptElement *script_elem;
1428 EventTarget *event_target;
1429 nsIDOMNodeList *node_list;
1430 nsIDOMNode *script_node;
1431 nsAString selector_str;
1432 IDispatch *event_disp;
1433 UINT32 length, i;
1434 WCHAR *event;
1435 nsresult nsres;
1436 HRESULT hres;
1437
1438 static const PRUnichar selectorW[] = {'s','c','r','i','p','t','[','e','v','e','n','t',']',0};
1439
1440 TRACE("%p\n", doc);
1441
1442 if(!doc->nsdoc)
1443 return;
1444
1445 nsAString_InitDepend(&selector_str, selectorW);
1446 nsres = nsIDOMHTMLDocument_QuerySelectorAll(doc->nsdoc, &selector_str, &node_list);
1447 nsAString_Finish(&selector_str);
1448 if(NS_FAILED(nsres)) {
1449 ERR("QuerySelectorAll failed: %08x\n", nsres);
1450 return;
1451 }
1452
1453 if(!node_list)
1454 return;
1455
1456 nsres = nsIDOMNodeList_GetLength(node_list, &length);
1457 assert(nsres == NS_OK);
1458
1459 for(i=0; i < length; i++) {
1460 nsres = nsIDOMNodeList_Item(node_list, i, &script_node);
1461 if(NS_FAILED(nsres) || !script_node) {
1462 ERR("Item(%d) failed: %08x\n", i, nsres);
1463 continue;
1464 }
1465
1466 nsres = nsIDOMNode_QueryInterface(script_node, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
1467 assert(nsres == NS_OK);
1468 nsIDOMNode_Release(script_node);
1469
1470 hres = script_elem_from_nsscript(doc, nsscript, &script_elem);
1471 if(FAILED(hres))
1472 continue;
1473
1474 event_disp = parse_event_elem(doc, script_elem, &event);
1475 if(event_disp) {
1476 event_target = find_event_target(doc, script_elem);
1477 if(event_target) {
1478 hres = IDispatchEx_QueryInterface(&event_target->dispex.IDispatchEx_iface, &IID_HTMLPluginContainer,
1479 (void**)&plugin_container);
1480 if(SUCCEEDED(hres))
1481 bind_activex_event(doc, plugin_container, event, event_disp);
1482 else
1483 bind_target_event(doc, event_target, event, event_disp);
1484
1485 IDispatchEx_Release(&event_target->dispex.IDispatchEx_iface);
1486 if(plugin_container)
1487 node_release(&plugin_container->element.node);
1488 }
1489
1491 IDispatch_Release(event_disp);
1492 }
1493
1494 IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface);
1495 }
1496
1497 nsIDOMNodeList_Release(node_list);
1498}
unsigned int UINT32
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define ERR(fmt,...)
Definition: precomp.h:57
static IDispatch * parse_event_elem(HTMLDocumentNode *doc, HTMLScriptElement *script_elem, WCHAR **ret_event)
Definition: script.c:1363
static EventTarget * find_event_target(HTMLDocumentNode *doc, HTMLScriptElement *script_elem)
Definition: script.c:1296
#define assert(x)
Definition: debug.h:53
struct _cl_event * event
Definition: glext.h:7739
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void bind_target_event(HTMLDocumentNode *doc, EventTarget *event_target, const WCHAR *event, IDispatch *disp)
Definition: htmlevent.c:1534
HRESULT script_elem_from_nsscript(HTMLDocumentNode *doc, nsIDOMHTMLScriptElement *nsscript, HTMLScriptElement **ret)
Definition: htmlscript.c:425
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hres
Definition: protocol.c:465
#define NS_OK
void nsAString_Finish(nsAString *) DECLSPEC_HIDDEN
Definition: nsembed.c:836
void nsAString_InitDepend(nsAString *, const PRUnichar *) DECLSPEC_HIDDEN
Definition: nsembed.c:826
static void node_release(HTMLDOMNode *node)
#define NS_FAILED(res)
WCHAR PRUnichar
Definition: nsiface.idl:48
void bind_activex_event(HTMLDocumentNode *doc, HTMLPluginContainer *plugin_container, WCHAR *event, IDispatch *disp)
Definition: pluginhost.c:758
#define TRACE(s)
Definition: solgame.cpp:4
IDispatchEx IDispatchEx_iface
DispatchEx dispex
nsIDOMHTMLDocument * nsdoc
HTMLDOMNode node
HTMLElement element
Definition: pluginhost.h:54
IHTMLScriptElement IHTMLScriptElement_iface
Definition: htmlscript.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by run_end_load().

◆ connect_scripts()

void connect_scripts ( HTMLInnerWindow window)

Definition at line 213 of file script.c.

214{
215 ScriptHost *iter;
216
217 LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
219 IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED);
220 }
221}
@ SCRIPTSTATE_STARTED
Definition: activscp.idl:58
@ SCRIPTSTATE_CONNECTED
Definition: activscp.idl:59
uint32_t entry
Definition: isohybrid.c:63
static IHTMLWindow2 * window
Definition: events.c:77
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
IActiveScript * script
Definition: script.c:62
SCRIPTSTATE script_state
Definition: script.c:66

Referenced by handle_load().

◆ doc_insert_script()

void doc_insert_script ( HTMLInnerWindow window,
HTMLScriptElement script_elem 
)

Definition at line 1172 of file script.c.

1173{
1174 ScriptHost *script_host;
1175
1176 script_host = get_elem_script_host(window, script_elem);
1177 if(!script_host)
1178 return;
1179
1180 if(script_host->parse)
1181 parse_script_elem(script_host, script_elem);
1182}
static void parse_script_elem(ScriptHost *script_host, HTMLScriptElement *script_elem)
Definition: script.c:1015
static ScriptHost * get_elem_script_host(HTMLInnerWindow *window, HTMLScriptElement *script_elem)
Definition: script.c:1154
IActiveScriptParse * parse
Definition: script.c:63

Referenced by HTMLScriptElement_put_src(), HTMLScriptElement_put_text(), and run_insert_script().

◆ exec_script()

HRESULT exec_script ( HTMLInnerWindow window,
const WCHAR code,
const WCHAR lang,
VARIANT ret 
)

Definition at line 1245 of file script.c.

1246{
1247 ScriptHost *script_host;
1248 EXCEPINFO ei;
1249 GUID guid;
1250 HRESULT hres;
1251
1252 static const WCHAR delimW[] = {'"',0};
1253
1255 WARN("Could not find script GUID\n");
1256 return CO_E_CLASSSTRING;
1257 }
1258
1259 script_host = get_script_host(window, &guid);
1260 if(!script_host) {
1261 FIXME("No script host\n");
1262 return E_FAIL;
1263 }
1264
1265 if(!script_host->parse) {
1266 FIXME("script_host->parse == NULL\n");
1267 return E_FAIL;
1268 }
1269
1270 memset(&ei, 0, sizeof(ei));
1271 TRACE(">>>\n");
1272 hres = IActiveScriptParse_ParseScriptText(script_host->parse, code, NULL, NULL, delimW, 0, 0, SCRIPTTEXT_ISVISIBLE, ret, &ei);
1273 if(SUCCEEDED(hres))
1274 TRACE("<<<\n");
1275 else
1276 WARN("<<< %08x\n", hres);
1277
1278 return hres;
1279}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
static ScriptHost * get_script_host(HTMLInnerWindow *window, const GUID *guid)
Definition: script.c:1142
#define IActiveScriptParse_ParseScriptText
Definition: script.c:41
static BOOL get_guid_from_language(LPCWSTR type, GUID *guid)
Definition: script.c:1085
const GUID * guid
struct stdole::EXCEPINFO EXCEPINFO
#define memset(x, y, z)
Definition: compat.h:39
Definition: inflate.c:139
static const WCHAR lang[]
Definition: wbemdisp.c:287
int ret
#define CO_E_CLASSSTRING
Definition: winerror.h:2806

Referenced by create_vbdisp(), exec_global_code(), HTMLWindow2_execScript(), invoke_vbdisp(), navigate_javascript_proc(), run_terminator(), and ScriptDisp_InvokeEx().

◆ find_global_prop()

BOOL find_global_prop ( HTMLInnerWindow window,
BSTR  name,
DWORD  flags,
ScriptHost **  ret_host,
DISPID ret_id 
)

Definition at line 1500 of file script.c.

1501{
1502 IDispatchEx *dispex;
1503 IDispatch *disp;
1504 ScriptHost *iter;
1505 HRESULT hres;
1506
1507 LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) {
1508 disp = get_script_disp(iter);
1509 if(!disp)
1510 continue;
1511
1512 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1513 if(SUCCEEDED(hres)) {
1514 hres = IDispatchEx_GetDispID(dispex, name, flags & (~fdexNameEnsure), ret_id);
1515 IDispatchEx_Release(dispex);
1516 }else {
1517 FIXME("No IDispatchEx\n");
1518 hres = E_NOTIMPL;
1519 }
1520
1521 IDispatch_Release(disp);
1522 if(SUCCEEDED(hres)) {
1523 *ret_host = iter;
1524 return TRUE;
1525 }
1526 }
1527
1528 return FALSE;
1529}
#define E_NOTIMPL
Definition: ddrawi.h:99
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
IDispatch * get_script_disp(ScriptHost *script_host)
Definition: script.c:1281
GLbitfield flags
Definition: glext.h:7161
Definition: name.c:39

Referenced by search_window_props().

◆ get_script_disp()

IDispatch * get_script_disp ( ScriptHost script_host)

Definition at line 1281 of file script.c.

1282{
1283 IDispatch *disp;
1284 HRESULT hres;
1285
1286 if(!script_host->script)
1287 return NULL;
1288
1289 hres = IActiveScript_GetScriptDispatch(script_host->script, windowW, &disp);
1290 if(FAILED(hres))
1291 return NULL;
1292
1293 return disp;
1294}
static const WCHAR windowW[]
Definition: script.c:48

Referenced by find_global_prop(), and HTMLWindow_invoke().

◆ release_script_hosts()

void release_script_hosts ( HTMLInnerWindow window)

Definition at line 1583 of file script.c.

1584{
1585 script_queue_entry_t *queue_iter;
1586 ScriptHost *iter;
1587
1588 while(!list_empty(&window->script_queue)) {
1589 queue_iter = LIST_ENTRY(list_head(&window->script_queue), script_queue_entry_t, entry);
1590
1591 list_remove(&queue_iter->entry);
1592 IHTMLScriptElement_Release(&queue_iter->script->IHTMLScriptElement_iface);
1593 heap_free(queue_iter);
1594 }
1595
1596 while(!list_empty(&window->script_hosts)) {
1597 iter = LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry);
1598
1600 list_remove(&iter->entry);
1601 iter->window = NULL;
1602 IActiveScriptSite_Release(&iter->IActiveScriptSite_iface);
1603 }
1604}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void release_script_engine(ScriptHost *This)
Definition: script.c:182
IActiveScriptSite IActiveScriptSite_iface
Definition: script.c:53
HTMLInnerWindow * window
Definition: script.c:68
struct list entry
Definition: script.c:71
Definition: list.h:15
Definition: htmlscript.h:33
struct list entry
Definition: htmlscript.h:34
HTMLScriptElement * script
Definition: htmlscript.h:35
#define LIST_ENTRY(type)
Definition: queue.h:175

Referenced by detach_inner_window().

◆ script_elem_from_nsscript()

HRESULT script_elem_from_nsscript ( HTMLDocumentNode doc,
nsIDOMHTMLScriptElement nsscript,
HTMLScriptElement **  ret 
)

Definition at line 425 of file htmlscript.c.

426{
427 nsIDOMNode *nsnode;
429 nsresult nsres;
431
432 nsres = nsIDOMHTMLScriptElement_QueryInterface(nsscript, &IID_nsIDOMNode, (void**)&nsnode);
433 assert(nsres == NS_OK);
434
435 hres = get_node(doc, nsnode, TRUE, &node);
436 nsIDOMNode_Release(nsnode);
437 if(FAILED(hres))
438 return hres;
439
442 return S_OK;
443}
HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
Definition: htmlnode.c:1339
static const NodeImplVtbl HTMLScriptElementImplVtbl
Definition: htmlscript.c:405
static HTMLScriptElement * impl_from_HTMLDOMNode(HTMLDOMNode *iface)
Definition: htmlscript.c:348
#define S_OK
Definition: intsafe.h:52
Definition: dlist.c:348

Referenced by bind_event_scripts(), nsDocumentObserver_BindToDocument(), and run_insert_script().

◆ script_parse_event()

IDispatch * script_parse_event ( HTMLInnerWindow window,
LPCWSTR  text 
)

Definition at line 1184 of file script.c.

1185{
1186 ScriptHost *script_host;
1187 GUID guid;
1188 const WCHAR *ptr;
1189 IDispatch *disp;
1190 HRESULT hres;
1191
1192 static const WCHAR delimiterW[] = {'\"',0};
1193
1194 TRACE("%s\n", debugstr_w(text));
1195
1196 for(ptr = text; isalnumW(*ptr); ptr++);
1197 if(*ptr == ':') {
1198 LPWSTR language;
1199 BOOL b;
1200
1201 language = heap_alloc((ptr-text+1)*sizeof(WCHAR));
1202 if(!language)
1203 return NULL;
1204
1205 memcpy(language, text, (ptr-text)*sizeof(WCHAR));
1206 language[ptr-text] = 0;
1207
1208 b = get_guid_from_language(language, &guid);
1209
1210 heap_free(language);
1211
1212 if(!b) {
1213 WARN("Could not find language\n");
1214 return NULL;
1215 }
1216
1217 ptr++;
1218 }else {
1219 ptr = text;
1221 }
1222
1224 && (!window->base.outer_window || window->base.outer_window->scriptmode != SCRIPTMODE_ACTIVESCRIPT)) {
1225 TRACE("Ignoring JScript\n");
1226 return NULL;
1227 }
1228
1229 script_host = get_script_host(window, &guid);
1230 if(!script_host || !script_host->parse_proc)
1231 return NULL;
1232
1234 NULL, NULL, delimiterW, 0 /* FIXME */, 0,
1235 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
1236 if(FAILED(hres)) {
1237 WARN("ParseProcedureText failed: %08x\n", hres);
1238 return NULL;
1239 }
1240
1241 TRACE("ret %p\n", disp);
1242 return disp;
1243}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define IActiveScriptParseProcedure2_ParseProcedureText
Definition: script.c:43
static const WCHAR emptyW[]
Definition: script.c:50
static GUID get_default_script_guid(HTMLInnerWindow *window)
Definition: script.c:1055
const WCHAR * text
Definition: package.c:1794
unsigned int BOOL
Definition: ntddk_ex.h:94
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define b
Definition: ke_i.h:79
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static const CLSID CLSID_JScript
Definition: activex.c:57
@ SCRIPTMODE_ACTIVESCRIPT
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define isalnumW(n)
Definition: unicode.h:55
IActiveScriptParseProcedure2 * parse_proc
Definition: script.c:64
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by check_event_attr(), and window_set_timer().

◆ set_script_mode()

void set_script_mode ( HTMLOuterWindow window,
SCRIPTMODE  mode 
)

Definition at line 1551 of file script.c.

1552{
1553 nsIWebBrowserSetup *setup;
1554 nsresult nsres;
1555
1557 TRACE("jscript.dll not available\n");
1558 window->scriptmode = SCRIPTMODE_GECKO;
1559 return;
1560 }
1561
1562 window->scriptmode = mode;
1563
1564 if(!window->doc_obj->nscontainer || !window->doc_obj->nscontainer->webbrowser)
1565 return;
1566
1567 nsres = nsIWebBrowser_QueryInterface(window->doc_obj->nscontainer->webbrowser,
1568 &IID_nsIWebBrowserSetup, (void**)&setup);
1569 if(NS_SUCCEEDED(nsres)) {
1570 nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT,
1571 window->scriptmode == SCRIPTMODE_GECKO);
1572
1573 if(NS_SUCCEEDED(nsres))
1574 nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_DISABLE_NOSCRIPT, TRUE);
1575
1576 nsIWebBrowserSetup_Release(setup);
1577 }
1578
1579 if(NS_FAILED(nsres))
1580 ERR("JavaScript setup failed: %08x\n", nsres);
1581}
static BOOL is_jscript_available(void)
Definition: script.c:1531
GLenum mode
Definition: glext.h:6217
static BOOL setup(void)
Definition: enum_files.c:97
@ SCRIPTMODE_GECKO
#define NS_SUCCEEDED(res)

Referenced by set_current_mon().