sync mshtml to wine 1.1.33
[reactos.git] / reactos / dll / win32 / mshtml / persist.c
1 /*
2 * Copyright 2005 Jacek Caban
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "shlguid.h"
33 #include "idispids.h"
34
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
37
38 #include "mshtml_private.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41
42 static BOOL use_gecko_script(LPCWSTR url)
43 {
44 static const WCHAR fileW[] = {'f','i','l','e',':'};
45 static const WCHAR aboutW[] = {'a','b','o','u','t',':'};
46
47 return strncmpiW(fileW, url, sizeof(fileW)/sizeof(WCHAR))
48 && strncmpiW(aboutW, url, sizeof(aboutW)/sizeof(WCHAR));
49 }
50
51 void set_current_mon(HTMLWindow *This, IMoniker *mon)
52 {
53 HRESULT hres;
54
55 if(This->mon) {
56 IMoniker_Release(This->mon);
57 This->mon = NULL;
58 }
59
60 if(This->url) {
61 CoTaskMemFree(This->url);
62 This->url = NULL;
63 }
64
65 if(!mon)
66 return;
67
68 IMoniker_AddRef(mon);
69 This->mon = mon;
70
71 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
72 if(FAILED(hres))
73 WARN("GetDisplayName failed: %08x\n", hres);
74
75 set_script_mode(This, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
76 }
77
78 static void set_progress_proc(task_t *_task)
79 {
80 docobj_task_t *task = (docobj_task_t*)_task;
81 IOleCommandTarget *olecmd = NULL;
82 HTMLDocumentObj *doc = task->doc;
83 HRESULT hres;
84
85 TRACE("(%p)\n", doc);
86
87 if(doc->client)
88 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
89
90 if(olecmd) {
91 VARIANT progress_max, progress;
92
93 V_VT(&progress_max) = VT_I4;
94 V_I4(&progress_max) = 0; /* FIXME */
95 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
96 &progress_max, NULL);
97
98 V_VT(&progress) = VT_I4;
99 V_I4(&progress) = 0; /* FIXME */
100 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
101 &progress, NULL);
102 }
103
104 if(doc->usermode == EDITMODE && doc->hostui) {
105 DOCHOSTUIINFO hostinfo;
106
107 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
108 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
109 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
110 if(SUCCEEDED(hres))
111 /* FIXME: use hostinfo */
112 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
113 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
114 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
115 }
116 }
117
118 static void set_downloading_proc(task_t *_task)
119 {
120 HTMLDocumentObj *doc = ((docobj_task_t*)_task)->doc;
121 IOleCommandTarget *olecmd;
122 HRESULT hres;
123
124 TRACE("(%p)\n", doc);
125
126 if(doc->frame)
127 IOleInPlaceFrame_SetStatusText(doc->frame, NULL /* FIXME */);
128
129 if(!doc->client)
130 return;
131
132 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
133 if(SUCCEEDED(hres)) {
134 VARIANT var;
135
136 V_VT(&var) = VT_I4;
137 V_I4(&var) = 1;
138
139 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE, OLECMDEXECOPT_DONTPROMPTUSER,
140 &var, NULL);
141 IOleCommandTarget_Release(olecmd);
142 }
143
144 if(doc->hostui) {
145 IDropTarget *drop_target = NULL;
146
147 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
148 if(drop_target) {
149 FIXME("Use IDropTarget\n");
150 IDropTarget_Release(drop_target);
151 }
152 }
153 }
154
155 static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc)
156 {
157 nsChannelBSC *bscallback;
158 LPOLESTR url = NULL;
159 docobj_task_t *task;
160 HRESULT hres;
161 nsresult nsres;
162
163 if(pibc) {
164 IUnknown *unk = NULL;
165
166 /* FIXME:
167 * Use params:
168 * "__PrecreatedObject"
169 * "BIND_CONTEXT_PARAM"
170 * "__HTMLLOADOPTIONS"
171 * "__DWNBINDINFO"
172 * "URL Context"
173 * "CBinding Context"
174 * "_ITransData_Object_"
175 * "_EnumFORMATETC_"
176 */
177
178 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
179 if(unk) {
180 IOleClientSite *client = NULL;
181
182 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
183 if(SUCCEEDED(hres)) {
184 TRACE("Got client site %p\n", client);
185 IOleObject_SetClientSite(OLEOBJ(This), client);
186 IOleClientSite_Release(client);
187 }
188
189 IUnknown_Release(unk);
190 }
191 }
192
193 set_ready_state(This->window, READYSTATE_LOADING);
194 update_doc(This, UPDATE_TITLE);
195
196 HTMLDocument_LockContainer(This->doc_obj, TRUE);
197
198 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
199 if(FAILED(hres)) {
200 WARN("GetDiaplayName failed: %08x\n", hres);
201 return hres;
202 }
203
204 TRACE("got url: %s\n", debugstr_w(url));
205
206 set_current_mon(This->window, mon);
207
208 if(This->doc_obj->client) {
209 VARIANT silent, offline;
210 IOleCommandTarget *cmdtrg = NULL;
211
212 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
213 if(SUCCEEDED(hres)) {
214 if(V_VT(&silent) != VT_BOOL)
215 WARN("V_VT(silent) = %d\n", V_VT(&silent));
216 else if(V_BOOL(&silent))
217 FIXME("silent == true\n");
218 }
219
220 hres = get_client_disp_property(This->doc_obj->client,
221 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
222 if(SUCCEEDED(hres)) {
223 if(V_VT(&silent) != VT_BOOL)
224 WARN("V_VT(offline) = %d\n", V_VT(&silent));
225 else if(V_BOOL(&silent))
226 FIXME("offline == true\n");
227 }
228
229 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
230 (void**)&cmdtrg);
231 if(SUCCEEDED(hres)) {
232 VARIANT var;
233
234 V_VT(&var) = VT_I4;
235 V_I4(&var) = 0;
236 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
237
238 IOleCommandTarget_Release(cmdtrg);
239 }
240 }
241
242 bscallback = create_channelbsc(mon);
243
244 if(This->doc_obj->frame) {
245 task = heap_alloc(sizeof(docobj_task_t));
246 task->doc = This->doc_obj;
247 push_task(&task->header, set_progress_proc, This->doc_obj->basedoc.task_magic);
248 }
249
250 task = heap_alloc(sizeof(docobj_task_t));
251 task->doc = This->doc_obj;
252 push_task(&task->header, set_downloading_proc, This->doc_obj->basedoc.task_magic);
253
254 if(This->doc_obj->nscontainer) {
255 This->doc_obj->nscontainer->bscallback = bscallback;
256 nsres = nsIWebNavigation_LoadURI(This->doc_obj->nscontainer->navigation, url,
257 LOAD_FLAGS_NONE, NULL, NULL, NULL);
258 This->doc_obj->nscontainer->bscallback = NULL;
259 if(NS_FAILED(nsres)) {
260 WARN("LoadURI failed: %08x\n", nsres);
261 IUnknown_Release((IUnknown*)bscallback);
262 CoTaskMemFree(url);
263 return E_FAIL;
264 }
265 }
266
267 set_window_bscallback(This->window, bscallback);
268 IUnknown_Release((IUnknown*)bscallback);
269 CoTaskMemFree(url);
270
271 return S_OK;
272 }
273
274 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
275 {
276 window->readystate = readystate;
277 if(window->doc_obj->basedoc.window == window)
278 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
279 }
280
281 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
282 {
283 nsIDOMNode *nsnode;
284 LPCWSTR strw;
285 nsAString nsstr;
286 nsresult nsres;
287
288 if(!This->nsdoc) {
289 WARN("NULL nsdoc\n");
290 return E_UNEXPECTED;
291 }
292
293 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
294 if(NS_FAILED(nsres)) {
295 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
296 return E_FAIL;
297 }
298
299 nsAString_Init(&nsstr, NULL);
300 nsnode_to_nsstring(nsnode, &nsstr);
301 nsIDOMNode_Release(nsnode);
302
303 nsAString_GetData(&nsstr, &strw);
304 TRACE("%s\n", debugstr_w(strw));
305
306 *str = heap_strdupWtoA(strw);
307
308 nsAString_Finish(&nsstr);
309
310 return S_OK;
311 }
312
313
314 /**********************************************************
315 * IPersistMoniker implementation
316 */
317
318 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
319
320 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
321 void **ppvObject)
322 {
323 HTMLDocument *This = PERSISTMON_THIS(iface);
324 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
325 }
326
327 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
328 {
329 HTMLDocument *This = PERSISTMON_THIS(iface);
330 return IHTMLDocument2_AddRef(HTMLDOC(This));
331 }
332
333 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
334 {
335 HTMLDocument *This = PERSISTMON_THIS(iface);
336 return IHTMLDocument2_Release(HTMLDOC(This));
337 }
338
339 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
340 {
341 HTMLDocument *This = PERSISTMON_THIS(iface);
342 return IPersist_GetClassID(PERSIST(This), pClassID);
343 }
344
345 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
346 {
347 HTMLDocument *This = PERSISTMON_THIS(iface);
348
349 TRACE("(%p)\n", This);
350
351 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
352 }
353
354 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
355 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
356 {
357 HTMLDocument *This = PERSISTMON_THIS(iface);
358 HRESULT hres;
359
360 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
361
362 hres = set_moniker(This, pimkName, pibc);
363 if(FAILED(hres))
364 return hres;
365
366 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
367 }
368
369 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
370 LPBC pbc, BOOL fRemember)
371 {
372 HTMLDocument *This = PERSISTMON_THIS(iface);
373 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
374 return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
378 {
379 HTMLDocument *This = PERSISTMON_THIS(iface);
380 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
381 return E_NOTIMPL;
382 }
383
384 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
385 {
386 HTMLDocument *This = PERSISTMON_THIS(iface);
387
388 TRACE("(%p)->(%p)\n", This, ppimkName);
389
390 if(!This->window || !This->window->mon)
391 return E_UNEXPECTED;
392
393 IMoniker_AddRef(This->window->mon);
394 *ppimkName = This->window->mon;
395 return S_OK;
396 }
397
398 static const IPersistMonikerVtbl PersistMonikerVtbl = {
399 PersistMoniker_QueryInterface,
400 PersistMoniker_AddRef,
401 PersistMoniker_Release,
402 PersistMoniker_GetClassID,
403 PersistMoniker_IsDirty,
404 PersistMoniker_Load,
405 PersistMoniker_Save,
406 PersistMoniker_SaveCompleted,
407 PersistMoniker_GetCurMoniker
408 };
409
410 /**********************************************************
411 * IMonikerProp implementation
412 */
413
414 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
415
416 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
417 {
418 HTMLDocument *This = MONPROP_THIS(iface);
419 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
420 }
421
422 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
423 {
424 HTMLDocument *This = MONPROP_THIS(iface);
425 return IHTMLDocument2_AddRef(HTMLDOC(This));
426 }
427
428 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
429 {
430 HTMLDocument *This = MONPROP_THIS(iface);
431 return IHTMLDocument_Release(HTMLDOC(This));
432 }
433
434 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
435 {
436 HTMLDocument *This = MONPROP_THIS(iface);
437
438 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
439
440 switch(mkp) {
441 case MIMETYPEPROP:
442 heap_free(This->doc_obj->mime);
443 This->doc_obj->mime = heap_strdupW(val);
444 break;
445
446 case CLASSIDPROP:
447 break;
448
449 default:
450 FIXME("mkp %d\n", mkp);
451 return E_NOTIMPL;
452 }
453
454 return S_OK;
455 }
456
457 static const IMonikerPropVtbl MonikerPropVtbl = {
458 MonikerProp_QueryInterface,
459 MonikerProp_AddRef,
460 MonikerProp_Release,
461 MonikerProp_PutProperty
462 };
463
464 /**********************************************************
465 * IPersistFile implementation
466 */
467
468 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
469
470 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
471 {
472 HTMLDocument *This = PERSISTFILE_THIS(iface);
473 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
474 }
475
476 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
477 {
478 HTMLDocument *This = PERSISTFILE_THIS(iface);
479 return IHTMLDocument2_AddRef(HTMLDOC(This));
480 }
481
482 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
483 {
484 HTMLDocument *This = PERSISTFILE_THIS(iface);
485 return IHTMLDocument2_Release(HTMLDOC(This));
486 }
487
488 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
489 {
490 HTMLDocument *This = PERSISTFILE_THIS(iface);
491
492 TRACE("(%p)->(%p)\n", This, pClassID);
493
494 if(!pClassID)
495 return E_INVALIDARG;
496
497 *pClassID = CLSID_HTMLDocument;
498 return S_OK;
499 }
500
501 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
502 {
503 HTMLDocument *This = PERSISTFILE_THIS(iface);
504
505 TRACE("(%p)\n", This);
506
507 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
508 }
509
510 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
511 {
512 HTMLDocument *This = PERSISTFILE_THIS(iface);
513 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
514 return E_NOTIMPL;
515 }
516
517 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
518 {
519 HTMLDocument *This = PERSISTFILE_THIS(iface);
520 char *str;
521 DWORD written=0;
522 HANDLE file;
523 HRESULT hres;
524
525 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
526
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());
531 return E_FAIL;
532 }
533
534 hres = get_doc_string(This->doc_node, &str);
535 if(SUCCEEDED(hres))
536 WriteFile(file, str, strlen(str), &written, NULL);
537
538 CloseHandle(file);
539 return hres;
540 }
541
542 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
543 {
544 HTMLDocument *This = PERSISTFILE_THIS(iface);
545 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
546 return E_NOTIMPL;
547 }
548
549 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
550 {
551 HTMLDocument *This = PERSISTFILE_THIS(iface);
552 FIXME("(%p)->(%p)\n", This, pszFileName);
553 return E_NOTIMPL;
554 }
555
556 static const IPersistFileVtbl PersistFileVtbl = {
557 PersistFile_QueryInterface,
558 PersistFile_AddRef,
559 PersistFile_Release,
560 PersistFile_GetClassID,
561 PersistFile_IsDirty,
562 PersistFile_Load,
563 PersistFile_Save,
564 PersistFile_SaveCompleted,
565 PersistFile_GetCurFile
566 };
567
568 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
569
570 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
571 REFIID riid, void **ppv)
572 {
573 HTMLDocument *This = PERSTRINIT_THIS(iface);
574 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
575 }
576
577 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
578 {
579 HTMLDocument *This = PERSTRINIT_THIS(iface);
580 return IHTMLDocument2_AddRef(HTMLDOC(This));
581 }
582
583 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
584 {
585 HTMLDocument *This = PERSTRINIT_THIS(iface);
586 return IHTMLDocument2_Release(HTMLDOC(This));
587 }
588
589 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
590 {
591 HTMLDocument *This = PERSTRINIT_THIS(iface);
592 return IPersist_GetClassID(PERSIST(This), pClassID);
593 }
594
595 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
596 {
597 HTMLDocument *This = PERSTRINIT_THIS(iface);
598
599 TRACE("(%p)\n", This);
600
601 if(This->doc_obj->usermode == EDITMODE)
602 return editor_is_dirty(This);
603
604 return S_FALSE;
605 }
606
607 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
608 {
609 HTMLDocument *This = PERSTRINIT_THIS(iface);
610 IMoniker *mon;
611 HRESULT hres;
612
613 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
614
615 TRACE("(%p)->(%p)\n", This, pStm);
616
617 hres = CreateURLMoniker(NULL, about_blankW, &mon);
618 if(FAILED(hres)) {
619 WARN("CreateURLMoniker failed: %08x\n", hres);
620 return hres;
621 }
622
623 hres = set_moniker(This, mon, NULL);
624 IMoniker_Release(mon);
625 if(FAILED(hres))
626 return hres;
627
628 return channelbsc_load_stream(This->window->bscallback, pStm);
629 }
630
631 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
632 BOOL fClearDirty)
633 {
634 HTMLDocument *This = PERSTRINIT_THIS(iface);
635 char *str;
636 DWORD written=0;
637 HRESULT hres;
638
639 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
640
641 hres = get_doc_string(This->doc_node, &str);
642 if(FAILED(hres))
643 return hres;
644
645 hres = IStream_Write(pStm, str, strlen(str), &written);
646 if(FAILED(hres))
647 FIXME("Write failed: %08x\n", hres);
648
649 heap_free(str);
650
651 if(fClearDirty)
652 set_dirty(This, VARIANT_FALSE);
653
654 return S_OK;
655 }
656
657 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
658 ULARGE_INTEGER *pcbSize)
659 {
660 HTMLDocument *This = PERSTRINIT_THIS(iface);
661 FIXME("(%p)->(%p)\n", This, pcbSize);
662 return E_NOTIMPL;
663 }
664
665 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
666 {
667 HTMLDocument *This = PERSTRINIT_THIS(iface);
668 FIXME("(%p)\n", This);
669 return E_NOTIMPL;
670 }
671
672 #undef PERSTRINIT_THIS
673
674 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
675 PersistStreamInit_QueryInterface,
676 PersistStreamInit_AddRef,
677 PersistStreamInit_Release,
678 PersistStreamInit_GetClassID,
679 PersistStreamInit_IsDirty,
680 PersistStreamInit_Load,
681 PersistStreamInit_Save,
682 PersistStreamInit_GetSizeMax,
683 PersistStreamInit_InitNew
684 };
685
686 /**********************************************************
687 * IPersistHistory implementation
688 */
689
690 #define PERSISTHIST_THIS(iface) DEFINE_THIS(HTMLDocument, PersistHistory, iface)
691
692 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppvObject)
693 {
694 HTMLDocument *This = PERSISTHIST_THIS(iface);
695 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
696 }
697
698 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
699 {
700 HTMLDocument *This = PERSISTHIST_THIS(iface);
701 return IHTMLDocument2_AddRef(HTMLDOC(This));
702 }
703
704 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
705 {
706 HTMLDocument *This = PERSISTHIST_THIS(iface);
707 return IHTMLDocument2_Release(HTMLDOC(This));
708 }
709
710 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
711 {
712 HTMLDocument *This = PERSISTHIST_THIS(iface);
713 return IPersist_GetClassID(PERSIST(This), pClassID);
714 }
715
716 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
717 {
718 HTMLDocument *This = PERSISTHIST_THIS(iface);
719 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
720 return E_NOTIMPL;
721 }
722
723 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
724 {
725 HTMLDocument *This = PERSISTHIST_THIS(iface);
726 FIXME("(%p)->(%p)\n", This, pStream);
727 return E_NOTIMPL;
728 }
729
730 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
731 {
732 HTMLDocument *This = PERSISTHIST_THIS(iface);
733 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
734 return E_NOTIMPL;
735 }
736
737 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
738 {
739 HTMLDocument *This = PERSISTHIST_THIS(iface);
740 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
741 return E_NOTIMPL;
742 }
743
744 #undef PERSISTHIST_THIS
745
746 static const IPersistHistoryVtbl PersistHistoryVtbl = {
747 PersistHistory_QueryInterface,
748 PersistHistory_AddRef,
749 PersistHistory_Release,
750 PersistHistory_GetClassID,
751 PersistHistory_LoadHistory,
752 PersistHistory_SaveHistory,
753 PersistHistory_SetPositionCookie,
754 PersistHistory_GetPositionCookie
755 };
756
757 void HTMLDocument_Persist_Init(HTMLDocument *This)
758 {
759 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
760 This->lpPersistFileVtbl = &PersistFileVtbl;
761 This->lpMonikerPropVtbl = &MonikerPropVtbl;
762 This->lpPersistStreamInitVtbl = &PersistStreamInitVtbl;
763 This->lpPersistHistoryVtbl = &PersistHistoryVtbl;
764 }