2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define HTMLPRIVWINDOW(x) ((IHTMLPrivateWindow*) &(x)->lpIHTMLPrivateWindowVtbl)
40 static struct list window_list = LIST_INIT(window_list);
42 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
45 abort_document_bindings(window->doc);
46 window->doc->basedoc.window = NULL;
47 htmldoc_release(&window->doc->basedoc);
49 window->doc = doc_node;
51 htmldoc_addref(&doc_node->basedoc);
53 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
54 if(window->doc_obj->basedoc.doc_node)
55 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
56 window->doc_obj->basedoc.doc_node = doc_node;
58 htmldoc_addref(&doc_node->basedoc);
61 if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
62 nsIDOMNSHTMLDocument *nshtmldoc;
66 static const PRUnichar onW[] = {'o','n',0};
68 nsres = nsIDOMHTMLDocument_QueryInterface(doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
69 if(NS_SUCCEEDED(nsres)) {
70 nsAString_Init(&mode_str, onW);
71 nsres = nsIDOMNSHTMLDocument_SetDesignMode(nshtmldoc, &mode_str);
72 nsAString_Finish(&mode_str);
73 nsIDOMNSHTMLDocument_Release(nshtmldoc);
75 ERR("SetDesignMode failed: %08x\n", nsres);
77 ERR("Could not get nsIDOMNSHTMLDocument interface: %08x\n", nsres);
82 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
84 nsIDOMDocumentView *nsdocview;
85 nsIDOMAbstractView *nsview;
86 nsIDOMWindow *nswindow;
89 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
90 nsIDOMDocument_Release(nsdoc);
91 if(NS_FAILED(nsres)) {
92 ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
96 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
97 nsIDOMDocumentView_Release(nsview);
98 if(NS_FAILED(nsres)) {
99 ERR("GetDefaultView failed: %08x\n", nsres);
103 nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
104 nsIDOMAbstractView_Release(nsview);
105 if(NS_FAILED(nsres)) {
106 ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
113 static void release_children(HTMLWindow *This)
117 while(!list_empty(&This->children)) {
118 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
120 list_remove(&child->sibling_entry);
121 child->parent = NULL;
122 IHTMLWindow2_Release(HTMLWINDOW2(child));
126 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
129 IHTMLLocation_AddRef(HTMLLOCATION(This->location));
133 hres = HTMLLocation_Create(This, &This->location);
138 *ret = This->location;
142 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
145 FIXME("No document\n");
149 return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
152 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
155 FIXME("No document\n");
159 return get_event_handler(&window->doc->body_event_target, eid, var);
162 #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
164 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
166 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
170 if(IsEqualGUID(&IID_IUnknown, riid)) {
171 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
172 *ppv = HTMLWINDOW2(This);
173 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
174 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
175 *ppv = HTMLWINDOW2(This);
176 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
177 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
178 *ppv = DISPATCHEX(This);
179 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
180 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
181 *ppv = HTMLWINDOW2(This);
182 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
183 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
184 *ppv = HTMLWINDOW2(This);
185 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
186 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
187 *ppv = HTMLWINDOW3(This);
188 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
189 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
190 *ppv = HTMLWINDOW4(This);
191 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
192 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
193 *ppv = HTMLPRIVWINDOW(This);
194 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
195 return *ppv ? S_OK : E_NOINTERFACE;
199 IUnknown_AddRef((IUnknown*)*ppv);
203 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
204 return E_NOINTERFACE;
207 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
209 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
210 LONG ref = InterlockedIncrement(&This->ref);
212 TRACE("(%p) ref=%d\n", This, ref);
217 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
219 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
220 LONG ref = InterlockedDecrement(&This->ref);
222 TRACE("(%p) ref=%d\n", This, ref);
227 remove_target_tasks(This->task_magic);
228 set_window_bscallback(This, NULL);
229 set_current_mon(This, NULL);
230 window_set_docnode(This, NULL);
231 release_children(This);
233 if(This->frame_element)
234 This->frame_element->content_window = NULL;
236 if(This->option_factory) {
237 This->option_factory->window = NULL;
238 IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
241 if(This->image_factory) {
242 This->image_factory->window = NULL;
243 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
247 This->location->window = NULL;
248 IHTMLLocation_Release(HTMLLOCATION(This->location));
252 IHTMLScreen_Release(This->screen);
254 for(i=0; i < This->global_prop_cnt; i++)
255 heap_free(This->global_props[i].name);
257 This->window_ref->window = NULL;
258 windowref_release(This->window_ref);
260 heap_free(This->global_props);
261 release_script_hosts(This);
264 nsIDOMWindow_Release(This->nswindow);
266 list_remove(&This->entry);
267 release_dispex(&This->dispex);
274 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
276 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
278 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
281 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
282 LCID lcid, ITypeInfo **ppTInfo)
284 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
286 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
289 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
290 LPOLESTR *rgszNames, UINT cNames,
291 LCID lcid, DISPID *rgDispId)
293 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
295 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
298 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
299 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
300 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
302 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
304 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
305 pVarResult, pExcepInfo, puArgErr);
308 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
311 nsIDOMWindow *nsWindow;
314 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
315 if(NS_FAILED(nsres)) {
316 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
321 return DISP_E_MEMBERNOTFOUND;
323 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
324 if(NS_FAILED(nsres)) {
325 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
329 *ret = nswindow_to_window(nsWindow);
331 nsIDOMWindow_Release(nsWindow);
336 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
338 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
339 nsIDOMWindowCollection *nsFrames;
344 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
346 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
347 if(NS_FAILED(nsres)) {
348 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
352 if(V_VT(pvarIndex) == VT_I4) {
353 int index = V_I4(pvarIndex);
354 TRACE("Getting index %d\n", index);
356 hres = DISP_E_MEMBERNOTFOUND;
359 hres = get_frame_by_index(nsFrames, index, &window);
362 }else if(V_VT(pvarIndex) == VT_UINT) {
363 unsigned int index = V_UINT(pvarIndex);
364 TRACE("Getting index %u\n", index);
365 hres = get_frame_by_index(nsFrames, index, &window);
368 }else if(V_VT(pvarIndex) == VT_BSTR) {
369 BSTR str = V_BSTR(pvarIndex);
372 TRACE("Getting name %s\n", wine_dbgstr_w(str));
374 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
377 for(i = 0; i < length && !window; ++i) {
378 HTMLWindow *cur_window;
379 nsIDOMWindow *nsWindow;
382 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
383 if(NS_FAILED(nsres)) {
384 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
389 cur_window = nswindow_to_window(nsWindow);
391 nsIDOMWindow_Release(nsWindow);
393 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
395 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
399 if(!strcmpW(id, str))
406 hres = DISP_E_MEMBERNOTFOUND;
414 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
415 V_VT(pvarResult) = VT_DISPATCH;
416 V_DISPATCH(pvarResult) = (IDispatch*)window;
421 nsIDOMWindowCollection_Release(nsFrames);
426 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
428 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
429 nsIDOMWindowCollection *nscollection;
433 TRACE("(%p)->(%p)\n", This, p);
435 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
436 if(NS_FAILED(nsres)) {
437 ERR("GetFrames failed: %08x\n", nsres);
441 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
442 nsIDOMWindowCollection_Release(nscollection);
443 if(NS_FAILED(nsres)) {
444 ERR("GetLength failed: %08x\n", nsres);
452 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
454 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
455 FIXME("(%p)->(%p): semi-stub\n", This, p);
457 /* FIXME: Should return a separate Window object */
458 *p = (IHTMLFramesCollection2*)HTMLWINDOW2(This);
459 HTMLWindow2_AddRef(iface);
463 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
465 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
466 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
470 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
472 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
473 FIXME("(%p)->(%p)\n", This, p);
477 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
479 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
480 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
484 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
486 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
487 FIXME("(%p)->(%p)\n", This, p);
491 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
492 LONG msec, VARIANT *language, LONG *timerID)
494 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
497 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
499 V_VT(&expr_var) = VT_BSTR;
500 V_BSTR(&expr_var) = expression;
502 return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
505 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
507 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
509 TRACE("(%p)->(%d)\n", This, timerID);
511 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
514 #define MAX_MESSAGE_LEN 2000
516 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
518 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
519 WCHAR title[100], *msg = message;
522 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
524 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
525 sizeof(title)/sizeof(WCHAR))) {
526 WARN("Could not load message box title: %d\n", GetLastError());
530 len = SysStringLen(message);
531 if(len > MAX_MESSAGE_LEN) {
532 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
534 return E_OUTOFMEMORY;
535 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
536 msg[MAX_MESSAGE_LEN] = 0;
539 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
545 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
546 VARIANT_BOOL *confirmed)
548 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
551 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
553 if(!confirmed) return E_INVALIDARG;
555 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
556 sizeof(wszTitle)/sizeof(WCHAR))) {
557 WARN("Could not load message box title: %d\n", GetLastError());
558 *confirmed = VARIANT_TRUE;
562 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
563 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
564 *confirmed = VARIANT_TRUE;
565 else *confirmed = VARIANT_FALSE;
577 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
578 WPARAM wparam, LPARAM lparam)
584 prompt_arg *arg = (prompt_arg*)lparam;
587 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
588 sizeof(wszTitle)/sizeof(WCHAR))) {
589 WARN("Could not load message box title: %d\n", GetLastError());
590 EndDialog(hwnd, wparam);
594 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
595 SetWindowTextW(hwnd, wszTitle);
596 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
597 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
603 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
604 EndDialog(hwnd, wparam);
606 case MAKEWPARAM(IDOK, BN_CLICKED):
609 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
610 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
611 INT len = GetWindowTextLengthW(hwndPrompt);
615 EndDialog(hwnd, wparam);
619 V_VT(arg->textdata) = VT_BSTR;
620 if(!len && !arg->dststr)
621 V_BSTR(arg->textdata) = NULL;
624 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
625 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
627 EndDialog(hwnd, wparam);
633 EndDialog(hwnd, IDCANCEL);
640 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
641 BSTR dststr, VARIANT *textdata)
643 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
646 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
648 if(textdata) V_VT(textdata) = VT_NULL;
650 arg.message = message;
652 arg.textdata = textdata;
654 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
655 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
659 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
661 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
663 TRACE("(%p)->(%p)\n", This, p);
665 if(!This->image_factory)
666 This->image_factory = HTMLImageElementFactory_Create(This);
668 *p = HTMLIMGFACTORY(This->image_factory);
669 IHTMLImageElementFactory_AddRef(*p);
674 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
676 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
677 HTMLLocation *location;
680 TRACE("(%p)->(%p)\n", This, p);
682 hres = get_location(This, &location);
686 *p = HTMLLOCATION(location);
690 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
692 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
693 FIXME("(%p)->(%p)\n", This, p);
697 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
699 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
700 FIXME("(%p)->()\n", This);
704 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
706 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
707 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
711 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
713 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
714 FIXME("(%p)->(%p)\n", This, p);
718 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
720 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
722 TRACE("(%p)->(%p)\n", This, p);
724 *p = OmNavigator_Create();
728 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
730 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
734 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
736 nsAString_InitDepend(&name_str, v);
737 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
738 nsAString_Finish(&name_str);
740 ERR("SetName failed: %08x\n", nsres);
745 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
747 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
752 TRACE("(%p)->(%p)\n", This, p);
754 nsAString_Init(&name_str, NULL);
755 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
756 if(NS_SUCCEEDED(nsres)) {
757 const PRUnichar *name;
759 nsAString_GetData(&name_str, &name);
761 *p = SysAllocString(name);
762 hres = *p ? S_OK : E_OUTOFMEMORY;
768 ERR("GetName failed: %08x\n", nsres);
771 nsAString_Finish(&name_str);
776 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
778 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
779 TRACE("(%p)->(%p)\n", This, p);
782 *p = HTMLWINDOW2(This->parent);
783 IHTMLWindow2_AddRef(*p);
790 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
791 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
793 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
794 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
795 debugstr_w(features), replace, pomWindowResult);
799 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
801 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
803 TRACE("(%p)->(%p)\n", This, p);
805 /* FIXME: We should return kind of proxy window here. */
806 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
807 *p = HTMLWINDOW2(This);
811 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
813 HTMLWindow *This = HTMLWINDOW2_THIS(iface), *curr;
814 TRACE("(%p)->(%p)\n", This, p);
819 *p = HTMLWINDOW2(curr);
820 IHTMLWindow2_AddRef(*p);
825 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
827 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
829 TRACE("(%p)->(%p)\n", This, p);
831 /* FIXME: We should return kind of proxy window here. */
832 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
833 *p = HTMLWINDOW2(This);
837 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
839 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
840 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
844 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
846 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
847 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
851 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
853 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
854 FIXME("(%p)->(%p)\n", This, p);
858 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
860 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
861 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
865 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
867 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
868 FIXME("(%p)->(%p)\n", This, p);
872 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
874 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
876 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
878 return set_window_event(This, EVENTID_LOAD, &v);
881 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
883 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
885 TRACE("(%p)->(%p)\n", This, p);
887 return get_window_event(This, EVENTID_LOAD, p);
890 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
892 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
894 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
896 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
899 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
901 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
903 TRACE("(%p)->(%p)\n", This, p);
905 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
908 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
910 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
911 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
915 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
917 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
918 FIXME("(%p)->(%p)\n", This, p);
922 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
924 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
925 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
929 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
931 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
932 FIXME("(%p)->(%p)\n", This, p);
936 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
938 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
939 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
943 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
945 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
946 FIXME("(%p)->(%p)\n", This, p);
950 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
952 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
954 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
956 return set_window_event(This, EVENTID_RESIZE, &v);
959 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
961 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
963 TRACE("(%p)->(%p)\n", This, p);
965 return get_window_event(This, EVENTID_RESIZE, p);
968 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
970 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
971 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
975 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
977 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
978 FIXME("(%p)->(%p)\n", This, p);
982 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
984 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
986 TRACE("(%p)->(%p)\n", This, p);
989 /* FIXME: We should return a wrapper object here */
990 *p = HTMLDOC(&This->doc->basedoc);
991 IHTMLDocument2_AddRef(*p);
999 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1001 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1003 TRACE("(%p)->(%p)\n", This, p);
1006 IHTMLEventObj_AddRef(This->event);
1011 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1013 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1014 FIXME("(%p)->(%p)\n", This, p);
1018 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1019 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1021 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1022 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1026 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1029 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1030 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1034 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1036 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1038 TRACE("(%p)->(%p)\n", This, p);
1043 hres = HTMLScreen_Create(&This->screen);
1049 IHTMLScreen_AddRef(This->screen);
1053 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1055 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1057 TRACE("(%p)->(%p)\n", This, p);
1059 if(!This->option_factory)
1060 This->option_factory = HTMLOptionElementFactory_Create(This);
1062 *p = HTMLOPTFACTORY(This->option_factory);
1063 IHTMLOptionElementFactory_AddRef(*p);
1068 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1070 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1071 FIXME("(%p)->()\n", This);
1075 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1077 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1082 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1084 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1085 FIXME("(%p)->()\n", This);
1089 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1091 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1092 FIXME("(%p)->(%d %d)\n", This, x, y);
1096 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1098 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1099 FIXME("(%p)->(%p)\n", This, p);
1103 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1104 LONG msec, VARIANT *language, LONG *timerID)
1106 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1109 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1111 V_VT(&expr) = VT_BSTR;
1112 V_BSTR(&expr) = expression;
1113 return IHTMLWindow3_setInterval(HTMLWINDOW3(This), &expr, msec, language, timerID);
1116 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1118 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1120 TRACE("(%p)->(%d)\n", This, timerID);
1122 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1125 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1127 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1128 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1132 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1134 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1135 FIXME("(%p)->(%p)\n", This, p);
1139 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1142 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1143 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1147 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1149 HTMLWindow *This = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(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 = HTMLWINDOW2_THIS(iface);
1214 FIXME("(%p)->(%d %d)\n", This, x, y);
1218 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1220 HTMLWindow *This = HTMLWINDOW2_THIS(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 HRESULT HTMLWindow_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1233 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1235 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1236 global_prop_t *prop;
1240 idx = id - MSHTML_DISPID_CUSTOM_MIN;
1241 if(idx >= This->global_prop_cnt)
1242 return DISP_E_MEMBERNOTFOUND;
1244 prop = This->global_props+idx;
1246 switch(prop->type) {
1247 case GLOBAL_SCRIPTVAR: {
1248 IDispatchEx *dispex;
1251 disp = get_script_disp(prop->script_host);
1253 return E_UNEXPECTED;
1255 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1256 if(SUCCEEDED(hres)) {
1257 TRACE("%s >>>\n", debugstr_w(prop->name));
1258 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
1260 TRACE("%s <<<\n", debugstr_w(prop->name));
1262 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
1263 IDispatchEx_Release(dispex);
1265 FIXME("No IDispatchEx\n");
1267 IDispatch_Release(disp);
1270 case GLOBAL_ELEMENTVAR: {
1273 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), prop->name, &elem);
1278 return DISP_E_MEMBERNOTFOUND;
1280 V_VT(res) = VT_DISPATCH;
1281 V_DISPATCH(res) = (IDispatch*)elem;
1285 ERR("invalid type %d\n", prop->type);
1286 hres = DISP_E_MEMBERNOTFOUND;
1292 #undef HTMLWINDOW2_THIS
1294 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1295 HTMLWindow2_QueryInterface,
1297 HTMLWindow2_Release,
1298 HTMLWindow2_GetTypeInfoCount,
1299 HTMLWindow2_GetTypeInfo,
1300 HTMLWindow2_GetIDsOfNames,
1303 HTMLWindow2_get_length,
1304 HTMLWindow2_get_frames,
1305 HTMLWindow2_put_defaultStatus,
1306 HTMLWindow2_get_defaultStatus,
1307 HTMLWindow2_put_status,
1308 HTMLWindow2_get_status,
1309 HTMLWindow2_setTimeout,
1310 HTMLWindow2_clearTimeout,
1312 HTMLWindow2_confirm,
1314 HTMLWindow2_get_Image,
1315 HTMLWindow2_get_location,
1316 HTMLWindow2_get_history,
1318 HTMLWindow2_put_opener,
1319 HTMLWindow2_get_opener,
1320 HTMLWindow2_get_navigator,
1321 HTMLWindow2_put_name,
1322 HTMLWindow2_get_name,
1323 HTMLWindow2_get_parent,
1325 HTMLWindow2_get_self,
1326 HTMLWindow2_get_top,
1327 HTMLWindow2_get_window,
1328 HTMLWindow2_navigate,
1329 HTMLWindow2_put_onfocus,
1330 HTMLWindow2_get_onfocus,
1331 HTMLWindow2_put_onblur,
1332 HTMLWindow2_get_onblur,
1333 HTMLWindow2_put_onload,
1334 HTMLWindow2_get_onload,
1335 HTMLWindow2_put_onbeforeunload,
1336 HTMLWindow2_get_onbeforeunload,
1337 HTMLWindow2_put_onunload,
1338 HTMLWindow2_get_onunload,
1339 HTMLWindow2_put_onhelp,
1340 HTMLWindow2_get_onhelp,
1341 HTMLWindow2_put_onerror,
1342 HTMLWindow2_get_onerror,
1343 HTMLWindow2_put_onresize,
1344 HTMLWindow2_get_onresize,
1345 HTMLWindow2_put_onscroll,
1346 HTMLWindow2_get_onscroll,
1347 HTMLWindow2_get_document,
1348 HTMLWindow2_get_event,
1349 HTMLWindow2_get__newEnum,
1350 HTMLWindow2_showModalDialog,
1351 HTMLWindow2_showHelp,
1352 HTMLWindow2_get_screen,
1353 HTMLWindow2_get_Option,
1355 HTMLWindow2_get_closed,
1358 HTMLWindow2_get_clientInformation,
1359 HTMLWindow2_setInterval,
1360 HTMLWindow2_clearInterval,
1361 HTMLWindow2_put_offscreenBuffering,
1362 HTMLWindow2_get_offscreenBuffering,
1363 HTMLWindow2_execScript,
1364 HTMLWindow2_toString,
1365 HTMLWindow2_scrollBy,
1366 HTMLWindow2_scrollTo,
1369 HTMLWindow2_resizeTo,
1370 HTMLWindow2_resizeBy,
1371 HTMLWindow2_get_external
1374 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
1376 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1378 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1380 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1383 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1385 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1387 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1390 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1392 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1394 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1397 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1399 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1401 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1404 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1405 LCID lcid, ITypeInfo **ppTInfo)
1407 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1409 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1412 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1413 LPOLESTR *rgszNames, UINT cNames,
1414 LCID lcid, DISPID *rgDispId)
1416 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1418 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1421 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1422 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1423 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1425 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1427 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1428 pVarResult, pExcepInfo, puArgErr);
1431 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1433 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1434 FIXME("(%p)->(%p)\n", This, p);
1438 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1440 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1441 FIXME("(%p)->(%p)\n", This, p);
1445 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1447 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1449 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1452 FIXME("No document\n");
1456 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1459 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1461 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1462 FIXME("(%p)->()\n", This);
1466 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1467 BOOL interval, LONG *timer_id)
1469 IDispatch *disp = NULL;
1471 switch(V_VT(expr)) {
1473 disp = V_DISPATCH(expr);
1474 IDispatch_AddRef(disp);
1478 disp = script_parse_event(This, V_BSTR(expr));
1482 FIXME("unimplemented vt=%d\n", V_VT(expr));
1489 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1490 IDispatch_Release(disp);
1495 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1496 VARIANT *language, LONG *timerID)
1498 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1500 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1502 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1505 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1506 VARIANT *language, LONG *timerID)
1508 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1510 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1512 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1515 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1517 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1518 FIXME("(%p)\n", This);
1522 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1524 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1525 FIXME("(%p)->()\n", This);
1529 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1531 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1532 FIXME("(%p)->(%p)\n", This, p);
1536 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1538 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1539 FIXME("(%p)->()\n", This);
1543 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1545 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1546 FIXME("(%p)->(%p)\n", This, p);
1550 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1552 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1553 FIXME("(%p)->(%p)\n", This, p);
1557 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1558 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1560 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1561 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1565 #undef HTMLWINDOW3_THIS
1567 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1568 HTMLWindow3_QueryInterface,
1570 HTMLWindow3_Release,
1571 HTMLWindow3_GetTypeInfoCount,
1572 HTMLWindow3_GetTypeInfo,
1573 HTMLWindow3_GetIDsOfNames,
1575 HTMLWindow3_get_screenLeft,
1576 HTMLWindow3_get_screenTop,
1577 HTMLWindow3_attachEvent,
1578 HTMLWindow3_detachEvent,
1579 HTMLWindow3_setTimeout,
1580 HTMLWindow3_setInterval,
1582 HTMLWindow3_put_onbeforeprint,
1583 HTMLWindow3_get_onbeforeprint,
1584 HTMLWindow3_put_onafterprint,
1585 HTMLWindow3_get_onafterprint,
1586 HTMLWindow3_get_clipboardData,
1587 HTMLWindow3_showModelessDialog
1590 #define HTMLWINDOW4_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow4, iface)
1592 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1594 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1596 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1599 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1601 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1603 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1606 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1608 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1610 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1613 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1615 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1617 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1620 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1621 LCID lcid, ITypeInfo **ppTInfo)
1623 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1625 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1628 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1629 LPOLESTR *rgszNames, UINT cNames,
1630 LCID lcid, DISPID *rgDispId)
1632 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1634 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1637 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1638 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1639 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1641 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1643 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1644 pVarResult, pExcepInfo, puArgErr);
1647 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1648 IDispatch **ppPopup)
1650 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1651 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1655 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1657 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1658 TRACE("(%p)->(%p)\n", This, p);
1660 if(This->frame_element) {
1661 *p = HTMLFRAMEBASE(This->frame_element);
1662 IHTMLFrameBase_AddRef(*p);
1669 #undef HTMLWINDOW4_THIS
1671 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1672 HTMLWindow4_QueryInterface,
1674 HTMLWindow4_Release,
1675 HTMLWindow4_GetTypeInfoCount,
1676 HTMLWindow4_GetTypeInfo,
1677 HTMLWindow4_GetIDsOfNames,
1679 HTMLWindow4_createPopup,
1680 HTMLWindow4_get_frameElement
1683 #define HTMLPRIVWINDOW_THIS(iface) DEFINE_THIS(HTMLWindow, IHTMLPrivateWindow, iface)
1685 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1687 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1689 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1692 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1694 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1696 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1699 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1701 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1703 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1706 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1707 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1709 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1710 DWORD post_data_size = 0;
1711 BYTE *post_data = NULL;
1712 WCHAR *headers = NULL;
1718 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1719 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1722 if(This->doc_obj->hostui) {
1723 OLECHAR *translated_url = NULL;
1725 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1726 if(hres == S_OK && translated_url) {
1727 new_url = SysAllocString(translated_url);
1728 CoTaskMemFree(translated_url);
1732 if(This->doc_obj->client) {
1733 IOleCommandTarget *cmdtrg;
1735 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1736 if(SUCCEEDED(hres)) {
1739 V_VT(&in) = VT_BSTR;
1740 V_BSTR(&in) = new_url;
1741 V_VT(&out) = VT_BOOL;
1742 V_BOOL(&out) = VARIANT_TRUE;
1743 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1744 IOleCommandTarget_Release(cmdtrg);
1750 /* FIXME: Why not set_ready_state? */
1751 This->readystate = READYSTATE_UNINITIALIZED;
1753 hres = CreateURLMoniker(NULL, new_url, &mon);
1755 SysFreeString(new_url);
1760 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1761 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1762 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1766 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1767 if(V_VT(headers_var) != VT_BSTR)
1768 return E_INVALIDARG;
1770 headers = V_BSTR(headers_var);
1773 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1775 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1777 IMoniker_Release(mon);
1781 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1783 hres = async_start_doc_binding(This, bsc);
1785 IUnknown_Release((IUnknown*)bsc);
1786 IMoniker_Release(mon);
1790 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1792 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1793 FIXME("(%p)->(%p)\n", This, url);
1797 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1799 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1800 FIXME("(%p)->(%p)\n", This, cmdtrg);
1804 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1806 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1807 FIXME("(%p)->(%x)\n", This, arg);
1811 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1813 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1814 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1818 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1820 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1821 FIXME("(%p)->(%p)\n", This, url);
1825 #undef HTMLPRIVWINDOW_THIS
1827 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1828 HTMLPrivateWindow_QueryInterface,
1829 HTMLPrivateWindow_AddRef,
1830 HTMLPrivateWindow_Release,
1831 HTMLPrivateWindow_SuperNavigate,
1832 HTMLPrivateWindow_GetPendingUrl,
1833 HTMLPrivateWindow_SetPICSTarget,
1834 HTMLPrivateWindow_PICSComplete,
1835 HTMLPrivateWindow_FindWindowByName,
1836 HTMLPrivateWindow_GetAddressBar
1839 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1841 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1843 HTMLWindow *This = DISPEX_THIS(iface);
1845 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1848 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1850 HTMLWindow *This = DISPEX_THIS(iface);
1852 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1855 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1857 HTMLWindow *This = DISPEX_THIS(iface);
1859 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1862 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1864 HTMLWindow *This = DISPEX_THIS(iface);
1866 TRACE("(%p)->(%p)\n", This, pctinfo);
1868 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1871 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1872 LCID lcid, ITypeInfo **ppTInfo)
1874 HTMLWindow *This = DISPEX_THIS(iface);
1876 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1878 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1881 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1882 LPOLESTR *rgszNames, UINT cNames,
1883 LCID lcid, DISPID *rgDispId)
1885 HTMLWindow *This = DISPEX_THIS(iface);
1889 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1892 for(i=0; i < cNames; i++) {
1893 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1894 hres = IDispatchEx_GetDispID(DISPATCHEX(This), rgszNames[i], 0, rgDispId+i);
1902 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1903 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1904 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1906 HTMLWindow *This = DISPEX_THIS(iface);
1908 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1909 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1911 /* FIXME: Use script dispatch */
1913 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1914 pVarResult, pExcepInfo, puArgErr);
1917 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1919 if(This->global_prop_cnt == This->global_prop_size) {
1920 global_prop_t *new_props;
1923 if(This->global_props) {
1924 new_size = This->global_prop_size*2;
1925 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1928 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1932 This->global_props = new_props;
1933 This->global_prop_size = new_size;
1936 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1937 if(!This->global_props[This->global_prop_cnt].name)
1940 This->global_props[This->global_prop_cnt].type = type;
1941 return This->global_props + This->global_prop_cnt++;
1944 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1946 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1949 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1952 ScriptHost *script_host;
1955 for(i=0; i < This->global_prop_cnt; i++) {
1956 /* FIXME: case sensitivity */
1957 if(!strcmpW(This->global_props[i].name, bstrName)) {
1958 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1963 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1964 global_prop_t *prop;
1966 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1968 return E_OUTOFMEMORY;
1970 prop->script_host = script_host;
1973 *pid = prop_to_dispid(This, prop);
1977 return DISP_E_UNKNOWNNAME;
1980 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1982 HTMLWindow *This = DISPEX_THIS(iface);
1985 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1987 hres = search_window_props(This, bstrName, grfdex, pid);
1988 if(hres != DISP_E_UNKNOWNNAME)
1991 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1992 if(hres != DISP_E_UNKNOWNNAME)
1996 global_prop_t *prop;
1999 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), bstrName, &elem);
2000 if(SUCCEEDED(hres) && elem) {
2001 IHTMLElement_Release(elem);
2003 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
2005 return E_OUTOFMEMORY;
2007 *pid = prop_to_dispid(This, prop);
2012 return DISP_E_UNKNOWNNAME;
2015 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2016 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2018 HTMLWindow *This = DISPEX_THIS(iface);
2020 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2022 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2023 HTMLLocation *location;
2026 TRACE("forwarding to location.href\n");
2028 hres = get_location(This, &location);
2032 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2033 IHTMLLocation_Release(HTMLLOCATION(location));
2037 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2040 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2042 HTMLWindow *This = DISPEX_THIS(iface);
2044 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2046 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
2049 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2051 HTMLWindow *This = DISPEX_THIS(iface);
2053 TRACE("(%p)->(%x)\n", This, id);
2055 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
2058 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2060 HTMLWindow *This = DISPEX_THIS(iface);
2062 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2064 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
2067 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2069 HTMLWindow *This = DISPEX_THIS(iface);
2071 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2073 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
2076 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2078 HTMLWindow *This = DISPEX_THIS(iface);
2080 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2082 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
2085 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2087 HTMLWindow *This = DISPEX_THIS(iface);
2089 TRACE("(%p)->(%p)\n", This, ppunk);
2097 static const IDispatchExVtbl WindowDispExVtbl = {
2098 WindowDispEx_QueryInterface,
2099 WindowDispEx_AddRef,
2100 WindowDispEx_Release,
2101 WindowDispEx_GetTypeInfoCount,
2102 WindowDispEx_GetTypeInfo,
2103 WindowDispEx_GetIDsOfNames,
2104 WindowDispEx_Invoke,
2105 WindowDispEx_GetDispID,
2106 WindowDispEx_InvokeEx,
2107 WindowDispEx_DeleteMemberByName,
2108 WindowDispEx_DeleteMemberByDispID,
2109 WindowDispEx_GetMemberProperties,
2110 WindowDispEx_GetMemberName,
2111 WindowDispEx_GetNextDispID,
2112 WindowDispEx_GetNameSpaceParent
2115 static const tid_t HTMLWindow_iface_tids[] = {
2122 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2128 static dispex_static_data_t HTMLWindow_dispex = {
2129 &HTMLWindow_dispex_vtbl,
2130 DispHTMLWindow2_tid,
2132 HTMLWindow_iface_tids
2135 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2139 window = heap_alloc_zero(sizeof(HTMLWindow));
2141 return E_OUTOFMEMORY;
2143 window->window_ref = heap_alloc(sizeof(windowref_t));
2144 if(!window->window_ref) {
2146 return E_OUTOFMEMORY;
2149 window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
2150 window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
2151 window->lpHTMLWindow4Vtbl = &HTMLWindow4Vtbl;
2152 window->lpIHTMLPrivateWindowVtbl = &HTMLPrivateWindowVtbl;
2153 window->lpIDispatchExVtbl = &WindowDispExVtbl;
2155 window->doc_obj = doc_obj;
2157 window->window_ref->window = window;
2158 window->window_ref->ref = 1;
2160 init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex);
2163 nsIDOMWindow_AddRef(nswindow);
2164 window->nswindow = nswindow;
2167 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2168 window->readystate = READYSTATE_UNINITIALIZED;
2169 list_init(&window->script_hosts);
2171 window->task_magic = get_task_target_magic();
2172 update_window_doc(window);
2174 list_init(&window->children);
2175 list_add_head(&window_list, &window->entry);
2178 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2180 window->parent = parent;
2181 list_add_tail(&parent->children, &window->sibling_entry);
2188 void update_window_doc(HTMLWindow *window)
2190 nsIDOMHTMLDocument *nshtmldoc;
2191 nsIDOMDocument *nsdoc;
2194 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2195 if(NS_FAILED(nsres) || !nsdoc) {
2196 ERR("GetDocument failed: %08x\n", nsres);
2200 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2201 nsIDOMDocument_Release(nsdoc);
2202 if(NS_FAILED(nsres)) {
2203 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2207 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2208 HTMLDocumentNode *doc;
2211 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2212 if(SUCCEEDED(hres)) {
2213 window_set_docnode(window, doc);
2214 htmldoc_release(&doc->basedoc);
2216 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2220 nsIDOMHTMLDocument_Release(nshtmldoc);
2223 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2227 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2228 if(iter->nswindow == nswindow)