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/wrapwin.h"
22 #include "wx/msw/missing.h"
23 #include "wx/sharedptr.h"
24 #include "wx/vector.h"
26 /* Classes and definitions from urlmon.h vary in their
27 * completeness between compilers and versions of compilers.
28 * We implement our own versions here which should work
29 * for all compilers. The definitions are taken from the
30 * mingw-w64 headers which are public domain.
33 #ifndef REFRESH_NORMAL
34 #define REFRESH_NORMAL 0
37 #ifndef REFRESH_COMPLETELY
38 #define REFRESH_COMPLETELY 3
41 typedef enum __wxMIDL_IBindStatusCallback_0006
43 wxBSCF_FIRSTDATANOTIFICATION
= 0x1,
44 wxBSCF_INTERMEDIATEDATANOTIFICATION
= 0x2,
45 wxBSCF_LASTDATANOTIFICATION
= 0x4,
46 wxBSCF_DATAFULLYAVAILABLE
= 0x8,
47 wxBSCF_AVAILABLEDATASIZEUNKNOWN
= 0x10
50 EXTERN_C
const IID CLSID_FileProtocol
;
52 typedef struct _tagwxBINDINFO
64 SECURITY_ATTRIBUTES securityAttributes
;
70 typedef struct _tagwxPROTOCOLDATA
78 class wxIInternetBindInfo
: public IUnknown
81 virtual HRESULT wxSTDCALL
GetBindInfo(DWORD
*grfBINDF
,wxBINDINFO
*pbindinfo
) = 0;
82 virtual HRESULT wxSTDCALL
GetBindString(ULONG ulStringType
,LPOLESTR
*ppwzStr
,
83 ULONG cEl
,ULONG
*pcElFetched
) = 0;
86 class wxIInternetProtocolSink
: public IUnknown
89 virtual HRESULT wxSTDCALL
Switch(wxPROTOCOLDATA
*pProtocolData
) = 0;
90 virtual HRESULT wxSTDCALL
ReportProgress(ULONG ulStatusCode
,
91 LPCWSTR szStatusText
) = 0;
92 virtual HRESULT wxSTDCALL
ReportData(DWORD grfBSCF
,ULONG ulProgress
,
93 ULONG ulProgressMax
) = 0;
94 virtual HRESULT wxSTDCALL
ReportResult(HRESULT hrResult
,DWORD dwError
,
95 LPCWSTR szResult
) = 0;
98 class wxIInternetProtocolRoot
: public IUnknown
101 virtual HRESULT wxSTDCALL
Start(LPCWSTR szUrl
,wxIInternetProtocolSink
*pOIProtSink
,
102 wxIInternetBindInfo
*pOIBindInfo
,DWORD grfPI
,
103 HANDLE_PTR dwReserved
) = 0;
104 virtual HRESULT wxSTDCALL
Continue(wxPROTOCOLDATA
*pProtocolData
) = 0;
105 virtual HRESULT wxSTDCALL
Abort(HRESULT hrReason
,DWORD dwOptions
) = 0;
106 virtual HRESULT wxSTDCALL
Terminate(DWORD dwOptions
) = 0;
107 virtual HRESULT wxSTDCALL
Suspend(void) = 0;
108 virtual HRESULT wxSTDCALL
Resume(void) = 0;
112 class wxIInternetProtocol
: public wxIInternetProtocolRoot
115 virtual HRESULT wxSTDCALL
Read(void *pv
,ULONG cb
,ULONG
*pcbRead
) = 0;
116 virtual HRESULT wxSTDCALL
Seek(LARGE_INTEGER dlibMove
,DWORD dwOrigin
,
117 ULARGE_INTEGER
*plibNewPosition
) = 0;
118 virtual HRESULT wxSTDCALL
LockRequest(DWORD dwOptions
) = 0;
119 virtual HRESULT wxSTDCALL
UnlockRequest(void) = 0;
123 class wxIInternetSession
: public IUnknown
126 virtual HRESULT wxSTDCALL
RegisterNameSpace(IClassFactory
*pCF
,REFCLSID rclsid
,
129 const LPCWSTR
*ppwzPatterns
,
130 DWORD dwReserved
) = 0;
131 virtual HRESULT wxSTDCALL
UnregisterNameSpace(IClassFactory
*pCF
,
132 LPCWSTR pszProtocol
) = 0;
133 virtual HRESULT wxSTDCALL
RegisterMimeFilter(IClassFactory
*pCF
,
135 LPCWSTR pwzType
) = 0;
136 virtual HRESULT wxSTDCALL
UnregisterMimeFilter(IClassFactory
*pCF
,
137 LPCWSTR pwzType
) = 0;
138 virtual HRESULT wxSTDCALL
CreateBinding(LPBC pBC
,LPCWSTR szUrl
,
139 IUnknown
*pUnkOuter
,IUnknown
**ppUnk
,
140 wxIInternetProtocol
**ppOInetProt
,
142 virtual HRESULT wxSTDCALL
SetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
143 DWORD dwBufferLength
,
144 DWORD dwReserved
) = 0;
145 virtual HRESULT wxSTDCALL
GetSessionOption(DWORD dwOption
,LPVOID pBuffer
,
146 DWORD
*pdwBufferLength
,
147 DWORD dwReserved
) = 0;
150 /* END OF URLMON.H implementation */
152 struct IHTMLDocument2
;
156 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
162 wxWebViewIE(wxWindow
* parent
,
164 const wxString
& url
= wxWebViewDefaultURLStr
,
165 const wxPoint
& pos
= wxDefaultPosition
,
166 const wxSize
& size
= wxDefaultSize
,
168 const wxString
& name
= wxWebViewNameStr
)
170 Create(parent
, id
, url
, pos
, size
, style
, name
);
175 bool Create(wxWindow
* parent
,
177 const wxString
& url
= wxWebViewDefaultURLStr
,
178 const wxPoint
& pos
= wxDefaultPosition
,
179 const wxSize
& size
= wxDefaultSize
,
181 const wxString
& name
= wxWebViewNameStr
);
183 virtual void LoadURL(const wxString
& url
);
184 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
185 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
186 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
188 virtual bool CanGoForward() const;
189 virtual bool CanGoBack() const;
190 virtual void GoBack();
191 virtual void GoForward();
192 virtual void ClearHistory();
193 virtual void EnableHistory(bool enable
= true);
195 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
197 virtual wxString
GetPageSource() const;
198 virtual wxString
GetPageText() const;
200 virtual bool IsBusy() const;
201 virtual wxString
GetCurrentURL() const;
202 virtual wxString
GetCurrentTitle() const;
204 virtual void SetZoomType(wxWebViewZoomType
);
205 virtual wxWebViewZoomType
GetZoomType() const;
206 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
208 virtual void Print();
210 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
212 virtual wxWebViewZoom
GetZoom() const;
213 virtual void SetZoom(wxWebViewZoom zoom
);
215 //Clipboard functions
216 virtual bool CanCut() const;
217 virtual bool CanCopy() const;
218 virtual bool CanPaste() const;
221 virtual void Paste();
223 //Undo / redo functionality
224 virtual bool CanUndo() const;
225 virtual bool CanRedo() const;
230 virtual void SetEditable(bool enable
= true);
231 virtual bool IsEditable() const;
234 virtual void SelectAll();
235 virtual bool HasSelection() const;
236 virtual void DeleteSelection();
237 virtual wxString
GetSelectedText() const;
238 virtual wxString
GetSelectedSource() const;
239 virtual void ClearSelection();
241 virtual void RunScript(const wxString
& javascript
);
243 //Virtual Filesystem Support
244 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
246 // ---- IE-specific methods
248 // FIXME: I seem to be able to access remote webpages even in offline mode...
249 bool IsOfflineMode();
250 void SetOfflineMode(bool offline
);
252 wxWebViewZoom
GetIETextZoom() const;
253 void SetIETextZoom(wxWebViewZoom level
);
255 wxWebViewZoom
GetIEOpticalZoom() const;
256 void SetIEOpticalZoom(wxWebViewZoom level
);
258 void onActiveXEvent(wxActiveXEvent
& evt
);
259 void onEraseBg(wxEraseEvent
&) {}
261 DECLARE_EVENT_TABLE();
264 wxActiveXContainer
* m_container
;
265 wxAutomationObject m_ie
;
266 IWebBrowser2
* m_webBrowser
;
269 //We store the current zoom type;
270 wxWebViewZoomType m_zoomType
;
272 /** The "Busy" property of IWebBrowser2 does not always return busy when
273 * we'd want it to; this variable may be set to true in cases where the
274 * Busy property is false but should be true.
277 //We manage our own history, the history list contains the history items
278 //which are added as documentcomplete events arrive, unless we are loading
279 //an item from the history. The position is stored as an int, and reflects
280 //where we are in the history list.
281 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
282 wxVector
<ClassFactory
*> m_factories
;
283 int m_historyPosition
;
284 bool m_historyLoadingFromList
;
285 bool m_historyEnabled
;
287 //Generic helper functions for IHtmlDocument commands
288 bool CanExecCommand(wxString command
) const;
289 void ExecCommand(wxString command
);
290 IHTMLDocument2
* GetDocument() const;
292 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
295 class VirtualProtocol
: public wxIInternetProtocol
299 wxIInternetProtocolSink
* m_protocolSink
;
304 wxSharedPtr
<wxWebViewHandler
> m_handler
;
307 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
311 ULONG STDMETHODCALLTYPE
AddRef();
312 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
313 ULONG STDMETHODCALLTYPE
Release();
315 //IInternetProtocolRoot
316 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
317 DWORD
WXUNUSED(dwOptions
))
318 { return E_NOTIMPL
; }
319 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
321 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
322 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
323 wxIInternetProtocolSink
*pOIProtSink
,
324 wxIInternetBindInfo
*pOIBindInfo
,
326 HANDLE_PTR dwReserved
);
327 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
328 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
331 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
333 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
334 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
335 DWORD
WXUNUSED(dwOrigin
),
336 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
338 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
341 class ClassFactory
: public IClassFactory
344 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_refCount(0), m_handler(handler
) {}
346 ULONG STDMETHODCALLTYPE
AddRef();
347 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
348 ULONG STDMETHODCALLTYPE
Release();
351 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
352 REFIID riid
, void** ppvObject
);
353 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
356 wxSharedPtr
<wxWebViewHandler
> m_handler
;
359 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
361 #endif // wxWebViewIE_H