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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
35 #define NO_SHLWAPI_REG
38 #include "wine/debug.h"
40 #include "mshtml_private.h"
41 #include "htmlscript.h"
42 #include "htmlevent.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
48 /* Undocumented notification, see tests */
49 #define CMDID_EXPLORER_UPDATEHISTORY 38
51 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
58 } download_proc_task_t
;
60 static BOOL
use_gecko_script(HTMLOuterWindow
*window
)
65 hres
= IInternetSecurityManager_MapUrlToZone(window
->secmgr
, window
->url
, &zone
, 0);
67 WARN("Could not map %s to zone: %08x\n", debugstr_w(window
->url
), hres
);
71 TRACE("zone %d\n", zone
);
72 return zone
== URLZONE_UNTRUSTED
;
75 static void notify_travellog_update(HTMLDocumentObj
*doc
)
77 IOleCommandTarget
*cmdtrg
;
83 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
90 IOleCommandTarget_Exec(cmdtrg
, &CGID_Explorer
, CMDID_EXPLORER_UPDATEHISTORY
, 0, &vin
, NULL
);
91 IOleCommandTarget_Release(cmdtrg
);
95 void set_current_uri(HTMLOuterWindow
*window
, IUri
*uri
)
98 IUri_Release(window
->uri
);
102 if(window
->uri_nofrag
) {
103 IUri_Release(window
->uri_nofrag
);
104 window
->uri_nofrag
= NULL
;
107 SysFreeString(window
->url
);
116 window
->uri_nofrag
= get_uri_nofrag(uri
);
117 if(!window
->uri_nofrag
) {
118 FIXME("get_uri_nofrag failed\n");
120 window
->uri_nofrag
= uri
;
123 IUri_GetDisplayUri(uri
, &window
->url
);
126 void set_current_mon(HTMLOuterWindow
*This
, IMoniker
*mon
, DWORD flags
)
128 IUriContainer
*uri_container
;
133 if(This
->doc_obj
&& !(flags
& (BINDING_REPLACE
|BINDING_REFRESH
)))
134 notify_travellog_update(This
->doc_obj
);
135 IMoniker_Release(This
->mon
);
139 This
->load_flags
= flags
;
143 IMoniker_AddRef(mon
);
146 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
147 if(SUCCEEDED(hres
)) {
148 hres
= IUriContainer_GetIUri(uri_container
, &uri
);
149 IUriContainer_Release(uri_container
);
151 WARN("GetIUri failed: %08x\n", hres
);
159 hres
= IMoniker_GetDisplayName(mon
, NULL
, NULL
, &url
);
160 if(SUCCEEDED(hres
)) {
161 hres
= create_uri(url
, 0, &uri
);
163 WARN("CrateUri failed: %08x\n", hres
);
164 set_current_uri(This
, NULL
);
165 This
->url
= SysAllocString(url
);
171 WARN("GetDisplayName failed: %08x\n", hres
);
175 set_current_uri(This
, uri
);
178 set_script_mode(This
, use_gecko_script(This
) ? SCRIPTMODE_GECKO
: SCRIPTMODE_ACTIVESCRIPT
);
181 HRESULT
create_uri(const WCHAR
*uri_str
, DWORD flags
, IUri
**uri
)
183 return CreateUri(uri_str
, flags
| Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, uri
);
186 HRESULT
create_relative_uri(HTMLOuterWindow
*window
, const WCHAR
*rel_uri
, IUri
**uri
)
189 ? CoInternetCombineUrlEx(window
->uri
, rel_uri
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, uri
, 0)
190 : create_uri(rel_uri
, 0, uri
);
193 void set_download_state(HTMLDocumentObj
*doc
, int state
)
196 IOleCommandTarget
*olecmd
;
199 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
200 if(SUCCEEDED(hres
)) {
206 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
,
207 OLECMDEXECOPT_DONTPROMPTUSER
, &var
, NULL
);
208 IOleCommandTarget_Release(olecmd
);
212 doc
->download_state
= state
;
215 static void set_progress_proc(task_t
*_task
)
217 docobj_task_t
*task
= (docobj_task_t
*)_task
;
218 IOleCommandTarget
*olecmd
= NULL
;
219 HTMLDocumentObj
*doc
= task
->doc
;
222 TRACE("(%p)\n", doc
);
225 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
228 VARIANT progress_max
, progress
;
230 V_VT(&progress_max
) = VT_I4
;
231 V_I4(&progress_max
) = 0; /* FIXME */
232 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSMAX
, OLECMDEXECOPT_DONTPROMPTUSER
,
233 &progress_max
, NULL
);
235 V_VT(&progress
) = VT_I4
;
236 V_I4(&progress
) = 0; /* FIXME */
237 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
239 IOleCommandTarget_Release(olecmd
);
242 if(doc
->usermode
== EDITMODE
&& doc
->hostui
) {
243 DOCHOSTUIINFO hostinfo
;
245 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
246 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
247 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
249 /* FIXME: use hostinfo */
250 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
251 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
252 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
256 static void set_downloading_proc(task_t
*_task
)
258 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
259 HTMLDocumentObj
*doc
= task
->doc
;
262 TRACE("(%p)\n", doc
);
264 set_statustext(doc
, IDS_STATUS_DOWNLOADINGFROM
, task
->url
);
266 if(task
->set_download
)
267 set_download_state(doc
, 1);
273 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
276 IDropTarget
*drop_target
= NULL
;
278 hres
= IDocHostUIHandler_GetDropTarget(doc
->hostui
, NULL
/* FIXME */, &drop_target
);
279 if(SUCCEEDED(hres
) && drop_target
) {
280 FIXME("Use IDropTarget\n");
281 IDropTarget_Release(drop_target
);
286 static void set_downloading_task_destr(task_t
*_task
)
288 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
290 CoTaskMemFree(task
->url
);
294 void prepare_for_binding(HTMLDocument
*This
, IMoniker
*mon
, DWORD flags
)
298 if(This
->doc_obj
->client
) {
299 VARIANT silent
, offline
;
301 hres
= get_client_disp_property(This
->doc_obj
->client
, DISPID_AMBIENT_SILENT
, &silent
);
302 if(SUCCEEDED(hres
)) {
303 if(V_VT(&silent
) != VT_BOOL
)
304 WARN("silent = %s\n", debugstr_variant(&silent
));
305 else if(V_BOOL(&silent
))
306 FIXME("silent == true\n");
309 hres
= get_client_disp_property(This
->doc_obj
->client
,
310 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
311 if(SUCCEEDED(hres
)) {
312 if(V_VT(&offline
) != VT_BOOL
)
313 WARN("offline = %s\n", debugstr_variant(&offline
));
314 else if(V_BOOL(&offline
))
315 FIXME("offline == true\n");
319 if(This
->window
->mon
) {
320 update_doc(This
, UPDATE_TITLE
|UPDATE_UI
);
322 update_doc(This
, UPDATE_TITLE
);
323 set_current_mon(This
->window
, mon
, flags
);
326 if(This
->doc_obj
->client
) {
327 IOleCommandTarget
*cmdtrg
= NULL
;
329 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
331 if(SUCCEEDED(hres
)) {
334 if(flags
& BINDING_NAVIGATED
) {
335 V_VT(&var
) = VT_UNKNOWN
;
336 V_UNKNOWN(&var
) = (IUnknown
*)&This
->window
->base
.IHTMLWindow2_iface
;
337 V_VT(&out
) = VT_EMPTY
;
338 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 63, 0, &var
, &out
);
341 }else if(!(flags
& BINDING_FROMHIST
)) {
344 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
347 IOleCommandTarget_Release(cmdtrg
);
352 HRESULT
set_moniker(HTMLOuterWindow
*window
, IMoniker
*mon
, IUri
*nav_uri
, IBindCtx
*pibc
, nsChannelBSC
*async_bsc
,
355 download_proc_task_t
*download_task
;
356 HTMLDocumentObj
*doc_obj
= NULL
;
357 nsChannelBSC
*bscallback
;
363 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
364 doc_obj
= window
->doc_obj
;
366 hres
= IMoniker_GetDisplayName(mon
, pibc
, NULL
, &url
);
368 WARN("GetDiaplayName failed: %08x\n", hres
);
375 hres
= create_uri(url
, 0, &uri
);
382 TRACE("got url: %s\n", debugstr_w(url
));
384 set_ready_state(window
, READYSTATE_LOADING
);
386 hres
= create_doc_uri(window
, uri
, &nsuri
);
389 if(SUCCEEDED(hres
)) {
391 bscallback
= async_bsc
;
393 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, TRUE
, &bscallback
);
396 if(SUCCEEDED(hres
)) {
397 if(window
->base
.inner_window
->doc
)
398 remove_target_tasks(window
->base
.inner_window
->task_magic
);
399 abort_window_bindings(window
->base
.inner_window
);
401 hres
= load_nsuri(window
, nsuri
, NULL
, bscallback
, LOAD_FLAGS_BYPASS_CACHE
);
402 nsISupports_Release((nsISupports
*)nsuri
); /* FIXME */
403 if(SUCCEEDED(hres
)) {
404 hres
= create_pending_window(window
, bscallback
);
405 TRACE("pending window for %p %p %p\n", window
, bscallback
, window
->pending_window
);
407 if(bscallback
!= async_bsc
)
408 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
417 HTMLDocument_LockContainer(doc_obj
, TRUE
);
422 task
= heap_alloc(sizeof(docobj_task_t
));
424 hres
= push_task(&task
->header
, set_progress_proc
, NULL
, doc_obj
->basedoc
.task_magic
);
431 download_task
= heap_alloc(sizeof(download_proc_task_t
));
432 download_task
->doc
= doc_obj
;
433 download_task
->set_download
= set_download
;
434 download_task
->url
= url
;
435 return push_task(&download_task
->header
, set_downloading_proc
, set_downloading_task_destr
, doc_obj
->basedoc
.task_magic
);
441 static void notif_readystate(HTMLOuterWindow
*window
)
443 window
->readystate_pending
= FALSE
;
445 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
446 call_property_onchanged(&window
->doc_obj
->basedoc
.cp_container
, DISPID_READYSTATE
);
448 fire_event(window
->base
.inner_window
->doc
, EVENTID_READYSTATECHANGE
, FALSE
,
449 window
->base
.inner_window
->doc
->node
.nsnode
, NULL
, NULL
);
451 if(window
->frame_element
)
452 fire_event(window
->frame_element
->element
.node
.doc
, EVENTID_READYSTATECHANGE
,
453 TRUE
, window
->frame_element
->element
.node
.nsnode
, NULL
, NULL
);
458 HTMLOuterWindow
*window
;
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
;
483 if(window
->readystate_pending
|| prev_state
== readystate
)
486 task
= heap_alloc(sizeof(*task
));
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
);
495 window
->readystate_pending
= TRUE
;
499 notif_readystate(window
);
502 static HRESULT
get_doc_string(HTMLDocumentNode
*This
, char **str
)
511 WARN("NULL nsdoc\n");
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
);
521 nsAString_Init(&nsstr
, NULL
);
522 hres
= nsnode_to_nsstring(nsnode
, &nsstr
);
523 nsIDOMNode_Release(nsnode
);
525 nsAString_Finish(&nsstr
);
529 nsAString_GetData(&nsstr
, &strw
);
530 TRACE("%s\n", debugstr_w(strw
));
532 *str
= heap_strdupWtoA(strw
);
534 nsAString_Finish(&nsstr
);
537 return E_OUTOFMEMORY
;
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
);
590 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
593 IUnknown
*unk
= NULL
;
597 * "__PrecreatedObject"
598 * "BIND_CONTEXT_PARAM"
599 * "__HTMLLOADOPTIONS"
602 * "_ITransData_Object_"
606 hres
= IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
607 if(SUCCEEDED(hres
) && unk
) {
608 IOleClientSite
*client
= NULL
;
610 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
611 if(SUCCEEDED(hres
)) {
612 TRACE("Got client site %p\n", client
);
613 IOleObject_SetClientSite(&This
->IOleObject_iface
, client
);
614 IOleClientSite_Release(client
);
617 IUnknown_Release(unk
);
621 prepare_for_binding(This
, pimkName
, FALSE
);
622 call_docview_84(This
->doc_obj
);
623 hres
= set_moniker(This
->window
, pimkName
, NULL
, pibc
, NULL
, TRUE
);
627 return start_binding(This
->window
->pending_window
, (BSCallback
*)This
->window
->pending_window
->bscallback
, pibc
);
630 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
631 LPBC pbc
, BOOL fRemember
)
633 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
634 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
638 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
640 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
641 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
645 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
647 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
649 TRACE("(%p)->(%p)\n", This
, ppimkName
);
651 if(!This
->window
|| !This
->window
->mon
)
654 IMoniker_AddRef(This
->window
->mon
);
655 *ppimkName
= This
->window
->mon
;
659 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
660 PersistMoniker_QueryInterface
,
661 PersistMoniker_AddRef
,
662 PersistMoniker_Release
,
663 PersistMoniker_GetClassID
,
664 PersistMoniker_IsDirty
,
667 PersistMoniker_SaveCompleted
,
668 PersistMoniker_GetCurMoniker
671 /**********************************************************
672 * IMonikerProp implementation
675 static inline HTMLDocument
*impl_from_IMonikerProp(IMonikerProp
*iface
)
677 return CONTAINING_RECORD(iface
, HTMLDocument
, IMonikerProp_iface
);
680 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppv
)
682 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
683 return htmldoc_query_interface(This
, riid
, ppv
);
686 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
688 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
689 return htmldoc_addref(This
);
692 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
694 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
695 return htmldoc_release(This
);
698 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
700 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
702 TRACE("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
706 heap_free(This
->doc_obj
->mime
);
707 This
->doc_obj
->mime
= heap_strdupW(val
);
714 FIXME("mkp %d\n", mkp
);
721 static const IMonikerPropVtbl MonikerPropVtbl
= {
722 MonikerProp_QueryInterface
,
725 MonikerProp_PutProperty
728 /**********************************************************
729 * IPersistFile implementation
732 static inline HTMLDocument
*impl_from_IPersistFile(IPersistFile
*iface
)
734 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistFile_iface
);
737 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppv
)
739 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
740 return htmldoc_query_interface(This
, riid
, ppv
);
743 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
745 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
746 return htmldoc_addref(This
);
749 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
751 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
752 return htmldoc_release(This
);
755 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
757 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
759 TRACE("(%p)->(%p)\n", This
, pClassID
);
764 *pClassID
= CLSID_HTMLDocument
;
768 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
770 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
772 TRACE("(%p)\n", This
);
774 return IPersistStreamInit_IsDirty(&This
->IPersistStreamInit_iface
);
777 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
779 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
780 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
784 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
786 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
792 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
794 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
795 FILE_ATTRIBUTE_NORMAL
, NULL
);
796 if(file
== INVALID_HANDLE_VALUE
) {
797 WARN("Could not create file: %u\n", GetLastError());
801 hres
= get_doc_string(This
->doc_node
, &str
);
803 WriteFile(file
, str
, strlen(str
), &written
, NULL
);
809 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
811 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
812 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
816 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
818 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
819 FIXME("(%p)->(%p)\n", This
, pszFileName
);
823 static const IPersistFileVtbl PersistFileVtbl
= {
824 PersistFile_QueryInterface
,
827 PersistFile_GetClassID
,
831 PersistFile_SaveCompleted
,
832 PersistFile_GetCurFile
835 static inline HTMLDocument
*impl_from_IPersistStreamInit(IPersistStreamInit
*iface
)
837 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistStreamInit_iface
);
840 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
841 REFIID riid
, void **ppv
)
843 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
844 return htmldoc_query_interface(This
, riid
, ppv
);
847 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
849 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
850 return htmldoc_addref(This
);
853 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
855 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
856 return htmldoc_release(This
);
859 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
861 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
862 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
865 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
867 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
869 TRACE("(%p)\n", This
);
871 if(This
->doc_obj
->usermode
== EDITMODE
)
872 return editor_is_dirty(This
);
877 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, LPSTREAM pStm
)
879 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
883 TRACE("(%p)->(%p)\n", This
, pStm
);
885 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
887 WARN("CreateURLMoniker failed: %08x\n", hres
);
891 prepare_for_binding(This
, mon
, FALSE
);
892 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, TRUE
);
896 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, pStm
);
897 IMoniker_Release(mon
);
901 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, LPSTREAM pStm
,
904 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
909 TRACE("(%p)->(%p %x)\n", This
, pStm
, fClearDirty
);
911 hres
= get_doc_string(This
->doc_node
, &str
);
915 hres
= IStream_Write(pStm
, str
, strlen(str
), &written
);
917 FIXME("Write failed: %08x\n", hres
);
922 set_dirty(This
, VARIANT_FALSE
);
927 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
928 ULARGE_INTEGER
*pcbSize
)
930 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
931 FIXME("(%p)->(%p)\n", This
, pcbSize
);
935 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
937 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
941 TRACE("(%p)\n", This
);
943 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
945 WARN("CreateURLMoniker failed: %08x\n", hres
);
949 prepare_for_binding(This
, mon
, FALSE
);
950 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, FALSE
);
954 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, NULL
);
955 IMoniker_Release(mon
);
959 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
960 PersistStreamInit_QueryInterface
,
961 PersistStreamInit_AddRef
,
962 PersistStreamInit_Release
,
963 PersistStreamInit_GetClassID
,
964 PersistStreamInit_IsDirty
,
965 PersistStreamInit_Load
,
966 PersistStreamInit_Save
,
967 PersistStreamInit_GetSizeMax
,
968 PersistStreamInit_InitNew
971 /**********************************************************
972 * IPersistHistory implementation
975 static inline HTMLDocument
*impl_from_IPersistHistory(IPersistHistory
*iface
)
977 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistHistory_iface
);
980 static HRESULT WINAPI
PersistHistory_QueryInterface(IPersistHistory
*iface
, REFIID riid
, void **ppv
)
982 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
983 return htmldoc_query_interface(This
, riid
, ppv
);
986 static ULONG WINAPI
PersistHistory_AddRef(IPersistHistory
*iface
)
988 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
989 return htmldoc_addref(This
);
992 static ULONG WINAPI
PersistHistory_Release(IPersistHistory
*iface
)
994 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
995 return htmldoc_release(This
);
998 static HRESULT WINAPI
PersistHistory_GetClassID(IPersistHistory
*iface
, CLSID
*pClassID
)
1000 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1001 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
1004 static HRESULT WINAPI
PersistHistory_LoadHistory(IPersistHistory
*iface
, IStream
*pStream
, IBindCtx
*pbc
)
1006 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1007 ULONG str_len
, read
;
1012 TRACE("(%p)->(%p %p)\n", This
, pStream
, pbc
);
1015 FIXME("No current window\n");
1016 return E_UNEXPECTED
;
1020 FIXME("pbc not supported\n");
1022 if(This
->doc_obj
->client
) {
1023 IOleCommandTarget
*cmdtrg
= NULL
;
1025 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
1027 if(SUCCEEDED(hres
)) {
1028 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 138, 0, NULL
, NULL
);
1029 IOleCommandTarget_Release(cmdtrg
);
1033 hres
= IStream_Read(pStream
, &str_len
, sizeof(str_len
), &read
);
1036 if(read
!= sizeof(str_len
))
1039 uri_str
= heap_alloc((str_len
+1)*sizeof(WCHAR
));
1041 return E_OUTOFMEMORY
;
1043 hres
= IStream_Read(pStream
, uri_str
, str_len
*sizeof(WCHAR
), &read
);
1044 if(SUCCEEDED(hres
) && read
!= str_len
*sizeof(WCHAR
))
1046 if(SUCCEEDED(hres
)) {
1047 uri_str
[str_len
] = 0;
1048 hres
= create_uri(uri_str
, 0, &uri
);
1054 hres
= load_uri(This
->window
, uri
, BINDING_FROMHIST
);
1059 static HRESULT WINAPI
PersistHistory_SaveHistory(IPersistHistory
*iface
, IStream
*pStream
)
1061 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1066 TRACE("(%p)->(%p)\n", This
, pStream
);
1068 if(!This
->window
|| !This
->window
->uri
) {
1069 FIXME("No current URI\n");
1073 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1074 * store only URI of the page (as a length followed by a string) */
1075 hres
= IUri_GetDisplayUri(This
->window
->uri
, &display_uri
);
1079 len
= SysStringLen(display_uri
);
1080 hres
= IStream_Write(pStream
, &len
, sizeof(len
), &written
);
1082 hres
= IStream_Write(pStream
, display_uri
, len
*sizeof(WCHAR
), &written
);
1083 SysFreeString(display_uri
);
1087 static HRESULT WINAPI
PersistHistory_SetPositionCookie(IPersistHistory
*iface
, DWORD dwPositioncookie
)
1089 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1090 FIXME("(%p)->(%x)\n", This
, dwPositioncookie
);
1094 static HRESULT WINAPI
PersistHistory_GetPositionCookie(IPersistHistory
*iface
, DWORD
*pdwPositioncookie
)
1096 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1097 FIXME("(%p)->(%p)\n", This
, pdwPositioncookie
);
1101 static const IPersistHistoryVtbl PersistHistoryVtbl
= {
1102 PersistHistory_QueryInterface
,
1103 PersistHistory_AddRef
,
1104 PersistHistory_Release
,
1105 PersistHistory_GetClassID
,
1106 PersistHistory_LoadHistory
,
1107 PersistHistory_SaveHistory
,
1108 PersistHistory_SetPositionCookie
,
1109 PersistHistory_GetPositionCookie
1112 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
1114 This
->IPersistMoniker_iface
.lpVtbl
= &PersistMonikerVtbl
;
1115 This
->IPersistFile_iface
.lpVtbl
= &PersistFileVtbl
;
1116 This
->IMonikerProp_iface
.lpVtbl
= &MonikerPropVtbl
;
1117 This
->IPersistStreamInit_iface
.lpVtbl
= &PersistStreamInitVtbl
;
1118 This
->IPersistHistory_iface
.lpVtbl
= &PersistHistoryVtbl
;