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 struct IHTMLDocument2
;
157 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
163 wxWebViewIE(wxWindow
* parent
,
165 const wxString
& url
= wxWebViewDefaultURLStr
,
166 const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
,
169 const wxString
& name
= wxWebViewNameStr
)
171 Create(parent
, id
, url
, pos
, size
, style
, name
);
176 bool Create(wxWindow
* parent
,
178 const wxString
& url
= wxWebViewDefaultURLStr
,
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
182 const wxString
& name
= wxWebViewNameStr
);
184 virtual void LoadURL(const wxString
& url
);
185 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
186 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
187 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
189 virtual bool CanGoForward() const;
190 virtual bool CanGoBack() const;
191 virtual void GoBack();
192 virtual void GoForward();
193 virtual void ClearHistory();
194 virtual void EnableHistory(bool enable
= true);
196 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
198 virtual wxString
GetPageSource() const;
199 virtual wxString
GetPageText() const;
201 virtual bool IsBusy() const;
202 virtual wxString
GetCurrentURL() const;
203 virtual wxString
GetCurrentTitle() const;
205 virtual void SetZoomType(wxWebViewZoomType
);
206 virtual wxWebViewZoomType
GetZoomType() const;
207 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
209 virtual void Print();
211 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
213 virtual wxWebViewZoom
GetZoom() const;
214 virtual void SetZoom(wxWebViewZoom zoom
);
216 //Clipboard functions
217 virtual bool CanCut() const;
218 virtual bool CanCopy() const;
219 virtual bool CanPaste() const;
222 virtual void Paste();
224 //Undo / redo functionality
225 virtual bool CanUndo() const;
226 virtual bool CanRedo() const;
231 virtual void SetEditable(bool enable
= true);
232 virtual bool IsEditable() const;
235 virtual void SelectAll();
236 virtual bool HasSelection() const;
237 virtual void DeleteSelection();
238 virtual wxString
GetSelectedText() const;
239 virtual wxString
GetSelectedSource() const;
240 virtual void ClearSelection();
242 virtual void RunScript(const wxString
& javascript
);
244 //Virtual Filesystem Support
245 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
247 // ---- IE-specific methods
249 // FIXME: I seem to be able to access remote webpages even in offline mode...
250 bool IsOfflineMode();
251 void SetOfflineMode(bool offline
);
253 wxWebViewZoom
GetIETextZoom() const;
254 void SetIETextZoom(wxWebViewZoom level
);
256 wxWebViewZoom
GetIEOpticalZoom() const;
257 void SetIEOpticalZoom(wxWebViewZoom level
);
259 void onActiveXEvent(wxActiveXEvent
& evt
);
260 void onEraseBg(wxEraseEvent
&) {}
262 DECLARE_EVENT_TABLE();
265 wxActiveXContainer
* m_container
;
266 wxAutomationObject m_ie
;
267 IWebBrowser2
* m_webBrowser
;
270 //We store the current zoom type;
271 wxWebViewZoomType m_zoomType
;
273 /** The "Busy" property of IWebBrowser2 does not always return busy when
274 * we'd want it to; this variable may be set to true in cases where the
275 * Busy property is false but should be true.
278 //We manage our own history, the history list contains the history items
279 //which are added as documentcomplete events arrive, unless we are loading
280 //an item from the history. The position is stored as an int, and reflects
281 //where we are in the history list.
282 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
283 wxVector
<ClassFactory
*> m_factories
;
284 int m_historyPosition
;
285 bool m_historyLoadingFromList
;
286 bool m_historyEnabled
;
288 //Generic helper functions for IHtmlDocument commands
289 bool CanExecCommand(wxString command
) const;
290 void ExecCommand(wxString command
);
291 IHTMLDocument2
* GetDocument() const;
293 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
296 class VirtualProtocol
: public wxIInternetProtocol
299 wxIInternetProtocolSink
* m_protocolSink
;
304 wxSharedPtr
<wxWebViewHandler
> m_handler
;
307 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
308 ~VirtualProtocol() {}
311 DECLARE_IUNKNOWN_METHODS
;
313 //IInternetProtocolRoot
314 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
315 DWORD
WXUNUSED(dwOptions
))
316 { return E_NOTIMPL
; }
317 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
319 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
320 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
321 wxIInternetProtocolSink
*pOIProtSink
,
322 wxIInternetBindInfo
*pOIBindInfo
,
324 HANDLE_PTR dwReserved
);
325 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
326 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
329 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
331 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
332 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
333 DWORD
WXUNUSED(dwOrigin
),
334 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
336 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
339 class ClassFactory
: public IClassFactory
342 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
345 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
346 REFIID riid
, void** ppvObject
);
347 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
350 DECLARE_IUNKNOWN_METHODS
;
353 wxSharedPtr
<wxWebViewHandler
> m_handler
;
356 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
358 #endif // wxWebViewIE_H