2 * Copyright 2005 Jacek Caban
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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 static nsIInputStream
*get_post_data_stream(IBindCtx
*bctx
)
44 nsIInputStream
*ret
= NULL
;
45 IBindStatusCallback
*callback
;
46 IHttpNegotiate
*http_negotiate
;
49 DWORD post_len
= 0, headers_len
= 0;
50 LPWSTR headers
= NULL
;
51 WCHAR emptystr
[] = {0};
55 static WCHAR _BSCB_Holder_
[] =
56 {'_','B','S','C','B','_','H','o','l','d','e','r','_',0};
59 /* FIXME: This should be done in URLMoniker */
63 hres
= IBindCtx_GetObjectParam(bctx
, _BSCB_Holder_
, (IUnknown
**)&callback
);
67 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
68 (void**)&http_negotiate
);
70 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, emptystr
,
71 emptystr
, 0, &headers
);
72 IHttpNegotiate_Release(http_negotiate
);
74 if(SUCCEEDED(hres
) && headers
)
75 headers_len
= WideCharToMultiByte(CP_ACP
, 0, headers
, -1, NULL
, 0, NULL
, NULL
);
78 memset(&bindinfo
, 0, sizeof(bindinfo
));
79 bindinfo
.cbSize
= sizeof(bindinfo
);
81 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
83 if(SUCCEEDED(hres
) && bindinfo
.dwBindVerb
== BINDVERB_POST
)
84 post_len
= bindinfo
.cbstgmedData
;
86 if(headers_len
|| post_len
) {
87 int len
= headers_len
? headers_len
-1 : 0;
89 static const char content_length
[] = "Content-Length: %u\r\n\r\n";
91 data
= mshtml_alloc(headers_len
+post_len
+sizeof(content_length
)+8);
94 WideCharToMultiByte(CP_ACP
, 0, headers
, -1, data
, -1, NULL
, NULL
);
95 CoTaskMemFree(headers
);
99 sprintf(data
+len
, content_length
, post_len
);
102 memcpy(data
+len
, bindinfo
.stgmedData
.u
.hGlobal
, post_len
);
105 TRACE("data = %s\n", debugstr_an(data
, len
+post_len
));
107 ret
= create_nsstream(data
, len
+post_len
);
110 ReleaseBindInfo(&bindinfo
);
111 IBindStatusCallback_Release(callback
);
116 void set_current_mon(HTMLDocument
*This
, IMoniker
*mon
)
121 IMoniker_Release(This
->mon
);
126 SysFreeString(This
->url
);
133 IMoniker_AddRef(mon
);
136 hres
= IMoniker_GetDisplayName(mon
, NULL
, NULL
, &This
->url
);
138 WARN("GetDisplayName failed: %08x\n", hres
);
141 static HRESULT
set_moniker(HTMLDocument
*This
, IMoniker
*mon
, IBindCtx
*pibc
, BOOL
*bind_complete
)
143 BSCallback
*bscallback
;
150 IUnknown
*unk
= NULL
;
154 * "__PrecreatedObject"
155 * "BIND_CONTEXT_PARAM"
156 * "__HTMLLOADOPTIONS"
160 * "_ITransData_Object_"
164 IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
166 IOleClientSite
*client
= NULL
;
168 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
169 if(SUCCEEDED(hres
)) {
170 TRACE("Got client site %p\n", client
);
171 IOleObject_SetClientSite(OLEOBJ(This
), client
);
172 IOleClientSite_Release(client
);
175 IUnknown_Release(unk
);
179 This
->readystate
= READYSTATE_LOADING
;
180 call_property_onchanged(&This
->cp_propnotif
, DISPID_READYSTATE
);
181 update_doc(This
, UPDATE_TITLE
);
183 HTMLDocument_LockContainer(This
, TRUE
);
185 hres
= IMoniker_GetDisplayName(mon
, pibc
, NULL
, &url
);
187 WARN("GetDiaplayName failed: %08x\n", hres
);
191 TRACE("got url: %s\n", debugstr_w(url
));
193 set_current_mon(This
, mon
);
196 VARIANT silent
, offline
;
197 IOleCommandTarget
*cmdtrg
= NULL
;
199 hres
= get_client_disp_property(This
->client
, DISPID_AMBIENT_SILENT
, &silent
);
200 if(SUCCEEDED(hres
)) {
201 if(V_VT(&silent
) != VT_BOOL
)
202 WARN("V_VT(silent) = %d\n", V_VT(&silent
));
203 else if(V_BOOL(&silent
))
204 FIXME("silent == true\n");
207 hres
= get_client_disp_property(This
->client
,
208 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
209 if(SUCCEEDED(hres
)) {
210 if(V_VT(&silent
) != VT_BOOL
)
211 WARN("V_VT(offline) = %d\n", V_VT(&silent
));
212 else if(V_BOOL(&silent
))
213 FIXME("offline == true\n");
216 hres
= IOleClientSite_QueryInterface(This
->client
, &IID_IOleCommandTarget
,
218 if(SUCCEEDED(hres
)) {
223 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
225 IOleCommandTarget_Release(cmdtrg
);
229 bscallback
= create_bscallback(mon
);
232 task
= mshtml_alloc(sizeof(task_t
));
235 task
->task_id
= TASK_SETPROGRESS
;
241 task
= mshtml_alloc(sizeof(task_t
));
244 task
->task_id
= TASK_SETDOWNLOADSTATE
;
249 if(This
->nscontainer
) {
250 nsIInputStream
*post_data_stream
= get_post_data_stream(pibc
);
252 This
->nscontainer
->bscallback
= bscallback
;
253 nsres
= nsIWebNavigation_LoadURI(This
->nscontainer
->navigation
, url
,
254 LOAD_FLAGS_NONE
, NULL
, post_data_stream
, NULL
);
255 This
->nscontainer
->bscallback
= NULL
;
258 nsIInputStream_Release(post_data_stream
);
260 if(NS_SUCCEEDED(nsres
)) {
261 /* FIXME: don't return here (URL Moniker needs to be good enough) */
263 IBindStatusCallback_Release(STATUSCLB(bscallback
));
267 *bind_complete
= TRUE
;
269 }else if(nsres
!= WINE_NS_LOAD_FROM_MONIKER
) {
270 WARN("LoadURI failed: %08x\n", nsres
);
274 set_document_bscallback(This
, bscallback
);
275 IBindStatusCallback_Release(STATUSCLB(bscallback
));
279 *bind_complete
= FALSE
;
283 static HRESULT
get_doc_string(HTMLDocument
*This
, char **str
, DWORD
*len
)
285 nsIDOMDocument
*nsdoc
;
291 if(!This
->nscontainer
) {
292 WARN("no nscontainer, returning NULL\n");
296 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
297 if(NS_FAILED(nsres
)) {
298 ERR("GetDocument failed: %08x\n", nsres
);
302 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
303 nsIDOMDocument_Release(nsdoc
);
304 if(NS_FAILED(nsres
)) {
305 ERR("Could not get nsIDOMNode failed: %08x\n", nsres
);
309 nsAString_Init(&nsstr
, NULL
);
310 nsnode_to_nsstring(nsnode
, &nsstr
);
311 nsIDOMNode_Release(nsnode
);
313 nsAString_GetData(&nsstr
, &strw
, NULL
);
314 TRACE("%s\n", debugstr_w(strw
));
316 *len
= WideCharToMultiByte(CP_ACP
, 0, strw
, -1, NULL
, 0, NULL
, NULL
);
317 *str
= mshtml_alloc(*len
);
318 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, *str
, *len
, NULL
, NULL
);
320 nsAString_Finish(&nsstr
);
326 /**********************************************************
327 * IPersistMoniker implementation
330 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
332 static HRESULT WINAPI
PersistMoniker_QueryInterface(IPersistMoniker
*iface
, REFIID riid
,
335 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
336 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
339 static ULONG WINAPI
PersistMoniker_AddRef(IPersistMoniker
*iface
)
341 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
342 return IHTMLDocument2_AddRef(HTMLDOC(This
));
345 static ULONG WINAPI
PersistMoniker_Release(IPersistMoniker
*iface
)
347 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
348 return IHTMLDocument2_Release(HTMLDOC(This
));
351 static HRESULT WINAPI
PersistMoniker_GetClassID(IPersistMoniker
*iface
, CLSID
*pClassID
)
353 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
354 return IPersist_GetClassID(PERSIST(This
), pClassID
);
357 static HRESULT WINAPI
PersistMoniker_IsDirty(IPersistMoniker
*iface
)
359 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
361 TRACE("(%p)\n", This
);
363 return IPersistStreamInit_IsDirty(PERSTRINIT(This
));
366 static HRESULT WINAPI
PersistMoniker_Load(IPersistMoniker
*iface
, BOOL fFullyAvailable
,
367 IMoniker
*pimkName
, LPBC pibc
, DWORD grfMode
)
369 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
370 BOOL bind_complete
= FALSE
;
373 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
375 hres
= set_moniker(This
, pimkName
, pibc
, &bind_complete
);
380 return start_binding(This
->bscallback
);
385 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
386 LPBC pbc
, BOOL fRemember
)
388 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
389 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
393 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
395 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
396 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
400 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
402 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
404 TRACE("(%p)->(%p)\n", This
, ppimkName
);
409 IMoniker_AddRef(This
->mon
);
410 *ppimkName
= This
->mon
;
414 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
415 PersistMoniker_QueryInterface
,
416 PersistMoniker_AddRef
,
417 PersistMoniker_Release
,
418 PersistMoniker_GetClassID
,
419 PersistMoniker_IsDirty
,
422 PersistMoniker_SaveCompleted
,
423 PersistMoniker_GetCurMoniker
426 /**********************************************************
427 * IMonikerProp implementation
430 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
432 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppvObject
)
434 HTMLDocument
*This
= MONPROP_THIS(iface
);
435 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
438 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
440 HTMLDocument
*This
= MONPROP_THIS(iface
);
441 return IHTMLDocument2_AddRef(HTMLDOC(This
));
444 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
446 HTMLDocument
*This
= MONPROP_THIS(iface
);
447 return IHTMLDocument_Release(HTMLDOC(This
));
450 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
452 HTMLDocument
*This
= MONPROP_THIS(iface
);
453 FIXME("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
457 static const IMonikerPropVtbl MonikerPropVtbl
= {
458 MonikerProp_QueryInterface
,
461 MonikerProp_PutProperty
464 /**********************************************************
465 * IPersistFile implementation
468 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
470 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppvObject
)
472 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
473 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
476 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
478 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
479 return IHTMLDocument2_AddRef(HTMLDOC(This
));
482 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
484 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
485 return IHTMLDocument2_Release(HTMLDOC(This
));
488 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
490 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
492 TRACE("(%p)->(%p)\n", This
, pClassID
);
497 memcpy(pClassID
, &CLSID_HTMLDocument
, sizeof(CLSID
));
501 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
503 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
505 TRACE("(%p)\n", This
);
507 return IPersistStreamInit_IsDirty(PERSTRINIT(This
));
510 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
512 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
513 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
517 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
519 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
521 DWORD len
, written
=0;
525 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
527 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
528 FILE_ATTRIBUTE_NORMAL
, NULL
);
529 if(file
== INVALID_HANDLE_VALUE
) {
530 WARN("Could not create file: %u\n", GetLastError());
534 hres
= get_doc_string(This
, &str
, &len
);
538 WriteFile(file
, str
, len
, &written
, NULL
);
543 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
545 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
546 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
550 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
552 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
553 FIXME("(%p)->(%p)\n", This
, pszFileName
);
557 static const IPersistFileVtbl PersistFileVtbl
= {
558 PersistFile_QueryInterface
,
561 PersistFile_GetClassID
,
565 PersistFile_SaveCompleted
,
566 PersistFile_GetCurFile
569 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
571 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
572 REFIID riid
, void **ppv
)
574 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
575 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppv
);
578 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
580 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
581 return IHTMLDocument2_AddRef(HTMLDOC(This
));
584 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
586 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
587 return IHTMLDocument2_Release(HTMLDOC(This
));
590 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
592 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
593 return IPersist_GetClassID(PERSIST(This
), pClassID
);
596 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
598 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
600 TRACE("(%p)\n", This
);
602 if(This
->usermode
== EDITMODE
)
603 FIXME("Unimplemented in edit mode\n");
608 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, LPSTREAM pStm
)
610 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
614 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
616 TRACE("(%p)->(%p)\n", This
, pStm
);
618 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
620 WARN("CreateURLMoniker failed: %08x\n", hres
);
624 hres
= set_moniker(This
, mon
, NULL
, NULL
);
625 IMoniker_Release(mon
);
629 return load_stream(This
->bscallback
, pStm
);
632 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, LPSTREAM pStm
,
635 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
637 DWORD len
, written
=0;
640 WARN("(%p)->(%p %x) needs more work\n", This
, pStm
, fClearDirty
);
642 hres
= get_doc_string(This
, &str
, &len
);
647 hres
= IStream_Write(pStm
, str
, len
, &written
);
649 FIXME("Write failed: %08x\n", hres
);
655 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
656 ULARGE_INTEGER
*pcbSize
)
658 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
659 FIXME("(%p)->(%p)\n", This
, pcbSize
);
663 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
665 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
666 FIXME("(%p)\n", This
);
670 #undef PERSTRINIT_THIS
672 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
673 PersistStreamInit_QueryInterface
,
674 PersistStreamInit_AddRef
,
675 PersistStreamInit_Release
,
676 PersistStreamInit_GetClassID
,
677 PersistStreamInit_IsDirty
,
678 PersistStreamInit_Load
,
679 PersistStreamInit_Save
,
680 PersistStreamInit_GetSizeMax
,
681 PersistStreamInit_InitNew
684 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
686 This
->lpPersistMonikerVtbl
= &PersistMonikerVtbl
;
687 This
->lpPersistFileVtbl
= &PersistFileVtbl
;
688 This
->lpMonikerPropVtbl
= &MonikerPropVtbl
;
689 This
->lpPersistStreamInitVtbl
= &PersistStreamInitVtbl
;
691 This
->bscallback
= NULL
;