static nsresult NSAPI handle_node_insert(nsIDOMEventListener *iface, nsIDOMEvent *event) { NSContainer *This = NSEVENTLIST_THIS(iface)->This; nsIDOMHTMLScriptElement *script; nsIDOMEventTarget *target; nsIDOMElement *elem; nsresult nsres; TRACE("(%p %p)\n", This, event); nsres = nsIDOMEvent_GetTarget(event, &target); if(NS_FAILED(nsres)) { ERR("GetTarget failed: %08x\n", nsres); return NS_OK; } nsres = nsIDOMEventTarget_QueryInterface(target, &IID_nsIDOMElement, (void**)&elem); nsIDOMEventTarget_Release(target); if(NS_FAILED(nsres)) return NS_OK; nsres = nsIDOMElement_QueryInterface(elem, &IID_nsIDOMHTMLScriptElement, (void**)&script); if(SUCCEEDED(nsres)) { doc_insert_script(This->doc, script); nsIDOMHTMLScriptElement_Release(script); } check_event_attr(This->doc, elem); nsIDOMNode_Release(elem); return NS_OK; }
static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v) { HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface); HTMLInnerWindow *window; nsIDOMNode *parent; nsAString src_str; nsresult nsres; TRACE("(%p)->(%s)\n", This, debugstr_w(v)); if(!This->element.node.doc || !This->element.node.doc->window) { WARN("no windoow\n"); return E_UNEXPECTED; } window = This->element.node.doc->window; nsAString_InitDepend(&src_str, v); nsres = nsIDOMHTMLScriptElement_SetSrc(This->nsscript, &src_str); nsAString_Finish(&src_str); if(NS_FAILED(nsres)) { ERR("SetSrc failed: %08x\n", nsres); return E_FAIL; } if(This->parsed) { WARN("already parsed\n"); return S_OK; } if(window->parser_callback_cnt) { script_queue_entry_t *queue; queue = heap_alloc(sizeof(*queue)); if(!queue) return E_OUTOFMEMORY; IHTMLScriptElement_AddRef(&This->IHTMLScriptElement_iface); queue->script = This; list_add_tail(&window->script_queue, &queue->entry); return S_OK; } nsres = nsIDOMHTMLElement_GetParentNode(This->element.nselem, &parent); if(NS_FAILED(nsres) || !parent) { TRACE("No parent, not executing\n"); This->parse_on_bind = TRUE; return S_OK; } nsIDOMNode_Release(parent); doc_insert_script(window, This); return S_OK; }
static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v) { HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface); HTMLInnerWindow *window; nsIDOMNode *parent; nsAString text_str; nsresult nsres; TRACE("(%p)->(%s)\n", This, debugstr_w(v)); if(!This->element.node.doc || !This->element.node.doc->window) { WARN("no windoow\n"); return E_UNEXPECTED; } window = This->element.node.doc->window; nsAString_InitDepend(&text_str, v); nsres = nsIDOMHTMLScriptElement_SetText(This->nsscript, &text_str); nsAString_Finish(&text_str); if(NS_FAILED(nsres)) { ERR("SetSrc failed: %08x\n", nsres); return E_FAIL; } nsres = nsIDOMHTMLElement_GetParentNode(This->element.nselem, &parent); if(NS_FAILED(nsres) || !parent) { TRACE("No parent, not executing\n"); This->parse_on_bind = TRUE; return S_OK; } nsIDOMNode_Release(parent); doc_insert_script(window, This); return S_OK; }
static nsresult run_insert_script(HTMLDocumentNode *doc, nsISupports *script_iface, nsISupports *parser_iface) { nsIDOMHTMLScriptElement *nsscript; HTMLScriptElement *script_elem; nsIParser *nsparser = NULL; script_queue_entry_t *iter; HTMLInnerWindow *window; nsresult nsres; HRESULT hres; TRACE("(%p)->(%p)\n", doc, script_iface); window = doc->window; if(!window) return NS_OK; nsres = nsISupports_QueryInterface(script_iface, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript); if(NS_FAILED(nsres)) { ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres); return nsres; } if(parser_iface) { nsres = nsISupports_QueryInterface(parser_iface, &IID_nsIParser, (void**)&nsparser); if(NS_FAILED(nsres)) { ERR("Could not get nsIParser iface: %08x\n", nsres); nsparser = NULL; } } hres = script_elem_from_nsscript(doc, nsscript, &script_elem); nsIDOMHTMLScriptElement_Release(nsscript); if(FAILED(hres)) return NS_ERROR_FAILURE; if(nsparser) { nsIParser_BeginEvaluatingParserInsertedScript(nsparser); window->parser_callback_cnt++; } IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface); doc_insert_script(window, script_elem); while(!list_empty(&window->script_queue)) { iter = LIST_ENTRY(list_head(&window->script_queue), script_queue_entry_t, entry); list_remove(&iter->entry); if(!iter->script->parsed) doc_insert_script(window, iter->script); IHTMLScriptElement_Release(&iter->script->IHTMLScriptElement_iface); heap_free(iter); } IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface); if(nsparser) { window->parser_callback_cnt--; nsIParser_EndEvaluatingParserInsertedScript(nsparser); nsIParser_Release(nsparser); } IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface); return NS_OK; }