2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define HTMLPRIVWINDOW(x) ((IHTMLPrivateWindow*) &(x)->lpIHTMLPrivateWindowVtbl)
40 static struct list window_list = LIST_INIT(window_list);
42 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
45 abort_document_bindings(window->doc);
46 window->doc->basedoc.window = NULL;
47 htmldoc_release(&window->doc->basedoc);
49 window->doc = doc_node;
51 htmldoc_addref(&doc_node->basedoc);
53 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
54 if(window->doc_obj->basedoc.doc_node)
55 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
56 window->doc_obj->basedoc.doc_node = doc_node;
58 htmldoc_addref(&doc_node->basedoc);
62 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
64 nsIDOMDocumentView *nsdocview;
65 nsIDOMAbstractView *nsview;
66 nsIDOMWindow *nswindow;
69 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
70 nsIDOMDocument_Release(nsdoc);
71 if(NS_FAILED(nsres)) {
72 ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
76 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
77 nsIDOMDocumentView_Release(nsview);
78 if(NS_FAILED(nsres)) {
79 ERR("GetDefaultView failed: %08x\n", nsres);
83 nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
84 nsIDOMAbstractView_Release(nsview);
85 if(NS_FAILED(nsres)) {
86 ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
93 static void release_children(HTMLWindow *This)
97 while(!list_empty(&This->children)) {
98 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
100 list_remove(&child->sibling_entry);
101 child->parent = NULL;
102 IHTMLWindow2_Release(HTMLWINDOW2(child));
106 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
109 IHTMLLocation_AddRef(HTMLLOCATION(This->location));
113 hres = HTMLLocation_Create(This, &This->location);
118 *ret = This->location;
122 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
125 FIXME("No document\n");
129 return set_event_handler(&window->doc->body_event_target, window->doc, eid, var);
132 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
135 FIXME("No document\n");
139 return get_event_handler(&window->doc->body_event_target, eid, var);
142 #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
144 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
146 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
150 if(IsEqualGUID(&IID_IUnknown, riid)) {
151 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
152 *ppv = HTMLWINDOW2(This);
153 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
154 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
155 *ppv = HTMLWINDOW2(This);
156 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
157 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
158 *ppv = DISPATCHEX(This);
159 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
160 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
161 *ppv = HTMLWINDOW2(This);
162 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
163 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
164 *ppv = HTMLWINDOW2(This);
165 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
166 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
167 *ppv = HTMLWINDOW3(This);
168 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
169 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
170 *ppv = HTMLWINDOW4(This);
171 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
172 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
173 *ppv = HTMLPRIVWINDOW(This);
174 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
175 return *ppv ? S_OK : E_NOINTERFACE;
179 IUnknown_AddRef((IUnknown*)*ppv);
183 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
184 return E_NOINTERFACE;
187 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
189 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
190 LONG ref = InterlockedIncrement(&This->ref);
192 TRACE("(%p) ref=%d\n", This, ref);
197 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
199 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
200 LONG ref = InterlockedDecrement(&This->ref);
202 TRACE("(%p) ref=%d\n", This, ref);
207 remove_target_tasks(This->task_magic);
208 set_window_bscallback(This, NULL);
209 set_current_mon(This, NULL);
210 window_set_docnode(This, NULL);
211 release_children(This);
213 if(This->frame_element)
214 This->frame_element->content_window = NULL;
216 if(This->option_factory) {
217 This->option_factory->window = NULL;
218 IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
221 if(This->image_factory) {
222 This->image_factory->window = NULL;
223 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
227 This->location->window = NULL;
228 IHTMLLocation_Release(HTMLLOCATION(This->location));
232 IHTMLScreen_Release(This->screen);
234 for(i=0; i < This->global_prop_cnt; i++)
235 heap_free(This->global_props[i].name);
237 This->window_ref->window = NULL;
238 windowref_release(This->window_ref);
240 heap_free(This->global_props);
241 release_script_hosts(This);
244 nsIDOMWindow_Release(This->nswindow);
246 list_remove(&This->entry);
247 release_dispex(&This->dispex);
254 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
256 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
258 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
261 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
262 LCID lcid, ITypeInfo **ppTInfo)
264 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
266 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
269 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
270 LPOLESTR *rgszNames, UINT cNames,
271 LCID lcid, DISPID *rgDispId)
273 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
275 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
278 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
279 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
280 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
282 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
284 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
285 pVarResult, pExcepInfo, puArgErr);
288 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
291 nsIDOMWindow *nsWindow;
294 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
295 if(NS_FAILED(nsres)) {
296 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
301 return DISP_E_MEMBERNOTFOUND;
303 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
304 if(NS_FAILED(nsres)) {
305 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
309 *ret = nswindow_to_window(nsWindow);
311 nsIDOMWindow_Release(nsWindow);
316 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
318 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
319 nsIDOMWindowCollection *nsFrames;
324 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
326 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
327 if(NS_FAILED(nsres)) {
328 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
332 if(V_VT(pvarIndex) == VT_I4) {
333 int index = V_I4(pvarIndex);
334 TRACE("Getting index %d\n", index);
336 hres = DISP_E_MEMBERNOTFOUND;
339 hres = get_frame_by_index(nsFrames, index, &window);
342 }else if(V_VT(pvarIndex) == VT_UINT) {
343 unsigned int index = V_UINT(pvarIndex);
344 TRACE("Getting index %u\n", index);
345 hres = get_frame_by_index(nsFrames, index, &window);
348 }else if(V_VT(pvarIndex) == VT_BSTR) {
349 BSTR str = V_BSTR(pvarIndex);
352 TRACE("Getting name %s\n", wine_dbgstr_w(str));
354 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
357 for(i = 0; i < length && !window; ++i) {
358 HTMLWindow *cur_window;
359 nsIDOMWindow *nsWindow;
362 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
363 if(NS_FAILED(nsres)) {
364 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
369 cur_window = nswindow_to_window(nsWindow);
371 nsIDOMWindow_Release(nsWindow);
373 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
375 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
379 if(!strcmpW(id, str))
386 hres = DISP_E_MEMBERNOTFOUND;
394 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
395 V_VT(pvarResult) = VT_DISPATCH;
396 V_DISPATCH(pvarResult) = (IDispatch*)window;
401 nsIDOMWindowCollection_Release(nsFrames);
406 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
408 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
409 nsIDOMWindowCollection *nscollection;
413 TRACE("(%p)->(%p)\n", This, p);
415 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
416 if(NS_FAILED(nsres)) {
417 ERR("GetFrames failed: %08x\n", nsres);
421 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
422 nsIDOMWindowCollection_Release(nscollection);
423 if(NS_FAILED(nsres)) {
424 ERR("GetLength failed: %08x\n", nsres);
432 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
434 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
435 FIXME("(%p)->(%p): semi-stub\n", This, p);
437 /* FIXME: Should return a separate Window object */
438 *p = (IHTMLFramesCollection2*)HTMLWINDOW2(This);
439 HTMLWindow2_AddRef(iface);
443 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
445 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
446 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
450 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
452 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
453 FIXME("(%p)->(%p)\n", This, p);
457 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
459 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
460 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
464 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
466 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
467 FIXME("(%p)->(%p)\n", This, p);
471 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
472 LONG msec, VARIANT *language, LONG *timerID)
474 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
477 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
479 V_VT(&expr_var) = VT_BSTR;
480 V_BSTR(&expr_var) = expression;
482 return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
485 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
487 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
489 TRACE("(%p)->(%d)\n", This, timerID);
491 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
494 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
496 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
499 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
501 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
502 sizeof(wszTitle)/sizeof(WCHAR))) {
503 WARN("Could not load message box title: %d\n", GetLastError());
507 MessageBoxW(This->doc_obj->hwnd, message, wszTitle, MB_ICONWARNING);
511 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
512 VARIANT_BOOL *confirmed)
514 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
517 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
519 if(!confirmed) return E_INVALIDARG;
521 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
522 sizeof(wszTitle)/sizeof(WCHAR))) {
523 WARN("Could not load message box title: %d\n", GetLastError());
524 *confirmed = VARIANT_TRUE;
528 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
529 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
530 *confirmed = VARIANT_TRUE;
531 else *confirmed = VARIANT_FALSE;
543 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
544 WPARAM wparam, LPARAM lparam)
550 prompt_arg *arg = (prompt_arg*)lparam;
553 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
554 sizeof(wszTitle)/sizeof(WCHAR))) {
555 WARN("Could not load message box title: %d\n", GetLastError());
556 EndDialog(hwnd, wparam);
560 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
561 SetWindowTextW(hwnd, wszTitle);
562 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
563 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
569 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
570 EndDialog(hwnd, wparam);
572 case MAKEWPARAM(IDOK, BN_CLICKED):
575 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
576 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
577 INT len = GetWindowTextLengthW(hwndPrompt);
581 EndDialog(hwnd, wparam);
585 V_VT(arg->textdata) = VT_BSTR;
586 if(!len && !arg->dststr)
587 V_BSTR(arg->textdata) = NULL;
590 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
591 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
593 EndDialog(hwnd, wparam);
599 EndDialog(hwnd, IDCANCEL);
606 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
607 BSTR dststr, VARIANT *textdata)
609 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
612 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
614 if(textdata) V_VT(textdata) = VT_NULL;
616 arg.message = message;
618 arg.textdata = textdata;
620 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
621 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
625 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
627 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
629 TRACE("(%p)->(%p)\n", This, p);
631 if(!This->image_factory)
632 This->image_factory = HTMLImageElementFactory_Create(This);
634 *p = HTMLIMGFACTORY(This->image_factory);
635 IHTMLImageElementFactory_AddRef(*p);
640 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
642 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
643 HTMLLocation *location;
646 TRACE("(%p)->(%p)\n", This, p);
648 hres = get_location(This, &location);
652 *p = HTMLLOCATION(location);
656 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
658 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
659 FIXME("(%p)->(%p)\n", This, p);
663 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
665 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
666 FIXME("(%p)->()\n", This);
670 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
672 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
673 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
677 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
679 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
680 FIXME("(%p)->(%p)\n", This, p);
684 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
686 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
688 TRACE("(%p)->(%p)\n", This, p);
690 *p = OmNavigator_Create();
694 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
696 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
700 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
702 nsAString_InitDepend(&name_str, v);
703 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
704 nsAString_Finish(&name_str);
706 ERR("SetName failed: %08x\n", nsres);
711 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
713 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
718 TRACE("(%p)->(%p)\n", This, p);
720 nsAString_Init(&name_str, NULL);
721 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
722 if(NS_SUCCEEDED(nsres)) {
723 const PRUnichar *name;
725 nsAString_GetData(&name_str, &name);
727 *p = SysAllocString(name);
728 hres = *p ? S_OK : E_OUTOFMEMORY;
734 ERR("GetName failed: %08x\n", nsres);
737 nsAString_Finish(&name_str);
742 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
744 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
745 TRACE("(%p)->(%p)\n", This, p);
748 *p = HTMLWINDOW2(This->parent);
749 IHTMLWindow2_AddRef(*p);
756 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
757 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
759 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
760 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
761 debugstr_w(features), replace, pomWindowResult);
765 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
767 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
769 TRACE("(%p)->(%p)\n", This, p);
771 /* FIXME: We should return kind of proxy window here. */
772 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
773 *p = HTMLWINDOW2(This);
777 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
779 HTMLWindow *This = HTMLWINDOW2_THIS(iface), *curr;
780 TRACE("(%p)->(%p)\n", This, p);
785 *p = HTMLWINDOW2(curr);
786 IHTMLWindow2_AddRef(*p);
791 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
793 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
795 TRACE("(%p)->(%p)\n", This, p);
797 /* FIXME: We should return kind of proxy window here. */
798 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
799 *p = HTMLWINDOW2(This);
803 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
805 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
806 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
810 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
812 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
813 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
817 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
819 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
820 FIXME("(%p)->(%p)\n", This, p);
824 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
826 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
827 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
831 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
833 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
834 FIXME("(%p)->(%p)\n", This, p);
838 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
840 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
842 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
844 return set_window_event(This, EVENTID_LOAD, &v);
847 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
849 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
851 TRACE("(%p)->(%p)\n", This, p);
853 return get_window_event(This, EVENTID_LOAD, p);
856 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
858 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
860 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
862 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
865 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
867 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
869 TRACE("(%p)->(%p)\n", This, p);
871 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
874 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
876 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
877 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
881 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
883 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
884 FIXME("(%p)->(%p)\n", This, p);
888 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
890 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
891 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
895 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
897 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
898 FIXME("(%p)->(%p)\n", This, p);
902 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
904 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
905 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
909 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
911 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
912 FIXME("(%p)->(%p)\n", This, p);
916 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
918 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
920 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
922 return set_window_event(This, EVENTID_RESIZE, &v);
925 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
927 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
929 TRACE("(%p)->(%p)\n", This, p);
931 return get_window_event(This, EVENTID_RESIZE, p);
934 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
936 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
937 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
941 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
943 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
944 FIXME("(%p)->(%p)\n", This, p);
948 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
950 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
952 TRACE("(%p)->(%p)\n", This, p);
955 /* FIXME: We should return a wrapper object here */
956 *p = HTMLDOC(&This->doc->basedoc);
957 IHTMLDocument2_AddRef(*p);
965 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
967 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
969 TRACE("(%p)->(%p)\n", This, p);
972 IHTMLEventObj_AddRef(This->event);
977 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
979 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
980 FIXME("(%p)->(%p)\n", This, p);
984 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
985 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
987 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
988 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
992 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
995 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
996 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1000 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1002 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1004 TRACE("(%p)->(%p)\n", This, p);
1009 hres = HTMLScreen_Create(&This->screen);
1015 IHTMLScreen_AddRef(This->screen);
1019 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1021 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1023 TRACE("(%p)->(%p)\n", This, p);
1025 if(!This->option_factory)
1026 This->option_factory = HTMLOptionElementFactory_Create(This);
1028 *p = HTMLOPTFACTORY(This->option_factory);
1029 IHTMLOptionElementFactory_AddRef(*p);
1034 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1036 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1037 FIXME("(%p)->()\n", This);
1041 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1043 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1044 FIXME("(%p)->(%p)\n", This, p);
1048 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1050 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1051 FIXME("(%p)->()\n", This);
1055 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1057 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1058 FIXME("(%p)->(%d %d)\n", This, x, y);
1062 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1064 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1065 FIXME("(%p)->(%p)\n", This, p);
1069 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1070 LONG msec, VARIANT *language, LONG *timerID)
1072 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1075 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1077 V_VT(&expr) = VT_BSTR;
1078 V_BSTR(&expr) = expression;
1079 return IHTMLWindow3_setInterval(HTMLWINDOW3(This), &expr, msec, language, timerID);
1082 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1084 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1086 TRACE("(%p)->(%d)\n", This, timerID);
1088 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1091 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1093 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1094 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1098 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1100 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1101 FIXME("(%p)->(%p)\n", This, p);
1105 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1108 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1109 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1113 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1115 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1117 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1119 TRACE("(%p)->(%p)\n", This, String);
1122 return E_INVALIDARG;
1124 *String = SysAllocString(objectW);
1125 return *String ? S_OK : E_OUTOFMEMORY;
1128 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1130 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1133 TRACE("(%p)->(%d %d)\n", This, x, y);
1135 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1136 if(NS_FAILED(nsres))
1137 ERR("ScrollBy failed: %08x\n", nsres);
1142 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1144 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1147 TRACE("(%p)->(%d %d)\n", This, x, y);
1149 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1150 if(NS_FAILED(nsres))
1151 ERR("ScrollTo failed: %08x\n", nsres);
1156 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1158 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1159 FIXME("(%p)->(%d %d)\n", This, x, y);
1163 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1165 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1166 FIXME("(%p)->(%d %d)\n", This, x, y);
1170 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1172 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1173 FIXME("(%p)->(%d %d)\n", This, x, y);
1177 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1179 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1180 FIXME("(%p)->(%d %d)\n", This, x, y);
1184 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1186 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1188 TRACE("(%p)->(%p)\n", This, p);
1192 if(!This->doc_obj->hostui)
1195 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1198 static HRESULT HTMLWindow_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1199 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1201 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1202 global_prop_t *prop;
1206 idx = id - MSHTML_DISPID_CUSTOM_MIN;
1207 if(idx >= This->global_prop_cnt)
1208 return DISP_E_MEMBERNOTFOUND;
1210 prop = This->global_props+idx;
1212 switch(prop->type) {
1213 case GLOBAL_SCRIPTVAR: {
1214 IDispatchEx *dispex;
1217 disp = get_script_disp(prop->script_host);
1219 return E_UNEXPECTED;
1221 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1222 if(SUCCEEDED(hres)) {
1223 TRACE("%s >>>\n", debugstr_w(prop->name));
1224 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
1226 TRACE("%s <<<\n", debugstr_w(prop->name));
1228 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
1229 IDispatchEx_Release(dispex);
1231 FIXME("No IDispatchEx\n");
1233 IDispatch_Release(disp);
1236 case GLOBAL_ELEMENTVAR: {
1239 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), prop->name, &elem);
1244 return DISP_E_MEMBERNOTFOUND;
1246 V_VT(res) = VT_DISPATCH;
1247 V_DISPATCH(res) = (IDispatch*)elem;
1251 ERR("invalid type %d\n", prop->type);
1252 hres = DISP_E_MEMBERNOTFOUND;
1258 #undef HTMLWINDOW2_THIS
1260 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1261 HTMLWindow2_QueryInterface,
1263 HTMLWindow2_Release,
1264 HTMLWindow2_GetTypeInfoCount,
1265 HTMLWindow2_GetTypeInfo,
1266 HTMLWindow2_GetIDsOfNames,
1269 HTMLWindow2_get_length,
1270 HTMLWindow2_get_frames,
1271 HTMLWindow2_put_defaultStatus,
1272 HTMLWindow2_get_defaultStatus,
1273 HTMLWindow2_put_status,
1274 HTMLWindow2_get_status,
1275 HTMLWindow2_setTimeout,
1276 HTMLWindow2_clearTimeout,
1278 HTMLWindow2_confirm,
1280 HTMLWindow2_get_Image,
1281 HTMLWindow2_get_location,
1282 HTMLWindow2_get_history,
1284 HTMLWindow2_put_opener,
1285 HTMLWindow2_get_opener,
1286 HTMLWindow2_get_navigator,
1287 HTMLWindow2_put_name,
1288 HTMLWindow2_get_name,
1289 HTMLWindow2_get_parent,
1291 HTMLWindow2_get_self,
1292 HTMLWindow2_get_top,
1293 HTMLWindow2_get_window,
1294 HTMLWindow2_navigate,
1295 HTMLWindow2_put_onfocus,
1296 HTMLWindow2_get_onfocus,
1297 HTMLWindow2_put_onblur,
1298 HTMLWindow2_get_onblur,
1299 HTMLWindow2_put_onload,
1300 HTMLWindow2_get_onload,
1301 HTMLWindow2_put_onbeforeunload,
1302 HTMLWindow2_get_onbeforeunload,
1303 HTMLWindow2_put_onunload,
1304 HTMLWindow2_get_onunload,
1305 HTMLWindow2_put_onhelp,
1306 HTMLWindow2_get_onhelp,
1307 HTMLWindow2_put_onerror,
1308 HTMLWindow2_get_onerror,
1309 HTMLWindow2_put_onresize,
1310 HTMLWindow2_get_onresize,
1311 HTMLWindow2_put_onscroll,
1312 HTMLWindow2_get_onscroll,
1313 HTMLWindow2_get_document,
1314 HTMLWindow2_get_event,
1315 HTMLWindow2_get__newEnum,
1316 HTMLWindow2_showModalDialog,
1317 HTMLWindow2_showHelp,
1318 HTMLWindow2_get_screen,
1319 HTMLWindow2_get_Option,
1321 HTMLWindow2_get_closed,
1324 HTMLWindow2_get_clientInformation,
1325 HTMLWindow2_setInterval,
1326 HTMLWindow2_clearInterval,
1327 HTMLWindow2_put_offscreenBuffering,
1328 HTMLWindow2_get_offscreenBuffering,
1329 HTMLWindow2_execScript,
1330 HTMLWindow2_toString,
1331 HTMLWindow2_scrollBy,
1332 HTMLWindow2_scrollTo,
1335 HTMLWindow2_resizeTo,
1336 HTMLWindow2_resizeBy,
1337 HTMLWindow2_get_external
1340 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
1342 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1344 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1346 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1349 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1351 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1353 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1356 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1358 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1360 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1363 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1365 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1367 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1370 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1371 LCID lcid, ITypeInfo **ppTInfo)
1373 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1375 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1378 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1379 LPOLESTR *rgszNames, UINT cNames,
1380 LCID lcid, DISPID *rgDispId)
1382 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1384 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1387 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1388 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1389 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1391 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1393 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1394 pVarResult, pExcepInfo, puArgErr);
1397 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1399 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1400 FIXME("(%p)->(%p)\n", This, p);
1404 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1406 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1407 FIXME("(%p)->(%p)\n", This, p);
1411 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1413 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1415 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1418 FIXME("No document\n");
1422 return attach_event(&This->doc->body_event_target, &This->doc->basedoc, event, pDisp, pfResult);
1425 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1427 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1428 FIXME("(%p)->()\n", This);
1432 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1433 BOOL interval, LONG *timer_id)
1435 IDispatch *disp = NULL;
1437 switch(V_VT(expr)) {
1439 disp = V_DISPATCH(expr);
1440 IDispatch_AddRef(disp);
1444 disp = script_parse_event(This, V_BSTR(expr));
1448 FIXME("unimplemented vt=%d\n", V_VT(expr));
1455 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1456 IDispatch_Release(disp);
1461 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1462 VARIANT *language, LONG *timerID)
1464 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1466 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1468 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1471 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1472 VARIANT *language, LONG *timerID)
1474 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1476 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1478 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1481 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1483 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1484 FIXME("(%p)\n", This);
1488 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1490 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1491 FIXME("(%p)->()\n", This);
1495 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1497 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1498 FIXME("(%p)->(%p)\n", This, p);
1502 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1504 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1505 FIXME("(%p)->()\n", This);
1509 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1511 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1512 FIXME("(%p)->(%p)\n", This, p);
1516 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1518 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1519 FIXME("(%p)->(%p)\n", This, p);
1523 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1524 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1526 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1527 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1531 #undef HTMLWINDOW3_THIS
1533 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1534 HTMLWindow3_QueryInterface,
1536 HTMLWindow3_Release,
1537 HTMLWindow3_GetTypeInfoCount,
1538 HTMLWindow3_GetTypeInfo,
1539 HTMLWindow3_GetIDsOfNames,
1541 HTMLWindow3_get_screenLeft,
1542 HTMLWindow3_get_screenTop,
1543 HTMLWindow3_attachEvent,
1544 HTMLWindow3_detachEvent,
1545 HTMLWindow3_setTimeout,
1546 HTMLWindow3_setInterval,
1548 HTMLWindow3_put_onbeforeprint,
1549 HTMLWindow3_get_onbeforeprint,
1550 HTMLWindow3_put_onafterprint,
1551 HTMLWindow3_get_onafterprint,
1552 HTMLWindow3_get_clipboardData,
1553 HTMLWindow3_showModelessDialog
1556 #define HTMLWINDOW4_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow4, iface)
1558 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1560 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1562 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1565 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1567 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1569 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1572 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1574 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1576 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1579 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1581 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1583 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1586 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1587 LCID lcid, ITypeInfo **ppTInfo)
1589 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1591 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1594 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1595 LPOLESTR *rgszNames, UINT cNames,
1596 LCID lcid, DISPID *rgDispId)
1598 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1600 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1603 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1604 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1605 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1607 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1609 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1610 pVarResult, pExcepInfo, puArgErr);
1613 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1614 IDispatch **ppPopup)
1616 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1617 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1621 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1623 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1624 TRACE("(%p)->(%p)\n", This, p);
1626 if(This->frame_element) {
1627 *p = HTMLFRAMEBASE(This->frame_element);
1628 IHTMLFrameBase_AddRef(*p);
1635 #undef HTMLWINDOW4_THIS
1637 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1638 HTMLWindow4_QueryInterface,
1640 HTMLWindow4_Release,
1641 HTMLWindow4_GetTypeInfoCount,
1642 HTMLWindow4_GetTypeInfo,
1643 HTMLWindow4_GetIDsOfNames,
1645 HTMLWindow4_createPopup,
1646 HTMLWindow4_get_frameElement
1649 #define HTMLPRIVWINDOW_THIS(iface) DEFINE_THIS(HTMLWindow, IHTMLPrivateWindow, iface)
1651 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1653 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1655 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1658 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1660 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1662 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1665 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1667 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1669 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1672 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1673 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1675 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1676 DWORD post_data_size = 0;
1677 BYTE *post_data = NULL;
1678 WCHAR *headers = NULL;
1684 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1685 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1688 if(This->doc_obj->hostui) {
1689 OLECHAR *translated_url = NULL;
1691 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1692 if(hres == S_OK && translated_url) {
1693 new_url = SysAllocString(translated_url);
1694 CoTaskMemFree(translated_url);
1698 if(This->doc_obj->client) {
1699 IOleCommandTarget *cmdtrg;
1701 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1702 if(SUCCEEDED(hres)) {
1705 V_VT(&in) = VT_BSTR;
1706 V_BSTR(&in) = new_url;
1707 V_VT(&out) = VT_BOOL;
1708 V_BOOL(&out) = VARIANT_TRUE;
1709 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1710 IOleCommandTarget_Release(cmdtrg);
1716 /* FIXME: Why not set_ready_state? */
1717 This->readystate = READYSTATE_UNINITIALIZED;
1719 hres = CreateURLMoniker(NULL, new_url, &mon);
1721 SysFreeString(new_url);
1726 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1727 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1728 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1732 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1733 if(V_VT(headers_var) != VT_BSTR)
1734 return E_INVALIDARG;
1736 headers = V_BSTR(headers_var);
1739 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1741 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1743 IMoniker_Release(mon);
1747 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1749 hres = async_start_doc_binding(This, bsc);
1751 IUnknown_Release((IUnknown*)bsc);
1752 IMoniker_Release(mon);
1756 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1758 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1759 FIXME("(%p)->(%p)\n", This, url);
1763 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1765 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1766 FIXME("(%p)->(%p)\n", This, cmdtrg);
1770 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1772 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1773 FIXME("(%p)->(%x)\n", This, arg);
1777 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1779 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1780 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1784 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1786 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1787 FIXME("(%p)->(%p)\n", This, url);
1791 #undef HTMLPRIVWINDOW_THIS
1793 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1794 HTMLPrivateWindow_QueryInterface,
1795 HTMLPrivateWindow_AddRef,
1796 HTMLPrivateWindow_Release,
1797 HTMLPrivateWindow_SuperNavigate,
1798 HTMLPrivateWindow_GetPendingUrl,
1799 HTMLPrivateWindow_SetPICSTarget,
1800 HTMLPrivateWindow_PICSComplete,
1801 HTMLPrivateWindow_FindWindowByName,
1802 HTMLPrivateWindow_GetAddressBar
1805 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1807 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1809 HTMLWindow *This = DISPEX_THIS(iface);
1811 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1814 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1816 HTMLWindow *This = DISPEX_THIS(iface);
1818 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1821 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1823 HTMLWindow *This = DISPEX_THIS(iface);
1825 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1828 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1830 HTMLWindow *This = DISPEX_THIS(iface);
1832 TRACE("(%p)->(%p)\n", This, pctinfo);
1834 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1837 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1838 LCID lcid, ITypeInfo **ppTInfo)
1840 HTMLWindow *This = DISPEX_THIS(iface);
1842 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1844 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1847 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1848 LPOLESTR *rgszNames, UINT cNames,
1849 LCID lcid, DISPID *rgDispId)
1851 HTMLWindow *This = DISPEX_THIS(iface);
1855 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1858 for(i=0; i < cNames; i++) {
1859 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1860 hres = IDispatchEx_GetDispID(DISPATCHEX(This), rgszNames[i], 0, rgDispId+i);
1868 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1869 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1870 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1872 HTMLWindow *This = DISPEX_THIS(iface);
1874 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1875 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1877 /* FIXME: Use script dispatch */
1879 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1880 pVarResult, pExcepInfo, puArgErr);
1883 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1885 if(This->global_prop_cnt == This->global_prop_size) {
1886 global_prop_t *new_props;
1889 if(This->global_props) {
1890 new_size = This->global_prop_size*2;
1891 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1894 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1898 This->global_props = new_props;
1899 This->global_prop_size = new_size;
1902 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1903 if(!This->global_props[This->global_prop_cnt].name)
1906 This->global_props[This->global_prop_cnt].type = type;
1907 return This->global_props + This->global_prop_cnt++;
1910 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1912 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1915 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1918 ScriptHost *script_host;
1921 for(i=0; i < This->global_prop_cnt; i++) {
1922 /* FIXME: case sensitivity */
1923 if(!strcmpW(This->global_props[i].name, bstrName)) {
1924 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1929 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1930 global_prop_t *prop;
1932 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1934 return E_OUTOFMEMORY;
1936 prop->script_host = script_host;
1939 *pid = prop_to_dispid(This, prop);
1943 return DISP_E_UNKNOWNNAME;
1946 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1948 HTMLWindow *This = DISPEX_THIS(iface);
1951 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1953 hres = search_window_props(This, bstrName, grfdex, pid);
1954 if(hres != DISP_E_UNKNOWNNAME)
1957 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1958 if(hres != DISP_E_UNKNOWNNAME)
1962 global_prop_t *prop;
1965 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), bstrName, &elem);
1966 if(SUCCEEDED(hres) && elem) {
1967 IHTMLElement_Release(elem);
1969 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1971 return E_OUTOFMEMORY;
1973 *pid = prop_to_dispid(This, prop);
1978 return DISP_E_UNKNOWNNAME;
1981 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1982 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1984 HTMLWindow *This = DISPEX_THIS(iface);
1986 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1988 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1989 HTMLLocation *location;
1992 TRACE("forwarding to location.href\n");
1994 hres = get_location(This, &location);
1998 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1999 IHTMLLocation_Release(HTMLLOCATION(location));
2003 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2006 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2008 HTMLWindow *This = DISPEX_THIS(iface);
2010 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2012 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
2015 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2017 HTMLWindow *This = DISPEX_THIS(iface);
2019 TRACE("(%p)->(%x)\n", This, id);
2021 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
2024 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2026 HTMLWindow *This = DISPEX_THIS(iface);
2028 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2030 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
2033 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2035 HTMLWindow *This = DISPEX_THIS(iface);
2037 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2039 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
2042 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2044 HTMLWindow *This = DISPEX_THIS(iface);
2046 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2048 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
2051 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2053 HTMLWindow *This = DISPEX_THIS(iface);
2055 TRACE("(%p)->(%p)\n", This, ppunk);
2063 static const IDispatchExVtbl WindowDispExVtbl = {
2064 WindowDispEx_QueryInterface,
2065 WindowDispEx_AddRef,
2066 WindowDispEx_Release,
2067 WindowDispEx_GetTypeInfoCount,
2068 WindowDispEx_GetTypeInfo,
2069 WindowDispEx_GetIDsOfNames,
2070 WindowDispEx_Invoke,
2071 WindowDispEx_GetDispID,
2072 WindowDispEx_InvokeEx,
2073 WindowDispEx_DeleteMemberByName,
2074 WindowDispEx_DeleteMemberByDispID,
2075 WindowDispEx_GetMemberProperties,
2076 WindowDispEx_GetMemberName,
2077 WindowDispEx_GetNextDispID,
2078 WindowDispEx_GetNameSpaceParent
2081 static const tid_t HTMLWindow_iface_tids[] = {
2088 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2094 static dispex_static_data_t HTMLWindow_dispex = {
2095 &HTMLWindow_dispex_vtbl,
2096 DispHTMLWindow2_tid,
2098 HTMLWindow_iface_tids
2101 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2105 window = heap_alloc_zero(sizeof(HTMLWindow));
2107 return E_OUTOFMEMORY;
2109 window->window_ref = heap_alloc(sizeof(windowref_t));
2110 if(!window->window_ref) {
2112 return E_OUTOFMEMORY;
2115 window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
2116 window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
2117 window->lpHTMLWindow4Vtbl = &HTMLWindow4Vtbl;
2118 window->lpIHTMLPrivateWindowVtbl = &HTMLPrivateWindowVtbl;
2119 window->lpIDispatchExVtbl = &WindowDispExVtbl;
2121 window->doc_obj = doc_obj;
2123 window->window_ref->window = window;
2124 window->window_ref->ref = 1;
2126 init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex);
2129 nsIDOMWindow_AddRef(nswindow);
2130 window->nswindow = nswindow;
2133 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2134 window->readystate = READYSTATE_UNINITIALIZED;
2135 list_init(&window->script_hosts);
2137 window->task_magic = get_task_target_magic();
2138 update_window_doc(window);
2140 list_init(&window->children);
2141 list_add_head(&window_list, &window->entry);
2144 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2146 window->parent = parent;
2147 list_add_tail(&parent->children, &window->sibling_entry);
2154 void update_window_doc(HTMLWindow *window)
2156 nsIDOMHTMLDocument *nshtmldoc;
2157 nsIDOMDocument *nsdoc;
2160 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2161 if(NS_FAILED(nsres) || !nsdoc) {
2162 ERR("GetDocument failed: %08x\n", nsres);
2166 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2167 nsIDOMDocument_Release(nsdoc);
2168 if(NS_FAILED(nsres)) {
2169 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2173 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2174 HTMLDocumentNode *doc;
2177 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2178 if(SUCCEEDED(hres)) {
2179 window_set_docnode(window, doc);
2180 htmldoc_release(&doc->basedoc);
2182 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2186 nsIDOMHTMLDocument_Release(nshtmldoc);
2189 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2193 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2194 if(iter->nswindow == nswindow)