shell32: Return empty list instead of NULL.
[wine.git] / dlls / mshtml / persist.c
blob5ad6104c04fb1070d9f4b31f674d9ff3cdb51595
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 /* Undocumented notification, see tests */
48 #define CMDID_EXPLORER_UPDATEHISTORY 38
50 typedef struct {
51 task_t header;
52 HTMLDocumentObj *doc;
53 BOOL set_download;
54 LPOLESTR url;
55 } download_proc_task_t;
57 static BOOL use_gecko_script(HTMLWindow *window)
59 DWORD zone;
60 HRESULT hres;
62 hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0);
63 if(FAILED(hres)) {
64 WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres);
65 return TRUE;
68 TRACE("zone %d\n", zone);
69 return zone == URLZONE_UNTRUSTED;
72 static void notify_travellog_update(HTMLDocumentObj *doc)
74 IOleCommandTarget *cmdtrg;
75 HRESULT hres;
77 if(!doc->is_webbrowser)
78 return;
80 /* Don't notify if we were in about: page */
81 if(doc->basedoc.window->uri) {
82 DWORD scheme;
84 hres = IUri_GetScheme(doc->basedoc.window->uri, &scheme);
85 if(SUCCEEDED(hres) && scheme == URL_SCHEME_ABOUT)
86 return;
89 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
90 if(SUCCEEDED(hres)) {
91 VARIANT vin;
93 V_VT(&vin) = VT_I4;
94 V_I4(&vin) = 0;
96 IOleCommandTarget_Exec(cmdtrg, &CGID_Explorer, CMDID_EXPLORER_UPDATEHISTORY, 0, &vin, NULL);
97 IOleCommandTarget_Release(cmdtrg);
101 void set_current_uri(HTMLWindow *window, IUri *uri)
103 if(window->uri) {
104 IUri_Release(window->uri);
105 window->uri = NULL;
108 SysFreeString(window->url);
109 window->url = NULL;
111 if(!uri)
112 return;
114 IUri_AddRef(uri);
115 window->uri = uri;
117 IUri_GetDisplayUri(uri, &window->url);
120 void set_current_mon(HTMLWindow *This, IMoniker *mon)
122 IUriContainer *uri_container;
123 IUri *uri = NULL;
124 HRESULT hres;
126 if(This->mon) {
127 if(This->doc_obj)
128 notify_travellog_update(This->doc_obj);
129 IMoniker_Release(This->mon);
130 This->mon = NULL;
133 if(!mon)
134 return;
136 IMoniker_AddRef(mon);
137 This->mon = mon;
139 hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
140 if(SUCCEEDED(hres)) {
141 hres = IUriContainer_GetIUri(uri_container, &uri);
142 IUriContainer_Release(uri_container);
143 if(hres != S_OK) {
144 WARN("GetIUri failed: %08x\n", hres);
145 uri = NULL;
149 if(!uri) {
150 WCHAR *url;
152 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
153 if(SUCCEEDED(hres)) {
154 hres = CreateUri(url, 0, 0, &uri);
155 if(FAILED(hres)) {
156 WARN("CrateUri failed: %08x\n", hres);
157 set_current_uri(This, NULL);
158 This->url = SysAllocString(url);
159 CoTaskMemFree(url);
160 return;
162 CoTaskMemFree(url);
163 }else {
164 WARN("GetDisplayName failed: %08x\n", hres);
168 set_current_uri(This, uri);
169 if(uri)
170 IUri_Release(uri);
171 set_script_mode(This, use_gecko_script(This) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
174 HRESULT create_relative_uri(HTMLWindow *window, const WCHAR *rel_uri, IUri **uri)
176 return window->uri
177 ? CoInternetCombineUrlEx(window->uri, rel_uri, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, uri, 0)
178 : CreateUri(rel_uri, 0, 0, uri);
181 void set_download_state(HTMLDocumentObj *doc, int state)
183 if(doc->client) {
184 IOleCommandTarget *olecmd;
185 HRESULT hres;
187 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
188 if(SUCCEEDED(hres)) {
189 VARIANT var;
191 V_VT(&var) = VT_I4;
192 V_I4(&var) = state;
194 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
195 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
196 IOleCommandTarget_Release(olecmd);
200 doc->download_state = state;
203 static void set_progress_proc(task_t *_task)
205 docobj_task_t *task = (docobj_task_t*)_task;
206 IOleCommandTarget *olecmd = NULL;
207 HTMLDocumentObj *doc = task->doc;
208 HRESULT hres;
210 TRACE("(%p)\n", doc);
212 if(doc->client)
213 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
215 if(olecmd) {
216 VARIANT progress_max, progress;
218 V_VT(&progress_max) = VT_I4;
219 V_I4(&progress_max) = 0; /* FIXME */
220 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
221 &progress_max, NULL);
223 V_VT(&progress) = VT_I4;
224 V_I4(&progress) = 0; /* FIXME */
225 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
226 &progress, NULL);
227 IOleCommandTarget_Release(olecmd);
230 if(doc->usermode == EDITMODE && doc->hostui) {
231 DOCHOSTUIINFO hostinfo;
233 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
234 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
235 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
236 if(SUCCEEDED(hres))
237 /* FIXME: use hostinfo */
238 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
239 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
240 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
244 static void set_downloading_proc(task_t *_task)
246 download_proc_task_t *task = (download_proc_task_t*)_task;
247 HTMLDocumentObj *doc = task->doc;
248 HRESULT hres;
250 TRACE("(%p)\n", doc);
252 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
254 if(task->set_download)
255 set_download_state(doc, 1);
257 if(!doc->client)
258 return;
260 if(doc->view_sink)
261 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
263 if(doc->hostui) {
264 IDropTarget *drop_target = NULL;
266 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
267 if(SUCCEEDED(hres) && drop_target) {
268 FIXME("Use IDropTarget\n");
269 IDropTarget_Release(drop_target);
274 static void set_downloading_task_destr(task_t *_task)
276 download_proc_task_t *task = (download_proc_task_t*)_task;
278 CoTaskMemFree(task->url);
279 heap_free(task);
282 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, BOOL navigated_binding)
284 HRESULT hres;
286 if(This->doc_obj->client) {
287 VARIANT silent, offline;
289 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
290 if(SUCCEEDED(hres)) {
291 if(V_VT(&silent) != VT_BOOL)
292 WARN("silent = %s\n", debugstr_variant(&silent));
293 else if(V_BOOL(&silent))
294 FIXME("silent == true\n");
297 hres = get_client_disp_property(This->doc_obj->client,
298 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
299 if(SUCCEEDED(hres)) {
300 if(V_VT(&offline) != VT_BOOL)
301 WARN("offline = %s\n", debugstr_variant(&offline));
302 else if(V_BOOL(&offline))
303 FIXME("offline == true\n");
307 if(This->window->mon) {
308 update_doc(This, UPDATE_TITLE|UPDATE_UI);
309 }else {
310 update_doc(This, UPDATE_TITLE);
311 set_current_mon(This->window, mon);
314 if(This->doc_obj->client) {
315 IOleCommandTarget *cmdtrg = NULL;
317 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
318 (void**)&cmdtrg);
319 if(SUCCEEDED(hres)) {
320 VARIANT var, out;
322 if(!navigated_binding) {
323 V_VT(&var) = VT_I4;
324 V_I4(&var) = 0;
325 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
326 }else {
327 V_VT(&var) = VT_UNKNOWN;
328 V_UNKNOWN(&var) = (IUnknown*)&This->window->IHTMLWindow2_iface;
329 V_VT(&out) = VT_EMPTY;
330 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
331 if(SUCCEEDED(hres))
332 VariantClear(&out);
335 IOleCommandTarget_Release(cmdtrg);
340 HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, nsChannelBSC *async_bsc, BOOL set_download)
342 download_proc_task_t *download_task;
343 nsChannelBSC *bscallback;
344 nsWineURI *nsuri;
345 LPOLESTR url;
346 HRESULT hres;
348 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
349 if(FAILED(hres)) {
350 WARN("GetDiaplayName failed: %08x\n", hres);
351 return hres;
354 TRACE("got url: %s\n", debugstr_w(url));
356 set_ready_state(This->window, READYSTATE_LOADING);
358 hres = create_doc_uri(This->window, url, &nsuri);
359 if(SUCCEEDED(hres)) {
360 if(async_bsc)
361 bscallback = async_bsc;
362 else
363 hres = create_channelbsc(mon, NULL, NULL, 0, &bscallback);
366 if(SUCCEEDED(hres)) {
367 remove_target_tasks(This->task_magic);
368 abort_document_bindings(This->doc_node);
370 hres = load_nsuri(This->window, nsuri, bscallback, 0/*LOAD_INITIAL_DOCUMENT_URI*/);
371 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
372 if(SUCCEEDED(hres))
373 set_window_bscallback(This->window, bscallback);
374 if(bscallback != async_bsc)
375 IUnknown_Release((IUnknown*)bscallback);
378 if(FAILED(hres)) {
379 CoTaskMemFree(url);
380 return hres;
383 HTMLDocument_LockContainer(This->doc_obj, TRUE);
385 if(This->doc_obj->frame) {
386 docobj_task_t *task;
388 task = heap_alloc(sizeof(docobj_task_t));
389 task->doc = This->doc_obj;
390 push_task(&task->header, set_progress_proc, NULL, This->doc_obj->basedoc.task_magic);
393 download_task = heap_alloc(sizeof(download_proc_task_t));
394 download_task->doc = This->doc_obj;
395 download_task->set_download = set_download;
396 download_task->url = url;
397 push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, This->doc_obj->basedoc.task_magic);
399 return S_OK;
402 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
404 window->readystate = readystate;
406 if(window->doc_obj && window->doc_obj->basedoc.window == window)
407 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
409 fire_event(window->doc, EVENTID_READYSTATECHANGE, FALSE, window->doc->node.nsnode, NULL);
411 if(window->frame_element)
412 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
413 TRUE, window->frame_element->element.node.nsnode, NULL);
416 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
418 nsIDOMNode *nsnode;
419 LPCWSTR strw;
420 nsAString nsstr;
421 nsresult nsres;
422 HRESULT hres;
424 if(!This->nsdoc) {
425 WARN("NULL nsdoc\n");
426 return E_UNEXPECTED;
429 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
430 if(NS_FAILED(nsres)) {
431 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
432 return E_FAIL;
435 nsAString_Init(&nsstr, NULL);
436 hres = nsnode_to_nsstring(nsnode, &nsstr);
437 nsIDOMNode_Release(nsnode);
438 if(FAILED(hres)) {
439 nsAString_Finish(&nsstr);
440 return hres;
443 nsAString_GetData(&nsstr, &strw);
444 TRACE("%s\n", debugstr_w(strw));
446 *str = heap_strdupWtoA(strw);
448 nsAString_Finish(&nsstr);
450 if(!*str)
451 return E_OUTOFMEMORY;
452 return S_OK;
456 /**********************************************************
457 * IPersistMoniker implementation
460 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
462 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
465 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
467 HTMLDocument *This = impl_from_IPersistMoniker(iface);
468 return htmldoc_query_interface(This, riid, ppv);
471 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
473 HTMLDocument *This = impl_from_IPersistMoniker(iface);
474 return htmldoc_addref(This);
477 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
479 HTMLDocument *This = impl_from_IPersistMoniker(iface);
480 return htmldoc_release(This);
483 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
485 HTMLDocument *This = impl_from_IPersistMoniker(iface);
486 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
489 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
491 HTMLDocument *This = impl_from_IPersistMoniker(iface);
493 TRACE("(%p)\n", This);
495 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
498 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
499 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
501 HTMLDocument *This = impl_from_IPersistMoniker(iface);
502 HRESULT hres;
504 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
506 if(pibc) {
507 IUnknown *unk = NULL;
509 /* FIXME:
510 * Use params:
511 * "__PrecreatedObject"
512 * "BIND_CONTEXT_PARAM"
513 * "__HTMLLOADOPTIONS"
514 * "__DWNBINDINFO"
515 * "URL Context"
516 * "_ITransData_Object_"
517 * "_EnumFORMATETC_"
520 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
521 if(unk) {
522 IOleClientSite *client = NULL;
524 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
525 if(SUCCEEDED(hres)) {
526 TRACE("Got client site %p\n", client);
527 IOleObject_SetClientSite(&This->IOleObject_iface, client);
528 IOleClientSite_Release(client);
531 IUnknown_Release(unk);
535 prepare_for_binding(This, pimkName, FALSE);
536 call_docview_84(This->doc_obj);
537 hres = set_moniker(This, pimkName, pibc, NULL, TRUE);
538 if(FAILED(hres))
539 return hres;
541 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
544 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
545 LPBC pbc, BOOL fRemember)
547 HTMLDocument *This = impl_from_IPersistMoniker(iface);
548 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
549 return E_NOTIMPL;
552 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
554 HTMLDocument *This = impl_from_IPersistMoniker(iface);
555 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
556 return E_NOTIMPL;
559 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
561 HTMLDocument *This = impl_from_IPersistMoniker(iface);
563 TRACE("(%p)->(%p)\n", This, ppimkName);
565 if(!This->window || !This->window->mon)
566 return E_UNEXPECTED;
568 IMoniker_AddRef(This->window->mon);
569 *ppimkName = This->window->mon;
570 return S_OK;
573 static const IPersistMonikerVtbl PersistMonikerVtbl = {
574 PersistMoniker_QueryInterface,
575 PersistMoniker_AddRef,
576 PersistMoniker_Release,
577 PersistMoniker_GetClassID,
578 PersistMoniker_IsDirty,
579 PersistMoniker_Load,
580 PersistMoniker_Save,
581 PersistMoniker_SaveCompleted,
582 PersistMoniker_GetCurMoniker
585 /**********************************************************
586 * IMonikerProp implementation
589 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
591 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
594 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
596 HTMLDocument *This = impl_from_IMonikerProp(iface);
597 return htmldoc_query_interface(This, riid, ppv);
600 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
602 HTMLDocument *This = impl_from_IMonikerProp(iface);
603 return htmldoc_addref(This);
606 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
608 HTMLDocument *This = impl_from_IMonikerProp(iface);
609 return htmldoc_release(This);
612 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
614 HTMLDocument *This = impl_from_IMonikerProp(iface);
616 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
618 switch(mkp) {
619 case MIMETYPEPROP:
620 heap_free(This->doc_obj->mime);
621 This->doc_obj->mime = heap_strdupW(val);
622 break;
624 case CLASSIDPROP:
625 break;
627 default:
628 FIXME("mkp %d\n", mkp);
629 return E_NOTIMPL;
632 return S_OK;
635 static const IMonikerPropVtbl MonikerPropVtbl = {
636 MonikerProp_QueryInterface,
637 MonikerProp_AddRef,
638 MonikerProp_Release,
639 MonikerProp_PutProperty
642 /**********************************************************
643 * IPersistFile implementation
646 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
648 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
651 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
653 HTMLDocument *This = impl_from_IPersistFile(iface);
654 return htmldoc_query_interface(This, riid, ppv);
657 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
659 HTMLDocument *This = impl_from_IPersistFile(iface);
660 return htmldoc_addref(This);
663 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
665 HTMLDocument *This = impl_from_IPersistFile(iface);
666 return htmldoc_release(This);
669 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
671 HTMLDocument *This = impl_from_IPersistFile(iface);
673 TRACE("(%p)->(%p)\n", This, pClassID);
675 if(!pClassID)
676 return E_INVALIDARG;
678 *pClassID = CLSID_HTMLDocument;
679 return S_OK;
682 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
684 HTMLDocument *This = impl_from_IPersistFile(iface);
686 TRACE("(%p)\n", This);
688 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
691 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
693 HTMLDocument *This = impl_from_IPersistFile(iface);
694 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
695 return E_NOTIMPL;
698 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
700 HTMLDocument *This = impl_from_IPersistFile(iface);
701 char *str;
702 DWORD written=0;
703 HANDLE file;
704 HRESULT hres;
706 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
708 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
709 FILE_ATTRIBUTE_NORMAL, NULL);
710 if(file == INVALID_HANDLE_VALUE) {
711 WARN("Could not create file: %u\n", GetLastError());
712 return E_FAIL;
715 hres = get_doc_string(This->doc_node, &str);
716 if(SUCCEEDED(hres))
717 WriteFile(file, str, strlen(str), &written, NULL);
719 CloseHandle(file);
720 return hres;
723 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
725 HTMLDocument *This = impl_from_IPersistFile(iface);
726 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
727 return E_NOTIMPL;
730 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
732 HTMLDocument *This = impl_from_IPersistFile(iface);
733 FIXME("(%p)->(%p)\n", This, pszFileName);
734 return E_NOTIMPL;
737 static const IPersistFileVtbl PersistFileVtbl = {
738 PersistFile_QueryInterface,
739 PersistFile_AddRef,
740 PersistFile_Release,
741 PersistFile_GetClassID,
742 PersistFile_IsDirty,
743 PersistFile_Load,
744 PersistFile_Save,
745 PersistFile_SaveCompleted,
746 PersistFile_GetCurFile
749 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
751 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
754 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
755 REFIID riid, void **ppv)
757 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
758 return htmldoc_query_interface(This, riid, ppv);
761 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
763 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
764 return htmldoc_addref(This);
767 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
769 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
770 return htmldoc_release(This);
773 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
775 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
776 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
779 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
781 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
783 TRACE("(%p)\n", This);
785 if(This->doc_obj->usermode == EDITMODE)
786 return editor_is_dirty(This);
788 return S_FALSE;
791 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
793 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
794 IMoniker *mon;
795 HRESULT hres;
797 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
799 TRACE("(%p)->(%p)\n", This, pStm);
801 hres = CreateURLMoniker(NULL, about_blankW, &mon);
802 if(FAILED(hres)) {
803 WARN("CreateURLMoniker failed: %08x\n", hres);
804 return hres;
807 prepare_for_binding(This, mon, FALSE);
808 hres = set_moniker(This, mon, NULL, NULL, TRUE);
809 IMoniker_Release(mon);
810 if(FAILED(hres))
811 return hres;
813 return channelbsc_load_stream(This->window->bscallback, pStm);
816 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
817 BOOL fClearDirty)
819 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
820 char *str;
821 DWORD written=0;
822 HRESULT hres;
824 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
826 hres = get_doc_string(This->doc_node, &str);
827 if(FAILED(hres))
828 return hres;
830 hres = IStream_Write(pStm, str, strlen(str), &written);
831 if(FAILED(hres))
832 FIXME("Write failed: %08x\n", hres);
834 heap_free(str);
836 if(fClearDirty)
837 set_dirty(This, VARIANT_FALSE);
839 return S_OK;
842 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
843 ULARGE_INTEGER *pcbSize)
845 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
846 FIXME("(%p)->(%p)\n", This, pcbSize);
847 return E_NOTIMPL;
850 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
852 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
853 IMoniker *mon;
854 HRESULT hres;
856 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
858 TRACE("(%p)\n", This);
860 hres = CreateURLMoniker(NULL, about_blankW, &mon);
861 if(FAILED(hres)) {
862 WARN("CreateURLMoniker failed: %08x\n", hres);
863 return hres;
866 prepare_for_binding(This, mon, FALSE);
867 hres = set_moniker(This, mon, NULL, NULL, FALSE);
868 IMoniker_Release(mon);
869 if(FAILED(hres))
870 return hres;
872 return channelbsc_load_stream(This->window->bscallback, NULL);
875 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
876 PersistStreamInit_QueryInterface,
877 PersistStreamInit_AddRef,
878 PersistStreamInit_Release,
879 PersistStreamInit_GetClassID,
880 PersistStreamInit_IsDirty,
881 PersistStreamInit_Load,
882 PersistStreamInit_Save,
883 PersistStreamInit_GetSizeMax,
884 PersistStreamInit_InitNew
887 /**********************************************************
888 * IPersistHistory implementation
891 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
893 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
896 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
898 HTMLDocument *This = impl_from_IPersistHistory(iface);
899 return htmldoc_query_interface(This, riid, ppv);
902 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
904 HTMLDocument *This = impl_from_IPersistHistory(iface);
905 return htmldoc_addref(This);
908 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
910 HTMLDocument *This = impl_from_IPersistHistory(iface);
911 return htmldoc_release(This);
914 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
916 HTMLDocument *This = impl_from_IPersistHistory(iface);
917 return IPersist_GetClassID(&This->IPersistFile_iface, pClassID);
920 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
922 HTMLDocument *This = impl_from_IPersistHistory(iface);
923 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
924 return E_NOTIMPL;
927 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
929 HTMLDocument *This = impl_from_IPersistHistory(iface);
930 FIXME("(%p)->(%p)\n", This, pStream);
931 return E_NOTIMPL;
934 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
936 HTMLDocument *This = impl_from_IPersistHistory(iface);
937 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
938 return E_NOTIMPL;
941 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
943 HTMLDocument *This = impl_from_IPersistHistory(iface);
944 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
945 return E_NOTIMPL;
948 static const IPersistHistoryVtbl PersistHistoryVtbl = {
949 PersistHistory_QueryInterface,
950 PersistHistory_AddRef,
951 PersistHistory_Release,
952 PersistHistory_GetClassID,
953 PersistHistory_LoadHistory,
954 PersistHistory_SaveHistory,
955 PersistHistory_SetPositionCookie,
956 PersistHistory_GetPositionCookie
959 void HTMLDocument_Persist_Init(HTMLDocument *This)
961 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
962 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
963 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
964 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
965 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;