msxml3: Basic support for startElement()/endElement().
[wine/multimedia.git] / dlls / mshtml / htmlwindow.c
blobe0d542be2283b795d220818261e605118174ef8b
1 /*
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "mshtmdid.h"
28 #include "shlguid.h"
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
34 #include "resource.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static struct list window_list = LIST_INIT(window_list);
40 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
42 if(window->doc) {
43 if(window->doc_obj && window == window->doc_obj->basedoc.window)
44 window->doc->basedoc.cp_container.forward_container = NULL;
45 abort_document_bindings(window->doc);
46 window->doc->basedoc.window = NULL;
47 htmldoc_release(&window->doc->basedoc);
49 window->doc = doc_node;
50 if(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;
57 if(doc_node)
58 htmldoc_addref(&doc_node->basedoc);
61 if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
62 nsIDOMNSHTMLDocument *nshtmldoc;
63 nsAString mode_str;
64 nsresult nsres;
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);
74 if(NS_FAILED(nsres))
75 ERR("SetDesignMode failed: %08x\n", nsres);
76 }else {
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;
87 nsresult nsres;
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);
93 return NULL;
96 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
97 nsIDOMDocumentView_Release(nsdocview);
98 if(NS_FAILED(nsres)) {
99 ERR("GetDefaultView failed: %08x\n", nsres);
100 return NULL;
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);
107 return NULL;
110 return nswindow;
113 static void release_children(HTMLWindow *This)
115 HTMLWindow *child;
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(&child->IHTMLWindow2_iface);
126 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
128 if(This->location) {
129 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
130 }else {
131 HRESULT hres;
133 hres = HTMLLocation_Create(This, &This->location);
134 if(FAILED(hres))
135 return hres;
138 *ret = This->location;
139 return S_OK;
142 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
144 if(!window->doc) {
145 FIXME("No document\n");
146 return E_FAIL;
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)
154 if(!window->doc) {
155 FIXME("No document\n");
156 return E_FAIL;
159 return get_event_handler(&window->doc->body_event_target, eid, var);
162 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
164 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
167 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
169 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
171 *ppv = NULL;
173 if(IsEqualGUID(&IID_IUnknown, riid)) {
174 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
175 *ppv = &This->IHTMLWindow2_iface;
176 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
177 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
178 *ppv = &This->IHTMLWindow2_iface;
179 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
180 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
181 *ppv = &This->IDispatchEx_iface;
182 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
183 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
184 *ppv = &This->IHTMLWindow2_iface;
185 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
186 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
187 *ppv = &This->IHTMLWindow2_iface;
188 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
189 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
190 *ppv = &This->IHTMLWindow3_iface;
191 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
192 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
193 *ppv = &This->IHTMLWindow4_iface;
194 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
195 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
196 *ppv = &This->IHTMLPrivateWindow_iface;
197 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
198 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
199 *ppv = &This->IServiceProvider_iface;
200 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
201 return *ppv ? S_OK : E_NOINTERFACE;
204 if(*ppv) {
205 IUnknown_AddRef((IUnknown*)*ppv);
206 return S_OK;
209 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
210 return E_NOINTERFACE;
213 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
215 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
216 LONG ref = InterlockedIncrement(&This->ref);
218 TRACE("(%p) ref=%d\n", This, ref);
220 return ref;
223 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
225 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
226 LONG ref = InterlockedDecrement(&This->ref);
228 TRACE("(%p) ref=%d\n", This, ref);
230 if(!ref) {
231 DWORD i;
233 remove_target_tasks(This->task_magic);
234 set_window_bscallback(This, NULL);
235 set_current_mon(This, NULL);
236 window_set_docnode(This, NULL);
237 release_children(This);
239 if(This->secmgr)
240 IInternetSecurityManager_Release(This->secmgr);
242 if(This->frame_element)
243 This->frame_element->content_window = NULL;
245 if(This->option_factory) {
246 This->option_factory->window = NULL;
247 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
250 if(This->image_factory) {
251 This->image_factory->window = NULL;
252 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
255 if(This->location) {
256 This->location->window = NULL;
257 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
260 if(This->screen)
261 IHTMLScreen_Release(This->screen);
263 for(i=0; i < This->global_prop_cnt; i++)
264 heap_free(This->global_props[i].name);
266 This->window_ref->window = NULL;
267 windowref_release(This->window_ref);
269 heap_free(This->global_props);
270 release_script_hosts(This);
272 if(This->nswindow)
273 nsIDOMWindow_Release(This->nswindow);
275 list_remove(&This->entry);
276 release_dispex(&This->dispex);
277 heap_free(This);
280 return ref;
283 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
285 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
287 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
290 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
291 LCID lcid, ITypeInfo **ppTInfo)
293 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
295 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
298 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
299 LPOLESTR *rgszNames, UINT cNames,
300 LCID lcid, DISPID *rgDispId)
302 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
304 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
305 rgDispId);
308 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
309 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
310 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
312 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
314 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
315 pDispParams, pVarResult, pExcepInfo, puArgErr);
318 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
320 PRUint32 length;
321 nsIDOMWindow *nsWindow;
322 nsresult nsres;
324 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
325 if(NS_FAILED(nsres)) {
326 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
327 return E_FAIL;
330 if(index >= length)
331 return DISP_E_MEMBERNOTFOUND;
333 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
334 if(NS_FAILED(nsres)) {
335 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
336 return E_FAIL;
339 *ret = nswindow_to_window(nsWindow);
341 nsIDOMWindow_Release(nsWindow);
343 return S_OK;
346 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
348 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
349 nsIDOMWindowCollection *nsFrames;
350 HTMLWindow *window;
351 HRESULT hres;
352 nsresult nsres;
354 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
356 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
357 if(NS_FAILED(nsres)) {
358 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
359 return E_FAIL;
362 if(V_VT(pvarIndex) == VT_I4) {
363 int index = V_I4(pvarIndex);
364 TRACE("Getting index %d\n", index);
365 if(index < 0) {
366 hres = DISP_E_MEMBERNOTFOUND;
367 goto cleanup;
369 hres = get_frame_by_index(nsFrames, index, &window);
370 if(FAILED(hres))
371 goto cleanup;
372 }else if(V_VT(pvarIndex) == VT_UINT) {
373 unsigned int index = V_UINT(pvarIndex);
374 TRACE("Getting index %u\n", index);
375 hres = get_frame_by_index(nsFrames, index, &window);
376 if(FAILED(hres))
377 goto cleanup;
378 }else if(V_VT(pvarIndex) == VT_BSTR) {
379 BSTR str = V_BSTR(pvarIndex);
380 PRUint32 length, i;
382 TRACE("Getting name %s\n", wine_dbgstr_w(str));
384 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
386 window = NULL;
387 for(i = 0; i < length && !window; ++i) {
388 HTMLWindow *cur_window;
389 nsIDOMWindow *nsWindow;
390 BSTR id;
392 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
393 if(NS_FAILED(nsres)) {
394 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
395 hres = E_FAIL;
396 goto cleanup;
399 cur_window = nswindow_to_window(nsWindow);
401 nsIDOMWindow_Release(nsWindow);
403 hres = IHTMLElement_get_id(&cur_window->frame_element->element.IHTMLElement_iface, &id);
404 if(FAILED(hres)) {
405 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
406 goto cleanup;
409 if(!strcmpW(id, str))
410 window = cur_window;
412 SysFreeString(id);
415 if(!window) {
416 hres = DISP_E_MEMBERNOTFOUND;
417 goto cleanup;
419 }else {
420 hres = E_INVALIDARG;
421 goto cleanup;
424 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
425 V_VT(pvarResult) = VT_DISPATCH;
426 V_DISPATCH(pvarResult) = (IDispatch*)window;
428 hres = S_OK;
430 cleanup:
431 nsIDOMWindowCollection_Release(nsFrames);
433 return hres;
436 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
438 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
439 nsIDOMWindowCollection *nscollection;
440 PRUint32 length;
441 nsresult nsres;
443 TRACE("(%p)->(%p)\n", This, p);
445 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
446 if(NS_FAILED(nsres)) {
447 ERR("GetFrames failed: %08x\n", nsres);
448 return E_FAIL;
451 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
452 nsIDOMWindowCollection_Release(nscollection);
453 if(NS_FAILED(nsres)) {
454 ERR("GetLength failed: %08x\n", nsres);
455 return E_FAIL;
458 *p = length;
459 return S_OK;
462 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
464 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
465 FIXME("(%p)->(%p): semi-stub\n", This, p);
467 /* FIXME: Should return a separate Window object */
468 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
469 HTMLWindow2_AddRef(iface);
470 return S_OK;
473 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
475 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
476 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
477 return E_NOTIMPL;
480 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
482 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
489 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
490 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
491 return E_NOTIMPL;
494 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
496 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
497 FIXME("(%p)->(%p)\n", This, p);
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
502 LONG msec, VARIANT *language, LONG *timerID)
504 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
505 VARIANT expr_var;
507 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
509 V_VT(&expr_var) = VT_BSTR;
510 V_BSTR(&expr_var) = expression;
512 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
515 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
517 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
519 TRACE("(%p)->(%d)\n", This, timerID);
521 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
524 #define MAX_MESSAGE_LEN 2000
526 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
528 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
529 WCHAR title[100], *msg = message;
530 DWORD len;
532 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
534 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
535 sizeof(title)/sizeof(WCHAR))) {
536 WARN("Could not load message box title: %d\n", GetLastError());
537 return S_OK;
540 len = SysStringLen(message);
541 if(len > MAX_MESSAGE_LEN) {
542 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
543 if(!msg)
544 return E_OUTOFMEMORY;
545 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
546 msg[MAX_MESSAGE_LEN] = 0;
549 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
550 if(msg != message)
551 heap_free(msg);
552 return S_OK;
555 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
556 VARIANT_BOOL *confirmed)
558 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
559 WCHAR wszTitle[100];
561 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
563 if(!confirmed) return E_INVALIDARG;
565 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
566 sizeof(wszTitle)/sizeof(WCHAR))) {
567 WARN("Could not load message box title: %d\n", GetLastError());
568 *confirmed = VARIANT_TRUE;
569 return S_OK;
572 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
573 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
574 *confirmed = VARIANT_TRUE;
575 else *confirmed = VARIANT_FALSE;
577 return S_OK;
580 typedef struct
582 BSTR message;
583 BSTR dststr;
584 VARIANT *textdata;
585 }prompt_arg;
587 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
588 WPARAM wparam, LPARAM lparam)
590 switch(msg)
592 case WM_INITDIALOG:
594 prompt_arg *arg = (prompt_arg*)lparam;
595 WCHAR wszTitle[100];
597 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
598 sizeof(wszTitle)/sizeof(WCHAR))) {
599 WARN("Could not load message box title: %d\n", GetLastError());
600 EndDialog(hwnd, wparam);
601 return FALSE;
604 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
605 SetWindowTextW(hwnd, wszTitle);
606 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
607 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
608 return FALSE;
610 case WM_COMMAND:
611 switch(wparam)
613 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
614 EndDialog(hwnd, wparam);
615 return TRUE;
616 case MAKEWPARAM(IDOK, BN_CLICKED):
618 prompt_arg *arg =
619 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
620 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
621 INT len = GetWindowTextLengthW(hwndPrompt);
623 if(!arg->textdata)
625 EndDialog(hwnd, wparam);
626 return TRUE;
629 V_VT(arg->textdata) = VT_BSTR;
630 if(!len && !arg->dststr)
631 V_BSTR(arg->textdata) = NULL;
632 else
634 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
635 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
637 EndDialog(hwnd, wparam);
638 return TRUE;
641 return FALSE;
642 case WM_CLOSE:
643 EndDialog(hwnd, IDCANCEL);
644 return TRUE;
645 default:
646 return FALSE;
650 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
651 BSTR dststr, VARIANT *textdata)
653 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
654 prompt_arg arg;
656 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
658 if(textdata) V_VT(textdata) = VT_NULL;
660 arg.message = message;
661 arg.dststr = dststr;
662 arg.textdata = textdata;
664 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
665 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
666 return S_OK;
669 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
671 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
673 TRACE("(%p)->(%p)\n", This, p);
675 if(!This->image_factory)
676 This->image_factory = HTMLImageElementFactory_Create(This);
678 *p = &This->image_factory->IHTMLImageElementFactory_iface;
679 IHTMLImageElementFactory_AddRef(*p);
681 return S_OK;
684 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
686 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
687 HTMLLocation *location;
688 HRESULT hres;
690 TRACE("(%p)->(%p)\n", This, p);
692 hres = get_location(This, &location);
693 if(FAILED(hres))
694 return hres;
696 *p = &location->IHTMLLocation_iface;
697 return S_OK;
700 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
702 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
703 FIXME("(%p)->(%p)\n", This, p);
704 return E_NOTIMPL;
707 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
709 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
710 FIXME("(%p)->()\n", This);
711 return E_NOTIMPL;
714 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
716 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
717 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
718 return E_NOTIMPL;
721 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
723 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
724 FIXME("(%p)->(%p)\n", This, p);
725 return E_NOTIMPL;
728 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
730 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
732 TRACE("(%p)->(%p)\n", This, p);
734 *p = OmNavigator_Create();
735 return S_OK;
738 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
740 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
741 nsAString name_str;
742 nsresult nsres;
744 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
746 nsAString_InitDepend(&name_str, v);
747 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
748 nsAString_Finish(&name_str);
749 if(NS_FAILED(nsres))
750 ERR("SetName failed: %08x\n", nsres);
752 return S_OK;
755 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
757 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
758 nsAString name_str;
759 nsresult nsres;
760 HRESULT hres;
762 TRACE("(%p)->(%p)\n", This, p);
764 nsAString_Init(&name_str, NULL);
765 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
766 if(NS_SUCCEEDED(nsres)) {
767 const PRUnichar *name;
769 nsAString_GetData(&name_str, &name);
770 if(*name) {
771 *p = SysAllocString(name);
772 hres = *p ? S_OK : E_OUTOFMEMORY;
773 }else {
774 *p = NULL;
775 hres = S_OK;
777 }else {
778 ERR("GetName failed: %08x\n", nsres);
779 hres = E_FAIL;
781 nsAString_Finish(&name_str);
783 return hres;
786 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
788 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
789 TRACE("(%p)->(%p)\n", This, p);
791 if(This->parent) {
792 *p = &This->parent->IHTMLWindow2_iface;
793 IHTMLWindow2_AddRef(*p);
794 }else
795 *p = NULL;
797 return S_OK;
800 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
801 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
803 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
804 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
805 debugstr_w(features), replace, pomWindowResult);
806 return E_NOTIMPL;
809 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
811 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
813 TRACE("(%p)->(%p)\n", This, p);
815 /* FIXME: We should return kind of proxy window here. */
816 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
817 *p = &This->IHTMLWindow2_iface;
818 return S_OK;
821 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
823 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
824 HTMLWindow *curr;
825 TRACE("(%p)->(%p)\n", This, p);
827 curr = This;
828 while(curr->parent)
829 curr = curr->parent;
830 *p = &curr->IHTMLWindow2_iface;
831 IHTMLWindow2_AddRef(*p);
833 return S_OK;
836 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
838 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
840 TRACE("(%p)->(%p)\n", This, p);
842 /* FIXME: We should return kind of proxy window here. */
843 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
844 *p = &This->IHTMLWindow2_iface;
845 return S_OK;
848 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
850 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
851 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
852 return E_NOTIMPL;
855 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
857 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
858 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
859 return E_NOTIMPL;
862 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
864 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
865 FIXME("(%p)->(%p)\n", This, p);
866 return E_NOTIMPL;
869 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
871 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
872 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
873 return E_NOTIMPL;
876 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
878 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
879 FIXME("(%p)->(%p)\n", This, p);
880 return E_NOTIMPL;
883 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
885 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
887 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
889 return set_window_event(This, EVENTID_LOAD, &v);
892 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
894 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
896 TRACE("(%p)->(%p)\n", This, p);
898 return get_window_event(This, EVENTID_LOAD, p);
901 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
903 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
905 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
907 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
910 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
912 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
914 TRACE("(%p)->(%p)\n", This, p);
916 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
919 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
921 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
922 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
923 return E_NOTIMPL;
926 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
928 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
929 FIXME("(%p)->(%p)\n", This, p);
930 return E_NOTIMPL;
933 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
935 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
936 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
937 return E_NOTIMPL;
940 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
942 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
943 FIXME("(%p)->(%p)\n", This, p);
944 return E_NOTIMPL;
947 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
949 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
950 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
951 return E_NOTIMPL;
954 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
956 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
957 FIXME("(%p)->(%p)\n", This, p);
958 return E_NOTIMPL;
961 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
963 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
965 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
967 return set_window_event(This, EVENTID_RESIZE, &v);
970 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
972 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
974 TRACE("(%p)->(%p)\n", This, p);
976 return get_window_event(This, EVENTID_RESIZE, p);
979 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
981 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
982 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
983 return E_NOTIMPL;
986 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
988 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
989 FIXME("(%p)->(%p)\n", This, p);
990 return E_NOTIMPL;
993 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
995 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
997 TRACE("(%p)->(%p)\n", This, p);
999 if(This->doc) {
1000 /* FIXME: We should return a wrapper object here */
1001 *p = &This->doc->basedoc.IHTMLDocument2_iface;
1002 IHTMLDocument2_AddRef(*p);
1003 }else {
1004 *p = NULL;
1007 return S_OK;
1010 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1012 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1014 TRACE("(%p)->(%p)\n", This, p);
1016 if(This->event)
1017 IHTMLEventObj_AddRef(This->event);
1018 *p = This->event;
1019 return S_OK;
1022 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1024 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1025 FIXME("(%p)->(%p)\n", This, p);
1026 return E_NOTIMPL;
1029 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1030 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1032 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1033 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1034 return E_NOTIMPL;
1037 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1038 BSTR features)
1040 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1041 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1042 return E_NOTIMPL;
1045 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1047 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1049 TRACE("(%p)->(%p)\n", This, p);
1051 if(!This->screen) {
1052 HRESULT hres;
1054 hres = HTMLScreen_Create(&This->screen);
1055 if(FAILED(hres))
1056 return hres;
1059 *p = This->screen;
1060 IHTMLScreen_AddRef(This->screen);
1061 return S_OK;
1064 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1066 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1068 TRACE("(%p)->(%p)\n", This, p);
1070 if(!This->option_factory)
1071 This->option_factory = HTMLOptionElementFactory_Create(This);
1073 *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1074 IHTMLOptionElementFactory_AddRef(*p);
1076 return S_OK;
1079 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1081 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1083 TRACE("(%p)->()\n", This);
1085 if(This->doc_obj)
1086 SetFocus(This->doc_obj->hwnd);
1087 return S_OK;
1090 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1092 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1093 FIXME("(%p)->(%p)\n", This, p);
1094 return E_NOTIMPL;
1097 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1099 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1100 FIXME("(%p)->()\n", This);
1101 return E_NOTIMPL;
1104 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1106 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1107 FIXME("(%p)->(%d %d)\n", This, x, y);
1108 return E_NOTIMPL;
1111 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1113 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1114 FIXME("(%p)->(%p)\n", This, p);
1115 return E_NOTIMPL;
1118 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1119 LONG msec, VARIANT *language, LONG *timerID)
1121 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1122 VARIANT expr;
1124 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1126 V_VT(&expr) = VT_BSTR;
1127 V_BSTR(&expr) = expression;
1128 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1131 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1133 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1135 TRACE("(%p)->(%d)\n", This, timerID);
1137 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1140 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1142 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1143 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1144 return E_NOTIMPL;
1147 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1149 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1150 FIXME("(%p)->(%p)\n", This, p);
1151 return E_NOTIMPL;
1154 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1155 VARIANT *pvarRet)
1157 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1159 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1161 return exec_script(This, scode, language, pvarRet);
1164 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1166 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1168 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1170 TRACE("(%p)->(%p)\n", This, String);
1172 if(!String)
1173 return E_INVALIDARG;
1175 *String = SysAllocString(objectW);
1176 return *String ? S_OK : E_OUTOFMEMORY;
1179 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1181 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1182 nsresult nsres;
1184 TRACE("(%p)->(%d %d)\n", This, x, y);
1186 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1187 if(NS_FAILED(nsres))
1188 ERR("ScrollBy failed: %08x\n", nsres);
1190 return S_OK;
1193 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1195 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1196 nsresult nsres;
1198 TRACE("(%p)->(%d %d)\n", This, x, y);
1200 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1201 if(NS_FAILED(nsres))
1202 ERR("ScrollTo failed: %08x\n", nsres);
1204 return S_OK;
1207 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1209 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1210 FIXME("(%p)->(%d %d)\n", This, x, y);
1211 return E_NOTIMPL;
1214 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1216 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1217 FIXME("(%p)->(%d %d)\n", This, x, y);
1218 return E_NOTIMPL;
1221 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1223 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1224 FIXME("(%p)->(%d %d)\n", This, x, y);
1225 return E_NOTIMPL;
1228 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1230 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1231 FIXME("(%p)->(%d %d)\n", This, x, y);
1232 return E_NOTIMPL;
1235 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1237 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1239 TRACE("(%p)->(%p)\n", This, p);
1241 *p = NULL;
1243 if(!This->doc_obj->hostui)
1244 return S_OK;
1246 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1249 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1250 HTMLWindow2_QueryInterface,
1251 HTMLWindow2_AddRef,
1252 HTMLWindow2_Release,
1253 HTMLWindow2_GetTypeInfoCount,
1254 HTMLWindow2_GetTypeInfo,
1255 HTMLWindow2_GetIDsOfNames,
1256 HTMLWindow2_Invoke,
1257 HTMLWindow2_item,
1258 HTMLWindow2_get_length,
1259 HTMLWindow2_get_frames,
1260 HTMLWindow2_put_defaultStatus,
1261 HTMLWindow2_get_defaultStatus,
1262 HTMLWindow2_put_status,
1263 HTMLWindow2_get_status,
1264 HTMLWindow2_setTimeout,
1265 HTMLWindow2_clearTimeout,
1266 HTMLWindow2_alert,
1267 HTMLWindow2_confirm,
1268 HTMLWindow2_prompt,
1269 HTMLWindow2_get_Image,
1270 HTMLWindow2_get_location,
1271 HTMLWindow2_get_history,
1272 HTMLWindow2_close,
1273 HTMLWindow2_put_opener,
1274 HTMLWindow2_get_opener,
1275 HTMLWindow2_get_navigator,
1276 HTMLWindow2_put_name,
1277 HTMLWindow2_get_name,
1278 HTMLWindow2_get_parent,
1279 HTMLWindow2_open,
1280 HTMLWindow2_get_self,
1281 HTMLWindow2_get_top,
1282 HTMLWindow2_get_window,
1283 HTMLWindow2_navigate,
1284 HTMLWindow2_put_onfocus,
1285 HTMLWindow2_get_onfocus,
1286 HTMLWindow2_put_onblur,
1287 HTMLWindow2_get_onblur,
1288 HTMLWindow2_put_onload,
1289 HTMLWindow2_get_onload,
1290 HTMLWindow2_put_onbeforeunload,
1291 HTMLWindow2_get_onbeforeunload,
1292 HTMLWindow2_put_onunload,
1293 HTMLWindow2_get_onunload,
1294 HTMLWindow2_put_onhelp,
1295 HTMLWindow2_get_onhelp,
1296 HTMLWindow2_put_onerror,
1297 HTMLWindow2_get_onerror,
1298 HTMLWindow2_put_onresize,
1299 HTMLWindow2_get_onresize,
1300 HTMLWindow2_put_onscroll,
1301 HTMLWindow2_get_onscroll,
1302 HTMLWindow2_get_document,
1303 HTMLWindow2_get_event,
1304 HTMLWindow2_get__newEnum,
1305 HTMLWindow2_showModalDialog,
1306 HTMLWindow2_showHelp,
1307 HTMLWindow2_get_screen,
1308 HTMLWindow2_get_Option,
1309 HTMLWindow2_focus,
1310 HTMLWindow2_get_closed,
1311 HTMLWindow2_blur,
1312 HTMLWindow2_scroll,
1313 HTMLWindow2_get_clientInformation,
1314 HTMLWindow2_setInterval,
1315 HTMLWindow2_clearInterval,
1316 HTMLWindow2_put_offscreenBuffering,
1317 HTMLWindow2_get_offscreenBuffering,
1318 HTMLWindow2_execScript,
1319 HTMLWindow2_toString,
1320 HTMLWindow2_scrollBy,
1321 HTMLWindow2_scrollTo,
1322 HTMLWindow2_moveTo,
1323 HTMLWindow2_moveBy,
1324 HTMLWindow2_resizeTo,
1325 HTMLWindow2_resizeBy,
1326 HTMLWindow2_get_external
1329 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1331 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1334 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1336 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1338 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1341 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1343 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1345 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1348 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1350 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1352 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1355 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1357 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1359 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1362 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1363 LCID lcid, ITypeInfo **ppTInfo)
1365 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1367 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1370 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1371 LPOLESTR *rgszNames, UINT cNames,
1372 LCID lcid, DISPID *rgDispId)
1374 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1376 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1377 rgDispId);
1380 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1381 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1382 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1384 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1386 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1387 pDispParams, pVarResult, pExcepInfo, puArgErr);
1390 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1392 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1393 FIXME("(%p)->(%p)\n", This, p);
1394 return E_NOTIMPL;
1397 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1399 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1400 FIXME("(%p)->(%p)\n", This, p);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1406 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1408 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1410 if(!This->doc) {
1411 FIXME("No document\n");
1412 return E_FAIL;
1415 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1418 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1420 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1421 FIXME("(%p)->()\n", This);
1422 return E_NOTIMPL;
1425 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1426 BOOL interval, LONG *timer_id)
1428 IDispatch *disp = NULL;
1430 switch(V_VT(expr)) {
1431 case VT_DISPATCH:
1432 disp = V_DISPATCH(expr);
1433 IDispatch_AddRef(disp);
1434 break;
1436 case VT_BSTR:
1437 disp = script_parse_event(This, V_BSTR(expr));
1438 break;
1440 default:
1441 FIXME("unimplemented vt=%d\n", V_VT(expr));
1442 return E_NOTIMPL;
1445 if(!disp)
1446 return E_FAIL;
1448 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1449 IDispatch_Release(disp);
1451 return S_OK;
1454 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1455 VARIANT *language, LONG *timerID)
1457 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1459 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1461 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1464 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1465 VARIANT *language, LONG *timerID)
1467 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1469 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1471 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1474 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1476 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1477 FIXME("(%p)\n", This);
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1483 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1484 FIXME("(%p)->()\n", This);
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1490 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1491 FIXME("(%p)->(%p)\n", This, p);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1497 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1498 FIXME("(%p)->()\n", This);
1499 return E_NOTIMPL;
1502 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1504 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1505 FIXME("(%p)->(%p)\n", This, p);
1506 return E_NOTIMPL;
1509 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1511 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1512 FIXME("(%p)->(%p)\n", This, p);
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1517 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1519 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1520 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1521 return E_NOTIMPL;
1524 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1525 HTMLWindow3_QueryInterface,
1526 HTMLWindow3_AddRef,
1527 HTMLWindow3_Release,
1528 HTMLWindow3_GetTypeInfoCount,
1529 HTMLWindow3_GetTypeInfo,
1530 HTMLWindow3_GetIDsOfNames,
1531 HTMLWindow3_Invoke,
1532 HTMLWindow3_get_screenLeft,
1533 HTMLWindow3_get_screenTop,
1534 HTMLWindow3_attachEvent,
1535 HTMLWindow3_detachEvent,
1536 HTMLWindow3_setTimeout,
1537 HTMLWindow3_setInterval,
1538 HTMLWindow3_print,
1539 HTMLWindow3_put_onbeforeprint,
1540 HTMLWindow3_get_onbeforeprint,
1541 HTMLWindow3_put_onafterprint,
1542 HTMLWindow3_get_onafterprint,
1543 HTMLWindow3_get_clipboardData,
1544 HTMLWindow3_showModelessDialog
1547 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1549 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1552 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1554 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1556 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1559 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1561 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1563 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1566 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1568 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1570 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1573 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1575 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1577 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1580 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1581 LCID lcid, ITypeInfo **ppTInfo)
1583 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1585 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1588 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1589 LPOLESTR *rgszNames, UINT cNames,
1590 LCID lcid, DISPID *rgDispId)
1592 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1594 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1595 rgDispId);
1598 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1599 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1600 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1602 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1604 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1605 pDispParams, pVarResult, pExcepInfo, puArgErr);
1608 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1609 IDispatch **ppPopup)
1611 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1612 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1613 return E_NOTIMPL;
1616 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1618 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1619 TRACE("(%p)->(%p)\n", This, p);
1621 if(This->frame_element) {
1622 *p = &This->frame_element->IHTMLFrameBase_iface;
1623 IHTMLFrameBase_AddRef(*p);
1624 }else
1625 *p = NULL;
1627 return S_OK;
1630 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1631 HTMLWindow4_QueryInterface,
1632 HTMLWindow4_AddRef,
1633 HTMLWindow4_Release,
1634 HTMLWindow4_GetTypeInfoCount,
1635 HTMLWindow4_GetTypeInfo,
1636 HTMLWindow4_GetIDsOfNames,
1637 HTMLWindow4_Invoke,
1638 HTMLWindow4_createPopup,
1639 HTMLWindow4_get_frameElement
1642 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1644 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1647 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1649 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1651 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1654 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1656 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1658 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1661 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1663 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1665 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1668 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1669 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1671 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1672 DWORD post_data_size = 0;
1673 BYTE *post_data = NULL;
1674 WCHAR *headers = NULL;
1675 nsChannelBSC *bsc;
1676 IMoniker *mon;
1677 BSTR new_url;
1678 HRESULT hres;
1680 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1681 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1683 new_url = url;
1684 if(This->doc_obj->hostui) {
1685 OLECHAR *translated_url = NULL;
1687 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1688 if(hres == S_OK && translated_url) {
1689 new_url = SysAllocString(translated_url);
1690 CoTaskMemFree(translated_url);
1694 if(This->doc_obj->client) {
1695 IOleCommandTarget *cmdtrg;
1697 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1698 if(SUCCEEDED(hres)) {
1699 VARIANT in, out;
1701 V_VT(&in) = VT_BSTR;
1702 V_BSTR(&in) = new_url;
1703 V_VT(&out) = VT_BOOL;
1704 V_BOOL(&out) = VARIANT_TRUE;
1705 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1706 IOleCommandTarget_Release(cmdtrg);
1707 if(SUCCEEDED(hres))
1708 VariantClear(&out);
1712 /* FIXME: Why not set_ready_state? */
1713 This->readystate = READYSTATE_UNINITIALIZED;
1715 hres = CreateURLMoniker(NULL, new_url, &mon);
1716 if(new_url != url)
1717 SysFreeString(new_url);
1718 if(FAILED(hres))
1719 return hres;
1721 if(post_data_var) {
1722 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1723 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1724 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1728 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1729 if(V_VT(headers_var) != VT_BSTR)
1730 return E_INVALIDARG;
1732 headers = V_BSTR(headers_var);
1735 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1736 if(post_data)
1737 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1738 if(FAILED(hres)) {
1739 IMoniker_Release(mon);
1740 return hres;
1743 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1744 if(SUCCEEDED(hres))
1745 hres = async_start_doc_binding(This, bsc);
1747 IUnknown_Release((IUnknown*)bsc);
1748 IMoniker_Release(mon);
1749 return hres;
1752 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1754 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1755 FIXME("(%p)->(%p)\n", This, url);
1756 return E_NOTIMPL;
1759 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1761 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1762 FIXME("(%p)->(%p)\n", This, cmdtrg);
1763 return E_NOTIMPL;
1766 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1768 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1769 FIXME("(%p)->(%x)\n", This, arg);
1770 return E_NOTIMPL;
1773 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1775 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1776 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1777 return E_NOTIMPL;
1780 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1782 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1783 TRACE("(%p)->(%p)\n", This, url);
1785 if(!url)
1786 return E_INVALIDARG;
1788 *url = SysAllocString(This->url);
1789 return S_OK;
1792 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1793 HTMLPrivateWindow_QueryInterface,
1794 HTMLPrivateWindow_AddRef,
1795 HTMLPrivateWindow_Release,
1796 HTMLPrivateWindow_SuperNavigate,
1797 HTMLPrivateWindow_GetPendingUrl,
1798 HTMLPrivateWindow_SetPICSTarget,
1799 HTMLPrivateWindow_PICSComplete,
1800 HTMLPrivateWindow_FindWindowByName,
1801 HTMLPrivateWindow_GetAddressBar
1804 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1806 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1809 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1811 HTMLWindow *This = impl_from_IDispatchEx(iface);
1813 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1816 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1818 HTMLWindow *This = impl_from_IDispatchEx(iface);
1820 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1823 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1825 HTMLWindow *This = impl_from_IDispatchEx(iface);
1827 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1830 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1832 HTMLWindow *This = impl_from_IDispatchEx(iface);
1834 TRACE("(%p)->(%p)\n", This, pctinfo);
1836 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1839 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1840 LCID lcid, ITypeInfo **ppTInfo)
1842 HTMLWindow *This = impl_from_IDispatchEx(iface);
1844 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1846 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1849 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1850 LPOLESTR *rgszNames, UINT cNames,
1851 LCID lcid, DISPID *rgDispId)
1853 HTMLWindow *This = impl_from_IDispatchEx(iface);
1854 UINT i;
1855 HRESULT hres;
1857 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1858 lcid, rgDispId);
1860 for(i=0; i < cNames; i++) {
1861 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1862 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
1863 if(FAILED(hres))
1864 return hres;
1867 return S_OK;
1870 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1871 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1872 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1874 HTMLWindow *This = impl_from_IDispatchEx(iface);
1876 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1877 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1879 /* FIXME: Use script dispatch */
1881 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1882 pDispParams, pVarResult, pExcepInfo, puArgErr);
1885 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1887 if(This->global_prop_cnt == This->global_prop_size) {
1888 global_prop_t *new_props;
1889 DWORD new_size;
1891 if(This->global_props) {
1892 new_size = This->global_prop_size*2;
1893 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1894 }else {
1895 new_size = 16;
1896 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1898 if(!new_props)
1899 return NULL;
1900 This->global_props = new_props;
1901 This->global_prop_size = new_size;
1904 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1905 if(!This->global_props[This->global_prop_cnt].name)
1906 return NULL;
1908 This->global_props[This->global_prop_cnt].type = type;
1909 return This->global_props + This->global_prop_cnt++;
1912 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1914 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1917 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1919 DWORD i;
1920 ScriptHost *script_host;
1921 DISPID id;
1923 for(i=0; i < This->global_prop_cnt; i++) {
1924 /* FIXME: case sensitivity */
1925 if(!strcmpW(This->global_props[i].name, bstrName)) {
1926 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1927 return S_OK;
1931 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1932 global_prop_t *prop;
1934 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1935 if(!prop)
1936 return E_OUTOFMEMORY;
1938 prop->script_host = script_host;
1939 prop->id = id;
1941 *pid = prop_to_dispid(This, prop);
1942 return S_OK;
1945 return DISP_E_UNKNOWNNAME;
1948 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1950 HTMLWindow *This = impl_from_IDispatchEx(iface);
1951 HRESULT hres;
1953 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1955 hres = search_window_props(This, bstrName, grfdex, pid);
1956 if(hres != DISP_E_UNKNOWNNAME)
1957 return hres;
1959 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
1960 if(hres != DISP_E_UNKNOWNNAME)
1961 return hres;
1963 if(This->doc) {
1964 global_prop_t *prop;
1965 IHTMLElement *elem;
1967 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
1968 bstrName, &elem);
1969 if(SUCCEEDED(hres) && elem) {
1970 IHTMLElement_Release(elem);
1972 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1973 if(!prop)
1974 return E_OUTOFMEMORY;
1976 *pid = prop_to_dispid(This, prop);
1977 return S_OK;
1981 return DISP_E_UNKNOWNNAME;
1984 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1985 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1987 HTMLWindow *This = impl_from_IDispatchEx(iface);
1989 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1991 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1992 HTMLLocation *location;
1993 HRESULT hres;
1995 TRACE("forwarding to location.href\n");
1997 hres = get_location(This, &location);
1998 if(FAILED(hres))
1999 return hres;
2001 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2002 wFlags, pdp, pvarRes, pei, pspCaller);
2003 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2004 return hres;
2007 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
2008 pei, pspCaller);
2011 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2013 HTMLWindow *This = impl_from_IDispatchEx(iface);
2015 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2017 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2020 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2022 HTMLWindow *This = impl_from_IDispatchEx(iface);
2024 TRACE("(%p)->(%x)\n", This, id);
2026 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2029 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2031 HTMLWindow *This = impl_from_IDispatchEx(iface);
2033 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2035 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2036 pgrfdex);
2039 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2041 HTMLWindow *This = impl_from_IDispatchEx(iface);
2043 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2045 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2048 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2050 HTMLWindow *This = impl_from_IDispatchEx(iface);
2052 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2054 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2057 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2059 HTMLWindow *This = impl_from_IDispatchEx(iface);
2061 TRACE("(%p)->(%p)\n", This, ppunk);
2063 *ppunk = NULL;
2064 return S_OK;
2067 static const IDispatchExVtbl WindowDispExVtbl = {
2068 WindowDispEx_QueryInterface,
2069 WindowDispEx_AddRef,
2070 WindowDispEx_Release,
2071 WindowDispEx_GetTypeInfoCount,
2072 WindowDispEx_GetTypeInfo,
2073 WindowDispEx_GetIDsOfNames,
2074 WindowDispEx_Invoke,
2075 WindowDispEx_GetDispID,
2076 WindowDispEx_InvokeEx,
2077 WindowDispEx_DeleteMemberByName,
2078 WindowDispEx_DeleteMemberByDispID,
2079 WindowDispEx_GetMemberProperties,
2080 WindowDispEx_GetMemberName,
2081 WindowDispEx_GetNextDispID,
2082 WindowDispEx_GetNameSpaceParent
2085 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2087 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2090 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2092 HTMLWindow *This = impl_from_IServiceProvider(iface);
2093 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2096 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2098 HTMLWindow *This = impl_from_IServiceProvider(iface);
2099 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2102 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2104 HTMLWindow *This = impl_from_IServiceProvider(iface);
2105 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2108 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2110 HTMLWindow *This = impl_from_IServiceProvider(iface);
2112 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2113 TRACE("IID_IHTMLWindow2\n");
2114 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2117 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2119 if(!This->doc_obj)
2120 return E_NOINTERFACE;
2122 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2123 guidService, riid, ppv);
2126 static const IServiceProviderVtbl ServiceProviderVtbl = {
2127 HTMLWindowSP_QueryInterface,
2128 HTMLWindowSP_AddRef,
2129 HTMLWindowSP_Release,
2130 HTMLWindowSP_QueryService
2133 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2135 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2138 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2139 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2141 HTMLWindow *This = impl_from_DispatchEx(dispex);
2142 global_prop_t *prop;
2143 DWORD idx;
2144 HRESULT hres;
2146 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2147 if(idx >= This->global_prop_cnt)
2148 return DISP_E_MEMBERNOTFOUND;
2150 prop = This->global_props+idx;
2152 switch(prop->type) {
2153 case GLOBAL_SCRIPTVAR: {
2154 IDispatchEx *iface;
2155 IDispatch *disp;
2157 disp = get_script_disp(prop->script_host);
2158 if(!disp)
2159 return E_UNEXPECTED;
2161 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2162 if(SUCCEEDED(hres)) {
2163 TRACE("%s >>>\n", debugstr_w(prop->name));
2164 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2165 if(hres == S_OK)
2166 TRACE("%s <<<\n", debugstr_w(prop->name));
2167 else
2168 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2169 IDispatchEx_Release(iface);
2170 }else {
2171 FIXME("No IDispatchEx\n");
2173 IDispatch_Release(disp);
2174 break;
2176 case GLOBAL_ELEMENTVAR: {
2177 IHTMLElement *elem;
2179 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2180 prop->name, &elem);
2181 if(FAILED(hres))
2182 return hres;
2184 if(!elem)
2185 return DISP_E_MEMBERNOTFOUND;
2187 V_VT(res) = VT_DISPATCH;
2188 V_DISPATCH(res) = (IDispatch*)elem;
2189 break;
2191 default:
2192 ERR("invalid type %d\n", prop->type);
2193 hres = DISP_E_MEMBERNOTFOUND;
2196 return hres;
2200 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2201 NULL,
2202 NULL,
2203 HTMLWindow_invoke
2206 static const tid_t HTMLWindow_iface_tids[] = {
2207 IHTMLWindow2_tid,
2208 IHTMLWindow3_tid,
2209 IHTMLWindow4_tid,
2213 static dispex_static_data_t HTMLWindow_dispex = {
2214 &HTMLWindow_dispex_vtbl,
2215 DispHTMLWindow2_tid,
2216 NULL,
2217 HTMLWindow_iface_tids
2220 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2222 HTMLWindow *window;
2223 HRESULT hres;
2225 window = heap_alloc_zero(sizeof(HTMLWindow));
2226 if(!window)
2227 return E_OUTOFMEMORY;
2229 window->window_ref = heap_alloc(sizeof(windowref_t));
2230 if(!window->window_ref) {
2231 heap_free(window);
2232 return E_OUTOFMEMORY;
2235 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2236 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2237 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2238 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2239 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2240 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2241 window->ref = 1;
2242 window->doc_obj = doc_obj;
2244 window->window_ref->window = window;
2245 window->window_ref->ref = 1;
2247 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2249 if(nswindow) {
2250 nsIDOMWindow_AddRef(nswindow);
2251 window->nswindow = nswindow;
2254 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2255 window->readystate = READYSTATE_UNINITIALIZED;
2256 list_init(&window->script_hosts);
2258 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
2259 if(FAILED(hres)) {
2260 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
2261 return hres;
2264 window->task_magic = get_task_target_magic();
2265 update_window_doc(window);
2267 list_init(&window->children);
2268 list_add_head(&window_list, &window->entry);
2270 if(parent) {
2271 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2273 window->parent = parent;
2274 list_add_tail(&parent->children, &window->sibling_entry);
2277 *ret = window;
2278 return S_OK;
2281 void update_window_doc(HTMLWindow *window)
2283 nsIDOMHTMLDocument *nshtmldoc;
2284 nsIDOMDocument *nsdoc;
2285 nsresult nsres;
2287 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2288 if(NS_FAILED(nsres) || !nsdoc) {
2289 ERR("GetDocument failed: %08x\n", nsres);
2290 return;
2293 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2294 nsIDOMDocument_Release(nsdoc);
2295 if(NS_FAILED(nsres)) {
2296 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2297 return;
2300 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2301 HTMLDocumentNode *doc;
2302 HRESULT hres;
2304 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2305 if(SUCCEEDED(hres)) {
2306 window_set_docnode(window, doc);
2307 htmldoc_release(&doc->basedoc);
2308 }else {
2309 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2313 nsIDOMHTMLDocument_Release(nshtmldoc);
2316 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2318 HTMLWindow *iter;
2320 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2321 if(iter->nswindow == nswindow)
2322 return iter;
2325 return NULL;