makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / mshtml / persist.c
blobe87ca47c3908fe13f9f91d54220cf199fb24737d
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 <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "shlguid.h"
29 #include "idispids.h"
30 #include "mimeole.h"
31 #include "shellapi.h"
33 #define NO_SHLWAPI_REG
34 #include "shlwapi.h"
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
39 #include "htmlscript.h"
40 #include "htmlevent.h"
41 #include "binding.h"
42 #include "resource.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
46 /* Undocumented notification, see tests */
47 #define CMDID_EXPLORER_UPDATEHISTORY 38
49 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
51 typedef struct {
52 task_t header;
53 HTMLDocumentObj *doc;
54 BOOL set_download;
55 LPOLESTR url;
56 } download_proc_task_t;
58 static void notify_travellog_update(HTMLDocumentObj *doc)
60 IOleCommandTarget *cmdtrg;
61 HRESULT hres;
63 if(!doc->webbrowser)
64 return;
66 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
67 if(SUCCEEDED(hres)) {
68 VARIANT vin;
70 V_VT(&vin) = VT_I4;
71 V_I4(&vin) = 0;
73 IOleCommandTarget_Exec(cmdtrg, &CGID_Explorer, CMDID_EXPLORER_UPDATEHISTORY, 0, &vin, NULL);
74 IOleCommandTarget_Release(cmdtrg);
78 void set_current_uri(HTMLOuterWindow *window, IUri *uri)
80 if(window->uri) {
81 IUri_Release(window->uri);
82 window->uri = NULL;
85 if(window->uri_nofrag) {
86 IUri_Release(window->uri_nofrag);
87 window->uri_nofrag = NULL;
90 SysFreeString(window->url);
91 window->url = NULL;
93 if(!uri)
94 return;
96 IUri_AddRef(uri);
97 window->uri = uri;
99 window->uri_nofrag = get_uri_nofrag(uri);
100 if(!window->uri_nofrag) {
101 FIXME("get_uri_nofrag failed\n");
102 IUri_AddRef(uri);
103 window->uri_nofrag = uri;
106 IUri_GetDisplayUri(uri, &window->url);
109 void set_current_mon(HTMLOuterWindow *This, IMoniker *mon, DWORD flags)
111 IUriContainer *uri_container;
112 IUri *uri = NULL;
113 HRESULT hres;
115 if(This->mon) {
116 if(This->browser && !(flags & (BINDING_REPLACE|BINDING_REFRESH))) {
117 if(is_main_content_window(This))
118 notify_travellog_update(This->browser->doc);
119 else
120 TRACE("Skipping travellog update for frame navigation.\n");
122 IMoniker_Release(This->mon);
123 This->mon = NULL;
126 This->load_flags = flags;
127 if(!mon)
128 return;
130 IMoniker_AddRef(mon);
131 This->mon = mon;
133 hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
134 if(SUCCEEDED(hres)) {
135 hres = IUriContainer_GetIUri(uri_container, &uri);
136 IUriContainer_Release(uri_container);
137 if(hres != S_OK) {
138 WARN("GetIUri failed: %08x\n", hres);
139 uri = NULL;
143 if(!uri) {
144 WCHAR *url;
146 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
147 if(SUCCEEDED(hres)) {
148 hres = create_uri(url, 0, &uri);
149 if(FAILED(hres)) {
150 WARN("CreateUri failed: %08x\n", hres);
151 set_current_uri(This, NULL);
152 This->url = SysAllocString(url);
153 CoTaskMemFree(url);
154 return;
156 CoTaskMemFree(url);
157 }else {
158 WARN("GetDisplayName failed: %08x\n", hres);
162 set_current_uri(This, uri);
163 if(uri)
164 IUri_Release(uri);
166 if(is_main_content_window(This))
167 update_browser_script_mode(This->browser, uri);
170 HRESULT create_uri(const WCHAR *uri_str, DWORD flags, IUri **uri)
172 return CreateUri(uri_str, flags | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, uri);
175 HRESULT create_relative_uri(HTMLOuterWindow *window, const WCHAR *rel_uri, IUri **uri)
177 return window->uri
178 ? CoInternetCombineUrlEx(window->uri, rel_uri, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, uri, 0)
179 : create_uri(rel_uri, 0, uri);
182 void set_download_state(HTMLDocumentObj *doc, int state)
184 if(doc->client) {
185 IOleCommandTarget *olecmd;
186 HRESULT hres;
188 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
189 if(SUCCEEDED(hres)) {
190 VARIANT var;
192 V_VT(&var) = VT_I4;
193 V_I4(&var) = state;
195 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
196 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
197 IOleCommandTarget_Release(olecmd);
201 doc->download_state = state;
204 static void set_progress_proc(task_t *_task)
206 docobj_task_t *task = (docobj_task_t*)_task;
207 IOleCommandTarget *olecmd = NULL;
208 HTMLDocumentObj *doc = task->doc;
209 HRESULT hres;
211 TRACE("(%p)\n", doc);
213 if(doc->client)
214 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
216 if(olecmd) {
217 VARIANT progress_max, progress;
219 V_VT(&progress_max) = VT_I4;
220 V_I4(&progress_max) = 0; /* FIXME */
221 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
222 &progress_max, NULL);
224 V_VT(&progress) = VT_I4;
225 V_I4(&progress) = 0; /* FIXME */
226 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
227 &progress, NULL);
228 IOleCommandTarget_Release(olecmd);
231 if(doc->nscontainer->usermode == EDITMODE && doc->hostui) {
232 DOCHOSTUIINFO hostinfo;
234 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
235 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
236 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
237 if(SUCCEEDED(hres))
238 /* FIXME: use hostinfo */
239 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
240 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
241 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
245 static void set_downloading_proc(task_t *_task)
247 download_proc_task_t *task = (download_proc_task_t*)_task;
248 HTMLDocumentObj *doc = task->doc;
249 HRESULT hres;
251 TRACE("(%p)\n", doc);
253 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
255 if(task->set_download)
256 set_download_state(doc, 1);
258 if(!doc->client)
259 return;
261 if(doc->view_sink)
262 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
264 if(doc->hostui) {
265 IDropTarget *drop_target = NULL;
267 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
268 if(SUCCEEDED(hres) && drop_target) {
269 FIXME("Use IDropTarget\n");
270 IDropTarget_Release(drop_target);
275 static void set_downloading_task_destr(task_t *_task)
277 download_proc_task_t *task = (download_proc_task_t*)_task;
279 CoTaskMemFree(task->url);
280 heap_free(task);
283 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, DWORD flags)
285 HRESULT hres;
287 if(This->doc_obj->client) {
288 VARIANT silent, offline;
290 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
291 if(SUCCEEDED(hres)) {
292 if(V_VT(&silent) != VT_BOOL)
293 WARN("silent = %s\n", debugstr_variant(&silent));
294 else if(V_BOOL(&silent))
295 FIXME("silent == true\n");
298 hres = get_client_disp_property(This->doc_obj->client,
299 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
300 if(SUCCEEDED(hres)) {
301 if(V_VT(&offline) != VT_BOOL)
302 WARN("offline = %s\n", debugstr_variant(&offline));
303 else if(V_BOOL(&offline))
304 FIXME("offline == true\n");
308 if(This->window->mon) {
309 update_doc(This->doc_obj, UPDATE_TITLE|UPDATE_UI);
310 }else {
311 update_doc(This->doc_obj, UPDATE_TITLE);
312 set_current_mon(This->window, mon, flags);
315 if(This->doc_obj->client) {
316 IOleCommandTarget *cmdtrg = NULL;
318 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
319 (void**)&cmdtrg);
320 if(SUCCEEDED(hres)) {
321 VARIANT var, out;
323 if(flags & BINDING_NAVIGATED) {
324 V_VT(&var) = VT_UNKNOWN;
325 V_UNKNOWN(&var) = (IUnknown*)&This->window->base.IHTMLWindow2_iface;
326 V_VT(&out) = VT_EMPTY;
327 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
328 if(SUCCEEDED(hres))
329 VariantClear(&out);
330 }else if(!(flags & BINDING_FROMHIST)) {
331 V_VT(&var) = VT_I4;
332 V_I4(&var) = 0;
333 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
336 IOleCommandTarget_Release(cmdtrg);
341 HRESULT set_moniker(HTMLOuterWindow *window, IMoniker *mon, IUri *nav_uri, IBindCtx *pibc, nsChannelBSC *async_bsc,
342 BOOL set_download)
344 download_proc_task_t *download_task;
345 HTMLDocumentObj *doc_obj = NULL;
346 nsChannelBSC *bscallback;
347 nsWineURI *nsuri;
348 LPOLESTR url;
349 IUri *uri;
350 HRESULT hres;
352 if(is_main_content_window(window))
353 doc_obj = window->browser->doc;
355 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
356 if(FAILED(hres)) {
357 WARN("GetDisplayName failed: %08x\n", hres);
358 return hres;
361 if(nav_uri) {
362 uri = nav_uri;
363 }else {
364 hres = create_uri(url, 0, &uri);
365 if(FAILED(hres)) {
366 CoTaskMemFree(url);
367 return hres;
371 TRACE("got url: %s\n", debugstr_w(url));
373 set_ready_state(window, READYSTATE_LOADING);
375 hres = create_doc_uri(uri, &nsuri);
376 if(!nav_uri)
377 IUri_Release(uri);
378 if(SUCCEEDED(hres)) {
379 if(async_bsc)
380 bscallback = async_bsc;
381 else
382 hres = create_channelbsc(mon, NULL, NULL, 0, TRUE, &bscallback);
385 if(SUCCEEDED(hres)) {
386 if(window->base.inner_window->doc)
387 remove_target_tasks(window->base.inner_window->task_magic);
388 abort_window_bindings(window->base.inner_window);
390 hres = load_nsuri(window, nsuri, NULL, bscallback, LOAD_FLAGS_BYPASS_CACHE);
391 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
392 if(SUCCEEDED(hres)) {
393 hres = create_pending_window(window, bscallback);
394 TRACE("pending window for %p %p %p\n", window, bscallback, window->pending_window);
396 if(bscallback != async_bsc)
397 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
400 if(FAILED(hres)) {
401 CoTaskMemFree(url);
402 return hres;
405 if(doc_obj) {
406 HTMLDocument_LockContainer(doc_obj, TRUE);
408 if(doc_obj->frame) {
409 docobj_task_t *task;
411 task = heap_alloc(sizeof(docobj_task_t));
412 task->doc = doc_obj;
413 hres = push_task(&task->header, set_progress_proc, NULL, doc_obj->task_magic);
414 if(FAILED(hres)) {
415 CoTaskMemFree(url);
416 return hres;
420 download_task = heap_alloc(sizeof(download_proc_task_t));
421 download_task->doc = doc_obj;
422 download_task->set_download = set_download;
423 download_task->url = url;
424 return push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, doc_obj->task_magic);
427 return S_OK;
430 static void notif_readystate(HTMLOuterWindow *window)
432 DOMEvent *event;
433 HRESULT hres;
435 window->readystate_pending = FALSE;
437 if(is_main_content_window(window))
438 call_property_onchanged(&window->browser->doc->basedoc.cp_container, DISPID_READYSTATE);
440 hres = create_document_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, &event);
441 if(SUCCEEDED(hres)) {
442 event->no_event_obj = TRUE;
443 dispatch_event(&window->base.inner_window->doc->node.event_target, event);
444 IDOMEvent_Release(&event->IDOMEvent_iface);
447 if(window->frame_element) {
448 hres = create_document_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE, &event);
449 if(SUCCEEDED(hres)) {
450 dispatch_event(&window->frame_element->element.node.event_target, event);
451 IDOMEvent_Release(&event->IDOMEvent_iface);
456 typedef struct {
457 task_t header;
458 HTMLOuterWindow *window;
459 } readystate_task_t;
461 static void notif_readystate_proc(task_t *_task)
463 readystate_task_t *task = (readystate_task_t*)_task;
464 notif_readystate(task->window);
467 static void notif_readystate_destr(task_t *_task)
469 readystate_task_t *task = (readystate_task_t*)_task;
470 IHTMLWindow2_Release(&task->window->base.IHTMLWindow2_iface);
473 void set_ready_state(HTMLOuterWindow *window, READYSTATE readystate)
475 READYSTATE prev_state = window->readystate;
477 window->readystate = readystate;
479 if(window->readystate_locked) {
480 readystate_task_t *task;
481 HRESULT hres;
483 if(window->readystate_pending || prev_state == readystate)
484 return;
486 task = heap_alloc(sizeof(*task));
487 if(!task)
488 return;
490 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
491 task->window = window;
493 hres = push_task(&task->header, notif_readystate_proc, notif_readystate_destr, window->task_magic);
494 if(SUCCEEDED(hres))
495 window->readystate_pending = TRUE;
496 return;
499 notif_readystate(window);
502 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
504 nsIDOMNode *nsnode;
505 LPCWSTR strw;
506 nsAString nsstr;
507 nsresult nsres;
508 HRESULT hres;
510 if(!This->nsdoc) {
511 WARN("NULL nsdoc\n");
512 return E_UNEXPECTED;
515 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
516 if(NS_FAILED(nsres)) {
517 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
518 return E_FAIL;
521 nsAString_Init(&nsstr, NULL);
522 hres = nsnode_to_nsstring(nsnode, &nsstr);
523 nsIDOMNode_Release(nsnode);
524 if(FAILED(hres)) {
525 nsAString_Finish(&nsstr);
526 return hres;
529 nsAString_GetData(&nsstr, &strw);
530 TRACE("%s\n", debugstr_w(strw));
532 *str = heap_strdupWtoA(strw);
534 nsAString_Finish(&nsstr);
536 if(!*str)
537 return E_OUTOFMEMORY;
538 return S_OK;
542 /**********************************************************
543 * IPersistMoniker implementation
546 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
548 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
551 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
553 HTMLDocument *This = impl_from_IPersistMoniker(iface);
554 return htmldoc_query_interface(This, riid, ppv);
557 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
559 HTMLDocument *This = impl_from_IPersistMoniker(iface);
560 return htmldoc_addref(This);
563 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
565 HTMLDocument *This = impl_from_IPersistMoniker(iface);
566 return htmldoc_release(This);
569 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
571 HTMLDocument *This = impl_from_IPersistMoniker(iface);
572 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
575 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
577 HTMLDocument *This = impl_from_IPersistMoniker(iface);
579 TRACE("(%p)\n", This);
581 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
584 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
585 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
587 HTMLDocument *This = impl_from_IPersistMoniker(iface);
588 IMoniker *mon;
589 HRESULT hres;
591 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
593 if(pibc) {
594 IUnknown *unk = NULL;
596 /* FIXME:
597 * Use params:
598 * "__PrecreatedObject"
599 * "BIND_CONTEXT_PARAM"
600 * "__HTMLLOADOPTIONS"
601 * "__DWNBINDINFO"
602 * "URL Context"
603 * "_ITransData_Object_"
604 * "_EnumFORMATETC_"
607 hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
608 if(SUCCEEDED(hres) && unk) {
609 IOleClientSite *client = NULL;
611 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
612 if(SUCCEEDED(hres)) {
613 TRACE("Got client site %p\n", client);
614 IOleObject_SetClientSite(&This->IOleObject_iface, client);
615 IOleClientSite_Release(client);
618 IUnknown_Release(unk);
622 if(This->doc_obj->is_mhtml) {
623 IUnknown *unk;
625 hres = MimeOleObjectFromMoniker(0, pimkName, pibc, &IID_IUnknown, (void**)&unk, &mon);
626 if(FAILED(hres))
627 return hres;
628 IUnknown_Release(unk);
629 pibc = NULL;
630 }else {
631 IMoniker_AddRef(mon = pimkName);
634 prepare_for_binding(This, mon, FALSE);
635 call_docview_84(This->doc_obj);
636 hres = set_moniker(This->window, mon, NULL, pibc, NULL, TRUE);
637 IMoniker_Release(mon);
638 if(FAILED(hres))
639 return hres;
641 return start_binding(This->window->pending_window, (BSCallback*)This->window->pending_window->bscallback, pibc);
644 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
645 LPBC pbc, BOOL fRemember)
647 HTMLDocument *This = impl_from_IPersistMoniker(iface);
648 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
649 return E_NOTIMPL;
652 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
654 HTMLDocument *This = impl_from_IPersistMoniker(iface);
655 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
656 return E_NOTIMPL;
659 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
661 HTMLDocument *This = impl_from_IPersistMoniker(iface);
663 TRACE("(%p)->(%p)\n", This, ppimkName);
665 if(!This->window || !This->window->mon)
666 return E_UNEXPECTED;
668 IMoniker_AddRef(This->window->mon);
669 *ppimkName = This->window->mon;
670 return S_OK;
673 static const IPersistMonikerVtbl PersistMonikerVtbl = {
674 PersistMoniker_QueryInterface,
675 PersistMoniker_AddRef,
676 PersistMoniker_Release,
677 PersistMoniker_GetClassID,
678 PersistMoniker_IsDirty,
679 PersistMoniker_Load,
680 PersistMoniker_Save,
681 PersistMoniker_SaveCompleted,
682 PersistMoniker_GetCurMoniker
685 /**********************************************************
686 * IMonikerProp implementation
689 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
691 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
694 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
696 HTMLDocument *This = impl_from_IMonikerProp(iface);
697 return htmldoc_query_interface(This, riid, ppv);
700 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
702 HTMLDocument *This = impl_from_IMonikerProp(iface);
703 return htmldoc_addref(This);
706 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
708 HTMLDocument *This = impl_from_IMonikerProp(iface);
709 return htmldoc_release(This);
712 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
714 HTMLDocument *This = impl_from_IMonikerProp(iface);
716 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
718 switch(mkp) {
719 case MIMETYPEPROP:
720 heap_free(This->doc_obj->mime);
721 This->doc_obj->mime = heap_strdupW(val);
722 break;
724 case CLASSIDPROP:
725 break;
727 default:
728 FIXME("mkp %d\n", mkp);
729 return E_NOTIMPL;
732 return S_OK;
735 static const IMonikerPropVtbl MonikerPropVtbl = {
736 MonikerProp_QueryInterface,
737 MonikerProp_AddRef,
738 MonikerProp_Release,
739 MonikerProp_PutProperty
742 /**********************************************************
743 * IPersistFile implementation
746 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
748 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
751 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
753 HTMLDocument *This = impl_from_IPersistFile(iface);
754 return htmldoc_query_interface(This, riid, ppv);
757 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
759 HTMLDocument *This = impl_from_IPersistFile(iface);
760 return htmldoc_addref(This);
763 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
765 HTMLDocument *This = impl_from_IPersistFile(iface);
766 return htmldoc_release(This);
769 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
771 HTMLDocument *This = impl_from_IPersistFile(iface);
773 TRACE("(%p)->(%p)\n", This, pClassID);
775 if(!pClassID)
776 return E_INVALIDARG;
778 *pClassID = CLSID_HTMLDocument;
779 return S_OK;
782 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
784 HTMLDocument *This = impl_from_IPersistFile(iface);
786 TRACE("(%p)\n", This);
788 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
791 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
793 HTMLDocument *This = impl_from_IPersistFile(iface);
794 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
795 return E_NOTIMPL;
798 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
800 HTMLDocument *This = impl_from_IPersistFile(iface);
801 char *str;
802 DWORD written=0;
803 HANDLE file;
804 HRESULT hres;
806 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
808 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
809 FILE_ATTRIBUTE_NORMAL, NULL);
810 if(file == INVALID_HANDLE_VALUE) {
811 WARN("Could not create file: %u\n", GetLastError());
812 return E_FAIL;
815 hres = get_doc_string(This->doc_node, &str);
816 if(SUCCEEDED(hres))
817 WriteFile(file, str, strlen(str), &written, NULL);
819 CloseHandle(file);
820 return hres;
823 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
825 HTMLDocument *This = impl_from_IPersistFile(iface);
826 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
827 return E_NOTIMPL;
830 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
832 HTMLDocument *This = impl_from_IPersistFile(iface);
833 FIXME("(%p)->(%p)\n", This, pszFileName);
834 return E_NOTIMPL;
837 static const IPersistFileVtbl PersistFileVtbl = {
838 PersistFile_QueryInterface,
839 PersistFile_AddRef,
840 PersistFile_Release,
841 PersistFile_GetClassID,
842 PersistFile_IsDirty,
843 PersistFile_Load,
844 PersistFile_Save,
845 PersistFile_SaveCompleted,
846 PersistFile_GetCurFile
849 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
851 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
854 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
855 REFIID riid, void **ppv)
857 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
858 return htmldoc_query_interface(This, riid, ppv);
861 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
863 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
864 return htmldoc_addref(This);
867 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
869 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
870 return htmldoc_release(This);
873 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
875 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
876 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
879 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
881 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
883 TRACE("(%p)\n", This);
885 return browser_is_dirty(This->doc_obj->nscontainer);
888 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, IStream *pStm)
890 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
891 IMoniker *mon;
892 HRESULT hres;
894 TRACE("(%p)->(%p)\n", This, pStm);
896 hres = CreateURLMoniker(NULL, about_blankW, &mon);
897 if(FAILED(hres)) {
898 WARN("CreateURLMoniker failed: %08x\n", hres);
899 return hres;
902 prepare_for_binding(This, mon, FALSE);
903 hres = set_moniker(This->window, mon, NULL, NULL, NULL, TRUE);
904 if(SUCCEEDED(hres))
905 hres = channelbsc_load_stream(This->window->pending_window, mon, pStm);
907 IMoniker_Release(mon);
908 return hres;
911 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, IStream *pStm,
912 BOOL fClearDirty)
914 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
915 char *str;
916 DWORD written=0;
917 HRESULT hres;
919 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
921 hres = get_doc_string(This->doc_node, &str);
922 if(FAILED(hres))
923 return hres;
925 hres = IStream_Write(pStm, str, strlen(str), &written);
926 if(FAILED(hres))
927 FIXME("Write failed: %08x\n", hres);
929 heap_free(str);
931 if(fClearDirty)
932 set_dirty(This->doc_obj->nscontainer, VARIANT_FALSE);
934 return S_OK;
937 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
938 ULARGE_INTEGER *pcbSize)
940 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
941 FIXME("(%p)->(%p)\n", This, pcbSize);
942 return E_NOTIMPL;
945 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
947 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
948 IMoniker *mon;
949 HRESULT hres;
951 TRACE("(%p)\n", This);
953 hres = CreateURLMoniker(NULL, about_blankW, &mon);
954 if(FAILED(hres)) {
955 WARN("CreateURLMoniker failed: %08x\n", hres);
956 return hres;
959 prepare_for_binding(This, mon, FALSE);
960 hres = set_moniker(This->window, mon, NULL, NULL, NULL, FALSE);
961 if(SUCCEEDED(hres))
962 hres = channelbsc_load_stream(This->window->pending_window, mon, NULL);
964 IMoniker_Release(mon);
965 return hres;
968 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
969 PersistStreamInit_QueryInterface,
970 PersistStreamInit_AddRef,
971 PersistStreamInit_Release,
972 PersistStreamInit_GetClassID,
973 PersistStreamInit_IsDirty,
974 PersistStreamInit_Load,
975 PersistStreamInit_Save,
976 PersistStreamInit_GetSizeMax,
977 PersistStreamInit_InitNew
980 /**********************************************************
981 * IPersistHistory implementation
984 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
986 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
989 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
991 HTMLDocument *This = impl_from_IPersistHistory(iface);
992 return htmldoc_query_interface(This, riid, ppv);
995 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
997 HTMLDocument *This = impl_from_IPersistHistory(iface);
998 return htmldoc_addref(This);
1001 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
1003 HTMLDocument *This = impl_from_IPersistHistory(iface);
1004 return htmldoc_release(This);
1007 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
1009 HTMLDocument *This = impl_from_IPersistHistory(iface);
1010 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1013 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
1015 HTMLDocument *This = impl_from_IPersistHistory(iface);
1016 ULONG str_len, read;
1017 WCHAR *uri_str;
1018 IUri *uri;
1019 HRESULT hres;
1021 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
1023 if(!This->window) {
1024 FIXME("No current window\n");
1025 return E_UNEXPECTED;
1028 if(pbc)
1029 FIXME("pbc not supported\n");
1031 if(This->doc_obj->client) {
1032 IOleCommandTarget *cmdtrg = NULL;
1034 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
1035 (void**)&cmdtrg);
1036 if(SUCCEEDED(hres)) {
1037 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 138, 0, NULL, NULL);
1038 IOleCommandTarget_Release(cmdtrg);
1042 hres = IStream_Read(pStream, &str_len, sizeof(str_len), &read);
1043 if(FAILED(hres))
1044 return hres;
1045 if(read != sizeof(str_len))
1046 return E_FAIL;
1048 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
1049 if(!uri_str)
1050 return E_OUTOFMEMORY;
1052 hres = IStream_Read(pStream, uri_str, str_len*sizeof(WCHAR), &read);
1053 if(SUCCEEDED(hres) && read != str_len*sizeof(WCHAR))
1054 hres = E_FAIL;
1055 if(SUCCEEDED(hres)) {
1056 uri_str[str_len] = 0;
1057 hres = create_uri(uri_str, 0, &uri);
1059 heap_free(uri_str);
1060 if(FAILED(hres))
1061 return hres;
1063 hres = load_uri(This->window, uri, BINDING_FROMHIST);
1064 IUri_Release(uri);
1065 return hres;
1068 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1070 HTMLDocument *This = impl_from_IPersistHistory(iface);
1071 ULONG len, written;
1072 BSTR display_uri;
1073 HRESULT hres;
1075 TRACE("(%p)->(%p)\n", This, pStream);
1077 if(!This->window || !This->window->uri) {
1078 FIXME("No current URI\n");
1079 return E_FAIL;
1082 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1083 * store only URI of the page (as a length followed by a string) */
1084 hres = IUri_GetDisplayUri(This->window->uri, &display_uri);
1085 if(FAILED(hres))
1086 return hres;
1088 len = SysStringLen(display_uri);
1089 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1090 if(SUCCEEDED(hres))
1091 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1092 SysFreeString(display_uri);
1093 return hres;
1096 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1098 HTMLDocument *This = impl_from_IPersistHistory(iface);
1099 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
1100 return E_NOTIMPL;
1103 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1105 HTMLDocument *This = impl_from_IPersistHistory(iface);
1106 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1107 return E_NOTIMPL;
1110 static const IPersistHistoryVtbl PersistHistoryVtbl = {
1111 PersistHistory_QueryInterface,
1112 PersistHistory_AddRef,
1113 PersistHistory_Release,
1114 PersistHistory_GetClassID,
1115 PersistHistory_LoadHistory,
1116 PersistHistory_SaveHistory,
1117 PersistHistory_SetPositionCookie,
1118 PersistHistory_GetPositionCookie
1121 /**********************************************************
1122 * IHlinkTarget implementation
1125 static inline HTMLDocument *impl_from_IHlinkTarget(IHlinkTarget *iface)
1127 return CONTAINING_RECORD(iface, HTMLDocument, IHlinkTarget_iface);
1130 static HRESULT WINAPI HlinkTarget_QueryInterface(IHlinkTarget *iface, REFIID riid, void **ppv)
1132 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1133 return htmldoc_query_interface(This, riid, ppv);
1136 static ULONG WINAPI HlinkTarget_AddRef(IHlinkTarget *iface)
1138 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1139 return htmldoc_addref(This);
1142 static ULONG WINAPI HlinkTarget_Release(IHlinkTarget *iface)
1144 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1145 return htmldoc_release(This);
1148 static HRESULT WINAPI HlinkTarget_SetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext *pihlbc)
1150 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1151 FIXME("(%p)->(%p)\n", This, pihlbc);
1152 return E_NOTIMPL;
1155 static HRESULT WINAPI HlinkTarget_GetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext **ppihlbc)
1157 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1158 FIXME("(%p)->(%p)\n", This, ppihlbc);
1159 return E_NOTIMPL;
1162 static HRESULT WINAPI HlinkTarget_Navigate(IHlinkTarget *iface, DWORD grfHLNF, LPCWSTR pwzJumpLocation)
1164 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1166 TRACE("(%p)->(%08x %s)\n", This, grfHLNF, debugstr_w(pwzJumpLocation));
1168 if(grfHLNF)
1169 FIXME("Unsupported grfHLNF=%08x\n", grfHLNF);
1170 if(pwzJumpLocation)
1171 FIXME("JumpLocation not supported\n");
1173 if(!This->doc_obj->client) {
1174 static const WCHAR szOpen[] = {'o','p','e','n',0};
1175 HRESULT hres;
1176 BSTR uri;
1178 hres = IUri_GetAbsoluteUri(This->window->uri, &uri);
1179 if (FAILED(hres))
1180 return hres;
1182 ShellExecuteW(NULL, szOpen, uri, NULL, NULL, SW_SHOW);
1183 SysFreeString(uri);
1184 return S_OK;
1187 return IOleObject_DoVerb(&This->IOleObject_iface, OLEIVERB_SHOW, NULL, NULL, -1, NULL, NULL);
1190 static HRESULT WINAPI HlinkTarget_GetMoniker(IHlinkTarget *iface, LPCWSTR pwzLocation, DWORD dwAssign,
1191 IMoniker **ppimkLocation)
1193 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1194 FIXME("(%p)->(%s %08x %p)\n", This, debugstr_w(pwzLocation), dwAssign, ppimkLocation);
1195 return E_NOTIMPL;
1198 static HRESULT WINAPI HlinkTarget_GetFriendlyName(IHlinkTarget *iface, LPCWSTR pwzLocation,
1199 LPWSTR *ppwzFriendlyName)
1201 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1202 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwzLocation), ppwzFriendlyName);
1203 return E_NOTIMPL;
1206 static const IHlinkTargetVtbl HlinkTargetVtbl = {
1207 HlinkTarget_QueryInterface,
1208 HlinkTarget_AddRef,
1209 HlinkTarget_Release,
1210 HlinkTarget_SetBrowseContext,
1211 HlinkTarget_GetBrowseContext,
1212 HlinkTarget_Navigate,
1213 HlinkTarget_GetMoniker,
1214 HlinkTarget_GetFriendlyName
1217 void HTMLDocument_Persist_Init(HTMLDocument *This)
1219 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
1220 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
1221 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
1222 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
1223 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;
1224 This->IHlinkTarget_iface.lpVtbl = &HlinkTargetVtbl;