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 /**********************************************************
43 * IPersistMoniker implementation
46 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
48 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
51 HTMLDocument *This = PERSISTMON_THIS(iface);
52 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
55 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
57 HTMLDocument *This = PERSISTMON_THIS(iface);
58 return IHTMLDocument2_AddRef(HTMLDOC(This));
61 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
63 HTMLDocument *This = PERSISTMON_THIS(iface);
64 return IHTMLDocument2_Release(HTMLDOC(This));
67 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
69 HTMLDocument *This = PERSISTMON_THIS(iface);
70 return IPersist_GetClassID(PERSIST(This), pClassID);
73 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
75 HTMLDocument *This = PERSISTMON_THIS(iface);
76 FIXME("(%p)\n", This);
80 static nsIInputStream *get_post_data_stream(IBindCtx *bctx)
82 nsIInputStream *ret = NULL;
83 IBindStatusCallback *callback;
84 IHttpNegotiate *http_negotiate;
87 DWORD post_len = 0, headers_len = 0;
88 LPWSTR headers = NULL;
89 WCHAR emptystr[] = {0};
93 static WCHAR _BSCB_Holder_[] =
94 {'_','B','S','C','B','_','H','o','l','d','e','r','_',0};
97 /* FIXME: This should be done in URLMoniker */
101 hres = IBindCtx_GetObjectParam(bctx, _BSCB_Holder_, (IUnknown**)&callback);
105 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
106 (void**)&http_negotiate);
107 if(SUCCEEDED(hres)) {
108 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, emptystr,
109 emptystr, 0, &headers);
110 IHttpNegotiate_Release(http_negotiate);
112 if(SUCCEEDED(hres) && headers)
113 headers_len = WideCharToMultiByte(CP_ACP, 0, headers, -1, NULL, 0, NULL, NULL);
116 memset(&bindinfo, 0, sizeof(bindinfo));
117 bindinfo.cbSize = sizeof(bindinfo);
119 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
121 if(SUCCEEDED(hres) && bindinfo.dwBindVerb == BINDVERB_POST)
122 post_len = bindinfo.cbstgmedData;
124 if(headers_len || post_len) {
125 int len = headers_len ? headers_len-1 : 0;
127 static const char content_length[] = "Content-Length: %u\r\n\r\n";
129 data = mshtml_alloc(headers_len+post_len+sizeof(content_length)+8);
132 WideCharToMultiByte(CP_ACP, 0, headers, -1, data, -1, NULL, NULL);
133 CoTaskMemFree(headers);
137 sprintf(data+len, content_length, post_len);
140 memcpy(data+len, bindinfo.stgmedData.u.hGlobal, post_len);
143 TRACE("data = %s\n", debugstr_an(data, len+post_len));
145 ret = create_nsstream(data, len+post_len);
148 ReleaseBindInfo(&bindinfo);
149 IBindStatusCallback_Release(callback);
154 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
155 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
157 HTMLDocument *This = PERSISTMON_THIS(iface);
158 BSCallback *bscallback;
164 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
167 IUnknown *unk = NULL;
171 * "__PrecreatedObject"
172 * "BIND_CONTEXT_PARAM"
173 * "__HTMLLOADOPTIONS"
177 * "_ITransData_Object_"
181 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
183 IOleClientSite *client = NULL;
185 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
186 if(SUCCEEDED(hres)) {
187 TRACE("Got client site %p\n", client);
188 IOleObject_SetClientSite(OLEOBJ(This), client);
189 IOleClientSite_Release(client);
192 IUnknown_Release(unk);
196 This->readystate = READYSTATE_LOADING;
197 call_property_onchanged(This->cp_propnotif, DISPID_READYSTATE);
199 HTMLDocument_LockContainer(This, TRUE);
201 hres = IMoniker_GetDisplayName(pimkName, pibc, NULL, &url);
203 WARN("GetDiaplayName failed: %08x\n", hres);
207 TRACE("got url: %s\n", debugstr_w(url));
210 IOleCommandTarget *cmdtrg = NULL;
212 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
214 if(SUCCEEDED(hres)) {
219 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
221 IOleCommandTarget_Release(cmdtrg);
226 VARIANT silent, offline;
228 hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
229 if(SUCCEEDED(hres)) {
230 if(V_VT(&silent) != VT_BOOL)
231 WARN("V_VT(silent) = %d\n", V_VT(&silent));
232 else if(V_BOOL(&silent))
233 FIXME("silent == true\n");
236 hres = get_client_disp_property(This->client,
237 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
238 if(SUCCEEDED(hres)) {
239 if(V_VT(&silent) != VT_BOOL)
240 WARN("V_VT(offline) = %d\n", V_VT(&silent));
241 else if(V_BOOL(&silent))
242 FIXME("offline == true\n");
246 bscallback = create_bscallback(pimkName);
249 task = mshtml_alloc(sizeof(task_t));
252 task->task_id = TASK_SETPROGRESS;
258 task = mshtml_alloc(sizeof(task_t));
261 task->task_id = TASK_SETDOWNLOADSTATE;
266 if(This->nscontainer) {
267 nsIInputStream *post_data_stream = get_post_data_stream(pibc);
269 This->nscontainer->bscallback = bscallback;
270 nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
271 LOAD_FLAGS_NONE, NULL, post_data_stream, NULL);
272 This->nscontainer->bscallback = NULL;
275 nsIInputStream_Release(post_data_stream);
277 if(NS_SUCCEEDED(nsres)) {
278 /* FIXME: don't return here (URL Moniker needs to be good enough) */
280 IBindStatusCallback_Release(STATUSCLB(bscallback));
283 }else if(nsres != WINE_NS_LOAD_FROM_MONIKER) {
284 WARN("LoadURI failed: %08x\n", nsres);
288 set_document_bscallback(This, bscallback);
289 hres = start_binding(bscallback);
291 IBindStatusCallback_Release(STATUSCLB(bscallback));
297 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
298 LPBC pbc, BOOL fRemember)
300 HTMLDocument *This = PERSISTMON_THIS(iface);
301 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
305 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
307 HTMLDocument *This = PERSISTMON_THIS(iface);
308 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
312 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
314 HTMLDocument *This = PERSISTMON_THIS(iface);
315 FIXME("(%p)->(%p)\n", This, ppimkName);
319 static const IPersistMonikerVtbl PersistMonikerVtbl = {
320 PersistMoniker_QueryInterface,
321 PersistMoniker_AddRef,
322 PersistMoniker_Release,
323 PersistMoniker_GetClassID,
324 PersistMoniker_IsDirty,
327 PersistMoniker_SaveCompleted,
328 PersistMoniker_GetCurMoniker
331 /**********************************************************
332 * IMonikerProp implementation
335 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
337 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
339 HTMLDocument *This = MONPROP_THIS(iface);
340 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
343 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
345 HTMLDocument *This = MONPROP_THIS(iface);
346 return IHTMLDocument2_AddRef(HTMLDOC(This));
349 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
351 HTMLDocument *This = MONPROP_THIS(iface);
352 return IHTMLDocument_Release(HTMLDOC(This));
355 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
357 HTMLDocument *This = MONPROP_THIS(iface);
358 FIXME("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
362 static const IMonikerPropVtbl MonikerPropVtbl = {
363 MonikerProp_QueryInterface,
366 MonikerProp_PutProperty
369 /**********************************************************
370 * IPersistFile implementation
373 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
375 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
377 HTMLDocument *This = PERSISTFILE_THIS(iface);
378 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
381 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
383 HTMLDocument *This = PERSISTFILE_THIS(iface);
384 return IHTMLDocument2_AddRef(HTMLDOC(This));
387 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
389 HTMLDocument *This = PERSISTFILE_THIS(iface);
390 return IHTMLDocument2_Release(HTMLDOC(This));
393 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
395 HTMLDocument *This = PERSISTFILE_THIS(iface);
397 TRACE("(%p)->(%p)\n", This, pClassID);
402 memcpy(pClassID, &CLSID_HTMLDocument, sizeof(CLSID));
406 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
408 HTMLDocument *This = PERSISTFILE_THIS(iface);
409 FIXME("(%p)\n", This);
413 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
415 HTMLDocument *This = PERSISTFILE_THIS(iface);
416 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
420 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
422 HTMLDocument *This = PERSISTFILE_THIS(iface);
423 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
427 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
429 HTMLDocument *This = PERSISTFILE_THIS(iface);
430 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
434 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
436 HTMLDocument *This = PERSISTFILE_THIS(iface);
437 FIXME("(%p)->(%p)\n", This, pszFileName);
441 static const IPersistFileVtbl PersistFileVtbl = {
442 PersistFile_QueryInterface,
445 PersistFile_GetClassID,
449 PersistFile_SaveCompleted,
450 PersistFile_GetCurFile
453 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
455 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
456 REFIID riid, void **ppv)
458 HTMLDocument *This = PERSTRINIT_THIS(iface);
459 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
462 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
464 HTMLDocument *This = PERSTRINIT_THIS(iface);
465 return IHTMLDocument2_AddRef(HTMLDOC(This));
468 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
470 HTMLDocument *This = PERSTRINIT_THIS(iface);
471 return IHTMLDocument2_AddRef(HTMLDOC(This));
474 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
476 HTMLDocument *This = PERSTRINIT_THIS(iface);
477 return IPersist_GetClassID(PERSIST(This), pClassID);
480 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
482 HTMLDocument *This = PERSTRINIT_THIS(iface);
483 FIXME("(%p)\n", This);
487 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
489 HTMLDocument *This = PERSTRINIT_THIS(iface);
490 FIXME("(%p)->(%p)\n", This, pStm);
494 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
497 HTMLDocument *This = PERSTRINIT_THIS(iface);
498 nsIDOMDocument *nsdoc;
503 DWORD len, written=0;
507 WARN("(%p)->(%p %x) needs more work\n", This, pStm, fClearDirty);
509 if(!This->nscontainer)
512 nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, &nsdoc);
513 if(NS_FAILED(nsres)) {
514 ERR("GetDocument failed: %08x\n", nsres);
518 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
519 nsIDOMDocument_Release(nsdoc);
520 if(NS_FAILED(nsres)) {
521 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
525 nsAString_Init(&nsstr, NULL);
526 nsnode_to_nsstring(nsnode, &nsstr);
527 nsIDOMNode_Release(nsnode);
529 nsAString_GetData(&nsstr, &strw, NULL);
531 len = WideCharToMultiByte(CP_ACP, 0, strw, -1, NULL, 0, NULL, NULL);
532 str = mshtml_alloc(len);
533 WideCharToMultiByte(CP_ACP, 0, strw, -1, str, len, NULL, NULL);
535 nsAString_Finish(&nsstr);
537 TRACE("%s\n", debugstr_a(str));
539 hres = IStream_Write(pStm, str, len, &written);
541 FIXME("Write failed: %08x\n", hres);
548 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
549 ULARGE_INTEGER *pcbSize)
551 HTMLDocument *This = PERSTRINIT_THIS(iface);
552 FIXME("(%p)->(%p)\n", This, pcbSize);
556 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
558 HTMLDocument *This = PERSTRINIT_THIS(iface);
559 FIXME("(%p)\n", This);
563 #undef PERSTRINIT_THIS
565 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
566 PersistStreamInit_QueryInterface,
567 PersistStreamInit_AddRef,
568 PersistStreamInit_Release,
569 PersistStreamInit_GetClassID,
570 PersistStreamInit_IsDirty,
571 PersistStreamInit_Load,
572 PersistStreamInit_Save,
573 PersistStreamInit_GetSizeMax,
574 PersistStreamInit_InitNew
577 void HTMLDocument_Persist_Init(HTMLDocument *This)
579 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
580 This->lpPersistFileVtbl = &PersistFileVtbl;
581 This->lpMonikerPropVtbl = &MonikerPropVtbl;
582 This->lpPersistStreamInitVtbl = &PersistStreamInitVtbl;
584 This->bscallback = NULL;