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(IsEqualGUID(&IID_IServiceProvider, riid)) {
195 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
196 *ppv = SERVPROV(This);
197 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
198 return *ppv ? S_OK : E_NOINTERFACE;
202 IUnknown_AddRef((IUnknown*)*ppv);
206 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
207 return E_NOINTERFACE;
210 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
212 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
213 LONG ref = InterlockedIncrement(&This->ref);
215 TRACE("(%p) ref=%d\n", This, ref);
220 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
222 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
223 LONG ref = InterlockedDecrement(&This->ref);
225 TRACE("(%p) ref=%d\n", This, ref);
230 remove_target_tasks(This->task_magic);
231 set_window_bscallback(This, NULL);
232 set_current_mon(This, NULL);
233 window_set_docnode(This, NULL);
234 release_children(This);
236 if(This->frame_element)
237 This->frame_element->content_window = NULL;
239 if(This->option_factory) {
240 This->option_factory->window = NULL;
241 IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
244 if(This->image_factory) {
245 This->image_factory->window = NULL;
246 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
250 This->location->window = NULL;
251 IHTMLLocation_Release(HTMLLOCATION(This->location));
255 IHTMLScreen_Release(This->screen);
257 for(i=0; i < This->global_prop_cnt; i++)
258 heap_free(This->global_props[i].name);
260 This->window_ref->window = NULL;
261 windowref_release(This->window_ref);
263 heap_free(This->global_props);
264 release_script_hosts(This);
267 nsIDOMWindow_Release(This->nswindow);
269 list_remove(&This->entry);
270 release_dispex(&This->dispex);
277 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
279 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
281 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
284 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
285 LCID lcid, ITypeInfo **ppTInfo)
287 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
289 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
292 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
293 LPOLESTR *rgszNames, UINT cNames,
294 LCID lcid, DISPID *rgDispId)
296 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
298 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
301 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
302 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
303 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
305 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
307 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
308 pVarResult, pExcepInfo, puArgErr);
311 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
314 nsIDOMWindow *nsWindow;
317 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
318 if(NS_FAILED(nsres)) {
319 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
324 return DISP_E_MEMBERNOTFOUND;
326 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
327 if(NS_FAILED(nsres)) {
328 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
332 *ret = nswindow_to_window(nsWindow);
334 nsIDOMWindow_Release(nsWindow);
339 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
341 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
342 nsIDOMWindowCollection *nsFrames;
347 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
349 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
350 if(NS_FAILED(nsres)) {
351 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
355 if(V_VT(pvarIndex) == VT_I4) {
356 int index = V_I4(pvarIndex);
357 TRACE("Getting index %d\n", index);
359 hres = DISP_E_MEMBERNOTFOUND;
362 hres = get_frame_by_index(nsFrames, index, &window);
365 }else if(V_VT(pvarIndex) == VT_UINT) {
366 unsigned int index = V_UINT(pvarIndex);
367 TRACE("Getting index %u\n", index);
368 hres = get_frame_by_index(nsFrames, index, &window);
371 }else if(V_VT(pvarIndex) == VT_BSTR) {
372 BSTR str = V_BSTR(pvarIndex);
375 TRACE("Getting name %s\n", wine_dbgstr_w(str));
377 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
380 for(i = 0; i < length && !window; ++i) {
381 HTMLWindow *cur_window;
382 nsIDOMWindow *nsWindow;
385 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
386 if(NS_FAILED(nsres)) {
387 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
392 cur_window = nswindow_to_window(nsWindow);
394 nsIDOMWindow_Release(nsWindow);
396 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
398 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
402 if(!strcmpW(id, str))
409 hres = DISP_E_MEMBERNOTFOUND;
417 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
418 V_VT(pvarResult) = VT_DISPATCH;
419 V_DISPATCH(pvarResult) = (IDispatch*)window;
424 nsIDOMWindowCollection_Release(nsFrames);
429 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
431 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
432 nsIDOMWindowCollection *nscollection;
436 TRACE("(%p)->(%p)\n", This, p);
438 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
439 if(NS_FAILED(nsres)) {
440 ERR("GetFrames failed: %08x\n", nsres);
444 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
445 nsIDOMWindowCollection_Release(nscollection);
446 if(NS_FAILED(nsres)) {
447 ERR("GetLength failed: %08x\n", nsres);
455 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
457 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
458 FIXME("(%p)->(%p): semi-stub\n", This, p);
460 /* FIXME: Should return a separate Window object */
461 *p = (IHTMLFramesCollection2*)HTMLWINDOW2(This);
462 HTMLWindow2_AddRef(iface);
466 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
468 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
469 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
473 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
475 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
476 FIXME("(%p)->(%p)\n", This, p);
480 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
482 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
483 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
487 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
489 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
490 FIXME("(%p)->(%p)\n", This, p);
494 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
495 LONG msec, VARIANT *language, LONG *timerID)
497 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
500 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
502 V_VT(&expr_var) = VT_BSTR;
503 V_BSTR(&expr_var) = expression;
505 return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
508 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
510 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
512 TRACE("(%p)->(%d)\n", This, timerID);
514 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
517 #define MAX_MESSAGE_LEN 2000
519 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
521 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
522 WCHAR title[100], *msg = message;
525 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
527 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
528 sizeof(title)/sizeof(WCHAR))) {
529 WARN("Could not load message box title: %d\n", GetLastError());
533 len = SysStringLen(message);
534 if(len > MAX_MESSAGE_LEN) {
535 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
537 return E_OUTOFMEMORY;
538 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
539 msg[MAX_MESSAGE_LEN] = 0;
542 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
548 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
549 VARIANT_BOOL *confirmed)
551 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
554 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
556 if(!confirmed) return E_INVALIDARG;
558 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
559 sizeof(wszTitle)/sizeof(WCHAR))) {
560 WARN("Could not load message box title: %d\n", GetLastError());
561 *confirmed = VARIANT_TRUE;
565 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
566 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
567 *confirmed = VARIANT_TRUE;
568 else *confirmed = VARIANT_FALSE;
580 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
581 WPARAM wparam, LPARAM lparam)
587 prompt_arg *arg = (prompt_arg*)lparam;
590 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
591 sizeof(wszTitle)/sizeof(WCHAR))) {
592 WARN("Could not load message box title: %d\n", GetLastError());
593 EndDialog(hwnd, wparam);
597 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
598 SetWindowTextW(hwnd, wszTitle);
599 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
600 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
606 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
607 EndDialog(hwnd, wparam);
609 case MAKEWPARAM(IDOK, BN_CLICKED):
612 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
613 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
614 INT len = GetWindowTextLengthW(hwndPrompt);
618 EndDialog(hwnd, wparam);
622 V_VT(arg->textdata) = VT_BSTR;
623 if(!len && !arg->dststr)
624 V_BSTR(arg->textdata) = NULL;
627 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
628 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
630 EndDialog(hwnd, wparam);
636 EndDialog(hwnd, IDCANCEL);
643 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
644 BSTR dststr, VARIANT *textdata)
646 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
649 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
651 if(textdata) V_VT(textdata) = VT_NULL;
653 arg.message = message;
655 arg.textdata = textdata;
657 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
658 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
662 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
664 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
666 TRACE("(%p)->(%p)\n", This, p);
668 if(!This->image_factory)
669 This->image_factory = HTMLImageElementFactory_Create(This);
671 *p = HTMLIMGFACTORY(This->image_factory);
672 IHTMLImageElementFactory_AddRef(*p);
677 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
679 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
680 HTMLLocation *location;
683 TRACE("(%p)->(%p)\n", This, p);
685 hres = get_location(This, &location);
689 *p = HTMLLOCATION(location);
693 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
695 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
696 FIXME("(%p)->(%p)\n", This, p);
700 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
702 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
703 FIXME("(%p)->()\n", This);
707 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
709 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
710 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
714 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
716 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
717 FIXME("(%p)->(%p)\n", This, p);
721 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
723 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
725 TRACE("(%p)->(%p)\n", This, p);
727 *p = OmNavigator_Create();
731 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
733 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
737 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
739 nsAString_InitDepend(&name_str, v);
740 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
741 nsAString_Finish(&name_str);
743 ERR("SetName failed: %08x\n", nsres);
748 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
750 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
755 TRACE("(%p)->(%p)\n", This, p);
757 nsAString_Init(&name_str, NULL);
758 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
759 if(NS_SUCCEEDED(nsres)) {
760 const PRUnichar *name;
762 nsAString_GetData(&name_str, &name);
764 *p = SysAllocString(name);
765 hres = *p ? S_OK : E_OUTOFMEMORY;
771 ERR("GetName failed: %08x\n", nsres);
774 nsAString_Finish(&name_str);
779 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
781 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
782 TRACE("(%p)->(%p)\n", This, p);
785 *p = HTMLWINDOW2(This->parent);
786 IHTMLWindow2_AddRef(*p);
793 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
794 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
796 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
797 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
798 debugstr_w(features), replace, pomWindowResult);
802 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
804 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
806 TRACE("(%p)->(%p)\n", This, p);
808 /* FIXME: We should return kind of proxy window here. */
809 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
810 *p = HTMLWINDOW2(This);
814 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
816 HTMLWindow *This = HTMLWINDOW2_THIS(iface), *curr;
817 TRACE("(%p)->(%p)\n", This, p);
822 *p = HTMLWINDOW2(curr);
823 IHTMLWindow2_AddRef(*p);
828 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
830 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
832 TRACE("(%p)->(%p)\n", This, p);
834 /* FIXME: We should return kind of proxy window here. */
835 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
836 *p = HTMLWINDOW2(This);
840 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
842 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
843 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
847 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
849 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
850 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
854 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
856 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
857 FIXME("(%p)->(%p)\n", This, p);
861 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
863 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
864 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
868 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
870 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
871 FIXME("(%p)->(%p)\n", This, p);
875 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
877 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
879 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
881 return set_window_event(This, EVENTID_LOAD, &v);
884 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
886 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
888 TRACE("(%p)->(%p)\n", This, p);
890 return get_window_event(This, EVENTID_LOAD, p);
893 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
895 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
897 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
899 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
902 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
904 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
906 TRACE("(%p)->(%p)\n", This, p);
908 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
911 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
913 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
914 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
918 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
920 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
921 FIXME("(%p)->(%p)\n", This, p);
925 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
927 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
928 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
932 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
934 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
935 FIXME("(%p)->(%p)\n", This, p);
939 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
941 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
942 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
946 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
948 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
949 FIXME("(%p)->(%p)\n", This, p);
953 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
955 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
957 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
959 return set_window_event(This, EVENTID_RESIZE, &v);
962 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
964 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
966 TRACE("(%p)->(%p)\n", This, p);
968 return get_window_event(This, EVENTID_RESIZE, p);
971 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
973 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
974 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
978 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
980 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
981 FIXME("(%p)->(%p)\n", This, p);
985 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
987 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
989 TRACE("(%p)->(%p)\n", This, p);
992 /* FIXME: We should return a wrapper object here */
993 *p = &This->doc->basedoc.IHTMLDocument2_iface;
994 IHTMLDocument2_AddRef(*p);
1002 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1004 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1006 TRACE("(%p)->(%p)\n", This, p);
1009 IHTMLEventObj_AddRef(This->event);
1014 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1016 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1017 FIXME("(%p)->(%p)\n", This, p);
1021 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1022 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1024 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1025 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1029 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1032 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1033 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1037 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1039 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1041 TRACE("(%p)->(%p)\n", This, p);
1046 hres = HTMLScreen_Create(&This->screen);
1052 IHTMLScreen_AddRef(This->screen);
1056 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1058 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1060 TRACE("(%p)->(%p)\n", This, p);
1062 if(!This->option_factory)
1063 This->option_factory = HTMLOptionElementFactory_Create(This);
1065 *p = HTMLOPTFACTORY(This->option_factory);
1066 IHTMLOptionElementFactory_AddRef(*p);
1071 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1073 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1074 FIXME("(%p)->()\n", This);
1078 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1080 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1081 FIXME("(%p)->(%p)\n", This, p);
1085 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1087 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1088 FIXME("(%p)->()\n", This);
1092 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1094 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1095 FIXME("(%p)->(%d %d)\n", This, x, y);
1099 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1101 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1102 FIXME("(%p)->(%p)\n", This, p);
1106 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1107 LONG msec, VARIANT *language, LONG *timerID)
1109 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1112 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1114 V_VT(&expr) = VT_BSTR;
1115 V_BSTR(&expr) = expression;
1116 return IHTMLWindow3_setInterval(HTMLWINDOW3(This), &expr, msec, language, timerID);
1119 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1121 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1123 TRACE("(%p)->(%d)\n", This, timerID);
1125 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1128 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1130 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1131 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1135 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1137 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1138 FIXME("(%p)->(%p)\n", This, p);
1142 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1145 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1147 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1149 return exec_script(This, scode, language, pvarRet);
1152 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1154 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1156 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1158 TRACE("(%p)->(%p)\n", This, String);
1161 return E_INVALIDARG;
1163 *String = SysAllocString(objectW);
1164 return *String ? S_OK : E_OUTOFMEMORY;
1167 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1169 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1172 TRACE("(%p)->(%d %d)\n", This, x, y);
1174 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1175 if(NS_FAILED(nsres))
1176 ERR("ScrollBy failed: %08x\n", nsres);
1181 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1183 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1186 TRACE("(%p)->(%d %d)\n", This, x, y);
1188 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1189 if(NS_FAILED(nsres))
1190 ERR("ScrollTo failed: %08x\n", nsres);
1195 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1197 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1198 FIXME("(%p)->(%d %d)\n", This, x, y);
1202 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1204 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1205 FIXME("(%p)->(%d %d)\n", This, x, y);
1209 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1211 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1212 FIXME("(%p)->(%d %d)\n", This, x, y);
1216 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1218 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1219 FIXME("(%p)->(%d %d)\n", This, x, y);
1223 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1225 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1227 TRACE("(%p)->(%p)\n", This, p);
1231 if(!This->doc_obj->hostui)
1234 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1237 static HRESULT HTMLWindow_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1238 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1240 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1241 global_prop_t *prop;
1245 idx = id - MSHTML_DISPID_CUSTOM_MIN;
1246 if(idx >= This->global_prop_cnt)
1247 return DISP_E_MEMBERNOTFOUND;
1249 prop = This->global_props+idx;
1251 switch(prop->type) {
1252 case GLOBAL_SCRIPTVAR: {
1253 IDispatchEx *dispex;
1256 disp = get_script_disp(prop->script_host);
1258 return E_UNEXPECTED;
1260 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1261 if(SUCCEEDED(hres)) {
1262 TRACE("%s >>>\n", debugstr_w(prop->name));
1263 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
1265 TRACE("%s <<<\n", debugstr_w(prop->name));
1267 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
1268 IDispatchEx_Release(dispex);
1270 FIXME("No IDispatchEx\n");
1272 IDispatch_Release(disp);
1275 case GLOBAL_ELEMENTVAR: {
1278 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), prop->name, &elem);
1283 return DISP_E_MEMBERNOTFOUND;
1285 V_VT(res) = VT_DISPATCH;
1286 V_DISPATCH(res) = (IDispatch*)elem;
1290 ERR("invalid type %d\n", prop->type);
1291 hres = DISP_E_MEMBERNOTFOUND;
1297 #undef HTMLWINDOW2_THIS
1299 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1300 HTMLWindow2_QueryInterface,
1302 HTMLWindow2_Release,
1303 HTMLWindow2_GetTypeInfoCount,
1304 HTMLWindow2_GetTypeInfo,
1305 HTMLWindow2_GetIDsOfNames,
1308 HTMLWindow2_get_length,
1309 HTMLWindow2_get_frames,
1310 HTMLWindow2_put_defaultStatus,
1311 HTMLWindow2_get_defaultStatus,
1312 HTMLWindow2_put_status,
1313 HTMLWindow2_get_status,
1314 HTMLWindow2_setTimeout,
1315 HTMLWindow2_clearTimeout,
1317 HTMLWindow2_confirm,
1319 HTMLWindow2_get_Image,
1320 HTMLWindow2_get_location,
1321 HTMLWindow2_get_history,
1323 HTMLWindow2_put_opener,
1324 HTMLWindow2_get_opener,
1325 HTMLWindow2_get_navigator,
1326 HTMLWindow2_put_name,
1327 HTMLWindow2_get_name,
1328 HTMLWindow2_get_parent,
1330 HTMLWindow2_get_self,
1331 HTMLWindow2_get_top,
1332 HTMLWindow2_get_window,
1333 HTMLWindow2_navigate,
1334 HTMLWindow2_put_onfocus,
1335 HTMLWindow2_get_onfocus,
1336 HTMLWindow2_put_onblur,
1337 HTMLWindow2_get_onblur,
1338 HTMLWindow2_put_onload,
1339 HTMLWindow2_get_onload,
1340 HTMLWindow2_put_onbeforeunload,
1341 HTMLWindow2_get_onbeforeunload,
1342 HTMLWindow2_put_onunload,
1343 HTMLWindow2_get_onunload,
1344 HTMLWindow2_put_onhelp,
1345 HTMLWindow2_get_onhelp,
1346 HTMLWindow2_put_onerror,
1347 HTMLWindow2_get_onerror,
1348 HTMLWindow2_put_onresize,
1349 HTMLWindow2_get_onresize,
1350 HTMLWindow2_put_onscroll,
1351 HTMLWindow2_get_onscroll,
1352 HTMLWindow2_get_document,
1353 HTMLWindow2_get_event,
1354 HTMLWindow2_get__newEnum,
1355 HTMLWindow2_showModalDialog,
1356 HTMLWindow2_showHelp,
1357 HTMLWindow2_get_screen,
1358 HTMLWindow2_get_Option,
1360 HTMLWindow2_get_closed,
1363 HTMLWindow2_get_clientInformation,
1364 HTMLWindow2_setInterval,
1365 HTMLWindow2_clearInterval,
1366 HTMLWindow2_put_offscreenBuffering,
1367 HTMLWindow2_get_offscreenBuffering,
1368 HTMLWindow2_execScript,
1369 HTMLWindow2_toString,
1370 HTMLWindow2_scrollBy,
1371 HTMLWindow2_scrollTo,
1374 HTMLWindow2_resizeTo,
1375 HTMLWindow2_resizeBy,
1376 HTMLWindow2_get_external
1379 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
1381 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1383 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1385 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1388 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1390 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1392 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1395 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1397 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1399 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1402 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1404 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1406 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1409 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1410 LCID lcid, ITypeInfo **ppTInfo)
1412 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1414 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1417 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1418 LPOLESTR *rgszNames, UINT cNames,
1419 LCID lcid, DISPID *rgDispId)
1421 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1423 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1426 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1427 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1428 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1430 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1432 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1433 pVarResult, pExcepInfo, puArgErr);
1436 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1438 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1439 FIXME("(%p)->(%p)\n", This, p);
1443 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1445 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1446 FIXME("(%p)->(%p)\n", This, p);
1450 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1452 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1454 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1457 FIXME("No document\n");
1461 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1464 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1466 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1467 FIXME("(%p)->()\n", This);
1471 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1472 BOOL interval, LONG *timer_id)
1474 IDispatch *disp = NULL;
1476 switch(V_VT(expr)) {
1478 disp = V_DISPATCH(expr);
1479 IDispatch_AddRef(disp);
1483 disp = script_parse_event(This, V_BSTR(expr));
1487 FIXME("unimplemented vt=%d\n", V_VT(expr));
1494 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1495 IDispatch_Release(disp);
1500 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1501 VARIANT *language, LONG *timerID)
1503 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1505 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1507 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1510 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1511 VARIANT *language, LONG *timerID)
1513 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1515 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1517 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1520 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1522 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1523 FIXME("(%p)\n", This);
1527 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1529 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1530 FIXME("(%p)->()\n", This);
1534 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1536 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1537 FIXME("(%p)->(%p)\n", This, p);
1541 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1543 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1544 FIXME("(%p)->()\n", This);
1548 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1550 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1551 FIXME("(%p)->(%p)\n", This, p);
1555 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1557 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1558 FIXME("(%p)->(%p)\n", This, p);
1562 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1563 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1565 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1566 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1570 #undef HTMLWINDOW3_THIS
1572 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1573 HTMLWindow3_QueryInterface,
1575 HTMLWindow3_Release,
1576 HTMLWindow3_GetTypeInfoCount,
1577 HTMLWindow3_GetTypeInfo,
1578 HTMLWindow3_GetIDsOfNames,
1580 HTMLWindow3_get_screenLeft,
1581 HTMLWindow3_get_screenTop,
1582 HTMLWindow3_attachEvent,
1583 HTMLWindow3_detachEvent,
1584 HTMLWindow3_setTimeout,
1585 HTMLWindow3_setInterval,
1587 HTMLWindow3_put_onbeforeprint,
1588 HTMLWindow3_get_onbeforeprint,
1589 HTMLWindow3_put_onafterprint,
1590 HTMLWindow3_get_onafterprint,
1591 HTMLWindow3_get_clipboardData,
1592 HTMLWindow3_showModelessDialog
1595 #define HTMLWINDOW4_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow4, iface)
1597 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1599 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1601 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1604 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1606 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1608 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1611 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1613 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1615 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1618 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1620 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1622 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1625 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1626 LCID lcid, ITypeInfo **ppTInfo)
1628 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1630 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1633 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1634 LPOLESTR *rgszNames, UINT cNames,
1635 LCID lcid, DISPID *rgDispId)
1637 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1639 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1642 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1643 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1644 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1646 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1648 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1649 pVarResult, pExcepInfo, puArgErr);
1652 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1653 IDispatch **ppPopup)
1655 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1656 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1660 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1662 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1663 TRACE("(%p)->(%p)\n", This, p);
1665 if(This->frame_element) {
1666 *p = HTMLFRAMEBASE(This->frame_element);
1667 IHTMLFrameBase_AddRef(*p);
1674 #undef HTMLWINDOW4_THIS
1676 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1677 HTMLWindow4_QueryInterface,
1679 HTMLWindow4_Release,
1680 HTMLWindow4_GetTypeInfoCount,
1681 HTMLWindow4_GetTypeInfo,
1682 HTMLWindow4_GetIDsOfNames,
1684 HTMLWindow4_createPopup,
1685 HTMLWindow4_get_frameElement
1688 #define HTMLPRIVWINDOW_THIS(iface) DEFINE_THIS(HTMLWindow, IHTMLPrivateWindow, iface)
1690 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1692 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1694 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1697 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1699 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1701 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1704 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1706 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1708 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1711 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1712 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1714 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1715 DWORD post_data_size = 0;
1716 BYTE *post_data = NULL;
1717 WCHAR *headers = NULL;
1723 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1724 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1727 if(This->doc_obj->hostui) {
1728 OLECHAR *translated_url = NULL;
1730 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1731 if(hres == S_OK && translated_url) {
1732 new_url = SysAllocString(translated_url);
1733 CoTaskMemFree(translated_url);
1737 if(This->doc_obj->client) {
1738 IOleCommandTarget *cmdtrg;
1740 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1741 if(SUCCEEDED(hres)) {
1744 V_VT(&in) = VT_BSTR;
1745 V_BSTR(&in) = new_url;
1746 V_VT(&out) = VT_BOOL;
1747 V_BOOL(&out) = VARIANT_TRUE;
1748 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1749 IOleCommandTarget_Release(cmdtrg);
1755 /* FIXME: Why not set_ready_state? */
1756 This->readystate = READYSTATE_UNINITIALIZED;
1758 hres = CreateURLMoniker(NULL, new_url, &mon);
1760 SysFreeString(new_url);
1765 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1766 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1767 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1771 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1772 if(V_VT(headers_var) != VT_BSTR)
1773 return E_INVALIDARG;
1775 headers = V_BSTR(headers_var);
1778 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1780 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1782 IMoniker_Release(mon);
1786 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1788 hres = async_start_doc_binding(This, bsc);
1790 IUnknown_Release((IUnknown*)bsc);
1791 IMoniker_Release(mon);
1795 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1797 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1798 FIXME("(%p)->(%p)\n", This, url);
1802 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1804 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1805 FIXME("(%p)->(%p)\n", This, cmdtrg);
1809 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1811 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1812 FIXME("(%p)->(%x)\n", This, arg);
1816 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1818 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1819 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1823 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1825 HTMLWindow *This = HTMLPRIVWINDOW_THIS(iface);
1826 FIXME("(%p)->(%p)\n", This, url);
1830 #undef HTMLPRIVWINDOW_THIS
1832 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1833 HTMLPrivateWindow_QueryInterface,
1834 HTMLPrivateWindow_AddRef,
1835 HTMLPrivateWindow_Release,
1836 HTMLPrivateWindow_SuperNavigate,
1837 HTMLPrivateWindow_GetPendingUrl,
1838 HTMLPrivateWindow_SetPICSTarget,
1839 HTMLPrivateWindow_PICSComplete,
1840 HTMLPrivateWindow_FindWindowByName,
1841 HTMLPrivateWindow_GetAddressBar
1844 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1846 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1848 HTMLWindow *This = DISPEX_THIS(iface);
1850 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1853 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1855 HTMLWindow *This = DISPEX_THIS(iface);
1857 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1860 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1862 HTMLWindow *This = DISPEX_THIS(iface);
1864 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1867 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1869 HTMLWindow *This = DISPEX_THIS(iface);
1871 TRACE("(%p)->(%p)\n", This, pctinfo);
1873 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1876 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1877 LCID lcid, ITypeInfo **ppTInfo)
1879 HTMLWindow *This = DISPEX_THIS(iface);
1881 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1883 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1886 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1887 LPOLESTR *rgszNames, UINT cNames,
1888 LCID lcid, DISPID *rgDispId)
1890 HTMLWindow *This = DISPEX_THIS(iface);
1894 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1897 for(i=0; i < cNames; i++) {
1898 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1899 hres = IDispatchEx_GetDispID(DISPATCHEX(This), rgszNames[i], 0, rgDispId+i);
1907 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1908 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1909 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1911 HTMLWindow *This = DISPEX_THIS(iface);
1913 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1914 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1916 /* FIXME: Use script dispatch */
1918 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1919 pVarResult, pExcepInfo, puArgErr);
1922 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1924 if(This->global_prop_cnt == This->global_prop_size) {
1925 global_prop_t *new_props;
1928 if(This->global_props) {
1929 new_size = This->global_prop_size*2;
1930 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1933 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1937 This->global_props = new_props;
1938 This->global_prop_size = new_size;
1941 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1942 if(!This->global_props[This->global_prop_cnt].name)
1945 This->global_props[This->global_prop_cnt].type = type;
1946 return This->global_props + This->global_prop_cnt++;
1949 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1951 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1954 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1957 ScriptHost *script_host;
1960 for(i=0; i < This->global_prop_cnt; i++) {
1961 /* FIXME: case sensitivity */
1962 if(!strcmpW(This->global_props[i].name, bstrName)) {
1963 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1968 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1969 global_prop_t *prop;
1971 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1973 return E_OUTOFMEMORY;
1975 prop->script_host = script_host;
1978 *pid = prop_to_dispid(This, prop);
1982 return DISP_E_UNKNOWNNAME;
1985 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1987 HTMLWindow *This = DISPEX_THIS(iface);
1990 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1992 hres = search_window_props(This, bstrName, grfdex, pid);
1993 if(hres != DISP_E_UNKNOWNNAME)
1996 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1997 if(hres != DISP_E_UNKNOWNNAME)
2001 global_prop_t *prop;
2004 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), bstrName, &elem);
2005 if(SUCCEEDED(hres) && elem) {
2006 IHTMLElement_Release(elem);
2008 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
2010 return E_OUTOFMEMORY;
2012 *pid = prop_to_dispid(This, prop);
2017 return DISP_E_UNKNOWNNAME;
2020 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2021 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2023 HTMLWindow *This = DISPEX_THIS(iface);
2025 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2027 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2028 HTMLLocation *location;
2031 TRACE("forwarding to location.href\n");
2033 hres = get_location(This, &location);
2037 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2038 IHTMLLocation_Release(HTMLLOCATION(location));
2042 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2045 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2047 HTMLWindow *This = DISPEX_THIS(iface);
2049 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2051 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
2054 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2056 HTMLWindow *This = DISPEX_THIS(iface);
2058 TRACE("(%p)->(%x)\n", This, id);
2060 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
2063 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2065 HTMLWindow *This = DISPEX_THIS(iface);
2067 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2069 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
2072 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2074 HTMLWindow *This = DISPEX_THIS(iface);
2076 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2078 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
2081 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2083 HTMLWindow *This = DISPEX_THIS(iface);
2085 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2087 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
2090 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2092 HTMLWindow *This = DISPEX_THIS(iface);
2094 TRACE("(%p)->(%p)\n", This, ppunk);
2102 static const IDispatchExVtbl WindowDispExVtbl = {
2103 WindowDispEx_QueryInterface,
2104 WindowDispEx_AddRef,
2105 WindowDispEx_Release,
2106 WindowDispEx_GetTypeInfoCount,
2107 WindowDispEx_GetTypeInfo,
2108 WindowDispEx_GetIDsOfNames,
2109 WindowDispEx_Invoke,
2110 WindowDispEx_GetDispID,
2111 WindowDispEx_InvokeEx,
2112 WindowDispEx_DeleteMemberByName,
2113 WindowDispEx_DeleteMemberByDispID,
2114 WindowDispEx_GetMemberProperties,
2115 WindowDispEx_GetMemberName,
2116 WindowDispEx_GetNextDispID,
2117 WindowDispEx_GetNameSpaceParent
2120 #define SERVPROV_THIS(iface) DEFINE_THIS(HTMLWindow, ServiceProvider, iface)
2122 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2124 HTMLWindow *This = SERVPROV_THIS(iface);
2125 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
2128 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2130 HTMLWindow *This = SERVPROV_THIS(iface);
2131 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
2134 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2136 HTMLWindow *This = SERVPROV_THIS(iface);
2137 return IHTMLWindow2_Release(HTMLWINDOW2(This));
2140 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2142 HTMLWindow *This = SERVPROV_THIS(iface);
2144 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2145 TRACE("IID_IHTMLWindow2\n");
2146 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
2149 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2152 return E_NOINTERFACE;
2154 return IServiceProvider_QueryService(SERVPROV(&This->doc_obj->basedoc), guidService, riid, ppv);
2157 #undef SERVPROV_THIS
2159 static const IServiceProviderVtbl ServiceProviderVtbl = {
2160 HTMLWindowSP_QueryInterface,
2161 HTMLWindowSP_AddRef,
2162 HTMLWindowSP_Release,
2163 HTMLWindowSP_QueryService
2166 static const tid_t HTMLWindow_iface_tids[] = {
2173 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2179 static dispex_static_data_t HTMLWindow_dispex = {
2180 &HTMLWindow_dispex_vtbl,
2181 DispHTMLWindow2_tid,
2183 HTMLWindow_iface_tids
2186 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2190 window = heap_alloc_zero(sizeof(HTMLWindow));
2192 return E_OUTOFMEMORY;
2194 window->window_ref = heap_alloc(sizeof(windowref_t));
2195 if(!window->window_ref) {
2197 return E_OUTOFMEMORY;
2200 window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
2201 window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
2202 window->lpHTMLWindow4Vtbl = &HTMLWindow4Vtbl;
2203 window->lpIHTMLPrivateWindowVtbl = &HTMLPrivateWindowVtbl;
2204 window->lpIDispatchExVtbl = &WindowDispExVtbl;
2205 window->lpServiceProviderVtbl = &ServiceProviderVtbl;
2207 window->doc_obj = doc_obj;
2209 window->window_ref->window = window;
2210 window->window_ref->ref = 1;
2212 init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex);
2215 nsIDOMWindow_AddRef(nswindow);
2216 window->nswindow = nswindow;
2219 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2220 window->readystate = READYSTATE_UNINITIALIZED;
2221 list_init(&window->script_hosts);
2223 window->task_magic = get_task_target_magic();
2224 update_window_doc(window);
2226 list_init(&window->children);
2227 list_add_head(&window_list, &window->entry);
2230 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
2232 window->parent = parent;
2233 list_add_tail(&parent->children, &window->sibling_entry);
2240 void update_window_doc(HTMLWindow *window)
2242 nsIDOMHTMLDocument *nshtmldoc;
2243 nsIDOMDocument *nsdoc;
2246 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2247 if(NS_FAILED(nsres) || !nsdoc) {
2248 ERR("GetDocument failed: %08x\n", nsres);
2252 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2253 nsIDOMDocument_Release(nsdoc);
2254 if(NS_FAILED(nsres)) {
2255 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2259 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2260 HTMLDocumentNode *doc;
2263 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2264 if(SUCCEEDED(hres)) {
2265 window_set_docnode(window, doc);
2266 htmldoc_release(&doc->basedoc);
2268 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2272 nsIDOMHTMLDocument_Release(nshtmldoc);
2275 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2279 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2280 if(iter->nswindow == nswindow)