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 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
39 #include "htmlevent.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
43 static BOOL use_gecko_script(LPCWSTR url)
45 static const WCHAR fileW[] = {'f','i','l','e',':'};
46 static const WCHAR aboutW[] = {'a','b','o','u','t',':'};
48 return strncmpiW(fileW, url, sizeof(fileW)/sizeof(WCHAR))
49 && strncmpiW(aboutW, url, sizeof(aboutW)/sizeof(WCHAR));
52 void set_current_mon(HTMLWindow *This, IMoniker *mon)
57 IMoniker_Release(This->mon);
62 CoTaskMemFree(This->url);
72 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
74 WARN("GetDisplayName failed: %08x\n", hres);
76 set_script_mode(This, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
79 static void set_progress_proc(task_t *_task)
81 docobj_task_t *task = (docobj_task_t*)_task;
82 IOleCommandTarget *olecmd = NULL;
83 HTMLDocumentObj *doc = task->doc;
89 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
92 VARIANT progress_max, progress;
94 V_VT(&progress_max) = VT_I4;
95 V_I4(&progress_max) = 0; /* FIXME */
96 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
99 V_VT(&progress) = VT_I4;
100 V_I4(&progress) = 0; /* FIXME */
101 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
105 if(doc->usermode == EDITMODE && doc->hostui) {
106 DOCHOSTUIINFO hostinfo;
108 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
109 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
110 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
112 /* FIXME: use hostinfo */
113 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
114 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
115 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
119 static void set_downloading_proc(task_t *_task)
121 HTMLDocumentObj *doc = ((docobj_task_t*)_task)->doc;
122 IOleCommandTarget *olecmd;
125 TRACE("(%p)\n", doc);
128 IOleInPlaceFrame_SetStatusText(doc->frame, NULL /* FIXME */);
133 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
134 if(SUCCEEDED(hres)) {
140 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE, OLECMDEXECOPT_DONTPROMPTUSER,
142 IOleCommandTarget_Release(olecmd);
146 IDropTarget *drop_target = NULL;
148 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
150 FIXME("Use IDropTarget\n");
151 IDropTarget_Release(drop_target);
156 static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc)
158 nsChannelBSC *bscallback;
165 IUnknown *unk = NULL;
169 * "__PrecreatedObject"
170 * "BIND_CONTEXT_PARAM"
171 * "__HTMLLOADOPTIONS"
175 * "_ITransData_Object_"
179 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
181 IOleClientSite *client = NULL;
183 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
184 if(SUCCEEDED(hres)) {
185 TRACE("Got client site %p\n", client);
186 IOleObject_SetClientSite(OLEOBJ(This), client);
187 IOleClientSite_Release(client);
190 IUnknown_Release(unk);
194 set_ready_state(This->window, READYSTATE_LOADING);
195 update_doc(This, UPDATE_TITLE);
197 HTMLDocument_LockContainer(This->doc_obj, TRUE);
199 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
201 WARN("GetDiaplayName failed: %08x\n", hres);
205 TRACE("got url: %s\n", debugstr_w(url));
207 set_current_mon(This->window, mon);
209 if(This->doc_obj->client) {
210 VARIANT silent, offline;
211 IOleCommandTarget *cmdtrg = NULL;
213 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
214 if(SUCCEEDED(hres)) {
215 if(V_VT(&silent) != VT_BOOL)
216 WARN("V_VT(silent) = %d\n", V_VT(&silent));
217 else if(V_BOOL(&silent))
218 FIXME("silent == true\n");
221 hres = get_client_disp_property(This->doc_obj->client,
222 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
223 if(SUCCEEDED(hres)) {
224 if(V_VT(&silent) != VT_BOOL)
225 WARN("V_VT(offline) = %d\n", V_VT(&silent));
226 else if(V_BOOL(&silent))
227 FIXME("offline == true\n");
230 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
232 if(SUCCEEDED(hres)) {
237 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
239 IOleCommandTarget_Release(cmdtrg);
243 bscallback = create_channelbsc(mon);
245 if(This->doc_obj->frame) {
246 task = heap_alloc(sizeof(docobj_task_t));
247 task->doc = This->doc_obj;
248 push_task(&task->header, set_progress_proc, This->doc_obj->basedoc.task_magic);
251 task = heap_alloc(sizeof(docobj_task_t));
252 task->doc = This->doc_obj;
253 push_task(&task->header, set_downloading_proc, This->doc_obj->basedoc.task_magic);
255 if(This->doc_obj->nscontainer) {
256 This->doc_obj->nscontainer->bscallback = bscallback;
257 nsres = nsIWebNavigation_LoadURI(This->doc_obj->nscontainer->navigation, url,
258 LOAD_FLAGS_NONE, NULL, NULL, NULL);
259 This->doc_obj->nscontainer->bscallback = NULL;
260 if(NS_FAILED(nsres)) {
261 WARN("LoadURI failed: %08x\n", nsres);
262 IUnknown_Release((IUnknown*)bscallback);
268 set_window_bscallback(This->window, bscallback);
269 IUnknown_Release((IUnknown*)bscallback);
275 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
277 window->readystate = readystate;
278 if(window->doc_obj && window->doc_obj->basedoc.window == window)
279 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
280 if(window->frame_element)
281 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
282 window->frame_element->element.node.nsnode, NULL);
285 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
293 WARN("NULL nsdoc\n");
297 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
298 if(NS_FAILED(nsres)) {
299 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
303 nsAString_Init(&nsstr, NULL);
304 nsnode_to_nsstring(nsnode, &nsstr);
305 nsIDOMNode_Release(nsnode);
307 nsAString_GetData(&nsstr, &strw);
308 TRACE("%s\n", debugstr_w(strw));
310 *str = heap_strdupWtoA(strw);
312 nsAString_Finish(&nsstr);
318 /**********************************************************
319 * IPersistMoniker implementation
322 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
324 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
327 HTMLDocument *This = PERSISTMON_THIS(iface);
328 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
331 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
333 HTMLDocument *This = PERSISTMON_THIS(iface);
334 return IHTMLDocument2_AddRef(HTMLDOC(This));
337 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
339 HTMLDocument *This = PERSISTMON_THIS(iface);
340 return IHTMLDocument2_Release(HTMLDOC(This));
343 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
345 HTMLDocument *This = PERSISTMON_THIS(iface);
346 return IPersist_GetClassID(PERSIST(This), pClassID);
349 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
351 HTMLDocument *This = PERSISTMON_THIS(iface);
353 TRACE("(%p)\n", This);
355 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
358 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
359 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
361 HTMLDocument *This = PERSISTMON_THIS(iface);
364 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
366 hres = set_moniker(This, pimkName, pibc);
370 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
373 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
374 LPBC pbc, BOOL fRemember)
376 HTMLDocument *This = PERSISTMON_THIS(iface);
377 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
381 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
383 HTMLDocument *This = PERSISTMON_THIS(iface);
384 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
388 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
390 HTMLDocument *This = PERSISTMON_THIS(iface);
392 TRACE("(%p)->(%p)\n", This, ppimkName);
394 if(!This->window || !This->window->mon)
397 IMoniker_AddRef(This->window->mon);
398 *ppimkName = This->window->mon;
402 static const IPersistMonikerVtbl PersistMonikerVtbl = {
403 PersistMoniker_QueryInterface,
404 PersistMoniker_AddRef,
405 PersistMoniker_Release,
406 PersistMoniker_GetClassID,
407 PersistMoniker_IsDirty,
410 PersistMoniker_SaveCompleted,
411 PersistMoniker_GetCurMoniker
414 /**********************************************************
415 * IMonikerProp implementation
418 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
420 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
422 HTMLDocument *This = MONPROP_THIS(iface);
423 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
426 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
428 HTMLDocument *This = MONPROP_THIS(iface);
429 return IHTMLDocument2_AddRef(HTMLDOC(This));
432 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
434 HTMLDocument *This = MONPROP_THIS(iface);
435 return IHTMLDocument_Release(HTMLDOC(This));
438 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
440 HTMLDocument *This = MONPROP_THIS(iface);
442 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
446 heap_free(This->doc_obj->mime);
447 This->doc_obj->mime = heap_strdupW(val);
454 FIXME("mkp %d\n", mkp);
461 static const IMonikerPropVtbl MonikerPropVtbl = {
462 MonikerProp_QueryInterface,
465 MonikerProp_PutProperty
468 /**********************************************************
469 * IPersistFile implementation
472 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
474 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
476 HTMLDocument *This = PERSISTFILE_THIS(iface);
477 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
480 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
482 HTMLDocument *This = PERSISTFILE_THIS(iface);
483 return IHTMLDocument2_AddRef(HTMLDOC(This));
486 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
488 HTMLDocument *This = PERSISTFILE_THIS(iface);
489 return IHTMLDocument2_Release(HTMLDOC(This));
492 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
494 HTMLDocument *This = PERSISTFILE_THIS(iface);
496 TRACE("(%p)->(%p)\n", This, pClassID);
501 *pClassID = CLSID_HTMLDocument;
505 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
507 HTMLDocument *This = PERSISTFILE_THIS(iface);
509 TRACE("(%p)\n", This);
511 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
514 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
516 HTMLDocument *This = PERSISTFILE_THIS(iface);
517 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
521 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
523 HTMLDocument *This = PERSISTFILE_THIS(iface);
529 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
531 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
532 FILE_ATTRIBUTE_NORMAL, NULL);
533 if(file == INVALID_HANDLE_VALUE) {
534 WARN("Could not create file: %u\n", GetLastError());
538 hres = get_doc_string(This->doc_node, &str);
540 WriteFile(file, str, strlen(str), &written, NULL);
546 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
548 HTMLDocument *This = PERSISTFILE_THIS(iface);
549 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
553 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
555 HTMLDocument *This = PERSISTFILE_THIS(iface);
556 FIXME("(%p)->(%p)\n", This, pszFileName);
560 static const IPersistFileVtbl PersistFileVtbl = {
561 PersistFile_QueryInterface,
564 PersistFile_GetClassID,
568 PersistFile_SaveCompleted,
569 PersistFile_GetCurFile
572 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
574 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
575 REFIID riid, void **ppv)
577 HTMLDocument *This = PERSTRINIT_THIS(iface);
578 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
581 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
583 HTMLDocument *This = PERSTRINIT_THIS(iface);
584 return IHTMLDocument2_AddRef(HTMLDOC(This));
587 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
589 HTMLDocument *This = PERSTRINIT_THIS(iface);
590 return IHTMLDocument2_Release(HTMLDOC(This));
593 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
595 HTMLDocument *This = PERSTRINIT_THIS(iface);
596 return IPersist_GetClassID(PERSIST(This), pClassID);
599 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
601 HTMLDocument *This = PERSTRINIT_THIS(iface);
603 TRACE("(%p)\n", This);
605 if(This->doc_obj->usermode == EDITMODE)
606 return editor_is_dirty(This);
611 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
613 HTMLDocument *This = PERSTRINIT_THIS(iface);
617 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
619 TRACE("(%p)->(%p)\n", This, pStm);
621 hres = CreateURLMoniker(NULL, about_blankW, &mon);
623 WARN("CreateURLMoniker failed: %08x\n", hres);
627 hres = set_moniker(This, mon, NULL);
628 IMoniker_Release(mon);
632 return channelbsc_load_stream(This->window->bscallback, pStm);
635 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
638 HTMLDocument *This = PERSTRINIT_THIS(iface);
643 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
645 hres = get_doc_string(This->doc_node, &str);
649 hres = IStream_Write(pStm, str, strlen(str), &written);
651 FIXME("Write failed: %08x\n", hres);
656 set_dirty(This, VARIANT_FALSE);
661 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
662 ULARGE_INTEGER *pcbSize)
664 HTMLDocument *This = PERSTRINIT_THIS(iface);
665 FIXME("(%p)->(%p)\n", This, pcbSize);
669 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
671 HTMLDocument *This = PERSTRINIT_THIS(iface);
672 FIXME("(%p)\n", This);
676 #undef PERSTRINIT_THIS
678 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
679 PersistStreamInit_QueryInterface,
680 PersistStreamInit_AddRef,
681 PersistStreamInit_Release,
682 PersistStreamInit_GetClassID,
683 PersistStreamInit_IsDirty,
684 PersistStreamInit_Load,
685 PersistStreamInit_Save,
686 PersistStreamInit_GetSizeMax,
687 PersistStreamInit_InitNew
690 /**********************************************************
691 * IPersistHistory implementation
694 #define PERSISTHIST_THIS(iface) DEFINE_THIS(HTMLDocument, PersistHistory, iface)
696 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppvObject)
698 HTMLDocument *This = PERSISTHIST_THIS(iface);
699 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
702 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
704 HTMLDocument *This = PERSISTHIST_THIS(iface);
705 return IHTMLDocument2_AddRef(HTMLDOC(This));
708 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
710 HTMLDocument *This = PERSISTHIST_THIS(iface);
711 return IHTMLDocument2_Release(HTMLDOC(This));
714 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
716 HTMLDocument *This = PERSISTHIST_THIS(iface);
717 return IPersist_GetClassID(PERSIST(This), pClassID);
720 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
722 HTMLDocument *This = PERSISTHIST_THIS(iface);
723 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
727 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
729 HTMLDocument *This = PERSISTHIST_THIS(iface);
730 FIXME("(%p)->(%p)\n", This, pStream);
734 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
736 HTMLDocument *This = PERSISTHIST_THIS(iface);
737 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
741 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
743 HTMLDocument *This = PERSISTHIST_THIS(iface);
744 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
748 #undef PERSISTHIST_THIS
750 static const IPersistHistoryVtbl PersistHistoryVtbl = {
751 PersistHistory_QueryInterface,
752 PersistHistory_AddRef,
753 PersistHistory_Release,
754 PersistHistory_GetClassID,
755 PersistHistory_LoadHistory,
756 PersistHistory_SaveHistory,
757 PersistHistory_SetPositionCookie,
758 PersistHistory_GetPositionCookie
761 void HTMLDocument_Persist_Init(HTMLDocument *This)
763 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
764 This->lpPersistFileVtbl = &PersistFileVtbl;
765 This->lpMonikerPropVtbl = &MonikerPropVtbl;
766 This->lpPersistStreamInitVtbl = &PersistStreamInitVtbl;
767 This->lpPersistHistoryVtbl = &PersistHistoryVtbl;