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
33 #define NO_SHLWAPI_REG
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
39 #include "htmlscript.h"
40 #include "htmlevent.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};
56 } download_proc_task_t
;
58 static void notify_travellog_update(HTMLDocumentObj
*doc
)
60 IOleCommandTarget
*cmdtrg
;
66 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
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
)
81 IUri_Release(window
->uri
);
85 if(window
->uri_nofrag
) {
86 IUri_Release(window
->uri_nofrag
);
87 window
->uri_nofrag
= NULL
;
90 SysFreeString(window
->url
);
99 window
->uri_nofrag
= get_uri_nofrag(uri
);
100 if(!window
->uri_nofrag
) {
101 FIXME("get_uri_nofrag failed\n");
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
;
116 if(This
->browser
&& !(flags
& (BINDING_REPLACE
|BINDING_REFRESH
))) {
117 if(is_main_content_window(This
))
118 notify_travellog_update(This
->browser
->doc
);
120 TRACE("Skipping travellog update for frame navigation.\n");
122 IMoniker_Release(This
->mon
);
126 This
->load_flags
= flags
;
130 IMoniker_AddRef(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
);
138 WARN("GetIUri failed: %08x\n", hres
);
146 hres
= IMoniker_GetDisplayName(mon
, NULL
, NULL
, &url
);
147 if(SUCCEEDED(hres
)) {
148 hres
= create_uri(url
, 0, &uri
);
150 WARN("CreateUri failed: %08x\n", hres
);
151 set_current_uri(This
, NULL
);
152 This
->url
= SysAllocString(url
);
158 WARN("GetDisplayName failed: %08x\n", hres
);
162 set_current_uri(This
, 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
)
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
)
185 IOleCommandTarget
*olecmd
;
188 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
189 if(SUCCEEDED(hres
)) {
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
;
211 TRACE("(%p)\n", doc
);
214 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&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
,
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
);
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
;
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);
262 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
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
);
283 void prepare_for_binding(HTMLDocument
*This
, IMoniker
*mon
, DWORD flags
)
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
);
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
,
320 if(SUCCEEDED(hres
)) {
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
);
330 }else if(!(flags
& BINDING_FROMHIST
)) {
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
,
344 download_proc_task_t
*download_task
;
345 HTMLDocumentObj
*doc_obj
= NULL
;
346 nsChannelBSC
*bscallback
;
352 if(is_main_content_window(window
))
353 doc_obj
= window
->browser
->doc
;
355 hres
= IMoniker_GetDisplayName(mon
, pibc
, NULL
, &url
);
357 WARN("GetDisplayName failed: %08x\n", hres
);
364 hres
= create_uri(url
, 0, &uri
);
371 TRACE("got url: %s\n", debugstr_w(url
));
373 set_ready_state(window
, READYSTATE_LOADING
);
375 hres
= create_doc_uri(uri
, &nsuri
);
378 if(SUCCEEDED(hres
)) {
380 bscallback
= async_bsc
;
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
);
406 HTMLDocument_LockContainer(doc_obj
, TRUE
);
411 task
= heap_alloc(sizeof(docobj_task_t
));
413 hres
= push_task(&task
->header
, set_progress_proc
, NULL
, doc_obj
->task_magic
);
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
);
430 static void notif_readystate(HTMLOuterWindow
*window
)
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
);
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
);
591 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
594 IUnknown
*unk
= NULL
;
598 * "__PrecreatedObject"
599 * "BIND_CONTEXT_PARAM"
600 * "__HTMLLOADOPTIONS"
603 * "_ITransData_Object_"
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
) {
625 hres
= MimeOleObjectFromMoniker(0, pimkName
, pibc
, &IID_IUnknown
, (void**)&unk
, &mon
);
628 IUnknown_Release(unk
);
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
);
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
);
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
);
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
)
668 IMoniker_AddRef(This
->window
->mon
);
669 *ppimkName
= This
->window
->mon
;
673 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
674 PersistMoniker_QueryInterface
,
675 PersistMoniker_AddRef
,
676 PersistMoniker_Release
,
677 PersistMoniker_GetClassID
,
678 PersistMoniker_IsDirty
,
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
));
720 heap_free(This
->doc_obj
->mime
);
721 This
->doc_obj
->mime
= heap_strdupW(val
);
728 FIXME("mkp %d\n", mkp
);
735 static const IMonikerPropVtbl MonikerPropVtbl
= {
736 MonikerProp_QueryInterface
,
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
);
778 *pClassID
= CLSID_HTMLDocument
;
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
);
798 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
800 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
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());
815 hres
= get_doc_string(This
->doc_node
, &str
);
817 WriteFile(file
, str
, strlen(str
), &written
, NULL
);
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
));
830 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
832 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
833 FIXME("(%p)->(%p)\n", This
, pszFileName
);
837 static const IPersistFileVtbl PersistFileVtbl
= {
838 PersistFile_QueryInterface
,
841 PersistFile_GetClassID
,
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
);
894 TRACE("(%p)->(%p)\n", This
, pStm
);
896 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
898 WARN("CreateURLMoniker failed: %08x\n", hres
);
902 prepare_for_binding(This
, mon
, FALSE
);
903 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, TRUE
);
905 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, pStm
);
907 IMoniker_Release(mon
);
911 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, IStream
*pStm
,
914 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
919 TRACE("(%p)->(%p %x)\n", This
, pStm
, fClearDirty
);
921 hres
= get_doc_string(This
->doc_node
, &str
);
925 hres
= IStream_Write(pStm
, str
, strlen(str
), &written
);
927 FIXME("Write failed: %08x\n", hres
);
932 set_dirty(This
->doc_obj
->nscontainer
, VARIANT_FALSE
);
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
);
945 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
947 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
951 TRACE("(%p)\n", This
);
953 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
955 WARN("CreateURLMoniker failed: %08x\n", hres
);
959 prepare_for_binding(This
, mon
, FALSE
);
960 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, FALSE
);
962 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, NULL
);
964 IMoniker_Release(mon
);
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
;
1021 TRACE("(%p)->(%p %p)\n", This
, pStream
, pbc
);
1024 FIXME("No current window\n");
1025 return E_UNEXPECTED
;
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
,
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
);
1045 if(read
!= sizeof(str_len
))
1048 uri_str
= heap_alloc((str_len
+1)*sizeof(WCHAR
));
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
))
1055 if(SUCCEEDED(hres
)) {
1056 uri_str
[str_len
] = 0;
1057 hres
= create_uri(uri_str
, 0, &uri
);
1063 hres
= load_uri(This
->window
, uri
, BINDING_FROMHIST
);
1068 static HRESULT WINAPI
PersistHistory_SaveHistory(IPersistHistory
*iface
, IStream
*pStream
)
1070 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1075 TRACE("(%p)->(%p)\n", This
, pStream
);
1077 if(!This
->window
|| !This
->window
->uri
) {
1078 FIXME("No current URI\n");
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
);
1088 len
= SysStringLen(display_uri
);
1089 hres
= IStream_Write(pStream
, &len
, sizeof(len
), &written
);
1091 hres
= IStream_Write(pStream
, display_uri
, len
*sizeof(WCHAR
), &written
);
1092 SysFreeString(display_uri
);
1096 static HRESULT WINAPI
PersistHistory_SetPositionCookie(IPersistHistory
*iface
, DWORD dwPositioncookie
)
1098 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1099 FIXME("(%p)->(%x)\n", This
, dwPositioncookie
);
1103 static HRESULT WINAPI
PersistHistory_GetPositionCookie(IPersistHistory
*iface
, DWORD
*pdwPositioncookie
)
1105 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1106 FIXME("(%p)->(%p)\n", This
, pdwPositioncookie
);
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
);
1155 static HRESULT WINAPI
HlinkTarget_GetBrowseContext(IHlinkTarget
*iface
, IHlinkBrowseContext
**ppihlbc
)
1157 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1158 FIXME("(%p)->(%p)\n", This
, ppihlbc
);
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
));
1169 FIXME("Unsupported grfHLNF=%08x\n", grfHLNF
);
1171 FIXME("JumpLocation not supported\n");
1173 if(!This
->doc_obj
->client
) {
1174 static const WCHAR szOpen
[] = {'o','p','e','n',0};
1178 hres
= IUri_GetAbsoluteUri(This
->window
->uri
, &uri
);
1182 ShellExecuteW(NULL
, szOpen
, uri
, NULL
, NULL
, SW_SHOW
);
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
);
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
);
1206 static const IHlinkTargetVtbl HlinkTargetVtbl
= {
1207 HlinkTarget_QueryInterface
,
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
;