mshtml: Pass proper JSContext to nsIDOMHTMLDocument::Write and Open.
[wine.git] / dlls / mshtml / htmldoc.c
blob8b5a16089e8543223c78318841e304c566485b3d
1 /*
2 * Copyright 2005-2009 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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <assert.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wininet.h"
31 #include "ole2.h"
32 #include "perhist.h"
33 #include "mshtmdid.h"
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
38 #include "htmlevent.h"
39 #include "pluginhost.h"
40 #include "binding.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
44 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
46 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
49 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
51 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
53 return htmldoc_query_interface(This, riid, ppv);
56 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
58 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
60 return htmldoc_addref(This);
63 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
65 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
67 return htmldoc_release(This);
70 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
72 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
74 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
77 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
78 LCID lcid, ITypeInfo **ppTInfo)
80 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
82 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
85 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
89 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
91 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
92 rgDispId);
95 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
96 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
97 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
99 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
101 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
102 pDispParams, pVarResult, pExcepInfo, puArgErr);
105 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
107 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
109 TRACE("(%p)->(%p)\n", This, p);
111 *p = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
112 IDispatch_AddRef(*p);
113 return S_OK;
116 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
118 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
119 nsIDOMElement *nselem = NULL;
120 HTMLDOMNode *node;
121 nsresult nsres;
122 HRESULT hres;
124 TRACE("(%p)->(%p)\n", This, p);
126 if(!This->doc_node->nsdoc) {
127 WARN("NULL nsdoc\n");
128 return E_UNEXPECTED;
131 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
132 if(NS_FAILED(nsres)) {
133 ERR("GetDocumentElement failed: %08x\n", nsres);
134 return E_FAIL;
137 if(!nselem) {
138 *p = NULL;
139 return S_OK;
142 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
143 nsIDOMElement_Release(nselem);
144 if(FAILED(hres))
145 return hres;
147 *p = create_all_collection(node, TRUE);
148 node_release(node);
149 return hres;
152 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
154 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
155 nsIDOMHTMLElement *nsbody = NULL;
156 HTMLDOMNode *node;
157 HRESULT hres;
159 TRACE("(%p)->(%p)\n", This, p);
161 if(This->doc_node->nsdoc) {
162 nsresult nsres;
164 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
165 if(NS_FAILED(nsres)) {
166 TRACE("Could not get body: %08x\n", nsres);
167 return E_UNEXPECTED;
171 if(!nsbody) {
172 *p = NULL;
173 return S_OK;
176 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
177 nsIDOMHTMLElement_Release(nsbody);
178 if(FAILED(hres))
179 return hres;
181 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
182 node_release(node);
183 return hres;
186 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
189 FIXME("(%p)->(%p)\n", This, p);
190 return E_NOTIMPL;
193 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
195 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
196 nsIDOMHTMLCollection *nscoll = NULL;
197 nsresult nsres;
199 TRACE("(%p)->(%p)\n", This, p);
201 if(!p)
202 return E_INVALIDARG;
204 *p = NULL;
206 if(!This->doc_node->nsdoc) {
207 WARN("NULL nsdoc\n");
208 return E_UNEXPECTED;
211 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
212 if(NS_FAILED(nsres)) {
213 ERR("GetImages failed: %08x\n", nsres);
214 return E_FAIL;
217 if(nscoll) {
218 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
219 nsIDOMHTMLCollection_Release(nscoll);
222 return S_OK;
225 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
227 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
228 nsIDOMHTMLCollection *nscoll = NULL;
229 nsresult nsres;
231 TRACE("(%p)->(%p)\n", This, p);
233 if(!p)
234 return E_INVALIDARG;
236 *p = NULL;
238 if(!This->doc_node->nsdoc) {
239 WARN("NULL nsdoc\n");
240 return E_UNEXPECTED;
243 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
244 if(NS_FAILED(nsres)) {
245 ERR("GetApplets failed: %08x\n", nsres);
246 return E_FAIL;
249 if(nscoll) {
250 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
251 nsIDOMHTMLCollection_Release(nscoll);
254 return S_OK;
257 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
259 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
260 nsIDOMHTMLCollection *nscoll = NULL;
261 nsresult nsres;
263 TRACE("(%p)->(%p)\n", This, p);
265 if(!p)
266 return E_INVALIDARG;
268 *p = NULL;
270 if(!This->doc_node->nsdoc) {
271 WARN("NULL nsdoc\n");
272 return E_UNEXPECTED;
275 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
276 if(NS_FAILED(nsres)) {
277 ERR("GetLinks failed: %08x\n", nsres);
278 return E_FAIL;
281 if(nscoll) {
282 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
283 nsIDOMHTMLCollection_Release(nscoll);
286 return S_OK;
289 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
291 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
292 nsIDOMHTMLCollection *nscoll = NULL;
293 nsresult nsres;
295 TRACE("(%p)->(%p)\n", This, p);
297 if(!p)
298 return E_INVALIDARG;
300 *p = NULL;
302 if(!This->doc_node->nsdoc) {
303 WARN("NULL nsdoc\n");
304 return E_UNEXPECTED;
307 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
308 if(NS_FAILED(nsres)) {
309 ERR("GetForms failed: %08x\n", nsres);
310 return E_FAIL;
313 if(nscoll) {
314 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
315 nsIDOMHTMLCollection_Release(nscoll);
318 return S_OK;
321 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
323 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
324 nsIDOMHTMLCollection *nscoll = NULL;
325 nsresult nsres;
327 TRACE("(%p)->(%p)\n", This, p);
329 if(!p)
330 return E_INVALIDARG;
332 *p = NULL;
334 if(!This->doc_node->nsdoc) {
335 WARN("NULL nsdoc\n");
336 return E_UNEXPECTED;
339 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
340 if(NS_FAILED(nsres)) {
341 ERR("GetAnchors failed: %08x\n", nsres);
342 return E_FAIL;
345 if(nscoll) {
346 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
347 nsIDOMHTMLCollection_Release(nscoll);
350 return S_OK;
353 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
355 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
356 nsAString nsstr;
357 nsresult nsres;
359 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
361 if(!This->doc_node->nsdoc) {
362 WARN("NULL nsdoc\n");
363 return E_UNEXPECTED;
366 nsAString_InitDepend(&nsstr, v);
367 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
368 nsAString_Finish(&nsstr);
369 if(NS_FAILED(nsres))
370 ERR("SetTitle failed: %08x\n", nsres);
372 return S_OK;
375 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
377 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
378 const PRUnichar *ret;
379 nsAString nsstr;
380 nsresult nsres;
382 TRACE("(%p)->(%p)\n", This, p);
384 if(!This->doc_node->nsdoc) {
385 WARN("NULL nsdoc\n");
386 return E_UNEXPECTED;
390 nsAString_Init(&nsstr, NULL);
391 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
392 if (NS_SUCCEEDED(nsres)) {
393 nsAString_GetData(&nsstr, &ret);
394 *p = SysAllocString(ret);
396 nsAString_Finish(&nsstr);
398 if(NS_FAILED(nsres)) {
399 ERR("GetTitle failed: %08x\n", nsres);
400 return E_FAIL;
403 return S_OK;
406 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
408 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
409 FIXME("(%p)->(%p)\n", This, p);
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
415 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
416 HRESULT hres;
418 static const WCHAR onW[] = {'o','n',0};
420 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
422 if(strcmpiW(v, onW)) {
423 FIXME("Unsupported arg %s\n", debugstr_w(v));
424 return E_NOTIMPL;
427 hres = setup_edit_mode(This->doc_obj);
428 if(FAILED(hres))
429 return hres;
431 call_property_onchanged(&This->cp_container, 1014);
432 return S_OK;
435 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
437 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
438 static WCHAR szOff[] = {'O','f','f',0};
439 FIXME("(%p)->(%p) always returning Off\n", This, p);
441 if(!p)
442 return E_INVALIDARG;
444 *p = SysAllocString(szOff);
446 return S_OK;
449 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
451 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
452 nsISelection *nsselection;
453 nsresult nsres;
455 TRACE("(%p)->(%p)\n", This, p);
457 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
458 if(NS_FAILED(nsres)) {
459 ERR("GetSelection failed: %08x\n", nsres);
460 return E_FAIL;
463 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
466 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
468 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
470 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
471 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
472 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
473 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
474 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
476 static const LPCWSTR readystate_str[] = {
477 wszUninitialized,
478 wszLoading,
479 wszLoaded,
480 wszInteractive,
481 wszComplete
484 TRACE("(%p)->(%p)\n", iface, p);
486 if(!p)
487 return E_POINTER;
489 *p = SysAllocString(readystate_str[This->window->readystate]);
490 return S_OK;
493 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
495 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
497 TRACE("(%p)->(%p)\n", This, p);
499 return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
502 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
504 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
505 FIXME("(%p)->(%p)\n", This, p);
506 return E_NOTIMPL;
509 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
511 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
512 FIXME("(%p)->(%p)\n", This, p);
513 return E_NOTIMPL;
516 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
518 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
519 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
520 return E_NOTIMPL;
523 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
525 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
526 FIXME("(%p)->(%p)\n", This, p);
527 return E_NOTIMPL;
530 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
532 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
533 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
534 return E_NOTIMPL;
537 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
539 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
540 FIXME("(%p)->(%p)\n", This, p);
541 return E_NOTIMPL;
544 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
546 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
547 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
548 return E_NOTIMPL;
551 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
553 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
554 FIXME("(%p)->(%p)\n", This, p);
555 return E_NOTIMPL;
558 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
560 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
561 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
562 return E_NOTIMPL;
565 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
567 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
569 return E_NOTIMPL;
572 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
574 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
575 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
576 return E_NOTIMPL;
579 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
581 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
582 FIXME("(%p)->(%p)\n", This, p);
583 return E_NOTIMPL;
586 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
588 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
590 FIXME("(%p)->(%p)\n", This, p);
592 *p = NULL;
593 return S_OK;
596 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
598 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
600 TRACE("(%p)->(%p)\n", This, p);
602 if(!This->doc_node->nsdoc) {
603 WARN("NULL nsdoc\n");
604 return E_UNEXPECTED;
607 return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
610 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
612 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
613 FIXME("(%p)->(%p)\n", This, p);
614 return E_NOTIMPL;
617 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
619 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
621 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
623 if(!This->window) {
624 FIXME("No window available\n");
625 return E_FAIL;
628 return navigate_url(This->window, v, This->window->uri, BINDING_NAVIGATED);
631 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
633 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
635 static const WCHAR about_blank_url[] =
636 {'a','b','o','u','t',':','b','l','a','n','k',0};
638 TRACE("(%p)->(%p)\n", iface, p);
640 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
641 return *p ? S_OK : E_OUTOFMEMORY;
644 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
646 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
647 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
648 return E_NOTIMPL;
651 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
653 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
654 HRESULT hres;
656 TRACE("(%p)->(%p)\n", This, p);
658 if(!This->window || !This->window->uri) {
659 FIXME("No current URI\n");
660 return E_FAIL;
663 hres = IUri_GetHost(This->window->uri, p);
664 return FAILED(hres) ? hres : S_OK;
667 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
669 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
670 BOOL bret;
672 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
674 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
675 if(!bret) {
676 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
677 return HRESULT_FROM_WIN32(GetLastError());
680 return S_OK;
683 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
685 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
686 DWORD size;
687 BOOL bret;
689 TRACE("(%p)->(%p)\n", This, p);
691 size = 0;
692 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
693 if(!bret) {
694 switch(GetLastError()) {
695 case ERROR_INSUFFICIENT_BUFFER:
696 break;
697 case ERROR_NO_MORE_ITEMS:
698 *p = NULL;
699 return S_OK;
700 default:
701 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
702 return HRESULT_FROM_WIN32(GetLastError());
706 if(!size) {
707 *p = NULL;
708 return S_OK;
711 *p = SysAllocStringLen(NULL, size/sizeof(WCHAR)-1);
712 if(!*p)
713 return E_OUTOFMEMORY;
715 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
716 if(!bret) {
717 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
718 return E_FAIL;
721 return S_OK;
724 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
726 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
727 FIXME("(%p)->(%x)\n", This, v);
728 return E_NOTIMPL;
731 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
733 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
734 FIXME("(%p)->(%p)\n", This, p);
735 return E_NOTIMPL;
738 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
740 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
741 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
742 return E_NOTIMPL;
745 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
747 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
748 nsAString charset_str;
749 nsresult nsres;
751 TRACE("(%p)->(%p)\n", This, p);
753 if(!This->doc_node->nsdoc) {
754 FIXME("NULL nsdoc\n");
755 return E_FAIL;
758 nsAString_Init(&charset_str, NULL);
759 nsres = nsIDOMHTMLDocument_GetCharacterSet(This->doc_node->nsdoc, &charset_str);
760 return return_nsstr(nsres, &charset_str, p);
763 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
765 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
766 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
767 return E_NOTIMPL;
770 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
772 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
773 FIXME("(%p)->(%p)\n", This, p);
774 return E_NOTIMPL;
777 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
779 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
780 FIXME("(%p)->(%p)\n", This, p);
781 return E_NOTIMPL;
784 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
786 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
787 FIXME("(%p)->(%p)\n", This, p);
788 return E_NOTIMPL;
791 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
793 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
794 FIXME("(%p)->(%p)\n", This, p);
795 return E_NOTIMPL;
798 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
800 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
801 FIXME("(%p)->(%p)\n", This, p);
802 return E_NOTIMPL;
805 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
807 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
808 FIXME("(%p)->(%p)\n", This, p);
809 return E_NOTIMPL;
812 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
814 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
815 FIXME("(%p)->(%p)\n", This, p);
816 return E_NOTIMPL;
819 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
821 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
822 FIXME("(%p)->(%p)\n", This, p);
823 return E_NOTIMPL;
826 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
828 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
829 FIXME("(%p)->(%p)\n", This, p);
830 return E_NOTIMPL;
833 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
835 VARIANT *var, tmp;
836 JSContext *jsctx;
837 nsAString nsstr;
838 ULONG i, argc;
839 nsresult nsres;
840 HRESULT hres;
842 if(!This->doc_node->nsdoc) {
843 WARN("NULL nsdoc\n");
844 return E_UNEXPECTED;
847 if (!psarray)
848 return S_OK;
850 if(psarray->cDims != 1) {
851 FIXME("cDims=%d\n", psarray->cDims);
852 return E_INVALIDARG;
855 hres = SafeArrayAccessData(psarray, (void**)&var);
856 if(FAILED(hres)) {
857 WARN("SafeArrayAccessData failed: %08x\n", hres);
858 return hres;
861 V_VT(&tmp) = VT_EMPTY;
863 jsctx = get_context_from_document(This->doc_node->nsdoc);
864 argc = psarray->rgsabound[0].cElements;
865 for(i=0; i < argc; i++) {
866 if(V_VT(var+i) == VT_BSTR) {
867 nsAString_InitDepend(&nsstr, V_BSTR(var+i));
868 }else {
869 hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
870 if(FAILED(hres)) {
871 WARN("Could not convert %s to string\n", debugstr_variant(var+i));
872 break;
874 nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
877 if(!ln || i != argc-1)
878 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, jsctx);
879 else
880 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, jsctx);
881 nsAString_Finish(&nsstr);
882 if(V_VT(var+i) != VT_BSTR)
883 VariantClear(&tmp);
884 if(NS_FAILED(nsres)) {
885 ERR("Write failed: %08x\n", nsres);
886 hres = E_FAIL;
887 break;
891 SafeArrayUnaccessData(psarray);
893 return hres;
896 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
898 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
900 TRACE("(%p)->(%p)\n", iface, psarray);
902 return document_write(This, psarray, FALSE);
905 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
907 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
909 TRACE("(%p)->(%p)\n", This, psarray);
911 return document_write(This, psarray, TRUE);
914 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
915 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
917 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
918 nsISupports *tmp;
919 nsresult nsres;
921 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
923 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
924 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
926 if(!This->doc_node->nsdoc) {
927 ERR("!nsdoc\n");
928 return E_NOTIMPL;
931 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
932 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
933 FIXME("unsupported args\n");
935 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL,
936 get_context_from_document(This->doc_node->nsdoc), 0, &tmp);
937 if(NS_FAILED(nsres)) {
938 ERR("Open failed: %08x\n", nsres);
939 return E_FAIL;
942 if(tmp)
943 nsISupports_Release(tmp);
945 *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
946 IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
947 return S_OK;
950 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
952 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
953 nsresult nsres;
955 TRACE("(%p)\n", This);
957 if(!This->doc_node->nsdoc) {
958 ERR("!nsdoc\n");
959 return E_NOTIMPL;
962 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
963 if(NS_FAILED(nsres)) {
964 ERR("Close failed: %08x\n", nsres);
965 return E_FAIL;
968 return S_OK;
971 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
973 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
974 nsresult nsres;
976 TRACE("(%p)\n", This);
978 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
979 if(NS_FAILED(nsres)) {
980 ERR("Clear failed: %08x\n", nsres);
981 return E_FAIL;
984 return S_OK;
987 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
988 VARIANT_BOOL *pfRet)
990 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
991 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
992 return E_NOTIMPL;
995 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
996 VARIANT_BOOL *pfRet)
998 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
999 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1000 return E_NOTIMPL;
1003 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1004 VARIANT_BOOL *pfRet)
1006 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1007 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1008 return E_NOTIMPL;
1011 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1012 VARIANT_BOOL *pfRet)
1014 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1015 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1016 return E_NOTIMPL;
1019 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1020 BSTR *pfRet)
1022 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1023 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1024 return E_NOTIMPL;
1027 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1028 VARIANT *pfRet)
1030 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1031 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1032 return E_NOTIMPL;
1035 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1036 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1038 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1039 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
1040 return E_NOTIMPL;
1043 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1044 VARIANT_BOOL *pfRet)
1046 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1047 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1052 IHTMLElement **newElem)
1054 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1055 HTMLElement *elem;
1056 HRESULT hres;
1058 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1060 hres = create_element(This->doc_node, eTag, &elem);
1061 if(FAILED(hres))
1062 return hres;
1064 *newElem = &elem->IHTMLElement_iface;
1065 return S_OK;
1068 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1070 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1071 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1072 return E_NOTIMPL;
1075 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1077 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1079 return E_NOTIMPL;
1082 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1084 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1086 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1088 return set_doc_event(This, EVENTID_CLICK, &v);
1091 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1093 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1095 TRACE("(%p)->(%p)\n", This, p);
1097 return get_doc_event(This, EVENTID_CLICK, p);
1100 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1102 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1103 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1104 return E_NOTIMPL;
1107 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1109 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1110 FIXME("(%p)->(%p)\n", This, p);
1111 return E_NOTIMPL;
1114 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1116 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1118 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1120 return set_doc_event(This, EVENTID_KEYUP, &v);
1123 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1125 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1127 TRACE("(%p)->(%p)\n", This, p);
1129 return get_doc_event(This, EVENTID_KEYUP, p);
1132 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1134 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1136 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1138 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1141 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1143 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1145 TRACE("(%p)->(%p)\n", This, p);
1147 return get_doc_event(This, EVENTID_KEYDOWN, p);
1150 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1152 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1154 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1156 return set_doc_event(This, EVENTID_KEYPRESS, &v);
1159 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1161 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1163 TRACE("(%p)->(%p)\n", This, p);
1165 return get_doc_event(This, EVENTID_KEYPRESS, p);
1168 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1170 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1172 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1174 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1177 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1179 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1181 TRACE("(%p)->(%p)\n", This, p);
1183 return get_doc_event(This, EVENTID_MOUSEUP, p);
1186 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1190 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1192 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1195 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1197 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1199 TRACE("(%p)->(%p)\n", This, p);
1201 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1204 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1206 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1208 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1210 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1213 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1215 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1217 TRACE("(%p)->(%p)\n", This, p);
1219 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1222 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1224 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1226 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1228 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1231 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1233 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1235 TRACE("(%p)->(%p)\n", This, p);
1237 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1240 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1242 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1244 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1246 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1249 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1251 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1253 TRACE("(%p)->(%p)\n", This, p);
1255 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1258 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1260 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1262 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1264 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1267 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1269 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1271 TRACE("(%p)->(%p)\n", This, p);
1273 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1276 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1278 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1279 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1280 return E_NOTIMPL;
1283 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1285 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1286 FIXME("(%p)->(%p)\n", This, p);
1287 return E_NOTIMPL;
1290 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1292 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1293 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1294 return E_NOTIMPL;
1297 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1299 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1300 FIXME("(%p)->(%p)\n", This, p);
1301 return E_NOTIMPL;
1304 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1306 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1307 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1308 return E_NOTIMPL;
1311 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1313 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1314 FIXME("(%p)->(%p)\n", This, p);
1315 return E_NOTIMPL;
1318 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1320 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1322 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1324 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1327 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1329 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1331 TRACE("(%p)->(%p)\n", This, p);
1333 return get_doc_event(This, EVENTID_DRAGSTART, p);
1336 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1338 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1340 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1342 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1345 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1347 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1349 TRACE("(%p)->(%p)\n", This, p);
1351 return get_doc_event(This, EVENTID_SELECTSTART, p);
1354 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1355 IHTMLElement **elementHit)
1357 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1358 nsIDOMElement *nselem;
1359 HTMLDOMNode *node;
1360 nsresult nsres;
1361 HRESULT hres;
1363 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1365 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1366 if(NS_FAILED(nsres)) {
1367 ERR("ElementFromPoint failed: %08x\n", nsres);
1368 return E_FAIL;
1371 if(!nselem) {
1372 *elementHit = NULL;
1373 return S_OK;
1376 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1377 nsIDOMElement_Release(nselem);
1378 if(FAILED(hres))
1379 return hres;
1381 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1382 node_release(node);
1383 return hres;
1386 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1388 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1390 TRACE("(%p)->(%p)\n", This, p);
1392 *p = &This->window->base.IHTMLWindow2_iface;
1393 IHTMLWindow2_AddRef(*p);
1394 return S_OK;
1397 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1398 IHTMLStyleSheetsCollection **p)
1400 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1401 nsIDOMStyleSheetList *nsstylelist;
1402 nsresult nsres;
1404 TRACE("(%p)->(%p)\n", This, p);
1406 *p = NULL;
1408 if(!This->doc_node->nsdoc) {
1409 WARN("NULL nsdoc\n");
1410 return E_UNEXPECTED;
1413 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1414 if(NS_FAILED(nsres)) {
1415 ERR("GetStyleSheets failed: %08x\n", nsres);
1416 return E_FAIL;
1419 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1420 nsIDOMStyleSheetList_Release(nsstylelist);
1422 return S_OK;
1425 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1427 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1428 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1429 return E_NOTIMPL;
1432 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1434 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1435 FIXME("(%p)->(%p)\n", This, p);
1436 return E_NOTIMPL;
1439 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1441 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1442 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1443 return E_NOTIMPL;
1446 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1448 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1449 FIXME("(%p)->(%p)\n", This, p);
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1455 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1456 FIXME("(%p)->(%p)\n", This, String);
1457 return E_NOTIMPL;
1460 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1461 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1463 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1464 nsIDOMHTMLHeadElement *head_elem;
1465 IHTMLStyleElement *style_elem;
1466 HTMLElement *elem;
1467 nsresult nsres;
1468 HRESULT hres;
1470 static const WCHAR styleW[] = {'s','t','y','l','e',0};
1472 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1474 if(!This->doc_node->nsdoc) {
1475 FIXME("not a real doc object\n");
1476 return E_NOTIMPL;
1479 if(lIndex != -1)
1480 FIXME("Unsupported lIndex %d\n", lIndex);
1482 if(bstrHref) {
1483 FIXME("semi-stub for href %s\n", debugstr_w(bstrHref));
1484 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1485 return S_OK;
1488 hres = create_element(This->doc_node, styleW, &elem);
1489 if(FAILED(hres))
1490 return hres;
1492 nsres = nsIDOMHTMLDocument_GetHead(This->doc_node->nsdoc, &head_elem);
1493 if(NS_SUCCEEDED(nsres)) {
1494 nsIDOMNode *tmp_node;
1496 nsres = nsIDOMHTMLHeadElement_AppendChild(head_elem, (nsIDOMNode*)elem->nselem, &tmp_node);
1497 nsIDOMHTMLHeadElement_Release(head_elem);
1498 if(NS_SUCCEEDED(nsres) && tmp_node)
1499 nsIDOMNode_Release(tmp_node);
1501 if(NS_FAILED(nsres)) {
1502 IHTMLElement_Release(&elem->IHTMLElement_iface);
1503 return E_FAIL;
1506 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLStyleElement, (void**)&style_elem);
1507 assert(hres == S_OK);
1508 IHTMLElement_Release(&elem->IHTMLElement_iface);
1510 hres = IHTMLStyleElement_get_styleSheet(style_elem, ppnewStyleSheet);
1511 IHTMLStyleElement_Release(style_elem);
1512 return hres;
1515 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1516 HTMLDocument_QueryInterface,
1517 HTMLDocument_AddRef,
1518 HTMLDocument_Release,
1519 HTMLDocument_GetTypeInfoCount,
1520 HTMLDocument_GetTypeInfo,
1521 HTMLDocument_GetIDsOfNames,
1522 HTMLDocument_Invoke,
1523 HTMLDocument_get_Script,
1524 HTMLDocument_get_all,
1525 HTMLDocument_get_body,
1526 HTMLDocument_get_activeElement,
1527 HTMLDocument_get_images,
1528 HTMLDocument_get_applets,
1529 HTMLDocument_get_links,
1530 HTMLDocument_get_forms,
1531 HTMLDocument_get_anchors,
1532 HTMLDocument_put_title,
1533 HTMLDocument_get_title,
1534 HTMLDocument_get_scripts,
1535 HTMLDocument_put_designMode,
1536 HTMLDocument_get_designMode,
1537 HTMLDocument_get_selection,
1538 HTMLDocument_get_readyState,
1539 HTMLDocument_get_frames,
1540 HTMLDocument_get_embeds,
1541 HTMLDocument_get_plugins,
1542 HTMLDocument_put_alinkColor,
1543 HTMLDocument_get_alinkColor,
1544 HTMLDocument_put_bgColor,
1545 HTMLDocument_get_bgColor,
1546 HTMLDocument_put_fgColor,
1547 HTMLDocument_get_fgColor,
1548 HTMLDocument_put_linkColor,
1549 HTMLDocument_get_linkColor,
1550 HTMLDocument_put_vlinkColor,
1551 HTMLDocument_get_vlinkColor,
1552 HTMLDocument_get_referrer,
1553 HTMLDocument_get_location,
1554 HTMLDocument_get_lastModified,
1555 HTMLDocument_put_URL,
1556 HTMLDocument_get_URL,
1557 HTMLDocument_put_domain,
1558 HTMLDocument_get_domain,
1559 HTMLDocument_put_cookie,
1560 HTMLDocument_get_cookie,
1561 HTMLDocument_put_expando,
1562 HTMLDocument_get_expando,
1563 HTMLDocument_put_charset,
1564 HTMLDocument_get_charset,
1565 HTMLDocument_put_defaultCharset,
1566 HTMLDocument_get_defaultCharset,
1567 HTMLDocument_get_mimeType,
1568 HTMLDocument_get_fileSize,
1569 HTMLDocument_get_fileCreatedDate,
1570 HTMLDocument_get_fileModifiedDate,
1571 HTMLDocument_get_fileUpdatedDate,
1572 HTMLDocument_get_security,
1573 HTMLDocument_get_protocol,
1574 HTMLDocument_get_nameProp,
1575 HTMLDocument_write,
1576 HTMLDocument_writeln,
1577 HTMLDocument_open,
1578 HTMLDocument_close,
1579 HTMLDocument_clear,
1580 HTMLDocument_queryCommandSupported,
1581 HTMLDocument_queryCommandEnabled,
1582 HTMLDocument_queryCommandState,
1583 HTMLDocument_queryCommandIndeterm,
1584 HTMLDocument_queryCommandText,
1585 HTMLDocument_queryCommandValue,
1586 HTMLDocument_execCommand,
1587 HTMLDocument_execCommandShowHelp,
1588 HTMLDocument_createElement,
1589 HTMLDocument_put_onhelp,
1590 HTMLDocument_get_onhelp,
1591 HTMLDocument_put_onclick,
1592 HTMLDocument_get_onclick,
1593 HTMLDocument_put_ondblclick,
1594 HTMLDocument_get_ondblclick,
1595 HTMLDocument_put_onkeyup,
1596 HTMLDocument_get_onkeyup,
1597 HTMLDocument_put_onkeydown,
1598 HTMLDocument_get_onkeydown,
1599 HTMLDocument_put_onkeypress,
1600 HTMLDocument_get_onkeypress,
1601 HTMLDocument_put_onmouseup,
1602 HTMLDocument_get_onmouseup,
1603 HTMLDocument_put_onmousedown,
1604 HTMLDocument_get_onmousedown,
1605 HTMLDocument_put_onmousemove,
1606 HTMLDocument_get_onmousemove,
1607 HTMLDocument_put_onmouseout,
1608 HTMLDocument_get_onmouseout,
1609 HTMLDocument_put_onmouseover,
1610 HTMLDocument_get_onmouseover,
1611 HTMLDocument_put_onreadystatechange,
1612 HTMLDocument_get_onreadystatechange,
1613 HTMLDocument_put_onafterupdate,
1614 HTMLDocument_get_onafterupdate,
1615 HTMLDocument_put_onrowexit,
1616 HTMLDocument_get_onrowexit,
1617 HTMLDocument_put_onrowenter,
1618 HTMLDocument_get_onrowenter,
1619 HTMLDocument_put_ondragstart,
1620 HTMLDocument_get_ondragstart,
1621 HTMLDocument_put_onselectstart,
1622 HTMLDocument_get_onselectstart,
1623 HTMLDocument_elementFromPoint,
1624 HTMLDocument_get_parentWindow,
1625 HTMLDocument_get_styleSheets,
1626 HTMLDocument_put_onbeforeupdate,
1627 HTMLDocument_get_onbeforeupdate,
1628 HTMLDocument_put_onerrorupdate,
1629 HTMLDocument_get_onerrorupdate,
1630 HTMLDocument_toString,
1631 HTMLDocument_createStyleSheet
1634 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1636 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1638 if(This->window)
1639 update_cp_events(This->window->base.inner_window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1642 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1644 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1647 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1649 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1650 return htmldoc_query_interface(This, riid, ppv);
1653 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1655 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1656 return htmldoc_addref(This);
1659 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1661 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1662 return htmldoc_release(This);
1665 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1667 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1668 return S_FALSE;
1671 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1672 SupportErrorInfo_QueryInterface,
1673 SupportErrorInfo_AddRef,
1674 SupportErrorInfo_Release,
1675 SupportErrorInfo_InterfaceSupportsErrorInfo
1678 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1680 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1683 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1685 nsIDOMNodeList *node_list;
1686 nsAString name_str;
1687 UINT32 len;
1688 unsigned i;
1689 nsresult nsres;
1691 if(!This->nsdoc)
1692 return DISP_E_UNKNOWNNAME;
1694 nsAString_InitDepend(&name_str, name);
1695 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1696 nsAString_Finish(&name_str);
1697 if(NS_FAILED(nsres))
1698 return E_FAIL;
1700 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1701 nsIDOMNodeList_Release(node_list);
1702 if(NS_FAILED(nsres))
1703 return E_FAIL;
1705 if(!len)
1706 return DISP_E_UNKNOWNNAME;
1708 for(i=0; i < This->elem_vars_cnt; i++) {
1709 if(!strcmpW(name, This->elem_vars[i])) {
1710 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1711 return S_OK;
1715 if(This->elem_vars_cnt == This->elem_vars_size) {
1716 WCHAR **new_vars;
1718 if(This->elem_vars_size) {
1719 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1720 if(!new_vars)
1721 return E_OUTOFMEMORY;
1722 This->elem_vars_size *= 2;
1723 }else {
1724 new_vars = heap_alloc(16*sizeof(WCHAR*));
1725 if(!new_vars)
1726 return E_OUTOFMEMORY;
1727 This->elem_vars_size = 16;
1730 This->elem_vars = new_vars;
1733 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1734 if(!This->elem_vars[This->elem_vars_cnt])
1735 return E_OUTOFMEMORY;
1737 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1738 return S_OK;
1741 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1743 HTMLDocument *This = impl_from_IDispatchEx(iface);
1745 return htmldoc_query_interface(This, riid, ppv);
1748 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1750 HTMLDocument *This = impl_from_IDispatchEx(iface);
1752 return htmldoc_addref(This);
1755 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1757 HTMLDocument *This = impl_from_IDispatchEx(iface);
1759 return htmldoc_release(This);
1762 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1764 HTMLDocument *This = impl_from_IDispatchEx(iface);
1766 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1769 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1770 LCID lcid, ITypeInfo **ppTInfo)
1772 HTMLDocument *This = impl_from_IDispatchEx(iface);
1774 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1777 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1778 LPOLESTR *rgszNames, UINT cNames,
1779 LCID lcid, DISPID *rgDispId)
1781 HTMLDocument *This = impl_from_IDispatchEx(iface);
1783 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1786 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1787 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1788 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1790 HTMLDocument *This = impl_from_IDispatchEx(iface);
1792 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1793 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1795 switch(dispIdMember) {
1796 case DISPID_READYSTATE:
1797 TRACE("DISPID_READYSTATE\n");
1799 if(!(wFlags & DISPATCH_PROPERTYGET))
1800 return E_INVALIDARG;
1802 V_VT(pVarResult) = VT_I4;
1803 V_I4(pVarResult) = This->window->readystate;
1804 return S_OK;
1807 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1808 pVarResult, pExcepInfo, puArgErr);
1811 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1813 HTMLDocument *This = impl_from_IDispatchEx(iface);
1814 HRESULT hres;
1816 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1817 if(hres != DISP_E_UNKNOWNNAME)
1818 return hres;
1820 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1823 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1824 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1826 HTMLDocument *This = impl_from_IDispatchEx(iface);
1828 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1829 return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1830 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1833 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1836 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1838 HTMLDocument *This = impl_from_IDispatchEx(iface);
1840 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1843 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1845 HTMLDocument *This = impl_from_IDispatchEx(iface);
1847 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1850 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1852 HTMLDocument *This = impl_from_IDispatchEx(iface);
1854 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1857 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1859 HTMLDocument *This = impl_from_IDispatchEx(iface);
1861 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1864 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1866 HTMLDocument *This = impl_from_IDispatchEx(iface);
1868 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1871 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1873 HTMLDocument *This = impl_from_IDispatchEx(iface);
1875 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1878 static const IDispatchExVtbl DocDispatchExVtbl = {
1879 DocDispatchEx_QueryInterface,
1880 DocDispatchEx_AddRef,
1881 DocDispatchEx_Release,
1882 DocDispatchEx_GetTypeInfoCount,
1883 DocDispatchEx_GetTypeInfo,
1884 DocDispatchEx_GetIDsOfNames,
1885 DocDispatchEx_Invoke,
1886 DocDispatchEx_GetDispID,
1887 DocDispatchEx_InvokeEx,
1888 DocDispatchEx_DeleteMemberByName,
1889 DocDispatchEx_DeleteMemberByDispID,
1890 DocDispatchEx_GetMemberProperties,
1891 DocDispatchEx_GetMemberName,
1892 DocDispatchEx_GetNextDispID,
1893 DocDispatchEx_GetNameSpaceParent
1896 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1898 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1901 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1902 REFIID riid, void **ppv)
1904 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1905 return htmldoc_query_interface(This, riid, ppv);
1908 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1910 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1911 return htmldoc_addref(This);
1914 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1916 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1917 return htmldoc_release(This);
1920 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1921 ITypeInfo **ppTI)
1923 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1924 TRACE("(%p)->(%p)\n", This, ppTI);
1925 return get_htmldoc_classinfo(ppTI);
1928 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1929 ProvideClassInfo_QueryInterface,
1930 ProvideClassInfo_AddRef,
1931 ProvideClassInfo_Release,
1932 ProvideClassInfo_GetClassInfo
1935 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1937 *ppv = NULL;
1939 if(IsEqualGUID(&IID_IUnknown, riid)) {
1940 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1941 *ppv = &This->IHTMLDocument2_iface;
1942 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1943 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1944 *ppv = &This->IDispatchEx_iface;
1945 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1946 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1947 *ppv = &This->IDispatchEx_iface;
1948 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1949 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1950 *ppv = &This->IHTMLDocument2_iface;
1951 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1952 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1953 *ppv = &This->IHTMLDocument2_iface;
1954 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1955 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1956 *ppv = &This->IHTMLDocument3_iface;
1957 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1958 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1959 *ppv = &This->IHTMLDocument4_iface;
1960 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1961 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1962 *ppv = &This->IHTMLDocument5_iface;
1963 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1964 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1965 *ppv = &This->IHTMLDocument6_iface;
1966 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1967 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1968 *ppv = &This->IPersistFile_iface;
1969 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1970 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1971 *ppv = &This->IPersistMoniker_iface;
1972 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1973 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1974 *ppv = &This->IPersistFile_iface;
1975 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1976 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1977 *ppv = &This->IMonikerProp_iface;
1978 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1979 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1980 *ppv = &This->IOleObject_iface;
1981 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1982 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1983 *ppv = &This->IOleDocument_iface;
1984 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1985 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1986 *ppv = &This->IOleDocumentView_iface;
1987 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1988 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1989 *ppv = &This->IOleInPlaceActiveObject_iface;
1990 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1991 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1992 *ppv = &This->IViewObjectEx_iface;
1993 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1994 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1995 *ppv = &This->IViewObjectEx_iface;
1996 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1997 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1998 *ppv = &This->IViewObjectEx_iface;
1999 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
2000 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
2001 *ppv = &This->IOleInPlaceActiveObject_iface;
2002 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
2003 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
2004 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2005 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
2006 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
2007 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2008 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
2009 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
2010 *ppv = &This->IServiceProvider_iface;
2011 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
2012 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
2013 *ppv = &This->IOleCommandTarget_iface;
2014 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
2015 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
2016 *ppv = &This->IOleControl_iface;
2017 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
2018 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
2019 *ppv = &This->IHlinkTarget_iface;
2020 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
2021 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
2022 *ppv = &This->cp_container.IConnectionPointContainer_iface;
2023 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
2024 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
2025 *ppv = &This->IPersistStreamInit_iface;
2026 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
2027 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
2028 *ppv = &This->IHTMLDocument2_iface;
2029 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
2030 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
2031 *ppv = &This->ISupportErrorInfo_iface;
2032 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
2033 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
2034 *ppv = &This->IPersistHistory_iface;
2035 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
2036 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
2037 *ppv = NULL;
2038 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
2039 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
2040 *ppv = NULL;
2041 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
2042 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
2043 *ppv = NULL;
2044 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
2045 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
2046 *ppv = NULL;
2047 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
2048 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
2049 *ppv = NULL;
2050 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
2051 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
2052 *ppv = NULL;
2053 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
2054 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
2055 *ppv = &This->IObjectWithSite_iface;
2056 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
2057 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
2058 *ppv = &This->IOleContainer_iface;
2059 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2060 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
2061 *ppv = &This->IObjectSafety_iface;
2062 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
2063 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
2064 *ppv = &This->IProvideClassInfo_iface;
2065 }else {
2066 return FALSE;
2069 if(*ppv)
2070 IUnknown_AddRef((IUnknown*)*ppv);
2071 return TRUE;
2074 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
2076 static const cpc_entry_t HTMLDocument_cpc[] = {
2077 {&IID_IDispatch, &HTMLDocumentEvents_data},
2078 {&IID_IPropertyNotifySink},
2079 {&DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data},
2080 {&DIID_HTMLDocumentEvents2},
2081 {NULL}
2084 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
2086 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
2087 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
2088 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
2089 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
2091 doc->unk_impl = unk_impl;
2092 doc->dispex = dispex;
2093 doc->task_magic = get_task_target_magic();
2095 HTMLDocument_HTMLDocument3_Init(doc);
2096 HTMLDocument_HTMLDocument5_Init(doc);
2097 HTMLDocument_Persist_Init(doc);
2098 HTMLDocument_OleCmd_Init(doc);
2099 HTMLDocument_OleObj_Init(doc);
2100 HTMLDocument_View_Init(doc);
2101 HTMLDocument_Window_Init(doc);
2102 HTMLDocument_Service_Init(doc);
2103 HTMLDocument_Hlink_Init(doc);
2105 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface, HTMLDocument_cpc);
2108 static void destroy_htmldoc(HTMLDocument *This)
2110 remove_target_tasks(This->task_magic);
2112 ConnectionPointContainer_Destroy(&This->cp_container);
2115 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2117 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2120 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2122 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2124 if(htmldoc_qi(&This->basedoc, riid, ppv))
2125 return *ppv ? S_OK : E_NOINTERFACE;
2127 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2128 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2129 *ppv = &This->IInternetHostSecurityManager_iface;
2130 }else {
2131 return HTMLDOMNode_QI(&This->node, riid, ppv);
2134 IUnknown_AddRef((IUnknown*)*ppv);
2135 return S_OK;
2138 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2140 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2141 unsigned i;
2143 for(i=0; i < This->elem_vars_cnt; i++)
2144 heap_free(This->elem_vars[i]);
2145 heap_free(This->elem_vars);
2147 detach_events(This);
2148 if(This->body_event_target)
2149 release_event_target(This->body_event_target);
2150 if(This->catmgr)
2151 ICatInformation_Release(This->catmgr);
2153 detach_selection(This);
2154 detach_ranges(This);
2156 while(!list_empty(&This->plugin_hosts))
2157 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2159 if(This->nsnode_selector) {
2160 nsIDOMNodeSelector_Release(This->nsnode_selector);
2161 This->nsnode_selector = NULL;
2164 if(This->nsdoc) {
2165 assert(!This->window);
2166 release_document_mutation(This);
2167 nsIDOMHTMLDocument_Release(This->nsdoc);
2168 }else if(This->window) {
2169 /* document fragments own reference to inner window */
2170 IHTMLWindow2_Release(&This->window->base.IHTMLWindow2_iface);
2171 This->window = NULL;
2174 heap_free(This->event_vector);
2175 destroy_htmldoc(&This->basedoc);
2178 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2180 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2181 FIXME("%p\n", This);
2182 return E_NOTIMPL;
2185 static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
2187 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2189 if(This->nsnode_selector)
2190 note_cc_edge((nsISupports*)This->nsnode_selector, "This->nsnode_selector", cb);
2191 if(This->nsdoc)
2192 note_cc_edge((nsISupports*)This->nsdoc, "This->nsdoc", cb);
2195 static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
2197 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2199 if(This->nsnode_selector) {
2200 nsIDOMNodeSelector_Release(This->nsnode_selector);
2201 This->nsnode_selector = NULL;
2204 if(This->nsdoc) {
2205 nsIDOMHTMLDocument *nsdoc = This->nsdoc;
2207 release_document_mutation(This);
2208 This->nsdoc = NULL;
2209 nsIDOMHTMLDocument_Release(nsdoc);
2210 This->window = NULL;
2214 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2215 HTMLDocumentNode_QI,
2216 HTMLDocumentNode_destructor,
2217 HTMLDocument_cpc,
2218 HTMLDocumentNode_clone,
2219 NULL,
2220 NULL,
2221 NULL,
2222 NULL,
2223 NULL,
2224 NULL,
2225 NULL,
2226 NULL,
2227 NULL,
2228 NULL,
2229 NULL,
2230 HTMLDocumentNode_traverse,
2231 HTMLDocumentNode_unlink
2234 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2236 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2237 HTMLDocumentNode *new_node;
2238 HRESULT hres;
2240 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2241 if(FAILED(hres))
2242 return hres;
2244 *ret = &new_node->node;
2245 return S_OK;
2248 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2250 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2253 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2254 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2256 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2257 nsIDOMNodeList *node_list;
2258 nsAString name_str;
2259 nsIDOMNode *nsnode;
2260 HTMLDOMNode *node;
2261 unsigned i;
2262 nsresult nsres;
2263 HRESULT hres;
2265 if(flags != DISPATCH_PROPERTYGET && flags != (DISPATCH_METHOD|DISPATCH_PROPERTYGET)) {
2266 FIXME("unsupported flags %x\n", flags);
2267 return E_NOTIMPL;
2270 i = id - MSHTML_DISPID_CUSTOM_MIN;
2272 if(!This->nsdoc || i >= This->elem_vars_cnt)
2273 return DISP_E_UNKNOWNNAME;
2275 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2276 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2277 nsAString_Finish(&name_str);
2278 if(NS_FAILED(nsres))
2279 return E_FAIL;
2281 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2282 nsIDOMNodeList_Release(node_list);
2283 if(NS_FAILED(nsres) || !nsnode)
2284 return DISP_E_UNKNOWNNAME;
2286 hres = get_node(This, nsnode, TRUE, &node);
2287 if(FAILED(hres))
2288 return hres;
2290 V_VT(res) = VT_DISPATCH;
2291 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2292 return S_OK;
2296 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2297 NULL,
2298 NULL,
2299 HTMLDocumentNode_invoke,
2300 NULL
2303 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2304 HTMLDocumentNode_QI,
2305 HTMLDocumentNode_destructor,
2306 HTMLDocument_cpc,
2307 HTMLDocumentFragment_clone
2310 static const tid_t HTMLDocumentNode_iface_tids[] = {
2311 IHTMLDOMNode_tid,
2312 IHTMLDOMNode2_tid,
2313 IHTMLDocument2_tid,
2314 IHTMLDocument3_tid,
2315 IHTMLDocument4_tid,
2316 IHTMLDocument5_tid,
2320 static dispex_static_data_t HTMLDocumentNode_dispex = {
2321 &HTMLDocumentNode_dispex_vtbl,
2322 DispHTMLDocument_tid,
2323 NULL,
2324 HTMLDocumentNode_iface_tids
2327 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window)
2329 HTMLDocumentNode *doc;
2331 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2332 if(!doc)
2333 return NULL;
2335 doc->ref = 1;
2336 doc->basedoc.doc_node = doc;
2337 doc->basedoc.doc_obj = doc_obj;
2338 doc->basedoc.window = window->base.outer_window;
2339 doc->window = window;
2341 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2342 &HTMLDocumentNode_dispex);
2343 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2344 &doc->node.dispex.IDispatchEx_iface);
2345 HTMLDocumentNode_SecMgr_Init(doc);
2347 list_init(&doc->selection_list);
2348 list_init(&doc->range_list);
2349 list_init(&doc->plugin_hosts);
2351 return doc;
2354 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLDocumentNode **ret)
2356 HTMLDocumentNode *doc;
2357 nsresult nsres;
2359 doc = alloc_doc_node(doc_obj, window);
2360 if(!doc)
2361 return E_OUTOFMEMORY;
2363 if(!doc_obj->basedoc.window || window->base.outer_window == doc_obj->basedoc.window)
2364 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2366 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2368 nsIDOMHTMLDocument_AddRef(nsdoc);
2369 doc->nsdoc = nsdoc;
2371 nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMNodeSelector, (void**)&doc->nsnode_selector);
2372 assert(nsres == NS_OK);
2374 init_document_mutation(doc);
2375 doc_init_events(doc);
2377 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2378 doc->node.cp_container = &doc->basedoc.cp_container;
2380 *ret = doc;
2381 return S_OK;
2384 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2386 HTMLDocumentNode *doc_frag;
2388 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->window);
2389 if(!doc_frag)
2390 return E_OUTOFMEMORY;
2392 IHTMLWindow2_AddRef(&doc_frag->window->base.IHTMLWindow2_iface);
2394 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2395 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2396 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2398 *ret = doc_frag;
2399 return S_OK;
2402 /**********************************************************
2403 * ICustomDoc implementation
2406 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2408 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2411 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2413 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2415 if(htmldoc_qi(&This->basedoc, riid, ppv))
2416 return *ppv ? S_OK : E_NOINTERFACE;
2418 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2419 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2420 *ppv = &This->ICustomDoc_iface;
2421 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2422 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2423 *ppv = &This->ITargetContainer_iface;
2424 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2425 return *ppv ? S_OK : E_NOINTERFACE;
2426 }else {
2427 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2428 *ppv = NULL;
2429 return E_NOINTERFACE;
2432 IUnknown_AddRef((IUnknown*)*ppv);
2433 return S_OK;
2436 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2438 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2439 ULONG ref = InterlockedIncrement(&This->ref);
2441 TRACE("(%p) ref = %u\n", This, ref);
2443 return ref;
2446 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2448 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2449 ULONG ref = InterlockedDecrement(&This->ref);
2451 TRACE("(%p) ref = %u\n", This, ref);
2453 if(!ref) {
2454 nsIDOMWindowUtils *window_utils = NULL;
2456 if(This->basedoc.window && This->basedoc.window->nswindow)
2457 get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);
2459 if(This->basedoc.doc_node) {
2460 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2461 htmldoc_release(&This->basedoc.doc_node->basedoc);
2463 if(This->basedoc.window) {
2464 This->basedoc.window->doc_obj = NULL;
2465 IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
2467 if(This->basedoc.advise_holder)
2468 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2470 if(This->view_sink)
2471 IAdviseSink_Release(This->view_sink);
2472 if(This->client)
2473 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2474 if(This->hostui)
2475 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2476 if(This->in_place_active)
2477 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2478 if(This->ipsite)
2479 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2480 if(This->undomgr)
2481 IOleUndoManager_Release(This->undomgr);
2482 if(This->tooltips_hwnd)
2483 DestroyWindow(This->tooltips_hwnd);
2485 if(This->hwnd)
2486 DestroyWindow(This->hwnd);
2487 heap_free(This->mime);
2489 destroy_htmldoc(&This->basedoc);
2490 release_dispex(&This->dispex);
2492 if(This->nscontainer)
2493 NSContainer_Release(This->nscontainer);
2494 heap_free(This);
2496 /* Force cycle collection */
2497 if(window_utils) {
2498 nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
2499 nsIDOMWindowUtils_Release(window_utils);
2503 return ref;
2506 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2508 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2509 IOleCommandTarget *cmdtrg;
2510 HRESULT hres;
2512 TRACE("(%p)->(%p)\n", This, pUIHandler);
2514 if(This->custom_hostui && This->hostui == pUIHandler)
2515 return S_OK;
2517 This->custom_hostui = TRUE;
2519 if(This->hostui)
2520 IDocHostUIHandler_Release(This->hostui);
2521 if(pUIHandler)
2522 IDocHostUIHandler_AddRef(pUIHandler);
2523 This->hostui = pUIHandler;
2524 if(!pUIHandler)
2525 return S_OK;
2527 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2528 if(SUCCEEDED(hres)) {
2529 FIXME("custom UI handler supports IOleCommandTarget\n");
2530 IOleCommandTarget_Release(cmdtrg);
2533 return S_OK;
2536 static const ICustomDocVtbl CustomDocVtbl = {
2537 CustomDoc_QueryInterface,
2538 CustomDoc_AddRef,
2539 CustomDoc_Release,
2540 CustomDoc_SetUIHandler
2543 static const tid_t HTMLDocumentObj_iface_tids[] = {
2544 IHTMLDocument2_tid,
2545 IHTMLDocument3_tid,
2546 IHTMLDocument4_tid,
2547 IHTMLDocument5_tid,
2550 static dispex_static_data_t HTMLDocumentObj_dispex = {
2551 NULL,
2552 DispHTMLDocument_tid,
2553 NULL,
2554 HTMLDocumentObj_iface_tids
2557 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2559 HTMLDocumentObj *doc;
2560 nsIDOMWindow *nswindow = NULL;
2561 nsresult nsres;
2562 HRESULT hres;
2564 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2566 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2567 if(!doc)
2568 return E_OUTOFMEMORY;
2570 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2571 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2572 TargetContainer_Init(doc);
2574 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2575 doc->ref = 1;
2576 doc->basedoc.doc_obj = doc;
2578 doc->usermode = UNKNOWN_USERMODE;
2580 init_binding_ui(doc);
2582 hres = create_nscontainer(doc, &doc->nscontainer);
2583 if(FAILED(hres)) {
2584 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2585 htmldoc_release(&doc->basedoc);
2586 return hres;
2589 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2590 htmldoc_release(&doc->basedoc);
2591 if(FAILED(hres))
2592 return hres;
2594 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2595 if(NS_FAILED(nsres))
2596 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2598 hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2599 if(nswindow)
2600 nsIDOMWindow_Release(nswindow);
2601 if(FAILED(hres)) {
2602 htmldoc_release(&doc->basedoc);
2603 return hres;
2606 if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
2607 doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
2608 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2611 get_thread_hwnd();
2613 return S_OK;