mshtml: COM cleanup for the IMonikerProp iface.
[wine/wine-gecko.git] / dlls / mshtml / persist.c
blob24d3c21f6a5ef8b3cf40f900b599b456851ae2de
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "shlguid.h"
33 #include "idispids.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
39 #include "htmlevent.h"
40 #include "resource.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
44 typedef struct {
45 task_t header;
46 HTMLDocumentObj *doc;
47 BOOL set_download;
48 LPOLESTR url;
49 } download_proc_task_t;
51 static BOOL use_gecko_script(LPCWSTR url)
53 static const WCHAR fileW[] = {'f','i','l','e',':'};
54 static const WCHAR aboutW[] = {'a','b','o','u','t',':'};
55 static const WCHAR resW[] = {'r','e','s',':'};
57 return strncmpiW(fileW, url, sizeof(fileW)/sizeof(WCHAR))
58 && strncmpiW(aboutW, url, sizeof(aboutW)/sizeof(WCHAR))
59 && strncmpiW(resW, url, sizeof(resW)/sizeof(WCHAR));
62 void set_current_mon(HTMLWindow *This, IMoniker *mon)
64 HRESULT hres;
66 if(This->mon) {
67 IMoniker_Release(This->mon);
68 This->mon = NULL;
71 if(This->url) {
72 CoTaskMemFree(This->url);
73 This->url = NULL;
76 if(!mon)
77 return;
79 IMoniker_AddRef(mon);
80 This->mon = mon;
82 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
83 if(FAILED(hres))
84 WARN("GetDisplayName failed: %08x\n", hres);
86 set_script_mode(This, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
89 static void set_progress_proc(task_t *_task)
91 docobj_task_t *task = (docobj_task_t*)_task;
92 IOleCommandTarget *olecmd = NULL;
93 HTMLDocumentObj *doc = task->doc;
94 HRESULT hres;
96 TRACE("(%p)\n", doc);
98 if(doc->client)
99 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
101 if(olecmd) {
102 VARIANT progress_max, progress;
104 V_VT(&progress_max) = VT_I4;
105 V_I4(&progress_max) = 0; /* FIXME */
106 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
107 &progress_max, NULL);
109 V_VT(&progress) = VT_I4;
110 V_I4(&progress) = 0; /* FIXME */
111 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
112 &progress, NULL);
113 IOleCommandTarget_Release(olecmd);
116 if(doc->usermode == EDITMODE && doc->hostui) {
117 DOCHOSTUIINFO hostinfo;
119 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
120 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
121 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
122 if(SUCCEEDED(hres))
123 /* FIXME: use hostinfo */
124 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
125 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
126 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
130 static void set_downloading_proc(task_t *_task)
132 download_proc_task_t *task = (download_proc_task_t*)_task;
133 HTMLDocumentObj *doc = task->doc;
134 IOleCommandTarget *olecmd;
135 HRESULT hres;
137 TRACE("(%p)\n", doc);
139 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
140 CoTaskMemFree(task->url);
142 if(!doc->client)
143 return;
145 if(task->set_download) {
146 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
147 if(SUCCEEDED(hres)) {
148 VARIANT var;
150 V_VT(&var) = VT_I4;
151 V_I4(&var) = 1;
153 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
154 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
155 IOleCommandTarget_Release(olecmd);
158 doc->download_state = 1;
161 if(doc->view_sink)
162 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
164 if(doc->hostui) {
165 IDropTarget *drop_target = NULL;
167 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
168 if(drop_target) {
169 FIXME("Use IDropTarget\n");
170 IDropTarget_Release(drop_target);
175 HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, nsChannelBSC *async_bsc, BOOL set_download)
177 nsChannelBSC *bscallback;
178 docobj_task_t *task;
179 download_proc_task_t *download_task;
180 nsWineURI *nsuri;
181 LPOLESTR url;
182 HRESULT hres;
184 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
185 if(FAILED(hres)) {
186 WARN("GetDiaplayName failed: %08x\n", hres);
187 return hres;
190 TRACE("got url: %s\n", debugstr_w(url));
192 if(This->doc_obj->client) {
193 VARIANT silent, offline;
195 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
196 if(SUCCEEDED(hres)) {
197 if(V_VT(&silent) != VT_BOOL)
198 WARN("V_VT(silent) = %d\n", V_VT(&silent));
199 else if(V_BOOL(&silent))
200 FIXME("silent == true\n");
203 hres = get_client_disp_property(This->doc_obj->client,
204 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
205 if(SUCCEEDED(hres)) {
206 if(V_VT(&silent) != VT_BOOL)
207 WARN("V_VT(offline) = %d\n", V_VT(&silent));
208 else if(V_BOOL(&silent))
209 FIXME("offline == true\n");
213 if(This->window->mon) {
214 update_doc(This, UPDATE_TITLE|UPDATE_UI);
215 }else {
216 update_doc(This, UPDATE_TITLE);
217 set_current_mon(This->window, mon);
220 set_ready_state(This->window, READYSTATE_LOADING);
222 if(This->doc_obj->client) {
223 IOleCommandTarget *cmdtrg = NULL;
225 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
226 (void**)&cmdtrg);
227 if(SUCCEEDED(hres)) {
228 VARIANT var, out;
230 if(!async_bsc) {
231 V_VT(&var) = VT_I4;
232 V_I4(&var) = 0;
233 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
234 }else {
235 V_VT(&var) = VT_UNKNOWN;
236 V_UNKNOWN(&var) = (IUnknown*)HTMLWINDOW2(This->window);
237 V_VT(&out) = VT_EMPTY;
238 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
239 if(SUCCEEDED(hres))
240 VariantClear(&out);
243 IOleCommandTarget_Release(cmdtrg);
247 hres = create_doc_uri(This->window, url, &nsuri);
249 if(SUCCEEDED(hres))
251 if(async_bsc) {
252 bscallback = async_bsc;
253 }else {
254 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
258 if(SUCCEEDED(hres))
260 hres = load_nsuri(This->window, nsuri, bscallback, LOAD_INITIAL_DOCUMENT_URI);
261 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
262 if(SUCCEEDED(hres))
263 set_window_bscallback(This->window, bscallback);
264 if(bscallback != async_bsc)
265 IUnknown_Release((IUnknown*)bscallback);
268 if(FAILED(hres))
270 CoTaskMemFree(url);
271 return hres;
274 HTMLDocument_LockContainer(This->doc_obj, TRUE);
276 if(This->doc_obj->frame) {
277 task = heap_alloc(sizeof(docobj_task_t));
278 task->doc = This->doc_obj;
279 push_task(&task->header, set_progress_proc, This->doc_obj->basedoc.task_magic);
282 download_task = heap_alloc(sizeof(download_proc_task_t));
283 download_task->doc = This->doc_obj;
284 download_task->set_download = set_download;
285 download_task->url = url;
286 push_task(&download_task->header, set_downloading_proc, This->doc_obj->basedoc.task_magic);
288 return S_OK;
291 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
293 window->readystate = readystate;
295 if(window->doc_obj && window->doc_obj->basedoc.window == window)
296 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
298 fire_event(window->doc, EVENTID_READYSTATECHANGE, FALSE, window->doc->node.nsnode, NULL);
300 if(window->frame_element)
301 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
302 TRUE, window->frame_element->element.node.nsnode, NULL);
305 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
307 nsIDOMNode *nsnode;
308 LPCWSTR strw;
309 nsAString nsstr;
310 nsresult nsres;
312 if(!This->nsdoc) {
313 WARN("NULL nsdoc\n");
314 return E_UNEXPECTED;
317 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
318 if(NS_FAILED(nsres)) {
319 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
320 return E_FAIL;
323 nsAString_Init(&nsstr, NULL);
324 nsnode_to_nsstring(nsnode, &nsstr);
325 nsIDOMNode_Release(nsnode);
327 nsAString_GetData(&nsstr, &strw);
328 TRACE("%s\n", debugstr_w(strw));
330 *str = heap_strdupWtoA(strw);
332 nsAString_Finish(&nsstr);
334 return S_OK;
338 /**********************************************************
339 * IPersistMoniker implementation
342 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
344 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
347 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
349 HTMLDocument *This = impl_from_IPersistMoniker(iface);
350 return htmldoc_query_interface(This, riid, ppv);
353 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
355 HTMLDocument *This = impl_from_IPersistMoniker(iface);
356 return htmldoc_addref(This);
359 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
361 HTMLDocument *This = impl_from_IPersistMoniker(iface);
362 return htmldoc_release(This);
365 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
367 HTMLDocument *This = impl_from_IPersistMoniker(iface);
368 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
371 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
373 HTMLDocument *This = impl_from_IPersistMoniker(iface);
375 TRACE("(%p)\n", This);
377 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
380 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
381 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
383 HTMLDocument *This = impl_from_IPersistMoniker(iface);
384 HRESULT hres;
386 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
388 if(pibc) {
389 IUnknown *unk = NULL;
391 /* FIXME:
392 * Use params:
393 * "__PrecreatedObject"
394 * "BIND_CONTEXT_PARAM"
395 * "__HTMLLOADOPTIONS"
396 * "__DWNBINDINFO"
397 * "URL Context"
398 * "_ITransData_Object_"
399 * "_EnumFORMATETC_"
402 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
403 if(unk) {
404 IOleClientSite *client = NULL;
406 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
407 if(SUCCEEDED(hres)) {
408 TRACE("Got client site %p\n", client);
409 IOleObject_SetClientSite(OLEOBJ(This), client);
410 IOleClientSite_Release(client);
413 IUnknown_Release(unk);
417 hres = set_moniker(This, pimkName, pibc, NULL, TRUE);
418 if(FAILED(hres))
419 return hres;
421 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
424 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
425 LPBC pbc, BOOL fRemember)
427 HTMLDocument *This = impl_from_IPersistMoniker(iface);
428 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
429 return E_NOTIMPL;
432 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
434 HTMLDocument *This = impl_from_IPersistMoniker(iface);
435 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
436 return E_NOTIMPL;
439 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
441 HTMLDocument *This = impl_from_IPersistMoniker(iface);
443 TRACE("(%p)->(%p)\n", This, ppimkName);
445 if(!This->window || !This->window->mon)
446 return E_UNEXPECTED;
448 IMoniker_AddRef(This->window->mon);
449 *ppimkName = This->window->mon;
450 return S_OK;
453 static const IPersistMonikerVtbl PersistMonikerVtbl = {
454 PersistMoniker_QueryInterface,
455 PersistMoniker_AddRef,
456 PersistMoniker_Release,
457 PersistMoniker_GetClassID,
458 PersistMoniker_IsDirty,
459 PersistMoniker_Load,
460 PersistMoniker_Save,
461 PersistMoniker_SaveCompleted,
462 PersistMoniker_GetCurMoniker
465 /**********************************************************
466 * IMonikerProp implementation
469 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
471 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
474 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
476 HTMLDocument *This = impl_from_IMonikerProp(iface);
477 return htmldoc_query_interface(This, riid, ppv);
480 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
482 HTMLDocument *This = impl_from_IMonikerProp(iface);
483 return htmldoc_addref(This);
486 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
488 HTMLDocument *This = impl_from_IMonikerProp(iface);
489 return htmldoc_release(This);
492 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
494 HTMLDocument *This = impl_from_IMonikerProp(iface);
496 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
498 switch(mkp) {
499 case MIMETYPEPROP:
500 heap_free(This->doc_obj->mime);
501 This->doc_obj->mime = heap_strdupW(val);
502 break;
504 case CLASSIDPROP:
505 break;
507 default:
508 FIXME("mkp %d\n", mkp);
509 return E_NOTIMPL;
512 return S_OK;
515 static const IMonikerPropVtbl MonikerPropVtbl = {
516 MonikerProp_QueryInterface,
517 MonikerProp_AddRef,
518 MonikerProp_Release,
519 MonikerProp_PutProperty
522 /**********************************************************
523 * IPersistFile implementation
526 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
528 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
531 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
533 HTMLDocument *This = impl_from_IPersistFile(iface);
534 return htmldoc_query_interface(This, riid, ppv);
537 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
539 HTMLDocument *This = impl_from_IPersistFile(iface);
540 return htmldoc_addref(This);
543 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
545 HTMLDocument *This = impl_from_IPersistFile(iface);
546 return htmldoc_release(This);
549 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
551 HTMLDocument *This = impl_from_IPersistFile(iface);
553 TRACE("(%p)->(%p)\n", This, pClassID);
555 if(!pClassID)
556 return E_INVALIDARG;
558 *pClassID = CLSID_HTMLDocument;
559 return S_OK;
562 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
564 HTMLDocument *This = impl_from_IPersistFile(iface);
566 TRACE("(%p)\n", This);
568 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
571 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
573 HTMLDocument *This = impl_from_IPersistFile(iface);
574 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
575 return E_NOTIMPL;
578 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
580 HTMLDocument *This = impl_from_IPersistFile(iface);
581 char *str;
582 DWORD written=0;
583 HANDLE file;
584 HRESULT hres;
586 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
588 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
589 FILE_ATTRIBUTE_NORMAL, NULL);
590 if(file == INVALID_HANDLE_VALUE) {
591 WARN("Could not create file: %u\n", GetLastError());
592 return E_FAIL;
595 hres = get_doc_string(This->doc_node, &str);
596 if(SUCCEEDED(hres))
597 WriteFile(file, str, strlen(str), &written, NULL);
599 CloseHandle(file);
600 return hres;
603 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
605 HTMLDocument *This = impl_from_IPersistFile(iface);
606 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
607 return E_NOTIMPL;
610 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
612 HTMLDocument *This = impl_from_IPersistFile(iface);
613 FIXME("(%p)->(%p)\n", This, pszFileName);
614 return E_NOTIMPL;
617 static const IPersistFileVtbl PersistFileVtbl = {
618 PersistFile_QueryInterface,
619 PersistFile_AddRef,
620 PersistFile_Release,
621 PersistFile_GetClassID,
622 PersistFile_IsDirty,
623 PersistFile_Load,
624 PersistFile_Save,
625 PersistFile_SaveCompleted,
626 PersistFile_GetCurFile
629 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
631 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
634 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
635 REFIID riid, void **ppv)
637 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
638 return htmldoc_query_interface(This, riid, ppv);
641 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
643 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
644 return htmldoc_addref(This);
647 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
649 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
650 return htmldoc_release(This);
653 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
655 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
656 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
659 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
661 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
663 TRACE("(%p)\n", This);
665 if(This->doc_obj->usermode == EDITMODE)
666 return editor_is_dirty(This);
668 return S_FALSE;
671 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
673 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
674 IMoniker *mon;
675 HRESULT hres;
677 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
679 TRACE("(%p)->(%p)\n", This, pStm);
681 hres = CreateURLMoniker(NULL, about_blankW, &mon);
682 if(FAILED(hres)) {
683 WARN("CreateURLMoniker failed: %08x\n", hres);
684 return hres;
687 hres = set_moniker(This, mon, NULL, NULL, TRUE);
688 IMoniker_Release(mon);
689 if(FAILED(hres))
690 return hres;
692 return channelbsc_load_stream(This->window->bscallback, pStm);
695 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
696 BOOL fClearDirty)
698 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
699 char *str;
700 DWORD written=0;
701 HRESULT hres;
703 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
705 hres = get_doc_string(This->doc_node, &str);
706 if(FAILED(hres))
707 return hres;
709 hres = IStream_Write(pStm, str, strlen(str), &written);
710 if(FAILED(hres))
711 FIXME("Write failed: %08x\n", hres);
713 heap_free(str);
715 if(fClearDirty)
716 set_dirty(This, VARIANT_FALSE);
718 return S_OK;
721 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
722 ULARGE_INTEGER *pcbSize)
724 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
725 FIXME("(%p)->(%p)\n", This, pcbSize);
726 return E_NOTIMPL;
729 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
731 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
732 IMoniker *mon;
733 HRESULT hres;
735 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
737 TRACE("(%p)\n", This);
739 hres = CreateURLMoniker(NULL, about_blankW, &mon);
740 if(FAILED(hres)) {
741 WARN("CreateURLMoniker failed: %08x\n", hres);
742 return hres;
745 hres = set_moniker(This, mon, NULL, NULL, FALSE);
746 IMoniker_Release(mon);
747 if(FAILED(hres))
748 return hres;
750 return channelbsc_load_stream(This->window->bscallback, NULL);
753 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
754 PersistStreamInit_QueryInterface,
755 PersistStreamInit_AddRef,
756 PersistStreamInit_Release,
757 PersistStreamInit_GetClassID,
758 PersistStreamInit_IsDirty,
759 PersistStreamInit_Load,
760 PersistStreamInit_Save,
761 PersistStreamInit_GetSizeMax,
762 PersistStreamInit_InitNew
765 /**********************************************************
766 * IPersistHistory implementation
769 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
771 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
774 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
776 HTMLDocument *This = impl_from_IPersistHistory(iface);
777 return htmldoc_query_interface(This, riid, ppv);
780 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
782 HTMLDocument *This = impl_from_IPersistHistory(iface);
783 return htmldoc_addref(This);
786 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
788 HTMLDocument *This = impl_from_IPersistHistory(iface);
789 return htmldoc_release(This);
792 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
794 HTMLDocument *This = impl_from_IPersistHistory(iface);
795 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
798 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
800 HTMLDocument *This = impl_from_IPersistHistory(iface);
801 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
802 return E_NOTIMPL;
805 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
807 HTMLDocument *This = impl_from_IPersistHistory(iface);
808 FIXME("(%p)->(%p)\n", This, pStream);
809 return E_NOTIMPL;
812 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
814 HTMLDocument *This = impl_from_IPersistHistory(iface);
815 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
816 return E_NOTIMPL;
819 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
821 HTMLDocument *This = impl_from_IPersistHistory(iface);
822 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
823 return E_NOTIMPL;
826 static const IPersistHistoryVtbl PersistHistoryVtbl = {
827 PersistHistory_QueryInterface,
828 PersistHistory_AddRef,
829 PersistHistory_Release,
830 PersistHistory_GetClassID,
831 PersistHistory_LoadHistory,
832 PersistHistory_SaveHistory,
833 PersistHistory_SetPositionCookie,
834 PersistHistory_GetPositionCookie
837 void HTMLDocument_Persist_Init(HTMLDocument *This)
839 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
840 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
841 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
842 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
843 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;