include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / ieframe / dochost.c
blobc76e91c2ff6690dc940cc44b44072388480e7289
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
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 "ieframe.h"
21 #include "exdispid.h"
22 #include "mshtml.h"
23 #include "perhist.h"
24 #include "initguid.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
30 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
32 #define DOCHOST_DOCCANNAVIGATE 0
34 /* Undocumented notification, see mshtml tests */
35 #define CMDID_EXPLORER_UPDATEHISTORY 38
37 static ATOM doc_view_atom = 0;
39 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, task_destr_t destr, BOOL send)
41 BOOL is_empty;
43 task->proc = proc;
44 task->destr = destr;
46 is_empty = list_empty(&This->task_queue);
47 list_add_tail(&This->task_queue, &task->entry);
49 if(send)
50 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
51 else if(is_empty)
52 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
55 LRESULT process_dochost_tasks(DocHost *This)
57 task_header_t *task;
59 while(!list_empty(&This->task_queue)) {
60 task = LIST_ENTRY(This->task_queue.next, task_header_t, entry);
61 list_remove(&task->entry);
63 task->proc(This, task);
64 task->destr(task);
67 return 0;
70 void abort_dochost_tasks(DocHost *This, task_proc_t proc)
72 task_header_t *task, *cursor;
74 LIST_FOR_EACH_ENTRY_SAFE(task, cursor, &This->task_queue, task_header_t, entry) {
75 if(proc && proc != task->proc)
76 continue;
78 list_remove(&task->entry);
79 task->destr(task);
83 static void notif_complete(DocHost *This, DISPID dispid)
85 DISPPARAMS dispparams;
86 VARIANTARG params[2];
87 VARIANT url;
89 dispparams.cArgs = 2;
90 dispparams.cNamedArgs = 0;
91 dispparams.rgdispidNamedArgs = NULL;
92 dispparams.rgvarg = params;
94 V_VT(params) = (VT_BYREF|VT_VARIANT);
95 V_BYREF(params) = &url;
97 V_VT(params+1) = VT_DISPATCH;
98 V_DISPATCH(params+1) = (IDispatch*)This->wb;
100 V_VT(&url) = VT_BSTR;
101 V_BSTR(&url) = SysAllocString(This->url);
103 TRACE("%d >>>\n", dispid);
104 call_sink(This->cps.wbe2, dispid, &dispparams);
105 TRACE("%d <<<\n", dispid);
107 SysFreeString(V_BSTR(&url));
108 This->busy = VARIANT_FALSE;
111 static void object_available(DocHost *This)
113 IHlinkTarget *hlink;
114 HRESULT hres;
116 TRACE("(%p)\n", This);
118 if(!This->document) {
119 WARN("document == NULL\n");
120 return;
123 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
124 if(SUCCEEDED(hres)) {
125 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
126 IHlinkTarget_Release(hlink);
127 if(FAILED(hres))
128 FIXME("Navigate failed\n");
129 }else {
130 IOleObject *ole_object;
131 RECT rect;
133 TRACE("No IHlink iface\n");
135 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&ole_object);
136 if(FAILED(hres)) {
137 FIXME("Could not get IOleObject iface: %08x\n", hres);
138 return;
141 GetClientRect(This->hwnd, &rect);
142 hres = IOleObject_DoVerb(ole_object, OLEIVERB_SHOW, NULL, &This->IOleClientSite_iface, -1, This->hwnd, &rect);
143 IOleObject_Release(ole_object);
144 if(FAILED(hres))
145 FIXME("DoVerb failed: %08x\n", hres);
149 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
151 DISPPARAMS dp = {NULL,NULL,0,0};
152 IDispatch *disp;
153 EXCEPINFO ei;
154 VARIANT var;
155 HRESULT hres;
157 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
158 if(FAILED(hres))
159 return hres;
161 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
162 &dp, &var, &ei, NULL);
163 IDispatch_Release(disp);
164 if(FAILED(hres)) {
165 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
166 return hres;
169 if(V_VT(&var) != VT_I4) {
170 WARN("V_VT(var) = %d\n", V_VT(&var));
171 VariantClear(&var);
172 return E_FAIL;
175 *ret = V_I4(&var);
176 return S_OK;
179 static void advise_prop_notif(DocHost *This, BOOL set)
181 IConnectionPointContainer *cp_container;
182 IConnectionPoint *cp;
183 HRESULT hres;
185 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
186 if(FAILED(hres))
187 return;
189 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
190 IConnectionPointContainer_Release(cp_container);
191 if(FAILED(hres))
192 return;
194 if(set)
195 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
196 else
197 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
198 IConnectionPoint_Release(cp);
200 if(SUCCEEDED(hres))
201 This->is_prop_notif = set;
204 void set_doc_state(DocHost *This, READYSTATE doc_state)
206 This->doc_state = doc_state;
207 if(doc_state > This->ready_state)
208 This->ready_state = doc_state;
211 static void update_ready_state(DocHost *This, READYSTATE ready_state)
213 if(ready_state > READYSTATE_LOADING && This->travellog.loading_pos != -1) {
214 WARN("histupdate not notified\n");
215 This->travellog.position = This->travellog.loading_pos;
216 This->travellog.loading_pos = -1;
219 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING && !This->browser_service /* FIXME */)
220 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
222 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
223 set_doc_state(This, READYSTATE_COMPLETE);
224 if(!This->browser_service) /* FIXME: Not fully correct */
225 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
226 }else {
227 set_doc_state(This, ready_state);
231 typedef struct {
232 task_header_t header;
233 IUnknown *doc;
234 READYSTATE ready_state;
235 } ready_state_task_t;
237 static void ready_state_task_destr(task_header_t *_task)
239 ready_state_task_t *task = (ready_state_task_t*)_task;
241 IUnknown_Release(task->doc);
242 heap_free(task);
245 static void ready_state_proc(DocHost *This, task_header_t *_task)
247 ready_state_task_t *task = (ready_state_task_t*)_task;
249 if(task->doc == This->document)
250 update_ready_state(This, task->ready_state);
253 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
255 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
257 IUnknown_AddRef(This->document);
258 task->doc = This->document;
259 task->ready_state = ready_state;
261 push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
264 static void object_available_task_destr(task_header_t *task)
266 heap_free(task);
269 static void object_available_proc(DocHost *This, task_header_t *task)
271 object_available(This);
274 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
276 READYSTATE ready_state;
277 task_header_t *task;
278 IOleObject *oleobj;
279 HRESULT hres;
281 IUnknown_AddRef(doc);
282 This->document = doc;
284 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
285 if(SUCCEEDED(hres)) {
286 CLSID clsid;
288 hres = IOleObject_GetUserClassID(oleobj, &clsid);
289 if(SUCCEEDED(hres))
290 TRACE("Got clsid %s\n",
291 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
293 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
294 if(FAILED(hres))
295 FIXME("SetClientSite failed: %08x\n", hres);
297 IOleObject_Release(oleobj);
298 }else {
299 FIXME("Could not get IOleObject iface: %08x\n", hres);
302 /* FIXME: Call SetAdvise */
304 task = heap_alloc(sizeof(*task));
305 push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
307 hres = get_doc_ready_state(This, &ready_state);
308 if(SUCCEEDED(hres)) {
309 if(ready_state == READYSTATE_COMPLETE)
310 push_ready_state_task(This, READYSTATE_COMPLETE);
311 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
312 advise_prop_notif(This, TRUE);
313 }else if(!This->doc_navigate) {
314 /* If we can't get document's ready state, there is not much we can do.
315 * Assume that document is complete at this point. */
316 push_ready_state_task(This, READYSTATE_COMPLETE);
319 return S_OK;
322 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
324 RECT rect = {0, 0, width, height};
326 TRACE("(%p)->(%d %d)\n", This, width, height);
328 if(This->view)
329 IOleDocumentView_SetRect(This->view, &rect);
331 return 0;
334 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
336 DocHost *This;
338 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
340 if(msg == WM_CREATE) {
341 This = *(DocHost**)lParam;
342 SetPropW(hwnd, wszTHIS, This);
343 }else {
344 This = GetPropW(hwnd, wszTHIS);
347 switch(msg) {
348 case WM_SIZE:
349 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
352 return DefWindowProcW(hwnd, msg, wParam, lParam);
355 static void free_travellog_entry(travellog_entry_t *entry)
357 if(entry->stream)
358 IStream_Release(entry->stream);
359 heap_free(entry->url);
362 static IStream *get_travellog_stream(DocHost *This)
364 IPersistHistory *persist_history;
365 IStream *stream;
366 HRESULT hres;
368 hres = IUnknown_QueryInterface(This->document, &IID_IPersistHistory, (void**)&persist_history);
369 if(FAILED(hres))
370 return NULL;
372 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
373 if(SUCCEEDED(hres))
374 hres = IPersistHistory_SaveHistory(persist_history, stream);
375 IPersistHistory_Release(persist_history);
376 if(FAILED(hres)) {
377 IStream_Release(stream);
378 return NULL;
381 return stream;
384 static void dump_travellog(DocHost *This)
386 unsigned i;
388 for(i=0; i < This->travellog.length; i++)
389 TRACE("%d: %s %s\n", i, i == This->travellog.position ? "=>" : " ", debugstr_w(This->travellog.log[i].url));
390 if(i == This->travellog.position)
391 TRACE("%d: =>\n", i);
394 static void update_travellog(DocHost *This)
396 travellog_entry_t *new_entry;
398 if(This->travellog.loading_pos == -1) {
399 /* Clear forward history. */
400 if(!This->travellog.log) {
401 This->travellog.log = heap_alloc(4 * sizeof(*This->travellog.log));
402 if(!This->travellog.log)
403 return;
405 This->travellog.size = 4;
406 }else if(This->travellog.size < This->travellog.position+1) {
407 travellog_entry_t *new_travellog;
409 new_travellog = heap_realloc(This->travellog.log, This->travellog.size*2*sizeof(*This->travellog.log));
410 if(!new_travellog)
411 return;
413 This->travellog.log = new_travellog;
414 This->travellog.size *= 2;
417 while(This->travellog.length > This->travellog.position)
418 free_travellog_entry(This->travellog.log + --This->travellog.length);
421 new_entry = This->travellog.log + This->travellog.position;
423 new_entry->url = heap_strdupW(This->url);
424 TRACE("Adding %s at %d\n", debugstr_w(This->url), This->travellog.position);
425 if(!new_entry->url)
426 return;
428 new_entry->stream = get_travellog_stream(This);
430 if(This->travellog.loading_pos == -1) {
431 This->travellog.position++;
432 }else {
433 This->travellog.position = This->travellog.loading_pos;
434 This->travellog.loading_pos = -1;
436 if(This->travellog.position > This->travellog.length)
437 This->travellog.length = This->travellog.position;
439 dump_travellog(This);
442 void create_doc_view_hwnd(DocHost *This)
444 RECT rect;
446 static const WCHAR wszShell_DocObject_View[] =
447 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
449 if(!doc_view_atom) {
450 static WNDCLASSEXW wndclass = {
451 sizeof(wndclass),
452 CS_PARENTDC,
453 doc_view_proc,
454 0, 0 /* native uses 4*/, NULL, NULL, NULL,
455 (HBRUSH)(COLOR_WINDOW + 1), NULL,
456 wszShell_DocObject_View,
457 NULL
460 wndclass.hInstance = ieframe_instance;
462 doc_view_atom = RegisterClassExW(&wndclass);
465 This->container_vtbl->GetDocObjRect(This, &rect);
466 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
467 wszShell_DocObject_View,
468 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
469 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
470 NULL, ieframe_instance, This);
473 void deactivate_document(DocHost *This)
475 IOleInPlaceObjectWindowless *winobj;
476 IOleObject *oleobj = NULL;
477 IHlinkTarget *hlink = NULL;
478 HRESULT hres;
480 if(!This->document) return;
482 if(This->doc_navigate) {
483 IUnknown_Release(This->doc_navigate);
484 This->doc_navigate = NULL;
487 if(This->is_prop_notif)
488 advise_prop_notif(This, FALSE);
490 if(This->view)
491 IOleDocumentView_UIActivate(This->view, FALSE);
493 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
494 (void**)&winobj);
495 if(SUCCEEDED(hres)) {
496 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
497 IOleInPlaceObjectWindowless_Release(winobj);
500 if(This->view) {
501 IOleDocumentView_Show(This->view, FALSE);
502 IOleDocumentView_CloseView(This->view, 0);
503 IOleDocumentView_SetInPlaceSite(This->view, NULL);
504 IOleDocumentView_Release(This->view);
505 This->view = NULL;
508 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
509 if(SUCCEEDED(hres))
510 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
512 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
513 if(SUCCEEDED(hres)) {
514 IHlinkTarget_SetBrowseContext(hlink, NULL);
515 IHlinkTarget_Release(hlink);
518 if(oleobj) {
519 IOleClientSite *client_site = NULL;
521 IOleObject_GetClientSite(oleobj, &client_site);
522 if(client_site) {
523 if(client_site == &This->IOleClientSite_iface)
524 IOleObject_SetClientSite(oleobj, NULL);
525 IOleClientSite_Release(client_site);
528 IOleObject_Release(oleobj);
531 IUnknown_Release(This->document);
532 This->document = NULL;
535 HRESULT refresh_document(DocHost *This, const VARIANT *level)
537 IOleCommandTarget *cmdtrg;
538 VARIANT vin, vout;
539 HRESULT hres;
541 if(level && (V_VT(level) != VT_I4 || V_I4(level) != REFRESH_NORMAL))
542 FIXME("Unsupported refresh level %s\n", debugstr_variant(level));
544 if(!This->document) {
545 FIXME("no document\n");
546 return E_FAIL;
549 hres = IUnknown_QueryInterface(This->document, &IID_IOleCommandTarget, (void**)&cmdtrg);
550 if(FAILED(hres))
551 return hres;
553 V_VT(&vin) = VT_EMPTY;
554 V_VT(&vout) = VT_EMPTY;
555 hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_REFRESH, OLECMDEXECOPT_PROMPTUSER, &vin, &vout);
556 IOleCommandTarget_Release(cmdtrg);
557 if(FAILED(hres))
558 return hres;
560 VariantClear(&vout);
561 return S_OK;
564 void release_dochost_client(DocHost *This)
566 if(This->hwnd) {
567 DestroyWindow(This->hwnd);
568 This->hwnd = NULL;
571 if(This->hostui) {
572 IDocHostUIHandler_Release(This->hostui);
573 This->hostui = NULL;
576 if(This->client_disp) {
577 IDispatch_Release(This->client_disp);
578 This->client_disp = NULL;
581 if(This->frame) {
582 IOleInPlaceFrame_Release(This->frame);
583 This->frame = NULL;
587 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
589 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
592 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
593 REFIID riid, void **ppv)
595 DocHost *This = impl_from_IOleCommandTarget(iface);
596 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
599 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
601 DocHost *This = impl_from_IOleCommandTarget(iface);
602 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
605 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
607 DocHost *This = impl_from_IOleCommandTarget(iface);
608 return IOleClientSite_Release(&This->IOleClientSite_iface);
611 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
612 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
614 DocHost *This = impl_from_IOleCommandTarget(iface);
615 ULONG i= 0;
616 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
617 pCmdText);
618 while (prgCmds && (cCmds > i)) {
619 FIXME("command_%u: %u, 0x%x\n", i, prgCmds[i].cmdID, prgCmds[i].cmdf);
620 i++;
622 return E_NOTIMPL;
625 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
626 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
627 VARIANT *pvaOut)
629 DocHost *This = impl_from_IOleCommandTarget(iface);
631 TRACE("(%p)->(%s %d %d %s %s)\n", This, debugstr_guid(pguidCmdGroup), nCmdID, nCmdexecopt,
632 debugstr_variant(pvaIn), debugstr_variant(pvaOut));
634 if(!pguidCmdGroup) {
635 switch(nCmdID) {
636 case OLECMDID_UPDATECOMMANDS:
637 case OLECMDID_SETDOWNLOADSTATE:
638 return This->container_vtbl->exec(This, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
639 default:
640 FIXME("Unimplemented cmdid %d\n", nCmdID);
641 return E_NOTIMPL;
645 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
646 switch(nCmdID) {
647 case DOCHOST_DOCCANNAVIGATE:
648 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
649 return E_INVALIDARG;
651 if(This->doc_navigate)
652 IUnknown_Release(This->doc_navigate);
653 IUnknown_AddRef(V_UNKNOWN(pvaIn));
654 This->doc_navigate = V_UNKNOWN(pvaIn);
655 return S_OK;
657 case 1: {
658 IHTMLWindow2 *win2;
659 SAFEARRAY *sa = V_ARRAY(pvaIn);
660 VARIANT status_code, url, htmlwindow;
661 LONG ind;
662 HRESULT hres;
664 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
665 return E_INVALIDARG;
667 ind = 0;
668 hres = SafeArrayGetElement(sa, &ind, &status_code);
669 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
670 return E_INVALIDARG;
672 ind = 1;
673 hres = SafeArrayGetElement(sa, &ind, &url);
674 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
675 return E_INVALIDARG;
677 ind = 3;
678 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
679 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
680 return E_INVALIDARG;
682 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
683 if(FAILED(hres))
684 return E_INVALIDARG;
686 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
687 IHTMLWindow2_Release(win2);
688 return S_OK;
691 default:
692 FIXME("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
693 return E_NOTIMPL;
697 if(IsEqualGUID(pguidCmdGroup, &CGID_Explorer)) {
698 switch(nCmdID) {
699 case CMDID_EXPLORER_UPDATEHISTORY:
700 update_travellog(This);
701 return S_OK;
703 default:
704 FIXME("Unimplemented cmdid %d of CGID_Explorer\n", nCmdID);
705 return E_NOTIMPL;
709 if(IsEqualGUID(pguidCmdGroup, &CGID_ShellDocView)) {
710 switch(nCmdID) {
711 default:
712 FIXME("Unimplemented cmdid %d of CGID_ShellDocView\n", nCmdID);
713 return E_NOTIMPL;
717 if(IsEqualGUID(&CGID_DocHostCommandHandler, pguidCmdGroup))
718 return This->container_vtbl->exec(This, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
720 FIXME("Unimplemented cmdid %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
721 return E_NOTIMPL;
724 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
725 ClOleCommandTarget_QueryInterface,
726 ClOleCommandTarget_AddRef,
727 ClOleCommandTarget_Release,
728 ClOleCommandTarget_QueryStatus,
729 ClOleCommandTarget_Exec
732 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
734 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
737 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
738 REFIID riid, void **ppv)
740 DocHost *This = impl_from_IDocHostUIHandler2(iface);
741 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
744 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
746 DocHost *This = impl_from_IDocHostUIHandler2(iface);
747 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
750 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
752 DocHost *This = impl_from_IDocHostUIHandler2(iface);
753 return IOleClientSite_Release(&This->IOleClientSite_iface);
756 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
757 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
759 DocHost *This = impl_from_IDocHostUIHandler2(iface);
760 HRESULT hres;
762 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
764 if(This->hostui) {
765 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
766 pdispReserved);
767 if(hres == S_OK)
768 return S_OK;
771 FIXME("default action not implemented\n");
772 return E_NOTIMPL;
775 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
776 DOCHOSTUIINFO *pInfo)
778 DocHost *This = impl_from_IDocHostUIHandler2(iface);
779 HRESULT hres;
781 TRACE("(%p)->(%p)\n", This, pInfo);
783 if(This->hostui) {
784 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
785 if(SUCCEEDED(hres))
786 return hres;
789 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
790 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
791 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
792 return S_OK;
795 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
796 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
797 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
799 DocHost *This = impl_from_IDocHostUIHandler2(iface);
800 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
801 pFrame, pDoc);
802 return E_NOTIMPL;
805 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
807 DocHost *This = impl_from_IDocHostUIHandler2(iface);
808 FIXME("(%p)\n", This);
809 return E_NOTIMPL;
812 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
814 DocHost *This = impl_from_IDocHostUIHandler2(iface);
816 TRACE("(%p)\n", This);
818 if(!This->hostui)
819 return S_FALSE;
821 return IDocHostUIHandler_UpdateUI(This->hostui);
824 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
825 BOOL fEnable)
827 DocHost *This = impl_from_IDocHostUIHandler2(iface);
828 FIXME("(%p)->(%x)\n", This, fEnable);
829 return E_NOTIMPL;
832 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
833 BOOL fActivate)
835 DocHost *This = impl_from_IDocHostUIHandler2(iface);
836 FIXME("(%p)->(%x)\n", This, fActivate);
837 return E_NOTIMPL;
840 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
841 BOOL fActivate)
843 DocHost *This = impl_from_IDocHostUIHandler2(iface);
844 FIXME("(%p)->(%x)\n", This, fActivate);
845 return E_NOTIMPL;
848 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
849 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
851 DocHost *This = impl_from_IDocHostUIHandler2(iface);
852 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
853 return E_NOTIMPL;
856 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
857 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
859 DocHost *This = impl_from_IDocHostUIHandler2(iface);
860 HRESULT hr = S_FALSE;
861 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
863 if(This->hostui)
864 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
866 return hr;
869 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
870 LPOLESTR *pchKey, DWORD dw)
872 DocHost *This = impl_from_IDocHostUIHandler2(iface);
874 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
876 if(This->hostui)
877 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
879 return S_OK;
882 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
883 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
885 DocHost *This = impl_from_IDocHostUIHandler2(iface);
886 FIXME("(%p)\n", This);
887 return E_NOTIMPL;
890 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
891 IDispatch **ppDispatch)
893 DocHost *This = impl_from_IDocHostUIHandler2(iface);
895 TRACE("(%p)->(%p)\n", This, ppDispatch);
897 if(This->hostui)
898 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
900 if(!This->shell_ui_helper) {
901 HRESULT hres;
903 hres = create_shell_ui_helper(&This->shell_ui_helper);
904 if(FAILED(hres))
905 return hres;
908 *ppDispatch = (IDispatch*)This->shell_ui_helper;
909 IDispatch_AddRef(*ppDispatch);
910 return S_OK;
913 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
914 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
916 DocHost *This = impl_from_IDocHostUIHandler2(iface);
918 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
920 if(This->hostui)
921 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
922 pchURLIn, ppchURLOut);
924 return S_FALSE;
927 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
928 IDataObject *pDO, IDataObject **ppDORet)
930 DocHost *This = impl_from_IDocHostUIHandler2(iface);
931 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
932 return E_NOTIMPL;
935 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
936 LPOLESTR *pchKey, DWORD dw)
938 DocHost *This = impl_from_IDocHostUIHandler2(iface);
939 IDocHostUIHandler2 *handler;
940 HRESULT hres;
942 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
944 if(!This->hostui)
945 return S_OK;
947 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
948 (void**)&handler);
949 if(SUCCEEDED(hres)) {
950 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
951 IDocHostUIHandler2_Release(handler);
952 return hres;
955 return S_OK;
958 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
959 DocHostUIHandler_QueryInterface,
960 DocHostUIHandler_AddRef,
961 DocHostUIHandler_Release,
962 DocHostUIHandler_ShowContextMenu,
963 DocHostUIHandler_GetHostInfo,
964 DocHostUIHandler_ShowUI,
965 DocHostUIHandler_HideUI,
966 DocHostUIHandler_UpdateUI,
967 DocHostUIHandler_EnableModeless,
968 DocHostUIHandler_OnDocWindowActivate,
969 DocHostUIHandler_OnFrameWindowActivate,
970 DocHostUIHandler_ResizeBorder,
971 DocHostUIHandler_TranslateAccelerator,
972 DocHostUIHandler_GetOptionKeyPath,
973 DocHostUIHandler_GetDropTarget,
974 DocHostUIHandler_GetExternal,
975 DocHostUIHandler_TranslateUrl,
976 DocHostUIHandler_FilterDataObject,
977 DocHostUIHandler_GetOverrideKeyPath
980 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
982 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
985 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
986 REFIID riid, void **ppv)
988 DocHost *This = impl_from_IPropertyNotifySink(iface);
989 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
992 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
994 DocHost *This = impl_from_IPropertyNotifySink(iface);
995 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
998 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1000 DocHost *This = impl_from_IPropertyNotifySink(iface);
1001 return IOleClientSite_Release(&This->IOleClientSite_iface);
1004 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1006 DocHost *This = impl_from_IPropertyNotifySink(iface);
1008 TRACE("(%p)->(%d)\n", This, dispID);
1010 switch(dispID) {
1011 case DISPID_READYSTATE: {
1012 READYSTATE ready_state;
1013 HRESULT hres;
1015 hres = get_doc_ready_state(This, &ready_state);
1016 if(FAILED(hres))
1017 return hres;
1019 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
1020 advise_prop_notif(This, FALSE);
1022 update_ready_state(This, ready_state);
1023 break;
1025 default:
1026 FIXME("unimplemented dispid %d\n", dispID);
1027 return E_NOTIMPL;
1030 return S_OK;
1033 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1035 DocHost *This = impl_from_IPropertyNotifySink(iface);
1036 FIXME("(%p)->(%d)\n", This, dispID);
1037 return E_NOTIMPL;
1040 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1041 PropertyNotifySink_QueryInterface,
1042 PropertyNotifySink_AddRef,
1043 PropertyNotifySink_Release,
1044 PropertyNotifySink_OnChanged,
1045 PropertyNotifySink_OnRequestEdit
1048 void DocHost_Init(DocHost *This, IWebBrowser2 *wb, const IDocHostContainerVtbl* container)
1050 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
1051 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1052 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1054 This->wb = wb;
1055 This->container_vtbl = container;
1057 This->ready_state = READYSTATE_UNINITIALIZED;
1058 list_init(&This->task_queue);
1060 This->travellog.loading_pos = -1;
1062 DocHost_ClientSite_Init(This);
1063 DocHost_Frame_Init(This);
1065 ConnectionPointContainer_Init(&This->cps, (IUnknown*)wb);
1066 IEHTMLWindow_Init(This);
1067 NewWindowManager_Init(This);
1070 void DocHost_Release(DocHost *This)
1072 if(This->shell_ui_helper)
1073 IShellUIHelper2_Release(This->shell_ui_helper);
1075 abort_dochost_tasks(This, NULL);
1076 release_dochost_client(This);
1077 DocHost_ClientSite_Release(This);
1079 ConnectionPointContainer_Destroy(&This->cps);
1081 while(This->travellog.length)
1082 free_travellog_entry(This->travellog.log + --This->travellog.length);
1083 heap_free(This->travellog.log);
1085 heap_free(This->url);