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 #define NO_SHLWAPI_REG
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static struct list window_list = LIST_INIT(window_list);
44 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
47 if(window->doc_obj && window == window->doc_obj->basedoc.window)
48 window->doc->basedoc.cp_container.forward_container = NULL;
49 abort_document_bindings(window->doc);
50 window->doc->basedoc.window = NULL;
51 htmldoc_release(&window->doc->basedoc);
53 window->doc = doc_node;
55 htmldoc_addref(&doc_node->basedoc);
57 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
58 if(window->doc_obj->basedoc.doc_node)
59 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
60 window->doc_obj->basedoc.doc_node = doc_node;
62 htmldoc_addref(&doc_node->basedoc);
65 if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
66 nsIDOMNSHTMLDocument *nshtmldoc;
70 static const PRUnichar onW[] = {'o','n',0};
72 nsres = nsIDOMHTMLDocument_QueryInterface(doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
73 if(NS_SUCCEEDED(nsres)) {
74 nsAString_Init(&mode_str, onW);
75 nsres = nsIDOMNSHTMLDocument_SetDesignMode(nshtmldoc, &mode_str);
76 nsAString_Finish(&mode_str);
77 nsIDOMNSHTMLDocument_Release(nshtmldoc);
79 ERR("SetDesignMode failed: %08x\n", nsres);
81 ERR("Could not get nsIDOMNSHTMLDocument interface: %08x\n", nsres);
86 static void release_children(HTMLWindow *This)
90 while(!list_empty(&This->children)) {
91 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
93 list_remove(&child->sibling_entry);
95 IHTMLWindow2_Release(&child->IHTMLWindow2_iface);
99 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
102 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
106 hres = HTMLLocation_Create(This, &This->location);
111 *ret = This->location;
115 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
118 FIXME("No document\n");
122 return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
125 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
128 FIXME("No document\n");
132 return get_event_handler(&window->doc->body_event_target, eid, var);
135 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
137 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
140 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
142 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
146 if(IsEqualGUID(&IID_IUnknown, riid)) {
147 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
148 *ppv = &This->IHTMLWindow2_iface;
149 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
150 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
151 *ppv = &This->IHTMLWindow2_iface;
152 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
153 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
154 *ppv = &This->IDispatchEx_iface;
155 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
156 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
157 *ppv = &This->IHTMLWindow2_iface;
158 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
159 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
160 *ppv = &This->IHTMLWindow2_iface;
161 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
162 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
163 *ppv = &This->IHTMLWindow3_iface;
164 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
165 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
166 *ppv = &This->IHTMLWindow4_iface;
167 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
168 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
169 *ppv = &This->IHTMLPrivateWindow_iface;
170 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
171 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
172 *ppv = &This->IServiceProvider_iface;
173 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
174 return *ppv ? S_OK : E_NOINTERFACE;
178 IUnknown_AddRef((IUnknown*)*ppv);
182 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
183 return E_NOINTERFACE;
186 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
188 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
189 LONG ref = InterlockedIncrement(&This->ref);
191 TRACE("(%p) ref=%d\n", This, ref);
196 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
198 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
199 LONG ref = InterlockedDecrement(&This->ref);
201 TRACE("(%p) ref=%d\n", This, ref);
206 remove_target_tasks(This->task_magic);
207 set_window_bscallback(This, NULL);
208 set_current_mon(This, NULL);
209 window_set_docnode(This, NULL);
210 release_children(This);
213 IInternetSecurityManager_Release(This->secmgr);
215 if(This->frame_element)
216 This->frame_element->content_window = NULL;
218 if(This->option_factory) {
219 This->option_factory->window = NULL;
220 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
223 if(This->image_factory) {
224 This->image_factory->window = NULL;
225 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
229 This->location->window = NULL;
230 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
234 IHTMLScreen_Release(This->screen);
236 for(i=0; i < This->global_prop_cnt; i++)
237 heap_free(This->global_props[i].name);
239 This->window_ref->window = NULL;
240 windowref_release(This->window_ref);
242 heap_free(This->global_props);
243 release_script_hosts(This);
246 nsIDOMWindow_Release(This->nswindow);
248 list_remove(&This->entry);
249 release_dispex(&This->dispex);
256 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
258 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
260 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
263 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
264 LCID lcid, ITypeInfo **ppTInfo)
266 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
268 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
271 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
272 LPOLESTR *rgszNames, UINT cNames,
273 LCID lcid, DISPID *rgDispId)
275 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
277 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
281 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
282 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
283 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
285 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
287 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
288 pDispParams, pVarResult, pExcepInfo, puArgErr);
291 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
294 nsIDOMWindow *nsWindow;
297 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
298 if(NS_FAILED(nsres)) {
299 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
304 return DISP_E_MEMBERNOTFOUND;
306 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
307 if(NS_FAILED(nsres)) {
308 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
312 *ret = nswindow_to_window(nsWindow);
314 nsIDOMWindow_Release(nsWindow);
319 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
321 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
322 nsIDOMWindowCollection *nsFrames;
327 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
329 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
330 if(NS_FAILED(nsres)) {
331 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
335 if(V_VT(pvarIndex) == VT_I4) {
336 int index = V_I4(pvarIndex);
337 TRACE("Getting index %d\n", index);
339 hres = DISP_E_MEMBERNOTFOUND;
342 hres = get_frame_by_index(nsFrames, index, &window);
345 }else if(V_VT(pvarIndex) == VT_UINT) {
346 unsigned int index = V_UINT(pvarIndex);
347 TRACE("Getting index %u\n", index);
348 hres = get_frame_by_index(nsFrames, index, &window);
351 }else if(V_VT(pvarIndex) == VT_BSTR) {
352 BSTR str = V_BSTR(pvarIndex);
355 TRACE("Getting name %s\n", wine_dbgstr_w(str));
357 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
360 for(i = 0; i < length && !window; ++i) {
361 HTMLWindow *cur_window;
362 nsIDOMWindow *nsWindow;
365 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
366 if(NS_FAILED(nsres)) {
367 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
372 cur_window = nswindow_to_window(nsWindow);
374 nsIDOMWindow_Release(nsWindow);
376 hres = IHTMLElement_get_id(&cur_window->frame_element->element.IHTMLElement_iface, &id);
378 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
382 if(!strcmpW(id, str))
389 hres = DISP_E_MEMBERNOTFOUND;
397 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
398 V_VT(pvarResult) = VT_DISPATCH;
399 V_DISPATCH(pvarResult) = (IDispatch*)window;
404 nsIDOMWindowCollection_Release(nsFrames);
409 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
411 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
412 nsIDOMWindowCollection *nscollection;
416 TRACE("(%p)->(%p)\n", This, p);
418 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
419 if(NS_FAILED(nsres)) {
420 ERR("GetFrames failed: %08x\n", nsres);
424 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
425 nsIDOMWindowCollection_Release(nscollection);
426 if(NS_FAILED(nsres)) {
427 ERR("GetLength failed: %08x\n", nsres);
435 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
437 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
438 FIXME("(%p)->(%p): semi-stub\n", This, p);
440 /* FIXME: Should return a separate Window object */
441 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
442 HTMLWindow2_AddRef(iface);
446 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
448 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
449 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
453 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
455 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
456 FIXME("(%p)->(%p)\n", This, p);
460 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
462 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
464 WARN("(%p)->(%s)\n", This, debugstr_w(v));
467 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
468 * Ignoring the call should be enough for us.
473 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
475 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
477 TRACE("(%p)->(%p)\n", This, p);
484 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
485 LONG msec, VARIANT *language, LONG *timerID)
487 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
490 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
492 V_VT(&expr_var) = VT_BSTR;
493 V_BSTR(&expr_var) = expression;
495 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
498 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
500 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
502 TRACE("(%p)->(%d)\n", This, timerID);
504 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
507 #define MAX_MESSAGE_LEN 2000
509 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
511 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
512 WCHAR title[100], *msg = message;
515 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
517 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
518 sizeof(title)/sizeof(WCHAR))) {
519 WARN("Could not load message box title: %d\n", GetLastError());
523 len = SysStringLen(message);
524 if(len > MAX_MESSAGE_LEN) {
525 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
527 return E_OUTOFMEMORY;
528 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
529 msg[MAX_MESSAGE_LEN] = 0;
532 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
538 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
539 VARIANT_BOOL *confirmed)
541 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
544 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
546 if(!confirmed) return E_INVALIDARG;
548 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
549 sizeof(wszTitle)/sizeof(WCHAR))) {
550 WARN("Could not load message box title: %d\n", GetLastError());
551 *confirmed = VARIANT_TRUE;
555 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
556 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
557 *confirmed = VARIANT_TRUE;
558 else *confirmed = VARIANT_FALSE;
570 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
571 WPARAM wparam, LPARAM lparam)
577 prompt_arg *arg = (prompt_arg*)lparam;
580 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
581 sizeof(wszTitle)/sizeof(WCHAR))) {
582 WARN("Could not load message box title: %d\n", GetLastError());
583 EndDialog(hwnd, wparam);
587 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
588 SetWindowTextW(hwnd, wszTitle);
589 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
590 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
596 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
597 EndDialog(hwnd, wparam);
599 case MAKEWPARAM(IDOK, BN_CLICKED):
602 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
603 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
604 INT len = GetWindowTextLengthW(hwndPrompt);
608 EndDialog(hwnd, wparam);
612 V_VT(arg->textdata) = VT_BSTR;
613 if(!len && !arg->dststr)
614 V_BSTR(arg->textdata) = NULL;
617 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
618 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
620 EndDialog(hwnd, wparam);
626 EndDialog(hwnd, IDCANCEL);
633 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
634 BSTR dststr, VARIANT *textdata)
636 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
639 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
641 if(textdata) V_VT(textdata) = VT_NULL;
643 arg.message = message;
645 arg.textdata = textdata;
647 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
648 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
652 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
654 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
656 TRACE("(%p)->(%p)\n", This, p);
658 if(!This->image_factory)
659 This->image_factory = HTMLImageElementFactory_Create(This);
661 *p = &This->image_factory->IHTMLImageElementFactory_iface;
662 IHTMLImageElementFactory_AddRef(*p);
667 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
669 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
670 HTMLLocation *location;
673 TRACE("(%p)->(%p)\n", This, p);
675 hres = get_location(This, &location);
679 *p = &location->IHTMLLocation_iface;
683 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
685 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
686 FIXME("(%p)->(%p)\n", This, p);
690 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
692 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
693 FIXME("(%p)->()\n", This);
697 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
699 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
700 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
704 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
706 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
707 FIXME("(%p)->(%p)\n", This, p);
711 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
713 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
715 TRACE("(%p)->(%p)\n", This, p);
717 *p = OmNavigator_Create();
721 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
723 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
727 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
729 nsAString_InitDepend(&name_str, v);
730 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
731 nsAString_Finish(&name_str);
733 ERR("SetName failed: %08x\n", nsres);
738 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
740 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
745 TRACE("(%p)->(%p)\n", This, p);
747 nsAString_Init(&name_str, NULL);
748 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
749 if(NS_SUCCEEDED(nsres)) {
750 const PRUnichar *name;
752 nsAString_GetData(&name_str, &name);
754 *p = SysAllocString(name);
755 hres = *p ? S_OK : E_OUTOFMEMORY;
761 ERR("GetName failed: %08x\n", nsres);
764 nsAString_Finish(&name_str);
769 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
771 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
772 TRACE("(%p)->(%p)\n", This, p);
775 *p = &This->parent->IHTMLWindow2_iface;
776 IHTMLWindow2_AddRef(*p);
783 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
784 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
786 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
787 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
788 debugstr_w(features), replace, pomWindowResult);
792 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
794 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
796 TRACE("(%p)->(%p)\n", This, p);
798 /* FIXME: We should return kind of proxy window here. */
799 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
800 *p = &This->IHTMLWindow2_iface;
804 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
806 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
808 TRACE("(%p)->(%p)\n", This, p);
813 *p = &curr->IHTMLWindow2_iface;
814 IHTMLWindow2_AddRef(*p);
819 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
821 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
823 TRACE("(%p)->(%p)\n", This, p);
825 /* FIXME: We should return kind of proxy window here. */
826 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
827 *p = &This->IHTMLWindow2_iface;
831 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
833 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
834 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
838 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
840 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
841 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
845 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
847 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
848 FIXME("(%p)->(%p)\n", This, p);
852 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
854 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
855 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
859 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
861 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
862 FIXME("(%p)->(%p)\n", This, p);
866 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
868 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
870 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
872 return set_window_event(This, EVENTID_LOAD, &v);
875 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
877 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
879 TRACE("(%p)->(%p)\n", This, p);
881 return get_window_event(This, EVENTID_LOAD, p);
884 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
886 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
888 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
890 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
893 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
895 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
897 TRACE("(%p)->(%p)\n", This, p);
899 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
902 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
904 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
905 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
909 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
911 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
912 FIXME("(%p)->(%p)\n", This, p);
916 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
918 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
919 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
923 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
925 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
926 FIXME("(%p)->(%p)\n", This, p);
930 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
932 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
933 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
937 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
939 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
940 FIXME("(%p)->(%p)\n", This, p);
944 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
946 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
948 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
950 return set_window_event(This, EVENTID_RESIZE, &v);
953 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
955 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
957 TRACE("(%p)->(%p)\n", This, p);
959 return get_window_event(This, EVENTID_RESIZE, p);
962 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
964 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
965 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
969 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
971 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
972 FIXME("(%p)->(%p)\n", This, p);
976 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
978 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
980 TRACE("(%p)->(%p)\n", This, p);
983 /* FIXME: We should return a wrapper object here */
984 *p = &This->doc->basedoc.IHTMLDocument2_iface;
985 IHTMLDocument2_AddRef(*p);
993 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
995 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
997 TRACE("(%p)->(%p)\n", This, p);
1000 IHTMLEventObj_AddRef(This->event);
1005 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1007 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1008 FIXME("(%p)->(%p)\n", This, p);
1012 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1013 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1015 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1016 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1020 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1023 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1024 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1028 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1030 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1032 TRACE("(%p)->(%p)\n", This, p);
1037 hres = HTMLScreen_Create(&This->screen);
1043 IHTMLScreen_AddRef(This->screen);
1047 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1049 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1051 TRACE("(%p)->(%p)\n", This, p);
1053 if(!This->option_factory)
1054 This->option_factory = HTMLOptionElementFactory_Create(This);
1056 *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1057 IHTMLOptionElementFactory_AddRef(*p);
1062 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1064 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1066 TRACE("(%p)->()\n", This);
1069 SetFocus(This->doc_obj->hwnd);
1073 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1075 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1076 FIXME("(%p)->(%p)\n", This, p);
1080 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1082 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1083 FIXME("(%p)->()\n", This);
1087 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1089 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1090 FIXME("(%p)->(%d %d)\n", This, x, y);
1094 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1096 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1097 FIXME("(%p)->(%p)\n", This, p);
1101 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1102 LONG msec, VARIANT *language, LONG *timerID)
1104 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1107 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1109 V_VT(&expr) = VT_BSTR;
1110 V_BSTR(&expr) = expression;
1111 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1114 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1116 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1118 TRACE("(%p)->(%d)\n", This, timerID);
1120 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1123 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1125 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1126 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1130 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1132 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1133 FIXME("(%p)->(%p)\n", This, p);
1137 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1140 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1142 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1144 return exec_script(This, scode, language, pvarRet);
1147 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1149 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1151 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1153 TRACE("(%p)->(%p)\n", This, String);
1156 return E_INVALIDARG;
1158 *String = SysAllocString(objectW);
1159 return *String ? S_OK : E_OUTOFMEMORY;
1162 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1164 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1167 TRACE("(%p)->(%d %d)\n", This, x, y);
1169 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1170 if(NS_FAILED(nsres))
1171 ERR("ScrollBy failed: %08x\n", nsres);
1176 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1178 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1181 TRACE("(%p)->(%d %d)\n", This, x, y);
1183 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1184 if(NS_FAILED(nsres))
1185 ERR("ScrollTo failed: %08x\n", nsres);
1190 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1192 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1193 FIXME("(%p)->(%d %d)\n", This, x, y);
1197 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1199 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1200 FIXME("(%p)->(%d %d)\n", This, x, y);
1204 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1206 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1207 FIXME("(%p)->(%d %d)\n", This, x, y);
1211 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1213 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1214 FIXME("(%p)->(%d %d)\n", This, x, y);
1218 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1220 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1222 TRACE("(%p)->(%p)\n", This, p);
1226 if(!This->doc_obj->hostui)
1229 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1232 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1233 HTMLWindow2_QueryInterface,
1235 HTMLWindow2_Release,
1236 HTMLWindow2_GetTypeInfoCount,
1237 HTMLWindow2_GetTypeInfo,
1238 HTMLWindow2_GetIDsOfNames,
1241 HTMLWindow2_get_length,
1242 HTMLWindow2_get_frames,
1243 HTMLWindow2_put_defaultStatus,
1244 HTMLWindow2_get_defaultStatus,
1245 HTMLWindow2_put_status,
1246 HTMLWindow2_get_status,
1247 HTMLWindow2_setTimeout,
1248 HTMLWindow2_clearTimeout,
1250 HTMLWindow2_confirm,
1252 HTMLWindow2_get_Image,
1253 HTMLWindow2_get_location,
1254 HTMLWindow2_get_history,
1256 HTMLWindow2_put_opener,
1257 HTMLWindow2_get_opener,
1258 HTMLWindow2_get_navigator,
1259 HTMLWindow2_put_name,
1260 HTMLWindow2_get_name,
1261 HTMLWindow2_get_parent,
1263 HTMLWindow2_get_self,
1264 HTMLWindow2_get_top,
1265 HTMLWindow2_get_window,
1266 HTMLWindow2_navigate,
1267 HTMLWindow2_put_onfocus,
1268 HTMLWindow2_get_onfocus,
1269 HTMLWindow2_put_onblur,
1270 HTMLWindow2_get_onblur,
1271 HTMLWindow2_put_onload,
1272 HTMLWindow2_get_onload,
1273 HTMLWindow2_put_onbeforeunload,
1274 HTMLWindow2_get_onbeforeunload,
1275 HTMLWindow2_put_onunload,
1276 HTMLWindow2_get_onunload,
1277 HTMLWindow2_put_onhelp,
1278 HTMLWindow2_get_onhelp,
1279 HTMLWindow2_put_onerror,
1280 HTMLWindow2_get_onerror,
1281 HTMLWindow2_put_onresize,
1282 HTMLWindow2_get_onresize,
1283 HTMLWindow2_put_onscroll,
1284 HTMLWindow2_get_onscroll,
1285 HTMLWindow2_get_document,
1286 HTMLWindow2_get_event,
1287 HTMLWindow2_get__newEnum,
1288 HTMLWindow2_showModalDialog,
1289 HTMLWindow2_showHelp,
1290 HTMLWindow2_get_screen,
1291 HTMLWindow2_get_Option,
1293 HTMLWindow2_get_closed,
1296 HTMLWindow2_get_clientInformation,
1297 HTMLWindow2_setInterval,
1298 HTMLWindow2_clearInterval,
1299 HTMLWindow2_put_offscreenBuffering,
1300 HTMLWindow2_get_offscreenBuffering,
1301 HTMLWindow2_execScript,
1302 HTMLWindow2_toString,
1303 HTMLWindow2_scrollBy,
1304 HTMLWindow2_scrollTo,
1307 HTMLWindow2_resizeTo,
1308 HTMLWindow2_resizeBy,
1309 HTMLWindow2_get_external
1312 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1314 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1317 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1319 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1321 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1324 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1326 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1328 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1331 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1333 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1335 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1338 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1340 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1342 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1345 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1346 LCID lcid, ITypeInfo **ppTInfo)
1348 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1350 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1353 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1354 LPOLESTR *rgszNames, UINT cNames,
1355 LCID lcid, DISPID *rgDispId)
1357 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1359 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1363 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1364 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1365 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1367 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1369 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1370 pDispParams, pVarResult, pExcepInfo, puArgErr);
1373 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1375 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1376 FIXME("(%p)->(%p)\n", This, p);
1380 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1382 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1383 FIXME("(%p)->(%p)\n", This, p);
1387 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1389 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1391 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1394 FIXME("No document\n");
1398 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1401 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1403 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1404 FIXME("(%p)->()\n", This);
1408 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1409 BOOL interval, LONG *timer_id)
1411 IDispatch *disp = NULL;
1413 switch(V_VT(expr)) {
1415 disp = V_DISPATCH(expr);
1416 IDispatch_AddRef(disp);
1420 disp = script_parse_event(This, V_BSTR(expr));
1424 FIXME("unimplemented vt=%d\n", V_VT(expr));
1431 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1432 IDispatch_Release(disp);
1437 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1438 VARIANT *language, LONG *timerID)
1440 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1442 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1444 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1447 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1448 VARIANT *language, LONG *timerID)
1450 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1452 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1454 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1457 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1459 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1460 FIXME("(%p)\n", This);
1464 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1466 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1467 FIXME("(%p)->()\n", This);
1471 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1473 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1474 FIXME("(%p)->(%p)\n", This, p);
1478 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1480 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1481 FIXME("(%p)->()\n", This);
1485 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1487 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1488 FIXME("(%p)->(%p)\n", This, p);
1492 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1494 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1495 FIXME("(%p)->(%p)\n", This, p);
1499 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1500 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1502 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1503 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1507 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1508 HTMLWindow3_QueryInterface,
1510 HTMLWindow3_Release,
1511 HTMLWindow3_GetTypeInfoCount,
1512 HTMLWindow3_GetTypeInfo,
1513 HTMLWindow3_GetIDsOfNames,
1515 HTMLWindow3_get_screenLeft,
1516 HTMLWindow3_get_screenTop,
1517 HTMLWindow3_attachEvent,
1518 HTMLWindow3_detachEvent,
1519 HTMLWindow3_setTimeout,
1520 HTMLWindow3_setInterval,
1522 HTMLWindow3_put_onbeforeprint,
1523 HTMLWindow3_get_onbeforeprint,
1524 HTMLWindow3_put_onafterprint,
1525 HTMLWindow3_get_onafterprint,
1526 HTMLWindow3_get_clipboardData,
1527 HTMLWindow3_showModelessDialog
1530 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1532 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1535 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1537 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1539 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1542 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1544 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1546 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1549 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1551 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1553 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1556 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1558 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1560 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1563 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1564 LCID lcid, ITypeInfo **ppTInfo)
1566 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1568 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1571 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1572 LPOLESTR *rgszNames, UINT cNames,
1573 LCID lcid, DISPID *rgDispId)
1575 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1577 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1581 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1582 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1583 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1585 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1587 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1588 pDispParams, pVarResult, pExcepInfo, puArgErr);
1591 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1592 IDispatch **ppPopup)
1594 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1595 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1599 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1601 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1602 TRACE("(%p)->(%p)\n", This, p);
1604 if(This->frame_element) {
1605 *p = &This->frame_element->IHTMLFrameBase_iface;
1606 IHTMLFrameBase_AddRef(*p);
1613 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1614 HTMLWindow4_QueryInterface,
1616 HTMLWindow4_Release,
1617 HTMLWindow4_GetTypeInfoCount,
1618 HTMLWindow4_GetTypeInfo,
1619 HTMLWindow4_GetIDsOfNames,
1621 HTMLWindow4_createPopup,
1622 HTMLWindow4_get_frameElement
1625 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1627 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1630 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1632 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1634 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1637 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1639 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1641 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1644 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1646 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1648 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1655 } navigate_javascript_task_t;
1657 static void navigate_javascript_proc(task_t *_task)
1659 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1660 HTMLWindow *window = task->window;
1665 static const WCHAR jscriptW[] = {'j','s','c','r','i','p','t',0};
1667 task->window->readystate = READYSTATE_COMPLETE;
1669 hres = IUri_GetPath(task->uri, &code);
1673 set_download_state(window->doc_obj, 1);
1675 V_VT(&v) = VT_EMPTY;
1676 hres = exec_script(window, code, jscriptW, &v);
1677 SysFreeString(code);
1678 if(SUCCEEDED(hres) && V_VT(&v) != VT_EMPTY) {
1679 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v));
1683 if(window->doc_obj->view_sink)
1684 IAdviseSink_OnViewChange(window->doc_obj->view_sink, DVASPECT_CONTENT, -1);
1686 set_download_state(window->doc_obj, 0);
1689 static void navigate_javascript_task_destr(task_t *_task)
1691 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1693 IUri_Release(task->uri);
1700 nsChannelBSC *bscallback;
1704 static void navigate_proc(task_t *_task)
1706 navigate_task_t *task = (navigate_task_t*)_task;
1709 hres = set_moniker(&task->window->doc_obj->basedoc, task->mon, NULL, task->bscallback, TRUE);
1711 hres = start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
1715 static void navigate_task_destr(task_t *_task)
1717 navigate_task_t *task = (navigate_task_t*)_task;
1719 IUnknown_Release((IUnknown*)task->bscallback);
1720 IMoniker_Release(task->mon);
1724 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1725 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1727 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1728 DWORD post_data_size = 0;
1729 BYTE *post_data = NULL;
1730 WCHAR *headers = NULL;
1738 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1739 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1742 if(This->doc_obj->hostui) {
1743 OLECHAR *translated_url = NULL;
1745 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1746 if(hres == S_OK && translated_url) {
1747 new_url = SysAllocString(translated_url);
1748 CoTaskMemFree(translated_url);
1752 if(This->doc_obj->client) {
1753 IOleCommandTarget *cmdtrg;
1755 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1756 if(SUCCEEDED(hres)) {
1759 V_VT(&in) = VT_BSTR;
1760 V_BSTR(&in) = new_url;
1761 V_VT(&out) = VT_BOOL;
1762 V_BOOL(&out) = VARIANT_TRUE;
1763 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1764 IOleCommandTarget_Release(cmdtrg);
1770 hres = CreateUri(new_url, 0, 0, &uri);
1772 SysFreeString(new_url);
1776 hres = CreateURLMonikerEx2(NULL, uri, &mon, URL_MK_UNIFORM);
1780 /* FIXME: Why not set_ready_state? */
1781 This->readystate = READYSTATE_UNINITIALIZED;
1784 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1785 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1786 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1790 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1791 if(V_VT(headers_var) != VT_BSTR)
1792 return E_INVALIDARG;
1794 headers = V_BSTR(headers_var);
1797 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1799 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1801 IMoniker_Release(mon);
1805 prepare_for_binding(&This->doc_obj->basedoc, mon, NULL, TRUE);
1807 hres = IUri_GetScheme(uri, &scheme);
1809 if(scheme != URL_SCHEME_JAVASCRIPT) {
1810 navigate_task_t *task;
1814 task = heap_alloc(sizeof(*task));
1816 IUnknown_Release((IUnknown*)bsc);
1817 IMoniker_Release(mon);
1818 return E_OUTOFMEMORY;
1821 task->window = This;
1822 task->bscallback = bsc;
1824 push_task(&task->header, navigate_proc, navigate_task_destr, This->task_magic);
1826 /* Silently and repeated when real loading starts? */
1827 This->readystate = READYSTATE_LOADING;
1829 navigate_javascript_task_t *task;
1831 IUnknown_Release((IUnknown*)bsc);
1832 IMoniker_Release(mon);
1834 task = heap_alloc(sizeof(*task));
1837 return E_OUTOFMEMORY;
1840 task->window = This;
1842 push_task(&task->header, navigate_javascript_proc, navigate_javascript_task_destr, This->task_magic);
1845 This->readystate = READYSTATE_COMPLETE;
1851 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1853 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1854 FIXME("(%p)->(%p)\n", This, url);
1858 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1860 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1861 FIXME("(%p)->(%p)\n", This, cmdtrg);
1865 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1867 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1868 FIXME("(%p)->(%x)\n", This, arg);
1872 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1874 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1875 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1879 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1881 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1882 TRACE("(%p)->(%p)\n", This, url);
1885 return E_INVALIDARG;
1887 *url = SysAllocString(This->url);
1891 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1892 HTMLPrivateWindow_QueryInterface,
1893 HTMLPrivateWindow_AddRef,
1894 HTMLPrivateWindow_Release,
1895 HTMLPrivateWindow_SuperNavigate,
1896 HTMLPrivateWindow_GetPendingUrl,
1897 HTMLPrivateWindow_SetPICSTarget,
1898 HTMLPrivateWindow_PICSComplete,
1899 HTMLPrivateWindow_FindWindowByName,
1900 HTMLPrivateWindow_GetAddressBar
1903 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1905 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1908 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1910 HTMLWindow *This = impl_from_IDispatchEx(iface);
1912 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1915 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1917 HTMLWindow *This = impl_from_IDispatchEx(iface);
1919 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1922 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1924 HTMLWindow *This = impl_from_IDispatchEx(iface);
1926 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1929 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1931 HTMLWindow *This = impl_from_IDispatchEx(iface);
1933 TRACE("(%p)->(%p)\n", This, pctinfo);
1935 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1938 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1939 LCID lcid, ITypeInfo **ppTInfo)
1941 HTMLWindow *This = impl_from_IDispatchEx(iface);
1943 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1945 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1948 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1949 LPOLESTR *rgszNames, UINT cNames,
1950 LCID lcid, DISPID *rgDispId)
1952 HTMLWindow *This = impl_from_IDispatchEx(iface);
1956 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1959 for(i=0; i < cNames; i++) {
1960 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1961 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
1969 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1970 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1971 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1973 HTMLWindow *This = impl_from_IDispatchEx(iface);
1975 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1976 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1978 /* FIXME: Use script dispatch */
1980 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1981 pDispParams, pVarResult, pExcepInfo, puArgErr);
1984 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1986 if(This->global_prop_cnt == This->global_prop_size) {
1987 global_prop_t *new_props;
1990 if(This->global_props) {
1991 new_size = This->global_prop_size*2;
1992 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1995 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1999 This->global_props = new_props;
2000 This->global_prop_size = new_size;
2003 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
2004 if(!This->global_props[This->global_prop_cnt].name)
2007 This->global_props[This->global_prop_cnt].type = type;
2008 return This->global_props + This->global_prop_cnt++;
2011 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
2013 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
2016 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
2019 ScriptHost *script_host;
2022 for(i=0; i < This->global_prop_cnt; i++) {
2023 /* FIXME: case sensitivity */
2024 if(!strcmpW(This->global_props[i].name, bstrName)) {
2025 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
2030 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
2031 global_prop_t *prop;
2033 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
2035 return E_OUTOFMEMORY;
2037 prop->script_host = script_host;
2040 *pid = prop_to_dispid(This, prop);
2044 return DISP_E_UNKNOWNNAME;
2047 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
2049 HTMLWindow *This = impl_from_IDispatchEx(iface);
2052 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
2054 hres = search_window_props(This, bstrName, grfdex, pid);
2055 if(hres != DISP_E_UNKNOWNNAME)
2058 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
2059 if(hres != DISP_E_UNKNOWNNAME)
2063 global_prop_t *prop;
2066 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2068 if(SUCCEEDED(hres) && elem) {
2069 IHTMLElement_Release(elem);
2071 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
2073 return E_OUTOFMEMORY;
2075 *pid = prop_to_dispid(This, prop);
2080 return DISP_E_UNKNOWNNAME;
2083 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2084 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2086 HTMLWindow *This = impl_from_IDispatchEx(iface);
2088 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2090 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2091 HTMLLocation *location;
2094 TRACE("forwarding to location.href\n");
2096 hres = get_location(This, &location);
2100 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2101 wFlags, pdp, pvarRes, pei, pspCaller);
2102 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2106 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
2110 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2112 HTMLWindow *This = impl_from_IDispatchEx(iface);
2114 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2116 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2119 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2121 HTMLWindow *This = impl_from_IDispatchEx(iface);
2123 TRACE("(%p)->(%x)\n", This, id);
2125 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2128 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2130 HTMLWindow *This = impl_from_IDispatchEx(iface);
2132 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2134 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2138 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2140 HTMLWindow *This = impl_from_IDispatchEx(iface);
2142 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2144 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2147 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2149 HTMLWindow *This = impl_from_IDispatchEx(iface);
2151 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2153 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2156 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2158 HTMLWindow *This = impl_from_IDispatchEx(iface);
2160 TRACE("(%p)->(%p)\n", This, ppunk);
2166 static const IDispatchExVtbl WindowDispExVtbl = {
2167 WindowDispEx_QueryInterface,
2168 WindowDispEx_AddRef,
2169 WindowDispEx_Release,
2170 WindowDispEx_GetTypeInfoCount,
2171 WindowDispEx_GetTypeInfo,
2172 WindowDispEx_GetIDsOfNames,
2173 WindowDispEx_Invoke,
2174 WindowDispEx_GetDispID,
2175 WindowDispEx_InvokeEx,
2176 WindowDispEx_DeleteMemberByName,
2177 WindowDispEx_DeleteMemberByDispID,
2178 WindowDispEx_GetMemberProperties,
2179 WindowDispEx_GetMemberName,
2180 WindowDispEx_GetNextDispID,
2181 WindowDispEx_GetNameSpaceParent
2184 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2186 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2189 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2191 HTMLWindow *This = impl_from_IServiceProvider(iface);
2192 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2195 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2197 HTMLWindow *This = impl_from_IServiceProvider(iface);
2198 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2201 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2203 HTMLWindow *This = impl_from_IServiceProvider(iface);
2204 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2207 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2209 HTMLWindow *This = impl_from_IServiceProvider(iface);
2211 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2212 TRACE("IID_IHTMLWindow2\n");
2213 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2216 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2219 return E_NOINTERFACE;
2221 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2222 guidService, riid, ppv);
2225 static const IServiceProviderVtbl ServiceProviderVtbl = {
2226 HTMLWindowSP_QueryInterface,
2227 HTMLWindowSP_AddRef,
2228 HTMLWindowSP_Release,
2229 HTMLWindowSP_QueryService
2232 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2234 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2237 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2238 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2240 HTMLWindow *This = impl_from_DispatchEx(dispex);
2241 global_prop_t *prop;
2245 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2246 if(idx >= This->global_prop_cnt)
2247 return DISP_E_MEMBERNOTFOUND;
2249 prop = This->global_props+idx;
2251 switch(prop->type) {
2252 case GLOBAL_SCRIPTVAR: {
2256 disp = get_script_disp(prop->script_host);
2258 return E_UNEXPECTED;
2260 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2261 if(SUCCEEDED(hres)) {
2262 TRACE("%s >>>\n", debugstr_w(prop->name));
2263 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2265 TRACE("%s <<<\n", debugstr_w(prop->name));
2267 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2268 IDispatchEx_Release(iface);
2270 FIXME("No IDispatchEx\n");
2272 IDispatch_Release(disp);
2275 case GLOBAL_ELEMENTVAR: {
2278 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2284 return DISP_E_MEMBERNOTFOUND;
2286 V_VT(res) = VT_DISPATCH;
2287 V_DISPATCH(res) = (IDispatch*)elem;
2291 ERR("invalid type %d\n", prop->type);
2292 hres = DISP_E_MEMBERNOTFOUND;
2299 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2306 static const tid_t HTMLWindow_iface_tids[] = {
2313 static dispex_static_data_t HTMLWindow_dispex = {
2314 &HTMLWindow_dispex_vtbl,
2315 DispHTMLWindow2_tid,
2317 HTMLWindow_iface_tids
2320 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2325 window = heap_alloc_zero(sizeof(HTMLWindow));
2327 return E_OUTOFMEMORY;
2329 window->window_ref = heap_alloc(sizeof(windowref_t));
2330 if(!window->window_ref) {
2332 return E_OUTOFMEMORY;
2335 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2336 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2337 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2338 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2339 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2340 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2342 window->doc_obj = doc_obj;
2344 window->window_ref->window = window;
2345 window->window_ref->ref = 1;
2347 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2350 nsIDOMWindow_AddRef(nswindow);
2351 window->nswindow = nswindow;
2354 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2355 window->readystate = READYSTATE_UNINITIALIZED;
2356 list_init(&window->script_hosts);
2358 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
2360 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
2364 window->task_magic = get_task_target_magic();
2365 update_window_doc(window);
2367 list_init(&window->children);
2368 list_add_head(&window_list, &window->entry);
2371 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2373 window->parent = parent;
2374 list_add_tail(&parent->children, &window->sibling_entry);
2381 void update_window_doc(HTMLWindow *window)
2383 nsIDOMHTMLDocument *nshtmldoc;
2384 nsIDOMDocument *nsdoc;
2387 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2388 if(NS_FAILED(nsres) || !nsdoc) {
2389 ERR("GetDocument failed: %08x\n", nsres);
2393 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2394 nsIDOMDocument_Release(nsdoc);
2395 if(NS_FAILED(nsres)) {
2396 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2400 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2401 HTMLDocumentNode *doc;
2404 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2405 if(SUCCEEDED(hres)) {
2406 window_set_docnode(window, doc);
2407 htmldoc_release(&doc->basedoc);
2409 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2413 nsIDOMHTMLDocument_Release(nshtmldoc);
2416 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2420 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2421 if(iter->nswindow == nswindow)