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 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
88 nsIDOMDocumentView *nsdocview;
89 nsIDOMAbstractView *nsview;
90 nsIDOMWindow *nswindow;
93 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
94 nsIDOMDocument_Release(nsdoc);
95 if(NS_FAILED(nsres)) {
96 ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
100 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
101 nsIDOMDocumentView_Release(nsdocview);
102 if(NS_FAILED(nsres)) {
103 ERR("GetDefaultView failed: %08x\n", nsres);
107 nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
108 nsIDOMAbstractView_Release(nsview);
109 if(NS_FAILED(nsres)) {
110 ERR("Could not get nsIDOMWindow iface: %08x\n", nsres);
117 static void release_children(HTMLWindow *This)
121 while(!list_empty(&This->children)) {
122 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
124 list_remove(&child->sibling_entry);
125 child->parent = NULL;
126 IHTMLWindow2_Release(&child->IHTMLWindow2_iface);
130 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
133 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
137 hres = HTMLLocation_Create(This, &This->location);
142 *ret = This->location;
146 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
149 FIXME("No document\n");
153 return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
156 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
159 FIXME("No document\n");
163 return get_event_handler(&window->doc->body_event_target, eid, var);
166 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
168 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
171 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
173 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
177 if(IsEqualGUID(&IID_IUnknown, riid)) {
178 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
179 *ppv = &This->IHTMLWindow2_iface;
180 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
181 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
182 *ppv = &This->IHTMLWindow2_iface;
183 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
184 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
185 *ppv = &This->IDispatchEx_iface;
186 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
187 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
188 *ppv = &This->IHTMLWindow2_iface;
189 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
190 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
191 *ppv = &This->IHTMLWindow2_iface;
192 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
193 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
194 *ppv = &This->IHTMLWindow3_iface;
195 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
196 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
197 *ppv = &This->IHTMLWindow4_iface;
198 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
199 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
200 *ppv = &This->IHTMLPrivateWindow_iface;
201 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
202 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
203 *ppv = &This->IServiceProvider_iface;
204 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
205 return *ppv ? S_OK : E_NOINTERFACE;
209 IUnknown_AddRef((IUnknown*)*ppv);
213 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
214 return E_NOINTERFACE;
217 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
219 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
220 LONG ref = InterlockedIncrement(&This->ref);
222 TRACE("(%p) ref=%d\n", This, ref);
227 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
229 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
230 LONG ref = InterlockedDecrement(&This->ref);
232 TRACE("(%p) ref=%d\n", This, ref);
237 remove_target_tasks(This->task_magic);
238 set_window_bscallback(This, NULL);
239 set_current_mon(This, NULL);
240 window_set_docnode(This, NULL);
241 release_children(This);
244 IInternetSecurityManager_Release(This->secmgr);
246 if(This->frame_element)
247 This->frame_element->content_window = NULL;
249 if(This->option_factory) {
250 This->option_factory->window = NULL;
251 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
254 if(This->image_factory) {
255 This->image_factory->window = NULL;
256 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
260 This->location->window = NULL;
261 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
265 IHTMLScreen_Release(This->screen);
267 for(i=0; i < This->global_prop_cnt; i++)
268 heap_free(This->global_props[i].name);
270 This->window_ref->window = NULL;
271 windowref_release(This->window_ref);
273 heap_free(This->global_props);
274 release_script_hosts(This);
277 nsIDOMWindow_Release(This->nswindow);
279 list_remove(&This->entry);
280 release_dispex(&This->dispex);
287 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
289 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
291 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
294 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
295 LCID lcid, ITypeInfo **ppTInfo)
297 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
299 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
302 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
303 LPOLESTR *rgszNames, UINT cNames,
304 LCID lcid, DISPID *rgDispId)
306 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
308 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
312 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
313 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
314 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
316 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
318 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
319 pDispParams, pVarResult, pExcepInfo, puArgErr);
322 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
325 nsIDOMWindow *nsWindow;
328 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
329 if(NS_FAILED(nsres)) {
330 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
335 return DISP_E_MEMBERNOTFOUND;
337 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
338 if(NS_FAILED(nsres)) {
339 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
343 *ret = nswindow_to_window(nsWindow);
345 nsIDOMWindow_Release(nsWindow);
350 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
352 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
353 nsIDOMWindowCollection *nsFrames;
358 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
360 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
361 if(NS_FAILED(nsres)) {
362 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
366 if(V_VT(pvarIndex) == VT_I4) {
367 int index = V_I4(pvarIndex);
368 TRACE("Getting index %d\n", index);
370 hres = DISP_E_MEMBERNOTFOUND;
373 hres = get_frame_by_index(nsFrames, index, &window);
376 }else if(V_VT(pvarIndex) == VT_UINT) {
377 unsigned int index = V_UINT(pvarIndex);
378 TRACE("Getting index %u\n", index);
379 hres = get_frame_by_index(nsFrames, index, &window);
382 }else if(V_VT(pvarIndex) == VT_BSTR) {
383 BSTR str = V_BSTR(pvarIndex);
386 TRACE("Getting name %s\n", wine_dbgstr_w(str));
388 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
391 for(i = 0; i < length && !window; ++i) {
392 HTMLWindow *cur_window;
393 nsIDOMWindow *nsWindow;
396 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
397 if(NS_FAILED(nsres)) {
398 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
403 cur_window = nswindow_to_window(nsWindow);
405 nsIDOMWindow_Release(nsWindow);
407 hres = IHTMLElement_get_id(&cur_window->frame_element->element.IHTMLElement_iface, &id);
409 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
413 if(!strcmpW(id, str))
420 hres = DISP_E_MEMBERNOTFOUND;
428 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
429 V_VT(pvarResult) = VT_DISPATCH;
430 V_DISPATCH(pvarResult) = (IDispatch*)window;
435 nsIDOMWindowCollection_Release(nsFrames);
440 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
442 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
443 nsIDOMWindowCollection *nscollection;
447 TRACE("(%p)->(%p)\n", This, p);
449 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
450 if(NS_FAILED(nsres)) {
451 ERR("GetFrames failed: %08x\n", nsres);
455 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
456 nsIDOMWindowCollection_Release(nscollection);
457 if(NS_FAILED(nsres)) {
458 ERR("GetLength failed: %08x\n", nsres);
466 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
468 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
469 FIXME("(%p)->(%p): semi-stub\n", This, p);
471 /* FIXME: Should return a separate Window object */
472 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
473 HTMLWindow2_AddRef(iface);
477 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
479 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
480 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
484 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
486 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
487 FIXME("(%p)->(%p)\n", This, p);
491 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
493 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
495 WARN("(%p)->(%s)\n", This, debugstr_w(v));
498 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
499 * Ignoring the call should be enough for us.
504 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
506 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
508 TRACE("(%p)->(%p)\n", This, p);
515 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
516 LONG msec, VARIANT *language, LONG *timerID)
518 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
521 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
523 V_VT(&expr_var) = VT_BSTR;
524 V_BSTR(&expr_var) = expression;
526 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
529 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
531 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
533 TRACE("(%p)->(%d)\n", This, timerID);
535 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
538 #define MAX_MESSAGE_LEN 2000
540 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
542 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
543 WCHAR title[100], *msg = message;
546 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
548 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
549 sizeof(title)/sizeof(WCHAR))) {
550 WARN("Could not load message box title: %d\n", GetLastError());
554 len = SysStringLen(message);
555 if(len > MAX_MESSAGE_LEN) {
556 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
558 return E_OUTOFMEMORY;
559 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
560 msg[MAX_MESSAGE_LEN] = 0;
563 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
569 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
570 VARIANT_BOOL *confirmed)
572 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
575 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
577 if(!confirmed) return E_INVALIDARG;
579 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
580 sizeof(wszTitle)/sizeof(WCHAR))) {
581 WARN("Could not load message box title: %d\n", GetLastError());
582 *confirmed = VARIANT_TRUE;
586 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
587 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
588 *confirmed = VARIANT_TRUE;
589 else *confirmed = VARIANT_FALSE;
601 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
602 WPARAM wparam, LPARAM lparam)
608 prompt_arg *arg = (prompt_arg*)lparam;
611 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
612 sizeof(wszTitle)/sizeof(WCHAR))) {
613 WARN("Could not load message box title: %d\n", GetLastError());
614 EndDialog(hwnd, wparam);
618 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
619 SetWindowTextW(hwnd, wszTitle);
620 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
621 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
627 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
628 EndDialog(hwnd, wparam);
630 case MAKEWPARAM(IDOK, BN_CLICKED):
633 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
634 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
635 INT len = GetWindowTextLengthW(hwndPrompt);
639 EndDialog(hwnd, wparam);
643 V_VT(arg->textdata) = VT_BSTR;
644 if(!len && !arg->dststr)
645 V_BSTR(arg->textdata) = NULL;
648 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
649 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
651 EndDialog(hwnd, wparam);
657 EndDialog(hwnd, IDCANCEL);
664 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
665 BSTR dststr, VARIANT *textdata)
667 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
670 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
672 if(textdata) V_VT(textdata) = VT_NULL;
674 arg.message = message;
676 arg.textdata = textdata;
678 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
679 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
683 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
685 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
687 TRACE("(%p)->(%p)\n", This, p);
689 if(!This->image_factory)
690 This->image_factory = HTMLImageElementFactory_Create(This);
692 *p = &This->image_factory->IHTMLImageElementFactory_iface;
693 IHTMLImageElementFactory_AddRef(*p);
698 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
700 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
701 HTMLLocation *location;
704 TRACE("(%p)->(%p)\n", This, p);
706 hres = get_location(This, &location);
710 *p = &location->IHTMLLocation_iface;
714 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
716 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
717 FIXME("(%p)->(%p)\n", This, p);
721 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
723 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
724 FIXME("(%p)->()\n", This);
728 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
730 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
731 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
735 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
737 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
738 FIXME("(%p)->(%p)\n", This, p);
742 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
744 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
746 TRACE("(%p)->(%p)\n", This, p);
748 *p = OmNavigator_Create();
752 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
754 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
758 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
760 nsAString_InitDepend(&name_str, v);
761 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
762 nsAString_Finish(&name_str);
764 ERR("SetName failed: %08x\n", nsres);
769 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
771 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
776 TRACE("(%p)->(%p)\n", This, p);
778 nsAString_Init(&name_str, NULL);
779 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
780 if(NS_SUCCEEDED(nsres)) {
781 const PRUnichar *name;
783 nsAString_GetData(&name_str, &name);
785 *p = SysAllocString(name);
786 hres = *p ? S_OK : E_OUTOFMEMORY;
792 ERR("GetName failed: %08x\n", nsres);
795 nsAString_Finish(&name_str);
800 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
802 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
803 TRACE("(%p)->(%p)\n", This, p);
806 *p = &This->parent->IHTMLWindow2_iface;
807 IHTMLWindow2_AddRef(*p);
814 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
815 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
817 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
818 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
819 debugstr_w(features), replace, pomWindowResult);
823 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
825 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
827 TRACE("(%p)->(%p)\n", This, p);
829 /* FIXME: We should return kind of proxy window here. */
830 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
831 *p = &This->IHTMLWindow2_iface;
835 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
837 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
839 TRACE("(%p)->(%p)\n", This, p);
844 *p = &curr->IHTMLWindow2_iface;
845 IHTMLWindow2_AddRef(*p);
850 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
852 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
854 TRACE("(%p)->(%p)\n", This, p);
856 /* FIXME: We should return kind of proxy window here. */
857 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
858 *p = &This->IHTMLWindow2_iface;
862 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
864 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
865 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
869 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
871 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
872 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
876 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
878 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
879 FIXME("(%p)->(%p)\n", This, p);
883 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
885 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
886 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
890 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
892 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
893 FIXME("(%p)->(%p)\n", This, p);
897 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
899 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
901 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
903 return set_window_event(This, EVENTID_LOAD, &v);
906 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
908 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
910 TRACE("(%p)->(%p)\n", This, p);
912 return get_window_event(This, EVENTID_LOAD, p);
915 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
917 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
919 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
921 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
924 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
926 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
928 TRACE("(%p)->(%p)\n", This, p);
930 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
933 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
935 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
936 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
940 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
942 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
943 FIXME("(%p)->(%p)\n", This, p);
947 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
949 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
950 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
954 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
956 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
957 FIXME("(%p)->(%p)\n", This, p);
961 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
963 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
964 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
968 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
970 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
971 FIXME("(%p)->(%p)\n", This, p);
975 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
977 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
979 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
981 return set_window_event(This, EVENTID_RESIZE, &v);
984 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
986 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
988 TRACE("(%p)->(%p)\n", This, p);
990 return get_window_event(This, EVENTID_RESIZE, p);
993 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
995 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
996 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1000 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
1002 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1003 FIXME("(%p)->(%p)\n", This, p);
1007 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
1009 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1011 TRACE("(%p)->(%p)\n", This, p);
1014 /* FIXME: We should return a wrapper object here */
1015 *p = &This->doc->basedoc.IHTMLDocument2_iface;
1016 IHTMLDocument2_AddRef(*p);
1024 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1026 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1028 TRACE("(%p)->(%p)\n", This, p);
1031 IHTMLEventObj_AddRef(This->event);
1036 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1038 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1039 FIXME("(%p)->(%p)\n", This, p);
1043 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1044 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1046 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1047 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1051 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1054 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1055 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1059 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1061 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1063 TRACE("(%p)->(%p)\n", This, p);
1068 hres = HTMLScreen_Create(&This->screen);
1074 IHTMLScreen_AddRef(This->screen);
1078 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1080 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1082 TRACE("(%p)->(%p)\n", This, p);
1084 if(!This->option_factory)
1085 This->option_factory = HTMLOptionElementFactory_Create(This);
1087 *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1088 IHTMLOptionElementFactory_AddRef(*p);
1093 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1095 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1097 TRACE("(%p)->()\n", This);
1100 SetFocus(This->doc_obj->hwnd);
1104 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1106 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1107 FIXME("(%p)->(%p)\n", This, p);
1111 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1113 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1114 FIXME("(%p)->()\n", This);
1118 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1120 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1121 FIXME("(%p)->(%d %d)\n", This, x, y);
1125 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1127 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1128 FIXME("(%p)->(%p)\n", This, p);
1132 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1133 LONG msec, VARIANT *language, LONG *timerID)
1135 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1138 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1140 V_VT(&expr) = VT_BSTR;
1141 V_BSTR(&expr) = expression;
1142 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1145 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1147 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1149 TRACE("(%p)->(%d)\n", This, timerID);
1151 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1154 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1156 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1157 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1161 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1163 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1164 FIXME("(%p)->(%p)\n", This, p);
1168 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1171 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1173 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1175 return exec_script(This, scode, language, pvarRet);
1178 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1180 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1182 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1184 TRACE("(%p)->(%p)\n", This, String);
1187 return E_INVALIDARG;
1189 *String = SysAllocString(objectW);
1190 return *String ? S_OK : E_OUTOFMEMORY;
1193 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1195 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1198 TRACE("(%p)->(%d %d)\n", This, x, y);
1200 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1201 if(NS_FAILED(nsres))
1202 ERR("ScrollBy failed: %08x\n", nsres);
1207 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1209 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1212 TRACE("(%p)->(%d %d)\n", This, x, y);
1214 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1215 if(NS_FAILED(nsres))
1216 ERR("ScrollTo failed: %08x\n", nsres);
1221 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1223 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1224 FIXME("(%p)->(%d %d)\n", This, x, y);
1228 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1230 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1231 FIXME("(%p)->(%d %d)\n", This, x, y);
1235 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1237 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1238 FIXME("(%p)->(%d %d)\n", This, x, y);
1242 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1244 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1245 FIXME("(%p)->(%d %d)\n", This, x, y);
1249 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1251 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1253 TRACE("(%p)->(%p)\n", This, p);
1257 if(!This->doc_obj->hostui)
1260 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1263 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1264 HTMLWindow2_QueryInterface,
1266 HTMLWindow2_Release,
1267 HTMLWindow2_GetTypeInfoCount,
1268 HTMLWindow2_GetTypeInfo,
1269 HTMLWindow2_GetIDsOfNames,
1272 HTMLWindow2_get_length,
1273 HTMLWindow2_get_frames,
1274 HTMLWindow2_put_defaultStatus,
1275 HTMLWindow2_get_defaultStatus,
1276 HTMLWindow2_put_status,
1277 HTMLWindow2_get_status,
1278 HTMLWindow2_setTimeout,
1279 HTMLWindow2_clearTimeout,
1281 HTMLWindow2_confirm,
1283 HTMLWindow2_get_Image,
1284 HTMLWindow2_get_location,
1285 HTMLWindow2_get_history,
1287 HTMLWindow2_put_opener,
1288 HTMLWindow2_get_opener,
1289 HTMLWindow2_get_navigator,
1290 HTMLWindow2_put_name,
1291 HTMLWindow2_get_name,
1292 HTMLWindow2_get_parent,
1294 HTMLWindow2_get_self,
1295 HTMLWindow2_get_top,
1296 HTMLWindow2_get_window,
1297 HTMLWindow2_navigate,
1298 HTMLWindow2_put_onfocus,
1299 HTMLWindow2_get_onfocus,
1300 HTMLWindow2_put_onblur,
1301 HTMLWindow2_get_onblur,
1302 HTMLWindow2_put_onload,
1303 HTMLWindow2_get_onload,
1304 HTMLWindow2_put_onbeforeunload,
1305 HTMLWindow2_get_onbeforeunload,
1306 HTMLWindow2_put_onunload,
1307 HTMLWindow2_get_onunload,
1308 HTMLWindow2_put_onhelp,
1309 HTMLWindow2_get_onhelp,
1310 HTMLWindow2_put_onerror,
1311 HTMLWindow2_get_onerror,
1312 HTMLWindow2_put_onresize,
1313 HTMLWindow2_get_onresize,
1314 HTMLWindow2_put_onscroll,
1315 HTMLWindow2_get_onscroll,
1316 HTMLWindow2_get_document,
1317 HTMLWindow2_get_event,
1318 HTMLWindow2_get__newEnum,
1319 HTMLWindow2_showModalDialog,
1320 HTMLWindow2_showHelp,
1321 HTMLWindow2_get_screen,
1322 HTMLWindow2_get_Option,
1324 HTMLWindow2_get_closed,
1327 HTMLWindow2_get_clientInformation,
1328 HTMLWindow2_setInterval,
1329 HTMLWindow2_clearInterval,
1330 HTMLWindow2_put_offscreenBuffering,
1331 HTMLWindow2_get_offscreenBuffering,
1332 HTMLWindow2_execScript,
1333 HTMLWindow2_toString,
1334 HTMLWindow2_scrollBy,
1335 HTMLWindow2_scrollTo,
1338 HTMLWindow2_resizeTo,
1339 HTMLWindow2_resizeBy,
1340 HTMLWindow2_get_external
1343 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1345 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1348 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1350 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1352 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1355 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1357 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1359 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1362 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1364 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1366 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1369 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1371 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1373 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1376 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1377 LCID lcid, ITypeInfo **ppTInfo)
1379 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1381 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1384 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1385 LPOLESTR *rgszNames, UINT cNames,
1386 LCID lcid, DISPID *rgDispId)
1388 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1390 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1394 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1395 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1396 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1398 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1400 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1401 pDispParams, pVarResult, pExcepInfo, puArgErr);
1404 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1406 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1407 FIXME("(%p)->(%p)\n", This, p);
1411 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1413 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1414 FIXME("(%p)->(%p)\n", This, p);
1418 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1420 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1422 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1425 FIXME("No document\n");
1429 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1432 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1434 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1435 FIXME("(%p)->()\n", This);
1439 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1440 BOOL interval, LONG *timer_id)
1442 IDispatch *disp = NULL;
1444 switch(V_VT(expr)) {
1446 disp = V_DISPATCH(expr);
1447 IDispatch_AddRef(disp);
1451 disp = script_parse_event(This, V_BSTR(expr));
1455 FIXME("unimplemented vt=%d\n", V_VT(expr));
1462 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1463 IDispatch_Release(disp);
1468 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1469 VARIANT *language, LONG *timerID)
1471 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1473 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1475 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1478 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1479 VARIANT *language, LONG *timerID)
1481 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1483 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1485 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1488 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1490 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1491 FIXME("(%p)\n", This);
1495 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1497 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1498 FIXME("(%p)->()\n", This);
1502 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1504 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1505 FIXME("(%p)->(%p)\n", This, p);
1509 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1511 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1512 FIXME("(%p)->()\n", This);
1516 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1518 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1519 FIXME("(%p)->(%p)\n", This, p);
1523 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1525 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1526 FIXME("(%p)->(%p)\n", This, p);
1530 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1531 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1533 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1534 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1538 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1539 HTMLWindow3_QueryInterface,
1541 HTMLWindow3_Release,
1542 HTMLWindow3_GetTypeInfoCount,
1543 HTMLWindow3_GetTypeInfo,
1544 HTMLWindow3_GetIDsOfNames,
1546 HTMLWindow3_get_screenLeft,
1547 HTMLWindow3_get_screenTop,
1548 HTMLWindow3_attachEvent,
1549 HTMLWindow3_detachEvent,
1550 HTMLWindow3_setTimeout,
1551 HTMLWindow3_setInterval,
1553 HTMLWindow3_put_onbeforeprint,
1554 HTMLWindow3_get_onbeforeprint,
1555 HTMLWindow3_put_onafterprint,
1556 HTMLWindow3_get_onafterprint,
1557 HTMLWindow3_get_clipboardData,
1558 HTMLWindow3_showModelessDialog
1561 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1563 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1566 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1568 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1570 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1573 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1575 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1577 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1580 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1582 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1584 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1587 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1589 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1591 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1594 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1595 LCID lcid, ITypeInfo **ppTInfo)
1597 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1599 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1602 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1603 LPOLESTR *rgszNames, UINT cNames,
1604 LCID lcid, DISPID *rgDispId)
1606 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1608 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1612 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1613 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1614 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1616 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1618 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1619 pDispParams, pVarResult, pExcepInfo, puArgErr);
1622 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1623 IDispatch **ppPopup)
1625 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1626 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1630 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1632 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1633 TRACE("(%p)->(%p)\n", This, p);
1635 if(This->frame_element) {
1636 *p = &This->frame_element->IHTMLFrameBase_iface;
1637 IHTMLFrameBase_AddRef(*p);
1644 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1645 HTMLWindow4_QueryInterface,
1647 HTMLWindow4_Release,
1648 HTMLWindow4_GetTypeInfoCount,
1649 HTMLWindow4_GetTypeInfo,
1650 HTMLWindow4_GetIDsOfNames,
1652 HTMLWindow4_createPopup,
1653 HTMLWindow4_get_frameElement
1656 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1658 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1661 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1663 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1665 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1668 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1670 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1672 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1675 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1677 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1679 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1686 } navigate_javascript_task_t;
1688 static void navigate_javascript_proc(task_t *_task)
1690 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1691 HTMLWindow *window = task->window;
1696 static const WCHAR jscriptW[] = {'j','s','c','r','i','p','t',0};
1698 task->window->readystate = READYSTATE_COMPLETE;
1700 hres = IUri_GetPath(task->uri, &code);
1704 set_download_state(window->doc_obj, 1);
1706 V_VT(&v) = VT_EMPTY;
1707 hres = exec_script(window, code, jscriptW, &v);
1708 SysFreeString(code);
1709 if(SUCCEEDED(hres) && V_VT(&v) != VT_EMPTY) {
1710 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v));
1714 if(window->doc_obj->view_sink)
1715 IAdviseSink_OnViewChange(window->doc_obj->view_sink, DVASPECT_CONTENT, -1);
1717 set_download_state(window->doc_obj, 0);
1720 static void navigate_javascript_task_destr(task_t *_task)
1722 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1724 IUri_Release(task->uri);
1731 nsChannelBSC *bscallback;
1735 static void navigate_proc(task_t *_task)
1737 navigate_task_t *task = (navigate_task_t*)_task;
1740 hres = set_moniker(&task->window->doc_obj->basedoc, task->mon, NULL, task->bscallback, TRUE);
1742 hres = start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
1746 static void navigate_task_destr(task_t *_task)
1748 navigate_task_t *task = (navigate_task_t*)_task;
1750 IUnknown_Release((IUnknown*)task->bscallback);
1751 IMoniker_Release(task->mon);
1755 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1756 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1758 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1759 DWORD post_data_size = 0;
1760 BYTE *post_data = NULL;
1761 WCHAR *headers = NULL;
1769 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1770 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1773 if(This->doc_obj->hostui) {
1774 OLECHAR *translated_url = NULL;
1776 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1777 if(hres == S_OK && translated_url) {
1778 new_url = SysAllocString(translated_url);
1779 CoTaskMemFree(translated_url);
1783 if(This->doc_obj->client) {
1784 IOleCommandTarget *cmdtrg;
1786 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1787 if(SUCCEEDED(hres)) {
1790 V_VT(&in) = VT_BSTR;
1791 V_BSTR(&in) = new_url;
1792 V_VT(&out) = VT_BOOL;
1793 V_BOOL(&out) = VARIANT_TRUE;
1794 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1795 IOleCommandTarget_Release(cmdtrg);
1801 hres = CreateUri(new_url, 0, 0, &uri);
1803 SysFreeString(new_url);
1807 hres = CreateURLMonikerEx2(NULL, uri, &mon, URL_MK_UNIFORM);
1811 /* FIXME: Why not set_ready_state? */
1812 This->readystate = READYSTATE_UNINITIALIZED;
1815 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1816 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1817 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1821 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1822 if(V_VT(headers_var) != VT_BSTR)
1823 return E_INVALIDARG;
1825 headers = V_BSTR(headers_var);
1828 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1830 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1832 IMoniker_Release(mon);
1836 prepare_for_binding(&This->doc_obj->basedoc, mon, NULL, TRUE);
1838 hres = IUri_GetScheme(uri, &scheme);
1840 if(scheme != URL_SCHEME_JAVASCRIPT) {
1841 navigate_task_t *task;
1845 task = heap_alloc(sizeof(*task));
1847 IUnknown_Release((IUnknown*)bsc);
1848 IMoniker_Release(mon);
1849 return E_OUTOFMEMORY;
1852 task->window = This;
1853 task->bscallback = bsc;
1855 push_task(&task->header, navigate_proc, navigate_task_destr, This->task_magic);
1857 /* Silently and repeated when real loading starts? */
1858 This->readystate = READYSTATE_LOADING;
1860 navigate_javascript_task_t *task;
1862 IUnknown_Release((IUnknown*)bsc);
1863 IMoniker_Release(mon);
1865 task = heap_alloc(sizeof(*task));
1868 return E_OUTOFMEMORY;
1871 task->window = This;
1873 push_task(&task->header, navigate_javascript_proc, navigate_javascript_task_destr, This->task_magic);
1876 This->readystate = READYSTATE_COMPLETE;
1882 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1884 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1885 FIXME("(%p)->(%p)\n", This, url);
1889 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1891 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1892 FIXME("(%p)->(%p)\n", This, cmdtrg);
1896 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1898 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1899 FIXME("(%p)->(%x)\n", This, arg);
1903 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1905 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1906 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1910 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1912 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1913 TRACE("(%p)->(%p)\n", This, url);
1916 return E_INVALIDARG;
1918 *url = SysAllocString(This->url);
1922 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1923 HTMLPrivateWindow_QueryInterface,
1924 HTMLPrivateWindow_AddRef,
1925 HTMLPrivateWindow_Release,
1926 HTMLPrivateWindow_SuperNavigate,
1927 HTMLPrivateWindow_GetPendingUrl,
1928 HTMLPrivateWindow_SetPICSTarget,
1929 HTMLPrivateWindow_PICSComplete,
1930 HTMLPrivateWindow_FindWindowByName,
1931 HTMLPrivateWindow_GetAddressBar
1934 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1936 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1939 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1941 HTMLWindow *This = impl_from_IDispatchEx(iface);
1943 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1946 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1948 HTMLWindow *This = impl_from_IDispatchEx(iface);
1950 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1953 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1955 HTMLWindow *This = impl_from_IDispatchEx(iface);
1957 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1960 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1962 HTMLWindow *This = impl_from_IDispatchEx(iface);
1964 TRACE("(%p)->(%p)\n", This, pctinfo);
1966 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1969 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1970 LCID lcid, ITypeInfo **ppTInfo)
1972 HTMLWindow *This = impl_from_IDispatchEx(iface);
1974 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1976 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1979 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1980 LPOLESTR *rgszNames, UINT cNames,
1981 LCID lcid, DISPID *rgDispId)
1983 HTMLWindow *This = impl_from_IDispatchEx(iface);
1987 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1990 for(i=0; i < cNames; i++) {
1991 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1992 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
2000 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
2001 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2002 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2004 HTMLWindow *This = impl_from_IDispatchEx(iface);
2006 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2007 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2009 /* FIXME: Use script dispatch */
2011 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2012 pDispParams, pVarResult, pExcepInfo, puArgErr);
2015 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
2017 if(This->global_prop_cnt == This->global_prop_size) {
2018 global_prop_t *new_props;
2021 if(This->global_props) {
2022 new_size = This->global_prop_size*2;
2023 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
2026 new_props = heap_alloc(new_size*sizeof(global_prop_t));
2030 This->global_props = new_props;
2031 This->global_prop_size = new_size;
2034 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
2035 if(!This->global_props[This->global_prop_cnt].name)
2038 This->global_props[This->global_prop_cnt].type = type;
2039 return This->global_props + This->global_prop_cnt++;
2042 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
2044 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
2047 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
2050 ScriptHost *script_host;
2053 for(i=0; i < This->global_prop_cnt; i++) {
2054 /* FIXME: case sensitivity */
2055 if(!strcmpW(This->global_props[i].name, bstrName)) {
2056 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
2061 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
2062 global_prop_t *prop;
2064 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
2066 return E_OUTOFMEMORY;
2068 prop->script_host = script_host;
2071 *pid = prop_to_dispid(This, prop);
2075 return DISP_E_UNKNOWNNAME;
2078 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
2080 HTMLWindow *This = impl_from_IDispatchEx(iface);
2083 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
2085 hres = search_window_props(This, bstrName, grfdex, pid);
2086 if(hres != DISP_E_UNKNOWNNAME)
2089 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
2090 if(hres != DISP_E_UNKNOWNNAME)
2094 global_prop_t *prop;
2097 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2099 if(SUCCEEDED(hres) && elem) {
2100 IHTMLElement_Release(elem);
2102 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
2104 return E_OUTOFMEMORY;
2106 *pid = prop_to_dispid(This, prop);
2111 return DISP_E_UNKNOWNNAME;
2114 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2115 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2117 HTMLWindow *This = impl_from_IDispatchEx(iface);
2119 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2121 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2122 HTMLLocation *location;
2125 TRACE("forwarding to location.href\n");
2127 hres = get_location(This, &location);
2131 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2132 wFlags, pdp, pvarRes, pei, pspCaller);
2133 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2137 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
2141 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2143 HTMLWindow *This = impl_from_IDispatchEx(iface);
2145 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2147 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2150 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2152 HTMLWindow *This = impl_from_IDispatchEx(iface);
2154 TRACE("(%p)->(%x)\n", This, id);
2156 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2159 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2161 HTMLWindow *This = impl_from_IDispatchEx(iface);
2163 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2165 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2169 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2171 HTMLWindow *This = impl_from_IDispatchEx(iface);
2173 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2175 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2178 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2180 HTMLWindow *This = impl_from_IDispatchEx(iface);
2182 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2184 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2187 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2189 HTMLWindow *This = impl_from_IDispatchEx(iface);
2191 TRACE("(%p)->(%p)\n", This, ppunk);
2197 static const IDispatchExVtbl WindowDispExVtbl = {
2198 WindowDispEx_QueryInterface,
2199 WindowDispEx_AddRef,
2200 WindowDispEx_Release,
2201 WindowDispEx_GetTypeInfoCount,
2202 WindowDispEx_GetTypeInfo,
2203 WindowDispEx_GetIDsOfNames,
2204 WindowDispEx_Invoke,
2205 WindowDispEx_GetDispID,
2206 WindowDispEx_InvokeEx,
2207 WindowDispEx_DeleteMemberByName,
2208 WindowDispEx_DeleteMemberByDispID,
2209 WindowDispEx_GetMemberProperties,
2210 WindowDispEx_GetMemberName,
2211 WindowDispEx_GetNextDispID,
2212 WindowDispEx_GetNameSpaceParent
2215 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2217 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2220 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2222 HTMLWindow *This = impl_from_IServiceProvider(iface);
2223 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2226 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2228 HTMLWindow *This = impl_from_IServiceProvider(iface);
2229 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2232 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2234 HTMLWindow *This = impl_from_IServiceProvider(iface);
2235 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2238 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2240 HTMLWindow *This = impl_from_IServiceProvider(iface);
2242 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2243 TRACE("IID_IHTMLWindow2\n");
2244 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2247 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2250 return E_NOINTERFACE;
2252 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2253 guidService, riid, ppv);
2256 static const IServiceProviderVtbl ServiceProviderVtbl = {
2257 HTMLWindowSP_QueryInterface,
2258 HTMLWindowSP_AddRef,
2259 HTMLWindowSP_Release,
2260 HTMLWindowSP_QueryService
2263 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2265 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2268 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2269 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2271 HTMLWindow *This = impl_from_DispatchEx(dispex);
2272 global_prop_t *prop;
2276 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2277 if(idx >= This->global_prop_cnt)
2278 return DISP_E_MEMBERNOTFOUND;
2280 prop = This->global_props+idx;
2282 switch(prop->type) {
2283 case GLOBAL_SCRIPTVAR: {
2287 disp = get_script_disp(prop->script_host);
2289 return E_UNEXPECTED;
2291 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2292 if(SUCCEEDED(hres)) {
2293 TRACE("%s >>>\n", debugstr_w(prop->name));
2294 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2296 TRACE("%s <<<\n", debugstr_w(prop->name));
2298 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2299 IDispatchEx_Release(iface);
2301 FIXME("No IDispatchEx\n");
2303 IDispatch_Release(disp);
2306 case GLOBAL_ELEMENTVAR: {
2309 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2315 return DISP_E_MEMBERNOTFOUND;
2317 V_VT(res) = VT_DISPATCH;
2318 V_DISPATCH(res) = (IDispatch*)elem;
2322 ERR("invalid type %d\n", prop->type);
2323 hres = DISP_E_MEMBERNOTFOUND;
2330 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2336 static const tid_t HTMLWindow_iface_tids[] = {
2343 static dispex_static_data_t HTMLWindow_dispex = {
2344 &HTMLWindow_dispex_vtbl,
2345 DispHTMLWindow2_tid,
2347 HTMLWindow_iface_tids
2350 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2355 window = heap_alloc_zero(sizeof(HTMLWindow));
2357 return E_OUTOFMEMORY;
2359 window->window_ref = heap_alloc(sizeof(windowref_t));
2360 if(!window->window_ref) {
2362 return E_OUTOFMEMORY;
2365 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2366 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2367 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2368 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2369 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2370 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2372 window->doc_obj = doc_obj;
2374 window->window_ref->window = window;
2375 window->window_ref->ref = 1;
2377 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2380 nsIDOMWindow_AddRef(nswindow);
2381 window->nswindow = nswindow;
2384 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2385 window->readystate = READYSTATE_UNINITIALIZED;
2386 list_init(&window->script_hosts);
2388 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
2390 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
2394 window->task_magic = get_task_target_magic();
2395 update_window_doc(window);
2397 list_init(&window->children);
2398 list_add_head(&window_list, &window->entry);
2401 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2403 window->parent = parent;
2404 list_add_tail(&parent->children, &window->sibling_entry);
2411 void update_window_doc(HTMLWindow *window)
2413 nsIDOMHTMLDocument *nshtmldoc;
2414 nsIDOMDocument *nsdoc;
2417 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2418 if(NS_FAILED(nsres) || !nsdoc) {
2419 ERR("GetDocument failed: %08x\n", nsres);
2423 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2424 nsIDOMDocument_Release(nsdoc);
2425 if(NS_FAILED(nsres)) {
2426 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2430 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2431 HTMLDocumentNode *doc;
2434 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2435 if(SUCCEEDED(hres)) {
2436 window_set_docnode(window, doc);
2437 htmldoc_release(&doc->basedoc);
2439 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2443 nsIDOMHTMLDocument_Release(nshtmldoc);
2446 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2450 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2451 if(iter->nswindow == nswindow)