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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 /**********************************************************
42 * IPersistMoniker implementation
45 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
47 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
50 HTMLDocument *This = PERSISTMON_THIS(iface);
51 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
54 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
56 HTMLDocument *This = PERSISTMON_THIS(iface);
57 return IHTMLDocument2_AddRef(HTMLDOC(This));
60 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
62 HTMLDocument *This = PERSISTMON_THIS(iface);
63 return IHTMLDocument2_Release(HTMLDOC(This));
66 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
68 HTMLDocument *This = PERSISTMON_THIS(iface);
69 return IPersist_GetClassID(PERSIST(This), pClassID);
72 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
74 HTMLDocument *This = PERSISTMON_THIS(iface);
75 FIXME("(%p)\n", This);
79 static nsIInputStream *get_post_data_stream(IBindCtx *bctx)
81 nsIInputStream *ret = NULL;
82 IBindStatusCallback *callback;
83 IHttpNegotiate *http_negotiate;
86 DWORD post_len = 0, headers_len = 0;
87 LPWSTR headers = NULL;
88 WCHAR emptystr[] = {0};
92 static WCHAR _BSCB_Holder_[] =
93 {'_','B','S','C','B','_','H','o','l','d','e','r','_',0};
96 /* FIXME: This should be done in URLMoniker */
100 hres = IBindCtx_GetObjectParam(bctx, _BSCB_Holder_, (IUnknown**)&callback);
104 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
105 (void**)&http_negotiate);
106 if(SUCCEEDED(hres)) {
107 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, emptystr,
108 emptystr, 0, &headers);
109 IHttpNegotiate_Release(http_negotiate);
111 if(SUCCEEDED(hres) && headers)
112 headers_len = WideCharToMultiByte(CP_ACP, 0, headers, -1, NULL, 0, NULL, NULL);
115 memset(&bindinfo, 0, sizeof(bindinfo));
116 bindinfo.cbSize = sizeof(bindinfo);
118 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
120 if(SUCCEEDED(hres) && bindinfo.dwBindVerb == BINDVERB_POST)
121 post_len = bindinfo.cbStgmedData;
123 if(headers_len || post_len) {
124 int len = headers_len ? headers_len-1 : 0;
126 static const char content_length[] = "Content-Length: %lu\r\n\r\n";
128 data = HeapAlloc(GetProcessHeap(), 0, headers_len+post_len+sizeof(content_length)+8);
131 WideCharToMultiByte(CP_ACP, 0, headers, -1, data, -1, NULL, NULL);
132 CoTaskMemFree(headers);
136 sprintf(data+len, content_length, post_len);
139 memcpy(data+len, bindinfo.stgmedData.u.hGlobal, post_len);
142 TRACE("data = %s\n", debugstr_an(data, len+post_len));
144 ret = create_nsstream(data, len+post_len);
147 ReleaseBindInfo(&bindinfo);
148 IBindStatusCallback_Release(callback);
153 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
154 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
156 HTMLDocument *This = PERSISTMON_THIS(iface);
157 BSCallback *bscallback;
162 TRACE("(%p)->(%x %p %p %08lx)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
165 IUnknown *unk = NULL;
169 * "__PrecreatedObject"
170 * "BIND_CONTEXT_PARAM"
171 * "__HTMLLOADOPTIONS"
175 * "_ITransData_Object_"
179 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
181 IOleClientSite *client = NULL;
183 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
184 if(SUCCEEDED(hres)) {
185 TRACE("Got client site %p\n", client);
186 IOleObject_SetClientSite(OLEOBJ(This), client);
187 IOleClientSite_Release(client);
190 IUnknown_Release(unk);
194 HTMLDocument_LockContainer(This, TRUE);
196 hres = IMoniker_GetDisplayName(pimkName, pibc, NULL, &url);
198 WARN("GetDiaplayName failed: %08lx\n", hres);
202 TRACE("got url: %s\n", debugstr_w(url));
205 IOleCommandTarget *cmdtrg = NULL;
207 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
209 if(SUCCEEDED(hres)) {
214 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
218 bscallback = create_bscallback(This, url);
220 if(This->nscontainer) {
221 nsIInputStream *post_data_stream = get_post_data_stream(pibc);
223 This->nscontainer->bscallback = bscallback;
224 nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
225 LOAD_FLAGS_NONE, NULL, post_data_stream, NULL);
226 This->nscontainer->bscallback = NULL;
229 nsIInputStream_Release(post_data_stream);
231 if(!bscallback->nschannel)
232 ERR("bscallback->nschannel == NULL\n");
234 if(NS_SUCCEEDED(nsres)) {
235 /* FIXME: don't return here (URL Moniker needs to be good enough) */
237 IBindStatusCallback_Release(STATUSCLB(bscallback));
241 WARN("LoadURI failed: %08lx\n", nsres);
245 /* FIXME: Use grfMode */
248 FIXME("not supported fFullyAvailable\n");
250 FIXME("not supported pibc\n");
252 hres = start_binding(bscallback, pimkName);
254 IBindStatusCallback_Release(STATUSCLB(bscallback));
260 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
261 LPBC pbc, BOOL fRemember)
263 HTMLDocument *This = PERSISTMON_THIS(iface);
264 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
268 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
270 HTMLDocument *This = PERSISTMON_THIS(iface);
271 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
275 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
277 HTMLDocument *This = PERSISTMON_THIS(iface);
278 FIXME("(%p)->(%p)\n", This, ppimkName);
282 static const IPersistMonikerVtbl PersistMonikerVtbl = {
283 PersistMoniker_QueryInterface,
284 PersistMoniker_AddRef,
285 PersistMoniker_Release,
286 PersistMoniker_GetClassID,
287 PersistMoniker_IsDirty,
290 PersistMoniker_SaveCompleted,
291 PersistMoniker_GetCurMoniker
294 /**********************************************************
295 * IMonikerProp implementation
298 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
300 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
302 HTMLDocument *This = MONPROP_THIS(iface);
303 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
306 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
308 HTMLDocument *This = MONPROP_THIS(iface);
309 return IHTMLDocument2_AddRef(HTMLDOC(This));
312 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
314 HTMLDocument *This = MONPROP_THIS(iface);
315 return IHTMLDocument_Release(HTMLDOC(This));
318 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
320 HTMLDocument *This = MONPROP_THIS(iface);
321 FIXME("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
325 static const IMonikerPropVtbl MonikerPropVtbl = {
326 MonikerProp_QueryInterface,
329 MonikerProp_PutProperty
332 /**********************************************************
333 * IPersistFile implementation
336 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
338 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
340 HTMLDocument *This = PERSISTFILE_THIS(iface);
341 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
344 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
346 HTMLDocument *This = PERSISTFILE_THIS(iface);
347 return IHTMLDocument2_AddRef(HTMLDOC(This));
350 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
352 HTMLDocument *This = PERSISTFILE_THIS(iface);
353 return IHTMLDocument2_Release(HTMLDOC(This));
356 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
358 HTMLDocument *This = PERSISTFILE_THIS(iface);
360 TRACE("(%p)->(%p)\n", This, pClassID);
365 memcpy(pClassID, &CLSID_HTMLDocument, sizeof(CLSID));
369 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
371 HTMLDocument *This = PERSISTFILE_THIS(iface);
372 FIXME("(%p)\n", This);
376 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
378 HTMLDocument *This = PERSISTFILE_THIS(iface);
379 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
383 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
385 HTMLDocument *This = PERSISTFILE_THIS(iface);
386 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
390 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
392 HTMLDocument *This = PERSISTFILE_THIS(iface);
393 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
397 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
399 HTMLDocument *This = PERSISTFILE_THIS(iface);
400 FIXME("(%p)->(%p)\n", This, pszFileName);
404 static const IPersistFileVtbl PersistFileVtbl = {
405 PersistFile_QueryInterface,
408 PersistFile_GetClassID,
412 PersistFile_SaveCompleted,
413 PersistFile_GetCurFile
416 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface);
418 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
419 REFIID riid, void **ppv)
421 HTMLDocument *This = PERSTRINIT_THIS(iface);
422 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
425 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
427 HTMLDocument *This = PERSTRINIT_THIS(iface);
428 return IHTMLDocument2_AddRef(HTMLDOC(This));
431 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
433 HTMLDocument *This = PERSTRINIT_THIS(iface);
434 return IHTMLDocument2_AddRef(HTMLDOC(This));
437 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
439 HTMLDocument *This = PERSTRINIT_THIS(iface);
440 return IPersist_GetClassID(PERSIST(This), pClassID);
443 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
445 HTMLDocument *This = PERSTRINIT_THIS(iface);
446 FIXME("(%p)\n", This);
450 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
452 HTMLDocument *This = PERSTRINIT_THIS(iface);
453 FIXME("(%p)->(%p)\n", This, pStm);
457 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
460 HTMLDocument *This = PERSTRINIT_THIS(iface);
461 FIXME("(%p)->(%p %x)\n", This, pStm, fClearDirty);
465 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
466 ULARGE_INTEGER *pcbSize)
468 HTMLDocument *This = PERSTRINIT_THIS(iface);
469 FIXME("(%p)->(%p)\n", This, pcbSize);
473 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
475 HTMLDocument *This = PERSTRINIT_THIS(iface);
476 FIXME("(%p)\n", This);
480 #undef PERSTRINIT_THIS
482 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
483 PersistStreamInit_QueryInterface,
484 PersistStreamInit_AddRef,
485 PersistStreamInit_Release,
486 PersistStreamInit_GetClassID,
487 PersistStreamInit_IsDirty,
488 PersistStreamInit_Load,
489 PersistStreamInit_Save,
490 PersistStreamInit_GetSizeMax,
491 PersistStreamInit_InitNew
494 void HTMLDocument_Persist_Init(HTMLDocument *This)
496 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
497 This->lpPersistFileVtbl = &PersistFileVtbl;
498 This->lpMonikerPropVtbl = &MonikerPropVtbl;
499 This->lpPersistStreamInitVtbl = &PersistStreamInitVtbl;