1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
17 #include "wx/control.h"
18 #include "wx/webview.h"
19 #include "wx/msw/ole/automtn.h"
20 #include "wx/msw/ole/activex.h"
21 #include "wx/msw/ole/oleutils.h"
22 #include "wx/msw/wrapwin.h"
23 #include "wx/msw/missing.h"
24 #include "wx/sharedptr.h"
25 #include "wx/vector.h"
27 /* Classes and definitions from urlmon.h vary in their
28 * completeness between compilers and versions of compilers.
29 * We implement our own versions here which should work
30 * for all compilers. The definitions are taken from the
31 * mingw-w64 headers which are public domain.
34 #ifndef REFRESH_NORMAL
35 #define REFRESH_NORMAL 0
38 #ifndef REFRESH_COMPLETELY
39 #define REFRESH_COMPLETELY 3
42 typedef enum __wxMIDL_IBindStatusCallback_0006
44 wxBSCF_FIRSTDATANOTIFICATION
= 0x1,
45 wxBSCF_INTERMEDIATEDATANOTIFICATION
= 0x2,
46 wxBSCF_LASTDATANOTIFICATION
= 0x4,
47 wxBSCF_DATAFULLYAVAILABLE
= 0x8,
48 wxBSCF_AVAILABLEDATASIZEUNKNOWN
= 0x10
51 EXTERN_C
const IID CLSID_FileProtocol
;
53 typedef struct _tagwxBINDINFO
65 SECURITY_ATTRIBUTES securityAttributes
;
71 typedef struct _tagwxPROTOCOLDATA
79 class wxIInternetBindInfo
: public IUnknown
82 virtual HRESULT wxSTDCALL
GetBindInfo(DWORD
*grfBINDF
,wxBINDINFO
*pbindinfo
) = 0;
83 virtual HRESULT wxSTDCALL
GetBindString(ULONG ulStringType
,LPOLESTR
*ppwzStr
,
84 ULONG cEl
,ULONG
*pcElFetched
) = 0;
87 class wxIInternetProtocolSink
: public IUnknown
90 virtual HRESULT wxSTDCALL
Switch(wxPROTOCOLDATA
*pProtocolData
) = 0;
91 virtual HRESULT wxSTDCALL
ReportProgress(ULONG ulStatusCode
,
92 LPCWSTR szStatusText
) = 0;
93 virtual HRESULT wxSTDCALL
ReportData(DWORD grfBSCF
,ULONG ulProgress
,
94 ULONG ulProgressMax
) = 0;
95 virtual HRESULT wxSTDCALL
ReportResult(HRESULT hrResult
,DWORD dwError
,
96 LPCWSTR szResult
) = 0;
99 class wxIInternetProtocolRoot
: public IUnknown
102 virtual HRESULT wxSTDCALL
Start(LPCWSTR szUrl
,wxIInternetProtocolSink
*pOIProtSink
,
103 wxIInternetBindInfo
*pOIBindInfo
,DWORD grfPI
,
104 HANDLE_PTR dwReserved
) = 0;
105 virtual HRESULT wxSTDCALL
Continue(wxPROTOCOLDATA
*pProtocolData
) = 0;
106 virtual HRESULT wxSTDCALL
Abort(HRESULT hrReason
,DWORD dwOptions
) = 0;
107 virtual HRESULT wxSTDCALL
Terminate(DWORD dwOptions
) = 0;
108 virtual HRESULT wxSTDCALL
Suspend(void) = 0;
109 virtual HRESULT wxSTDCALL
Resume(void) = 0;
113 class wxIInternetProtocol
: public wxIInternetProtocolRoot
116 virtual HRESULT wxSTDCALL
Read(void *pv
,ULONG cb
,ULONG
*pcbRead
) = 0;
117 virtual HRESULT wxSTDCALL
Seek(LARGE_INTEGER dlibMove
,DWORD dwOrigin
,
118 ULARGE_INTEGER
*plibNewPosition
) = 0;
119 virtual HRESULT wxSTDCALL
LockRequest(DWORD dwOptions
) = 0;
120 virtual HRESULT wxSTDCALL
UnlockRequest(void) = 0;
124 class wxIInternetSession
: public IUnknown
127 virtual HRESULT wxSTDCALL
RegisterNameSpace(IClassFactory
*pCF
,REFCLSID rclsid
,
130 const LPCWSTR
*ppwzPatterns
,
131 DWORD dwReserved
) = 0;
132 virtual HRESULT wxSTDCALL
UnregisterNameSpace(IClassFactory
*pCF
,
133 LPCWSTR pszProtocol
) = 0;
134 virtual HRESULT wxSTDCALL
RegisterMimeFilter(IClassFactory
*pCF
,
136 LPCWSTR pwzType
) = 0;
137 virtual HRESULT wxSTDCALL
UnregisterMimeFilter(IClassFactory
*pCF
,
138 LPCWSTR pwzType
) = 0;
139 virtual HRESULT wxSTDCALL
CreateBinding(LPBC pBC
,LPCWSTR szUrl
,
140 IUnknown
*pUnkOuter
,IUnknown
**ppUnk
,
141 wxIInternetProtocol
**ppOInetProt
,
143 virtual HRESULT wxSTDCALL
SetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
144 DWORD dwBufferLength
,
145 DWORD dwReserved
) = 0;
146 virtual HRESULT wxSTDCALL
GetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
147 DWORD
*pdwBufferLength
,
148 DWORD dwReserved
) = 0;
151 /* END OF URLMON.H implementation */
153 /* Same goes for the mshtmhst.h, these are also taken
154 * from mingw-w64 headers.
157 typedef enum _tagwxDOCHOSTUIFLAG
159 DOCHOSTUIFLAG_DIALOG
= 0x1,
160 DOCHOSTUIFLAG_DISABLE_HELP_MENU
= 0x2,
161 DOCHOSTUIFLAG_NO3DBORDER
= 0x4,
162 DOCHOSTUIFLAG_SCROLL_NO
= 0x8,
163 DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
= 0x10,
164 DOCHOSTUIFLAG_OPENNEWWIN
= 0x20,
165 DOCHOSTUIFLAG_DISABLE_OFFSCREEN
= 0x40,
166 DOCHOSTUIFLAG_FLAT_SCROLLBAR
= 0x80,
167 DOCHOSTUIFLAG_DIV_BLOCKDEFAULT
= 0x100,
168 DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY
= 0x200,
169 DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY
= 0x400,
170 DOCHOSTUIFLAG_CODEPAGELINKEDFONTS
= 0x800,
171 DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8
= 0x1000,
172 DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
= 0x2000,
173 DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE
= 0x4000,
174 DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
= 0x10000,
175 DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
= 0x20000,
176 DOCHOSTUIFLAG_THEME
= 0x40000,
177 DOCHOSTUIFLAG_NOTHEME
= 0x80000,
178 DOCHOSTUIFLAG_NOPICS
= 0x100000,
179 DOCHOSTUIFLAG_NO3DOUTERBORDER
= 0x200000,
180 DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP
= 0x400000,
181 DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK
= 0x800000,
182 DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL
= 0x1000000
185 typedef struct _tagwxDOCHOSTUIINFO
194 class wxIDocHostUIHandler
: public IUnknown
197 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
198 IUnknown
*pcmdtReserved
,
199 IDispatch
*pdispReserved
) = 0;
201 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
) = 0;
203 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
204 IOleInPlaceActiveObject
*pActiveObject
,
205 IOleCommandTarget
*pCommandTarget
,
206 IOleInPlaceFrame
*pFrame
,
207 IOleInPlaceUIWindow
*pDoc
) = 0;
209 virtual HRESULT wxSTDCALL
HideUI(void) = 0;
211 virtual HRESULT wxSTDCALL
UpdateUI(void) = 0;
213 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
) = 0;
215 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
) = 0;
217 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
) = 0;
219 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
220 IOleInPlaceUIWindow
*pUIWindow
,
221 BOOL fRameWindow
) = 0;
223 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
224 const GUID
*pguidCmdGroup
,
227 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
230 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
231 IDropTarget
**ppDropTarget
) = 0;
233 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
) = 0;
235 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
237 OLECHAR
**ppchURLOut
) = 0;
239 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
240 IDataObject
**ppDORet
) = 0;
243 /* END OF MSHTMHST.H implementation */
245 struct IHTMLDocument2
;
249 class DocHostUIHandler
;
251 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
257 wxWebViewIE(wxWindow
* parent
,
259 const wxString
& url
= wxWebViewDefaultURLStr
,
260 const wxPoint
& pos
= wxDefaultPosition
,
261 const wxSize
& size
= wxDefaultSize
,
263 const wxString
& name
= wxWebViewNameStr
)
265 Create(parent
, id
, url
, pos
, size
, style
, name
);
270 bool Create(wxWindow
* parent
,
272 const wxString
& url
= wxWebViewDefaultURLStr
,
273 const wxPoint
& pos
= wxDefaultPosition
,
274 const wxSize
& size
= wxDefaultSize
,
276 const wxString
& name
= wxWebViewNameStr
);
278 virtual void LoadURL(const wxString
& url
);
279 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
280 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
281 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
283 virtual bool CanGoForward() const;
284 virtual bool CanGoBack() const;
285 virtual void GoBack();
286 virtual void GoForward();
287 virtual void ClearHistory();
288 virtual void EnableHistory(bool enable
= true);
290 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
292 virtual wxString
GetPageSource() const;
293 virtual wxString
GetPageText() const;
295 virtual bool IsBusy() const;
296 virtual wxString
GetCurrentURL() const;
297 virtual wxString
GetCurrentTitle() const;
299 virtual void SetZoomType(wxWebViewZoomType
);
300 virtual wxWebViewZoomType
GetZoomType() const;
301 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
303 virtual void Print();
305 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
307 virtual wxWebViewZoom
GetZoom() const;
308 virtual void SetZoom(wxWebViewZoom zoom
);
310 //Clipboard functions
311 virtual bool CanCut() const;
312 virtual bool CanCopy() const;
313 virtual bool CanPaste() const;
316 virtual void Paste();
318 //Undo / redo functionality
319 virtual bool CanUndo() const;
320 virtual bool CanRedo() const;
325 virtual void SetEditable(bool enable
= true);
326 virtual bool IsEditable() const;
329 virtual void SelectAll();
330 virtual bool HasSelection() const;
331 virtual void DeleteSelection();
332 virtual wxString
GetSelectedText() const;
333 virtual wxString
GetSelectedSource() const;
334 virtual void ClearSelection();
336 virtual void RunScript(const wxString
& javascript
);
338 //Virtual Filesystem Support
339 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
341 // ---- IE-specific methods
343 // FIXME: I seem to be able to access remote webpages even in offline mode...
344 bool IsOfflineMode();
345 void SetOfflineMode(bool offline
);
347 wxWebViewZoom
GetIETextZoom() const;
348 void SetIETextZoom(wxWebViewZoom level
);
350 wxWebViewZoom
GetIEOpticalZoom() const;
351 void SetIEOpticalZoom(wxWebViewZoom level
);
353 void onActiveXEvent(wxActiveXEvent
& evt
);
354 void onEraseBg(wxEraseEvent
&) {}
356 DECLARE_EVENT_TABLE();
359 wxIEContainer
* m_container
;
360 wxAutomationObject m_ie
;
361 IWebBrowser2
* m_webBrowser
;
363 DocHostUIHandler
* m_uiHandler
;
365 //We store the current zoom type;
366 wxWebViewZoomType m_zoomType
;
368 /** The "Busy" property of IWebBrowser2 does not always return busy when
369 * we'd want it to; this variable may be set to true in cases where the
370 * Busy property is false but should be true.
373 //We manage our own history, the history list contains the history items
374 //which are added as documentcomplete events arrive, unless we are loading
375 //an item from the history. The position is stored as an int, and reflects
376 //where we are in the history list.
377 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
378 wxVector
<ClassFactory
*> m_factories
;
379 int m_historyPosition
;
380 bool m_historyLoadingFromList
;
381 bool m_historyEnabled
;
383 //Generic helper functions for IHtmlDocument commands
384 bool CanExecCommand(wxString command
) const;
385 void ExecCommand(wxString command
);
386 IHTMLDocument2
* GetDocument() const;
388 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
391 class VirtualProtocol
: public wxIInternetProtocol
394 wxIInternetProtocolSink
* m_protocolSink
;
399 wxSharedPtr
<wxWebViewHandler
> m_handler
;
402 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
403 ~VirtualProtocol() {}
406 DECLARE_IUNKNOWN_METHODS
;
408 //IInternetProtocolRoot
409 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
410 DWORD
WXUNUSED(dwOptions
))
411 { return E_NOTIMPL
; }
412 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
414 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
415 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
416 wxIInternetProtocolSink
*pOIProtSink
,
417 wxIInternetBindInfo
*pOIBindInfo
,
419 HANDLE_PTR dwReserved
);
420 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
421 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
424 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
426 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
427 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
428 DWORD
WXUNUSED(dwOrigin
),
429 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
431 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
434 class ClassFactory
: public IClassFactory
437 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
440 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
441 REFIID riid
, void** ppvObject
);
442 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
445 DECLARE_IUNKNOWN_METHODS
;
448 wxSharedPtr
<wxWebViewHandler
> m_handler
;
451 class wxIEContainer
: public wxActiveXContainer
454 wxIEContainer(wxWindow
*parent
, REFIID iid
, IUnknown
*pUnk
, DocHostUIHandler
* uiHandler
= NULL
);
455 virtual ~wxIEContainer();
456 virtual bool QueryClientSiteInterface(REFIID iid
, void **_interface
, const char *&desc
);
458 DocHostUIHandler
* m_uiHandler
;
461 class DocHostUIHandler
: public wxIDocHostUIHandler
464 DocHostUIHandler() {};
465 ~DocHostUIHandler() {};
466 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
467 IUnknown
*pcmdtReserved
,
468 IDispatch
*pdispReserved
);
470 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
);
472 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
473 IOleInPlaceActiveObject
*pActiveObject
,
474 IOleCommandTarget
*pCommandTarget
,
475 IOleInPlaceFrame
*pFrame
,
476 IOleInPlaceUIWindow
*pDoc
);
478 virtual HRESULT wxSTDCALL
HideUI(void);
480 virtual HRESULT wxSTDCALL
UpdateUI(void);
482 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
);
484 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
);
486 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
);
488 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
489 IOleInPlaceUIWindow
*pUIWindow
,
492 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
493 const GUID
*pguidCmdGroup
,
496 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
499 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
500 IDropTarget
**ppDropTarget
);
502 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
);
504 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
506 OLECHAR
**ppchURLOut
);
508 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
509 IDataObject
**ppDORet
);
511 DECLARE_IUNKNOWN_METHODS
;
514 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
516 #endif // wxWebViewIE_H