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
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
)
46 is_empty
= list_empty(&This
->task_queue
);
47 list_add_tail(&This
->task_queue
, &task
->entry
);
50 SendMessageW(This
->frame_hwnd
, WM_DOCHOSTTASK
, 0, 0);
52 PostMessageW(This
->frame_hwnd
, WM_DOCHOSTTASK
, 0, 0);
55 LRESULT
process_dochost_tasks(DocHost
*This
)
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
);
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
)
78 list_remove(&task
->entry
);
83 void on_commandstate_change(DocHost
*doc_host
, LONG command
, BOOL enable
)
85 DISPPARAMS dispparams
;
88 TRACE("command=%d enable=%d\n", command
, enable
);
91 dispparams
.cNamedArgs
= 0;
92 dispparams
.rgdispidNamedArgs
= NULL
;
93 dispparams
.rgvarg
= params
;
95 V_VT(params
) = VT_BOOL
;
96 V_BOOL(params
) = enable
? VARIANT_TRUE
: VARIANT_FALSE
;
98 V_VT(params
+1) = VT_I4
;
99 V_I4(params
+1) = command
;
101 call_sink(doc_host
->cps
.wbe2
, DISPID_COMMANDSTATECHANGE
, &dispparams
);
103 doc_host
->container_vtbl
->on_command_state_change(doc_host
, command
, enable
);
106 void update_navigation_commands(DocHost
*dochost
)
108 unsigned pos
= dochost
->travellog
.loading_pos
== -1 ? dochost
->travellog
.position
: dochost
->travellog
.loading_pos
;
110 on_commandstate_change(dochost
, CSC_NAVIGATEBACK
, pos
> 0);
111 on_commandstate_change(dochost
, CSC_NAVIGATEFORWARD
, pos
< dochost
->travellog
.length
);
114 static void notif_complete(DocHost
*This
, DISPID dispid
)
116 DISPPARAMS dispparams
;
117 VARIANTARG params
[2];
120 dispparams
.cArgs
= 2;
121 dispparams
.cNamedArgs
= 0;
122 dispparams
.rgdispidNamedArgs
= NULL
;
123 dispparams
.rgvarg
= params
;
125 V_VT(params
) = (VT_BYREF
|VT_VARIANT
);
126 V_BYREF(params
) = &url
;
128 V_VT(params
+1) = VT_DISPATCH
;
129 V_DISPATCH(params
+1) = (IDispatch
*)This
->wb
;
131 V_VT(&url
) = VT_BSTR
;
132 V_BSTR(&url
) = SysAllocString(This
->url
);
134 TRACE("%d >>>\n", dispid
);
135 call_sink(This
->cps
.wbe2
, dispid
, &dispparams
);
136 TRACE("%d <<<\n", dispid
);
138 SysFreeString(V_BSTR(&url
));
141 static void object_available(DocHost
*This
)
146 TRACE("(%p)\n", This
);
148 if(!This
->document
) {
149 WARN("document == NULL\n");
153 hres
= IUnknown_QueryInterface(This
->document
, &IID_IHlinkTarget
, (void**)&hlink
);
154 if(SUCCEEDED(hres
)) {
155 hres
= IHlinkTarget_Navigate(hlink
, 0, NULL
);
156 IHlinkTarget_Release(hlink
);
158 FIXME("Navigate failed\n");
160 IOleObject
*ole_object
;
163 TRACE("No IHlink iface\n");
165 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleObject
, (void**)&ole_object
);
167 FIXME("Could not get IOleObject iface: %08x\n", hres
);
171 GetClientRect(This
->hwnd
, &rect
);
172 hres
= IOleObject_DoVerb(ole_object
, OLEIVERB_SHOW
, NULL
, &This
->IOleClientSite_iface
, -1, This
->hwnd
, &rect
);
173 IOleObject_Release(ole_object
);
175 FIXME("DoVerb failed: %08x\n", hres
);
179 static HRESULT
get_doc_ready_state(DocHost
*This
, READYSTATE
*ret
)
181 DISPPARAMS dp
= {NULL
,NULL
,0,0};
187 hres
= IUnknown_QueryInterface(This
->document
, &IID_IDispatch
, (void**)&disp
);
191 hres
= IDispatch_Invoke(disp
, DISPID_READYSTATE
, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_PROPERTYGET
,
192 &dp
, &var
, &ei
, NULL
);
193 IDispatch_Release(disp
);
195 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres
);
199 if(V_VT(&var
) != VT_I4
) {
200 WARN("V_VT(var) = %d\n", V_VT(&var
));
209 static void advise_prop_notif(DocHost
*This
, BOOL set
)
211 IConnectionPointContainer
*cp_container
;
212 IConnectionPoint
*cp
;
215 hres
= IUnknown_QueryInterface(This
->document
, &IID_IConnectionPointContainer
, (void**)&cp_container
);
219 hres
= IConnectionPointContainer_FindConnectionPoint(cp_container
, &IID_IPropertyNotifySink
, &cp
);
220 IConnectionPointContainer_Release(cp_container
);
225 hres
= IConnectionPoint_Advise(cp
, (IUnknown
*)&This
->IPropertyNotifySink_iface
, &This
->prop_notif_cookie
);
227 hres
= IConnectionPoint_Unadvise(cp
, This
->prop_notif_cookie
);
228 IConnectionPoint_Release(cp
);
231 This
->is_prop_notif
= set
;
234 void set_doc_state(DocHost
*This
, READYSTATE doc_state
)
236 This
->doc_state
= doc_state
;
237 if(doc_state
> This
->ready_state
)
238 This
->ready_state
= doc_state
;
241 static void update_ready_state(DocHost
*This
, READYSTATE ready_state
)
243 if(ready_state
> READYSTATE_LOADING
&& This
->travellog
.loading_pos
!= -1) {
244 WARN("histupdate not notified\n");
245 This
->travellog
.position
= This
->travellog
.loading_pos
;
246 This
->travellog
.loading_pos
= -1;
249 if(ready_state
> READYSTATE_LOADING
&& This
->doc_state
<= READYSTATE_LOADING
&& !This
->browser_service
/* FIXME */)
250 notif_complete(This
, DISPID_NAVIGATECOMPLETE2
);
252 if(ready_state
== READYSTATE_COMPLETE
&& This
->doc_state
< READYSTATE_COMPLETE
) {
253 set_doc_state(This
, READYSTATE_COMPLETE
);
254 if(!This
->browser_service
) /* FIXME: Not fully correct */
255 notif_complete(This
, DISPID_DOCUMENTCOMPLETE
);
257 set_doc_state(This
, ready_state
);
262 task_header_t header
;
264 READYSTATE ready_state
;
265 } ready_state_task_t
;
267 static void ready_state_task_destr(task_header_t
*_task
)
269 ready_state_task_t
*task
= (ready_state_task_t
*)_task
;
271 IUnknown_Release(task
->doc
);
275 static void ready_state_proc(DocHost
*This
, task_header_t
*_task
)
277 ready_state_task_t
*task
= (ready_state_task_t
*)_task
;
279 if(task
->doc
== This
->document
)
280 update_ready_state(This
, task
->ready_state
);
283 static void push_ready_state_task(DocHost
*This
, READYSTATE ready_state
)
285 ready_state_task_t
*task
= heap_alloc(sizeof(ready_state_task_t
));
287 IUnknown_AddRef(This
->document
);
288 task
->doc
= This
->document
;
289 task
->ready_state
= ready_state
;
291 push_dochost_task(This
, &task
->header
, ready_state_proc
, ready_state_task_destr
, FALSE
);
294 static void object_available_task_destr(task_header_t
*task
)
299 static void object_available_proc(DocHost
*This
, task_header_t
*task
)
301 object_available(This
);
304 HRESULT
dochost_object_available(DocHost
*This
, IUnknown
*doc
)
306 READYSTATE ready_state
;
311 IUnknown_AddRef(doc
);
312 This
->document
= doc
;
314 hres
= IUnknown_QueryInterface(doc
, &IID_IOleObject
, (void**)&oleobj
);
315 if(SUCCEEDED(hres
)) {
318 hres
= IOleObject_GetUserClassID(oleobj
, &clsid
);
320 TRACE("Got clsid %s\n",
321 IsEqualGUID(&clsid
, &CLSID_HTMLDocument
) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid
));
323 hres
= IOleObject_SetClientSite(oleobj
, &This
->IOleClientSite_iface
);
325 FIXME("SetClientSite failed: %08x\n", hres
);
327 IOleObject_Release(oleobj
);
329 FIXME("Could not get IOleObject iface: %08x\n", hres
);
332 /* FIXME: Call SetAdvise */
334 task
= heap_alloc(sizeof(*task
));
335 push_dochost_task(This
, task
, object_available_proc
, object_available_task_destr
, FALSE
);
337 hres
= get_doc_ready_state(This
, &ready_state
);
338 if(SUCCEEDED(hres
)) {
339 if(ready_state
== READYSTATE_COMPLETE
)
340 push_ready_state_task(This
, READYSTATE_COMPLETE
);
341 if(ready_state
!= READYSTATE_COMPLETE
|| This
->doc_navigate
)
342 advise_prop_notif(This
, TRUE
);
343 }else if(!This
->doc_navigate
) {
344 /* If we can't get document's ready state, there is not much we can do.
345 * Assume that document is complete at this point. */
346 push_ready_state_task(This
, READYSTATE_COMPLETE
);
352 static LRESULT
resize_document(DocHost
*This
, LONG width
, LONG height
)
354 RECT rect
= {0, 0, width
, height
};
356 TRACE("(%p)->(%d %d)\n", This
, width
, height
);
359 IOleDocumentView_SetRect(This
->view
, &rect
);
364 static LRESULT WINAPI
doc_view_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
368 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
370 if(msg
== WM_CREATE
) {
371 This
= *(DocHost
**)lParam
;
372 SetPropW(hwnd
, wszTHIS
, This
);
374 This
= GetPropW(hwnd
, wszTHIS
);
379 return resize_document(This
, LOWORD(lParam
), HIWORD(lParam
));
382 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
385 static void free_travellog_entry(travellog_entry_t
*entry
)
388 IStream_Release(entry
->stream
);
389 entry
->stream
= NULL
;
391 heap_free(entry
->url
);
395 static IStream
*get_travellog_stream(DocHost
*This
)
397 IPersistHistory
*persist_history
;
401 hres
= IUnknown_QueryInterface(This
->document
, &IID_IPersistHistory
, (void**)&persist_history
);
405 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
407 hres
= IPersistHistory_SaveHistory(persist_history
, stream
);
408 IPersistHistory_Release(persist_history
);
410 IStream_Release(stream
);
417 static void dump_travellog(DocHost
*This
)
421 for(i
=0; i
< This
->travellog
.length
; i
++)
422 TRACE("%d: %s %s\n", i
, i
== This
->travellog
.position
? "=>" : " ", debugstr_w(This
->travellog
.log
[i
].url
));
423 if(i
== This
->travellog
.position
)
424 TRACE("%d: =>\n", i
);
427 static void update_travellog(DocHost
*This
)
429 travellog_entry_t
*new_entry
;
431 static const WCHAR about_schemeW
[] = {'a','b','o','u','t',':'};
433 if(This
->url
&& !wcsnicmp(This
->url
, about_schemeW
, ARRAY_SIZE(about_schemeW
))) {
434 TRACE("Skipping about URL\n");
438 if(!This
->travellog
.log
) {
439 This
->travellog
.log
= heap_alloc(4 * sizeof(*This
->travellog
.log
));
440 if(!This
->travellog
.log
)
443 This
->travellog
.size
= 4;
444 }else if(This
->travellog
.size
< This
->travellog
.position
+1) {
445 travellog_entry_t
*new_travellog
;
447 new_travellog
= heap_realloc(This
->travellog
.log
, This
->travellog
.size
*2*sizeof(*This
->travellog
.log
));
451 This
->travellog
.log
= new_travellog
;
452 This
->travellog
.size
*= 2;
455 if(This
->travellog
.loading_pos
== -1) {
456 /* Clear forward history. */
457 while(This
->travellog
.length
> This
->travellog
.position
)
458 free_travellog_entry(This
->travellog
.log
+ --This
->travellog
.length
);
461 new_entry
= This
->travellog
.log
+ This
->travellog
.position
;
463 new_entry
->url
= heap_strdupW(This
->url
);
464 TRACE("Adding %s at %d\n", debugstr_w(This
->url
), This
->travellog
.position
);
468 new_entry
->stream
= get_travellog_stream(This
);
470 if(This
->travellog
.loading_pos
== -1) {
471 This
->travellog
.position
++;
473 This
->travellog
.position
= This
->travellog
.loading_pos
;
474 This
->travellog
.loading_pos
= -1;
476 if(This
->travellog
.position
> This
->travellog
.length
)
477 This
->travellog
.length
= This
->travellog
.position
;
479 dump_travellog(This
);
482 void create_doc_view_hwnd(DocHost
*This
)
486 static const WCHAR wszShell_DocObject_View
[] =
487 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
490 static WNDCLASSEXW wndclass
= {
494 0, 0 /* native uses 4*/, NULL
, NULL
, NULL
,
495 (HBRUSH
)(COLOR_WINDOW
+ 1), NULL
,
496 wszShell_DocObject_View
,
500 wndclass
.hInstance
= ieframe_instance
;
502 doc_view_atom
= RegisterClassExW(&wndclass
);
505 This
->container_vtbl
->get_docobj_rect(This
, &rect
);
506 This
->hwnd
= CreateWindowExW(0, wszShell_DocObject_View
,
507 wszShell_DocObject_View
,
508 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_TABSTOP
,
509 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
, This
->frame_hwnd
,
510 NULL
, ieframe_instance
, This
);
513 void deactivate_document(DocHost
*This
)
515 IOleInPlaceObjectWindowless
*winobj
;
516 IOleObject
*oleobj
= NULL
;
517 IHlinkTarget
*hlink
= NULL
;
520 if(!This
->document
) return;
522 if(This
->doc_navigate
) {
523 IUnknown_Release(This
->doc_navigate
);
524 This
->doc_navigate
= NULL
;
527 if(This
->is_prop_notif
)
528 advise_prop_notif(This
, FALSE
);
531 IOleDocumentView_UIActivate(This
->view
, FALSE
);
533 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleInPlaceObjectWindowless
,
535 if(SUCCEEDED(hres
)) {
536 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj
);
537 IOleInPlaceObjectWindowless_Release(winobj
);
541 IOleDocumentView_Show(This
->view
, FALSE
);
542 IOleDocumentView_CloseView(This
->view
, 0);
543 IOleDocumentView_SetInPlaceSite(This
->view
, NULL
);
544 IOleDocumentView_Release(This
->view
);
548 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleObject
, (void**)&oleobj
);
550 IOleObject_Close(oleobj
, OLECLOSE_NOSAVE
);
552 hres
= IUnknown_QueryInterface(This
->document
, &IID_IHlinkTarget
, (void**)&hlink
);
553 if(SUCCEEDED(hres
)) {
554 IHlinkTarget_SetBrowseContext(hlink
, NULL
);
555 IHlinkTarget_Release(hlink
);
559 IOleClientSite
*client_site
= NULL
;
561 IOleObject_GetClientSite(oleobj
, &client_site
);
563 if(client_site
== &This
->IOleClientSite_iface
)
564 IOleObject_SetClientSite(oleobj
, NULL
);
565 IOleClientSite_Release(client_site
);
568 IOleObject_Release(oleobj
);
571 IUnknown_Release(This
->document
);
572 This
->document
= NULL
;
575 HRESULT
refresh_document(DocHost
*This
, const VARIANT
*level
)
577 IOleCommandTarget
*cmdtrg
;
581 if(level
&& (V_VT(level
) != VT_I4
|| V_I4(level
) != REFRESH_NORMAL
))
582 FIXME("Unsupported refresh level %s\n", debugstr_variant(level
));
584 if(!This
->document
) {
585 FIXME("no document\n");
589 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
593 V_VT(&vin
) = VT_EMPTY
;
594 V_VT(&vout
) = VT_EMPTY
;
595 hres
= IOleCommandTarget_Exec(cmdtrg
, NULL
, OLECMDID_REFRESH
, OLECMDEXECOPT_PROMPTUSER
, &vin
, &vout
);
596 IOleCommandTarget_Release(cmdtrg
);
604 void activate_document(DocHost
*This
)
610 if(!This
->document
) return;
612 hres
= IUnknown_QueryInterface(This
->document
, &IID_IHlinkTarget
, (void**)&hlink
);
613 if(SUCCEEDED(hres
)) {
614 IHlinkTarget_Navigate(hlink
, 0, NULL
);
615 IHlinkTarget_Release(hlink
);
618 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleObject
, (void**)&oleobj
);
619 if(SUCCEEDED(hres
)) {
620 IOleObject_DoVerb(oleobj
, OLEIVERB_SHOW
, NULL
, NULL
, -1, 0, NULL
);
621 IOleObject_Release(oleobj
);
624 refresh_document(This
, NULL
);
627 IOleDocumentView_UIActivate(This
->view
, TRUE
);
630 void release_dochost_client(DocHost
*This
)
633 DestroyWindow(This
->hwnd
);
638 IDocHostUIHandler_Release(This
->hostui
);
642 if(This
->client_disp
) {
643 IDispatch_Release(This
->client_disp
);
644 This
->client_disp
= NULL
;
648 IOleInPlaceFrame_Release(This
->frame
);
653 IOleCommandTarget_Release(This
->olecmd
);
658 static inline DocHost
*impl_from_IOleCommandTarget(IOleCommandTarget
*iface
)
660 return CONTAINING_RECORD(iface
, DocHost
, IOleCommandTarget_iface
);
663 static HRESULT WINAPI
ClOleCommandTarget_QueryInterface(IOleCommandTarget
*iface
,
664 REFIID riid
, void **ppv
)
666 DocHost
*This
= impl_from_IOleCommandTarget(iface
);
667 return IOleClientSite_QueryInterface(&This
->IOleClientSite_iface
, riid
, ppv
);
670 static ULONG WINAPI
ClOleCommandTarget_AddRef(IOleCommandTarget
*iface
)
672 DocHost
*This
= impl_from_IOleCommandTarget(iface
);
673 return IOleClientSite_AddRef(&This
->IOleClientSite_iface
);
676 static ULONG WINAPI
ClOleCommandTarget_Release(IOleCommandTarget
*iface
)
678 DocHost
*This
= impl_from_IOleCommandTarget(iface
);
679 return IOleClientSite_Release(&This
->IOleClientSite_iface
);
682 static HRESULT WINAPI
ClOleCommandTarget_QueryStatus(IOleCommandTarget
*iface
,
683 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
685 DocHost
*This
= impl_from_IOleCommandTarget(iface
);
688 TRACE("(%p)->(%s %u %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
,
690 for(i
=0; prgCmds
&& i
< cCmds
; i
++)
691 TRACE("unsupported command %u (%x)\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
696 static HRESULT WINAPI
ClOleCommandTarget_Exec(IOleCommandTarget
*iface
,
697 const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
,
700 DocHost
*This
= impl_from_IOleCommandTarget(iface
);
702 TRACE("(%p)->(%s %d %d %s %s)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
, nCmdexecopt
,
703 debugstr_variant(pvaIn
), debugstr_variant(pvaOut
));
707 case OLECMDID_UPDATECOMMANDS
:
710 return IOleCommandTarget_Exec(This
->olecmd
, pguidCmdGroup
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
711 case OLECMDID_SETDOWNLOADSTATE
:
712 if(pvaIn
&& V_VT(pvaIn
) == VT_I4
)
713 This
->busy
= V_I4(pvaIn
) ? VARIANT_TRUE
: VARIANT_FALSE
;
715 return IOleCommandTarget_Exec(This
->olecmd
, pguidCmdGroup
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
717 if(!pvaIn
|| V_VT(pvaIn
) != VT_I4
)
720 notify_download_state(This
, V_I4(pvaIn
));
723 TRACE("Unimplemented cmdid %d\n", nCmdID
);
728 if(IsEqualGUID(pguidCmdGroup
, &CGID_DocHostCmdPriv
)) {
730 case DOCHOST_DOCCANNAVIGATE
:
731 if(!pvaIn
|| V_VT(pvaIn
) != VT_UNKNOWN
)
734 if(This
->doc_navigate
)
735 IUnknown_Release(This
->doc_navigate
);
736 IUnknown_AddRef(V_UNKNOWN(pvaIn
));
737 This
->doc_navigate
= V_UNKNOWN(pvaIn
);
742 SAFEARRAY
*sa
= V_ARRAY(pvaIn
);
743 VARIANT status_code
, url
, htmlwindow
;
747 if(V_VT(pvaIn
) != VT_ARRAY
|| !sa
|| (SafeArrayGetDim(sa
) != 1))
751 hres
= SafeArrayGetElement(sa
, &ind
, &status_code
);
752 if(FAILED(hres
) || V_VT(&status_code
)!=VT_I4
)
756 hres
= SafeArrayGetElement(sa
, &ind
, &url
);
757 if(FAILED(hres
) || V_VT(&url
)!=VT_BSTR
)
761 hres
= SafeArrayGetElement(sa
, &ind
, &htmlwindow
);
762 if(FAILED(hres
) || V_VT(&htmlwindow
)!=VT_UNKNOWN
|| !V_UNKNOWN(&htmlwindow
))
765 hres
= IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow
), &IID_IHTMLWindow2
, (void**)&win2
);
769 handle_navigation_error(This
, V_I4(&status_code
), V_BSTR(&url
), win2
);
770 IHTMLWindow2_Release(win2
);
775 TRACE("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID
);
780 if(IsEqualGUID(pguidCmdGroup
, &CGID_Explorer
)) {
782 case CMDID_EXPLORER_UPDATEHISTORY
:
783 update_travellog(This
);
784 update_navigation_commands(This
);
788 TRACE("Unimplemented cmdid %d of CGID_Explorer\n", nCmdID
);
793 if(IsEqualGUID(pguidCmdGroup
, &CGID_ShellDocView
)) {
796 TRACE("Unimplemented cmdid %d of CGID_ShellDocView\n", nCmdID
);
801 if(IsEqualGUID(&CGID_DocHostCommandHandler
, pguidCmdGroup
)) {
804 return IOleCommandTarget_Exec(This
->olecmd
, pguidCmdGroup
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
807 TRACE("Unimplemented cmdid %d of group %s\n", nCmdID
, debugstr_guid(pguidCmdGroup
));
811 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
812 ClOleCommandTarget_QueryInterface
,
813 ClOleCommandTarget_AddRef
,
814 ClOleCommandTarget_Release
,
815 ClOleCommandTarget_QueryStatus
,
816 ClOleCommandTarget_Exec
819 static inline DocHost
*impl_from_IDocHostUIHandler2(IDocHostUIHandler2
*iface
)
821 return CONTAINING_RECORD(iface
, DocHost
, IDocHostUIHandler2_iface
);
824 static HRESULT WINAPI
DocHostUIHandler_QueryInterface(IDocHostUIHandler2
*iface
,
825 REFIID riid
, void **ppv
)
827 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
828 return IOleClientSite_QueryInterface(&This
->IOleClientSite_iface
, riid
, ppv
);
831 static ULONG WINAPI
DocHostUIHandler_AddRef(IDocHostUIHandler2
*iface
)
833 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
834 return IOleClientSite_AddRef(&This
->IOleClientSite_iface
);
837 static ULONG WINAPI
DocHostUIHandler_Release(IDocHostUIHandler2
*iface
)
839 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
840 return IOleClientSite_Release(&This
->IOleClientSite_iface
);
843 static HRESULT WINAPI
DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2
*iface
,
844 DWORD dwID
, POINT
*ppt
, IUnknown
*pcmdtReserved
, IDispatch
*pdispReserved
)
846 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
849 TRACE("(%p)->(%d %p %p %p)\n", This
, dwID
, ppt
, pcmdtReserved
, pdispReserved
);
852 hres
= IDocHostUIHandler_ShowContextMenu(This
->hostui
, dwID
, ppt
, pcmdtReserved
,
858 FIXME("default action not implemented\n");
862 static HRESULT WINAPI
DocHostUIHandler_GetHostInfo(IDocHostUIHandler2
*iface
,
863 DOCHOSTUIINFO
*pInfo
)
865 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
868 TRACE("(%p)->(%p)\n", This
, pInfo
);
871 hres
= IDocHostUIHandler_GetHostInfo(This
->hostui
, pInfo
);
876 pInfo
->dwFlags
= DOCHOSTUIFLAG_DISABLE_HELP_MENU
| DOCHOSTUIFLAG_OPENNEWWIN
877 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
| DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
878 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
;
882 static HRESULT WINAPI
DocHostUIHandler_ShowUI(IDocHostUIHandler2
*iface
, DWORD dwID
,
883 IOleInPlaceActiveObject
*pActiveObject
, IOleCommandTarget
*pCommandTarget
,
884 IOleInPlaceFrame
*pFrame
, IOleInPlaceUIWindow
*pDoc
)
886 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
887 FIXME("(%p)->(%d %p %p %p %p)\n", This
, dwID
, pActiveObject
, pCommandTarget
,
892 static HRESULT WINAPI
DocHostUIHandler_HideUI(IDocHostUIHandler2
*iface
)
894 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
895 FIXME("(%p)\n", This
);
899 static HRESULT WINAPI
DocHostUIHandler_UpdateUI(IDocHostUIHandler2
*iface
)
901 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
903 TRACE("(%p)\n", This
);
908 return IDocHostUIHandler_UpdateUI(This
->hostui
);
911 static HRESULT WINAPI
DocHostUIHandler_EnableModeless(IDocHostUIHandler2
*iface
,
914 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
915 FIXME("(%p)->(%x)\n", This
, fEnable
);
919 static HRESULT WINAPI
DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2
*iface
,
922 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
923 FIXME("(%p)->(%x)\n", This
, fActivate
);
927 static HRESULT WINAPI
DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2
*iface
,
930 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
931 FIXME("(%p)->(%x)\n", This
, fActivate
);
935 static HRESULT WINAPI
DocHostUIHandler_ResizeBorder(IDocHostUIHandler2
*iface
,
936 LPCRECT prcBorder
, IOleInPlaceUIWindow
*pUIWindow
, BOOL fRameWindow
)
938 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
939 FIXME("(%p)->(%p %p %X)\n", This
, prcBorder
, pUIWindow
, fRameWindow
);
943 static HRESULT WINAPI
DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2
*iface
,
944 LPMSG lpMsg
, const GUID
*pguidCmdGroup
, DWORD nCmdID
)
946 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
947 HRESULT hr
= S_FALSE
;
948 TRACE("(%p)->(%p %p %d)\n", This
, lpMsg
, pguidCmdGroup
, nCmdID
);
951 hr
= IDocHostUIHandler_TranslateAccelerator(This
->hostui
, lpMsg
, pguidCmdGroup
, nCmdID
);
956 static HRESULT WINAPI
DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2
*iface
,
957 LPOLESTR
*pchKey
, DWORD dw
)
959 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
961 TRACE("(%p)->(%p %d)\n", This
, pchKey
, dw
);
964 return IDocHostUIHandler_GetOptionKeyPath(This
->hostui
, pchKey
, dw
);
969 static HRESULT WINAPI
DocHostUIHandler_GetDropTarget(IDocHostUIHandler2
*iface
,
970 IDropTarget
*pDropTarget
, IDropTarget
**ppDropTarget
)
972 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
973 FIXME("(%p)\n", This
);
977 static HRESULT WINAPI
DocHostUIHandler_GetExternal(IDocHostUIHandler2
*iface
,
978 IDispatch
**ppDispatch
)
980 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
982 TRACE("(%p)->(%p)\n", This
, ppDispatch
);
985 return IDocHostUIHandler_GetExternal(This
->hostui
, ppDispatch
);
987 if(!This
->shell_ui_helper
) {
990 hres
= create_shell_ui_helper(&This
->shell_ui_helper
);
995 *ppDispatch
= (IDispatch
*)This
->shell_ui_helper
;
996 IDispatch_AddRef(*ppDispatch
);
1000 static HRESULT WINAPI
DocHostUIHandler_TranslateUrl(IDocHostUIHandler2
*iface
,
1001 DWORD dwTranslate
, OLECHAR
*pchURLIn
, OLECHAR
**ppchURLOut
)
1003 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
1005 TRACE("(%p)->(%d %s %p)\n", This
, dwTranslate
, debugstr_w(pchURLIn
), ppchURLOut
);
1008 return IDocHostUIHandler_TranslateUrl(This
->hostui
, dwTranslate
,
1009 pchURLIn
, ppchURLOut
);
1014 static HRESULT WINAPI
DocHostUIHandler_FilterDataObject(IDocHostUIHandler2
*iface
,
1015 IDataObject
*pDO
, IDataObject
**ppDORet
)
1017 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
1018 FIXME("(%p)->(%p %p)\n", This
, pDO
, ppDORet
);
1022 static HRESULT WINAPI
DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2
*iface
,
1023 LPOLESTR
*pchKey
, DWORD dw
)
1025 DocHost
*This
= impl_from_IDocHostUIHandler2(iface
);
1026 IDocHostUIHandler2
*handler
;
1029 TRACE("(%p)->(%p %d)\n", This
, pchKey
, dw
);
1034 hres
= IDocHostUIHandler_QueryInterface(This
->hostui
, &IID_IDocHostUIHandler2
,
1036 if(SUCCEEDED(hres
)) {
1037 hres
= IDocHostUIHandler2_GetOverrideKeyPath(handler
, pchKey
, dw
);
1038 IDocHostUIHandler2_Release(handler
);
1045 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl
= {
1046 DocHostUIHandler_QueryInterface
,
1047 DocHostUIHandler_AddRef
,
1048 DocHostUIHandler_Release
,
1049 DocHostUIHandler_ShowContextMenu
,
1050 DocHostUIHandler_GetHostInfo
,
1051 DocHostUIHandler_ShowUI
,
1052 DocHostUIHandler_HideUI
,
1053 DocHostUIHandler_UpdateUI
,
1054 DocHostUIHandler_EnableModeless
,
1055 DocHostUIHandler_OnDocWindowActivate
,
1056 DocHostUIHandler_OnFrameWindowActivate
,
1057 DocHostUIHandler_ResizeBorder
,
1058 DocHostUIHandler_TranslateAccelerator
,
1059 DocHostUIHandler_GetOptionKeyPath
,
1060 DocHostUIHandler_GetDropTarget
,
1061 DocHostUIHandler_GetExternal
,
1062 DocHostUIHandler_TranslateUrl
,
1063 DocHostUIHandler_FilterDataObject
,
1064 DocHostUIHandler_GetOverrideKeyPath
1067 static inline DocHost
*impl_from_IPropertyNotifySink(IPropertyNotifySink
*iface
)
1069 return CONTAINING_RECORD(iface
, DocHost
, IPropertyNotifySink_iface
);
1072 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
1073 REFIID riid
, void **ppv
)
1075 DocHost
*This
= impl_from_IPropertyNotifySink(iface
);
1076 return IOleClientSite_QueryInterface(&This
->IOleClientSite_iface
, riid
, ppv
);
1079 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
1081 DocHost
*This
= impl_from_IPropertyNotifySink(iface
);
1082 return IOleClientSite_AddRef(&This
->IOleClientSite_iface
);
1085 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
1087 DocHost
*This
= impl_from_IPropertyNotifySink(iface
);
1088 return IOleClientSite_Release(&This
->IOleClientSite_iface
);
1091 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
1093 DocHost
*This
= impl_from_IPropertyNotifySink(iface
);
1095 TRACE("(%p)->(%d)\n", This
, dispID
);
1098 case DISPID_READYSTATE
: {
1099 READYSTATE ready_state
;
1102 hres
= get_doc_ready_state(This
, &ready_state
);
1106 if(ready_state
== READYSTATE_COMPLETE
&& !This
->doc_navigate
)
1107 advise_prop_notif(This
, FALSE
);
1109 update_ready_state(This
, ready_state
);
1113 FIXME("unimplemented dispid %d\n", dispID
);
1120 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
1122 DocHost
*This
= impl_from_IPropertyNotifySink(iface
);
1123 FIXME("(%p)->(%d)\n", This
, dispID
);
1127 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
1128 PropertyNotifySink_QueryInterface
,
1129 PropertyNotifySink_AddRef
,
1130 PropertyNotifySink_Release
,
1131 PropertyNotifySink_OnChanged
,
1132 PropertyNotifySink_OnRequestEdit
1135 void DocHost_Init(DocHost
*This
, IWebBrowser2
*wb
, const IDocHostContainerVtbl
* container
)
1137 This
->IDocHostUIHandler2_iface
.lpVtbl
= &DocHostUIHandler2Vtbl
;
1138 This
->IOleCommandTarget_iface
.lpVtbl
= &OleCommandTargetVtbl
;
1139 This
->IPropertyNotifySink_iface
.lpVtbl
= &PropertyNotifySinkVtbl
;
1142 This
->container_vtbl
= container
;
1144 This
->ready_state
= READYSTATE_UNINITIALIZED
;
1145 list_init(&This
->task_queue
);
1147 This
->travellog
.loading_pos
= -1;
1149 DocHost_ClientSite_Init(This
);
1150 DocHost_Frame_Init(This
);
1152 ConnectionPointContainer_Init(&This
->cps
, (IUnknown
*)wb
);
1153 IEHTMLWindow_Init(This
);
1154 NewWindowManager_Init(This
);
1157 void DocHost_Release(DocHost
*This
)
1159 if(This
->shell_ui_helper
)
1160 IShellUIHelper2_Release(This
->shell_ui_helper
);
1162 abort_dochost_tasks(This
, NULL
);
1163 release_dochost_client(This
);
1164 DocHost_ClientSite_Release(This
);
1166 ConnectionPointContainer_Destroy(&This
->cps
);
1168 while(This
->travellog
.length
)
1169 free_travellog_entry(This
->travellog
.log
+ --This
->travellog
.length
);
1170 heap_free(This
->travellog
.log
);
1172 heap_free(This
->url
);