Only send a document complete event when the page is completely loaded, as opposed...
[wxWidgets.git] / src / msw / webview_ie.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/webview_ie.cpp
3 // Purpose: wxMSW wxWebViewIE class implementation for web view component
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
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
17 #include "wx/msw/webview_ie.h"
18
19 #if wxUSE_WEBVIEW_IE
20
21 #include <olectl.h>
22 #include <oleidl.h>
23 #include <exdispid.h>
24 #include <exdisp.h>
25 #include <mshtml.h>
26
27 // Various definitions are missing from mingw
28 #ifdef __MINGW32__
29 typedef enum CommandStateChangeConstants {
30 CSC_UPDATECOMMANDS = (int) 0xFFFFFFFF,
31 CSC_NAVIGATEFORWARD = 0x1,
32 CSC_NAVIGATEBACK = 0x2
33 } CommandStateChangeConstants;
34
35 #define DISPID_COMMANDSTATECHANGE 105
36 #define DISPID_NAVIGATECOMPLETE2 252
37 #define DISPID_NAVIGATEERROR 271
38 #define DISPID_NEWWINDOW3 273
39 #define OLECMDID_OPTICAL_ZOOM 63
40 #define INET_E_ERROR_FIRST 0x800C0002L
41 #define INET_E_INVALID_URL 0x800C0002L
42 #define INET_E_NO_SESSION 0x800C0003L
43 #define INET_E_CANNOT_CONNECT 0x800C0004L
44 #define INET_E_RESOURCE_NOT_FOUND 0x800C0005L
45 #define INET_E_OBJECT_NOT_FOUND 0x800C0006L
46 #define INET_E_DATA_NOT_AVAILABLE 0x800C0007L
47 #define INET_E_DOWNLOAD_FAILURE 0x800C0008L
48 #define INET_E_AUTHENTICATION_REQUIRED 0x800C0009L
49 #define INET_E_NO_VALID_MEDIA 0x800C000AL
50 #define INET_E_CONNECTION_TIMEOUT 0x800C000BL
51 #define INET_E_INVALID_REQUEST 0x800C000CL
52 #define INET_E_UNKNOWN_PROTOCOL 0x800C000DL
53 #define INET_E_SECURITY_PROBLEM 0x800C000EL
54 #define INET_E_CANNOT_LOAD_DATA 0x800C000FL
55 #define INET_E_CANNOT_INSTANTIATE_OBJECT 0x800C0010L
56 #define INET_E_QUERYOPTION_UNKNOWN 0x800C0013L
57 #define INET_E_REDIRECT_FAILED 0x800C0014L
58 #define INET_E_REDIRECT_TO_DIR 0x800C0015L
59 #define INET_E_CANNOT_LOCK_REQUEST 0x800C0016L
60 #define INET_E_USE_EXTEND_BINDING 0x800C0017L
61 #define INET_E_TERMINATED_BIND 0x800C0018L
62 #define INET_E_INVALID_CERTIFICATE 0x800C0019L
63 #define INET_E_CODE_DOWNLOAD_DECLINED 0x800C0100L
64 #define INET_E_RESULT_DISPATCHED 0x800C0200L
65 #define INET_E_CANNOT_REPLACE_SFP_FILE 0x800C0300L
66 #define INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY 0x800C0500L
67 #define INET_E_CODE_INSTALL_SUPPRESSED 0x800C0400L
68
69 #define REFRESH_NORMAL 0
70 #define REFRESH_COMPLETELY 3
71 #endif
72
73 BEGIN_EVENT_TABLE(wxWebViewIE, wxControl)
74 EVT_ACTIVEX(wxID_ANY, wxWebViewIE::onActiveXEvent)
75 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg)
76 END_EVENT_TABLE()
77
78 bool wxWebViewIE::Create(wxWindow* parent,
79 wxWindowID id,
80 const wxString& url,
81 const wxPoint& pos,
82 const wxSize& size,
83 long style,
84 const wxString& name)
85 {
86 if (!wxControl::Create(parent, id, pos, size, style,
87 wxDefaultValidator, name))
88 {
89 return false;
90 }
91
92 m_webBrowser = NULL;
93 m_canNavigateBack = false;
94 m_canNavigateForward = false;
95 m_isBusy = false;
96
97 if (::CoCreateInstance(CLSID_WebBrowser, NULL,
98 CLSCTX_INPROC_SERVER, // CLSCTX_INPROC,
99 IID_IWebBrowser2 , (void**)&m_webBrowser) != 0)
100 {
101 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
102 return false;
103 }
104
105 m_ie.SetDispatchPtr(m_webBrowser); // wxAutomationObject will release itself
106
107 m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE);
108 m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
109 //m_webBrowser->put_Silent(VARIANT_FALSE);
110
111 m_container = new wxActiveXContainer(this, IID_IWebBrowser2, m_webBrowser);
112
113 SetBackgroundStyle(wxBG_STYLE_PAINT);
114 SetDoubleBuffered(true);
115 LoadUrl(url);
116 return true;
117 }
118
119
120 void wxWebViewIE::LoadUrl(const wxString& url)
121 {
122 wxVariant out = m_ie.CallMethod("Navigate", (BSTR) url.wc_str(),
123 NULL, NULL, NULL, NULL);
124
125 // FIXME: why is out value null??
126 //(HRESULT)(out.GetLong()) == S_OK;
127 }
128
129 void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
130 {
131 LoadUrl("about:blank");
132
133 // Let the wx events generated for navigation events be processed, so
134 // that the underlying IE component completes its Document object.
135 // FIXME: calling wxYield is not elegant nor very reliable probably
136 wxYield();
137
138 wxVariant documentVariant = m_ie.GetProperty("Document");
139 void* documentPtr = documentVariant.GetVoidPtr();
140
141 wxASSERT (documentPtr != NULL);
142
143 // TODO: consider the "baseUrl" parameter if possible
144 // TODO: consider encoding
145 BSTR bstr = SysAllocString(html.wc_str());
146
147 // Creates a new one-dimensional array
148 SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
149 if (psaStrings != NULL)
150 {
151 VARIANT *param;
152 HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)&param);
153 param->vt = VT_BSTR;
154 param->bstrVal = bstr;
155
156 hr = SafeArrayUnaccessData(psaStrings);
157
158 IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
159 document->write(psaStrings);
160
161 // SafeArrayDestroy calls SysFreeString for each BSTR
162 SafeArrayDestroy(psaStrings);
163 }
164 else
165 {
166 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
167 }
168
169 }
170
171 wxString wxWebViewIE::GetPageSource()
172 {
173 wxVariant documentVariant = m_ie.GetProperty("Document");
174 void* documentPtr = documentVariant.GetVoidPtr();
175
176 if (documentPtr == NULL)
177 {
178 return wxEmptyString;
179 }
180
181 IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
182
183 IHTMLElement *bodyTag = NULL;
184 IHTMLElement *htmlTag = NULL;
185 document->get_body(&bodyTag);
186 wxASSERT(bodyTag != NULL);
187
188 document->Release();
189 bodyTag->get_parentElement(&htmlTag);
190 wxASSERT(htmlTag != NULL);
191
192 BSTR bstr;
193 htmlTag->get_outerHTML(&bstr);
194
195 bodyTag->Release();
196 htmlTag->Release();
197
198 //wxMessageBox(wxString(bstr));
199
200 // TODO: check encoding
201 return wxString(bstr);
202 }
203
204 // FIXME? retrieve OLECMDID_GETZOOMRANGE instead of hardcoding range 0-4
205 wxWebViewZoom wxWebViewIE::GetZoom()
206 {
207 const int zoom = GetIETextZoom();
208
209 switch (zoom)
210 {
211 case 0:
212 return wxWEB_VIEW_ZOOM_TINY;
213 break;
214 case 1:
215 return wxWEB_VIEW_ZOOM_SMALL;
216 break;
217 case 2:
218 return wxWEB_VIEW_ZOOM_MEDIUM;
219 break;
220 case 3:
221 return wxWEB_VIEW_ZOOM_LARGE;
222 break;
223 case 4:
224 return wxWEB_VIEW_ZOOM_LARGEST;
225 break;
226 default:
227 wxASSERT(false);
228 return wxWEB_VIEW_ZOOM_MEDIUM;
229 }
230 }
231 void wxWebViewIE::SetZoom(wxWebViewZoom zoom)
232 {
233 // I know I could cast from enum to int since wxWebViewZoom happens to
234 // match with IE's zoom levels, but I don't like doing that, what if enum
235 // values change...
236 switch (zoom)
237 {
238 case wxWEB_VIEW_ZOOM_TINY:
239 SetIETextZoom(0);
240 break;
241 case wxWEB_VIEW_ZOOM_SMALL:
242 SetIETextZoom(1);
243 break;
244 case wxWEB_VIEW_ZOOM_MEDIUM:
245 SetIETextZoom(2);
246 break;
247 case wxWEB_VIEW_ZOOM_LARGE:
248 SetIETextZoom(3);
249 break;
250 case wxWEB_VIEW_ZOOM_LARGEST:
251 SetIETextZoom(4);
252 break;
253 default:
254 wxASSERT(false);
255 }
256 }
257
258 void wxWebViewIE::SetIETextZoom(int level)
259 {
260 VARIANT zoomVariant;
261 VariantInit (&zoomVariant);
262 V_VT(&zoomVariant) = VT_I4;
263 V_I4(&zoomVariant) = level;
264
265 HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
266 OLECMDEXECOPT_DONTPROMPTUSER,
267 &zoomVariant, NULL);
268 wxASSERT (result == S_OK);
269
270 VariantClear (&zoomVariant);
271 }
272
273 int wxWebViewIE::GetIETextZoom()
274 {
275 VARIANT zoomVariant;
276 VariantInit (&zoomVariant);
277 V_VT(&zoomVariant) = VT_I4;
278 V_I4(&zoomVariant) = 4;
279
280 HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
281 OLECMDEXECOPT_DONTPROMPTUSER,
282 NULL, &zoomVariant);
283 wxASSERT (result == S_OK);
284
285 int zoom = V_I4(&zoomVariant);
286 // wxMessageBox(wxString::Format("Zoom : %i", zoom));
287 VariantClear (&zoomVariant);
288
289 return zoom;
290 }
291
292 void wxWebViewIE::SetIEOpticalZoom(float zoom)
293 {
294 // TODO: add support for optical zoom (IE7+ only)
295
296 // TODO: get range from OLECMDID_OPTICAL_GETZOOMRANGE instead of hardcoding?
297 wxASSERT(zoom >= 10.0f);
298 wxASSERT(zoom <= 1000.0f);
299
300 VARIANT zoomVariant;
301 VariantInit (&zoomVariant);
302 V_VT(&zoomVariant) = VT_I4;
303 V_I4(&zoomVariant) = (zoom * 100.0f);
304
305 HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
306 OLECMDEXECOPT_DODEFAULT,
307 &zoomVariant,
308 NULL);
309 wxASSERT (result == S_OK);
310 }
311
312 float wxWebViewIE::GetIEOpticalZoom()
313 {
314 // TODO: add support for optical zoom (IE7+ only)
315
316 VARIANT zoomVariant;
317 VariantInit (&zoomVariant);
318 V_VT(&zoomVariant) = VT_I4;
319 V_I4(&zoomVariant) = -1;
320
321 HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
322 OLECMDEXECOPT_DODEFAULT, NULL,
323 &zoomVariant);
324 wxASSERT (result == S_OK);
325
326 const int zoom = V_I4(&zoomVariant);
327 VariantClear (&zoomVariant);
328
329 return zoom / 100.0f;
330 }
331
332 void wxWebViewIE::SetZoomType(wxWebViewZoomType)
333 {
334 // TODO: add support for optical zoom (IE7+ only)
335 wxASSERT(false);
336 }
337
338 wxWebViewZoomType wxWebViewIE::GetZoomType() const
339 {
340 // TODO: add support for optical zoom (IE7+ only)
341 return wxWEB_VIEW_ZOOM_TYPE_TEXT;
342 }
343
344 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType) const
345 {
346 // both are supported
347 // TODO: IE6 only supports text zoom, check if it's IE6 first
348 return true;
349 }
350
351 void wxWebViewIE::Print()
352 {
353 m_webBrowser->ExecWB(OLECMDID_PRINTPREVIEW,
354 OLECMDEXECOPT_DODEFAULT, NULL, NULL);
355 }
356
357 void wxWebViewIE::GoBack()
358 {
359 wxVariant out = m_ie.CallMethod("GoBack");
360
361 // FIXME: why is out value null??
362 //return (HRESULT)(out.GetLong()) == S_OK;
363 }
364
365 void wxWebViewIE::GoForward()
366 {
367 wxVariant out = m_ie.CallMethod("GoForward");
368
369 // FIXME: why is out value null??
370 //return (HRESULT)(out.GetLong()) == S_OK;
371 }
372
373 void wxWebViewIE::Stop()
374 {
375 wxVariant out = m_ie.CallMethod("Stop");
376
377 // FIXME: why is out value null??
378 //return (HRESULT)(out.GetLong()) == S_OK;
379 }
380
381
382 void wxWebViewIE::Reload(wxWebViewReloadFlags flags)
383 {
384 VARIANTARG level;
385 VariantInit(&level);
386 V_VT(&level) = VT_I2;
387
388 switch(flags)
389 {
390 case wxWEB_VIEW_RELOAD_DEFAULT:
391 V_I2(&level) = REFRESH_NORMAL;
392 break;
393 case wxWEB_VIEW_RELOAD_NO_CACHE:
394 V_I2(&level) = REFRESH_COMPLETELY;
395 break;
396 default:
397 wxFAIL_MSG("Unexpected reload type");
398 }
399
400 m_webBrowser->Refresh2(&level);
401 }
402
403 bool wxWebViewIE::IsOfflineMode()
404 {
405 wxVariant out = m_ie.GetProperty("Offline");
406
407 wxASSERT(out.GetType() == "bool");
408
409 return out.GetBool();
410 }
411
412 void wxWebViewIE::SetOfflineMode(bool offline)
413 {
414 // FIXME: the wxWidgets docs do not really document what the return
415 // parameter of PutProperty is
416 const bool success = m_ie.PutProperty("Offline", (offline ?
417 VARIANT_TRUE :
418 VARIANT_FALSE));
419 wxASSERT(success);
420 }
421
422 bool wxWebViewIE::IsBusy()
423 {
424 if (m_isBusy) return true;
425
426 wxVariant out = m_ie.GetProperty("Busy");
427
428 wxASSERT(out.GetType() == "bool");
429
430 return out.GetBool();
431 }
432
433 wxString wxWebViewIE::GetCurrentURL()
434 {
435 wxVariant out = m_ie.GetProperty("LocationURL");
436
437 wxASSERT(out.GetType() == "string");
438 return out.GetString();
439 }
440
441 wxString wxWebViewIE::GetCurrentTitle()
442 {
443 wxVariant out = m_ie.GetProperty("LocationName");
444
445 wxASSERT(out.GetType() == "string");
446 return out.GetString();
447 }
448
449 void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
450 {
451 if (m_webBrowser == NULL) return;
452
453 switch (evt.GetDispatchId())
454 {
455 case DISPID_BEFORENAVIGATE2:
456 {
457 m_isBusy = true;
458
459 wxString url = evt[1].GetString();
460 wxString target = evt[3].GetString();
461
462 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
463 GetId(), url, target, true);
464 event.SetEventObject(this);
465 HandleWindowEvent(event);
466
467 if (event.IsVetoed())
468 {
469 wxActiveXEventNativeMSW* nativeParams =
470 evt.GetNativeParameters();
471 *V_BOOLREF(&nativeParams->pDispParams->rgvarg[0]) = VARIANT_TRUE;
472 }
473
474 // at this point, either the navigation event has been cancelled
475 // and we're not busy, either it was accepted and IWebBrowser2's
476 // Busy property will be true; so we don't need our override
477 // flag anymore.
478 m_isBusy = false;
479
480 break;
481 }
482
483 case DISPID_NAVIGATECOMPLETE2:
484 {
485 wxString url = evt[1].GetString();
486 // TODO: set target parameter if possible
487 wxString target = wxEmptyString;
488 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
489 GetId(), url, target, false);
490 event.SetEventObject(this);
491 HandleWindowEvent(event);
492 break;
493 }
494
495 case DISPID_PROGRESSCHANGE:
496 {
497 // download progress
498 break;
499 }
500
501 case DISPID_DOCUMENTCOMPLETE:
502 {
503 //Only send a complete even if we are actually finished, this brings
504 //the event in to line with webkit
505 READYSTATE rs;
506 m_webBrowser->get_ReadyState( &rs );
507 if(rs != READYSTATE_COMPLETE)
508 break;
509
510 wxString url = evt[1].GetString();
511 // TODO: set target parameter if possible
512 wxString target = wxEmptyString;
513 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_LOADED, GetId(),
514 url, target, false);
515 event.SetEventObject(this);
516 HandleWindowEvent(event);
517 break;
518 }
519
520 case DISPID_STATUSTEXTCHANGE:
521 {
522 break;
523 }
524
525 case DISPID_TITLECHANGE:
526 {
527 break;
528 }
529
530 case DISPID_NAVIGATEERROR:
531 {
532 wxWebNavigationError errorType = wxWEB_NAV_ERR_OTHER;
533 wxString errorCode = "?";
534 switch (evt[3].GetLong())
535 {
536 case INET_E_INVALID_URL: // (0x800C0002L or -2146697214)
537 errorCode = "INET_E_INVALID_URL";
538 errorType = wxWEB_NAV_ERR_REQUEST;
539 break;
540 case INET_E_NO_SESSION: // (0x800C0003L or -2146697213)
541 errorCode = "INET_E_NO_SESSION";
542 errorType = wxWEB_NAV_ERR_CONNECTION;
543 break;
544 case INET_E_CANNOT_CONNECT: // (0x800C0004L or -2146697212)
545 errorCode = "INET_E_CANNOT_CONNECT";
546 errorType = wxWEB_NAV_ERR_CONNECTION;
547 break;
548 case INET_E_RESOURCE_NOT_FOUND: // (0x800C0005L or -2146697211)
549 errorCode = "INET_E_RESOURCE_NOT_FOUND";
550 errorType = wxWEB_NAV_ERR_NOT_FOUND;
551 break;
552 case INET_E_OBJECT_NOT_FOUND: // (0x800C0006L or -2146697210)
553 errorCode = "INET_E_OBJECT_NOT_FOUND";
554 errorType = wxWEB_NAV_ERR_NOT_FOUND;
555 break;
556 case INET_E_DATA_NOT_AVAILABLE: // (0x800C0007L or -2146697209)
557 errorCode = "INET_E_DATA_NOT_AVAILABLE";
558 errorType = wxWEB_NAV_ERR_NOT_FOUND;
559 break;
560 case INET_E_DOWNLOAD_FAILURE: // (0x800C0008L or -2146697208)
561 errorCode = "INET_E_DOWNLOAD_FAILURE";
562 errorType = wxWEB_NAV_ERR_CONNECTION;
563 break;
564 case INET_E_AUTHENTICATION_REQUIRED: // (0x800C0009L or -2146697207)
565 errorCode = "INET_E_AUTHENTICATION_REQUIRED";
566 errorType = wxWEB_NAV_ERR_AUTH;
567 break;
568 case INET_E_NO_VALID_MEDIA: // (0x800C000AL or -2146697206)
569 errorCode = "INET_E_NO_VALID_MEDIA";
570 errorType = wxWEB_NAV_ERR_REQUEST;
571 break;
572 case INET_E_CONNECTION_TIMEOUT: // (0x800C000BL or -2146697205)
573 errorCode = "INET_E_CONNECTION_TIMEOUT";
574 errorType = wxWEB_NAV_ERR_CONNECTION;
575 break;
576 case INET_E_INVALID_REQUEST: // (0x800C000CL or -2146697204)
577 errorCode = "INET_E_INVALID_REQUEST";
578 errorType = wxWEB_NAV_ERR_REQUEST;
579 break;
580 case INET_E_UNKNOWN_PROTOCOL: // (0x800C000DL or -2146697203)
581 errorCode = "INET_E_UNKNOWN_PROTOCOL";
582 errorType = wxWEB_NAV_ERR_REQUEST;
583 break;
584 case INET_E_SECURITY_PROBLEM: // (0x800C000EL or -2146697202)
585 errorCode = "INET_E_SECURITY_PROBLEM";
586 errorType = wxWEB_NAV_ERR_SECURITY;
587 break;
588 case INET_E_CANNOT_LOAD_DATA: // (0x800C000FL or -2146697201)
589 errorCode = "INET_E_CANNOT_LOAD_DATA";
590 errorType = wxWEB_NAV_ERR_OTHER;
591 break;
592 case INET_E_CANNOT_INSTANTIATE_OBJECT:
593 // CoCreateInstance will return an error code if this happens,
594 // we'll handle this above.
595 return;
596 break;
597 case INET_E_REDIRECT_FAILED: // (0x800C0014L or -2146697196)
598 errorCode = "INET_E_REDIRECT_FAILED";
599 errorType = wxWEB_NAV_ERR_OTHER;
600 break;
601 case INET_E_REDIRECT_TO_DIR: // (0x800C0015L or -2146697195)
602 errorCode = "INET_E_REDIRECT_TO_DIR";
603 errorType = wxWEB_NAV_ERR_REQUEST;
604 break;
605 case INET_E_CANNOT_LOCK_REQUEST: // (0x800C0016L or -2146697194)
606 errorCode = "INET_E_CANNOT_LOCK_REQUEST";
607 errorType = wxWEB_NAV_ERR_OTHER;
608 break;
609 case INET_E_USE_EXTEND_BINDING: // (0x800C0017L or -2146697193)
610 errorCode = "INET_E_USE_EXTEND_BINDING";
611 errorType = wxWEB_NAV_ERR_OTHER;
612 break;
613 case INET_E_TERMINATED_BIND: // (0x800C0018L or -2146697192)
614 errorCode = "INET_E_TERMINATED_BIND";
615 errorType = wxWEB_NAV_ERR_OTHER;
616 break;
617 case INET_E_INVALID_CERTIFICATE: // (0x800C0019L or -2146697191)
618 errorCode = "INET_E_INVALID_CERTIFICATE";
619 errorType = wxWEB_NAV_ERR_CERTIFICATE;
620 break;
621 case INET_E_CODE_DOWNLOAD_DECLINED: // (0x800C0100L or -2146696960)
622 errorCode = "INET_E_CODE_DOWNLOAD_DECLINED";
623 errorType = wxWEB_NAV_ERR_USER_CANCELLED;
624 break;
625 case INET_E_RESULT_DISPATCHED: // (0x800C0200L or -2146696704)
626 // cancel request cancelled...
627 errorCode = "INET_E_RESULT_DISPATCHED";
628 errorType = wxWEB_NAV_ERR_OTHER;
629 break;
630 case INET_E_CANNOT_REPLACE_SFP_FILE: // (0x800C0300L or -2146696448)
631 errorCode = "INET_E_CANNOT_REPLACE_SFP_FILE";
632 errorType = wxWEB_NAV_ERR_SECURITY;
633 break;
634 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY:
635 errorCode = "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
636 errorType = wxWEB_NAV_ERR_SECURITY;
637 break;
638 case INET_E_CODE_INSTALL_SUPPRESSED:
639 errorCode = "INET_E_CODE_INSTALL_SUPPRESSED";
640 errorType = wxWEB_NAV_ERR_SECURITY;
641 break;
642 }
643
644 wxString url = evt[1].GetString();
645 wxString target = evt[2].GetString();
646 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_ERROR, GetId(),
647 url, target, false);
648 event.SetEventObject(this);
649 event.SetInt(errorType);
650 event.SetString(errorCode);
651 HandleWindowEvent(event);
652 break;
653 }
654
655 case DISPID_COMMANDSTATECHANGE:
656 {
657 long commandId = evt[0].GetLong();
658 bool enable = evt[1].GetBool();
659 if (commandId == CSC_NAVIGATEBACK)
660 {
661 m_canNavigateBack = enable;
662 }
663 else if (commandId == CSC_NAVIGATEFORWARD)
664 {
665 m_canNavigateForward = enable;
666 }
667 break;
668 }
669 case DISPID_NEWWINDOW3:
670 {
671 wxString url = evt[4].GetString();
672
673 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
674 GetId(), url, wxEmptyString, true);
675 event.SetEventObject(this);
676 HandleWindowEvent(event);
677
678 //If we veto the event then we cancel the new window
679 if (event.IsVetoed())
680 {
681 wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters();
682 *V_BOOLREF(&nativeParams->pDispParams->rgvarg[3]) = VARIANT_TRUE;
683 }
684 break;
685 }
686 }
687
688 evt.Skip();
689 }
690
691 #endif