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/missing.h"
22 #include "wx/sharedptr.h"
23 #include "wx/vector.h"
25 /* Classes and definitions from urlmon.h vary in their
26 * completeness between compilers and versions of compilers.
27 * We implement our own versions here which should work
28 * for all compilers. The definitions are taken from the
29 * mingw-w64 headers which are public domain.
32 #ifndef REFRESH_NORMAL
33 #define REFRESH_NORMAL 0
36 #ifndef REFRESH_COMPLETELY
37 #define REFRESH_COMPLETELY 3
40 typedef enum __wxMIDL_IBindStatusCallback_0006
42 wxBSCF_FIRSTDATANOTIFICATION
= 0x1,
43 wxBSCF_INTERMEDIATEDATANOTIFICATION
= 0x2,
44 wxBSCF_LASTDATANOTIFICATION
= 0x4,
45 wxBSCF_DATAFULLYAVAILABLE
= 0x8,
46 wxBSCF_AVAILABLEDATASIZEUNKNOWN
= 0x10
49 EXTERN_C
const IID CLSID_FileProtocol
;
51 typedef struct _tagwxBINDINFO
63 SECURITY_ATTRIBUTES securityAttributes
;
69 typedef struct _tagwxPROTOCOLDATA
77 class wxIInternetBindInfo
: public IUnknown
80 virtual HRESULT wxSTDCALL
GetBindInfo(DWORD
*grfBINDF
,wxBINDINFO
*pbindinfo
) = 0;
81 virtual HRESULT wxSTDCALL
GetBindString(ULONG ulStringType
,LPOLESTR
*ppwzStr
,
82 ULONG cEl
,ULONG
*pcElFetched
) = 0;
85 class wxIInternetProtocolSink
: public IUnknown
88 virtual HRESULT wxSTDCALL
Switch(wxPROTOCOLDATA
*pProtocolData
) = 0;
89 virtual HRESULT wxSTDCALL
ReportProgress(ULONG ulStatusCode
,
90 LPCWSTR szStatusText
) = 0;
91 virtual HRESULT wxSTDCALL
ReportData(DWORD grfBSCF
,ULONG ulProgress
,
92 ULONG ulProgressMax
) = 0;
93 virtual HRESULT wxSTDCALL
ReportResult(HRESULT hrResult
,DWORD dwError
,
94 LPCWSTR szResult
) = 0;
97 class wxIInternetProtocolRoot
: public IUnknown
100 virtual HRESULT wxSTDCALL
Start(LPCWSTR szUrl
,wxIInternetProtocolSink
*pOIProtSink
,
101 wxIInternetBindInfo
*pOIBindInfo
,DWORD grfPI
,
102 HANDLE_PTR dwReserved
) = 0;
103 virtual HRESULT wxSTDCALL
Continue(wxPROTOCOLDATA
*pProtocolData
) = 0;
104 virtual HRESULT wxSTDCALL
Abort(HRESULT hrReason
,DWORD dwOptions
) = 0;
105 virtual HRESULT wxSTDCALL
Terminate(DWORD dwOptions
) = 0;
106 virtual HRESULT wxSTDCALL
Suspend(void) = 0;
107 virtual HRESULT wxSTDCALL
Resume(void) = 0;
111 class wxIInternetProtocol
: public wxIInternetProtocolRoot
114 virtual HRESULT wxSTDCALL
Read(void *pv
,ULONG cb
,ULONG
*pcbRead
) = 0;
115 virtual HRESULT wxSTDCALL
Seek(LARGE_INTEGER dlibMove
,DWORD dwOrigin
,
116 ULARGE_INTEGER
*plibNewPosition
) = 0;
117 virtual HRESULT wxSTDCALL
LockRequest(DWORD dwOptions
) = 0;
118 virtual HRESULT wxSTDCALL
UnlockRequest(void) = 0;
122 class wxIInternetSession
: public IUnknown
125 virtual HRESULT wxSTDCALL
RegisterNameSpace(IClassFactory
*pCF
,REFCLSID rclsid
,
128 const LPCWSTR
*ppwzPatterns
,
129 DWORD dwReserved
) = 0;
130 virtual HRESULT wxSTDCALL
UnregisterNameSpace(IClassFactory
*pCF
,
131 LPCWSTR pszProtocol
) = 0;
132 virtual HRESULT wxSTDCALL
RegisterMimeFilter(IClassFactory
*pCF
,
134 LPCWSTR pwzType
) = 0;
135 virtual HRESULT wxSTDCALL
UnregisterMimeFilter(IClassFactory
*pCF
,
136 LPCWSTR pwzType
) = 0;
137 virtual HRESULT wxSTDCALL
CreateBinding(LPBC pBC
,LPCWSTR szUrl
,
138 IUnknown
*pUnkOuter
,IUnknown
**ppUnk
,
139 wxIInternetProtocol
**ppOInetProt
,
141 virtual HRESULT wxSTDCALL
SetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
142 DWORD dwBufferLength
,
143 DWORD dwReserved
) = 0;
144 virtual HRESULT wxSTDCALL
GetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
145 DWORD
*pdwBufferLength
,
146 DWORD dwReserved
) = 0;
149 /* END OF URLMON.H implementation */
151 struct IHTMLDocument2
;
155 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
161 wxWebViewIE(wxWindow
* parent
,
163 const wxString
& url
= wxWebViewDefaultURLStr
,
164 const wxPoint
& pos
= wxDefaultPosition
,
165 const wxSize
& size
= wxDefaultSize
,
167 const wxString
& name
= wxWebViewNameStr
)
169 Create(parent
, id
, url
, pos
, size
, style
, name
);
174 bool Create(wxWindow
* parent
,
176 const wxString
& url
= wxWebViewDefaultURLStr
,
177 const wxPoint
& pos
= wxDefaultPosition
,
178 const wxSize
& size
= wxDefaultSize
,
180 const wxString
& name
= wxWebViewNameStr
);
182 virtual void LoadURL(const wxString
& url
);
183 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
184 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
185 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
187 virtual bool CanGoForward() const;
188 virtual bool CanGoBack() const;
189 virtual void GoBack();
190 virtual void GoForward();
191 virtual void ClearHistory();
192 virtual void EnableHistory(bool enable
= true);
194 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
196 virtual wxString
GetPageSource() const;
197 virtual wxString
GetPageText() const;
199 virtual bool IsBusy() const;
200 virtual wxString
GetCurrentURL() const;
201 virtual wxString
GetCurrentTitle() const;
203 virtual void SetZoomType(wxWebViewZoomType
);
204 virtual wxWebViewZoomType
GetZoomType() const;
205 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
207 virtual void Print();
209 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
211 virtual wxWebViewZoom
GetZoom() const;
212 virtual void SetZoom(wxWebViewZoom zoom
);
214 //Clipboard functions
215 virtual bool CanCut() const;
216 virtual bool CanCopy() const;
217 virtual bool CanPaste() const;
220 virtual void Paste();
222 //Undo / redo functionality
223 virtual bool CanUndo() const;
224 virtual bool CanRedo() const;
229 virtual void SetEditable(bool enable
= true);
230 virtual bool IsEditable() const;
233 virtual void SelectAll();
234 virtual bool HasSelection() const;
235 virtual void DeleteSelection();
236 virtual wxString
GetSelectedText() const;
237 virtual wxString
GetSelectedSource() const;
238 virtual void ClearSelection();
240 virtual void RunScript(const wxString
& javascript
);
242 //Virtual Filesystem Support
243 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
245 // ---- IE-specific methods
247 // FIXME: I seem to be able to access remote webpages even in offline mode...
248 bool IsOfflineMode();
249 void SetOfflineMode(bool offline
);
251 wxWebViewZoom
GetIETextZoom() const;
252 void SetIETextZoom(wxWebViewZoom level
);
254 wxWebViewZoom
GetIEOpticalZoom() const;
255 void SetIEOpticalZoom(wxWebViewZoom level
);
257 void onActiveXEvent(wxActiveXEvent
& evt
);
258 void onEraseBg(wxEraseEvent
&) {}
260 DECLARE_EVENT_TABLE();
263 wxActiveXContainer
* m_container
;
264 wxAutomationObject m_ie
;
265 IWebBrowser2
* m_webBrowser
;
268 //We store the current zoom type;
269 wxWebViewZoomType m_zoomType
;
271 /** The "Busy" property of IWebBrowser2 does not always return busy when
272 * we'd want it to; this variable may be set to true in cases where the
273 * Busy property is false but should be true.
276 //We manage our own history, the history list contains the history items
277 //which are added as documentcomplete events arrive, unless we are loading
278 //an item from the history. The position is stored as an int, and reflects
279 //where we are in the history list.
280 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
281 wxVector
<ClassFactory
*> m_factories
;
282 int m_historyPosition
;
283 bool m_historyLoadingFromList
;
284 bool m_historyEnabled
;
286 //Generic helper functions for IHtmlDocument commands
287 bool CanExecCommand(wxString command
) const;
288 void ExecCommand(wxString command
);
289 IHTMLDocument2
* GetDocument() const;
291 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
294 class VirtualProtocol
: public wxIInternetProtocol
298 wxIInternetProtocolSink
* m_protocolSink
;
303 wxSharedPtr
<wxWebViewHandler
> m_handler
;
306 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
310 ULONG STDMETHODCALLTYPE
AddRef();
311 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
312 ULONG STDMETHODCALLTYPE
Release();
314 //IInternetProtocolRoot
315 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
316 DWORD
WXUNUSED(dwOptions
))
317 { return E_NOTIMPL
; }
318 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
320 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
321 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
322 wxIInternetProtocolSink
*pOIProtSink
,
323 wxIInternetBindInfo
*pOIBindInfo
,
325 HANDLE_PTR dwReserved
);
326 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
327 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
330 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
332 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
333 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
334 DWORD
WXUNUSED(dwOrigin
),
335 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
337 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
340 class ClassFactory
: public IClassFactory
343 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_refCount(0), m_handler(handler
) {}
345 ULONG STDMETHODCALLTYPE
AddRef();
346 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
347 ULONG STDMETHODCALLTYPE
Release();
350 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
351 REFIID riid
, void** ppvObject
);
352 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
355 wxSharedPtr
<wxWebViewHandler
> m_handler
;
358 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
360 #endif // wxWebViewIE_H