msxml3: Get rid of libxml2 output buffer implementation.
[wine/multimedia.git] / dlls / mshtml / persist.c
blob4167659d997c7bebc4bb4aa338b7e006f323dfdd
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 #define NO_SHLWAPI_REG
36 #include "shlwapi.h"
38 #include "wine/debug.h"
40 #include "mshtml_private.h"
41 #include "htmlevent.h"
42 #include "binding.h"
43 #include "resource.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
47 typedef struct {
48 task_t header;
49 HTMLDocumentObj *doc;
50 BOOL set_download;
51 LPOLESTR url;
52 } download_proc_task_t;
54 static BOOL use_gecko_script(HTMLWindow *window)
56 DWORD zone, scheme;
57 HRESULT hres;
59 hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0);
60 if(FAILED(hres)) {
61 WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres);
62 return TRUE;
65 TRACE("zone %d\n", zone);
66 if(zone == URLZONE_LOCAL_MACHINE || zone == URLZONE_TRUSTED || !window->uri)
67 return FALSE;
69 hres = IUri_GetScheme(window->uri, &scheme);
70 return FAILED(hres) || scheme != URL_SCHEME_ABOUT;
73 void set_current_uri(HTMLWindow *window, IUri *uri)
75 if(window->uri) {
76 IUri_Release(window->uri);
77 window->uri = NULL;
80 if(window->url) {
81 SysFreeString(window->url);
82 window->url = NULL;
85 if(!uri)
86 return;
88 IUri_AddRef(uri);
89 window->uri = uri;
91 IUri_GetDisplayUri(uri, &window->url);
94 void set_current_mon(HTMLWindow *This, IMoniker *mon)
96 IUriContainer *uri_container;
97 IUri *uri = NULL;
98 HRESULT hres;
100 if(This->mon) {
101 IMoniker_Release(This->mon);
102 This->mon = NULL;
106 if(!mon)
107 return;
109 IMoniker_AddRef(mon);
110 This->mon = mon;
112 hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
113 if(SUCCEEDED(hres)) {
114 hres = IUriContainer_GetIUri(uri_container, &uri);
115 IUriContainer_Release(uri_container);
116 if(hres != S_OK) {
117 WARN("GetIUri failed: %08x\n", hres);
118 uri = NULL;
122 if(!uri) {
123 WCHAR *url;
125 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
126 if(SUCCEEDED(hres)) {
127 hres = CreateUri(url, 0, 0, &uri);
128 if(FAILED(hres)) {
129 WARN("CrateUri failed: %08x\n", hres);
130 set_current_uri(This, NULL);
131 This->url = SysAllocString(url);
132 CoTaskMemFree(url);
133 return;
135 CoTaskMemFree(url);
136 }else {
137 WARN("GetDisplayName failed: %08x\n", hres);
141 set_current_uri(This, uri);
142 if(uri)
143 IUri_Release(uri);
144 set_script_mode(This, use_gecko_script(This) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
147 void set_download_state(HTMLDocumentObj *doc, int state)
149 if(doc->client) {
150 IOleCommandTarget *olecmd;
151 HRESULT hres;
153 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
154 if(SUCCEEDED(hres)) {
155 VARIANT var;
157 V_VT(&var) = VT_I4;
158 V_I4(&var) = state;
160 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
161 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
162 IOleCommandTarget_Release(olecmd);
166 doc->download_state = state;
169 static void set_progress_proc(task_t *_task)
171 docobj_task_t *task = (docobj_task_t*)_task;
172 IOleCommandTarget *olecmd = NULL;
173 HTMLDocumentObj *doc = task->doc;
174 HRESULT hres;
176 TRACE("(%p)\n", doc);
178 if(doc->client)
179 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
181 if(olecmd) {
182 VARIANT progress_max, progress;
184 V_VT(&progress_max) = VT_I4;
185 V_I4(&progress_max) = 0; /* FIXME */
186 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
187 &progress_max, NULL);
189 V_VT(&progress) = VT_I4;
190 V_I4(&progress) = 0; /* FIXME */
191 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
192 &progress, NULL);
193 IOleCommandTarget_Release(olecmd);
196 if(doc->usermode == EDITMODE && doc->hostui) {
197 DOCHOSTUIINFO hostinfo;
199 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
200 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
201 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
202 if(SUCCEEDED(hres))
203 /* FIXME: use hostinfo */
204 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
205 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
206 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
210 static void set_downloading_proc(task_t *_task)
212 download_proc_task_t *task = (download_proc_task_t*)_task;
213 HTMLDocumentObj *doc = task->doc;
214 HRESULT hres;
216 TRACE("(%p)\n", doc);
218 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
220 if(task->set_download)
221 set_download_state(doc, 1);
223 if(!doc->client)
224 return;
226 if(doc->view_sink)
227 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
229 if(doc->hostui) {
230 IDropTarget *drop_target = NULL;
232 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
233 if(SUCCEEDED(hres)) {
234 FIXME("Use IDropTarget\n");
235 IDropTarget_Release(drop_target);
240 static void set_downloading_task_destr(task_t *_task)
242 download_proc_task_t *task = (download_proc_task_t*)_task;
244 CoTaskMemFree(task->url);
245 heap_free(task);
248 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, BOOL navigated_binding)
250 HRESULT hres;
252 if(This->doc_obj->client) {
253 VARIANT silent, offline;
255 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
256 if(SUCCEEDED(hres)) {
257 if(V_VT(&silent) != VT_BOOL)
258 WARN("V_VT(silent) = %d\n", V_VT(&silent));
259 else if(V_BOOL(&silent))
260 FIXME("silent == true\n");
263 hres = get_client_disp_property(This->doc_obj->client,
264 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
265 if(SUCCEEDED(hres)) {
266 if(V_VT(&offline) != VT_BOOL)
267 WARN("V_VT(offline) = %d\n", V_VT(&offline));
268 else if(V_BOOL(&offline))
269 FIXME("offline == true\n");
273 if(This->window->mon) {
274 update_doc(This, UPDATE_TITLE|UPDATE_UI);
275 }else {
276 update_doc(This, UPDATE_TITLE);
277 set_current_mon(This->window, mon);
280 if(This->doc_obj->client) {
281 IOleCommandTarget *cmdtrg = NULL;
283 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
284 (void**)&cmdtrg);
285 if(SUCCEEDED(hres)) {
286 VARIANT var, out;
288 if(!navigated_binding) {
289 V_VT(&var) = VT_I4;
290 V_I4(&var) = 0;
291 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
292 }else {
293 V_VT(&var) = VT_UNKNOWN;
294 V_UNKNOWN(&var) = (IUnknown*)&This->window->IHTMLWindow2_iface;
295 V_VT(&out) = VT_EMPTY;
296 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
297 if(SUCCEEDED(hres))
298 VariantClear(&out);
301 IOleCommandTarget_Release(cmdtrg);
306 HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, nsChannelBSC *async_bsc, BOOL set_download)
308 download_proc_task_t *download_task;
309 nsChannelBSC *bscallback;
310 nsWineURI *nsuri;
311 LPOLESTR url;
312 HRESULT hres;
314 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
315 if(FAILED(hres)) {
316 WARN("GetDiaplayName failed: %08x\n", hres);
317 return hres;
320 TRACE("got url: %s\n", debugstr_w(url));
322 set_ready_state(This->window, READYSTATE_LOADING);
324 hres = create_doc_uri(This->window, url, &nsuri);
325 if(SUCCEEDED(hres)) {
326 if(async_bsc)
327 bscallback = async_bsc;
328 else
329 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
332 if(SUCCEEDED(hres)) {
333 remove_target_tasks(This->task_magic);
334 abort_document_bindings(This->doc_node);
336 hres = load_nsuri(This->window, nsuri, bscallback, 0/*LOAD_INITIAL_DOCUMENT_URI*/);
337 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
338 if(SUCCEEDED(hres))
339 set_window_bscallback(This->window, bscallback);
340 if(bscallback != async_bsc)
341 IUnknown_Release((IUnknown*)bscallback);
344 if(FAILED(hres)) {
345 CoTaskMemFree(url);
346 return hres;
349 HTMLDocument_LockContainer(This->doc_obj, TRUE);
351 if(This->doc_obj->frame) {
352 docobj_task_t *task;
354 task = heap_alloc(sizeof(docobj_task_t));
355 task->doc = This->doc_obj;
356 push_task(&task->header, set_progress_proc, NULL, This->doc_obj->basedoc.task_magic);
359 download_task = heap_alloc(sizeof(download_proc_task_t));
360 download_task->doc = This->doc_obj;
361 download_task->set_download = set_download;
362 download_task->url = url;
363 push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, This->doc_obj->basedoc.task_magic);
365 return S_OK;
368 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
370 window->readystate = readystate;
372 if(window->doc_obj && window->doc_obj->basedoc.window == window)
373 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
375 fire_event(window->doc, EVENTID_READYSTATECHANGE, FALSE, window->doc->node.nsnode, NULL);
377 if(window->frame_element)
378 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
379 TRUE, window->frame_element->element.node.nsnode, NULL);
382 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
384 nsIDOMNode *nsnode;
385 LPCWSTR strw;
386 nsAString nsstr;
387 nsresult nsres;
388 HRESULT hres;
390 if(!This->nsdoc) {
391 WARN("NULL nsdoc\n");
392 return E_UNEXPECTED;
395 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
396 if(NS_FAILED(nsres)) {
397 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
398 return E_FAIL;
401 nsAString_Init(&nsstr, NULL);
402 hres = nsnode_to_nsstring(nsnode, &nsstr);
403 nsIDOMNode_Release(nsnode);
404 if(FAILED(hres)) {
405 nsAString_Finish(&nsstr);
406 return hres;
409 nsAString_GetData(&nsstr, &strw);
410 TRACE("%s\n", debugstr_w(strw));
412 *str = heap_strdupWtoA(strw);
414 nsAString_Finish(&nsstr);
416 if(!*str)
417 return E_OUTOFMEMORY;
418 return S_OK;
422 /**********************************************************
423 * IPersistMoniker implementation
426 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
428 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
431 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
433 HTMLDocument *This = impl_from_IPersistMoniker(iface);
434 return htmldoc_query_interface(This, riid, ppv);
437 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
439 HTMLDocument *This = impl_from_IPersistMoniker(iface);
440 return htmldoc_addref(This);
443 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
445 HTMLDocument *This = impl_from_IPersistMoniker(iface);
446 return htmldoc_release(This);
449 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
451 HTMLDocument *This = impl_from_IPersistMoniker(iface);
452 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
455 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
457 HTMLDocument *This = impl_from_IPersistMoniker(iface);
459 TRACE("(%p)\n", This);
461 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
464 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
465 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
467 HTMLDocument *This = impl_from_IPersistMoniker(iface);
468 HRESULT hres;
470 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
472 if(pibc) {
473 IUnknown *unk = NULL;
475 /* FIXME:
476 * Use params:
477 * "__PrecreatedObject"
478 * "BIND_CONTEXT_PARAM"
479 * "__HTMLLOADOPTIONS"
480 * "__DWNBINDINFO"
481 * "URL Context"
482 * "_ITransData_Object_"
483 * "_EnumFORMATETC_"
486 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
487 if(unk) {
488 IOleClientSite *client = NULL;
490 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
491 if(SUCCEEDED(hres)) {
492 TRACE("Got client site %p\n", client);
493 IOleObject_SetClientSite(&This->IOleObject_iface, client);
494 IOleClientSite_Release(client);
497 IUnknown_Release(unk);
501 prepare_for_binding(This, pimkName, FALSE);
502 hres = set_moniker(This, pimkName, pibc, NULL, TRUE);
503 if(FAILED(hres))
504 return hres;
506 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
509 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
510 LPBC pbc, BOOL fRemember)
512 HTMLDocument *This = impl_from_IPersistMoniker(iface);
513 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
514 return E_NOTIMPL;
517 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
519 HTMLDocument *This = impl_from_IPersistMoniker(iface);
520 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
521 return E_NOTIMPL;
524 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
526 HTMLDocument *This = impl_from_IPersistMoniker(iface);
528 TRACE("(%p)->(%p)\n", This, ppimkName);
530 if(!This->window || !This->window->mon)
531 return E_UNEXPECTED;
533 IMoniker_AddRef(This->window->mon);
534 *ppimkName = This->window->mon;
535 return S_OK;
538 static const IPersistMonikerVtbl PersistMonikerVtbl = {
539 PersistMoniker_QueryInterface,
540 PersistMoniker_AddRef,
541 PersistMoniker_Release,
542 PersistMoniker_GetClassID,
543 PersistMoniker_IsDirty,
544 PersistMoniker_Load,
545 PersistMoniker_Save,
546 PersistMoniker_SaveCompleted,
547 PersistMoniker_GetCurMoniker
550 /**********************************************************
551 * IMonikerProp implementation
554 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
556 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
559 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
561 HTMLDocument *This = impl_from_IMonikerProp(iface);
562 return htmldoc_query_interface(This, riid, ppv);
565 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
567 HTMLDocument *This = impl_from_IMonikerProp(iface);
568 return htmldoc_addref(This);
571 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
573 HTMLDocument *This = impl_from_IMonikerProp(iface);
574 return htmldoc_release(This);
577 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
579 HTMLDocument *This = impl_from_IMonikerProp(iface);
581 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
583 switch(mkp) {
584 case MIMETYPEPROP:
585 heap_free(This->doc_obj->mime);
586 This->doc_obj->mime = heap_strdupW(val);
587 break;
589 case CLASSIDPROP:
590 break;
592 default:
593 FIXME("mkp %d\n", mkp);
594 return E_NOTIMPL;
597 return S_OK;
600 static const IMonikerPropVtbl MonikerPropVtbl = {
601 MonikerProp_QueryInterface,
602 MonikerProp_AddRef,
603 MonikerProp_Release,
604 MonikerProp_PutProperty
607 /**********************************************************
608 * IPersistFile implementation
611 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
613 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
616 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
618 HTMLDocument *This = impl_from_IPersistFile(iface);
619 return htmldoc_query_interface(This, riid, ppv);
622 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
624 HTMLDocument *This = impl_from_IPersistFile(iface);
625 return htmldoc_addref(This);
628 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
630 HTMLDocument *This = impl_from_IPersistFile(iface);
631 return htmldoc_release(This);
634 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
636 HTMLDocument *This = impl_from_IPersistFile(iface);
638 TRACE("(%p)->(%p)\n", This, pClassID);
640 if(!pClassID)
641 return E_INVALIDARG;
643 *pClassID = CLSID_HTMLDocument;
644 return S_OK;
647 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
649 HTMLDocument *This = impl_from_IPersistFile(iface);
651 TRACE("(%p)\n", This);
653 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
656 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
658 HTMLDocument *This = impl_from_IPersistFile(iface);
659 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
660 return E_NOTIMPL;
663 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
665 HTMLDocument *This = impl_from_IPersistFile(iface);
666 char *str;
667 DWORD written=0;
668 HANDLE file;
669 HRESULT hres;
671 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
673 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
674 FILE_ATTRIBUTE_NORMAL, NULL);
675 if(file == INVALID_HANDLE_VALUE) {
676 WARN("Could not create file: %u\n", GetLastError());
677 return E_FAIL;
680 hres = get_doc_string(This->doc_node, &str);
681 if(SUCCEEDED(hres))
682 WriteFile(file, str, strlen(str), &written, NULL);
684 CloseHandle(file);
685 return hres;
688 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
690 HTMLDocument *This = impl_from_IPersistFile(iface);
691 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
692 return E_NOTIMPL;
695 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
697 HTMLDocument *This = impl_from_IPersistFile(iface);
698 FIXME("(%p)->(%p)\n", This, pszFileName);
699 return E_NOTIMPL;
702 static const IPersistFileVtbl PersistFileVtbl = {
703 PersistFile_QueryInterface,
704 PersistFile_AddRef,
705 PersistFile_Release,
706 PersistFile_GetClassID,
707 PersistFile_IsDirty,
708 PersistFile_Load,
709 PersistFile_Save,
710 PersistFile_SaveCompleted,
711 PersistFile_GetCurFile
714 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
716 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
719 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
720 REFIID riid, void **ppv)
722 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
723 return htmldoc_query_interface(This, riid, ppv);
726 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
728 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
729 return htmldoc_addref(This);
732 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
734 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
735 return htmldoc_release(This);
738 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
740 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
741 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
744 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
746 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
748 TRACE("(%p)\n", This);
750 if(This->doc_obj->usermode == EDITMODE)
751 return editor_is_dirty(This);
753 return S_FALSE;
756 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
758 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
759 IMoniker *mon;
760 HRESULT hres;
762 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
764 TRACE("(%p)->(%p)\n", This, pStm);
766 hres = CreateURLMoniker(NULL, about_blankW, &mon);
767 if(FAILED(hres)) {
768 WARN("CreateURLMoniker failed: %08x\n", hres);
769 return hres;
772 prepare_for_binding(This, mon, FALSE);
773 hres = set_moniker(This, mon, NULL, NULL, TRUE);
774 IMoniker_Release(mon);
775 if(FAILED(hres))
776 return hres;
778 return channelbsc_load_stream(This->window->bscallback, pStm);
781 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
782 BOOL fClearDirty)
784 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
785 char *str;
786 DWORD written=0;
787 HRESULT hres;
789 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
791 hres = get_doc_string(This->doc_node, &str);
792 if(FAILED(hres))
793 return hres;
795 hres = IStream_Write(pStm, str, strlen(str), &written);
796 if(FAILED(hres))
797 FIXME("Write failed: %08x\n", hres);
799 heap_free(str);
801 if(fClearDirty)
802 set_dirty(This, VARIANT_FALSE);
804 return S_OK;
807 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
808 ULARGE_INTEGER *pcbSize)
810 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
811 FIXME("(%p)->(%p)\n", This, pcbSize);
812 return E_NOTIMPL;
815 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
817 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
818 IMoniker *mon;
819 HRESULT hres;
821 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
823 TRACE("(%p)\n", This);
825 hres = CreateURLMoniker(NULL, about_blankW, &mon);
826 if(FAILED(hres)) {
827 WARN("CreateURLMoniker failed: %08x\n", hres);
828 return hres;
831 prepare_for_binding(This, mon, FALSE);
832 hres = set_moniker(This, mon, NULL, NULL, FALSE);
833 IMoniker_Release(mon);
834 if(FAILED(hres))
835 return hres;
837 return channelbsc_load_stream(This->window->bscallback, NULL);
840 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
841 PersistStreamInit_QueryInterface,
842 PersistStreamInit_AddRef,
843 PersistStreamInit_Release,
844 PersistStreamInit_GetClassID,
845 PersistStreamInit_IsDirty,
846 PersistStreamInit_Load,
847 PersistStreamInit_Save,
848 PersistStreamInit_GetSizeMax,
849 PersistStreamInit_InitNew
852 /**********************************************************
853 * IPersistHistory implementation
856 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
858 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
861 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
863 HTMLDocument *This = impl_from_IPersistHistory(iface);
864 return htmldoc_query_interface(This, riid, ppv);
867 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
869 HTMLDocument *This = impl_from_IPersistHistory(iface);
870 return htmldoc_addref(This);
873 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
875 HTMLDocument *This = impl_from_IPersistHistory(iface);
876 return htmldoc_release(This);
879 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
881 HTMLDocument *This = impl_from_IPersistHistory(iface);
882 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
885 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
887 HTMLDocument *This = impl_from_IPersistHistory(iface);
888 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
889 return E_NOTIMPL;
892 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
894 HTMLDocument *This = impl_from_IPersistHistory(iface);
895 FIXME("(%p)->(%p)\n", This, pStream);
896 return E_NOTIMPL;
899 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
901 HTMLDocument *This = impl_from_IPersistHistory(iface);
902 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
903 return E_NOTIMPL;
906 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
908 HTMLDocument *This = impl_from_IPersistHistory(iface);
909 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
910 return E_NOTIMPL;
913 static const IPersistHistoryVtbl PersistHistoryVtbl = {
914 PersistHistory_QueryInterface,
915 PersistHistory_AddRef,
916 PersistHistory_Release,
917 PersistHistory_GetClassID,
918 PersistHistory_LoadHistory,
919 PersistHistory_SaveHistory,
920 PersistHistory_SetPositionCookie,
921 PersistHistory_GetPositionCookie
924 void HTMLDocument_Persist_Init(HTMLDocument *This)
926 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
927 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
928 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
929 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
930 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;