wineps: Fix a couple of typos in the path painting function.
[wine/testsucceed.git] / dlls / mshtml / htmlwindow.c
blobea02cb1ac20c1d53748fd123f144e5463b0b9c6f
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 #define NO_SHLWAPI_REG
31 #include "shlwapi.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
36 #include "htmlevent.h"
37 #include "binding.h"
38 #include "resource.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static struct list window_list = LIST_INIT(window_list);
44 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
46 if(window->doc) {
47 if(window->doc_obj && window == window->doc_obj->basedoc.window)
48 window->doc->basedoc.cp_container.forward_container = NULL;
49 abort_document_bindings(window->doc);
50 window->doc->basedoc.window = NULL;
51 htmldoc_release(&window->doc->basedoc);
53 window->doc = doc_node;
54 if(doc_node)
55 htmldoc_addref(&doc_node->basedoc);
57 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
58 if(window->doc_obj->basedoc.doc_node)
59 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
60 window->doc_obj->basedoc.doc_node = doc_node;
61 if(doc_node)
62 htmldoc_addref(&doc_node->basedoc);
65 if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
66 nsIDOMNSHTMLDocument *nshtmldoc;
67 nsAString mode_str;
68 nsresult nsres;
70 static const PRUnichar onW[] = {'o','n',0};
72 nsres = nsIDOMHTMLDocument_QueryInterface(doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
73 if(NS_SUCCEEDED(nsres)) {
74 nsAString_Init(&mode_str, onW);
75 nsres = nsIDOMNSHTMLDocument_SetDesignMode(nshtmldoc, &mode_str);
76 nsAString_Finish(&mode_str);
77 nsIDOMNSHTMLDocument_Release(nshtmldoc);
78 if(NS_FAILED(nsres))
79 ERR("SetDesignMode failed: %08x\n", nsres);
80 }else {
81 ERR("Could not get nsIDOMNSHTMLDocument interface: %08x\n", nsres);
86 static void release_children(HTMLWindow *This)
88 HTMLWindow *child;
90 while(!list_empty(&This->children)) {
91 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
93 list_remove(&child->sibling_entry);
94 child->parent = NULL;
95 IHTMLWindow2_Release(&child->IHTMLWindow2_iface);
99 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
101 if(This->location) {
102 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
103 }else {
104 HRESULT hres;
106 hres = HTMLLocation_Create(This, &This->location);
107 if(FAILED(hres))
108 return hres;
111 *ret = This->location;
112 return S_OK;
115 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
117 if(!window->doc) {
118 FIXME("No document\n");
119 return E_FAIL;
122 return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
125 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
127 if(!window->doc) {
128 FIXME("No document\n");
129 return E_FAIL;
132 return get_event_handler(&window->doc->body_event_target, eid, var);
135 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
137 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
140 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
142 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
144 *ppv = NULL;
146 if(IsEqualGUID(&IID_IUnknown, riid)) {
147 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
148 *ppv = &This->IHTMLWindow2_iface;
149 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
150 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
151 *ppv = &This->IHTMLWindow2_iface;
152 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
153 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
154 *ppv = &This->IDispatchEx_iface;
155 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
156 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
157 *ppv = &This->IHTMLWindow2_iface;
158 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
159 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
160 *ppv = &This->IHTMLWindow2_iface;
161 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
162 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
163 *ppv = &This->IHTMLWindow3_iface;
164 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
165 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
166 *ppv = &This->IHTMLWindow4_iface;
167 }else if(IsEqualGUID(&IID_IHTMLWindow6, riid)) {
168 TRACE("(%p)->(IID_IHTMLWindow6 %p)\n", This, ppv);
169 *ppv = &This->IHTMLWindow6_iface;
170 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
171 TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
172 *ppv = &This->IHTMLPrivateWindow_iface;
173 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
174 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
175 *ppv = &This->IServiceProvider_iface;
176 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
177 return *ppv ? S_OK : E_NOINTERFACE;
180 if(*ppv) {
181 IUnknown_AddRef((IUnknown*)*ppv);
182 return S_OK;
185 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
186 return E_NOINTERFACE;
189 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
191 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
192 LONG ref = InterlockedIncrement(&This->ref);
194 TRACE("(%p) ref=%d\n", This, ref);
196 return ref;
199 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
201 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
202 LONG ref = InterlockedDecrement(&This->ref);
204 TRACE("(%p) ref=%d\n", This, ref);
206 if(!ref) {
207 DWORD i;
209 remove_target_tasks(This->task_magic);
210 set_window_bscallback(This, NULL);
211 set_current_mon(This, NULL);
212 window_set_docnode(This, NULL);
213 release_children(This);
215 if(This->secmgr)
216 IInternetSecurityManager_Release(This->secmgr);
218 if(This->frame_element)
219 This->frame_element->content_window = NULL;
221 if(This->option_factory) {
222 This->option_factory->window = NULL;
223 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
226 if(This->image_factory) {
227 This->image_factory->window = NULL;
228 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
231 if(This->location) {
232 This->location->window = NULL;
233 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
236 if(This->screen)
237 IHTMLScreen_Release(This->screen);
239 for(i=0; i < This->global_prop_cnt; i++)
240 heap_free(This->global_props[i].name);
242 This->window_ref->window = NULL;
243 windowref_release(This->window_ref);
245 heap_free(This->global_props);
246 release_script_hosts(This);
248 if(This->nswindow)
249 nsIDOMWindow_Release(This->nswindow);
251 list_remove(&This->entry);
252 release_dispex(&This->dispex);
253 heap_free(This);
256 return ref;
259 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
261 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
263 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
266 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
267 LCID lcid, ITypeInfo **ppTInfo)
269 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
271 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
274 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
275 LPOLESTR *rgszNames, UINT cNames,
276 LCID lcid, DISPID *rgDispId)
278 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
280 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
281 rgDispId);
284 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
285 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
286 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
288 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
290 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
291 pDispParams, pVarResult, pExcepInfo, puArgErr);
294 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
296 PRUint32 length;
297 nsIDOMWindow *nsWindow;
298 nsresult nsres;
300 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
301 if(NS_FAILED(nsres)) {
302 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
303 return E_FAIL;
306 if(index >= length)
307 return DISP_E_MEMBERNOTFOUND;
309 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
310 if(NS_FAILED(nsres)) {
311 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
312 return E_FAIL;
315 *ret = nswindow_to_window(nsWindow);
317 nsIDOMWindow_Release(nsWindow);
319 return S_OK;
322 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
324 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
325 nsIDOMWindowCollection *nsFrames;
326 HTMLWindow *window;
327 HRESULT hres;
328 nsresult nsres;
330 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
332 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
333 if(NS_FAILED(nsres)) {
334 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
335 return E_FAIL;
338 if(V_VT(pvarIndex) == VT_I4) {
339 int index = V_I4(pvarIndex);
340 TRACE("Getting index %d\n", index);
341 if(index < 0) {
342 hres = DISP_E_MEMBERNOTFOUND;
343 goto cleanup;
345 hres = get_frame_by_index(nsFrames, index, &window);
346 if(FAILED(hres))
347 goto cleanup;
348 }else if(V_VT(pvarIndex) == VT_UINT) {
349 unsigned int index = V_UINT(pvarIndex);
350 TRACE("Getting index %u\n", index);
351 hres = get_frame_by_index(nsFrames, index, &window);
352 if(FAILED(hres))
353 goto cleanup;
354 }else if(V_VT(pvarIndex) == VT_BSTR) {
355 BSTR str = V_BSTR(pvarIndex);
356 PRUint32 length, i;
358 TRACE("Getting name %s\n", wine_dbgstr_w(str));
360 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
362 window = NULL;
363 for(i = 0; i < length && !window; ++i) {
364 HTMLWindow *cur_window;
365 nsIDOMWindow *nsWindow;
366 BSTR id;
368 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
369 if(NS_FAILED(nsres)) {
370 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
371 hres = E_FAIL;
372 goto cleanup;
375 cur_window = nswindow_to_window(nsWindow);
377 nsIDOMWindow_Release(nsWindow);
379 hres = IHTMLElement_get_id(&cur_window->frame_element->element.IHTMLElement_iface, &id);
380 if(FAILED(hres)) {
381 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
382 goto cleanup;
385 if(!strcmpW(id, str))
386 window = cur_window;
388 SysFreeString(id);
391 if(!window) {
392 hres = DISP_E_MEMBERNOTFOUND;
393 goto cleanup;
395 }else {
396 hres = E_INVALIDARG;
397 goto cleanup;
400 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
401 V_VT(pvarResult) = VT_DISPATCH;
402 V_DISPATCH(pvarResult) = (IDispatch*)window;
404 hres = S_OK;
406 cleanup:
407 nsIDOMWindowCollection_Release(nsFrames);
409 return hres;
412 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
414 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
415 nsIDOMWindowCollection *nscollection;
416 PRUint32 length;
417 nsresult nsres;
419 TRACE("(%p)->(%p)\n", This, p);
421 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
422 if(NS_FAILED(nsres)) {
423 ERR("GetFrames failed: %08x\n", nsres);
424 return E_FAIL;
427 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
428 nsIDOMWindowCollection_Release(nscollection);
429 if(NS_FAILED(nsres)) {
430 ERR("GetLength failed: %08x\n", nsres);
431 return E_FAIL;
434 *p = length;
435 return S_OK;
438 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
440 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
441 FIXME("(%p)->(%p): semi-stub\n", This, p);
443 /* FIXME: Should return a separate Window object */
444 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
445 HTMLWindow2_AddRef(iface);
446 return S_OK;
449 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
451 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
452 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
453 return E_NOTIMPL;
456 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
458 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
459 FIXME("(%p)->(%p)\n", This, p);
460 return E_NOTIMPL;
463 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
465 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
467 WARN("(%p)->(%s)\n", This, debugstr_w(v));
470 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
471 * Ignoring the call should be enough for us.
473 return S_OK;
476 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
478 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
480 TRACE("(%p)->(%p)\n", This, p);
482 /* See put_status */
483 *p = NULL;
484 return S_OK;
487 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
488 LONG msec, VARIANT *language, LONG *timerID)
490 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
491 VARIANT expr_var;
493 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
495 V_VT(&expr_var) = VT_BSTR;
496 V_BSTR(&expr_var) = expression;
498 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
501 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
503 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
505 TRACE("(%p)->(%d)\n", This, timerID);
507 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
510 #define MAX_MESSAGE_LEN 2000
512 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
514 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
515 WCHAR title[100], *msg = message;
516 DWORD len;
518 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
520 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
521 sizeof(title)/sizeof(WCHAR))) {
522 WARN("Could not load message box title: %d\n", GetLastError());
523 return S_OK;
526 len = SysStringLen(message);
527 if(len > MAX_MESSAGE_LEN) {
528 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
529 if(!msg)
530 return E_OUTOFMEMORY;
531 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
532 msg[MAX_MESSAGE_LEN] = 0;
535 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
536 if(msg != message)
537 heap_free(msg);
538 return S_OK;
541 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
542 VARIANT_BOOL *confirmed)
544 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
545 WCHAR wszTitle[100];
547 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
549 if(!confirmed) return E_INVALIDARG;
551 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
552 sizeof(wszTitle)/sizeof(WCHAR))) {
553 WARN("Could not load message box title: %d\n", GetLastError());
554 *confirmed = VARIANT_TRUE;
555 return S_OK;
558 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
559 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
560 *confirmed = VARIANT_TRUE;
561 else *confirmed = VARIANT_FALSE;
563 return S_OK;
566 typedef struct
568 BSTR message;
569 BSTR dststr;
570 VARIANT *textdata;
571 }prompt_arg;
573 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
574 WPARAM wparam, LPARAM lparam)
576 switch(msg)
578 case WM_INITDIALOG:
580 prompt_arg *arg = (prompt_arg*)lparam;
581 WCHAR wszTitle[100];
583 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
584 sizeof(wszTitle)/sizeof(WCHAR))) {
585 WARN("Could not load message box title: %d\n", GetLastError());
586 EndDialog(hwnd, wparam);
587 return FALSE;
590 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
591 SetWindowTextW(hwnd, wszTitle);
592 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
593 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
594 return FALSE;
596 case WM_COMMAND:
597 switch(wparam)
599 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
600 EndDialog(hwnd, wparam);
601 return TRUE;
602 case MAKEWPARAM(IDOK, BN_CLICKED):
604 prompt_arg *arg =
605 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
606 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
607 INT len = GetWindowTextLengthW(hwndPrompt);
609 if(!arg->textdata)
611 EndDialog(hwnd, wparam);
612 return TRUE;
615 V_VT(arg->textdata) = VT_BSTR;
616 if(!len && !arg->dststr)
617 V_BSTR(arg->textdata) = NULL;
618 else
620 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
621 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
623 EndDialog(hwnd, wparam);
624 return TRUE;
627 return FALSE;
628 case WM_CLOSE:
629 EndDialog(hwnd, IDCANCEL);
630 return TRUE;
631 default:
632 return FALSE;
636 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
637 BSTR dststr, VARIANT *textdata)
639 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
640 prompt_arg arg;
642 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
644 if(textdata) V_VT(textdata) = VT_NULL;
646 arg.message = message;
647 arg.dststr = dststr;
648 arg.textdata = textdata;
650 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
651 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
652 return S_OK;
655 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
657 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
659 TRACE("(%p)->(%p)\n", This, p);
661 if(!This->image_factory)
662 This->image_factory = HTMLImageElementFactory_Create(This);
664 *p = &This->image_factory->IHTMLImageElementFactory_iface;
665 IHTMLImageElementFactory_AddRef(*p);
667 return S_OK;
670 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
672 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
673 HTMLLocation *location;
674 HRESULT hres;
676 TRACE("(%p)->(%p)\n", This, p);
678 hres = get_location(This, &location);
679 if(FAILED(hres))
680 return hres;
682 *p = &location->IHTMLLocation_iface;
683 return S_OK;
686 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
688 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
689 FIXME("(%p)->(%p)\n", This, p);
690 return E_NOTIMPL;
693 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
695 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
696 FIXME("(%p)->()\n", This);
697 return E_NOTIMPL;
700 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
702 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
703 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
704 return E_NOTIMPL;
707 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
709 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
710 FIXME("(%p)->(%p)\n", This, p);
711 return E_NOTIMPL;
714 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
716 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
718 TRACE("(%p)->(%p)\n", This, p);
720 *p = OmNavigator_Create();
721 return S_OK;
724 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
726 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
727 nsAString name_str;
728 nsresult nsres;
730 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
732 nsAString_InitDepend(&name_str, v);
733 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
734 nsAString_Finish(&name_str);
735 if(NS_FAILED(nsres))
736 ERR("SetName failed: %08x\n", nsres);
738 return S_OK;
741 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
743 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
744 nsAString name_str;
745 nsresult nsres;
746 HRESULT hres;
748 TRACE("(%p)->(%p)\n", This, p);
750 nsAString_Init(&name_str, NULL);
751 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
752 if(NS_SUCCEEDED(nsres)) {
753 const PRUnichar *name;
755 nsAString_GetData(&name_str, &name);
756 if(*name) {
757 *p = SysAllocString(name);
758 hres = *p ? S_OK : E_OUTOFMEMORY;
759 }else {
760 *p = NULL;
761 hres = S_OK;
763 }else {
764 ERR("GetName failed: %08x\n", nsres);
765 hres = E_FAIL;
767 nsAString_Finish(&name_str);
769 return hres;
772 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
774 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
775 TRACE("(%p)->(%p)\n", This, p);
777 if(This->parent) {
778 *p = &This->parent->IHTMLWindow2_iface;
779 IHTMLWindow2_AddRef(*p);
780 }else
781 *p = NULL;
783 return S_OK;
786 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
787 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
789 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
790 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
791 debugstr_w(features), replace, pomWindowResult);
792 return E_NOTIMPL;
795 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
797 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
799 TRACE("(%p)->(%p)\n", This, p);
801 /* FIXME: We should return kind of proxy window here. */
802 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
803 *p = &This->IHTMLWindow2_iface;
804 return S_OK;
807 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
809 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
810 HTMLWindow *curr;
811 TRACE("(%p)->(%p)\n", This, p);
813 curr = This;
814 while(curr->parent)
815 curr = curr->parent;
816 *p = &curr->IHTMLWindow2_iface;
817 IHTMLWindow2_AddRef(*p);
819 return S_OK;
822 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
824 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
826 TRACE("(%p)->(%p)\n", This, p);
828 /* FIXME: We should return kind of proxy window here. */
829 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
830 *p = &This->IHTMLWindow2_iface;
831 return S_OK;
834 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
836 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
837 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
838 return E_NOTIMPL;
841 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
843 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
844 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
845 return E_NOTIMPL;
848 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
850 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
851 FIXME("(%p)->(%p)\n", This, p);
852 return E_NOTIMPL;
855 static HRESULT WINAPI HTMLWindow2_put_onblur(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_onblur(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_onload(IHTMLWindow2 *iface, VARIANT v)
871 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
873 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
875 return set_window_event(This, EVENTID_LOAD, &v);
878 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
880 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
882 TRACE("(%p)->(%p)\n", This, p);
884 return get_window_event(This, EVENTID_LOAD, p);
887 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
889 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
891 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
893 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
896 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
898 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
900 TRACE("(%p)->(%p)\n", This, p);
902 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
905 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
907 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
908 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
909 return E_NOTIMPL;
912 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
914 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
915 FIXME("(%p)->(%p)\n", This, p);
916 return E_NOTIMPL;
919 static HRESULT WINAPI HTMLWindow2_put_onhelp(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_onhelp(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_onerror(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_onerror(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_onresize(IHTMLWindow2 *iface, VARIANT v)
949 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
951 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
953 return set_window_event(This, EVENTID_RESIZE, &v);
956 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
958 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
960 TRACE("(%p)->(%p)\n", This, p);
962 return get_window_event(This, EVENTID_RESIZE, p);
965 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
967 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
968 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
969 return E_NOTIMPL;
972 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
974 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
975 FIXME("(%p)->(%p)\n", This, p);
976 return E_NOTIMPL;
979 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
981 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
983 TRACE("(%p)->(%p)\n", This, p);
985 if(This->doc) {
986 /* FIXME: We should return a wrapper object here */
987 *p = &This->doc->basedoc.IHTMLDocument2_iface;
988 IHTMLDocument2_AddRef(*p);
989 }else {
990 *p = NULL;
993 return S_OK;
996 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
998 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1000 TRACE("(%p)->(%p)\n", This, p);
1002 if(This->event)
1003 IHTMLEventObj_AddRef(This->event);
1004 *p = This->event;
1005 return S_OK;
1008 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1010 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1011 FIXME("(%p)->(%p)\n", This, p);
1012 return E_NOTIMPL;
1015 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1016 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1018 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1019 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1024 BSTR features)
1026 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1027 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1028 return E_NOTIMPL;
1031 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1033 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1035 TRACE("(%p)->(%p)\n", This, p);
1037 if(!This->screen) {
1038 HRESULT hres;
1040 hres = HTMLScreen_Create(&This->screen);
1041 if(FAILED(hres))
1042 return hres;
1045 *p = This->screen;
1046 IHTMLScreen_AddRef(This->screen);
1047 return S_OK;
1050 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1052 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1054 TRACE("(%p)->(%p)\n", This, p);
1056 if(!This->option_factory)
1057 This->option_factory = HTMLOptionElementFactory_Create(This);
1059 *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1060 IHTMLOptionElementFactory_AddRef(*p);
1062 return S_OK;
1065 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1067 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1069 TRACE("(%p)->()\n", This);
1071 if(This->doc_obj)
1072 SetFocus(This->doc_obj->hwnd);
1073 return S_OK;
1076 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1078 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1079 FIXME("(%p)->(%p)\n", This, p);
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1085 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1086 FIXME("(%p)->()\n", This);
1087 return E_NOTIMPL;
1090 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1092 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1093 FIXME("(%p)->(%d %d)\n", This, x, y);
1094 return E_NOTIMPL;
1097 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1099 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1100 FIXME("(%p)->(%p)\n", This, p);
1101 return E_NOTIMPL;
1104 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1105 LONG msec, VARIANT *language, LONG *timerID)
1107 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1108 VARIANT expr;
1110 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1112 V_VT(&expr) = VT_BSTR;
1113 V_BSTR(&expr) = expression;
1114 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1117 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1119 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1121 TRACE("(%p)->(%d)\n", This, timerID);
1123 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1126 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1128 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1129 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1130 return E_NOTIMPL;
1133 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1135 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1136 FIXME("(%p)->(%p)\n", This, p);
1137 return E_NOTIMPL;
1140 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1141 VARIANT *pvarRet)
1143 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1145 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1147 return exec_script(This, scode, language, pvarRet);
1150 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1152 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1154 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1156 TRACE("(%p)->(%p)\n", This, String);
1158 if(!String)
1159 return E_INVALIDARG;
1161 *String = SysAllocString(objectW);
1162 return *String ? S_OK : E_OUTOFMEMORY;
1165 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1167 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1168 nsresult nsres;
1170 TRACE("(%p)->(%d %d)\n", This, x, y);
1172 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1173 if(NS_FAILED(nsres))
1174 ERR("ScrollBy failed: %08x\n", nsres);
1176 return S_OK;
1179 static HRESULT WINAPI HTMLWindow2_scrollTo(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_ScrollTo(This->nswindow, x, y);
1187 if(NS_FAILED(nsres))
1188 ERR("ScrollTo failed: %08x\n", nsres);
1190 return S_OK;
1193 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1195 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1196 FIXME("(%p)->(%d %d)\n", This, x, y);
1197 return E_NOTIMPL;
1200 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1202 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1203 FIXME("(%p)->(%d %d)\n", This, x, y);
1204 return E_NOTIMPL;
1207 static HRESULT WINAPI HTMLWindow2_resizeTo(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_resizeBy(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_get_external(IHTMLWindow2 *iface, IDispatch **p)
1223 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1225 TRACE("(%p)->(%p)\n", This, p);
1227 *p = NULL;
1229 if(!This->doc_obj->hostui)
1230 return S_OK;
1232 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1235 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1236 HTMLWindow2_QueryInterface,
1237 HTMLWindow2_AddRef,
1238 HTMLWindow2_Release,
1239 HTMLWindow2_GetTypeInfoCount,
1240 HTMLWindow2_GetTypeInfo,
1241 HTMLWindow2_GetIDsOfNames,
1242 HTMLWindow2_Invoke,
1243 HTMLWindow2_item,
1244 HTMLWindow2_get_length,
1245 HTMLWindow2_get_frames,
1246 HTMLWindow2_put_defaultStatus,
1247 HTMLWindow2_get_defaultStatus,
1248 HTMLWindow2_put_status,
1249 HTMLWindow2_get_status,
1250 HTMLWindow2_setTimeout,
1251 HTMLWindow2_clearTimeout,
1252 HTMLWindow2_alert,
1253 HTMLWindow2_confirm,
1254 HTMLWindow2_prompt,
1255 HTMLWindow2_get_Image,
1256 HTMLWindow2_get_location,
1257 HTMLWindow2_get_history,
1258 HTMLWindow2_close,
1259 HTMLWindow2_put_opener,
1260 HTMLWindow2_get_opener,
1261 HTMLWindow2_get_navigator,
1262 HTMLWindow2_put_name,
1263 HTMLWindow2_get_name,
1264 HTMLWindow2_get_parent,
1265 HTMLWindow2_open,
1266 HTMLWindow2_get_self,
1267 HTMLWindow2_get_top,
1268 HTMLWindow2_get_window,
1269 HTMLWindow2_navigate,
1270 HTMLWindow2_put_onfocus,
1271 HTMLWindow2_get_onfocus,
1272 HTMLWindow2_put_onblur,
1273 HTMLWindow2_get_onblur,
1274 HTMLWindow2_put_onload,
1275 HTMLWindow2_get_onload,
1276 HTMLWindow2_put_onbeforeunload,
1277 HTMLWindow2_get_onbeforeunload,
1278 HTMLWindow2_put_onunload,
1279 HTMLWindow2_get_onunload,
1280 HTMLWindow2_put_onhelp,
1281 HTMLWindow2_get_onhelp,
1282 HTMLWindow2_put_onerror,
1283 HTMLWindow2_get_onerror,
1284 HTMLWindow2_put_onresize,
1285 HTMLWindow2_get_onresize,
1286 HTMLWindow2_put_onscroll,
1287 HTMLWindow2_get_onscroll,
1288 HTMLWindow2_get_document,
1289 HTMLWindow2_get_event,
1290 HTMLWindow2_get__newEnum,
1291 HTMLWindow2_showModalDialog,
1292 HTMLWindow2_showHelp,
1293 HTMLWindow2_get_screen,
1294 HTMLWindow2_get_Option,
1295 HTMLWindow2_focus,
1296 HTMLWindow2_get_closed,
1297 HTMLWindow2_blur,
1298 HTMLWindow2_scroll,
1299 HTMLWindow2_get_clientInformation,
1300 HTMLWindow2_setInterval,
1301 HTMLWindow2_clearInterval,
1302 HTMLWindow2_put_offscreenBuffering,
1303 HTMLWindow2_get_offscreenBuffering,
1304 HTMLWindow2_execScript,
1305 HTMLWindow2_toString,
1306 HTMLWindow2_scrollBy,
1307 HTMLWindow2_scrollTo,
1308 HTMLWindow2_moveTo,
1309 HTMLWindow2_moveBy,
1310 HTMLWindow2_resizeTo,
1311 HTMLWindow2_resizeBy,
1312 HTMLWindow2_get_external
1315 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1317 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1320 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1322 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1324 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1327 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1329 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1331 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1334 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1336 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1338 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1341 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1343 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1345 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1348 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1349 LCID lcid, ITypeInfo **ppTInfo)
1351 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1353 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1356 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1357 LPOLESTR *rgszNames, UINT cNames,
1358 LCID lcid, DISPID *rgDispId)
1360 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1362 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1363 rgDispId);
1366 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1367 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1368 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1370 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1372 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1373 pDispParams, pVarResult, pExcepInfo, puArgErr);
1376 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1378 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1379 FIXME("(%p)->(%p)\n", This, p);
1380 return E_NOTIMPL;
1383 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1385 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1386 FIXME("(%p)->(%p)\n", This, p);
1387 return E_NOTIMPL;
1390 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1392 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1394 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1396 if(!This->doc) {
1397 FIXME("No document\n");
1398 return E_FAIL;
1401 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1404 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1406 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1407 FIXME("(%p)->()\n", This);
1408 return E_NOTIMPL;
1411 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1412 BOOL interval, LONG *timer_id)
1414 IDispatch *disp = NULL;
1416 switch(V_VT(expr)) {
1417 case VT_DISPATCH:
1418 disp = V_DISPATCH(expr);
1419 IDispatch_AddRef(disp);
1420 break;
1422 case VT_BSTR:
1423 disp = script_parse_event(This, V_BSTR(expr));
1424 break;
1426 default:
1427 FIXME("unimplemented vt=%d\n", V_VT(expr));
1428 return E_NOTIMPL;
1431 if(!disp)
1432 return E_FAIL;
1434 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1435 IDispatch_Release(disp);
1437 return S_OK;
1440 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1441 VARIANT *language, LONG *timerID)
1443 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1445 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1447 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1450 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1451 VARIANT *language, LONG *timerID)
1453 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1455 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1457 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1460 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1462 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1463 FIXME("(%p)\n", This);
1464 return E_NOTIMPL;
1467 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1469 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1470 FIXME("(%p)->()\n", This);
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1476 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1477 FIXME("(%p)->(%p)\n", This, p);
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI HTMLWindow3_put_onafterprint(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_onafterprint(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_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1497 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1498 FIXME("(%p)->(%p)\n", This, p);
1499 return E_NOTIMPL;
1502 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1503 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1505 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1506 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1507 return E_NOTIMPL;
1510 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1511 HTMLWindow3_QueryInterface,
1512 HTMLWindow3_AddRef,
1513 HTMLWindow3_Release,
1514 HTMLWindow3_GetTypeInfoCount,
1515 HTMLWindow3_GetTypeInfo,
1516 HTMLWindow3_GetIDsOfNames,
1517 HTMLWindow3_Invoke,
1518 HTMLWindow3_get_screenLeft,
1519 HTMLWindow3_get_screenTop,
1520 HTMLWindow3_attachEvent,
1521 HTMLWindow3_detachEvent,
1522 HTMLWindow3_setTimeout,
1523 HTMLWindow3_setInterval,
1524 HTMLWindow3_print,
1525 HTMLWindow3_put_onbeforeprint,
1526 HTMLWindow3_get_onbeforeprint,
1527 HTMLWindow3_put_onafterprint,
1528 HTMLWindow3_get_onafterprint,
1529 HTMLWindow3_get_clipboardData,
1530 HTMLWindow3_showModelessDialog
1533 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1535 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1538 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1540 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1542 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1545 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1547 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1549 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1552 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1554 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1556 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1559 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1561 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1563 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1566 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1567 LCID lcid, ITypeInfo **ppTInfo)
1569 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1571 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1574 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1575 LPOLESTR *rgszNames, UINT cNames,
1576 LCID lcid, DISPID *rgDispId)
1578 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1580 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1581 rgDispId);
1584 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1585 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1586 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1588 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1590 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1591 pDispParams, pVarResult, pExcepInfo, puArgErr);
1594 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1595 IDispatch **ppPopup)
1597 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1598 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1599 return E_NOTIMPL;
1602 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1604 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1605 TRACE("(%p)->(%p)\n", This, p);
1607 if(This->frame_element) {
1608 *p = &This->frame_element->IHTMLFrameBase_iface;
1609 IHTMLFrameBase_AddRef(*p);
1610 }else
1611 *p = NULL;
1613 return S_OK;
1616 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1617 HTMLWindow4_QueryInterface,
1618 HTMLWindow4_AddRef,
1619 HTMLWindow4_Release,
1620 HTMLWindow4_GetTypeInfoCount,
1621 HTMLWindow4_GetTypeInfo,
1622 HTMLWindow4_GetIDsOfNames,
1623 HTMLWindow4_Invoke,
1624 HTMLWindow4_createPopup,
1625 HTMLWindow4_get_frameElement
1628 static inline HTMLWindow *impl_from_IHTMLWindow6(IHTMLWindow6 *iface)
1630 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow6_iface);
1633 static HRESULT WINAPI HTMLWindow6_QueryInterface(IHTMLWindow6 *iface, REFIID riid, void **ppv)
1635 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1637 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1640 static ULONG WINAPI HTMLWindow6_AddRef(IHTMLWindow6 *iface)
1642 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1644 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1647 static ULONG WINAPI HTMLWindow6_Release(IHTMLWindow6 *iface)
1649 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1651 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1654 static HRESULT WINAPI HTMLWindow6_GetTypeInfoCount(IHTMLWindow6 *iface, UINT *pctinfo)
1656 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1658 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1661 static HRESULT WINAPI HTMLWindow6_GetTypeInfo(IHTMLWindow6 *iface, UINT iTInfo,
1662 LCID lcid, ITypeInfo **ppTInfo)
1664 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1666 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1669 static HRESULT WINAPI HTMLWindow6_GetIDsOfNames(IHTMLWindow6 *iface, REFIID riid,
1670 LPOLESTR *rgszNames, UINT cNames,
1671 LCID lcid, DISPID *rgDispId)
1673 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1675 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1676 rgDispId);
1679 static HRESULT WINAPI HTMLWindow6_Invoke(IHTMLWindow6 *iface, DISPID dispIdMember,
1680 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1681 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1683 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1685 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1686 pDispParams, pVarResult, pExcepInfo, puArgErr);
1689 static HRESULT WINAPI HTMLWindow6_put_XDomainRequest(IHTMLWindow6 *iface, VARIANT v)
1691 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1692 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1693 return E_NOTIMPL;
1696 static HRESULT WINAPI HTMLWindow6_get_XDomainRequest(IHTMLWindow6 *iface, VARIANT *p)
1698 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1699 FIXME("(%p)->(%p)\n", This, p);
1700 return E_NOTIMPL;
1703 static HRESULT WINAPI HTMLWindow6_get_sessionStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
1705 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1706 FIXME("(%p)->(%p)\n", This, p);
1707 return E_NOTIMPL;
1710 static HRESULT WINAPI HTMLWindow6_get_localStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
1712 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1713 FIXME("(%p)->(%p)\n", This, p);
1714 return E_NOTIMPL;
1717 static HRESULT WINAPI HTMLWindow6_put_onhashchange(IHTMLWindow6 *iface, VARIANT v)
1719 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1720 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1721 return E_NOTIMPL;
1724 static HRESULT WINAPI HTMLWindow6_get_onhashchange(IHTMLWindow6 *iface, VARIANT *p)
1726 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1727 FIXME("(%p)->(%p)\n", This, p);
1728 return E_NOTIMPL;
1731 static HRESULT WINAPI HTMLWindow6_get_maxConnectionsPerServer(IHTMLWindow6 *iface, LONG *p)
1733 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1734 FIXME("(%p)->(%p)\n", This, p);
1735 return E_NOTIMPL;
1738 static HRESULT WINAPI HTMLWindow6_postMessage(IHTMLWindow6 *iface, BSTR msg, VARIANT targetOrigin)
1740 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1741 FIXME("(%p)->(%s %s)\n", This, debugstr_w(msg), debugstr_variant(&targetOrigin));
1742 return E_NOTIMPL;
1745 static HRESULT WINAPI HTMLWindow6_toStaticHTML(IHTMLWindow6 *iface, BSTR bstrHTML, BSTR *pbstrStaticHTML)
1747 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1748 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrHTML), pbstrStaticHTML);
1749 return E_NOTIMPL;
1752 static HRESULT WINAPI HTMLWindow6_put_onmessage(IHTMLWindow6 *iface, VARIANT v)
1754 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1755 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1756 return E_NOTIMPL;
1759 static HRESULT WINAPI HTMLWindow6_get_onmessage(IHTMLWindow6 *iface, VARIANT *p)
1761 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1762 FIXME("(%p)->(%p)\n", This, p);
1763 return E_NOTIMPL;
1766 static HRESULT WINAPI HTMLWindow6_msWriteProfilerMark(IHTMLWindow6 *iface, BSTR bstrProfilerMark)
1768 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1769 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrProfilerMark));
1770 return E_NOTIMPL;
1773 static const IHTMLWindow6Vtbl HTMLWindow6Vtbl = {
1774 HTMLWindow6_QueryInterface,
1775 HTMLWindow6_AddRef,
1776 HTMLWindow6_Release,
1777 HTMLWindow6_GetTypeInfoCount,
1778 HTMLWindow6_GetTypeInfo,
1779 HTMLWindow6_GetIDsOfNames,
1780 HTMLWindow6_Invoke,
1781 HTMLWindow6_put_XDomainRequest,
1782 HTMLWindow6_get_XDomainRequest,
1783 HTMLWindow6_get_sessionStorage,
1784 HTMLWindow6_get_localStorage,
1785 HTMLWindow6_put_onhashchange,
1786 HTMLWindow6_get_onhashchange,
1787 HTMLWindow6_get_maxConnectionsPerServer,
1788 HTMLWindow6_postMessage,
1789 HTMLWindow6_toStaticHTML,
1790 HTMLWindow6_put_onmessage,
1791 HTMLWindow6_get_onmessage,
1792 HTMLWindow6_msWriteProfilerMark
1795 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1797 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1800 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1802 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1804 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1807 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1809 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1811 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1814 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1816 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1818 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1821 typedef struct {
1822 task_t header;
1823 HTMLWindow *window;
1824 IUri *uri;
1825 } navigate_javascript_task_t;
1827 static void navigate_javascript_proc(task_t *_task)
1829 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1830 HTMLWindow *window = task->window;
1831 VARIANT v;
1832 BSTR code;
1833 HRESULT hres;
1835 static const WCHAR jscriptW[] = {'j','s','c','r','i','p','t',0};
1837 task->window->readystate = READYSTATE_COMPLETE;
1839 hres = IUri_GetPath(task->uri, &code);
1840 if(FAILED(hres))
1841 return;
1843 set_download_state(window->doc_obj, 1);
1845 V_VT(&v) = VT_EMPTY;
1846 hres = exec_script(window, code, jscriptW, &v);
1847 SysFreeString(code);
1848 if(SUCCEEDED(hres) && V_VT(&v) != VT_EMPTY) {
1849 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v));
1850 VariantClear(&v);
1853 if(window->doc_obj->view_sink)
1854 IAdviseSink_OnViewChange(window->doc_obj->view_sink, DVASPECT_CONTENT, -1);
1856 set_download_state(window->doc_obj, 0);
1859 static void navigate_javascript_task_destr(task_t *_task)
1861 navigate_javascript_task_t *task = (navigate_javascript_task_t*)_task;
1863 IUri_Release(task->uri);
1864 heap_free(task);
1867 typedef struct {
1868 task_t header;
1869 HTMLWindow *window;
1870 nsChannelBSC *bscallback;
1871 IMoniker *mon;
1872 } navigate_task_t;
1874 static void navigate_proc(task_t *_task)
1876 navigate_task_t *task = (navigate_task_t*)_task;
1877 HRESULT hres;
1879 hres = set_moniker(&task->window->doc_obj->basedoc, task->mon, NULL, task->bscallback, TRUE);
1880 if(SUCCEEDED(hres))
1881 hres = start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
1885 static void navigate_task_destr(task_t *_task)
1887 navigate_task_t *task = (navigate_task_t*)_task;
1889 IUnknown_Release((IUnknown*)task->bscallback);
1890 IMoniker_Release(task->mon);
1891 heap_free(task);
1894 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1895 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1897 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1898 DWORD post_data_size = 0;
1899 BYTE *post_data = NULL;
1900 WCHAR *headers = NULL;
1901 nsChannelBSC *bsc;
1902 IMoniker *mon;
1903 DWORD scheme;
1904 BSTR new_url;
1905 IUri *uri;
1906 HRESULT hres;
1908 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1909 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1911 new_url = url;
1912 if(This->doc_obj->hostui) {
1913 OLECHAR *translated_url = NULL;
1915 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1916 if(hres == S_OK && translated_url) {
1917 new_url = SysAllocString(translated_url);
1918 CoTaskMemFree(translated_url);
1922 if(This->doc_obj->client) {
1923 IOleCommandTarget *cmdtrg;
1925 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1926 if(SUCCEEDED(hres)) {
1927 VARIANT in, out;
1929 V_VT(&in) = VT_BSTR;
1930 V_BSTR(&in) = new_url;
1931 V_VT(&out) = VT_BOOL;
1932 V_BOOL(&out) = VARIANT_TRUE;
1933 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1934 IOleCommandTarget_Release(cmdtrg);
1935 if(SUCCEEDED(hres))
1936 VariantClear(&out);
1940 hres = CreateUri(new_url, 0, 0, &uri);
1941 if(new_url != url)
1942 SysFreeString(new_url);
1943 if(FAILED(hres))
1944 return hres;
1946 hres = CreateURLMonikerEx2(NULL, uri, &mon, URL_MK_UNIFORM);
1947 if(FAILED(hres))
1948 return hres;
1950 /* FIXME: Why not set_ready_state? */
1951 This->readystate = READYSTATE_UNINITIALIZED;
1953 if(post_data_var) {
1954 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1955 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1956 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1960 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1961 if(V_VT(headers_var) != VT_BSTR)
1962 return E_INVALIDARG;
1964 headers = V_BSTR(headers_var);
1967 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1968 if(post_data)
1969 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1970 if(FAILED(hres)) {
1971 IMoniker_Release(mon);
1972 return hres;
1975 prepare_for_binding(&This->doc_obj->basedoc, mon, NULL, TRUE);
1977 hres = IUri_GetScheme(uri, &scheme);
1979 if(scheme != URL_SCHEME_JAVASCRIPT) {
1980 navigate_task_t *task;
1982 IUri_Release(uri);
1984 task = heap_alloc(sizeof(*task));
1985 if(!task) {
1986 IUnknown_Release((IUnknown*)bsc);
1987 IMoniker_Release(mon);
1988 return E_OUTOFMEMORY;
1991 task->window = This;
1992 task->bscallback = bsc;
1993 task->mon = mon;
1994 push_task(&task->header, navigate_proc, navigate_task_destr, This->task_magic);
1996 /* Silently and repeated when real loading starts? */
1997 This->readystate = READYSTATE_LOADING;
1998 }else {
1999 navigate_javascript_task_t *task;
2001 IUnknown_Release((IUnknown*)bsc);
2002 IMoniker_Release(mon);
2004 task = heap_alloc(sizeof(*task));
2005 if(!task) {
2006 IUri_Release(uri);
2007 return E_OUTOFMEMORY;
2010 task->window = This;
2011 task->uri = uri;
2012 push_task(&task->header, navigate_javascript_proc, navigate_javascript_task_destr, This->task_magic);
2014 /* Why silently? */
2015 This->readystate = READYSTATE_COMPLETE;
2018 return S_OK;
2021 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
2023 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2024 FIXME("(%p)->(%p)\n", This, url);
2025 return E_NOTIMPL;
2028 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
2030 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2031 FIXME("(%p)->(%p)\n", This, cmdtrg);
2032 return E_NOTIMPL;
2035 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
2037 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2038 FIXME("(%p)->(%x)\n", This, arg);
2039 return E_NOTIMPL;
2042 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
2044 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2045 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
2046 return E_NOTIMPL;
2049 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
2051 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2052 TRACE("(%p)->(%p)\n", This, url);
2054 if(!url)
2055 return E_INVALIDARG;
2057 *url = SysAllocString(This->url);
2058 return S_OK;
2061 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
2062 HTMLPrivateWindow_QueryInterface,
2063 HTMLPrivateWindow_AddRef,
2064 HTMLPrivateWindow_Release,
2065 HTMLPrivateWindow_SuperNavigate,
2066 HTMLPrivateWindow_GetPendingUrl,
2067 HTMLPrivateWindow_SetPICSTarget,
2068 HTMLPrivateWindow_PICSComplete,
2069 HTMLPrivateWindow_FindWindowByName,
2070 HTMLPrivateWindow_GetAddressBar
2073 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
2075 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
2078 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
2080 HTMLWindow *This = impl_from_IDispatchEx(iface);
2082 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2085 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
2087 HTMLWindow *This = impl_from_IDispatchEx(iface);
2089 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2092 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
2094 HTMLWindow *This = impl_from_IDispatchEx(iface);
2096 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2099 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
2101 HTMLWindow *This = impl_from_IDispatchEx(iface);
2103 TRACE("(%p)->(%p)\n", This, pctinfo);
2105 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2108 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
2109 LCID lcid, ITypeInfo **ppTInfo)
2111 HTMLWindow *This = impl_from_IDispatchEx(iface);
2113 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2115 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2118 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
2119 LPOLESTR *rgszNames, UINT cNames,
2120 LCID lcid, DISPID *rgDispId)
2122 HTMLWindow *This = impl_from_IDispatchEx(iface);
2123 UINT i;
2124 HRESULT hres;
2126 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2127 lcid, rgDispId);
2129 for(i=0; i < cNames; i++) {
2130 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
2131 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
2132 if(FAILED(hres))
2133 return hres;
2136 return S_OK;
2139 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
2140 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2141 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2143 HTMLWindow *This = impl_from_IDispatchEx(iface);
2145 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2146 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2148 /* FIXME: Use script dispatch */
2150 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2151 pDispParams, pVarResult, pExcepInfo, puArgErr);
2154 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
2156 if(This->global_prop_cnt == This->global_prop_size) {
2157 global_prop_t *new_props;
2158 DWORD new_size;
2160 if(This->global_props) {
2161 new_size = This->global_prop_size*2;
2162 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
2163 }else {
2164 new_size = 16;
2165 new_props = heap_alloc(new_size*sizeof(global_prop_t));
2167 if(!new_props)
2168 return NULL;
2169 This->global_props = new_props;
2170 This->global_prop_size = new_size;
2173 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
2174 if(!This->global_props[This->global_prop_cnt].name)
2175 return NULL;
2177 This->global_props[This->global_prop_cnt].type = type;
2178 return This->global_props + This->global_prop_cnt++;
2181 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
2183 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
2186 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
2188 DWORD i;
2189 ScriptHost *script_host;
2190 DISPID id;
2192 for(i=0; i < This->global_prop_cnt; i++) {
2193 /* FIXME: case sensitivity */
2194 if(!strcmpW(This->global_props[i].name, bstrName)) {
2195 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
2196 return S_OK;
2200 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
2201 global_prop_t *prop;
2203 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
2204 if(!prop)
2205 return E_OUTOFMEMORY;
2207 prop->script_host = script_host;
2208 prop->id = id;
2210 *pid = prop_to_dispid(This, prop);
2211 return S_OK;
2214 return DISP_E_UNKNOWNNAME;
2217 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
2219 HTMLWindow *This = impl_from_IDispatchEx(iface);
2220 HRESULT hres;
2222 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
2224 hres = search_window_props(This, bstrName, grfdex, pid);
2225 if(hres != DISP_E_UNKNOWNNAME)
2226 return hres;
2228 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
2229 if(hres != DISP_E_UNKNOWNNAME)
2230 return hres;
2232 if(This->doc) {
2233 global_prop_t *prop;
2234 IHTMLElement *elem;
2236 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2237 bstrName, &elem);
2238 if(SUCCEEDED(hres) && elem) {
2239 IHTMLElement_Release(elem);
2241 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
2242 if(!prop)
2243 return E_OUTOFMEMORY;
2245 *pid = prop_to_dispid(This, prop);
2246 return S_OK;
2250 return DISP_E_UNKNOWNNAME;
2253 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2254 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2256 HTMLWindow *This = impl_from_IDispatchEx(iface);
2258 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2260 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2261 HTMLLocation *location;
2262 HRESULT hres;
2264 TRACE("forwarding to location.href\n");
2266 hres = get_location(This, &location);
2267 if(FAILED(hres))
2268 return hres;
2270 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2271 wFlags, pdp, pvarRes, pei, pspCaller);
2272 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2273 return hres;
2276 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
2277 pei, pspCaller);
2280 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2282 HTMLWindow *This = impl_from_IDispatchEx(iface);
2284 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2286 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2289 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2291 HTMLWindow *This = impl_from_IDispatchEx(iface);
2293 TRACE("(%p)->(%x)\n", This, id);
2295 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2298 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2300 HTMLWindow *This = impl_from_IDispatchEx(iface);
2302 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2304 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2305 pgrfdex);
2308 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2310 HTMLWindow *This = impl_from_IDispatchEx(iface);
2312 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2314 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2317 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2319 HTMLWindow *This = impl_from_IDispatchEx(iface);
2321 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2323 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2326 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2328 HTMLWindow *This = impl_from_IDispatchEx(iface);
2330 TRACE("(%p)->(%p)\n", This, ppunk);
2332 *ppunk = NULL;
2333 return S_OK;
2336 static const IDispatchExVtbl WindowDispExVtbl = {
2337 WindowDispEx_QueryInterface,
2338 WindowDispEx_AddRef,
2339 WindowDispEx_Release,
2340 WindowDispEx_GetTypeInfoCount,
2341 WindowDispEx_GetTypeInfo,
2342 WindowDispEx_GetIDsOfNames,
2343 WindowDispEx_Invoke,
2344 WindowDispEx_GetDispID,
2345 WindowDispEx_InvokeEx,
2346 WindowDispEx_DeleteMemberByName,
2347 WindowDispEx_DeleteMemberByDispID,
2348 WindowDispEx_GetMemberProperties,
2349 WindowDispEx_GetMemberName,
2350 WindowDispEx_GetNextDispID,
2351 WindowDispEx_GetNameSpaceParent
2354 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2356 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2359 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2361 HTMLWindow *This = impl_from_IServiceProvider(iface);
2362 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2365 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2367 HTMLWindow *This = impl_from_IServiceProvider(iface);
2368 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2371 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2373 HTMLWindow *This = impl_from_IServiceProvider(iface);
2374 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2377 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2379 HTMLWindow *This = impl_from_IServiceProvider(iface);
2381 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2382 TRACE("IID_IHTMLWindow2\n");
2383 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2386 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2388 if(!This->doc_obj)
2389 return E_NOINTERFACE;
2391 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2392 guidService, riid, ppv);
2395 static const IServiceProviderVtbl ServiceProviderVtbl = {
2396 HTMLWindowSP_QueryInterface,
2397 HTMLWindowSP_AddRef,
2398 HTMLWindowSP_Release,
2399 HTMLWindowSP_QueryService
2402 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2404 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2407 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2408 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2410 HTMLWindow *This = impl_from_DispatchEx(dispex);
2411 global_prop_t *prop;
2412 DWORD idx;
2413 HRESULT hres;
2415 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2416 if(idx >= This->global_prop_cnt)
2417 return DISP_E_MEMBERNOTFOUND;
2419 prop = This->global_props+idx;
2421 switch(prop->type) {
2422 case GLOBAL_SCRIPTVAR: {
2423 IDispatchEx *iface;
2424 IDispatch *disp;
2426 disp = get_script_disp(prop->script_host);
2427 if(!disp)
2428 return E_UNEXPECTED;
2430 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2431 if(SUCCEEDED(hres)) {
2432 TRACE("%s >>>\n", debugstr_w(prop->name));
2433 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2434 if(hres == S_OK)
2435 TRACE("%s <<<\n", debugstr_w(prop->name));
2436 else
2437 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2438 IDispatchEx_Release(iface);
2439 }else {
2440 FIXME("No IDispatchEx\n");
2442 IDispatch_Release(disp);
2443 break;
2445 case GLOBAL_ELEMENTVAR: {
2446 IHTMLElement *elem;
2448 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2449 prop->name, &elem);
2450 if(FAILED(hres))
2451 return hres;
2453 if(!elem)
2454 return DISP_E_MEMBERNOTFOUND;
2456 V_VT(res) = VT_DISPATCH;
2457 V_DISPATCH(res) = (IDispatch*)elem;
2458 break;
2460 default:
2461 ERR("invalid type %d\n", prop->type);
2462 hres = DISP_E_MEMBERNOTFOUND;
2465 return hres;
2469 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2470 NULL,
2471 NULL,
2472 HTMLWindow_invoke,
2473 NULL
2476 static const tid_t HTMLWindow_iface_tids[] = {
2477 IHTMLWindow2_tid,
2478 IHTMLWindow3_tid,
2479 IHTMLWindow4_tid,
2480 IHTMLWindow6_tid,
2484 static dispex_static_data_t HTMLWindow_dispex = {
2485 &HTMLWindow_dispex_vtbl,
2486 DispHTMLWindow2_tid,
2487 NULL,
2488 HTMLWindow_iface_tids
2491 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2493 HTMLWindow *window;
2494 HRESULT hres;
2496 window = heap_alloc_zero(sizeof(HTMLWindow));
2497 if(!window)
2498 return E_OUTOFMEMORY;
2500 window->window_ref = heap_alloc(sizeof(windowref_t));
2501 if(!window->window_ref) {
2502 heap_free(window);
2503 return E_OUTOFMEMORY;
2506 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2507 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2508 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2509 window->IHTMLWindow6_iface.lpVtbl = &HTMLWindow6Vtbl;
2510 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2511 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2512 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2513 window->ref = 1;
2514 window->doc_obj = doc_obj;
2516 window->window_ref->window = window;
2517 window->window_ref->ref = 1;
2519 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2521 if(nswindow) {
2522 nsIDOMWindow_AddRef(nswindow);
2523 window->nswindow = nswindow;
2526 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2527 window->readystate = READYSTATE_UNINITIALIZED;
2528 list_init(&window->script_hosts);
2530 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
2531 if(FAILED(hres)) {
2532 IHTMLWindow2_Release(&window->IHTMLWindow2_iface);
2533 return hres;
2536 window->task_magic = get_task_target_magic();
2537 update_window_doc(window);
2539 list_init(&window->children);
2540 list_add_head(&window_list, &window->entry);
2542 if(parent) {
2543 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2545 window->parent = parent;
2546 list_add_tail(&parent->children, &window->sibling_entry);
2549 *ret = window;
2550 return S_OK;
2553 void update_window_doc(HTMLWindow *window)
2555 nsIDOMHTMLDocument *nshtmldoc;
2556 nsIDOMDocument *nsdoc;
2557 nsresult nsres;
2559 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2560 if(NS_FAILED(nsres) || !nsdoc) {
2561 ERR("GetDocument failed: %08x\n", nsres);
2562 return;
2565 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2566 nsIDOMDocument_Release(nsdoc);
2567 if(NS_FAILED(nsres)) {
2568 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2569 return;
2572 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2573 HTMLDocumentNode *doc;
2574 HRESULT hres;
2576 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2577 if(SUCCEEDED(hres)) {
2578 window_set_docnode(window, doc);
2579 htmldoc_release(&doc->basedoc);
2580 }else {
2581 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2585 nsIDOMHTMLDocument_Release(nshtmldoc);
2588 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2590 HTMLWindow *iter;
2592 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2593 if(iter->nswindow == nswindow)
2594 return iter;
2597 return NULL;