wrc: Use ARRAY_SIZE instead of open coding it.
[wine.git] / dlls / mshtml / persist.c
blob1f8e47b936f4a6994daff76ece7e32180043af9e
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 typedef struct {
50 task_t header;
51 HTMLDocumentObj *doc;
52 BOOL set_download;
53 LPOLESTR url;
54 } download_proc_task_t;
56 static void notify_travellog_update(HTMLDocumentObj *doc)
58 IOleCommandTarget *cmdtrg;
59 HRESULT hres;
61 if(!doc->webbrowser)
62 return;
64 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
65 if(SUCCEEDED(hres)) {
66 VARIANT vin;
68 V_VT(&vin) = VT_I4;
69 V_I4(&vin) = 0;
71 IOleCommandTarget_Exec(cmdtrg, &CGID_Explorer, CMDID_EXPLORER_UPDATEHISTORY, 0, &vin, NULL);
72 IOleCommandTarget_Release(cmdtrg);
76 void set_current_uri(HTMLOuterWindow *window, IUri *uri)
78 if(window->uri) {
79 IUri_Release(window->uri);
80 window->uri = NULL;
83 if(window->uri_nofrag) {
84 IUri_Release(window->uri_nofrag);
85 window->uri_nofrag = NULL;
88 SysFreeString(window->url);
89 window->url = NULL;
91 if(!uri)
92 return;
94 IUri_AddRef(uri);
95 window->uri = uri;
97 window->uri_nofrag = get_uri_nofrag(uri);
98 if(!window->uri_nofrag) {
99 FIXME("get_uri_nofrag failed\n");
100 IUri_AddRef(uri);
101 window->uri_nofrag = uri;
104 IUri_GetDisplayUri(uri, &window->url);
107 void set_current_mon(HTMLOuterWindow *This, IMoniker *mon, DWORD flags)
109 IUriContainer *uri_container;
110 IUri *uri = NULL;
111 HRESULT hres;
113 if(This->mon) {
114 if(This->browser && !(flags & (BINDING_REPLACE|BINDING_REFRESH))) {
115 if(is_main_content_window(This))
116 notify_travellog_update(This->browser->doc);
117 else
118 TRACE("Skipping travellog update for frame navigation.\n");
120 IMoniker_Release(This->mon);
121 This->mon = NULL;
124 This->load_flags = flags;
125 if(!mon)
126 return;
128 IMoniker_AddRef(mon);
129 This->mon = mon;
131 hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
132 if(SUCCEEDED(hres)) {
133 hres = IUriContainer_GetIUri(uri_container, &uri);
134 IUriContainer_Release(uri_container);
135 if(hres != S_OK) {
136 WARN("GetIUri failed: %08lx\n", hres);
137 uri = NULL;
141 if(!uri) {
142 WCHAR *url;
144 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
145 if(SUCCEEDED(hres)) {
146 hres = create_uri(url, 0, &uri);
147 if(FAILED(hres)) {
148 WARN("CreateUri failed: %08lx\n", hres);
149 set_current_uri(This, NULL);
150 This->url = SysAllocString(url);
151 CoTaskMemFree(url);
152 return;
154 CoTaskMemFree(url);
155 }else {
156 WARN("GetDisplayName failed: %08lx\n", hres);
160 set_current_uri(This, uri);
161 if(uri)
162 IUri_Release(uri);
164 if(is_main_content_window(This))
165 update_browser_script_mode(This->browser, uri);
168 HRESULT create_uri(const WCHAR *uri_str, DWORD flags, IUri **uri)
170 return CreateUri(uri_str, flags | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, uri);
173 HRESULT create_relative_uri(HTMLOuterWindow *window, const WCHAR *rel_uri, IUri **uri)
175 return window->uri
176 ? CoInternetCombineUrlEx(window->uri, rel_uri, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, uri, 0)
177 : create_uri(rel_uri, 0, uri);
180 void set_download_state(HTMLDocumentObj *doc, int state)
182 if(doc->client) {
183 IOleCommandTarget *olecmd;
184 HRESULT hres;
186 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
187 if(SUCCEEDED(hres)) {
188 VARIANT var;
190 V_VT(&var) = VT_I4;
191 V_I4(&var) = state;
193 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
194 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
195 IOleCommandTarget_Release(olecmd);
199 doc->download_state = state;
202 static void set_progress_proc(task_t *_task)
204 docobj_task_t *task = (docobj_task_t*)_task;
205 IOleCommandTarget *olecmd = NULL;
206 HTMLDocumentObj *doc = task->doc;
207 HRESULT hres;
209 TRACE("(%p)\n", doc);
211 if(doc->client)
212 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
214 if(olecmd) {
215 VARIANT progress_max, progress;
217 V_VT(&progress_max) = VT_I4;
218 V_I4(&progress_max) = 0; /* FIXME */
219 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
220 &progress_max, NULL);
222 V_VT(&progress) = VT_I4;
223 V_I4(&progress) = 0; /* FIXME */
224 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
225 &progress, NULL);
226 IOleCommandTarget_Release(olecmd);
229 if(doc->nscontainer->usermode == EDITMODE && doc->hostui) {
230 DOCHOSTUIINFO hostinfo;
232 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
233 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
234 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
235 if(SUCCEEDED(hres))
236 /* FIXME: use hostinfo */
237 TRACE("hostinfo = {%lu %08lx %08lx %s %s}\n",
238 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
239 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
243 static void set_downloading_proc(task_t *_task)
245 download_proc_task_t *task = (download_proc_task_t*)_task;
246 HTMLDocumentObj *doc = task->doc;
247 HRESULT hres;
249 TRACE("(%p)\n", doc);
251 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
253 if(task->set_download)
254 set_download_state(doc, 1);
256 if(!doc->client)
257 return;
259 if(doc->view_sink)
260 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
262 if(doc->hostui) {
263 IDropTarget *drop_target = NULL;
265 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
266 if(SUCCEEDED(hres) && drop_target) {
267 FIXME("Use IDropTarget\n");
268 IDropTarget_Release(drop_target);
273 static void set_downloading_task_destr(task_t *_task)
275 download_proc_task_t *task = (download_proc_task_t*)_task;
277 CoTaskMemFree(task->url);
278 heap_free(task);
281 void prepare_for_binding(HTMLDocumentObj *This, IMoniker *mon, DWORD flags)
283 HRESULT hres;
285 if(This->client) {
286 VARIANT silent, offline;
288 hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
289 if(SUCCEEDED(hres)) {
290 if(V_VT(&silent) != VT_BOOL)
291 WARN("silent = %s\n", debugstr_variant(&silent));
292 else if(V_BOOL(&silent))
293 FIXME("silent == true\n");
296 hres = get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
297 if(SUCCEEDED(hres)) {
298 if(V_VT(&offline) != VT_BOOL)
299 WARN("offline = %s\n", debugstr_variant(&offline));
300 else if(V_BOOL(&offline))
301 FIXME("offline == true\n");
305 if(This->basedoc.window->mon) {
306 update_doc(This, UPDATE_TITLE|UPDATE_UI);
307 }else {
308 update_doc(This, UPDATE_TITLE);
309 set_current_mon(This->basedoc.window, mon, flags);
312 if(This->client) {
313 IOleCommandTarget *cmdtrg = NULL;
315 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
316 if(SUCCEEDED(hres)) {
317 VARIANT var, out;
319 if(flags & BINDING_NAVIGATED) {
320 V_VT(&var) = VT_UNKNOWN;
321 V_UNKNOWN(&var) = (IUnknown*)&This->basedoc.window->base.IHTMLWindow2_iface;
322 V_VT(&out) = VT_EMPTY;
323 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
324 if(SUCCEEDED(hres))
325 VariantClear(&out);
326 }else if(!(flags & BINDING_FROMHIST)) {
327 V_VT(&var) = VT_I4;
328 V_I4(&var) = 0;
329 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
332 IOleCommandTarget_Release(cmdtrg);
337 HRESULT set_moniker(HTMLOuterWindow *window, IMoniker *mon, IUri *nav_uri, IBindCtx *pibc, nsChannelBSC *async_bsc,
338 BOOL set_download)
340 download_proc_task_t *download_task;
341 HTMLDocumentObj *doc_obj = NULL;
342 nsChannelBSC *bscallback;
343 nsWineURI *nsuri;
344 LPOLESTR url;
345 IUri *uri;
346 HRESULT hres;
348 if(is_main_content_window(window))
349 doc_obj = window->browser->doc;
351 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
352 if(FAILED(hres)) {
353 WARN("GetDisplayName failed: %08lx\n", hres);
354 return hres;
357 if(nav_uri) {
358 uri = nav_uri;
359 }else {
360 hres = create_uri(url, 0, &uri);
361 if(FAILED(hres)) {
362 CoTaskMemFree(url);
363 return hres;
367 TRACE("got url: %s\n", debugstr_w(url));
369 set_ready_state(window, READYSTATE_LOADING);
371 hres = create_doc_uri(uri, &nsuri);
372 if(!nav_uri)
373 IUri_Release(uri);
374 if(SUCCEEDED(hres)) {
375 if(async_bsc)
376 bscallback = async_bsc;
377 else
378 hres = create_channelbsc(mon, NULL, NULL, 0, TRUE, &bscallback);
381 if(SUCCEEDED(hres)) {
382 if(window->base.inner_window->doc)
383 remove_target_tasks(window->base.inner_window->task_magic);
384 abort_window_bindings(window->base.inner_window);
386 hres = load_nsuri(window, nsuri, NULL, bscallback, LOAD_FLAGS_BYPASS_CACHE);
387 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
388 if(SUCCEEDED(hres)) {
389 hres = create_pending_window(window, bscallback);
390 TRACE("pending window for %p %p %p\n", window, bscallback, window->pending_window);
392 if(bscallback != async_bsc)
393 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
396 if(FAILED(hres)) {
397 CoTaskMemFree(url);
398 return hres;
401 if(doc_obj) {
402 HTMLDocument_LockContainer(doc_obj, TRUE);
404 if(doc_obj->frame) {
405 docobj_task_t *task;
407 task = heap_alloc(sizeof(docobj_task_t));
408 task->doc = doc_obj;
409 hres = push_task(&task->header, set_progress_proc, NULL, doc_obj->task_magic);
410 if(FAILED(hres)) {
411 CoTaskMemFree(url);
412 return hres;
416 download_task = heap_alloc(sizeof(download_proc_task_t));
417 download_task->doc = doc_obj;
418 download_task->set_download = set_download;
419 download_task->url = url;
420 return push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, doc_obj->task_magic);
423 return S_OK;
426 static void notif_readystate(HTMLOuterWindow *window)
428 DOMEvent *event;
429 HRESULT hres;
431 window->readystate_pending = FALSE;
433 if(is_main_content_window(window))
434 call_property_onchanged(&window->browser->doc->cp_container, DISPID_READYSTATE);
436 hres = create_document_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, &event);
437 if(SUCCEEDED(hres)) {
438 event->no_event_obj = TRUE;
439 dispatch_event(&window->base.inner_window->doc->node.event_target, event);
440 IDOMEvent_Release(&event->IDOMEvent_iface);
443 if(window->frame_element) {
444 hres = create_document_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE, &event);
445 if(SUCCEEDED(hres)) {
446 dispatch_event(&window->frame_element->element.node.event_target, event);
447 IDOMEvent_Release(&event->IDOMEvent_iface);
452 typedef struct {
453 task_t header;
454 HTMLOuterWindow *window;
455 } readystate_task_t;
457 static void notif_readystate_proc(task_t *_task)
459 readystate_task_t *task = (readystate_task_t*)_task;
460 notif_readystate(task->window);
463 static void notif_readystate_destr(task_t *_task)
465 readystate_task_t *task = (readystate_task_t*)_task;
466 IHTMLWindow2_Release(&task->window->base.IHTMLWindow2_iface);
469 void set_ready_state(HTMLOuterWindow *window, READYSTATE readystate)
471 READYSTATE prev_state = window->readystate;
473 window->readystate = readystate;
475 if(window->readystate_locked) {
476 readystate_task_t *task;
477 HRESULT hres;
479 if(window->readystate_pending || prev_state == readystate)
480 return;
482 task = heap_alloc(sizeof(*task));
483 if(!task)
484 return;
486 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
487 task->window = window;
489 hres = push_task(&task->header, notif_readystate_proc, notif_readystate_destr, window->task_magic);
490 if(SUCCEEDED(hres))
491 window->readystate_pending = TRUE;
492 return;
495 notif_readystate(window);
498 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
500 nsIDOMNode *nsnode;
501 LPCWSTR strw;
502 nsAString nsstr;
503 nsresult nsres;
504 HRESULT hres;
506 if(!This->nsdoc) {
507 WARN("NULL nsdoc\n");
508 return E_UNEXPECTED;
511 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
512 if(NS_FAILED(nsres)) {
513 ERR("Could not get nsIDOMNode failed: %08lx\n", nsres);
514 return E_FAIL;
517 nsAString_Init(&nsstr, NULL);
518 hres = nsnode_to_nsstring(nsnode, &nsstr);
519 nsIDOMNode_Release(nsnode);
520 if(FAILED(hres)) {
521 nsAString_Finish(&nsstr);
522 return hres;
525 nsAString_GetData(&nsstr, &strw);
526 TRACE("%s\n", debugstr_w(strw));
528 *str = heap_strdupWtoA(strw);
530 nsAString_Finish(&nsstr);
532 if(!*str)
533 return E_OUTOFMEMORY;
534 return S_OK;
538 /**********************************************************
539 * IPersistMoniker implementation
542 static inline HTMLDocumentNode *HTMLDocumentNode_from_IPersistMoniker(IPersistMoniker *iface)
544 return CONTAINING_RECORD(iface, HTMLDocumentNode, IPersistMoniker_iface);
547 static HRESULT WINAPI DocNodePersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
549 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
550 return htmldoc_query_interface(&This->basedoc, riid, ppv);
553 static ULONG WINAPI DocNodePersistMoniker_AddRef(IPersistMoniker *iface)
555 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
556 return htmldoc_addref(&This->basedoc);
559 static ULONG WINAPI DocNodePersistMoniker_Release(IPersistMoniker *iface)
561 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
562 return htmldoc_release(&This->basedoc);
565 static HRESULT WINAPI DocNodePersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
567 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
568 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
571 static HRESULT WINAPI DocNodePersistMoniker_IsDirty(IPersistMoniker *iface)
573 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
575 TRACE("(%p)\n", This);
577 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
580 static HRESULT WINAPI DocNodePersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
581 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
583 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
584 return IPersistMoniker_Load(&This->basedoc.doc_obj->IPersistMoniker_iface, fFullyAvailable, pimkName, pibc, grfMode);
587 static HRESULT WINAPI DocNodePersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
588 LPBC pbc, BOOL fRemember)
590 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
591 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
592 return E_NOTIMPL;
595 static HRESULT WINAPI DocNodePersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
597 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
598 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
599 return E_NOTIMPL;
602 static HRESULT WINAPI DocNodePersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
604 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistMoniker(iface);
605 return IPersistMoniker_GetCurMoniker(&This->basedoc.doc_obj->IPersistMoniker_iface, ppimkName);
608 static const IPersistMonikerVtbl DocNodePersistMonikerVtbl = {
609 DocNodePersistMoniker_QueryInterface,
610 DocNodePersistMoniker_AddRef,
611 DocNodePersistMoniker_Release,
612 DocNodePersistMoniker_GetClassID,
613 DocNodePersistMoniker_IsDirty,
614 DocNodePersistMoniker_Load,
615 DocNodePersistMoniker_Save,
616 DocNodePersistMoniker_SaveCompleted,
617 DocNodePersistMoniker_GetCurMoniker
620 static inline HTMLDocumentObj *HTMLDocumentObj_from_IPersistMoniker(IPersistMoniker *iface)
622 return CONTAINING_RECORD(iface, HTMLDocumentObj, IPersistMoniker_iface);
625 static HRESULT WINAPI DocObjPersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
627 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
628 return htmldoc_query_interface(&This->basedoc, riid, ppv);
631 static ULONG WINAPI DocObjPersistMoniker_AddRef(IPersistMoniker *iface)
633 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
634 return htmldoc_addref(&This->basedoc);
637 static ULONG WINAPI DocObjPersistMoniker_Release(IPersistMoniker *iface)
639 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
640 return htmldoc_release(&This->basedoc);
643 static HRESULT WINAPI DocObjPersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
645 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
646 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
649 static HRESULT WINAPI DocObjPersistMoniker_IsDirty(IPersistMoniker *iface)
651 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
653 TRACE("(%p)\n", This);
655 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
658 static HRESULT WINAPI DocObjPersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
659 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
661 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
662 IMoniker *mon;
663 HRESULT hres;
665 TRACE("(%p)->(%x %p %p %08lx)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
667 if(pibc) {
668 IUnknown *unk = NULL;
670 /* FIXME:
671 * Use params:
672 * "__PrecreatedObject"
673 * "BIND_CONTEXT_PARAM"
674 * "__HTMLLOADOPTIONS"
675 * "__DWNBINDINFO"
676 * "URL Context"
677 * "_ITransData_Object_"
678 * "_EnumFORMATETC_"
681 hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
682 if(SUCCEEDED(hres) && unk) {
683 IOleClientSite *client = NULL;
685 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
686 if(SUCCEEDED(hres)) {
687 TRACE("Got client site %p\n", client);
688 IOleObject_SetClientSite(&This->IOleObject_iface, client);
689 IOleClientSite_Release(client);
692 IUnknown_Release(unk);
696 if(This->is_mhtml) {
697 IUnknown *unk;
699 hres = MimeOleObjectFromMoniker(0, pimkName, pibc, &IID_IUnknown, (void**)&unk, &mon);
700 if(FAILED(hres))
701 return hres;
702 IUnknown_Release(unk);
703 pibc = NULL;
704 }else {
705 IMoniker_AddRef(mon = pimkName);
708 prepare_for_binding(This, mon, FALSE);
709 call_docview_84(This);
710 hres = set_moniker(This->basedoc.window, mon, NULL, pibc, NULL, TRUE);
711 IMoniker_Release(mon);
712 if(FAILED(hres))
713 return hres;
715 return start_binding(This->basedoc.window->pending_window, (BSCallback*)This->basedoc.window->pending_window->bscallback, pibc);
718 static HRESULT WINAPI DocObjPersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
719 LPBC pbc, BOOL fRemember)
721 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
722 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
723 return E_NOTIMPL;
726 static HRESULT WINAPI DocObjPersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
728 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
729 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
730 return E_NOTIMPL;
733 static HRESULT WINAPI DocObjPersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
735 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistMoniker(iface);
737 TRACE("(%p)->(%p)\n", This, ppimkName);
739 if(!This->basedoc.window || !This->basedoc.window->mon)
740 return E_UNEXPECTED;
742 IMoniker_AddRef(This->basedoc.window->mon);
743 *ppimkName = This->basedoc.window->mon;
744 return S_OK;
747 static const IPersistMonikerVtbl DocObjPersistMonikerVtbl = {
748 DocObjPersistMoniker_QueryInterface,
749 DocObjPersistMoniker_AddRef,
750 DocObjPersistMoniker_Release,
751 DocObjPersistMoniker_GetClassID,
752 DocObjPersistMoniker_IsDirty,
753 DocObjPersistMoniker_Load,
754 DocObjPersistMoniker_Save,
755 DocObjPersistMoniker_SaveCompleted,
756 DocObjPersistMoniker_GetCurMoniker
759 /**********************************************************
760 * IMonikerProp implementation
763 static inline HTMLDocumentNode *HTMLDocumentNode_from_IMonikerProp(IMonikerProp *iface)
765 return CONTAINING_RECORD(iface, HTMLDocumentNode, IMonikerProp_iface);
768 static HRESULT WINAPI DocNodeMonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
770 HTMLDocumentNode *This = HTMLDocumentNode_from_IMonikerProp(iface);
771 return htmldoc_query_interface(&This->basedoc, riid, ppv);
774 static ULONG WINAPI DocNodeMonikerProp_AddRef(IMonikerProp *iface)
776 HTMLDocumentNode *This = HTMLDocumentNode_from_IMonikerProp(iface);
777 return htmldoc_addref(&This->basedoc);
780 static ULONG WINAPI DocNodeMonikerProp_Release(IMonikerProp *iface)
782 HTMLDocumentNode *This = HTMLDocumentNode_from_IMonikerProp(iface);
783 return htmldoc_release(&This->basedoc);
786 static HRESULT WINAPI DocNodeMonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
788 HTMLDocumentNode *This = HTMLDocumentNode_from_IMonikerProp(iface);
789 return IMonikerProp_PutProperty(&This->basedoc.doc_obj->IMonikerProp_iface, mkp, val);
792 static const IMonikerPropVtbl DocNodeMonikerPropVtbl = {
793 DocNodeMonikerProp_QueryInterface,
794 DocNodeMonikerProp_AddRef,
795 DocNodeMonikerProp_Release,
796 DocNodeMonikerProp_PutProperty
799 static inline HTMLDocumentObj *HTMLDocumentObj_from_IMonikerProp(IMonikerProp *iface)
801 return CONTAINING_RECORD(iface, HTMLDocumentObj, IMonikerProp_iface);
804 static HRESULT WINAPI DocObjMonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
806 HTMLDocumentObj *This = HTMLDocumentObj_from_IMonikerProp(iface);
807 return htmldoc_query_interface(&This->basedoc, riid, ppv);
810 static ULONG WINAPI DocObjMonikerProp_AddRef(IMonikerProp *iface)
812 HTMLDocumentObj *This = HTMLDocumentObj_from_IMonikerProp(iface);
813 return htmldoc_addref(&This->basedoc);
816 static ULONG WINAPI DocObjMonikerProp_Release(IMonikerProp *iface)
818 HTMLDocumentObj *This = HTMLDocumentObj_from_IMonikerProp(iface);
819 return htmldoc_release(&This->basedoc);
822 static HRESULT WINAPI DocObjMonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
824 HTMLDocumentObj *This = HTMLDocumentObj_from_IMonikerProp(iface);
826 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
828 switch(mkp) {
829 case MIMETYPEPROP:
830 heap_free(This->mime);
831 This->mime = heap_strdupW(val);
832 break;
834 case CLASSIDPROP:
835 break;
837 default:
838 FIXME("mkp %d\n", mkp);
839 return E_NOTIMPL;
842 return S_OK;
845 static const IMonikerPropVtbl DocObjMonikerPropVtbl = {
846 DocObjMonikerProp_QueryInterface,
847 DocObjMonikerProp_AddRef,
848 DocObjMonikerProp_Release,
849 DocObjMonikerProp_PutProperty
852 /**********************************************************
853 * IPersistFile implementation
856 static inline HTMLDocumentNode *HTMLDocumentNode_from_IPersistFile(IPersistFile *iface)
858 return CONTAINING_RECORD(iface, HTMLDocumentNode, IPersistFile_iface);
861 static HRESULT WINAPI DocNodePersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
863 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
864 return htmldoc_query_interface(&This->basedoc, riid, ppv);
867 static ULONG WINAPI DocNodePersistFile_AddRef(IPersistFile *iface)
869 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
870 return htmldoc_addref(&This->basedoc);
873 static ULONG WINAPI DocNodePersistFile_Release(IPersistFile *iface)
875 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
876 return htmldoc_release(&This->basedoc);
879 static HRESULT WINAPI DocNodePersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
881 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
882 return IPersistFile_GetClassID(&This->basedoc.doc_obj->IPersistFile_iface, pClassID);
885 static HRESULT WINAPI DocNodePersistFile_IsDirty(IPersistFile *iface)
887 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
889 TRACE("(%p)\n", This);
891 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
894 static HRESULT WINAPI DocNodePersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
896 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
897 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
898 return E_NOTIMPL;
901 static HRESULT WINAPI DocNodePersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
903 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
904 char *str;
905 DWORD written=0;
906 HANDLE file;
907 HRESULT hres;
909 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
911 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
912 FILE_ATTRIBUTE_NORMAL, NULL);
913 if(file == INVALID_HANDLE_VALUE) {
914 WARN("Could not create file: %lu\n", GetLastError());
915 return E_FAIL;
918 hres = get_doc_string(This, &str);
919 if(SUCCEEDED(hres))
920 WriteFile(file, str, strlen(str), &written, NULL);
922 CloseHandle(file);
923 return hres;
926 static HRESULT WINAPI DocNodePersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
928 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
929 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
930 return E_NOTIMPL;
933 static HRESULT WINAPI DocNodePersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
935 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistFile(iface);
936 FIXME("(%p)->(%p)\n", This, pszFileName);
937 return E_NOTIMPL;
940 static const IPersistFileVtbl DocNodePersistFileVtbl = {
941 DocNodePersistFile_QueryInterface,
942 DocNodePersistFile_AddRef,
943 DocNodePersistFile_Release,
944 DocNodePersistFile_GetClassID,
945 DocNodePersistFile_IsDirty,
946 DocNodePersistFile_Load,
947 DocNodePersistFile_Save,
948 DocNodePersistFile_SaveCompleted,
949 DocNodePersistFile_GetCurFile
952 static inline HTMLDocumentObj *HTMLDocumentObj_from_IPersistFile(IPersistFile *iface)
954 return CONTAINING_RECORD(iface, HTMLDocumentObj, IPersistFile_iface);
957 static HRESULT WINAPI DocObjPersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
959 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
960 return htmldoc_query_interface(&This->basedoc, riid, ppv);
963 static ULONG WINAPI DocObjPersistFile_AddRef(IPersistFile *iface)
965 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
966 return htmldoc_addref(&This->basedoc);
969 static ULONG WINAPI DocObjPersistFile_Release(IPersistFile *iface)
971 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
972 return htmldoc_release(&This->basedoc);
975 static HRESULT WINAPI DocObjPersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
977 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
979 TRACE("(%p)->(%p)\n", This, pClassID);
981 if(!pClassID)
982 return E_INVALIDARG;
984 *pClassID = CLSID_HTMLDocument;
985 return S_OK;
988 static HRESULT WINAPI DocObjPersistFile_IsDirty(IPersistFile *iface)
990 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
992 TRACE("(%p)\n", This);
994 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
997 static HRESULT WINAPI DocObjPersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
999 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
1000 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI DocObjPersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
1006 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
1008 if(!This->basedoc.doc_node) {
1009 FIXME("No doc_node\n");
1010 return E_UNEXPECTED;
1012 return IPersistFile_Save(&This->basedoc.doc_node->IPersistFile_iface, pszFileName, fRemember);
1015 static HRESULT WINAPI DocObjPersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
1017 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
1018 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
1019 return E_NOTIMPL;
1022 static HRESULT WINAPI DocObjPersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
1024 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistFile(iface);
1025 FIXME("(%p)->(%p)\n", This, pszFileName);
1026 return E_NOTIMPL;
1029 static const IPersistFileVtbl DocObjPersistFileVtbl = {
1030 DocObjPersistFile_QueryInterface,
1031 DocObjPersistFile_AddRef,
1032 DocObjPersistFile_Release,
1033 DocObjPersistFile_GetClassID,
1034 DocObjPersistFile_IsDirty,
1035 DocObjPersistFile_Load,
1036 DocObjPersistFile_Save,
1037 DocObjPersistFile_SaveCompleted,
1038 DocObjPersistFile_GetCurFile
1041 static inline HTMLDocumentNode *HTMLDocumentNode_from_IPersistStreamInit(IPersistStreamInit *iface)
1043 return CONTAINING_RECORD(iface, HTMLDocumentNode, IPersistStreamInit_iface);
1046 static HRESULT WINAPI DocNodePersistStreamInit_QueryInterface(IPersistStreamInit *iface,
1047 REFIID riid, void **ppv)
1049 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1050 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1053 static ULONG WINAPI DocNodePersistStreamInit_AddRef(IPersistStreamInit *iface)
1055 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1056 return htmldoc_addref(&This->basedoc);
1059 static ULONG WINAPI DocNodePersistStreamInit_Release(IPersistStreamInit *iface)
1061 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1062 return htmldoc_release(&This->basedoc);
1065 static HRESULT WINAPI DocNodePersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
1067 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1068 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1071 static HRESULT WINAPI DocNodePersistStreamInit_IsDirty(IPersistStreamInit *iface)
1073 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1074 return IPersistStreamInit_IsDirty(&This->basedoc.doc_obj->IPersistStreamInit_iface);
1077 static HRESULT WINAPI DocNodePersistStreamInit_Load(IPersistStreamInit *iface, IStream *pStm)
1079 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1080 return IPersistStreamInit_Load(&This->basedoc.doc_obj->IPersistStreamInit_iface, pStm);
1083 static HRESULT WINAPI DocNodePersistStreamInit_Save(IPersistStreamInit *iface, IStream *pStm,
1084 BOOL fClearDirty)
1086 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1087 char *str;
1088 DWORD written=0;
1089 HRESULT hres;
1091 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
1093 hres = get_doc_string(This, &str);
1094 if(FAILED(hres))
1095 return hres;
1097 hres = IStream_Write(pStm, str, strlen(str), &written);
1098 if(FAILED(hres))
1099 FIXME("Write failed: %08lx\n", hres);
1101 heap_free(str);
1103 if(fClearDirty)
1104 set_dirty(This->basedoc.doc_obj->nscontainer, VARIANT_FALSE);
1106 return S_OK;
1109 static HRESULT WINAPI DocNodePersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
1110 ULARGE_INTEGER *pcbSize)
1112 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1113 FIXME("(%p)->(%p)\n", This, pcbSize);
1114 return E_NOTIMPL;
1117 static HRESULT WINAPI DocNodePersistStreamInit_InitNew(IPersistStreamInit *iface)
1119 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistStreamInit(iface);
1120 return IPersistStreamInit_InitNew(&This->basedoc.doc_obj->IPersistStreamInit_iface);
1123 static const IPersistStreamInitVtbl DocNodePersistStreamInitVtbl = {
1124 DocNodePersistStreamInit_QueryInterface,
1125 DocNodePersistStreamInit_AddRef,
1126 DocNodePersistStreamInit_Release,
1127 DocNodePersistStreamInit_GetClassID,
1128 DocNodePersistStreamInit_IsDirty,
1129 DocNodePersistStreamInit_Load,
1130 DocNodePersistStreamInit_Save,
1131 DocNodePersistStreamInit_GetSizeMax,
1132 DocNodePersistStreamInit_InitNew
1135 static inline HTMLDocumentObj *HTMLDocumentObj_from_IPersistStreamInit(IPersistStreamInit *iface)
1137 return CONTAINING_RECORD(iface, HTMLDocumentObj, IPersistStreamInit_iface);
1140 static HRESULT WINAPI DocObjPersistStreamInit_QueryInterface(IPersistStreamInit *iface,
1141 REFIID riid, void **ppv)
1143 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1144 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1147 static ULONG WINAPI DocObjPersistStreamInit_AddRef(IPersistStreamInit *iface)
1149 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1150 return htmldoc_addref(&This->basedoc);
1153 static ULONG WINAPI DocObjPersistStreamInit_Release(IPersistStreamInit *iface)
1155 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1156 return htmldoc_release(&This->basedoc);
1159 static HRESULT WINAPI DocObjPersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
1161 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1162 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1165 static HRESULT WINAPI DocObjPersistStreamInit_IsDirty(IPersistStreamInit *iface)
1167 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1169 TRACE("(%p)\n", This);
1171 return browser_is_dirty(This->nscontainer);
1174 static HRESULT WINAPI DocObjPersistStreamInit_Load(IPersistStreamInit *iface, IStream *pStm)
1176 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1177 IMoniker *mon;
1178 HRESULT hres;
1180 TRACE("(%p)->(%p)\n", This, pStm);
1182 hres = CreateURLMoniker(NULL, L"about:blank", &mon);
1183 if(FAILED(hres)) {
1184 WARN("CreateURLMoniker failed: %08lx\n", hres);
1185 return hres;
1188 prepare_for_binding(This, mon, FALSE);
1189 hres = set_moniker(This->basedoc.window, mon, NULL, NULL, NULL, TRUE);
1190 if(SUCCEEDED(hres))
1191 hres = channelbsc_load_stream(This->basedoc.window->pending_window, mon, pStm);
1193 IMoniker_Release(mon);
1194 return hres;
1197 static HRESULT WINAPI DocObjPersistStreamInit_Save(IPersistStreamInit *iface, IStream *pStm,
1198 BOOL fClearDirty)
1200 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1202 if(!This->basedoc.doc_node) {
1203 FIXME("No doc_node\n");
1204 return E_UNEXPECTED;
1206 return IPersistStreamInit_Save(&This->basedoc.doc_node->IPersistStreamInit_iface, pStm, fClearDirty);
1209 static HRESULT WINAPI DocObjPersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
1210 ULARGE_INTEGER *pcbSize)
1212 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1213 FIXME("(%p)->(%p)\n", This, pcbSize);
1214 return E_NOTIMPL;
1217 static HRESULT WINAPI DocObjPersistStreamInit_InitNew(IPersistStreamInit *iface)
1219 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistStreamInit(iface);
1220 IMoniker *mon;
1221 HRESULT hres;
1223 TRACE("(%p)\n", This);
1225 hres = CreateURLMoniker(NULL, L"about:blank", &mon);
1226 if(FAILED(hres)) {
1227 WARN("CreateURLMoniker failed: %08lx\n", hres);
1228 return hres;
1231 prepare_for_binding(This, mon, FALSE);
1232 hres = set_moniker(This->basedoc.window, mon, NULL, NULL, NULL, FALSE);
1233 if(SUCCEEDED(hres))
1234 hres = channelbsc_load_stream(This->basedoc.window->pending_window, mon, NULL);
1236 IMoniker_Release(mon);
1237 return hres;
1240 static const IPersistStreamInitVtbl DocObjPersistStreamInitVtbl = {
1241 DocObjPersistStreamInit_QueryInterface,
1242 DocObjPersistStreamInit_AddRef,
1243 DocObjPersistStreamInit_Release,
1244 DocObjPersistStreamInit_GetClassID,
1245 DocObjPersistStreamInit_IsDirty,
1246 DocObjPersistStreamInit_Load,
1247 DocObjPersistStreamInit_Save,
1248 DocObjPersistStreamInit_GetSizeMax,
1249 DocObjPersistStreamInit_InitNew
1252 /**********************************************************
1253 * IPersistHistory implementation
1256 static inline HTMLDocumentNode *HTMLDocumentNode_from_IPersistHistory(IPersistHistory *iface)
1258 return CONTAINING_RECORD(iface, HTMLDocumentNode, IPersistHistory_iface);
1261 static HRESULT WINAPI DocNodePersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
1263 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1264 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1267 static ULONG WINAPI DocNodePersistHistory_AddRef(IPersistHistory *iface)
1269 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1270 return htmldoc_addref(&This->basedoc);
1273 static ULONG WINAPI DocNodePersistHistory_Release(IPersistHistory *iface)
1275 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1276 return htmldoc_release(&This->basedoc);
1279 static HRESULT WINAPI DocNodePersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
1281 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1282 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1285 static HRESULT WINAPI DocNodePersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
1287 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1288 return IPersistHistory_LoadHistory(&This->basedoc.doc_obj->IPersistHistory_iface, pStream, pbc);
1291 static HRESULT WINAPI DocNodePersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1293 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1294 return IPersistHistory_SaveHistory(&This->basedoc.doc_obj->IPersistHistory_iface, pStream);
1297 static HRESULT WINAPI DocNodePersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1299 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1300 FIXME("(%p)->(%lx)\n", This, dwPositioncookie);
1301 return E_NOTIMPL;
1304 static HRESULT WINAPI DocNodePersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1306 HTMLDocumentNode *This = HTMLDocumentNode_from_IPersistHistory(iface);
1307 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1308 return E_NOTIMPL;
1311 static const IPersistHistoryVtbl DocNodePersistHistoryVtbl = {
1312 DocNodePersistHistory_QueryInterface,
1313 DocNodePersistHistory_AddRef,
1314 DocNodePersistHistory_Release,
1315 DocNodePersistHistory_GetClassID,
1316 DocNodePersistHistory_LoadHistory,
1317 DocNodePersistHistory_SaveHistory,
1318 DocNodePersistHistory_SetPositionCookie,
1319 DocNodePersistHistory_GetPositionCookie
1322 static inline HTMLDocumentObj *HTMLDocumentObj_from_IPersistHistory(IPersistHistory *iface)
1324 return CONTAINING_RECORD(iface, HTMLDocumentObj, IPersistHistory_iface);
1327 static HRESULT WINAPI DocObjPersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
1329 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1330 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1333 static ULONG WINAPI DocObjPersistHistory_AddRef(IPersistHistory *iface)
1335 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1336 return htmldoc_addref(&This->basedoc);
1339 static ULONG WINAPI DocObjPersistHistory_Release(IPersistHistory *iface)
1341 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1342 return htmldoc_release(&This->basedoc);
1345 static HRESULT WINAPI DocObjPersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
1347 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1348 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1351 static HRESULT WINAPI DocObjPersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
1353 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1354 ULONG str_len, read;
1355 WCHAR *uri_str;
1356 IUri *uri;
1357 HRESULT hres;
1359 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
1361 if(!This->basedoc.window) {
1362 FIXME("No current window\n");
1363 return E_UNEXPECTED;
1366 if(pbc)
1367 FIXME("pbc not supported\n");
1369 if(This->client) {
1370 IOleCommandTarget *cmdtrg = NULL;
1372 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1373 if(SUCCEEDED(hres)) {
1374 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 138, 0, NULL, NULL);
1375 IOleCommandTarget_Release(cmdtrg);
1379 hres = IStream_Read(pStream, &str_len, sizeof(str_len), &read);
1380 if(FAILED(hres))
1381 return hres;
1382 if(read != sizeof(str_len))
1383 return E_FAIL;
1385 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
1386 if(!uri_str)
1387 return E_OUTOFMEMORY;
1389 hres = IStream_Read(pStream, uri_str, str_len*sizeof(WCHAR), &read);
1390 if(SUCCEEDED(hres) && read != str_len*sizeof(WCHAR))
1391 hres = E_FAIL;
1392 if(SUCCEEDED(hres)) {
1393 uri_str[str_len] = 0;
1394 hres = create_uri(uri_str, 0, &uri);
1396 heap_free(uri_str);
1397 if(FAILED(hres))
1398 return hres;
1400 hres = load_uri(This->basedoc.window, uri, BINDING_FROMHIST);
1401 IUri_Release(uri);
1402 return hres;
1405 static HRESULT WINAPI DocObjPersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1407 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1408 ULONG len, written;
1409 BSTR display_uri;
1410 HRESULT hres;
1412 TRACE("(%p)->(%p)\n", This, pStream);
1414 if(!This->basedoc.window || !This->basedoc.window->uri) {
1415 FIXME("No current URI\n");
1416 return E_FAIL;
1419 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1420 * store only URI of the page (as a length followed by a string) */
1421 hres = IUri_GetDisplayUri(This->basedoc.window->uri, &display_uri);
1422 if(FAILED(hres))
1423 return hres;
1425 len = SysStringLen(display_uri);
1426 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1427 if(SUCCEEDED(hres))
1428 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1429 SysFreeString(display_uri);
1430 return hres;
1433 static HRESULT WINAPI DocObjPersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1435 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1436 FIXME("(%p)->(%lx)\n", This, dwPositioncookie);
1437 return E_NOTIMPL;
1440 static HRESULT WINAPI DocObjPersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1442 HTMLDocumentObj *This = HTMLDocumentObj_from_IPersistHistory(iface);
1443 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1444 return E_NOTIMPL;
1447 static const IPersistHistoryVtbl DocObjPersistHistoryVtbl = {
1448 DocObjPersistHistory_QueryInterface,
1449 DocObjPersistHistory_AddRef,
1450 DocObjPersistHistory_Release,
1451 DocObjPersistHistory_GetClassID,
1452 DocObjPersistHistory_LoadHistory,
1453 DocObjPersistHistory_SaveHistory,
1454 DocObjPersistHistory_SetPositionCookie,
1455 DocObjPersistHistory_GetPositionCookie
1458 /**********************************************************
1459 * IHlinkTarget implementation
1462 static inline HTMLDocumentNode *HTMLDocumentNode_from_IHlinkTarget(IHlinkTarget *iface)
1464 return CONTAINING_RECORD(iface, HTMLDocumentNode, IHlinkTarget_iface);
1467 static HRESULT WINAPI DocNodeHlinkTarget_QueryInterface(IHlinkTarget *iface, REFIID riid, void **ppv)
1469 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1470 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1473 static ULONG WINAPI DocNodeHlinkTarget_AddRef(IHlinkTarget *iface)
1475 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1476 return htmldoc_addref(&This->basedoc);
1479 static ULONG WINAPI DocNodeHlinkTarget_Release(IHlinkTarget *iface)
1481 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1482 return htmldoc_release(&This->basedoc);
1485 static HRESULT WINAPI DocNodeHlinkTarget_SetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext *pihlbc)
1487 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1488 FIXME("(%p)->(%p)\n", This, pihlbc);
1489 return E_NOTIMPL;
1492 static HRESULT WINAPI DocNodeHlinkTarget_GetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext **ppihlbc)
1494 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1495 FIXME("(%p)->(%p)\n", This, ppihlbc);
1496 return E_NOTIMPL;
1499 static HRESULT WINAPI DocNodeHlinkTarget_Navigate(IHlinkTarget *iface, DWORD grfHLNF, LPCWSTR pwzJumpLocation)
1501 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1503 TRACE("(%p)->(%08lx %s)\n", This, grfHLNF, debugstr_w(pwzJumpLocation));
1505 if(grfHLNF)
1506 FIXME("Unsupported grfHLNF=%08lx\n", grfHLNF);
1507 if(pwzJumpLocation)
1508 FIXME("JumpLocation not supported\n");
1510 if(This->basedoc.doc_obj->client)
1511 return IOleObject_DoVerb(&This->IOleObject_iface, OLEIVERB_SHOW, NULL, NULL, -1, NULL, NULL);
1513 return IHlinkTarget_Navigate(&This->basedoc.doc_obj->IHlinkTarget_iface, grfHLNF, pwzJumpLocation);
1516 static HRESULT WINAPI DocNodeHlinkTarget_GetMoniker(IHlinkTarget *iface, LPCWSTR pwzLocation, DWORD dwAssign,
1517 IMoniker **ppimkLocation)
1519 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1520 FIXME("(%p)->(%s %08lx %p)\n", This, debugstr_w(pwzLocation), dwAssign, ppimkLocation);
1521 return E_NOTIMPL;
1524 static HRESULT WINAPI DocNodeHlinkTarget_GetFriendlyName(IHlinkTarget *iface, LPCWSTR pwzLocation,
1525 LPWSTR *ppwzFriendlyName)
1527 HTMLDocumentNode *This = HTMLDocumentNode_from_IHlinkTarget(iface);
1528 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwzLocation), ppwzFriendlyName);
1529 return E_NOTIMPL;
1532 static const IHlinkTargetVtbl DocNodeHlinkTargetVtbl = {
1533 DocNodeHlinkTarget_QueryInterface,
1534 DocNodeHlinkTarget_AddRef,
1535 DocNodeHlinkTarget_Release,
1536 DocNodeHlinkTarget_SetBrowseContext,
1537 DocNodeHlinkTarget_GetBrowseContext,
1538 DocNodeHlinkTarget_Navigate,
1539 DocNodeHlinkTarget_GetMoniker,
1540 DocNodeHlinkTarget_GetFriendlyName
1543 static inline HTMLDocumentObj *HTMLDocumentObj_from_IHlinkTarget(IHlinkTarget *iface)
1545 return CONTAINING_RECORD(iface, HTMLDocumentObj, IHlinkTarget_iface);
1548 static HRESULT WINAPI DocObjHlinkTarget_QueryInterface(IHlinkTarget *iface, REFIID riid, void **ppv)
1550 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1551 return htmldoc_query_interface(&This->basedoc, riid, ppv);
1554 static ULONG WINAPI DocObjHlinkTarget_AddRef(IHlinkTarget *iface)
1556 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1557 return htmldoc_addref(&This->basedoc);
1560 static ULONG WINAPI DocObjHlinkTarget_Release(IHlinkTarget *iface)
1562 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1563 return htmldoc_release(&This->basedoc);
1566 static HRESULT WINAPI DocObjHlinkTarget_SetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext *pihlbc)
1568 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1569 FIXME("(%p)->(%p)\n", This, pihlbc);
1570 return E_NOTIMPL;
1573 static HRESULT WINAPI DocObjHlinkTarget_GetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext **ppihlbc)
1575 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1576 FIXME("(%p)->(%p)\n", This, ppihlbc);
1577 return E_NOTIMPL;
1580 static HRESULT WINAPI DocObjHlinkTarget_Navigate(IHlinkTarget *iface, DWORD grfHLNF, LPCWSTR pwzJumpLocation)
1582 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1584 TRACE("(%p)->(%08lx %s)\n", This, grfHLNF, debugstr_w(pwzJumpLocation));
1586 if(grfHLNF)
1587 FIXME("Unsupported grfHLNF=%08lx\n", grfHLNF);
1588 if(pwzJumpLocation)
1589 FIXME("JumpLocation not supported\n");
1591 if(!This->client) {
1592 HRESULT hres;
1593 BSTR uri;
1595 hres = IUri_GetAbsoluteUri(This->basedoc.window->uri, &uri);
1596 if(FAILED(hres))
1597 return hres;
1599 if(hres == S_OK)
1600 ShellExecuteW(NULL, L"open", uri, NULL, NULL, SW_SHOW);
1601 SysFreeString(uri);
1602 return S_OK;
1605 return IOleObject_DoVerb(&This->IOleObject_iface, OLEIVERB_SHOW, NULL, NULL, -1, NULL, NULL);
1608 static HRESULT WINAPI DocObjHlinkTarget_GetMoniker(IHlinkTarget *iface, LPCWSTR pwzLocation, DWORD dwAssign,
1609 IMoniker **ppimkLocation)
1611 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1612 FIXME("(%p)->(%s %08lx %p)\n", This, debugstr_w(pwzLocation), dwAssign, ppimkLocation);
1613 return E_NOTIMPL;
1616 static HRESULT WINAPI DocObjHlinkTarget_GetFriendlyName(IHlinkTarget *iface, LPCWSTR pwzLocation,
1617 LPWSTR *ppwzFriendlyName)
1619 HTMLDocumentObj *This = HTMLDocumentObj_from_IHlinkTarget(iface);
1620 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwzLocation), ppwzFriendlyName);
1621 return E_NOTIMPL;
1624 static const IHlinkTargetVtbl DocObjHlinkTargetVtbl = {
1625 DocObjHlinkTarget_QueryInterface,
1626 DocObjHlinkTarget_AddRef,
1627 DocObjHlinkTarget_Release,
1628 DocObjHlinkTarget_SetBrowseContext,
1629 DocObjHlinkTarget_GetBrowseContext,
1630 DocObjHlinkTarget_Navigate,
1631 DocObjHlinkTarget_GetMoniker,
1632 DocObjHlinkTarget_GetFriendlyName
1635 void HTMLDocumentNode_Persist_Init(HTMLDocumentNode *This)
1637 This->IPersistMoniker_iface.lpVtbl = &DocNodePersistMonikerVtbl;
1638 This->IPersistFile_iface.lpVtbl = &DocNodePersistFileVtbl;
1639 This->IMonikerProp_iface.lpVtbl = &DocNodeMonikerPropVtbl;
1640 This->IPersistStreamInit_iface.lpVtbl = &DocNodePersistStreamInitVtbl;
1641 This->IPersistHistory_iface.lpVtbl = &DocNodePersistHistoryVtbl;
1642 This->IHlinkTarget_iface.lpVtbl = &DocNodeHlinkTargetVtbl;
1645 void HTMLDocumentObj_Persist_Init(HTMLDocumentObj *This)
1647 This->IPersistMoniker_iface.lpVtbl = &DocObjPersistMonikerVtbl;
1648 This->IPersistFile_iface.lpVtbl = &DocObjPersistFileVtbl;
1649 This->IMonikerProp_iface.lpVtbl = &DocObjMonikerPropVtbl;
1650 This->IPersistStreamInit_iface.lpVtbl = &DocObjPersistStreamInitVtbl;
1651 This->IPersistHistory_iface.lpVtbl = &DocObjPersistHistoryVtbl;
1652 This->IHlinkTarget_iface.lpVtbl = &DocObjHlinkTargetVtbl;