2 * Copyright 2006 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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static struct list window_list = LIST_INIT(window_list);
40 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
43 abort_document_bindings(window->doc);
44 window->doc->basedoc.window = NULL;
45 htmldoc_release(&window->doc->basedoc);
47 window->doc = doc_node;
49 htmldoc_addref(&doc_node->basedoc);
51 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
52 if(window->doc_obj->basedoc.doc_node)
53 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
54 window->doc_obj->basedoc.doc_node = doc_node;
56 htmldoc_addref(&doc_node->basedoc);
60 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
62 nsIDOMDocumentView *nsdocview;
63 nsIDOMAbstractView *nsview;
64 nsIDOMWindow *nswindow;
67 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
68 nsIDOMDocument_Release(nsdoc);
69 if(NS_FAILED(nsres)) {
70 ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
74 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
75 nsIDOMDocumentView_Release(nsview);
76 if(NS_FAILED(nsres)) {
77 ERR("GetDefaultView failed: %08x\n", nsres);
81 nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
82 nsIDOMAbstractView_Release(nsview);
83 if(NS_FAILED(nsres)) {
84 ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
91 static void release_children(HTMLWindow *This)
95 while(!list_empty(&This->children)) {
96 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
98 list_remove(&child->sibling_entry);
100 IHTMLWindow2_Release(HTMLWINDOW2(child));
104 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
107 IHTMLLocation_AddRef(HTMLLOCATION(This->location));
111 hres = HTMLLocation_Create(This, &This->location);
116 *ret = This->location;
120 #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
122 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
124 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
128 if(IsEqualGUID(&IID_IUnknown, riid)) {
129 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
130 *ppv = HTMLWINDOW2(This);
131 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
132 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
133 *ppv = HTMLWINDOW2(This);
134 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
135 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
136 *ppv = DISPATCHEX(This);
137 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
138 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
139 *ppv = HTMLWINDOW2(This);
140 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
141 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
142 *ppv = HTMLWINDOW2(This);
143 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
144 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
145 *ppv = HTMLWINDOW3(This);
146 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
147 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
148 *ppv = HTMLWINDOW4(This);
149 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
150 return *ppv ? S_OK : E_NOINTERFACE;
154 IUnknown_AddRef((IUnknown*)*ppv);
158 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
159 return E_NOINTERFACE;
162 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
164 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
165 LONG ref = InterlockedIncrement(&This->ref);
167 TRACE("(%p) ref=%d\n", This, ref);
172 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
174 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
175 LONG ref = InterlockedDecrement(&This->ref);
177 TRACE("(%p) ref=%d\n", This, ref);
182 remove_target_tasks(This->task_magic);
183 set_window_bscallback(This, NULL);
184 set_current_mon(This, NULL);
185 window_set_docnode(This, NULL);
186 release_children(This);
188 if(This->frame_element)
189 This->frame_element->content_window = NULL;
191 if(This->option_factory) {
192 This->option_factory->window = NULL;
193 IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
196 if(This->image_factory) {
197 This->image_factory->window = NULL;
198 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
202 This->location->window = NULL;
203 IHTMLLocation_Release(HTMLLOCATION(This->location));
207 IHTMLScreen_Release(This->screen);
209 if(This->event_target)
210 release_event_target(This->event_target);
211 for(i=0; i < This->global_prop_cnt; i++)
212 heap_free(This->global_props[i].name);
214 This->window_ref->window = NULL;
215 windowref_release(This->window_ref);
217 heap_free(This->global_props);
218 release_script_hosts(This);
221 nsIDOMWindow_Release(This->nswindow);
223 list_remove(&This->entry);
224 release_dispex(&This->dispex);
231 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
233 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
235 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
238 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
239 LCID lcid, ITypeInfo **ppTInfo)
241 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
243 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
246 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
247 LPOLESTR *rgszNames, UINT cNames,
248 LCID lcid, DISPID *rgDispId)
250 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
252 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
255 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
256 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
257 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
259 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
261 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
262 pVarResult, pExcepInfo, puArgErr);
265 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
268 nsIDOMWindow *nsWindow;
271 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
272 if(NS_FAILED(nsres)) {
273 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
278 return DISP_E_MEMBERNOTFOUND;
280 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
281 if(NS_FAILED(nsres)) {
282 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
286 *ret = nswindow_to_window(nsWindow);
288 nsIDOMWindow_Release(nsWindow);
293 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
295 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
296 nsIDOMWindowCollection *nsFrames;
301 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
303 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
304 if(NS_FAILED(nsres)) {
305 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
309 if(V_VT(pvarIndex) == VT_I4) {
310 int index = V_I4(pvarIndex);
311 TRACE("Getting index %d\n", index);
313 hres = DISP_E_MEMBERNOTFOUND;
316 hres = get_frame_by_index(nsFrames, index, &window);
319 }else if(V_VT(pvarIndex) == VT_UINT) {
320 unsigned int index = V_UINT(pvarIndex);
321 TRACE("Getting index %u\n", index);
322 hres = get_frame_by_index(nsFrames, index, &window);
325 }else if(V_VT(pvarIndex) == VT_BSTR) {
326 BSTR str = V_BSTR(pvarIndex);
329 TRACE("Getting name %s\n", wine_dbgstr_w(str));
331 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
334 for(i = 0; i < length && !window; ++i) {
335 HTMLWindow *cur_window;
336 nsIDOMWindow *nsWindow;
339 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
340 if(NS_FAILED(nsres)) {
341 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
346 cur_window = nswindow_to_window(nsWindow);
348 nsIDOMWindow_Release(nsWindow);
350 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
352 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
356 if(!strcmpW(id, str))
363 hres = DISP_E_MEMBERNOTFOUND;
371 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
372 V_VT(pvarResult) = VT_DISPATCH;
373 V_DISPATCH(pvarResult) = (IDispatch*)window;
378 nsIDOMWindowCollection_Release(nsFrames);
383 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
385 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
386 nsIDOMWindowCollection *nscollection;
390 TRACE("(%p)->(%p)\n", This, p);
392 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
393 if(NS_FAILED(nsres)) {
394 ERR("GetFrames failed: %08x\n", nsres);
398 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
399 nsIDOMWindowCollection_Release(nscollection);
400 if(NS_FAILED(nsres)) {
401 ERR("GetLength failed: %08x\n", nsres);
409 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
411 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
412 FIXME("(%p)->(%p): semi-stub\n", This, p);
414 /* FIXME: Should return a separate Window object */
415 *p = (IHTMLFramesCollection2*)HTMLWINDOW2(This);
416 HTMLWindow2_AddRef(iface);
420 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
422 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
423 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
427 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
429 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
430 FIXME("(%p)->(%p)\n", This, p);
434 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
436 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
437 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
441 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
443 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
444 FIXME("(%p)->(%p)\n", This, p);
448 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
449 LONG msec, VARIANT *language, LONG *timerID)
451 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
454 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
456 V_VT(&expr_var) = VT_BSTR;
457 V_BSTR(&expr_var) = expression;
459 return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
462 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
464 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
466 TRACE("(%p)->(%d)\n", This, timerID);
468 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
471 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
473 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
476 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
478 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
479 sizeof(wszTitle)/sizeof(WCHAR))) {
480 WARN("Could not load message box title: %d\n", GetLastError());
484 MessageBoxW(This->doc_obj->hwnd, message, wszTitle, MB_ICONWARNING);
488 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
489 VARIANT_BOOL *confirmed)
491 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
494 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
496 if(!confirmed) return E_INVALIDARG;
498 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
499 sizeof(wszTitle)/sizeof(WCHAR))) {
500 WARN("Could not load message box title: %d\n", GetLastError());
501 *confirmed = VARIANT_TRUE;
505 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
506 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
507 *confirmed = VARIANT_TRUE;
508 else *confirmed = VARIANT_FALSE;
520 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
521 WPARAM wparam, LPARAM lparam)
527 prompt_arg *arg = (prompt_arg*)lparam;
530 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
531 sizeof(wszTitle)/sizeof(WCHAR))) {
532 WARN("Could not load message box title: %d\n", GetLastError());
533 EndDialog(hwnd, wparam);
537 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
538 SetWindowTextW(hwnd, wszTitle);
539 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
540 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
546 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
547 EndDialog(hwnd, wparam);
549 case MAKEWPARAM(IDOK, BN_CLICKED):
552 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
553 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
554 INT len = GetWindowTextLengthW(hwndPrompt);
558 EndDialog(hwnd, wparam);
562 V_VT(arg->textdata) = VT_BSTR;
563 if(!len && !arg->dststr)
564 V_BSTR(arg->textdata) = NULL;
567 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
568 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
570 EndDialog(hwnd, wparam);
576 EndDialog(hwnd, IDCANCEL);
583 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
584 BSTR dststr, VARIANT *textdata)
586 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
589 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
591 if(textdata) V_VT(textdata) = VT_NULL;
593 arg.message = message;
595 arg.textdata = textdata;
597 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
598 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
602 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
604 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
606 TRACE("(%p)->(%p)\n", This, p);
608 if(!This->image_factory)
609 This->image_factory = HTMLImageElementFactory_Create(This);
611 *p = HTMLIMGFACTORY(This->image_factory);
612 IHTMLImageElementFactory_AddRef(*p);
617 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
619 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
620 HTMLLocation *location;
623 TRACE("(%p)->(%p)\n", This, p);
625 hres = get_location(This, &location);
629 *p = HTMLLOCATION(location);
633 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
635 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
636 FIXME("(%p)->(%p)\n", This, p);
640 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
642 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
643 FIXME("(%p)->()\n", This);
647 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
649 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
650 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
654 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
656 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
657 FIXME("(%p)->(%p)\n", This, p);
661 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
663 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
665 TRACE("(%p)->(%p)\n", This, p);
667 *p = OmNavigator_Create();
671 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
673 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
677 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
679 nsAString_Init(&name_str, v);
680 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
681 nsAString_Finish(&name_str);
683 ERR("SetName failed: %08x\n", nsres);
688 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
690 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
695 TRACE("(%p)->(%p)\n", This, p);
697 nsAString_Init(&name_str, NULL);
698 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
699 if(NS_SUCCEEDED(nsres)) {
700 const PRUnichar *name;
702 nsAString_GetData(&name_str, &name);
704 *p = SysAllocString(name);
705 hres = *p ? S_OK : E_OUTOFMEMORY;
711 ERR("GetName failed: %08x\n", nsres);
714 nsAString_Finish(&name_str);
719 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
721 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
722 TRACE("(%p)->(%p)\n", This, p);
725 *p = HTMLWINDOW2(This->parent);
726 IHTMLWindow2_AddRef(*p);
733 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
734 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
736 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
737 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
738 debugstr_w(features), replace, pomWindowResult);
742 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
744 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
746 TRACE("(%p)->(%p)\n", This, p);
748 /* FIXME: We should return kind of proxy window here. */
749 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
750 *p = HTMLWINDOW2(This);
754 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
756 HTMLWindow *This = HTMLWINDOW2_THIS(iface), *curr;
757 TRACE("(%p)->(%p)\n", This, p);
762 *p = HTMLWINDOW2(curr);
763 IHTMLWindow2_AddRef(*p);
768 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
770 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
772 TRACE("(%p)->(%p)\n", This, p);
774 /* FIXME: We should return kind of proxy window here. */
775 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
776 *p = HTMLWINDOW2(This);
780 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
782 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
783 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
787 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
789 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
790 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
794 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
796 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
797 FIXME("(%p)->(%p)\n", This, p);
801 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
803 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
804 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
808 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
810 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
811 FIXME("(%p)->(%p)\n", This, p);
815 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
817 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
819 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
821 return set_window_event(This, EVENTID_LOAD, &v);
824 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
826 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
828 TRACE("(%p)->(%p)\n", This, p);
830 return get_window_event(This, EVENTID_LOAD, p);
833 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
835 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
837 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
839 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
842 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
844 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
846 TRACE("(%p)->(%p)\n", This, p);
848 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
851 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
853 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
854 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
858 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
860 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
861 FIXME("(%p)->(%p)\n", This, p);
865 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
867 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
868 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
872 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
874 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
875 FIXME("(%p)->(%p)\n", This, p);
879 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
881 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
882 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
886 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
888 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
889 FIXME("(%p)->(%p)\n", This, p);
893 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
895 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
897 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
899 return set_window_event(This, EVENTID_RESIZE, &v);
902 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
904 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
906 TRACE("(%p)->(%p)\n", This, p);
908 return get_window_event(This, EVENTID_RESIZE, p);
911 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
913 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
914 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
918 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
920 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
921 FIXME("(%p)->(%p)\n", This, p);
925 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
927 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
929 TRACE("(%p)->(%p)\n", This, p);
932 /* FIXME: We should return a wrapper object here */
933 *p = HTMLDOC(&This->doc->basedoc);
934 IHTMLDocument2_AddRef(*p);
942 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
944 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
946 TRACE("(%p)->(%p)\n", This, p);
949 IHTMLEventObj_AddRef(This->event);
954 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
956 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
957 FIXME("(%p)->(%p)\n", This, p);
961 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
962 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
964 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
965 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
969 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
972 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
973 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
977 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
979 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
981 TRACE("(%p)->(%p)\n", This, p);
986 hres = HTMLScreen_Create(&This->screen);
992 IHTMLScreen_AddRef(This->screen);
996 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
998 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1000 TRACE("(%p)->(%p)\n", This, p);
1002 if(!This->option_factory)
1003 This->option_factory = HTMLOptionElementFactory_Create(This);
1005 *p = HTMLOPTFACTORY(This->option_factory);
1006 IHTMLOptionElementFactory_AddRef(*p);
1011 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1013 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1014 FIXME("(%p)->()\n", This);
1018 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1020 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, p);
1025 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1027 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1028 FIXME("(%p)->()\n", This);
1032 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1034 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1035 FIXME("(%p)->(%d %d)\n", This, x, y);
1039 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1041 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1042 FIXME("(%p)->(%p)\n", This, p);
1046 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1047 LONG msec, VARIANT *language, LONG *timerID)
1049 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1052 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1054 V_VT(&expr) = VT_BSTR;
1055 V_BSTR(&expr) = expression;
1056 return IHTMLWindow3_setInterval(HTMLWINDOW3(This), &expr, msec, language, timerID);
1059 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1061 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1063 TRACE("(%p)->(%d)\n", This, timerID);
1065 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1068 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1070 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1071 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1075 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1077 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1082 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1085 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1086 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1090 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1092 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1094 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1096 TRACE("(%p)->(%p)\n", This, String);
1099 return E_INVALIDARG;
1101 *String = SysAllocString(objectW);
1102 return *String ? S_OK : E_OUTOFMEMORY;
1105 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1107 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1110 TRACE("(%p)->(%d %d)\n", This, x, y);
1112 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1113 if(NS_FAILED(nsres))
1114 ERR("ScrollBy failed: %08x\n", nsres);
1119 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1121 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1124 TRACE("(%p)->(%d %d)\n", This, x, y);
1126 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1127 if(NS_FAILED(nsres))
1128 ERR("ScrollTo failed: %08x\n", nsres);
1133 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1135 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1136 FIXME("(%p)->(%d %d)\n", This, x, y);
1140 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1142 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1143 FIXME("(%p)->(%d %d)\n", This, x, y);
1147 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1149 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1150 FIXME("(%p)->(%d %d)\n", This, x, y);
1154 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1156 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1157 FIXME("(%p)->(%d %d)\n", This, x, y);
1161 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1163 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1165 TRACE("(%p)->(%p)\n", This, p);
1169 if(!This->doc_obj->hostui)
1172 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1175 static HRESULT HTMLWindow_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1176 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1178 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1179 global_prop_t *prop;
1183 idx = id - MSHTML_DISPID_CUSTOM_MIN;
1184 if(idx >= This->global_prop_cnt)
1185 return DISP_E_MEMBERNOTFOUND;
1187 prop = This->global_props+idx;
1189 switch(prop->type) {
1190 case GLOBAL_SCRIPTVAR: {
1191 IDispatchEx *dispex;
1194 disp = get_script_disp(prop->script_host);
1196 return E_UNEXPECTED;
1198 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1199 if(SUCCEEDED(hres)) {
1200 TRACE("%s >>>\n", debugstr_w(prop->name));
1201 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
1203 TRACE("%s <<<\n", debugstr_w(prop->name));
1205 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
1206 IDispatchEx_Release(dispex);
1208 FIXME("No IDispatchEx\n");
1210 IDispatch_Release(disp);
1213 case GLOBAL_ELEMENTVAR: {
1216 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), prop->name, &elem);
1221 return DISP_E_MEMBERNOTFOUND;
1223 V_VT(res) = VT_DISPATCH;
1224 V_DISPATCH(res) = (IDispatch*)elem;
1228 ERR("invalid type %d\n", prop->type);
1229 hres = DISP_E_MEMBERNOTFOUND;
1235 #undef HTMLWINDOW2_THIS
1237 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1238 HTMLWindow2_QueryInterface,
1240 HTMLWindow2_Release,
1241 HTMLWindow2_GetTypeInfoCount,
1242 HTMLWindow2_GetTypeInfo,
1243 HTMLWindow2_GetIDsOfNames,
1246 HTMLWindow2_get_length,
1247 HTMLWindow2_get_frames,
1248 HTMLWindow2_put_defaultStatus,
1249 HTMLWindow2_get_defaultStatus,
1250 HTMLWindow2_put_status,
1251 HTMLWindow2_get_status,
1252 HTMLWindow2_setTimeout,
1253 HTMLWindow2_clearTimeout,
1255 HTMLWindow2_confirm,
1257 HTMLWindow2_get_Image,
1258 HTMLWindow2_get_location,
1259 HTMLWindow2_get_history,
1261 HTMLWindow2_put_opener,
1262 HTMLWindow2_get_opener,
1263 HTMLWindow2_get_navigator,
1264 HTMLWindow2_put_name,
1265 HTMLWindow2_get_name,
1266 HTMLWindow2_get_parent,
1268 HTMLWindow2_get_self,
1269 HTMLWindow2_get_top,
1270 HTMLWindow2_get_window,
1271 HTMLWindow2_navigate,
1272 HTMLWindow2_put_onfocus,
1273 HTMLWindow2_get_onfocus,
1274 HTMLWindow2_put_onblur,
1275 HTMLWindow2_get_onblur,
1276 HTMLWindow2_put_onload,
1277 HTMLWindow2_get_onload,
1278 HTMLWindow2_put_onbeforeunload,
1279 HTMLWindow2_get_onbeforeunload,
1280 HTMLWindow2_put_onunload,
1281 HTMLWindow2_get_onunload,
1282 HTMLWindow2_put_onhelp,
1283 HTMLWindow2_get_onhelp,
1284 HTMLWindow2_put_onerror,
1285 HTMLWindow2_get_onerror,
1286 HTMLWindow2_put_onresize,
1287 HTMLWindow2_get_onresize,
1288 HTMLWindow2_put_onscroll,
1289 HTMLWindow2_get_onscroll,
1290 HTMLWindow2_get_document,
1291 HTMLWindow2_get_event,
1292 HTMLWindow2_get__newEnum,
1293 HTMLWindow2_showModalDialog,
1294 HTMLWindow2_showHelp,
1295 HTMLWindow2_get_screen,
1296 HTMLWindow2_get_Option,
1298 HTMLWindow2_get_closed,
1301 HTMLWindow2_get_clientInformation,
1302 HTMLWindow2_setInterval,
1303 HTMLWindow2_clearInterval,
1304 HTMLWindow2_put_offscreenBuffering,
1305 HTMLWindow2_get_offscreenBuffering,
1306 HTMLWindow2_execScript,
1307 HTMLWindow2_toString,
1308 HTMLWindow2_scrollBy,
1309 HTMLWindow2_scrollTo,
1312 HTMLWindow2_resizeTo,
1313 HTMLWindow2_resizeBy,
1314 HTMLWindow2_get_external
1317 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
1319 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1321 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1323 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1326 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1328 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1330 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1333 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1335 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1337 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1340 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1342 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1344 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1347 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1348 LCID lcid, ITypeInfo **ppTInfo)
1350 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1352 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1355 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1356 LPOLESTR *rgszNames, UINT cNames,
1357 LCID lcid, DISPID *rgDispId)
1359 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1361 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1364 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1365 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1366 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1368 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1370 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1371 pVarResult, pExcepInfo, puArgErr);
1374 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1376 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1377 FIXME("(%p)->(%p)\n", This, p);
1381 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1383 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1384 FIXME("(%p)->(%p)\n", This, p);
1388 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1390 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1392 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1394 return attach_event(&This->event_target, &This->doc_obj->basedoc, event, pDisp, pfResult);
1397 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1399 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1400 FIXME("(%p)->()\n", This);
1404 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1405 BOOL interval, LONG *timer_id)
1407 IDispatch *disp = NULL;
1409 switch(V_VT(expr)) {
1411 disp = V_DISPATCH(expr);
1412 IDispatch_AddRef(disp);
1416 disp = script_parse_event(This, V_BSTR(expr));
1420 FIXME("unimplemented vt=%d\n", V_VT(expr));
1427 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1428 IDispatch_Release(disp);
1433 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1434 VARIANT *language, LONG *timerID)
1436 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1438 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1440 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1443 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1444 VARIANT *language, LONG *timerID)
1446 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1448 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1450 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1453 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1455 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1456 FIXME("(%p)\n", This);
1460 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1462 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1463 FIXME("(%p)->()\n", This);
1467 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1469 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1470 FIXME("(%p)->(%p)\n", This, p);
1474 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1476 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1477 FIXME("(%p)->()\n", This);
1481 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1483 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1484 FIXME("(%p)->(%p)\n", This, p);
1488 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1490 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1491 FIXME("(%p)->(%p)\n", This, p);
1495 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1496 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1498 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1499 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1503 #undef HTMLWINDOW3_THIS
1505 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1506 HTMLWindow3_QueryInterface,
1508 HTMLWindow3_Release,
1509 HTMLWindow3_GetTypeInfoCount,
1510 HTMLWindow3_GetTypeInfo,
1511 HTMLWindow3_GetIDsOfNames,
1513 HTMLWindow3_get_screenLeft,
1514 HTMLWindow3_get_screenTop,
1515 HTMLWindow3_attachEvent,
1516 HTMLWindow3_detachEvent,
1517 HTMLWindow3_setTimeout,
1518 HTMLWindow3_setInterval,
1520 HTMLWindow3_put_onbeforeprint,
1521 HTMLWindow3_get_onbeforeprint,
1522 HTMLWindow3_put_onafterprint,
1523 HTMLWindow3_get_onafterprint,
1524 HTMLWindow3_get_clipboardData,
1525 HTMLWindow3_showModelessDialog
1528 #define HTMLWINDOW4_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow4, iface)
1530 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1532 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1534 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1537 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1539 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1541 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1544 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1546 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1548 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1551 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1553 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1555 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1558 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1559 LCID lcid, ITypeInfo **ppTInfo)
1561 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1563 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1566 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1567 LPOLESTR *rgszNames, UINT cNames,
1568 LCID lcid, DISPID *rgDispId)
1570 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1572 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1575 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1576 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1577 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1579 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1581 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1582 pVarResult, pExcepInfo, puArgErr);
1585 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1586 IDispatch **ppPopup)
1588 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1589 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1593 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1595 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1596 TRACE("(%p)->(%p)\n", This, p);
1598 if(This->frame_element) {
1599 *p = HTMLFRAMEBASE(This->frame_element);
1600 IHTMLFrameBase_AddRef(*p);
1607 #undef HTMLWINDOW4_THIS
1609 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1610 HTMLWindow4_QueryInterface,
1612 HTMLWindow4_Release,
1613 HTMLWindow4_GetTypeInfoCount,
1614 HTMLWindow4_GetTypeInfo,
1615 HTMLWindow4_GetIDsOfNames,
1617 HTMLWindow4_createPopup,
1618 HTMLWindow4_get_frameElement
1621 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1623 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1625 HTMLWindow *This = DISPEX_THIS(iface);
1627 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1630 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1632 HTMLWindow *This = DISPEX_THIS(iface);
1634 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1637 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1639 HTMLWindow *This = DISPEX_THIS(iface);
1641 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1644 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1646 HTMLWindow *This = DISPEX_THIS(iface);
1648 TRACE("(%p)->(%p)\n", This, pctinfo);
1650 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1653 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1654 LCID lcid, ITypeInfo **ppTInfo)
1656 HTMLWindow *This = DISPEX_THIS(iface);
1658 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1660 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1663 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1664 LPOLESTR *rgszNames, UINT cNames,
1665 LCID lcid, DISPID *rgDispId)
1667 HTMLWindow *This = DISPEX_THIS(iface);
1669 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1672 /* FIXME: Use script dispatch */
1674 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1677 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1678 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1679 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1681 HTMLWindow *This = DISPEX_THIS(iface);
1683 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1684 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1686 /* FIXME: Use script dispatch */
1688 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1689 pVarResult, pExcepInfo, puArgErr);
1692 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1694 if(This->global_prop_cnt == This->global_prop_size) {
1695 global_prop_t *new_props;
1698 if(This->global_props) {
1699 new_size = This->global_prop_size*2;
1700 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1703 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1707 This->global_props = new_props;
1708 This->global_prop_size = new_size;
1711 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1712 if(!This->global_props[This->global_prop_cnt].name)
1715 This->global_props[This->global_prop_cnt].type = type;
1716 return This->global_props + This->global_prop_cnt++;
1719 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1721 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1724 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1727 ScriptHost *script_host;
1730 for(i=0; i < This->global_prop_cnt; i++) {
1731 /* FIXME: case sensitivity */
1732 if(!strcmpW(This->global_props[i].name, bstrName)) {
1733 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1738 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1739 global_prop_t *prop;
1741 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1743 return E_OUTOFMEMORY;
1745 prop->script_host = script_host;
1748 *pid = prop_to_dispid(This, prop);
1752 return DISP_E_UNKNOWNNAME;
1755 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1757 HTMLWindow *This = DISPEX_THIS(iface);
1760 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1762 hres = search_window_props(This, bstrName, grfdex, pid);
1763 if(hres != DISP_E_UNKNOWNNAME)
1766 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1767 if(hres != DISP_E_UNKNOWNNAME)
1771 global_prop_t *prop;
1774 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), bstrName, &elem);
1775 if(SUCCEEDED(hres) && elem) {
1776 IHTMLElement_Release(elem);
1778 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1780 return E_OUTOFMEMORY;
1782 *pid = prop_to_dispid(This, prop);
1787 return DISP_E_UNKNOWNNAME;
1790 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1791 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1793 HTMLWindow *This = DISPEX_THIS(iface);
1795 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1797 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1798 HTMLLocation *location;
1801 TRACE("forwarding to location.href\n");
1803 hres = get_location(This, &location);
1807 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1808 IHTMLLocation_Release(HTMLLOCATION(location));
1812 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1815 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1817 HTMLWindow *This = DISPEX_THIS(iface);
1819 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
1821 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1824 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1826 HTMLWindow *This = DISPEX_THIS(iface);
1828 TRACE("(%p)->(%x)\n", This, id);
1830 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1833 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1835 HTMLWindow *This = DISPEX_THIS(iface);
1837 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
1839 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1842 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1844 HTMLWindow *This = DISPEX_THIS(iface);
1846 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
1848 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1851 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1853 HTMLWindow *This = DISPEX_THIS(iface);
1855 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
1857 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1860 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1862 HTMLWindow *This = DISPEX_THIS(iface);
1864 TRACE("(%p)->(%p)\n", This, ppunk);
1872 static const IDispatchExVtbl WindowDispExVtbl = {
1873 WindowDispEx_QueryInterface,
1874 WindowDispEx_AddRef,
1875 WindowDispEx_Release,
1876 WindowDispEx_GetTypeInfoCount,
1877 WindowDispEx_GetTypeInfo,
1878 WindowDispEx_GetIDsOfNames,
1879 WindowDispEx_Invoke,
1880 WindowDispEx_GetDispID,
1881 WindowDispEx_InvokeEx,
1882 WindowDispEx_DeleteMemberByName,
1883 WindowDispEx_DeleteMemberByDispID,
1884 WindowDispEx_GetMemberProperties,
1885 WindowDispEx_GetMemberName,
1886 WindowDispEx_GetNextDispID,
1887 WindowDispEx_GetNameSpaceParent
1890 static const tid_t HTMLWindow_iface_tids[] = {
1897 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
1903 static dispex_static_data_t HTMLWindow_dispex = {
1904 &HTMLWindow_dispex_vtbl,
1905 DispHTMLWindow2_tid,
1907 HTMLWindow_iface_tids
1910 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
1914 window = heap_alloc_zero(sizeof(HTMLWindow));
1916 return E_OUTOFMEMORY;
1918 window->window_ref = heap_alloc(sizeof(windowref_t));
1919 if(!window->window_ref) {
1921 return E_OUTOFMEMORY;
1924 window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
1925 window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
1926 window->lpHTMLWindow4Vtbl = &HTMLWindow4Vtbl;
1927 window->lpIDispatchExVtbl = &WindowDispExVtbl;
1929 window->doc_obj = doc_obj;
1931 window->window_ref->window = window;
1932 window->window_ref->ref = 1;
1934 init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex);
1937 nsIDOMWindow_AddRef(nswindow);
1938 window->nswindow = nswindow;
1941 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
1942 window->readystate = READYSTATE_UNINITIALIZED;
1943 list_init(&window->script_hosts);
1945 window->task_magic = get_task_target_magic();
1946 update_window_doc(window);
1948 list_init(&window->children);
1949 list_add_head(&window_list, &window->entry);
1952 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
1954 window->parent = parent;
1955 list_add_tail(&parent->children, &window->sibling_entry);
1962 void update_window_doc(HTMLWindow *window)
1964 nsIDOMHTMLDocument *nshtmldoc;
1965 nsIDOMDocument *nsdoc;
1968 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
1969 if(NS_FAILED(nsres) || !nsdoc) {
1970 ERR("GetDocument failed: %08x\n", nsres);
1974 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
1975 nsIDOMDocument_Release(nsdoc);
1976 if(NS_FAILED(nsres)) {
1977 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
1981 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
1982 HTMLDocumentNode *doc;
1985 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
1986 if(SUCCEEDED(hres)) {
1987 window_set_docnode(window, doc);
1988 htmldoc_release(&doc->basedoc);
1990 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
1994 nsIDOMHTMLDocument_Release(nshtmldoc);
1997 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2001 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2002 if(iter->nswindow == nswindow)