]>
Commit | Line | Data |
---|---|---|
61b98a2d | 1 | ///////////////////////////////////////////////////////////////////////////// |
8290e3cd | 2 | // Name: src/msw/webview_ie.cpp |
61b98a2d SL |
3 | // Purpose: wxMSW wxWebViewIE class implementation for web view component |
4 | // Author: Marianne Gagnon | |
5 | // Id: $Id$ | |
153530af | 6 | // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton |
61b98a2d SL |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
384b8d9f SL |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if defined(__BORLANDC__) | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
8290e3cd | 17 | #include "wx/msw/webview_ie.h" |
61b98a2d | 18 | |
9d2f31db | 19 | #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE |
61b98a2d SL |
20 | |
21 | #include <olectl.h> | |
22 | #include <oleidl.h> | |
23 | #include <exdispid.h> | |
24 | #include <exdisp.h> | |
25 | #include <mshtml.h> | |
cd4e4673 | 26 | #include "wx/msw/registry.h" |
1d7d04d7 | 27 | #include "wx/msw/missing.h" |
7d3f6b4d | 28 | #include "wx/filesys.h" |
e924e848 | 29 | #include "wx/dynlib.h" |
f559d1a2 VZ |
30 | #include <initguid.h> |
31 | ||
32 | /* These GUID definitions are our own implementation to support interfaces | |
33 | * normally in urlmon.h. See include/wx/msw/webview_ie.h | |
34 | */ | |
35 | ||
36 | namespace { | |
37 | ||
38 | DEFINE_GUID(wxIID_IInternetProtocolRoot,0x79eac9e3,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); | |
39 | DEFINE_GUID(wxIID_IInternetProtocol,0x79eac9e4,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); | |
accc94d5 | 40 | DEFINE_GUID(wxIID_IDocHostUIHandler, 0xbd3f23c0, 0xd43e, 0x11cf, 0x89, 0x3b, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x1a); |
f559d1a2 VZ |
41 | |
42 | } | |
7d3f6b4d | 43 | |
cddf4541 SL |
44 | wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewIE, wxWebView); |
45 | ||
61b98a2d | 46 | BEGIN_EVENT_TABLE(wxWebViewIE, wxControl) |
97ad1425 SL |
47 | EVT_ACTIVEX(wxID_ANY, wxWebViewIE::onActiveXEvent) |
48 | EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg) | |
61b98a2d SL |
49 | END_EVENT_TABLE() |
50 | ||
51 | bool wxWebViewIE::Create(wxWindow* parent, | |
52 | wxWindowID id, | |
53 | const wxString& url, | |
54 | const wxPoint& pos, | |
55 | const wxSize& size, | |
56 | long style, | |
57 | const wxString& name) | |
58 | { | |
59 | if (!wxControl::Create(parent, id, pos, size, style, | |
60 | wxDefaultValidator, name)) | |
61 | { | |
62 | return false; | |
63 | } | |
64 | ||
65 | m_webBrowser = NULL; | |
61b98a2d | 66 | m_isBusy = false; |
74af0b13 SL |
67 | m_historyLoadingFromList = false; |
68 | m_historyEnabled = true; | |
69 | m_historyPosition = -1; | |
c5f417cb | 70 | m_zoomType = wxWEB_VIEW_ZOOM_TYPE_TEXT; |
61b98a2d SL |
71 | |
72 | if (::CoCreateInstance(CLSID_WebBrowser, NULL, | |
73 | CLSCTX_INPROC_SERVER, // CLSCTX_INPROC, | |
74 | IID_IWebBrowser2 , (void**)&m_webBrowser) != 0) | |
75 | { | |
76 | wxLogError("Failed to initialize IE, CoCreateInstance returned an error"); | |
77 | return false; | |
78 | } | |
79 | ||
80 | m_ie.SetDispatchPtr(m_webBrowser); // wxAutomationObject will release itself | |
81 | ||
82 | m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE); | |
83 | m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE); | |
61b98a2d | 84 | |
accc94d5 SL |
85 | m_uiHandler = new DocHostUIHandler; |
86 | m_uiHandler->AddRef(); | |
87 | ||
88 | m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler); | |
61b98a2d | 89 | |
9447a0d6 SL |
90 | EnableControlFeature(21 /* FEATURE_DISABLE_NAVIGATION_SOUNDS */); |
91 | ||
4d0dddc7 | 92 | LoadURL(url); |
61b98a2d SL |
93 | return true; |
94 | } | |
95 | ||
39498710 SL |
96 | wxWebViewIE::~wxWebViewIE() |
97 | { | |
98 | for(unsigned int i = 0; i < m_factories.size(); i++) | |
99 | { | |
100 | m_factories[i]->Release(); | |
101 | } | |
accc94d5 SL |
102 | |
103 | m_uiHandler->Release(); | |
39498710 | 104 | } |
61b98a2d | 105 | |
4d0dddc7 | 106 | void wxWebViewIE::LoadURL(const wxString& url) |
61b98a2d | 107 | { |
e8d243a9 | 108 | m_ie.CallMethod("Navigate", wxConvertStringToOle(url)); |
61b98a2d SL |
109 | } |
110 | ||
442262d4 | 111 | void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl) |
61b98a2d | 112 | { |
7f98bdd6 | 113 | BSTR bstr = SysAllocString(OLESTR("")); |
61b98a2d SL |
114 | SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1); |
115 | if (psaStrings != NULL) | |
116 | { | |
117 | VARIANT *param; | |
118 | HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m); | |
119 | param->vt = VT_BSTR; | |
120 | param->bstrVal = bstr; | |
442262d4 | 121 | |
7f98bdd6 | 122 | hr = SafeArrayUnaccessData(psaStrings); |
accc94d5 | 123 | |
617227c3 | 124 | IHTMLDocument2* document = GetDocument(); |
61b98a2d | 125 | document->write(psaStrings); |
7f98bdd6 | 126 | document->close(); |
442262d4 | 127 | document->Release(); |
61b98a2d | 128 | |
61b98a2d | 129 | SafeArrayDestroy(psaStrings); |
442262d4 | 130 | |
7f98bdd6 SL |
131 | bstr = SysAllocString(html.wc_str()); |
132 | ||
133 | // Creates a new one-dimensional array | |
134 | psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1); | |
135 | if (psaStrings != NULL) | |
136 | { | |
137 | hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m); | |
138 | param->vt = VT_BSTR; | |
139 | param->bstrVal = bstr; | |
140 | hr = SafeArrayUnaccessData(psaStrings); | |
141 | ||
142 | document = GetDocument(); | |
143 | document->write(psaStrings); | |
144 | document->Release(); | |
145 | ||
146 | // SafeArrayDestroy calls SysFreeString for each BSTR | |
147 | SafeArrayDestroy(psaStrings); | |
148 | ||
149 | //We send the events when we are done to mimic webkit | |
150 | //Navigated event | |
151 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, | |
152 | GetId(), baseUrl, ""); | |
153 | event.SetEventObject(this); | |
154 | HandleWindowEvent(event); | |
155 | ||
156 | //Document complete event | |
157 | event.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED); | |
158 | event.SetEventObject(this); | |
159 | HandleWindowEvent(event); | |
160 | } | |
161 | else | |
162 | { | |
163 | wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL"); | |
164 | } | |
61b98a2d SL |
165 | } |
166 | else | |
167 | { | |
7f98bdd6 | 168 | wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL during clear"); |
61b98a2d | 169 | } |
61b98a2d SL |
170 | } |
171 | ||
e669ddde | 172 | wxString wxWebViewIE::GetPageSource() const |
61b98a2d | 173 | { |
617227c3 | 174 | IHTMLDocument2* document = GetDocument(); |
61b98a2d SL |
175 | IHTMLElement *bodyTag = NULL; |
176 | IHTMLElement *htmlTag = NULL; | |
423adfde | 177 | wxString source; |
7fbc727b SL |
178 | HRESULT hr = document->get_body(&bodyTag); |
179 | if(SUCCEEDED(hr)) | |
180 | { | |
181 | hr = bodyTag->get_parentElement(&htmlTag); | |
182 | if(SUCCEEDED(hr)) | |
183 | { | |
423adfde | 184 | BSTR bstr; |
7fbc727b | 185 | htmlTag->get_outerHTML(&bstr); |
423adfde | 186 | source = wxString(bstr); |
7fbc727b SL |
187 | htmlTag->Release(); |
188 | } | |
189 | bodyTag->Release(); | |
190 | } | |
61b98a2d SL |
191 | |
192 | document->Release(); | |
423adfde | 193 | return source; |
61b98a2d SL |
194 | } |
195 | ||
e669ddde | 196 | wxWebViewZoom wxWebViewIE::GetZoom() const |
61b98a2d | 197 | { |
8acbf08b SL |
198 | switch( m_zoomType ) |
199 | { | |
200 | case wxWEB_VIEW_ZOOM_TYPE_LAYOUT: | |
201 | return GetIEOpticalZoom(); | |
202 | case wxWEB_VIEW_ZOOM_TYPE_TEXT: | |
203 | return GetIETextZoom(); | |
204 | default: | |
205 | wxFAIL; | |
206 | } | |
423adfde SL |
207 | |
208 | //Dummy return to stop compiler warnings | |
209 | return wxWEB_VIEW_ZOOM_MEDIUM; | |
1d7d04d7 | 210 | |
61b98a2d | 211 | } |
c5f417cb | 212 | |
61b98a2d SL |
213 | void wxWebViewIE::SetZoom(wxWebViewZoom zoom) |
214 | { | |
8acbf08b SL |
215 | switch( m_zoomType ) |
216 | { | |
217 | case wxWEB_VIEW_ZOOM_TYPE_LAYOUT: | |
218 | SetIEOpticalZoom(zoom); | |
219 | break; | |
220 | case wxWEB_VIEW_ZOOM_TYPE_TEXT: | |
221 | SetIETextZoom(zoom); | |
222 | break; | |
223 | default: | |
224 | wxFAIL; | |
225 | } | |
61b98a2d SL |
226 | } |
227 | ||
c5f417cb | 228 | void wxWebViewIE::SetIETextZoom(wxWebViewZoom level) |
61b98a2d | 229 | { |
1d7d04d7 | 230 | //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range |
c5f417cb SL |
231 | //is 0 to 4 so the check is unnecessary, these match exactly with the |
232 | //enum values | |
61b98a2d SL |
233 | VARIANT zoomVariant; |
234 | VariantInit (&zoomVariant); | |
235 | V_VT(&zoomVariant) = VT_I4; | |
236 | V_I4(&zoomVariant) = level; | |
237 | ||
8acbf08b SL |
238 | #if wxDEBUG_LEVEL |
239 | HRESULT result = | |
240 | #endif | |
241 | m_webBrowser->ExecWB(OLECMDID_ZOOM, | |
242 | OLECMDEXECOPT_DONTPROMPTUSER, | |
243 | &zoomVariant, NULL); | |
c5f417cb | 244 | wxASSERT(result == S_OK); |
61b98a2d SL |
245 | } |
246 | ||
e669ddde | 247 | wxWebViewZoom wxWebViewIE::GetIETextZoom() const |
61b98a2d SL |
248 | { |
249 | VARIANT zoomVariant; | |
250 | VariantInit (&zoomVariant); | |
251 | V_VT(&zoomVariant) = VT_I4; | |
61b98a2d | 252 | |
8acbf08b SL |
253 | #if wxDEBUG_LEVEL |
254 | HRESULT result = | |
255 | #endif | |
256 | m_webBrowser->ExecWB(OLECMDID_ZOOM, | |
257 | OLECMDEXECOPT_DONTPROMPTUSER, | |
258 | NULL, &zoomVariant); | |
c5f417cb | 259 | wxASSERT(result == S_OK); |
61b98a2d | 260 | |
c5f417cb SL |
261 | //We can safely cast here as we know that the range matches our enum |
262 | return static_cast<wxWebViewZoom>(V_I4(&zoomVariant)); | |
61b98a2d SL |
263 | } |
264 | ||
c5f417cb | 265 | void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level) |
61b98a2d | 266 | { |
1d7d04d7 | 267 | //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range |
c5f417cb | 268 | //is 10 to 1000 so the check is unnecessary |
61b98a2d SL |
269 | VARIANT zoomVariant; |
270 | VariantInit (&zoomVariant); | |
271 | V_VT(&zoomVariant) = VT_I4; | |
c5f417cb SL |
272 | |
273 | //We make a somewhat arbitray map here, taken from values used by webkit | |
274 | switch(level) | |
275 | { | |
276 | case wxWEB_VIEW_ZOOM_TINY: | |
277 | V_I4(&zoomVariant) = 60; | |
278 | break; | |
279 | case wxWEB_VIEW_ZOOM_SMALL: | |
280 | V_I4(&zoomVariant) = 80; | |
281 | break; | |
282 | case wxWEB_VIEW_ZOOM_MEDIUM: | |
283 | V_I4(&zoomVariant) = 100; | |
284 | break; | |
285 | case wxWEB_VIEW_ZOOM_LARGE: | |
286 | V_I4(&zoomVariant) = 130; | |
287 | break; | |
288 | case wxWEB_VIEW_ZOOM_LARGEST: | |
289 | V_I4(&zoomVariant) = 160; | |
290 | break; | |
291 | default: | |
292 | wxFAIL; | |
293 | } | |
61b98a2d | 294 | |
8acbf08b SL |
295 | #if wxDEBUG_LEVEL |
296 | HRESULT result = | |
297 | #endif | |
298 | m_webBrowser->ExecWB((OLECMDID)63 /*OLECMDID_OPTICAL_ZOOM*/, | |
299 | OLECMDEXECOPT_DODEFAULT, | |
300 | &zoomVariant, | |
301 | NULL); | |
c5f417cb | 302 | wxASSERT(result == S_OK); |
61b98a2d SL |
303 | } |
304 | ||
e669ddde | 305 | wxWebViewZoom wxWebViewIE::GetIEOpticalZoom() const |
61b98a2d | 306 | { |
61b98a2d SL |
307 | VARIANT zoomVariant; |
308 | VariantInit (&zoomVariant); | |
309 | V_VT(&zoomVariant) = VT_I4; | |
61b98a2d | 310 | |
8acbf08b SL |
311 | #if wxDEBUG_LEVEL |
312 | HRESULT result = | |
313 | #endif | |
314 | m_webBrowser->ExecWB((OLECMDID)63 /*OLECMDID_OPTICAL_ZOOM*/, | |
315 | OLECMDEXECOPT_DODEFAULT, NULL, | |
316 | &zoomVariant); | |
c5f417cb | 317 | wxASSERT(result == S_OK); |
61b98a2d SL |
318 | |
319 | const int zoom = V_I4(&zoomVariant); | |
61b98a2d | 320 | |
c5f417cb SL |
321 | //We make a somewhat arbitray map here, taken from values used by webkit |
322 | if (zoom <= 65) | |
323 | { | |
324 | return wxWEB_VIEW_ZOOM_TINY; | |
325 | } | |
326 | else if (zoom > 65 && zoom <= 90) | |
327 | { | |
328 | return wxWEB_VIEW_ZOOM_SMALL; | |
329 | } | |
330 | else if (zoom > 90 && zoom <= 115) | |
331 | { | |
332 | return wxWEB_VIEW_ZOOM_MEDIUM; | |
333 | } | |
334 | else if (zoom > 115 && zoom <= 145) | |
335 | { | |
336 | return wxWEB_VIEW_ZOOM_LARGE; | |
337 | } | |
423adfde | 338 | else /*if (zoom > 145) */ //Using else removes a compiler warning |
c5f417cb SL |
339 | { |
340 | return wxWEB_VIEW_ZOOM_LARGEST; | |
341 | } | |
61b98a2d SL |
342 | } |
343 | ||
c5f417cb | 344 | void wxWebViewIE::SetZoomType(wxWebViewZoomType type) |
61b98a2d | 345 | { |
c5f417cb | 346 | m_zoomType = type; |
61b98a2d SL |
347 | } |
348 | ||
349 | wxWebViewZoomType wxWebViewIE::GetZoomType() const | |
350 | { | |
c5f417cb | 351 | return m_zoomType; |
61b98a2d SL |
352 | } |
353 | ||
cd4e4673 | 354 | bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type) const |
61b98a2d | 355 | { |
cd4e4673 SL |
356 | //IE 6 and below only support text zoom, so check the registry to see what |
357 | //version we actually have | |
358 | wxRegKey key(wxRegKey::HKLM, "Software\\Microsoft\\Internet Explorer"); | |
359 | wxString value; | |
360 | key.QueryValue("Version", value); | |
361 | ||
362 | long version = wxAtoi(value.Left(1)); | |
363 | if(version <= 6 && type == wxWEB_VIEW_ZOOM_TYPE_LAYOUT) | |
364 | return false; | |
365 | else | |
366 | return true; | |
61b98a2d SL |
367 | } |
368 | ||
369 | void wxWebViewIE::Print() | |
370 | { | |
371 | m_webBrowser->ExecWB(OLECMDID_PRINTPREVIEW, | |
372 | OLECMDEXECOPT_DODEFAULT, NULL, NULL); | |
373 | } | |
374 | ||
e669ddde | 375 | bool wxWebViewIE::CanGoBack() const |
61b98a2d | 376 | { |
74af0b13 SL |
377 | if(m_historyEnabled) |
378 | return m_historyPosition > 0; | |
379 | else | |
380 | return false; | |
381 | } | |
61b98a2d | 382 | |
e669ddde | 383 | bool wxWebViewIE::CanGoForward() const |
74af0b13 SL |
384 | { |
385 | if(m_historyEnabled) | |
22ca10fa | 386 | return m_historyPosition != static_cast<int>(m_historyList.size()) - 1; |
74af0b13 SL |
387 | else |
388 | return false; | |
61b98a2d SL |
389 | } |
390 | ||
c13d6ac1 | 391 | void wxWebViewIE::LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) |
61b98a2d | 392 | { |
74af0b13 SL |
393 | int pos = -1; |
394 | for(unsigned int i = 0; i < m_historyList.size(); i++) | |
395 | { | |
3e7968c2 SL |
396 | //We compare the actual pointers to find the correct item |
397 | if(m_historyList[i].get() == item.get()) | |
74af0b13 SL |
398 | pos = i; |
399 | } | |
1d7d04d7 | 400 | wxASSERT_MSG(pos != static_cast<int>(m_historyList.size()), |
22ca10fa | 401 | "invalid history item"); |
74af0b13 | 402 | m_historyLoadingFromList = true; |
4d0dddc7 | 403 | LoadURL(item->GetUrl()); |
74af0b13 SL |
404 | m_historyPosition = pos; |
405 | } | |
61b98a2d | 406 | |
c13d6ac1 | 407 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewIE::GetBackwardHistory() |
5cbda74b | 408 | { |
c13d6ac1 | 409 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > backhist; |
5cbda74b SL |
410 | //As we don't have std::copy or an iterator constructor in the wxwidgets |
411 | //native vector we construct it by hand | |
412 | for(int i = 0; i < m_historyPosition; i++) | |
413 | { | |
414 | backhist.push_back(m_historyList[i]); | |
415 | } | |
416 | return backhist; | |
417 | } | |
418 | ||
c13d6ac1 | 419 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewIE::GetForwardHistory() |
5cbda74b | 420 | { |
c13d6ac1 | 421 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > forwardhist; |
5cbda74b SL |
422 | //As we don't have std::copy or an iterator constructor in the wxwidgets |
423 | //native vector we construct it by hand | |
22ca10fa | 424 | for(int i = m_historyPosition + 1; i < static_cast<int>(m_historyList.size()); i++) |
5cbda74b SL |
425 | { |
426 | forwardhist.push_back(m_historyList[i]); | |
427 | } | |
428 | return forwardhist; | |
429 | } | |
430 | ||
74af0b13 SL |
431 | void wxWebViewIE::GoBack() |
432 | { | |
3e7968c2 | 433 | LoadHistoryItem(m_historyList[m_historyPosition - 1]); |
74af0b13 SL |
434 | } |
435 | ||
436 | void wxWebViewIE::GoForward() | |
437 | { | |
3e7968c2 | 438 | LoadHistoryItem(m_historyList[m_historyPosition + 1]); |
61b98a2d SL |
439 | } |
440 | ||
441 | void wxWebViewIE::Stop() | |
442 | { | |
7fbc727b | 443 | m_ie.CallMethod("Stop"); |
61b98a2d SL |
444 | } |
445 | ||
74af0b13 SL |
446 | void wxWebViewIE::ClearHistory() |
447 | { | |
448 | m_historyList.clear(); | |
449 | m_historyPosition = -1; | |
450 | } | |
451 | ||
452 | void wxWebViewIE::EnableHistory(bool enable) | |
453 | { | |
454 | m_historyEnabled = enable; | |
455 | m_historyList.clear(); | |
456 | m_historyPosition = -1; | |
457 | } | |
61b98a2d SL |
458 | |
459 | void wxWebViewIE::Reload(wxWebViewReloadFlags flags) | |
460 | { | |
7aa18fc7 SL |
461 | VARIANTARG level; |
462 | VariantInit(&level); | |
463 | V_VT(&level) = VT_I2; | |
61b98a2d | 464 | |
7aa18fc7 | 465 | switch(flags) |
61b98a2d | 466 | { |
7aa18fc7 SL |
467 | case wxWEB_VIEW_RELOAD_DEFAULT: |
468 | V_I2(&level) = REFRESH_NORMAL; | |
469 | break; | |
470 | case wxWEB_VIEW_RELOAD_NO_CACHE: | |
471 | V_I2(&level) = REFRESH_COMPLETELY; | |
472 | break; | |
473 | default: | |
474 | wxFAIL_MSG("Unexpected reload type"); | |
61b98a2d SL |
475 | } |
476 | ||
7aa18fc7 | 477 | m_webBrowser->Refresh2(&level); |
61b98a2d SL |
478 | } |
479 | ||
480 | bool wxWebViewIE::IsOfflineMode() | |
481 | { | |
482 | wxVariant out = m_ie.GetProperty("Offline"); | |
483 | ||
484 | wxASSERT(out.GetType() == "bool"); | |
485 | ||
486 | return out.GetBool(); | |
487 | } | |
488 | ||
489 | void wxWebViewIE::SetOfflineMode(bool offline) | |
490 | { | |
491 | // FIXME: the wxWidgets docs do not really document what the return | |
492 | // parameter of PutProperty is | |
8acbf08b SL |
493 | #if wxDEBUG_LEVEL |
494 | const bool success = | |
495 | #endif | |
496 | m_ie.PutProperty("Offline", (offline ? | |
497 | VARIANT_TRUE : | |
498 | VARIANT_FALSE)); | |
61b98a2d SL |
499 | wxASSERT(success); |
500 | } | |
501 | ||
e669ddde | 502 | bool wxWebViewIE::IsBusy() const |
60eabdbe | 503 | { |
61b98a2d SL |
504 | if (m_isBusy) return true; |
505 | ||
506 | wxVariant out = m_ie.GetProperty("Busy"); | |
507 | ||
508 | wxASSERT(out.GetType() == "bool"); | |
509 | ||
510 | return out.GetBool(); | |
511 | } | |
512 | ||
e669ddde | 513 | wxString wxWebViewIE::GetCurrentURL() const |
61b98a2d SL |
514 | { |
515 | wxVariant out = m_ie.GetProperty("LocationURL"); | |
516 | ||
517 | wxASSERT(out.GetType() == "string"); | |
518 | return out.GetString(); | |
519 | } | |
520 | ||
e669ddde | 521 | wxString wxWebViewIE::GetCurrentTitle() const |
61b98a2d | 522 | { |
617227c3 | 523 | IHTMLDocument2* document = GetDocument(); |
977c5320 | 524 | BSTR title; |
7fbc727b | 525 | |
977c5320 | 526 | document->get_nameProp(&title); |
7fbc727b | 527 | document->Release(); |
977c5320 | 528 | return wxString(title); |
61b98a2d SL |
529 | } |
530 | ||
e669ddde | 531 | bool wxWebViewIE::CanCut() const |
4681a3ea SL |
532 | { |
533 | return CanExecCommand("Cut"); | |
534 | } | |
535 | ||
e669ddde | 536 | bool wxWebViewIE::CanCopy() const |
4681a3ea SL |
537 | { |
538 | return CanExecCommand("Copy"); | |
539 | } | |
e669ddde | 540 | bool wxWebViewIE::CanPaste() const |
4681a3ea SL |
541 | { |
542 | return CanExecCommand("Paste"); | |
543 | } | |
544 | ||
545 | void wxWebViewIE::Cut() | |
546 | { | |
547 | ExecCommand("Cut"); | |
548 | } | |
549 | ||
550 | void wxWebViewIE::Copy() | |
551 | { | |
552 | ExecCommand("Copy"); | |
553 | } | |
554 | ||
555 | void wxWebViewIE::Paste() | |
556 | { | |
557 | ExecCommand("Paste"); | |
558 | } | |
559 | ||
e669ddde | 560 | bool wxWebViewIE::CanUndo() const |
97e49559 SL |
561 | { |
562 | return CanExecCommand("Undo"); | |
563 | } | |
e669ddde | 564 | bool wxWebViewIE::CanRedo() const |
97e49559 SL |
565 | { |
566 | return CanExecCommand("Redo"); | |
567 | } | |
568 | ||
569 | void wxWebViewIE::Undo() | |
570 | { | |
571 | ExecCommand("Undo"); | |
572 | } | |
573 | ||
574 | void wxWebViewIE::Redo() | |
575 | { | |
576 | ExecCommand("Redo"); | |
577 | } | |
578 | ||
c7cbe308 SL |
579 | void wxWebViewIE::SetEditable(bool enable) |
580 | { | |
581 | IHTMLDocument2* document = GetDocument(); | |
582 | if( enable ) | |
583 | document->put_designMode(SysAllocString(L"On")); | |
584 | else | |
585 | document->put_designMode(SysAllocString(L"Off")); | |
7fbc727b SL |
586 | |
587 | document->Release(); | |
c7cbe308 SL |
588 | } |
589 | ||
e669ddde | 590 | bool wxWebViewIE::IsEditable() const |
c7cbe308 SL |
591 | { |
592 | IHTMLDocument2* document = GetDocument(); | |
593 | BSTR mode; | |
594 | document->get_designMode(&mode); | |
423adfde | 595 | document->Release(); |
c7cbe308 SL |
596 | if(wxString(mode) == "On") |
597 | return true; | |
598 | else | |
599 | return false; | |
600 | } | |
601 | ||
63a65070 SL |
602 | void wxWebViewIE::SelectAll() |
603 | { | |
604 | ExecCommand("SelectAll"); | |
605 | } | |
606 | ||
e669ddde | 607 | bool wxWebViewIE::HasSelection() const |
63a65070 SL |
608 | { |
609 | IHTMLDocument2* document = GetDocument(); | |
610 | IHTMLSelectionObject* selection; | |
423adfde | 611 | wxString sel; |
7fbc727b SL |
612 | HRESULT hr = document->get_selection(&selection); |
613 | if(SUCCEEDED(hr)) | |
614 | { | |
423adfde | 615 | BSTR type; |
7fbc727b | 616 | selection->get_type(&type); |
423adfde | 617 | sel = wxString(type); |
7fbc727b SL |
618 | selection->Release(); |
619 | } | |
620 | document->Release(); | |
423adfde | 621 | return sel != "None"; |
63a65070 SL |
622 | } |
623 | ||
624 | void wxWebViewIE::DeleteSelection() | |
625 | { | |
626 | ExecCommand("Delete"); | |
627 | } | |
628 | ||
e669ddde | 629 | wxString wxWebViewIE::GetSelectedText() const |
c9355a3d SL |
630 | { |
631 | IHTMLDocument2* document = GetDocument(); | |
632 | IHTMLSelectionObject* selection; | |
633 | wxString selected; | |
634 | HRESULT hr = document->get_selection(&selection); | |
635 | if(SUCCEEDED(hr)) | |
636 | { | |
637 | IDispatch* disrange; | |
638 | hr = selection->createRange(&disrange); | |
639 | if(SUCCEEDED(hr)) | |
640 | { | |
641 | IHTMLTxtRange* range; | |
642 | hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); | |
643 | if(SUCCEEDED(hr)) | |
644 | { | |
645 | BSTR text; | |
646 | range->get_text(&text); | |
647 | selected = wxString(text); | |
648 | range->Release(); | |
649 | } | |
650 | disrange->Release(); | |
651 | } | |
652 | selection->Release(); | |
653 | } | |
654 | document->Release(); | |
655 | return selected; | |
656 | } | |
657 | ||
e669ddde | 658 | wxString wxWebViewIE::GetSelectedSource() const |
0fe8a1b6 SL |
659 | { |
660 | IHTMLDocument2* document = GetDocument(); | |
661 | IHTMLSelectionObject* selection; | |
662 | wxString selected; | |
663 | HRESULT hr = document->get_selection(&selection); | |
664 | if(SUCCEEDED(hr)) | |
665 | { | |
666 | IDispatch* disrange; | |
667 | hr = selection->createRange(&disrange); | |
668 | if(SUCCEEDED(hr)) | |
669 | { | |
670 | IHTMLTxtRange* range; | |
671 | hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); | |
672 | if(SUCCEEDED(hr)) | |
673 | { | |
674 | BSTR text; | |
675 | range->get_htmlText(&text); | |
676 | selected = wxString(text); | |
677 | range->Release(); | |
678 | } | |
679 | disrange->Release(); | |
680 | } | |
681 | selection->Release(); | |
682 | } | |
683 | document->Release(); | |
684 | return selected; | |
685 | } | |
686 | ||
41933aa5 SL |
687 | void wxWebViewIE::ClearSelection() |
688 | { | |
689 | IHTMLDocument2* document = GetDocument(); | |
690 | IHTMLSelectionObject* selection; | |
691 | wxString selected; | |
692 | HRESULT hr = document->get_selection(&selection); | |
693 | if(SUCCEEDED(hr)) | |
694 | { | |
695 | selection->empty(); | |
696 | selection->Release(); | |
697 | } | |
698 | document->Release(); | |
699 | } | |
700 | ||
e669ddde | 701 | wxString wxWebViewIE::GetPageText() const |
241b769f SL |
702 | { |
703 | IHTMLDocument2* document = GetDocument(); | |
423adfde | 704 | wxString text; |
241b769f SL |
705 | IHTMLElement* body; |
706 | HRESULT hr = document->get_body(&body); | |
707 | if(SUCCEEDED(hr)) | |
708 | { | |
423adfde | 709 | BSTR out; |
241b769f | 710 | body->get_innerText(&out); |
423adfde | 711 | text = wxString(out); |
241b769f SL |
712 | body->Release(); |
713 | } | |
714 | document->Release(); | |
423adfde | 715 | return text; |
241b769f SL |
716 | } |
717 | ||
c9ccc09c SL |
718 | void wxWebViewIE::RunScript(const wxString& javascript) |
719 | { | |
720 | IHTMLDocument2* document = GetDocument(); | |
721 | IHTMLWindow2* window; | |
722 | wxString language = "javascript"; | |
723 | HRESULT hr = document->get_parentWindow(&window); | |
724 | if(SUCCEEDED(hr)) | |
725 | { | |
726 | VARIANT level; | |
727 | VariantInit(&level); | |
728 | V_VT(&level) = VT_EMPTY; | |
c9a828e7 | 729 | window->execScript(SysAllocString(javascript.wc_str()), |
ee8bc1a8 | 730 | SysAllocString(language.wc_str()), |
c9a828e7 | 731 | &level); |
c9ccc09c SL |
732 | } |
733 | document->Release(); | |
734 | } | |
735 | ||
7d8d6163 | 736 | void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) |
29365629 | 737 | { |
e924e848 SL |
738 | wxDynamicLibrary urlMon(wxT("urlmon.dll")); |
739 | if(urlMon.HasSymbol(wxT("CoInternetGetSession"))) | |
29365629 | 740 | { |
f559d1a2 | 741 | typedef HRESULT (WINAPI *CoInternetGetSession_t)(DWORD, wxIInternetSession**, DWORD); |
e924e848 SL |
742 | wxDYNLIB_FUNCTION(CoInternetGetSession_t, CoInternetGetSession, urlMon); |
743 | ||
744 | ClassFactory* cf = new ClassFactory(handler); | |
f559d1a2 | 745 | wxIInternetSession* session; |
e924e848 SL |
746 | HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); |
747 | if(FAILED(res)) | |
748 | { | |
749 | wxFAIL_MSG("Could not retrive internet session"); | |
750 | } | |
29365629 | 751 | |
c9a828e7 VZ |
752 | HRESULT hr = session->RegisterNameSpace(cf, CLSID_FileProtocol, |
753 | handler->GetName().wc_str(), | |
754 | 0, NULL, 0); | |
e924e848 SL |
755 | if(FAILED(hr)) |
756 | { | |
757 | wxFAIL_MSG("Could not register protocol"); | |
758 | } | |
39498710 | 759 | m_factories.push_back(cf); |
e924e848 SL |
760 | } |
761 | else | |
29365629 | 762 | { |
e924e848 | 763 | wxFAIL_MSG("urlmon does not contain CoInternetGetSession"); |
29365629 SL |
764 | } |
765 | } | |
766 | ||
e669ddde | 767 | bool wxWebViewIE::CanExecCommand(wxString command) const |
4681a3ea | 768 | { |
617227c3 | 769 | IHTMLDocument2* document = GetDocument(); |
4681a3ea | 770 | VARIANT_BOOL enabled; |
7fbc727b | 771 | |
4681a3ea | 772 | document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled); |
7fbc727b | 773 | document->Release(); |
4681a3ea SL |
774 | |
775 | return (enabled == VARIANT_TRUE); | |
776 | } | |
777 | ||
778 | void wxWebViewIE::ExecCommand(wxString command) | |
779 | { | |
617227c3 SL |
780 | IHTMLDocument2* document = GetDocument(); |
781 | document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL); | |
7fbc727b | 782 | document->Release(); |
617227c3 | 783 | } |
4681a3ea | 784 | |
e669ddde | 785 | IHTMLDocument2* wxWebViewIE::GetDocument() const |
617227c3 SL |
786 | { |
787 | wxVariant variant = m_ie.GetProperty("Document"); | |
788 | IHTMLDocument2* document = (IHTMLDocument2*)variant.GetVoidPtr(); | |
4681a3ea | 789 | |
617227c3 SL |
790 | wxASSERT(document); |
791 | ||
792 | return document; | |
4681a3ea SL |
793 | } |
794 | ||
9447a0d6 SL |
795 | bool wxWebViewIE::EnableControlFeature(long flag, bool enable) |
796 | { | |
797 | #if wxUSE_DYNLIB_CLASS | |
798 | ||
799 | wxDynamicLibrary urlMon(wxT("urlmon.dll")); | |
800 | if( urlMon.IsLoaded() && | |
801 | urlMon.HasSymbol("CoInternetSetFeatureEnabled") && | |
802 | urlMon.HasSymbol("CoInternetIsFeatureEnabled")) | |
803 | { | |
804 | typedef HRESULT (WINAPI *CoInternetSetFeatureEnabled_t)(DWORD, DWORD, BOOL); | |
805 | typedef HRESULT (WINAPI *CoInternetIsFeatureEnabled_t)(DWORD, DWORD); | |
806 | ||
807 | wxDYNLIB_FUNCTION(CoInternetSetFeatureEnabled_t, CoInternetSetFeatureEnabled, urlMon); | |
808 | wxDYNLIB_FUNCTION(CoInternetIsFeatureEnabled_t, CoInternetIsFeatureEnabled, urlMon); | |
809 | ||
810 | HRESULT hr = (*pfnCoInternetIsFeatureEnabled)(flag, | |
811 | 0x2 /* SET_FEATURE_ON_PROCESS */); | |
812 | if((hr == S_OK && enable) || (hr == S_FALSE && !enable)) | |
813 | return true; | |
814 | ||
815 | hr = (*pfnCoInternetSetFeatureEnabled)(flag, | |
816 | 0x2/* SET_FEATURE_ON_PROCESS */, | |
817 | (enable ? TRUE : FALSE)); | |
818 | if ( FAILED(hr) ) | |
819 | { | |
820 | wxLogApiError(wxT("CoInternetSetFeatureEnabled"), hr); | |
821 | return false; | |
822 | } | |
823 | return true; | |
824 | } | |
825 | return false; | |
826 | #else | |
827 | wxUnusedVar(flag); | |
828 | wxUnusedVar(enable); | |
829 | return false; | |
830 | #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS | |
831 | } | |
832 | ||
61b98a2d SL |
833 | void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt) |
834 | { | |
835 | if (m_webBrowser == NULL) return; | |
836 | ||
837 | switch (evt.GetDispatchId()) | |
838 | { | |
839 | case DISPID_BEFORENAVIGATE2: | |
840 | { | |
841 | m_isBusy = true; | |
842 | ||
843 | wxString url = evt[1].GetString(); | |
844 | wxString target = evt[3].GetString(); | |
845 | ||
04fa04d8 | 846 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, |
3225a4b8 | 847 | GetId(), url, target); |
e11b9a6b SL |
848 | |
849 | //skip empty javascript events. | |
850 | if(url == "javascript:\"\"" && target.IsEmpty()) | |
851 | { | |
852 | event.Veto(); | |
853 | } | |
854 | else | |
855 | { | |
856 | event.SetEventObject(this); | |
857 | HandleWindowEvent(event); | |
858 | } | |
61b98a2d | 859 | |
3225a4b8 | 860 | if (!event.IsAllowed()) |
61b98a2d SL |
861 | { |
862 | wxActiveXEventNativeMSW* nativeParams = | |
863 | evt.GetNativeParameters(); | |
864 | *V_BOOLREF(&nativeParams->pDispParams->rgvarg[0]) = VARIANT_TRUE; | |
865 | } | |
866 | ||
867 | // at this point, either the navigation event has been cancelled | |
868 | // and we're not busy, either it was accepted and IWebBrowser2's | |
869 | // Busy property will be true; so we don't need our override | |
870 | // flag anymore. | |
871 | m_isBusy = false; | |
872 | ||
873 | break; | |
874 | } | |
875 | ||
876 | case DISPID_NAVIGATECOMPLETE2: | |
877 | { | |
878 | wxString url = evt[1].GetString(); | |
879 | // TODO: set target parameter if possible | |
880 | wxString target = wxEmptyString; | |
04fa04d8 | 881 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, |
3225a4b8 | 882 | GetId(), url, target); |
61b98a2d SL |
883 | event.SetEventObject(this); |
884 | HandleWindowEvent(event); | |
885 | break; | |
886 | } | |
887 | ||
888 | case DISPID_PROGRESSCHANGE: | |
889 | { | |
890 | // download progress | |
891 | break; | |
892 | } | |
893 | ||
894 | case DISPID_DOCUMENTCOMPLETE: | |
895 | { | |
3ee442ff SL |
896 | //Only send a complete even if we are actually finished, this brings |
897 | //the event in to line with webkit | |
898 | READYSTATE rs; | |
899 | m_webBrowser->get_ReadyState( &rs ); | |
900 | if(rs != READYSTATE_COMPLETE) | |
901 | break; | |
902 | ||
61b98a2d | 903 | wxString url = evt[1].GetString(); |
113e0a92 SL |
904 | |
905 | //As we are complete we also add to the history list, but not if the | |
906 | //page is not the main page, ie it is a subframe | |
60eabdbe | 907 | //We also have to check if we are loading a file:// url, if so we |
f239a200 SL |
908 | //need to change the comparison as ie passes back a different style |
909 | //of url | |
60eabdbe VZ |
910 | if(m_historyEnabled && !m_historyLoadingFromList && |
911 | (url == GetCurrentURL() || | |
912 | (GetCurrentURL().substr(0, 4) == "file" && | |
f239a200 | 913 | wxFileSystem::URLToFileName(GetCurrentURL()).GetFullPath() == url))) |
74af0b13 SL |
914 | { |
915 | //If we are not at the end of the list, then erase everything | |
916 | //between us and the end before adding the new page | |
22ca10fa | 917 | if(m_historyPosition != static_cast<int>(m_historyList.size()) - 1) |
74af0b13 SL |
918 | { |
919 | m_historyList.erase(m_historyList.begin() + m_historyPosition + 1, | |
920 | m_historyList.end()); | |
921 | } | |
c13d6ac1 | 922 | wxSharedPtr<wxWebViewHistoryItem> item(new wxWebViewHistoryItem(url, GetCurrentTitle())); |
74af0b13 SL |
923 | m_historyList.push_back(item); |
924 | m_historyPosition++; | |
925 | } | |
926 | //Reset as we are done now | |
927 | m_historyLoadingFromList = false; | |
61b98a2d SL |
928 | // TODO: set target parameter if possible |
929 | wxString target = wxEmptyString; | |
04fa04d8 | 930 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_LOADED, GetId(), |
3225a4b8 | 931 | url, target); |
61b98a2d SL |
932 | event.SetEventObject(this); |
933 | HandleWindowEvent(event); | |
934 | break; | |
935 | } | |
936 | ||
937 | case DISPID_STATUSTEXTCHANGE: | |
938 | { | |
939 | break; | |
940 | } | |
941 | ||
942 | case DISPID_TITLECHANGE: | |
943 | { | |
153530af SL |
944 | wxString title = evt[0].GetString(); |
945 | ||
04fa04d8 | 946 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, |
3225a4b8 | 947 | GetId(), GetCurrentURL(), ""); |
153530af SL |
948 | event.SetString(title); |
949 | event.SetEventObject(this); | |
950 | HandleWindowEvent(event); | |
61b98a2d SL |
951 | break; |
952 | } | |
953 | ||
954 | case DISPID_NAVIGATEERROR: | |
955 | { | |
04fa04d8 | 956 | wxWebViewNavigationError errorType = wxWEB_NAV_ERR_OTHER; |
61b98a2d SL |
957 | wxString errorCode = "?"; |
958 | switch (evt[3].GetLong()) | |
959 | { | |
960 | case INET_E_INVALID_URL: // (0x800C0002L or -2146697214) | |
961 | errorCode = "INET_E_INVALID_URL"; | |
962 | errorType = wxWEB_NAV_ERR_REQUEST; | |
963 | break; | |
964 | case INET_E_NO_SESSION: // (0x800C0003L or -2146697213) | |
965 | errorCode = "INET_E_NO_SESSION"; | |
966 | errorType = wxWEB_NAV_ERR_CONNECTION; | |
967 | break; | |
968 | case INET_E_CANNOT_CONNECT: // (0x800C0004L or -2146697212) | |
969 | errorCode = "INET_E_CANNOT_CONNECT"; | |
970 | errorType = wxWEB_NAV_ERR_CONNECTION; | |
971 | break; | |
972 | case INET_E_RESOURCE_NOT_FOUND: // (0x800C0005L or -2146697211) | |
973 | errorCode = "INET_E_RESOURCE_NOT_FOUND"; | |
974 | errorType = wxWEB_NAV_ERR_NOT_FOUND; | |
975 | break; | |
976 | case INET_E_OBJECT_NOT_FOUND: // (0x800C0006L or -2146697210) | |
977 | errorCode = "INET_E_OBJECT_NOT_FOUND"; | |
978 | errorType = wxWEB_NAV_ERR_NOT_FOUND; | |
979 | break; | |
980 | case INET_E_DATA_NOT_AVAILABLE: // (0x800C0007L or -2146697209) | |
981 | errorCode = "INET_E_DATA_NOT_AVAILABLE"; | |
982 | errorType = wxWEB_NAV_ERR_NOT_FOUND; | |
983 | break; | |
984 | case INET_E_DOWNLOAD_FAILURE: // (0x800C0008L or -2146697208) | |
985 | errorCode = "INET_E_DOWNLOAD_FAILURE"; | |
986 | errorType = wxWEB_NAV_ERR_CONNECTION; | |
987 | break; | |
988 | case INET_E_AUTHENTICATION_REQUIRED: // (0x800C0009L or -2146697207) | |
989 | errorCode = "INET_E_AUTHENTICATION_REQUIRED"; | |
990 | errorType = wxWEB_NAV_ERR_AUTH; | |
991 | break; | |
992 | case INET_E_NO_VALID_MEDIA: // (0x800C000AL or -2146697206) | |
993 | errorCode = "INET_E_NO_VALID_MEDIA"; | |
994 | errorType = wxWEB_NAV_ERR_REQUEST; | |
995 | break; | |
996 | case INET_E_CONNECTION_TIMEOUT: // (0x800C000BL or -2146697205) | |
997 | errorCode = "INET_E_CONNECTION_TIMEOUT"; | |
998 | errorType = wxWEB_NAV_ERR_CONNECTION; | |
999 | break; | |
1000 | case INET_E_INVALID_REQUEST: // (0x800C000CL or -2146697204) | |
1001 | errorCode = "INET_E_INVALID_REQUEST"; | |
1002 | errorType = wxWEB_NAV_ERR_REQUEST; | |
1003 | break; | |
1004 | case INET_E_UNKNOWN_PROTOCOL: // (0x800C000DL or -2146697203) | |
1005 | errorCode = "INET_E_UNKNOWN_PROTOCOL"; | |
1006 | errorType = wxWEB_NAV_ERR_REQUEST; | |
1007 | break; | |
1008 | case INET_E_SECURITY_PROBLEM: // (0x800C000EL or -2146697202) | |
1009 | errorCode = "INET_E_SECURITY_PROBLEM"; | |
1010 | errorType = wxWEB_NAV_ERR_SECURITY; | |
1011 | break; | |
1012 | case INET_E_CANNOT_LOAD_DATA: // (0x800C000FL or -2146697201) | |
1013 | errorCode = "INET_E_CANNOT_LOAD_DATA"; | |
1014 | errorType = wxWEB_NAV_ERR_OTHER; | |
1015 | break; | |
1016 | case INET_E_CANNOT_INSTANTIATE_OBJECT: | |
1017 | // CoCreateInstance will return an error code if this happens, | |
1018 | // we'll handle this above. | |
1019 | return; | |
1020 | break; | |
1021 | case INET_E_REDIRECT_FAILED: // (0x800C0014L or -2146697196) | |
1022 | errorCode = "INET_E_REDIRECT_FAILED"; | |
1023 | errorType = wxWEB_NAV_ERR_OTHER; | |
1024 | break; | |
1025 | case INET_E_REDIRECT_TO_DIR: // (0x800C0015L or -2146697195) | |
1026 | errorCode = "INET_E_REDIRECT_TO_DIR"; | |
1027 | errorType = wxWEB_NAV_ERR_REQUEST; | |
1028 | break; | |
1029 | case INET_E_CANNOT_LOCK_REQUEST: // (0x800C0016L or -2146697194) | |
1030 | errorCode = "INET_E_CANNOT_LOCK_REQUEST"; | |
1031 | errorType = wxWEB_NAV_ERR_OTHER; | |
1032 | break; | |
1033 | case INET_E_USE_EXTEND_BINDING: // (0x800C0017L or -2146697193) | |
1034 | errorCode = "INET_E_USE_EXTEND_BINDING"; | |
1035 | errorType = wxWEB_NAV_ERR_OTHER; | |
1036 | break; | |
1037 | case INET_E_TERMINATED_BIND: // (0x800C0018L or -2146697192) | |
1038 | errorCode = "INET_E_TERMINATED_BIND"; | |
1039 | errorType = wxWEB_NAV_ERR_OTHER; | |
1040 | break; | |
1041 | case INET_E_INVALID_CERTIFICATE: // (0x800C0019L or -2146697191) | |
1042 | errorCode = "INET_E_INVALID_CERTIFICATE"; | |
1043 | errorType = wxWEB_NAV_ERR_CERTIFICATE; | |
1044 | break; | |
1045 | case INET_E_CODE_DOWNLOAD_DECLINED: // (0x800C0100L or -2146696960) | |
1046 | errorCode = "INET_E_CODE_DOWNLOAD_DECLINED"; | |
1047 | errorType = wxWEB_NAV_ERR_USER_CANCELLED; | |
1048 | break; | |
1049 | case INET_E_RESULT_DISPATCHED: // (0x800C0200L or -2146696704) | |
1050 | // cancel request cancelled... | |
1051 | errorCode = "INET_E_RESULT_DISPATCHED"; | |
1052 | errorType = wxWEB_NAV_ERR_OTHER; | |
1053 | break; | |
1054 | case INET_E_CANNOT_REPLACE_SFP_FILE: // (0x800C0300L or -2146696448) | |
1055 | errorCode = "INET_E_CANNOT_REPLACE_SFP_FILE"; | |
1056 | errorType = wxWEB_NAV_ERR_SECURITY; | |
1057 | break; | |
1058 | case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY: | |
1059 | errorCode = "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY"; | |
1060 | errorType = wxWEB_NAV_ERR_SECURITY; | |
1061 | break; | |
1062 | case INET_E_CODE_INSTALL_SUPPRESSED: | |
1063 | errorCode = "INET_E_CODE_INSTALL_SUPPRESSED"; | |
1064 | errorType = wxWEB_NAV_ERR_SECURITY; | |
1065 | break; | |
1066 | } | |
1067 | ||
1068 | wxString url = evt[1].GetString(); | |
1069 | wxString target = evt[2].GetString(); | |
04fa04d8 | 1070 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_ERROR, GetId(), |
3225a4b8 | 1071 | url, target); |
61b98a2d SL |
1072 | event.SetEventObject(this); |
1073 | event.SetInt(errorType); | |
1074 | event.SetString(errorCode); | |
1075 | HandleWindowEvent(event); | |
1076 | break; | |
1077 | } | |
853b6cd0 | 1078 | case DISPID_NEWWINDOW3: |
61b98a2d | 1079 | { |
853b6cd0 SL |
1080 | wxString url = evt[4].GetString(); |
1081 | ||
04fa04d8 | 1082 | wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, |
3225a4b8 | 1083 | GetId(), url, wxEmptyString); |
853b6cd0 SL |
1084 | event.SetEventObject(this); |
1085 | HandleWindowEvent(event); | |
1086 | ||
d676fb21 SL |
1087 | //We always cancel this event otherwise an Internet Exporer window |
1088 | //is opened for the url | |
1089 | wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters(); | |
1090 | *V_BOOLREF(&nativeParams->pDispParams->rgvarg[3]) = VARIANT_TRUE; | |
be19c556 SL |
1091 | break; |
1092 | } | |
61b98a2d SL |
1093 | } |
1094 | ||
1095 | evt.Skip(); | |
1096 | } | |
1097 | ||
7d8d6163 | 1098 | VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler) |
7d3f6b4d | 1099 | { |
7d3f6b4d | 1100 | m_file = NULL; |
29365629 | 1101 | m_handler = handler; |
7d3f6b4d SL |
1102 | } |
1103 | ||
9f194b9d SL |
1104 | BEGIN_IID_TABLE(VirtualProtocol) |
1105 | ADD_IID(Unknown) | |
1106 | ADD_RAW_IID(wxIID_IInternetProtocolRoot) | |
1107 | ADD_RAW_IID(wxIID_IInternetProtocol) | |
1108 | END_IID_TABLE; | |
7d3f6b4d | 1109 | |
9f194b9d | 1110 | IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol) |
7d3f6b4d | 1111 | |
f559d1a2 VZ |
1112 | HRESULT VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink, |
1113 | wxIInternetBindInfo *pOIBindInfo, DWORD grfPI, | |
0995b9dc | 1114 | HANDLE_PTR dwReserved) |
7d3f6b4d | 1115 | { |
0995b9dc SL |
1116 | wxUnusedVar(szUrl); |
1117 | wxUnusedVar(pOIBindInfo); | |
1118 | wxUnusedVar(grfPI); | |
1119 | wxUnusedVar(dwReserved); | |
7d3f6b4d | 1120 | m_protocolSink = pOIProtSink; |
60eabdbe | 1121 | |
29365629 SL |
1122 | //We get the file itself from the protocol handler |
1123 | m_file = m_handler->GetFile(szUrl); | |
1124 | ||
7d3f6b4d SL |
1125 | |
1126 | if(!m_file) | |
1127 | return INET_E_RESOURCE_NOT_FOUND; | |
1128 | ||
1129 | //We return the stream length for current and total size as we can always | |
1130 | //read the whole file from the stream | |
666f73c4 | 1131 | wxFileOffset length = m_file->GetStream()->GetLength(); |
f559d1a2 VZ |
1132 | m_protocolSink->ReportData(wxBSCF_FIRSTDATANOTIFICATION | |
1133 | wxBSCF_DATAFULLYAVAILABLE | | |
1134 | wxBSCF_LASTDATANOTIFICATION, | |
666f73c4 | 1135 | length, length); |
60eabdbe | 1136 | return S_OK; |
7d3f6b4d SL |
1137 | } |
1138 | ||
1139 | HRESULT VirtualProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead) | |
1140 | { | |
1141 | //If the file is null we return false to indicte it is finished | |
60eabdbe | 1142 | if(!m_file) |
7d3f6b4d SL |
1143 | return S_FALSE; |
1144 | ||
1145 | wxStreamError err = m_file->GetStream()->Read(pv, cb).GetLastError(); | |
1146 | *pcbRead = m_file->GetStream()->LastRead(); | |
1147 | ||
1148 | if(err == wxSTREAM_NO_ERROR) | |
1149 | { | |
1150 | if(*pcbRead < cb) | |
1151 | { | |
1152 | wxDELETE(m_file); | |
1153 | m_protocolSink->ReportResult(S_OK, 0, NULL); | |
1154 | } | |
1155 | //As we are not eof there is more data | |
1156 | return S_OK; | |
1157 | } | |
1158 | else if(err == wxSTREAM_EOF) | |
1159 | { | |
1160 | wxDELETE(m_file); | |
1161 | m_protocolSink->ReportResult(S_OK, 0, NULL); | |
1162 | //We are eof and so finished | |
1163 | return S_OK; | |
1164 | } | |
1165 | else if(err == wxSTREAM_READ_ERROR) | |
1166 | { | |
1167 | wxDELETE(m_file); | |
1168 | return INET_E_DOWNLOAD_FAILURE; | |
1169 | } | |
0995b9dc SL |
1170 | else |
1171 | { | |
1172 | //Dummy return to surpress a compiler warning | |
1173 | wxFAIL; | |
1174 | return INET_E_DOWNLOAD_FAILURE; | |
1175 | } | |
7d3f6b4d SL |
1176 | } |
1177 | ||
9f194b9d SL |
1178 | BEGIN_IID_TABLE(ClassFactory) |
1179 | ADD_IID(Unknown) | |
1180 | ADD_IID(ClassFactory) | |
1181 | END_IID_TABLE; | |
1182 | ||
1183 | IMPLEMENT_IUNKNOWN_METHODS(ClassFactory) | |
1184 | ||
7d3f6b4d SL |
1185 | HRESULT ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, |
1186 | void ** ppvObject) | |
1187 | { | |
60eabdbe | 1188 | if (pUnkOuter) |
7d3f6b4d | 1189 | return CLASS_E_NOAGGREGATION; |
29365629 | 1190 | VirtualProtocol* vp = new VirtualProtocol(m_handler); |
7d3f6b4d SL |
1191 | vp->AddRef(); |
1192 | HRESULT hr = vp->QueryInterface(riid, ppvObject); | |
1193 | vp->Release(); | |
1194 | return hr; | |
1195 | ||
60eabdbe | 1196 | } |
7d3f6b4d SL |
1197 | |
1198 | STDMETHODIMP ClassFactory::LockServer(BOOL fLock) | |
1199 | { | |
0995b9dc SL |
1200 | wxUnusedVar(fLock); |
1201 | return S_OK; | |
7d3f6b4d SL |
1202 | } |
1203 | ||
accc94d5 SL |
1204 | wxIEContainer::wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk, |
1205 | DocHostUIHandler* uiHandler) : | |
1206 | wxActiveXContainer(parent,iid,pUnk) | |
1207 | { | |
1208 | m_uiHandler = uiHandler; | |
1209 | } | |
1210 | ||
1211 | wxIEContainer::~wxIEContainer() | |
1212 | { | |
1213 | } | |
1214 | ||
1215 | bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface, | |
1216 | const char *&desc) | |
1217 | { | |
1218 | if (m_uiHandler && IsEqualIID(iid, wxIID_IDocHostUIHandler)) | |
1219 | { | |
1220 | *_interface = (IUnknown *) (wxIDocHostUIHandler *) m_uiHandler; | |
1221 | desc = "IDocHostUIHandler"; | |
1222 | return true; | |
1223 | } | |
1224 | return false; | |
1225 | } | |
1226 | ||
1227 | HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt, | |
1228 | IUnknown *pcmdtReserved, | |
1229 | IDispatch *pdispReserved) | |
1230 | { | |
1231 | wxUnusedVar(dwID); | |
1232 | wxUnusedVar(ppt); | |
1233 | wxUnusedVar(pcmdtReserved); | |
1234 | wxUnusedVar(pdispReserved); | |
1235 | return E_NOTIMPL; | |
1236 | } | |
1237 | ||
1238 | HRESULT DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo) | |
1239 | { | |
1240 | //don't show 3d border and ebales themes. | |
1241 | pInfo->dwFlags = pInfo->dwFlags | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_THEME; | |
1242 | return S_OK; | |
1243 | } | |
1244 | ||
1245 | HRESULT DocHostUIHandler::ShowUI(DWORD dwID, | |
1246 | IOleInPlaceActiveObject *pActiveObject, | |
1247 | IOleCommandTarget *pCommandTarget, | |
1248 | IOleInPlaceFrame *pFrame, | |
1249 | IOleInPlaceUIWindow *pDoc) | |
1250 | { | |
1251 | wxUnusedVar(dwID); | |
1252 | wxUnusedVar(pActiveObject); | |
1253 | wxUnusedVar(pCommandTarget); | |
1254 | wxUnusedVar(pFrame); | |
1255 | wxUnusedVar(pDoc); | |
1256 | return S_FALSE; | |
1257 | } | |
1258 | ||
1259 | HRESULT DocHostUIHandler::HideUI(void) | |
1260 | { | |
1261 | return E_NOTIMPL; | |
1262 | } | |
1263 | ||
1264 | HRESULT DocHostUIHandler::UpdateUI(void) | |
1265 | { | |
1266 | return E_NOTIMPL; | |
1267 | } | |
1268 | ||
1269 | HRESULT DocHostUIHandler::EnableModeless(BOOL fEnable) | |
1270 | { | |
1271 | wxUnusedVar(fEnable); | |
1272 | return E_NOTIMPL; | |
1273 | } | |
1274 | ||
1275 | HRESULT DocHostUIHandler::OnDocWindowActivate(BOOL fActivate) | |
1276 | { | |
1277 | wxUnusedVar(fActivate); | |
1278 | return E_NOTIMPL; | |
1279 | } | |
1280 | ||
1281 | HRESULT DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate) | |
1282 | { | |
1283 | wxUnusedVar(fActivate); | |
1284 | return E_NOTIMPL; | |
1285 | } | |
1286 | ||
1287 | HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder, | |
1288 | IOleInPlaceUIWindow *pUIWindow, | |
1289 | BOOL fFrameWindow) | |
1290 | { | |
1291 | wxUnusedVar(prcBorder); | |
1292 | wxUnusedVar(pUIWindow); | |
1293 | wxUnusedVar(fFrameWindow); | |
1294 | return E_NOTIMPL; | |
1295 | } | |
1296 | ||
1297 | HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg, | |
1298 | const GUID *pguidCmdGroup, | |
1299 | DWORD nCmdID) | |
1300 | { | |
1301 | if(lpMsg && lpMsg->message == WM_KEYDOWN) | |
1302 | { | |
1303 | //control is down? | |
1304 | if((GetKeyState(VK_CONTROL) & 0x8000 )) | |
1305 | { | |
1306 | //skip CTRL-N, CTRL-F and CTRL-P | |
1307 | if(lpMsg->wParam == 'N' || lpMsg->wParam == 'P' || lpMsg->wParam == 'F') | |
1308 | { | |
1309 | return S_OK; | |
1310 | } | |
1311 | } | |
1312 | //skip F5 | |
1313 | if(lpMsg->wParam == VK_F5) | |
1314 | { | |
1315 | return S_OK; | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | wxUnusedVar(pguidCmdGroup); | |
1320 | wxUnusedVar(nCmdID); | |
1321 | return E_NOTIMPL; | |
1322 | } | |
1323 | ||
1324 | HRESULT DocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw) | |
1325 | { | |
1326 | wxUnusedVar(pchKey); | |
1327 | wxUnusedVar(dw); | |
1328 | return E_NOTIMPL; | |
1329 | } | |
1330 | ||
1331 | HRESULT DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget, | |
1332 | IDropTarget **ppDropTarget) | |
1333 | { | |
1334 | wxUnusedVar(pDropTarget); | |
1335 | wxUnusedVar(ppDropTarget); | |
1336 | return E_NOTIMPL; | |
1337 | } | |
1338 | ||
1339 | HRESULT DocHostUIHandler::GetExternal(IDispatch **ppDispatch) | |
1340 | { | |
1341 | wxUnusedVar(ppDispatch); | |
1342 | return E_NOTIMPL; | |
1343 | } | |
1344 | ||
1345 | HRESULT DocHostUIHandler::TranslateUrl(DWORD dwTranslate, | |
1346 | OLECHAR *pchURLIn, | |
1347 | OLECHAR **ppchURLOut) | |
1348 | { | |
1349 | wxUnusedVar(dwTranslate); | |
1350 | wxUnusedVar(pchURLIn); | |
1351 | wxUnusedVar(ppchURLOut); | |
1352 | return E_NOTIMPL; | |
1353 | } | |
1354 | ||
1355 | HRESULT DocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet) | |
1356 | { | |
1357 | wxUnusedVar(pDO); | |
1358 | wxUnusedVar(ppDORet); | |
1359 | return E_NOTIMPL; | |
1360 | } | |
1361 | ||
1362 | BEGIN_IID_TABLE(DocHostUIHandler) | |
1363 | ADD_IID(Unknown) | |
1364 | ADD_RAW_IID(wxIID_IDocHostUIHandler) | |
1365 | END_IID_TABLE; | |
1366 | ||
1367 | IMPLEMENT_IUNKNOWN_METHODS(DocHostUIHandler) | |
1368 | ||
9d2f31db | 1369 | #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE |