msi: Check transform validation flags.
[wine/multimedia.git] / dlls / mshtml / htmlwindow.c
blob6c6c328963572db240ce40c6b0e1f70ad46da2e1
1 /*
2 * Copyright 2006-2012 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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "mshtmdid.h"
29 #include "shlguid.h"
30 #include "shobjidl.h"
31 #include "exdispid.h"
33 #define NO_SHLWAPI_REG
34 #include "shlwapi.h"
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
39 #include "htmlevent.h"
40 #include "htmlscript.h"
41 #include "pluginhost.h"
42 #include "binding.h"
43 #include "resource.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
47 static struct list window_list = LIST_INIT(window_list);
49 static inline BOOL is_outer_window(HTMLWindow *window)
51 return &window->outer_window->base == window;
54 static void release_children(HTMLOuterWindow *This)
56 HTMLOuterWindow *child;
58 while(!list_empty(&This->children)) {
59 child = LIST_ENTRY(list_tail(&This->children), HTMLOuterWindow, sibling_entry);
61 list_remove(&child->sibling_entry);
62 child->parent = NULL;
63 IHTMLWindow2_Release(&child->base.IHTMLWindow2_iface);
67 static HRESULT get_location(HTMLInnerWindow *This, HTMLLocation **ret)
69 if(This->location) {
70 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
71 }else {
72 HRESULT hres;
74 hres = HTMLLocation_Create(This, &This->location);
75 if(FAILED(hres))
76 return hres;
79 *ret = This->location;
80 return S_OK;
83 void get_top_window(HTMLOuterWindow *window, HTMLOuterWindow **ret)
85 HTMLOuterWindow *iter;
87 for(iter = window; iter->parent; iter = iter->parent);
88 *ret = iter;
91 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
93 if(!window->inner_window->doc) {
94 FIXME("No document\n");
95 return E_FAIL;
98 return set_event_handler(&window->inner_window->doc->body_event_target, window->inner_window->doc, eid, var);
101 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
103 if(!window->inner_window->doc) {
104 FIXME("No document\n");
105 return E_FAIL;
108 return get_event_handler(&window->inner_window->doc->body_event_target, eid, var);
111 static void detach_inner_window(HTMLInnerWindow *window)
113 HTMLOuterWindow *outer_window = window->base.outer_window;
115 if(outer_window && outer_window->doc_obj && outer_window == outer_window->doc_obj->basedoc.window)
116 window->doc->basedoc.cp_container.forward_container = NULL;
118 if(window->doc) {
119 detach_events(window->doc);
120 while(!list_empty(&window->doc->plugin_hosts))
121 detach_plugin_host(LIST_ENTRY(list_head(&window->doc->plugin_hosts), PluginHost, entry));
124 abort_window_bindings(window);
125 remove_target_tasks(window->task_magic);
126 release_script_hosts(window);
127 window->base.outer_window = NULL;
129 if(outer_window && outer_window->base.inner_window == window) {
130 outer_window->base.inner_window = NULL;
131 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
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 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
146 if(IsEqualGUID(&IID_IUnknown, riid)) {
147 *ppv = &This->IHTMLWindow2_iface;
148 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
149 *ppv = &This->IHTMLWindow2_iface;
150 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
151 *ppv = &This->IDispatchEx_iface;
152 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
153 *ppv = &This->IHTMLWindow2_iface;
154 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
155 *ppv = &This->IHTMLWindow2_iface;
156 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
157 *ppv = &This->IHTMLWindow3_iface;
158 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
159 *ppv = &This->IHTMLWindow4_iface;
160 }else if(IsEqualGUID(&IID_IHTMLWindow5, riid)) {
161 *ppv = &This->IHTMLWindow5_iface;
162 }else if(IsEqualGUID(&IID_IHTMLWindow6, riid)) {
163 *ppv = &This->IHTMLWindow6_iface;
164 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
165 *ppv = &This->IHTMLPrivateWindow_iface;
166 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
167 *ppv = &This->IServiceProvider_iface;
168 }else if(IsEqualGUID(&IID_ITravelLogClient, riid)) {
169 *ppv = &This->ITravelLogClient_iface;
170 }else if(IsEqualGUID(&IID_IObjectIdentity, riid)) {
171 *ppv = &This->IObjectIdentity_iface;
172 }else if(dispex_query_interface(&This->inner_window->dispex, riid, ppv)) {
173 assert(!*ppv);
174 return E_NOINTERFACE;
175 }else {
176 *ppv = NULL;
177 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
178 return E_NOINTERFACE;
181 IUnknown_AddRef((IUnknown*)*ppv);
182 return S_OK;
185 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
187 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
188 LONG ref = InterlockedIncrement(&This->ref);
190 TRACE("(%p) ref=%d\n", This, ref);
192 return ref;
195 static void release_outer_window(HTMLOuterWindow *This)
197 if(This->pending_window) {
198 abort_window_bindings(This->pending_window);
199 This->pending_window->base.outer_window = NULL;
200 IHTMLWindow2_Release(&This->pending_window->base.IHTMLWindow2_iface);
203 remove_target_tasks(This->task_magic);
204 set_current_mon(This, NULL, 0);
205 if(This->base.inner_window)
206 detach_inner_window(This->base.inner_window);
207 release_children(This);
209 if(This->secmgr)
210 IInternetSecurityManager_Release(This->secmgr);
212 if(This->frame_element)
213 This->frame_element->content_window = NULL;
215 This->window_ref->window = NULL;
216 windowref_release(This->window_ref);
218 if(This->nswindow)
219 nsIDOMWindow_Release(This->nswindow);
221 list_remove(&This->entry);
222 heap_free(This);
225 static void release_inner_window(HTMLInnerWindow *This)
227 unsigned i;
229 TRACE("%p\n", This);
231 detach_inner_window(This);
233 if(This->doc) {
234 This->doc->window = NULL;
235 htmldoc_release(&This->doc->basedoc);
238 release_dispex(&This->dispex);
240 for(i=0; i < This->global_prop_cnt; i++)
241 heap_free(This->global_props[i].name);
242 heap_free(This->global_props);
244 if(This->location) {
245 This->location->window = NULL;
246 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
249 if(This->image_factory) {
250 This->image_factory->window = NULL;
251 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
254 if(This->option_factory) {
255 This->option_factory->window = NULL;
256 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
259 if(This->screen)
260 IHTMLScreen_Release(This->screen);
262 if(This->history) {
263 This->history->window = NULL;
264 IOmHistory_Release(&This->history->IOmHistory_iface);
267 if(This->session_storage)
268 IHTMLStorage_Release(This->session_storage);
270 if(This->mon)
271 IMoniker_Release(This->mon);
273 heap_free(This);
276 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
278 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
279 LONG ref = InterlockedDecrement(&This->ref);
281 TRACE("(%p) ref=%d\n", This, ref);
283 if(!ref) {
284 if(is_outer_window(This))
285 release_outer_window(This->outer_window);
286 else
287 release_inner_window(This->inner_window);
290 return ref;
293 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
295 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
297 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
300 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
301 LCID lcid, ITypeInfo **ppTInfo)
303 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
305 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
308 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
309 LPOLESTR *rgszNames, UINT cNames,
310 LCID lcid, DISPID *rgDispId)
312 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
314 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
315 rgDispId);
318 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
319 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
320 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
322 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
324 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
325 pDispParams, pVarResult, pExcepInfo, puArgErr);
328 static HRESULT get_frame_by_index(HTMLOuterWindow *This, UINT32 index, HTMLOuterWindow **ret)
330 nsIDOMWindowCollection *nsframes;
331 nsIDOMWindow *nswindow;
332 UINT32 length;
333 nsresult nsres;
335 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
336 if(NS_FAILED(nsres)) {
337 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
338 return E_FAIL;
341 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
342 assert(nsres == NS_OK);
344 if(index >= length) {
345 nsIDOMWindowCollection_Release(nsframes);
346 return DISP_E_MEMBERNOTFOUND;
349 nsres = nsIDOMWindowCollection_Item(nsframes, index, &nswindow);
350 nsIDOMWindowCollection_Release(nsframes);
351 if(NS_FAILED(nsres)) {
352 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
353 return E_FAIL;
356 *ret = nswindow_to_window(nswindow);
358 nsIDOMWindow_Release(nswindow);
359 return S_OK;
362 HRESULT get_frame_by_name(HTMLOuterWindow *This, const WCHAR *name, BOOL deep, HTMLOuterWindow **ret)
364 nsIDOMWindowCollection *nsframes;
365 HTMLOuterWindow *window = NULL;
366 nsIDOMWindow *nswindow;
367 nsAString name_str;
368 UINT32 length, i;
369 nsresult nsres;
370 HRESULT hres = S_OK;
372 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
373 if(NS_FAILED(nsres)) {
374 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
375 return E_FAIL;
378 nsAString_InitDepend(&name_str, name);
379 nsres = nsIDOMWindowCollection_NamedItem(nsframes, &name_str, &nswindow);
380 nsAString_Finish(&name_str);
381 if(NS_FAILED(nsres)) {
382 nsIDOMWindowCollection_Release(nsframes);
383 return E_FAIL;
386 if(nswindow) {
387 *ret = nswindow_to_window(nswindow);
388 return S_OK;
391 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
392 assert(nsres == NS_OK);
394 for(i = 0; i < length && !window; ++i) {
395 HTMLOuterWindow *window_iter;
396 BSTR id;
398 nsres = nsIDOMWindowCollection_Item(nsframes, i, &nswindow);
399 if(NS_FAILED(nsres)) {
400 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
401 hres = E_FAIL;
402 break;
405 window_iter = nswindow_to_window(nswindow);
407 nsIDOMWindow_Release(nswindow);
409 hres = IHTMLElement_get_id(&window_iter->frame_element->element.IHTMLElement_iface, &id);
410 if(FAILED(hres)) {
411 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
412 break;
415 if(id && !strcmpiW(id, name))
416 window = window_iter;
418 SysFreeString(id);
420 if(!window && deep)
421 get_frame_by_name(window_iter, name, TRUE, &window);
424 nsIDOMWindowCollection_Release(nsframes);
425 if(FAILED(hres))
426 return hres;
428 *ret = window;
429 return NS_OK;
432 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
434 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
435 HTMLOuterWindow *window = NULL;
436 HRESULT hres;
438 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
440 switch(V_VT(pvarIndex)) {
441 case VT_I4: {
442 int index = V_I4(pvarIndex);
443 TRACE("Getting index %d\n", index);
444 if(index < 0)
445 return DISP_E_MEMBERNOTFOUND;
446 hres = get_frame_by_index(This->outer_window, index, &window);
447 break;
449 case VT_UINT: {
450 unsigned int index = V_UINT(pvarIndex);
451 TRACE("Getting index %u\n", index);
452 hres = get_frame_by_index(This->outer_window, index, &window);
453 break;
455 case VT_BSTR: {
456 BSTR str = V_BSTR(pvarIndex);
457 TRACE("Getting name %s\n", wine_dbgstr_w(str));
458 hres = get_frame_by_name(This->outer_window, str, FALSE, &window);
459 break;
461 default:
462 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
463 return E_INVALIDARG;
466 if(FAILED(hres))
467 return hres;
468 if(!window)
469 return DISP_E_MEMBERNOTFOUND;
471 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
472 V_VT(pvarResult) = VT_DISPATCH;
473 V_DISPATCH(pvarResult) = (IDispatch*)window;
474 return S_OK;
477 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
479 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
480 nsIDOMWindowCollection *nscollection;
481 UINT32 length;
482 nsresult nsres;
484 TRACE("(%p)->(%p)\n", This, p);
486 nsres = nsIDOMWindow_GetFrames(This->outer_window->nswindow, &nscollection);
487 if(NS_FAILED(nsres)) {
488 ERR("GetFrames failed: %08x\n", nsres);
489 return E_FAIL;
492 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
493 nsIDOMWindowCollection_Release(nscollection);
494 if(NS_FAILED(nsres)) {
495 ERR("GetLength failed: %08x\n", nsres);
496 return E_FAIL;
499 *p = length;
500 return S_OK;
503 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
505 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
506 FIXME("(%p)->(%p): semi-stub\n", This, p);
508 /* FIXME: Should return a separate Window object */
509 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
510 HTMLWindow2_AddRef(iface);
511 return S_OK;
514 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
516 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
517 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
518 return E_NOTIMPL;
521 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
523 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
524 FIXME("(%p)->(%p)\n", This, p);
525 return E_NOTIMPL;
528 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
530 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
532 WARN("(%p)->(%s)\n", This, debugstr_w(v));
535 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
536 * Ignoring the call should be enough for us.
538 return S_OK;
541 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
543 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
545 TRACE("(%p)->(%p)\n", This, p);
547 /* See put_status */
548 *p = NULL;
549 return S_OK;
552 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
553 LONG msec, VARIANT *language, LONG *timerID)
555 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
556 VARIANT expr_var;
558 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
560 V_VT(&expr_var) = VT_BSTR;
561 V_BSTR(&expr_var) = expression;
563 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
566 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
568 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
570 TRACE("(%p)->(%d)\n", This, timerID);
572 return clear_task_timer(This->inner_window, FALSE, timerID);
575 #define MAX_MESSAGE_LEN 2000
577 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
579 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
580 WCHAR title[100], *msg = message;
581 DWORD len;
583 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
585 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
586 sizeof(title)/sizeof(WCHAR))) {
587 WARN("Could not load message box title: %d\n", GetLastError());
588 return S_OK;
591 len = SysStringLen(message);
592 if(len > MAX_MESSAGE_LEN) {
593 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
594 if(!msg)
595 return E_OUTOFMEMORY;
596 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
597 msg[MAX_MESSAGE_LEN] = 0;
600 MessageBoxW(This->outer_window->doc_obj->hwnd, msg, title, MB_ICONWARNING);
601 if(msg != message)
602 heap_free(msg);
603 return S_OK;
606 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
607 VARIANT_BOOL *confirmed)
609 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
610 WCHAR wszTitle[100];
612 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
614 if(!confirmed) return E_INVALIDARG;
616 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
617 sizeof(wszTitle)/sizeof(WCHAR))) {
618 WARN("Could not load message box title: %d\n", GetLastError());
619 *confirmed = VARIANT_TRUE;
620 return S_OK;
623 if(MessageBoxW(This->outer_window->doc_obj->hwnd, message, wszTitle,
624 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
625 *confirmed = VARIANT_TRUE;
626 else *confirmed = VARIANT_FALSE;
628 return S_OK;
631 typedef struct
633 BSTR message;
634 BSTR dststr;
635 VARIANT *textdata;
636 }prompt_arg;
638 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
639 WPARAM wparam, LPARAM lparam)
641 switch(msg)
643 case WM_INITDIALOG:
645 prompt_arg *arg = (prompt_arg*)lparam;
646 WCHAR wszTitle[100];
648 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
649 sizeof(wszTitle)/sizeof(WCHAR))) {
650 WARN("Could not load message box title: %d\n", GetLastError());
651 EndDialog(hwnd, wparam);
652 return FALSE;
655 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
656 SetWindowTextW(hwnd, wszTitle);
657 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
658 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
659 return FALSE;
661 case WM_COMMAND:
662 switch(wparam)
664 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
665 EndDialog(hwnd, wparam);
666 return TRUE;
667 case MAKEWPARAM(IDOK, BN_CLICKED):
669 prompt_arg *arg =
670 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
671 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
672 INT len = GetWindowTextLengthW(hwndPrompt);
674 if(!arg->textdata)
676 EndDialog(hwnd, wparam);
677 return TRUE;
680 V_VT(arg->textdata) = VT_BSTR;
681 if(!len && !arg->dststr)
682 V_BSTR(arg->textdata) = NULL;
683 else
685 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
686 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
688 EndDialog(hwnd, wparam);
689 return TRUE;
692 return FALSE;
693 case WM_CLOSE:
694 EndDialog(hwnd, IDCANCEL);
695 return TRUE;
696 default:
697 return FALSE;
701 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
702 BSTR dststr, VARIANT *textdata)
704 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
705 prompt_arg arg;
707 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
709 if(textdata) V_VT(textdata) = VT_NULL;
711 arg.message = message;
712 arg.dststr = dststr;
713 arg.textdata = textdata;
715 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
716 This->outer_window->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
717 return S_OK;
720 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
722 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
723 HTMLInnerWindow *window = This->inner_window;
725 TRACE("(%p)->(%p)\n", This, p);
727 if(!window->image_factory) {
728 HRESULT hres;
730 hres = HTMLImageElementFactory_Create(window, &window->image_factory);
731 if(FAILED(hres))
732 return hres;
735 *p = &window->image_factory->IHTMLImageElementFactory_iface;
736 IHTMLImageElementFactory_AddRef(*p);
738 return S_OK;
741 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
743 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
744 HTMLLocation *location;
745 HRESULT hres;
747 TRACE("(%p)->(%p)\n", This, p);
749 hres = get_location(This->inner_window, &location);
750 if(FAILED(hres))
751 return hres;
753 *p = &location->IHTMLLocation_iface;
754 return S_OK;
757 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
759 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
760 HTMLInnerWindow *window = This->inner_window;
762 TRACE("(%p)->(%p)\n", This, p);
764 if(!window->history) {
765 HRESULT hres;
767 hres = create_history(window, &window->history);
768 if(FAILED(hres))
769 return hres;
772 IOmHistory_AddRef(&window->history->IOmHistory_iface);
773 *p = &window->history->IOmHistory_iface;
774 return S_OK;
777 static BOOL notify_webbrowser_close(HTMLOuterWindow *window, HTMLDocumentObj *doc)
779 IConnectionPointContainer *cp_container;
780 VARIANT_BOOL cancel = VARIANT_FALSE;
781 IEnumConnections *enum_conn;
782 VARIANT args[2];
783 DISPPARAMS dp = {args, NULL, 2, 0};
784 CONNECTDATA conn_data;
785 IConnectionPoint *cp;
786 IDispatch *disp;
787 ULONG fetched;
788 HRESULT hres;
790 if(!doc->webbrowser)
791 return TRUE;
793 hres = IUnknown_QueryInterface(doc->webbrowser, &IID_IConnectionPointContainer, (void**)&cp_container);
794 if(FAILED(hres))
795 return TRUE;
797 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &DIID_DWebBrowserEvents2, &cp);
798 IConnectionPointContainer_Release(cp_container);
799 if(FAILED(hres))
800 return TRUE;
802 hres = IConnectionPoint_EnumConnections(cp, &enum_conn);
803 IConnectionPoint_Release(cp);
804 if(FAILED(hres))
805 return TRUE;
807 while(!cancel) {
808 conn_data.pUnk = NULL;
809 conn_data.dwCookie = 0;
810 fetched = 0;
811 hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
812 if(hres != S_OK)
813 break;
815 hres = IUnknown_QueryInterface(conn_data.pUnk, &IID_IDispatch, (void**)&disp);
816 IUnknown_Release(conn_data.pUnk);
817 if(FAILED(hres))
818 continue;
820 V_VT(args) = VT_BYREF|VT_BOOL;
821 V_BOOLREF(args) = &cancel;
822 V_VT(args+1) = VT_BOOL;
823 V_BOOL(args+1) = window->parent ? VARIANT_TRUE : VARIANT_FALSE;
824 hres = IDispatch_Invoke(disp, DISPID_WINDOWCLOSING, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
825 IDispatch_Release(disp);
826 if(FAILED(hres))
827 cancel = VARIANT_FALSE;
830 IEnumConnections_Release(enum_conn);
831 return !cancel;
834 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
836 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
837 HTMLOuterWindow *window = This->outer_window;
839 TRACE("(%p)\n", This);
841 if(!window->doc_obj) {
842 FIXME("No document object\n");
843 return E_FAIL;
846 if(!notify_webbrowser_close(window, window->doc_obj))
847 return S_OK;
849 FIXME("default action not implemented\n");
850 return E_NOTIMPL;
853 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
855 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
856 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
857 return E_NOTIMPL;
860 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
862 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
864 FIXME("(%p)->(%p) returning empty\n", This, p);
866 V_VT(p) = VT_EMPTY;
867 return S_OK;
870 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
872 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
874 TRACE("(%p)->(%p)\n", This, p);
876 *p = OmNavigator_Create();
877 return *p ? S_OK : E_OUTOFMEMORY;
880 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
882 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
883 nsAString name_str;
884 nsresult nsres;
886 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
888 nsAString_InitDepend(&name_str, v);
889 nsres = nsIDOMWindow_SetName(This->outer_window->nswindow, &name_str);
890 nsAString_Finish(&name_str);
891 if(NS_FAILED(nsres))
892 ERR("SetName failed: %08x\n", nsres);
894 return S_OK;
897 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
899 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
900 nsAString name_str;
901 nsresult nsres;
903 TRACE("(%p)->(%p)\n", This, p);
905 nsAString_Init(&name_str, NULL);
906 nsres = nsIDOMWindow_GetName(This->outer_window->nswindow, &name_str);
907 return return_nsstr(nsres, &name_str, p);
910 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
912 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
913 HTMLOuterWindow *window = This->outer_window;
915 TRACE("(%p)->(%p)\n", This, p);
917 if(!window->parent)
918 return IHTMLWindow2_get_self(&This->IHTMLWindow2_iface, p);
920 *p = &window->parent->base.IHTMLWindow2_iface;
921 IHTMLWindow2_AddRef(*p);
922 return S_OK;
925 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
926 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
928 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
929 HTMLOuterWindow *window = This->outer_window;
930 INewWindowManager *new_window_mgr;
931 BSTR uri_str;
932 IUri *uri;
933 HRESULT hres;
935 TRACE("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
936 debugstr_w(features), replace, pomWindowResult);
938 if(!window->doc_obj || !window->uri_nofrag)
939 return E_UNEXPECTED;
941 if(name && *name == '_') {
942 FIXME("Unsupported name %s\n", debugstr_w(name));
943 return E_NOTIMPL;
946 hres = do_query_service((IUnknown*)window->doc_obj->client, &SID_SNewWindowManager, &IID_INewWindowManager,
947 (void**)&new_window_mgr);
948 if(FAILED(hres)) {
949 FIXME("No INewWindowManager\n");
950 return E_NOTIMPL;
953 hres = IUri_GetDisplayUri(window->uri_nofrag, &uri_str);
954 if(SUCCEEDED(hres)) {
955 hres = INewWindowManager_EvaluateNewWindow(new_window_mgr, url, name, uri_str,
956 features, !!replace, window->doc_obj->has_popup ? 0 : NWMF_FIRST, 0);
957 window->doc_obj->has_popup = TRUE;
958 SysFreeString(uri_str);
960 INewWindowManager_Release(new_window_mgr);
961 if(FAILED(hres)) {
962 *pomWindowResult = NULL;
963 return S_OK;
966 hres = create_relative_uri(window, url, &uri);
967 if(FAILED(hres))
968 return hres;
970 hres = navigate_new_window(window, uri, name, pomWindowResult);
971 IUri_Release(uri);
972 return hres;
975 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
977 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
979 TRACE("(%p)->(%p)\n", This, p);
981 /* FIXME: We should return kind of proxy window here. */
982 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
983 *p = &This->IHTMLWindow2_iface;
984 return S_OK;
987 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
989 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
990 HTMLOuterWindow *top;
992 TRACE("(%p)->(%p)\n", This, p);
994 get_top_window(This->outer_window, &top);
995 *p = &top->base.IHTMLWindow2_iface;
996 IHTMLWindow2_AddRef(*p);
998 return S_OK;
1001 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1003 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1005 TRACE("(%p)->(%p)\n", This, p);
1007 /* FIXME: We should return kind of proxy window here. */
1008 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1009 *p = &This->IHTMLWindow2_iface;
1010 return S_OK;
1013 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
1015 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1017 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
1019 return navigate_url(This->outer_window, url, This->outer_window->uri, BINDING_NAVIGATED);
1022 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
1024 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1026 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1028 return set_window_event(This, EVENTID_FOCUS, &v);
1031 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
1033 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1035 TRACE("(%p)->(%p)\n", This, p);
1037 return get_window_event(This, EVENTID_FOCUS, p);
1040 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
1042 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1044 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1046 return set_window_event(This, EVENTID_BLUR, &v);
1049 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
1051 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1053 TRACE("(%p)->(%p)\n", This, p);
1055 return get_window_event(This, EVENTID_BLUR, p);
1058 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
1060 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1062 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1064 return set_window_event(This, EVENTID_LOAD, &v);
1067 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
1069 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1071 TRACE("(%p)->(%p)\n", This, p);
1073 return get_window_event(This, EVENTID_LOAD, p);
1076 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
1078 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1080 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1082 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
1085 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
1087 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1089 TRACE("(%p)->(%p)\n", This, p);
1091 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
1094 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
1096 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1097 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1098 return E_NOTIMPL;
1101 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
1103 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1104 FIXME("(%p)->(%p)\n", This, p);
1105 return E_NOTIMPL;
1108 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
1110 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1112 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1114 return set_window_event(This, EVENTID_HELP, &v);
1117 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
1119 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1121 TRACE("(%p)->(%p)\n", This, p);
1123 return get_window_event(This, EVENTID_HELP, p);
1126 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
1128 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1130 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1132 return set_window_event(This, EVENTID_ERROR, &v);
1135 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
1137 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1139 TRACE("(%p)->(%p)\n", This, p);
1141 return get_window_event(This, EVENTID_ERROR, p);
1144 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
1146 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1148 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1150 return set_window_event(This, EVENTID_RESIZE, &v);
1153 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
1155 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1157 TRACE("(%p)->(%p)\n", This, p);
1159 return get_window_event(This, EVENTID_RESIZE, p);
1162 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
1164 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1166 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1168 return set_window_event(This, EVENTID_SCROLL, &v);
1171 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
1173 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1175 TRACE("(%p)->(%p)\n", This, p);
1177 return get_window_event(This, EVENTID_SCROLL, p);
1180 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
1182 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1184 TRACE("(%p)->(%p)\n", This, p);
1186 if(This->inner_window->doc) {
1187 /* FIXME: We should return a wrapper object here */
1188 *p = &This->inner_window->doc->basedoc.IHTMLDocument2_iface;
1189 IHTMLDocument2_AddRef(*p);
1190 }else {
1191 *p = NULL;
1194 return S_OK;
1197 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1199 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1200 HTMLInnerWindow *window = This->inner_window;
1202 TRACE("(%p)->(%p)\n", This, p);
1204 if(window->event)
1205 IHTMLEventObj_AddRef(window->event);
1206 *p = window->event;
1207 return S_OK;
1210 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1212 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1213 FIXME("(%p)->(%p)\n", This, p);
1214 return E_NOTIMPL;
1217 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1218 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1220 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1221 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1222 return E_NOTIMPL;
1225 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1226 BSTR features)
1228 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1229 FIXME("(%p)->(%s %s %s)\n", This, debugstr_w(helpURL), debugstr_variant(&helpArg), debugstr_w(features));
1230 return E_NOTIMPL;
1233 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1235 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1236 HTMLInnerWindow *window = This->inner_window;
1238 TRACE("(%p)->(%p)\n", This, p);
1240 if(!window->screen) {
1241 HRESULT hres;
1243 hres = HTMLScreen_Create(&window->screen);
1244 if(FAILED(hres))
1245 return hres;
1248 *p = window->screen;
1249 IHTMLScreen_AddRef(window->screen);
1250 return S_OK;
1253 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1255 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1256 HTMLInnerWindow *window = This->inner_window;
1258 TRACE("(%p)->(%p)\n", This, p);
1260 if(!window->option_factory) {
1261 HRESULT hres;
1263 hres = HTMLOptionElementFactory_Create(window, &window->option_factory);
1264 if(FAILED(hres))
1265 return hres;
1268 *p = &window->option_factory->IHTMLOptionElementFactory_iface;
1269 IHTMLOptionElementFactory_AddRef(*p);
1271 return S_OK;
1274 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1276 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1278 TRACE("(%p)->()\n", This);
1280 if(This->outer_window->doc_obj)
1281 SetFocus(This->outer_window->doc_obj->hwnd);
1282 return S_OK;
1285 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1287 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1288 FIXME("(%p)->(%p)\n", This, p);
1289 return E_NOTIMPL;
1292 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1294 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1295 FIXME("(%p)->()\n", This);
1296 return E_NOTIMPL;
1299 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1301 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1302 nsresult nsres;
1304 TRACE("(%p)->(%d %d)\n", This, x, y);
1306 nsres = nsIDOMWindow_Scroll(This->outer_window->nswindow, x, y);
1307 if(NS_FAILED(nsres)) {
1308 ERR("ScrollBy failed: %08x\n", nsres);
1309 return E_FAIL;
1312 return S_OK;
1315 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1317 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1318 FIXME("(%p)->(%p)\n", This, p);
1319 return E_NOTIMPL;
1322 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1323 LONG msec, VARIANT *language, LONG *timerID)
1325 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1326 VARIANT expr;
1328 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1330 V_VT(&expr) = VT_BSTR;
1331 V_BSTR(&expr) = expression;
1332 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1335 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1337 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1339 TRACE("(%p)->(%d)\n", This, timerID);
1341 return clear_task_timer(This->inner_window, TRUE, timerID);
1344 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1346 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1347 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1348 return E_NOTIMPL;
1351 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1353 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1354 FIXME("(%p)->(%p)\n", This, p);
1355 return E_NOTIMPL;
1358 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1359 VARIANT *pvarRet)
1361 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1363 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1365 return exec_script(This->inner_window, scode, language, pvarRet);
1368 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1370 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1372 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1374 TRACE("(%p)->(%p)\n", This, String);
1376 if(!String)
1377 return E_INVALIDARG;
1379 *String = SysAllocString(objectW);
1380 return *String ? S_OK : E_OUTOFMEMORY;
1383 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1385 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1386 nsresult nsres;
1388 TRACE("(%p)->(%d %d)\n", This, x, y);
1390 nsres = nsIDOMWindow_ScrollBy(This->outer_window->nswindow, x, y);
1391 if(NS_FAILED(nsres))
1392 ERR("ScrollBy failed: %08x\n", nsres);
1394 return S_OK;
1397 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1399 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1400 nsresult nsres;
1402 TRACE("(%p)->(%d %d)\n", This, x, y);
1404 nsres = nsIDOMWindow_ScrollTo(This->outer_window->nswindow, x, y);
1405 if(NS_FAILED(nsres))
1406 ERR("ScrollTo failed: %08x\n", nsres);
1408 return S_OK;
1411 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1413 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1414 FIXME("(%p)->(%d %d)\n", This, x, y);
1415 return E_NOTIMPL;
1418 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1420 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1421 FIXME("(%p)->(%d %d)\n", This, x, y);
1422 return E_NOTIMPL;
1425 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1427 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1428 FIXME("(%p)->(%d %d)\n", This, x, y);
1429 return E_NOTIMPL;
1432 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1434 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1435 FIXME("(%p)->(%d %d)\n", This, x, y);
1436 return E_NOTIMPL;
1439 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1441 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1443 TRACE("(%p)->(%p)\n", This, p);
1445 *p = NULL;
1447 if(!This->outer_window->doc_obj->hostui)
1448 return S_OK;
1450 return IDocHostUIHandler_GetExternal(This->outer_window->doc_obj->hostui, p);
1453 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1454 HTMLWindow2_QueryInterface,
1455 HTMLWindow2_AddRef,
1456 HTMLWindow2_Release,
1457 HTMLWindow2_GetTypeInfoCount,
1458 HTMLWindow2_GetTypeInfo,
1459 HTMLWindow2_GetIDsOfNames,
1460 HTMLWindow2_Invoke,
1461 HTMLWindow2_item,
1462 HTMLWindow2_get_length,
1463 HTMLWindow2_get_frames,
1464 HTMLWindow2_put_defaultStatus,
1465 HTMLWindow2_get_defaultStatus,
1466 HTMLWindow2_put_status,
1467 HTMLWindow2_get_status,
1468 HTMLWindow2_setTimeout,
1469 HTMLWindow2_clearTimeout,
1470 HTMLWindow2_alert,
1471 HTMLWindow2_confirm,
1472 HTMLWindow2_prompt,
1473 HTMLWindow2_get_Image,
1474 HTMLWindow2_get_location,
1475 HTMLWindow2_get_history,
1476 HTMLWindow2_close,
1477 HTMLWindow2_put_opener,
1478 HTMLWindow2_get_opener,
1479 HTMLWindow2_get_navigator,
1480 HTMLWindow2_put_name,
1481 HTMLWindow2_get_name,
1482 HTMLWindow2_get_parent,
1483 HTMLWindow2_open,
1484 HTMLWindow2_get_self,
1485 HTMLWindow2_get_top,
1486 HTMLWindow2_get_window,
1487 HTMLWindow2_navigate,
1488 HTMLWindow2_put_onfocus,
1489 HTMLWindow2_get_onfocus,
1490 HTMLWindow2_put_onblur,
1491 HTMLWindow2_get_onblur,
1492 HTMLWindow2_put_onload,
1493 HTMLWindow2_get_onload,
1494 HTMLWindow2_put_onbeforeunload,
1495 HTMLWindow2_get_onbeforeunload,
1496 HTMLWindow2_put_onunload,
1497 HTMLWindow2_get_onunload,
1498 HTMLWindow2_put_onhelp,
1499 HTMLWindow2_get_onhelp,
1500 HTMLWindow2_put_onerror,
1501 HTMLWindow2_get_onerror,
1502 HTMLWindow2_put_onresize,
1503 HTMLWindow2_get_onresize,
1504 HTMLWindow2_put_onscroll,
1505 HTMLWindow2_get_onscroll,
1506 HTMLWindow2_get_document,
1507 HTMLWindow2_get_event,
1508 HTMLWindow2_get__newEnum,
1509 HTMLWindow2_showModalDialog,
1510 HTMLWindow2_showHelp,
1511 HTMLWindow2_get_screen,
1512 HTMLWindow2_get_Option,
1513 HTMLWindow2_focus,
1514 HTMLWindow2_get_closed,
1515 HTMLWindow2_blur,
1516 HTMLWindow2_scroll,
1517 HTMLWindow2_get_clientInformation,
1518 HTMLWindow2_setInterval,
1519 HTMLWindow2_clearInterval,
1520 HTMLWindow2_put_offscreenBuffering,
1521 HTMLWindow2_get_offscreenBuffering,
1522 HTMLWindow2_execScript,
1523 HTMLWindow2_toString,
1524 HTMLWindow2_scrollBy,
1525 HTMLWindow2_scrollTo,
1526 HTMLWindow2_moveTo,
1527 HTMLWindow2_moveBy,
1528 HTMLWindow2_resizeTo,
1529 HTMLWindow2_resizeBy,
1530 HTMLWindow2_get_external
1533 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1535 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1538 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1540 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1542 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1545 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1547 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1549 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1552 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1554 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1556 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1559 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1561 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1563 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1566 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1567 LCID lcid, ITypeInfo **ppTInfo)
1569 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1571 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1574 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1575 LPOLESTR *rgszNames, UINT cNames,
1576 LCID lcid, DISPID *rgDispId)
1578 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1580 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1581 rgDispId);
1584 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1585 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1586 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1588 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1590 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1591 pDispParams, pVarResult, pExcepInfo, puArgErr);
1594 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1596 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1597 FIXME("(%p)->(%p)\n", This, p);
1598 return E_NOTIMPL;
1601 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1603 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1604 FIXME("(%p)->(%p)\n", This, p);
1605 return E_NOTIMPL;
1608 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1610 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1611 HTMLInnerWindow *window = This->inner_window;
1613 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1615 if(!window->doc) {
1616 FIXME("No document\n");
1617 return E_FAIL;
1620 return attach_event(&window->doc->body_event_target, &window->doc->basedoc, event, pDisp, pfResult);
1623 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1625 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1626 HTMLInnerWindow *window = This->inner_window;
1628 TRACE("(%p)->()\n", This);
1630 if(!window->doc) {
1631 FIXME("No document\n");
1632 return E_FAIL;
1635 return detach_event(window->doc->body_event_target, &window->doc->basedoc, event, pDisp);
1638 static HRESULT window_set_timer(HTMLInnerWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1639 BOOL interval, LONG *timer_id)
1641 IDispatch *disp = NULL;
1642 HRESULT hres;
1644 switch(V_VT(expr)) {
1645 case VT_DISPATCH:
1646 disp = V_DISPATCH(expr);
1647 IDispatch_AddRef(disp);
1648 break;
1650 case VT_BSTR:
1651 disp = script_parse_event(This->base.inner_window, V_BSTR(expr));
1652 break;
1654 default:
1655 FIXME("unimplemented expr %s\n", debugstr_variant(expr));
1656 return E_NOTIMPL;
1659 if(!disp)
1660 return E_FAIL;
1662 hres = set_task_timer(This, msec, interval, disp, timer_id);
1663 IDispatch_Release(disp);
1665 return hres;
1668 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1669 VARIANT *language, LONG *timerID)
1671 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1673 TRACE("(%p)->(%s %d %s %p)\n", This, debugstr_variant(expression), msec, debugstr_variant(language), timerID);
1675 return window_set_timer(This->inner_window, expression, msec, language, FALSE, timerID);
1678 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1679 VARIANT *language, LONG *timerID)
1681 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1683 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1685 return window_set_timer(This->inner_window, expression, msec, language, TRUE, timerID);
1688 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1690 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1691 FIXME("(%p)\n", This);
1692 return E_NOTIMPL;
1695 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1697 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1698 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1699 return E_NOTIMPL;
1702 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1704 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1705 FIXME("(%p)->(%p)\n", This, p);
1706 return E_NOTIMPL;
1709 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1711 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1712 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1713 return E_NOTIMPL;
1716 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1718 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1719 FIXME("(%p)->(%p)\n", This, p);
1720 return E_NOTIMPL;
1723 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1725 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1726 FIXME("(%p)->(%p)\n", This, p);
1727 return E_NOTIMPL;
1730 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1731 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1733 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1734 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1735 return E_NOTIMPL;
1738 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1739 HTMLWindow3_QueryInterface,
1740 HTMLWindow3_AddRef,
1741 HTMLWindow3_Release,
1742 HTMLWindow3_GetTypeInfoCount,
1743 HTMLWindow3_GetTypeInfo,
1744 HTMLWindow3_GetIDsOfNames,
1745 HTMLWindow3_Invoke,
1746 HTMLWindow3_get_screenLeft,
1747 HTMLWindow3_get_screenTop,
1748 HTMLWindow3_attachEvent,
1749 HTMLWindow3_detachEvent,
1750 HTMLWindow3_setTimeout,
1751 HTMLWindow3_setInterval,
1752 HTMLWindow3_print,
1753 HTMLWindow3_put_onbeforeprint,
1754 HTMLWindow3_get_onbeforeprint,
1755 HTMLWindow3_put_onafterprint,
1756 HTMLWindow3_get_onafterprint,
1757 HTMLWindow3_get_clipboardData,
1758 HTMLWindow3_showModelessDialog
1761 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1763 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1766 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1768 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1770 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1773 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1775 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1777 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1780 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1782 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1784 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1787 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1789 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1791 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1794 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1795 LCID lcid, ITypeInfo **ppTInfo)
1797 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1799 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1802 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1803 LPOLESTR *rgszNames, UINT cNames,
1804 LCID lcid, DISPID *rgDispId)
1806 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1808 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1809 rgDispId);
1812 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1813 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1814 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1816 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1818 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1819 pDispParams, pVarResult, pExcepInfo, puArgErr);
1822 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1823 IDispatch **ppPopup)
1825 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1826 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1827 return E_NOTIMPL;
1830 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1832 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1833 TRACE("(%p)->(%p)\n", This, p);
1835 if(This->outer_window->frame_element) {
1836 *p = &This->outer_window->frame_element->IHTMLFrameBase_iface;
1837 IHTMLFrameBase_AddRef(*p);
1838 }else
1839 *p = NULL;
1841 return S_OK;
1844 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1845 HTMLWindow4_QueryInterface,
1846 HTMLWindow4_AddRef,
1847 HTMLWindow4_Release,
1848 HTMLWindow4_GetTypeInfoCount,
1849 HTMLWindow4_GetTypeInfo,
1850 HTMLWindow4_GetIDsOfNames,
1851 HTMLWindow4_Invoke,
1852 HTMLWindow4_createPopup,
1853 HTMLWindow4_get_frameElement
1856 static inline HTMLWindow *impl_from_IHTMLWindow5(IHTMLWindow5 *iface)
1858 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow5_iface);
1861 static HRESULT WINAPI HTMLWindow5_QueryInterface(IHTMLWindow5 *iface, REFIID riid, void **ppv)
1863 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1865 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1868 static ULONG WINAPI HTMLWindow5_AddRef(IHTMLWindow5 *iface)
1870 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1872 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1875 static ULONG WINAPI HTMLWindow5_Release(IHTMLWindow5 *iface)
1877 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1879 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1882 static HRESULT WINAPI HTMLWindow5_GetTypeInfoCount(IHTMLWindow5 *iface, UINT *pctinfo)
1884 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1886 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1889 static HRESULT WINAPI HTMLWindow5_GetTypeInfo(IHTMLWindow5 *iface, UINT iTInfo,
1890 LCID lcid, ITypeInfo **ppTInfo)
1892 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1894 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1897 static HRESULT WINAPI HTMLWindow5_GetIDsOfNames(IHTMLWindow5 *iface, REFIID riid,
1898 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1900 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1902 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1903 rgDispId);
1906 static HRESULT WINAPI HTMLWindow5_Invoke(IHTMLWindow5 *iface, DISPID dispIdMember,
1907 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1908 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1910 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1912 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1913 pDispParams, pVarResult, pExcepInfo, puArgErr);
1916 static HRESULT WINAPI HTMLWindow5_put_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT v)
1918 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1919 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1920 return E_NOTIMPL;
1923 static HRESULT WINAPI HTMLWindow5_get_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT *p)
1925 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1926 FIXME("(%p)->(%p)\n", This, p);
1927 return E_NOTIMPL;
1930 static const IHTMLWindow5Vtbl HTMLWindow5Vtbl = {
1931 HTMLWindow5_QueryInterface,
1932 HTMLWindow5_AddRef,
1933 HTMLWindow5_Release,
1934 HTMLWindow5_GetTypeInfoCount,
1935 HTMLWindow5_GetTypeInfo,
1936 HTMLWindow5_GetIDsOfNames,
1937 HTMLWindow5_Invoke,
1938 HTMLWindow5_put_XMLHttpRequest,
1939 HTMLWindow5_get_XMLHttpRequest
1942 static inline HTMLWindow *impl_from_IHTMLWindow6(IHTMLWindow6 *iface)
1944 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow6_iface);
1947 static HRESULT WINAPI HTMLWindow6_QueryInterface(IHTMLWindow6 *iface, REFIID riid, void **ppv)
1949 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1951 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1954 static ULONG WINAPI HTMLWindow6_AddRef(IHTMLWindow6 *iface)
1956 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1958 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1961 static ULONG WINAPI HTMLWindow6_Release(IHTMLWindow6 *iface)
1963 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1965 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1968 static HRESULT WINAPI HTMLWindow6_GetTypeInfoCount(IHTMLWindow6 *iface, UINT *pctinfo)
1970 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1972 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1975 static HRESULT WINAPI HTMLWindow6_GetTypeInfo(IHTMLWindow6 *iface, UINT iTInfo,
1976 LCID lcid, ITypeInfo **ppTInfo)
1978 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1980 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1983 static HRESULT WINAPI HTMLWindow6_GetIDsOfNames(IHTMLWindow6 *iface, REFIID riid,
1984 LPOLESTR *rgszNames, UINT cNames,
1985 LCID lcid, DISPID *rgDispId)
1987 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1989 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1990 rgDispId);
1993 static HRESULT WINAPI HTMLWindow6_Invoke(IHTMLWindow6 *iface, DISPID dispIdMember,
1994 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1995 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1997 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
1999 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2000 pDispParams, pVarResult, pExcepInfo, puArgErr);
2003 static HRESULT WINAPI HTMLWindow6_put_XDomainRequest(IHTMLWindow6 *iface, VARIANT v)
2005 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2006 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2007 return E_NOTIMPL;
2010 static HRESULT WINAPI HTMLWindow6_get_XDomainRequest(IHTMLWindow6 *iface, VARIANT *p)
2012 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2013 FIXME("(%p)->(%p)\n", This, p);
2014 return E_NOTIMPL;
2017 static HRESULT WINAPI HTMLWindow6_get_sessionStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2019 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2021 FIXME("(%p)->(%p)\n", This, p);
2023 if(!This->inner_window->session_storage) {
2024 HRESULT hres;
2026 hres = create_storage(&This->inner_window->session_storage);
2027 if(FAILED(hres))
2028 return hres;
2031 IHTMLStorage_AddRef(This->inner_window->session_storage);
2032 *p = This->inner_window->session_storage;
2033 return S_OK;
2036 static HRESULT WINAPI HTMLWindow6_get_localStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2038 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2039 FIXME("(%p)->(%p)\n", This, p);
2040 return E_NOTIMPL;
2043 static HRESULT WINAPI HTMLWindow6_put_onhashchange(IHTMLWindow6 *iface, VARIANT v)
2045 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2046 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2047 return E_NOTIMPL;
2050 static HRESULT WINAPI HTMLWindow6_get_onhashchange(IHTMLWindow6 *iface, VARIANT *p)
2052 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2053 FIXME("(%p)->(%p)\n", This, p);
2054 return E_NOTIMPL;
2057 static HRESULT WINAPI HTMLWindow6_get_maxConnectionsPerServer(IHTMLWindow6 *iface, LONG *p)
2059 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2060 FIXME("(%p)->(%p)\n", This, p);
2061 return E_NOTIMPL;
2064 static HRESULT WINAPI HTMLWindow6_postMessage(IHTMLWindow6 *iface, BSTR msg, VARIANT targetOrigin)
2066 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2067 FIXME("(%p)->(%s %s)\n", This, debugstr_w(msg), debugstr_variant(&targetOrigin));
2068 return E_NOTIMPL;
2071 static HRESULT WINAPI HTMLWindow6_toStaticHTML(IHTMLWindow6 *iface, BSTR bstrHTML, BSTR *pbstrStaticHTML)
2073 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2074 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrHTML), pbstrStaticHTML);
2075 return E_NOTIMPL;
2078 static HRESULT WINAPI HTMLWindow6_put_onmessage(IHTMLWindow6 *iface, VARIANT v)
2080 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2081 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2082 return E_NOTIMPL;
2085 static HRESULT WINAPI HTMLWindow6_get_onmessage(IHTMLWindow6 *iface, VARIANT *p)
2087 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2088 FIXME("(%p)->(%p)\n", This, p);
2089 return E_NOTIMPL;
2092 static HRESULT WINAPI HTMLWindow6_msWriteProfilerMark(IHTMLWindow6 *iface, BSTR bstrProfilerMark)
2094 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2095 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrProfilerMark));
2096 return E_NOTIMPL;
2099 static const IHTMLWindow6Vtbl HTMLWindow6Vtbl = {
2100 HTMLWindow6_QueryInterface,
2101 HTMLWindow6_AddRef,
2102 HTMLWindow6_Release,
2103 HTMLWindow6_GetTypeInfoCount,
2104 HTMLWindow6_GetTypeInfo,
2105 HTMLWindow6_GetIDsOfNames,
2106 HTMLWindow6_Invoke,
2107 HTMLWindow6_put_XDomainRequest,
2108 HTMLWindow6_get_XDomainRequest,
2109 HTMLWindow6_get_sessionStorage,
2110 HTMLWindow6_get_localStorage,
2111 HTMLWindow6_put_onhashchange,
2112 HTMLWindow6_get_onhashchange,
2113 HTMLWindow6_get_maxConnectionsPerServer,
2114 HTMLWindow6_postMessage,
2115 HTMLWindow6_toStaticHTML,
2116 HTMLWindow6_put_onmessage,
2117 HTMLWindow6_get_onmessage,
2118 HTMLWindow6_msWriteProfilerMark
2121 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
2123 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
2126 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
2128 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2130 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2133 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
2135 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2137 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2140 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
2142 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2144 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2147 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
2148 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
2150 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2151 HTMLOuterWindow *window = This->outer_window;
2152 OLECHAR *translated_url = NULL;
2153 DWORD post_data_size = 0;
2154 BYTE *post_data = NULL;
2155 WCHAR *headers = NULL;
2156 IUri *uri;
2157 HRESULT hres;
2159 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
2160 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
2162 if(window->doc_obj->hostui) {
2163 hres = IDocHostUIHandler_TranslateUrl(window->doc_obj->hostui, 0, url, &translated_url);
2164 if(hres != S_OK)
2165 translated_url = NULL;
2168 hres = create_uri(translated_url ? translated_url : url, 0, &uri);
2169 CoTaskMemFree(translated_url);
2170 if(FAILED(hres))
2171 return hres;
2173 if(post_data_var) {
2174 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
2175 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
2176 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
2180 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
2181 if(V_VT(headers_var) != VT_BSTR)
2182 return E_INVALIDARG;
2184 headers = V_BSTR(headers_var);
2187 hres = super_navigate(window, uri, BINDING_NAVIGATED|BINDING_NOFRAG, headers, post_data, post_data_size);
2188 IUri_Release(uri);
2189 if(post_data)
2190 SafeArrayUnaccessData(V_ARRAY(post_data_var));
2192 return hres;
2195 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
2197 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2198 FIXME("(%p)->(%p)\n", This, url);
2199 return E_NOTIMPL;
2202 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
2204 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2205 FIXME("(%p)->(%p)\n", This, cmdtrg);
2206 return E_NOTIMPL;
2209 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
2211 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2212 FIXME("(%p)->(%x)\n", This, arg);
2213 return E_NOTIMPL;
2216 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
2218 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2219 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
2220 return E_NOTIMPL;
2223 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBarUrl(IHTMLPrivateWindow *iface, BSTR *url)
2225 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2226 TRACE("(%p)->(%p)\n", This, url);
2228 if(!url)
2229 return E_INVALIDARG;
2231 *url = SysAllocString(This->outer_window->url);
2232 return S_OK;
2235 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
2236 HTMLPrivateWindow_QueryInterface,
2237 HTMLPrivateWindow_AddRef,
2238 HTMLPrivateWindow_Release,
2239 HTMLPrivateWindow_SuperNavigate,
2240 HTMLPrivateWindow_GetPendingUrl,
2241 HTMLPrivateWindow_SetPICSTarget,
2242 HTMLPrivateWindow_PICSComplete,
2243 HTMLPrivateWindow_FindWindowByName,
2244 HTMLPrivateWindow_GetAddressBarUrl
2247 static inline HTMLWindow *impl_from_ITravelLogClient(ITravelLogClient *iface)
2249 return CONTAINING_RECORD(iface, HTMLWindow, ITravelLogClient_iface);
2252 static HRESULT WINAPI TravelLogClient_QueryInterface(ITravelLogClient *iface, REFIID riid, void **ppv)
2254 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2256 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2259 static ULONG WINAPI TravelLogClient_AddRef(ITravelLogClient *iface)
2261 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2263 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2266 static ULONG WINAPI TravelLogClient_Release(ITravelLogClient *iface)
2268 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2270 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2273 static HRESULT WINAPI TravelLogClient_FindWindowByIndex(ITravelLogClient *iface, DWORD dwID, IUnknown **ppunk)
2275 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2277 FIXME("(%p)->(%d %p) semi-stub\n", This, dwID, ppunk);
2279 *ppunk = NULL;
2280 return E_FAIL;
2283 static HRESULT WINAPI TravelLogClient_GetWindowData(ITravelLogClient *iface, IStream *pStream, LPWINDOWDATA pWinData)
2285 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2286 FIXME("(%p)->(%p %p)\n", This, pStream, pWinData);
2287 return E_NOTIMPL;
2290 static HRESULT WINAPI TravelLogClient_LoadHistoryPosition(ITravelLogClient *iface, LPWSTR pszUrlLocation, DWORD dwPosition)
2292 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2293 FIXME("(%p)->(%s %d)\n", This, debugstr_w(pszUrlLocation), dwPosition);
2294 return E_NOTIMPL;
2297 static const ITravelLogClientVtbl TravelLogClientVtbl = {
2298 TravelLogClient_QueryInterface,
2299 TravelLogClient_AddRef,
2300 TravelLogClient_Release,
2301 TravelLogClient_FindWindowByIndex,
2302 TravelLogClient_GetWindowData,
2303 TravelLogClient_LoadHistoryPosition
2306 static inline HTMLWindow *impl_from_IObjectIdentity(IObjectIdentity *iface)
2308 return CONTAINING_RECORD(iface, HTMLWindow, IObjectIdentity_iface);
2311 static HRESULT WINAPI ObjectIdentity_QueryInterface(IObjectIdentity *iface, REFIID riid, void **ppv)
2313 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2315 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2318 static ULONG WINAPI ObjectIdentity_AddRef(IObjectIdentity *iface)
2320 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2322 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2325 static ULONG WINAPI ObjectIdentity_Release(IObjectIdentity *iface)
2327 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2329 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2332 static HRESULT WINAPI ObjectIdentity_IsEqualObject(IObjectIdentity *iface, IUnknown *unk)
2334 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2335 IServiceProvider *sp;
2336 HRESULT hres;
2338 TRACE("(%p)->(%p)\n", This, unk);
2340 hres = IUnknown_QueryInterface(unk, &IID_IServiceProvider, (void**)&sp);
2341 if(hres != S_OK)
2342 return hres;
2344 hres = &This->inner_window->base.IServiceProvider_iface==sp ||
2345 &This->outer_window->base.IServiceProvider_iface==sp ? S_OK : S_FALSE;
2346 IServiceProvider_Release(sp);
2347 return hres;
2350 static const IObjectIdentityVtbl ObjectIdentityVtbl = {
2351 ObjectIdentity_QueryInterface,
2352 ObjectIdentity_AddRef,
2353 ObjectIdentity_Release,
2354 ObjectIdentity_IsEqualObject
2357 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
2359 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
2362 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
2364 HTMLWindow *This = impl_from_IDispatchEx(iface);
2366 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2369 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
2371 HTMLWindow *This = impl_from_IDispatchEx(iface);
2373 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2376 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
2378 HTMLWindow *This = impl_from_IDispatchEx(iface);
2380 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2383 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
2385 HTMLWindow *This = impl_from_IDispatchEx(iface);
2387 TRACE("(%p)->(%p)\n", This, pctinfo);
2389 return IDispatchEx_GetTypeInfoCount(&This->inner_window->dispex.IDispatchEx_iface, pctinfo);
2392 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
2393 LCID lcid, ITypeInfo **ppTInfo)
2395 HTMLWindow *This = impl_from_IDispatchEx(iface);
2397 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2399 return IDispatchEx_GetTypeInfo(&This->inner_window->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2402 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
2403 LPOLESTR *rgszNames, UINT cNames,
2404 LCID lcid, DISPID *rgDispId)
2406 HTMLWindow *This = impl_from_IDispatchEx(iface);
2407 UINT i;
2408 HRESULT hres;
2410 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2412 for(i=0; i < cNames; i++) {
2413 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
2414 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
2415 if(FAILED(hres))
2416 return hres;
2419 return S_OK;
2422 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
2423 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2424 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2426 HTMLWindow *This = impl_from_IDispatchEx(iface);
2428 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2429 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2431 /* FIXME: Use script dispatch */
2433 return IDispatchEx_Invoke(&This->inner_window->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2434 pDispParams, pVarResult, pExcepInfo, puArgErr);
2437 static global_prop_t *alloc_global_prop(HTMLInnerWindow *This, global_prop_type_t type, BSTR name)
2439 if(This->global_prop_cnt == This->global_prop_size) {
2440 global_prop_t *new_props;
2441 DWORD new_size;
2443 if(This->global_props) {
2444 new_size = This->global_prop_size*2;
2445 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
2446 }else {
2447 new_size = 16;
2448 new_props = heap_alloc(new_size*sizeof(global_prop_t));
2450 if(!new_props)
2451 return NULL;
2452 This->global_props = new_props;
2453 This->global_prop_size = new_size;
2456 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
2457 if(!This->global_props[This->global_prop_cnt].name)
2458 return NULL;
2460 This->global_props[This->global_prop_cnt].type = type;
2461 return This->global_props + This->global_prop_cnt++;
2464 static inline DWORD prop_to_dispid(HTMLInnerWindow *This, global_prop_t *prop)
2466 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
2469 HRESULT search_window_props(HTMLInnerWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
2471 DWORD i;
2472 ScriptHost *script_host;
2473 DISPID id;
2475 for(i=0; i < This->global_prop_cnt; i++) {
2476 /* FIXME: case sensitivity */
2477 if(!strcmpW(This->global_props[i].name, bstrName)) {
2478 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
2479 return S_OK;
2483 if(find_global_prop(This->base.inner_window, bstrName, grfdex, &script_host, &id)) {
2484 global_prop_t *prop;
2486 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
2487 if(!prop)
2488 return E_OUTOFMEMORY;
2490 prop->script_host = script_host;
2491 prop->id = id;
2493 *pid = prop_to_dispid(This, prop);
2494 return S_OK;
2497 return DISP_E_UNKNOWNNAME;
2500 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
2502 HTMLWindow *This = impl_from_IDispatchEx(iface);
2503 HTMLInnerWindow *window = This->inner_window;
2504 HRESULT hres;
2506 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
2508 hres = search_window_props(window, bstrName, grfdex, pid);
2509 if(hres != DISP_E_UNKNOWNNAME)
2510 return hres;
2512 hres = IDispatchEx_GetDispID(&window->base.inner_window->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
2513 if(hres != DISP_E_UNKNOWNNAME)
2514 return hres;
2516 if(This->outer_window) {
2517 HTMLOuterWindow *frame;
2519 hres = get_frame_by_name(This->outer_window, bstrName, FALSE, &frame);
2520 if(SUCCEEDED(hres) && frame) {
2521 global_prop_t *prop;
2523 IHTMLWindow2_Release(&frame->base.IHTMLWindow2_iface);
2525 prop = alloc_global_prop(window, GLOBAL_FRAMEVAR, bstrName);
2526 if(!prop)
2527 return E_OUTOFMEMORY;
2529 *pid = prop_to_dispid(window, prop);
2530 return S_OK;
2534 if(window->doc) {
2535 global_prop_t *prop;
2536 IHTMLElement *elem;
2538 hres = IHTMLDocument3_getElementById(&window->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
2539 bstrName, &elem);
2540 if(SUCCEEDED(hres) && elem) {
2541 IHTMLElement_Release(elem);
2543 prop = alloc_global_prop(window, GLOBAL_ELEMENTVAR, bstrName);
2544 if(!prop)
2545 return E_OUTOFMEMORY;
2547 *pid = prop_to_dispid(window, prop);
2548 return S_OK;
2552 return DISP_E_UNKNOWNNAME;
2555 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2556 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2558 HTMLWindow *This = impl_from_IDispatchEx(iface);
2559 HTMLInnerWindow *window = This->inner_window;
2561 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2563 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
2564 HTMLLocation *location;
2565 HRESULT hres;
2567 TRACE("forwarding to location.href\n");
2569 hres = get_location(window, &location);
2570 if(FAILED(hres))
2571 return hres;
2573 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2574 wFlags, pdp, pvarRes, pei, pspCaller);
2575 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2576 return hres;
2579 return IDispatchEx_InvokeEx(&window->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2582 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2584 HTMLWindow *This = impl_from_IDispatchEx(iface);
2586 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2588 return IDispatchEx_DeleteMemberByName(&This->inner_window->dispex.IDispatchEx_iface, bstrName, grfdex);
2591 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2593 HTMLWindow *This = impl_from_IDispatchEx(iface);
2595 TRACE("(%p)->(%x)\n", This, id);
2597 return IDispatchEx_DeleteMemberByDispID(&This->inner_window->dispex.IDispatchEx_iface, id);
2600 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2602 HTMLWindow *This = impl_from_IDispatchEx(iface);
2604 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2606 return IDispatchEx_GetMemberProperties(&This->inner_window->dispex.IDispatchEx_iface, id, grfdexFetch,
2607 pgrfdex);
2610 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2612 HTMLWindow *This = impl_from_IDispatchEx(iface);
2614 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2616 return IDispatchEx_GetMemberName(&This->inner_window->dispex.IDispatchEx_iface, id, pbstrName);
2619 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2621 HTMLWindow *This = impl_from_IDispatchEx(iface);
2623 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2625 return IDispatchEx_GetNextDispID(&This->inner_window->dispex.IDispatchEx_iface, grfdex, id, pid);
2628 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2630 HTMLWindow *This = impl_from_IDispatchEx(iface);
2632 TRACE("(%p)->(%p)\n", This, ppunk);
2634 *ppunk = NULL;
2635 return S_OK;
2638 static const IDispatchExVtbl WindowDispExVtbl = {
2639 WindowDispEx_QueryInterface,
2640 WindowDispEx_AddRef,
2641 WindowDispEx_Release,
2642 WindowDispEx_GetTypeInfoCount,
2643 WindowDispEx_GetTypeInfo,
2644 WindowDispEx_GetIDsOfNames,
2645 WindowDispEx_Invoke,
2646 WindowDispEx_GetDispID,
2647 WindowDispEx_InvokeEx,
2648 WindowDispEx_DeleteMemberByName,
2649 WindowDispEx_DeleteMemberByDispID,
2650 WindowDispEx_GetMemberProperties,
2651 WindowDispEx_GetMemberName,
2652 WindowDispEx_GetNextDispID,
2653 WindowDispEx_GetNameSpaceParent
2656 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2658 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2661 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2663 HTMLWindow *This = impl_from_IServiceProvider(iface);
2664 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2667 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2669 HTMLWindow *This = impl_from_IServiceProvider(iface);
2670 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2673 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2675 HTMLWindow *This = impl_from_IServiceProvider(iface);
2676 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2679 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2681 HTMLWindow *This = impl_from_IServiceProvider(iface);
2683 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2684 TRACE("IID_IHTMLWindow2\n");
2685 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2688 TRACE("(%p)->(%s %s %p)\n", This, debugstr_mshtml_guid(guidService), debugstr_mshtml_guid(riid), ppv);
2690 if(!This->outer_window->doc_obj)
2691 return E_NOINTERFACE;
2693 return IServiceProvider_QueryService(&This->outer_window->doc_obj->basedoc.IServiceProvider_iface,
2694 guidService, riid, ppv);
2697 static const IServiceProviderVtbl ServiceProviderVtbl = {
2698 HTMLWindowSP_QueryInterface,
2699 HTMLWindowSP_AddRef,
2700 HTMLWindowSP_Release,
2701 HTMLWindowSP_QueryService
2704 static inline HTMLInnerWindow *impl_from_DispatchEx(DispatchEx *iface)
2706 return CONTAINING_RECORD(iface, HTMLInnerWindow, dispex);
2709 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2710 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2712 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
2713 global_prop_t *prop;
2714 DWORD idx;
2715 HRESULT hres;
2717 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2718 if(idx >= This->global_prop_cnt)
2719 return DISP_E_MEMBERNOTFOUND;
2721 prop = This->global_props+idx;
2723 switch(prop->type) {
2724 case GLOBAL_SCRIPTVAR: {
2725 IDispatchEx *iface;
2726 IDispatch *disp;
2728 disp = get_script_disp(prop->script_host);
2729 if(!disp)
2730 return E_UNEXPECTED;
2732 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2733 if(SUCCEEDED(hres)) {
2734 TRACE("%s >>>\n", debugstr_w(prop->name));
2735 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2736 if(hres == S_OK)
2737 TRACE("%s <<<\n", debugstr_w(prop->name));
2738 else
2739 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2740 IDispatchEx_Release(iface);
2741 }else {
2742 FIXME("No IDispatchEx\n");
2744 IDispatch_Release(disp);
2745 break;
2747 case GLOBAL_ELEMENTVAR:
2748 switch(flags) {
2749 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
2750 case DISPATCH_PROPERTYGET: {
2751 IHTMLElement *elem;
2753 hres = IHTMLDocument3_getElementById(&This->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
2754 prop->name, &elem);
2755 if(FAILED(hres))
2756 return hres;
2758 if(!elem)
2759 return DISP_E_MEMBERNOTFOUND;
2761 V_VT(res) = VT_DISPATCH;
2762 V_DISPATCH(res) = (IDispatch*)elem;
2763 return S_OK;
2765 case DISPATCH_PROPERTYPUT: {
2766 DISPID dispex_id;
2768 hres = dispex_get_dynid(&This->dispex, prop->name, &dispex_id);
2769 if(FAILED(hres))
2770 return hres;
2772 prop->type = GLOBAL_DISPEXVAR;
2773 prop->id = dispex_id;
2774 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, dispex_id, 0, flags, params, res, ei, caller);
2776 default:
2777 FIXME("Not supported flags: %x\n", flags);
2778 return E_NOTIMPL;
2780 case GLOBAL_FRAMEVAR:
2781 if(!This->base.outer_window)
2782 return E_UNEXPECTED;
2784 switch(flags) {
2785 case DISPATCH_PROPERTYGET: {
2786 HTMLOuterWindow *frame;
2788 hres = get_frame_by_name(This->base.outer_window, prop->name, FALSE, &frame);
2789 if(FAILED(hres))
2790 return hres;
2792 if(!frame)
2793 return DISP_E_MEMBERNOTFOUND;
2795 V_VT(res) = VT_DISPATCH;
2796 V_DISPATCH(res) = (IDispatch*)&frame->base.inner_window->base.IHTMLWindow2_iface;
2797 IDispatch_AddRef(V_DISPATCH(res));
2798 return S_OK;
2800 default:
2801 FIXME("Not supported flags: %x\n", flags);
2802 return E_NOTIMPL;
2804 case GLOBAL_DISPEXVAR:
2805 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, prop->id, 0, flags, params, res, ei, caller);
2806 default:
2807 ERR("invalid type %d\n", prop->type);
2808 hres = DISP_E_MEMBERNOTFOUND;
2811 return hres;
2815 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2816 NULL,
2817 NULL,
2818 HTMLWindow_invoke,
2819 NULL
2822 static const tid_t HTMLWindow_iface_tids[] = {
2823 IHTMLWindow2_tid,
2824 IHTMLWindow3_tid,
2825 IHTMLWindow4_tid,
2826 IHTMLWindow6_tid,
2830 static dispex_static_data_t HTMLWindow_dispex = {
2831 &HTMLWindow_dispex_vtbl,
2832 DispHTMLWindow2_tid,
2833 NULL,
2834 HTMLWindow_iface_tids
2837 static void *alloc_window(size_t size)
2839 HTMLWindow *window;
2841 window = heap_alloc_zero(size);
2842 if(!window)
2843 return NULL;
2845 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2846 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2847 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2848 window->IHTMLWindow5_iface.lpVtbl = &HTMLWindow5Vtbl;
2849 window->IHTMLWindow6_iface.lpVtbl = &HTMLWindow6Vtbl;
2850 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2851 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2852 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2853 window->ITravelLogClient_iface.lpVtbl = &TravelLogClientVtbl;
2854 window->IObjectIdentity_iface.lpVtbl = &ObjectIdentityVtbl;
2855 window->ref = 1;
2857 return window;
2860 static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, HTMLInnerWindow **ret)
2862 HTMLInnerWindow *window;
2864 window = alloc_window(sizeof(HTMLInnerWindow));
2865 if(!window)
2866 return E_OUTOFMEMORY;
2868 list_init(&window->script_hosts);
2869 list_init(&window->bindings);
2870 list_init(&window->script_queue);
2872 window->base.outer_window = outer_window;
2873 window->base.inner_window = window;
2875 init_dispex(&window->dispex, (IUnknown*)&window->base.IHTMLWindow2_iface, &HTMLWindow_dispex);
2877 window->task_magic = get_task_target_magic();
2879 if(mon) {
2880 IMoniker_AddRef(mon);
2881 window->mon = mon;
2884 *ret = window;
2885 return S_OK;
2888 HRESULT HTMLOuterWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow,
2889 HTMLOuterWindow *parent, HTMLOuterWindow **ret)
2891 HTMLOuterWindow *window;
2892 HRESULT hres;
2894 window = alloc_window(sizeof(HTMLOuterWindow));
2895 if(!window)
2896 return E_OUTOFMEMORY;
2898 window->base.outer_window = window;
2899 window->base.inner_window = NULL;
2901 window->window_ref = heap_alloc(sizeof(windowref_t));
2902 if(!window->window_ref) {
2903 heap_free(window);
2904 return E_OUTOFMEMORY;
2907 window->doc_obj = doc_obj;
2909 window->window_ref->window = window;
2910 window->window_ref->ref = 1;
2912 if(nswindow) {
2913 nsIDOMWindow_AddRef(nswindow);
2914 window->nswindow = nswindow;
2917 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2918 window->readystate = READYSTATE_UNINITIALIZED;
2920 hres = create_pending_window(window, NULL);
2921 if(SUCCEEDED(hres))
2922 hres = update_window_doc(window->pending_window);
2923 if(FAILED(hres)) {
2924 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
2925 return hres;
2928 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
2929 if(FAILED(hres)) {
2930 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
2931 return hres;
2934 window->task_magic = get_task_target_magic();
2936 list_init(&window->children);
2937 list_add_head(&window_list, &window->entry);
2939 if(parent) {
2940 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
2942 window->parent = parent;
2943 list_add_tail(&parent->children, &window->sibling_entry);
2946 TRACE("%p inner_window %p\n", window, window->base.inner_window);
2948 *ret = window;
2949 return S_OK;
2952 HRESULT create_pending_window(HTMLOuterWindow *outer_window, nsChannelBSC *channelbsc)
2954 HTMLInnerWindow *pending_window;
2955 HRESULT hres;
2957 hres = create_inner_window(outer_window, outer_window->mon /* FIXME */, &pending_window);
2958 if(FAILED(hres))
2959 return hres;
2961 if(channelbsc) {
2962 IBindStatusCallback_AddRef(&channelbsc->bsc.IBindStatusCallback_iface);
2963 pending_window->bscallback = channelbsc;
2966 if(outer_window->pending_window) {
2967 abort_window_bindings(outer_window->pending_window);
2968 outer_window->pending_window->base.outer_window = NULL;
2969 IHTMLWindow2_Release(&outer_window->pending_window->base.IHTMLWindow2_iface);
2972 outer_window->pending_window = pending_window;
2973 return S_OK;
2976 HRESULT update_window_doc(HTMLInnerWindow *window)
2978 HTMLOuterWindow *outer_window = window->base.outer_window;
2979 nsIDOMHTMLDocument *nshtmldoc;
2980 nsIDOMDocument *nsdoc;
2981 nsresult nsres;
2982 HRESULT hres;
2984 assert(!window->doc);
2986 if(!outer_window) {
2987 ERR("NULL outer window\n");
2988 return E_UNEXPECTED;
2991 nsres = nsIDOMWindow_GetDocument(outer_window->nswindow, &nsdoc);
2992 if(NS_FAILED(nsres) || !nsdoc) {
2993 ERR("GetDocument failed: %08x\n", nsres);
2994 return E_FAIL;
2997 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2998 nsIDOMDocument_Release(nsdoc);
2999 if(NS_FAILED(nsres)) {
3000 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
3001 return E_FAIL;
3004 hres = create_doc_from_nsdoc(nshtmldoc, outer_window->doc_obj, window, &window->doc);
3005 nsIDOMHTMLDocument_Release(nshtmldoc);
3006 if(FAILED(hres))
3007 return hres;
3009 if(outer_window->doc_obj->usermode == EDITMODE) {
3010 nsAString mode_str;
3011 nsresult nsres;
3013 static const PRUnichar onW[] = {'o','n',0};
3015 nsAString_InitDepend(&mode_str, onW);
3016 nsres = nsIDOMHTMLDocument_SetDesignMode(window->doc->nsdoc, &mode_str);
3017 nsAString_Finish(&mode_str);
3018 if(NS_FAILED(nsres))
3019 ERR("SetDesignMode failed: %08x\n", nsres);
3022 if(window != outer_window->pending_window) {
3023 ERR("not current pending window\n");
3024 return S_OK;
3027 if(outer_window->base.inner_window)
3028 detach_inner_window(outer_window->base.inner_window);
3029 outer_window->base.inner_window = window;
3030 outer_window->pending_window = NULL;
3032 if(outer_window->doc_obj->basedoc.window == outer_window || !outer_window->doc_obj->basedoc.window) {
3033 if(outer_window->doc_obj->basedoc.doc_node)
3034 htmldoc_release(&outer_window->doc_obj->basedoc.doc_node->basedoc);
3035 outer_window->doc_obj->basedoc.doc_node = window->doc;
3036 htmldoc_addref(&window->doc->basedoc);
3039 return hres;
3042 HTMLOuterWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
3044 HTMLOuterWindow *iter;
3046 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLOuterWindow, entry) {
3047 if(iter->nswindow == nswindow)
3048 return iter;
3051 return NULL;