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/private/comptr.h"
23 #include "wx/msw/wrapwin.h"
24 #include "wx/msw/missing.h"
25 #include "wx/sharedptr.h"
26 #include "wx/vector.h"
28 /* Classes and definitions from urlmon.h vary in their
29 * completeness between compilers and versions of compilers.
30 * We implement our own versions here which should work
31 * for all compilers. The definitions are taken from the
32 * mingw-w64 headers which are public domain.
35 #ifndef REFRESH_NORMAL
36 #define REFRESH_NORMAL 0
39 #ifndef REFRESH_COMPLETELY
40 #define REFRESH_COMPLETELY 3
43 typedef enum __wxMIDL_IBindStatusCallback_0006
45 wxBSCF_FIRSTDATANOTIFICATION
= 0x1,
46 wxBSCF_INTERMEDIATEDATANOTIFICATION
= 0x2,
47 wxBSCF_LASTDATANOTIFICATION
= 0x4,
48 wxBSCF_DATAFULLYAVAILABLE
= 0x8,
49 wxBSCF_AVAILABLEDATASIZEUNKNOWN
= 0x10
52 EXTERN_C
const IID CLSID_FileProtocol
;
54 typedef struct _tagwxBINDINFO
66 SECURITY_ATTRIBUTES securityAttributes
;
72 typedef struct _tagwxPROTOCOLDATA
80 class wxIInternetBindInfo
: public IUnknown
83 virtual HRESULT wxSTDCALL
GetBindInfo(DWORD
*grfBINDF
,wxBINDINFO
*pbindinfo
) = 0;
84 virtual HRESULT wxSTDCALL
GetBindString(ULONG ulStringType
,LPOLESTR
*ppwzStr
,
85 ULONG cEl
,ULONG
*pcElFetched
) = 0;
88 class wxIInternetProtocolSink
: public IUnknown
91 virtual HRESULT wxSTDCALL
Switch(wxPROTOCOLDATA
*pProtocolData
) = 0;
92 virtual HRESULT wxSTDCALL
ReportProgress(ULONG ulStatusCode
,
93 LPCWSTR szStatusText
) = 0;
94 virtual HRESULT wxSTDCALL
ReportData(DWORD grfBSCF
,ULONG ulProgress
,
95 ULONG ulProgressMax
) = 0;
96 virtual HRESULT wxSTDCALL
ReportResult(HRESULT hrResult
,DWORD dwError
,
97 LPCWSTR szResult
) = 0;
100 class wxIInternetProtocolRoot
: public IUnknown
103 virtual HRESULT wxSTDCALL
Start(LPCWSTR szUrl
,wxIInternetProtocolSink
*pOIProtSink
,
104 wxIInternetBindInfo
*pOIBindInfo
,DWORD grfPI
,
105 HANDLE_PTR dwReserved
) = 0;
106 virtual HRESULT wxSTDCALL
Continue(wxPROTOCOLDATA
*pProtocolData
) = 0;
107 virtual HRESULT wxSTDCALL
Abort(HRESULT hrReason
,DWORD dwOptions
) = 0;
108 virtual HRESULT wxSTDCALL
Terminate(DWORD dwOptions
) = 0;
109 virtual HRESULT wxSTDCALL
Suspend(void) = 0;
110 virtual HRESULT wxSTDCALL
Resume(void) = 0;
114 class wxIInternetProtocol
: public wxIInternetProtocolRoot
117 virtual HRESULT wxSTDCALL
Read(void *pv
,ULONG cb
,ULONG
*pcbRead
) = 0;
118 virtual HRESULT wxSTDCALL
Seek(LARGE_INTEGER dlibMove
,DWORD dwOrigin
,
119 ULARGE_INTEGER
*plibNewPosition
) = 0;
120 virtual HRESULT wxSTDCALL
LockRequest(DWORD dwOptions
) = 0;
121 virtual HRESULT wxSTDCALL
UnlockRequest(void) = 0;
125 class wxIInternetSession
: public IUnknown
128 virtual HRESULT wxSTDCALL
RegisterNameSpace(IClassFactory
*pCF
,REFCLSID rclsid
,
131 const LPCWSTR
*ppwzPatterns
,
132 DWORD dwReserved
) = 0;
133 virtual HRESULT wxSTDCALL
UnregisterNameSpace(IClassFactory
*pCF
,
134 LPCWSTR pszProtocol
) = 0;
135 virtual HRESULT wxSTDCALL
RegisterMimeFilter(IClassFactory
*pCF
,
137 LPCWSTR pwzType
) = 0;
138 virtual HRESULT wxSTDCALL
UnregisterMimeFilter(IClassFactory
*pCF
,
139 LPCWSTR pwzType
) = 0;
140 virtual HRESULT wxSTDCALL
CreateBinding(LPBC pBC
,LPCWSTR szUrl
,
141 IUnknown
*pUnkOuter
,IUnknown
**ppUnk
,
142 wxIInternetProtocol
**ppOInetProt
,
144 virtual HRESULT wxSTDCALL
SetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
145 DWORD dwBufferLength
,
146 DWORD dwReserved
) = 0;
147 virtual HRESULT wxSTDCALL
GetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
148 DWORD
*pdwBufferLength
,
149 DWORD dwReserved
) = 0;
152 /* END OF URLMON.H implementation */
154 /* Same goes for the mshtmhst.h, these are also taken
155 * from mingw-w64 headers.
158 typedef enum _tagwxDOCHOSTUIFLAG
160 DOCHOSTUIFLAG_DIALOG
= 0x1,
161 DOCHOSTUIFLAG_DISABLE_HELP_MENU
= 0x2,
162 DOCHOSTUIFLAG_NO3DBORDER
= 0x4,
163 DOCHOSTUIFLAG_SCROLL_NO
= 0x8,
164 DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
= 0x10,
165 DOCHOSTUIFLAG_OPENNEWWIN
= 0x20,
166 DOCHOSTUIFLAG_DISABLE_OFFSCREEN
= 0x40,
167 DOCHOSTUIFLAG_FLAT_SCROLLBAR
= 0x80,
168 DOCHOSTUIFLAG_DIV_BLOCKDEFAULT
= 0x100,
169 DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY
= 0x200,
170 DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY
= 0x400,
171 DOCHOSTUIFLAG_CODEPAGELINKEDFONTS
= 0x800,
172 DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8
= 0x1000,
173 DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
= 0x2000,
174 DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE
= 0x4000,
175 DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
= 0x10000,
176 DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
= 0x20000,
177 DOCHOSTUIFLAG_THEME
= 0x40000,
178 DOCHOSTUIFLAG_NOTHEME
= 0x80000,
179 DOCHOSTUIFLAG_NOPICS
= 0x100000,
180 DOCHOSTUIFLAG_NO3DOUTERBORDER
= 0x200000,
181 DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP
= 0x400000,
182 DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK
= 0x800000,
183 DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL
= 0x1000000
186 typedef struct _tagwxDOCHOSTUIINFO
195 class wxIDocHostUIHandler
: public IUnknown
198 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
199 IUnknown
*pcmdtReserved
,
200 IDispatch
*pdispReserved
) = 0;
202 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
) = 0;
204 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
205 IOleInPlaceActiveObject
*pActiveObject
,
206 IOleCommandTarget
*pCommandTarget
,
207 IOleInPlaceFrame
*pFrame
,
208 IOleInPlaceUIWindow
*pDoc
) = 0;
210 virtual HRESULT wxSTDCALL
HideUI(void) = 0;
212 virtual HRESULT wxSTDCALL
UpdateUI(void) = 0;
214 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
) = 0;
216 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
) = 0;
218 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
) = 0;
220 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
221 IOleInPlaceUIWindow
*pUIWindow
,
222 BOOL fRameWindow
) = 0;
224 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
225 const GUID
*pguidCmdGroup
,
228 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
231 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
232 IDropTarget
**ppDropTarget
) = 0;
234 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
) = 0;
236 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
238 OLECHAR
**ppchURLOut
) = 0;
240 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
241 IDataObject
**ppDORet
) = 0;
244 /* END OF MSHTMHST.H implementation */
246 struct IHTMLDocument2
;
250 class DocHostUIHandler
;
252 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
258 wxWebViewIE(wxWindow
* parent
,
260 const wxString
& url
= wxWebViewDefaultURLStr
,
261 const wxPoint
& pos
= wxDefaultPosition
,
262 const wxSize
& size
= wxDefaultSize
,
264 const wxString
& name
= wxWebViewNameStr
)
266 Create(parent
, id
, url
, pos
, size
, style
, name
);
271 bool Create(wxWindow
* parent
,
273 const wxString
& url
= wxWebViewDefaultURLStr
,
274 const wxPoint
& pos
= wxDefaultPosition
,
275 const wxSize
& size
= wxDefaultSize
,
277 const wxString
& name
= wxWebViewNameStr
);
279 virtual void LoadURL(const wxString
& url
);
280 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
281 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
282 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
284 virtual bool CanGoForward() const;
285 virtual bool CanGoBack() const;
286 virtual void GoBack();
287 virtual void GoForward();
288 virtual void ClearHistory();
289 virtual void EnableHistory(bool enable
= true);
291 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
293 virtual wxString
GetPageSource() const;
294 virtual wxString
GetPageText() const;
296 virtual bool IsBusy() const;
297 virtual wxString
GetCurrentURL() const;
298 virtual wxString
GetCurrentTitle() const;
300 virtual void SetZoomType(wxWebViewZoomType
);
301 virtual wxWebViewZoomType
GetZoomType() const;
302 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
304 virtual void Print();
306 virtual wxWebViewZoom
GetZoom() const;
307 virtual void SetZoom(wxWebViewZoom zoom
);
309 //Clipboard functions
310 virtual bool CanCut() const;
311 virtual bool CanCopy() const;
312 virtual bool CanPaste() const;
315 virtual void Paste();
317 //Undo / redo functionality
318 virtual bool CanUndo() const;
319 virtual bool CanRedo() const;
324 virtual void SetEditable(bool enable
= true);
325 virtual bool IsEditable() const;
328 virtual void SelectAll();
329 virtual bool HasSelection() const;
330 virtual void DeleteSelection();
331 virtual wxString
GetSelectedText() const;
332 virtual wxString
GetSelectedSource() const;
333 virtual void ClearSelection();
335 virtual void RunScript(const wxString
& javascript
);
337 //Virtual Filesystem Support
338 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
340 // ---- IE-specific methods
342 // FIXME: I seem to be able to access remote webpages even in offline mode...
343 bool IsOfflineMode();
344 void SetOfflineMode(bool offline
);
346 wxWebViewZoom
GetIETextZoom() const;
347 void SetIETextZoom(wxWebViewZoom level
);
349 wxWebViewZoom
GetIEOpticalZoom() const;
350 void SetIEOpticalZoom(wxWebViewZoom level
);
352 void onActiveXEvent(wxActiveXEvent
& evt
);
353 void onEraseBg(wxEraseEvent
&) {}
355 DECLARE_EVENT_TABLE();
358 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
);
361 wxIEContainer
* m_container
;
362 wxAutomationObject m_ie
;
363 IWebBrowser2
* m_webBrowser
;
365 wxCOMPtr
<DocHostUIHandler
> m_uiHandler
;
367 //We store the current zoom type;
368 wxWebViewZoomType m_zoomType
;
370 /** The "Busy" property of IWebBrowser2 does not always return busy when
371 * we'd want it to; this variable may be set to true in cases where the
372 * Busy property is false but should be true.
375 //We manage our own history, the history list contains the history items
376 //which are added as documentcomplete events arrive, unless we are loading
377 //an item from the history. The position is stored as an int, and reflects
378 //where we are in the history list.
379 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
380 wxVector
<ClassFactory
*> m_factories
;
381 int m_historyPosition
;
382 bool m_historyLoadingFromList
;
383 bool m_historyEnabled
;
385 //Generic helper functions for IHtmlDocument commands
386 bool CanExecCommand(wxString command
) const;
387 void ExecCommand(wxString command
);
388 wxCOMPtr
<IHTMLDocument2
> GetDocument() const;
389 //Toggles control features see INTERNETFEATURELIST for values.
390 bool EnableControlFeature(long flag
, bool enable
= true);
392 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
395 class VirtualProtocol
: public wxIInternetProtocol
398 wxIInternetProtocolSink
* m_protocolSink
;
403 wxSharedPtr
<wxWebViewHandler
> m_handler
;
406 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
407 ~VirtualProtocol() {}
410 DECLARE_IUNKNOWN_METHODS
;
412 //IInternetProtocolRoot
413 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
414 DWORD
WXUNUSED(dwOptions
))
415 { return E_NOTIMPL
; }
416 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
418 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
419 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
420 wxIInternetProtocolSink
*pOIProtSink
,
421 wxIInternetBindInfo
*pOIBindInfo
,
423 HANDLE_PTR dwReserved
);
424 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
425 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
428 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
430 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
431 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
432 DWORD
WXUNUSED(dwOrigin
),
433 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
435 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
438 class ClassFactory
: public IClassFactory
441 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
444 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
445 REFIID riid
, void** ppvObject
);
446 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
449 DECLARE_IUNKNOWN_METHODS
;
452 wxSharedPtr
<wxWebViewHandler
> m_handler
;
455 class wxIEContainer
: public wxActiveXContainer
458 wxIEContainer(wxWindow
*parent
, REFIID iid
, IUnknown
*pUnk
, DocHostUIHandler
* uiHandler
= NULL
);
459 virtual ~wxIEContainer();
460 virtual bool QueryClientSiteInterface(REFIID iid
, void **_interface
, const char *&desc
);
462 DocHostUIHandler
* m_uiHandler
;
465 class DocHostUIHandler
: public wxIDocHostUIHandler
468 DocHostUIHandler() {};
469 ~DocHostUIHandler() {};
470 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
471 IUnknown
*pcmdtReserved
,
472 IDispatch
*pdispReserved
);
474 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
);
476 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
477 IOleInPlaceActiveObject
*pActiveObject
,
478 IOleCommandTarget
*pCommandTarget
,
479 IOleInPlaceFrame
*pFrame
,
480 IOleInPlaceUIWindow
*pDoc
);
482 virtual HRESULT wxSTDCALL
HideUI(void);
484 virtual HRESULT wxSTDCALL
UpdateUI(void);
486 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
);
488 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
);
490 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
);
492 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
493 IOleInPlaceUIWindow
*pUIWindow
,
496 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
497 const GUID
*pguidCmdGroup
,
500 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
503 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
504 IDropTarget
**ppDropTarget
);
506 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
);
508 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
510 OLECHAR
**ppchURLOut
);
512 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
513 IDataObject
**ppDORet
);
515 DECLARE_IUNKNOWN_METHODS
;
518 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
520 #endif // wxWebViewIE_H