1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/webview_ie.cpp
3 // Purpose: wxMSW wxWebViewIE class implementation for web view component
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if defined(__BORLANDC__)
17 #include "wx/msw/webview_ie.h"
27 #include "wx/msw/registry.h"
28 // Various definitions are missing from mingw
30 typedef enum CommandStateChangeConstants
{
31 CSC_UPDATECOMMANDS
= (int) 0xFFFFFFFF,
32 CSC_NAVIGATEFORWARD
= 0x1,
33 CSC_NAVIGATEBACK
= 0x2
34 } CommandStateChangeConstants
;
36 #define DISPID_COMMANDSTATECHANGE 105
37 #define DISPID_NAVIGATECOMPLETE2 252
38 #define DISPID_NAVIGATEERROR 271
39 #define DISPID_NEWWINDOW3 273
40 #define OLECMDID_OPTICAL_ZOOM 63
41 #define INET_E_ERROR_FIRST 0x800C0002L
42 #define INET_E_INVALID_URL 0x800C0002L
43 #define INET_E_NO_SESSION 0x800C0003L
44 #define INET_E_CANNOT_CONNECT 0x800C0004L
45 #define INET_E_RESOURCE_NOT_FOUND 0x800C0005L
46 #define INET_E_OBJECT_NOT_FOUND 0x800C0006L
47 #define INET_E_DATA_NOT_AVAILABLE 0x800C0007L
48 #define INET_E_DOWNLOAD_FAILURE 0x800C0008L
49 #define INET_E_AUTHENTICATION_REQUIRED 0x800C0009L
50 #define INET_E_NO_VALID_MEDIA 0x800C000AL
51 #define INET_E_CONNECTION_TIMEOUT 0x800C000BL
52 #define INET_E_INVALID_REQUEST 0x800C000CL
53 #define INET_E_UNKNOWN_PROTOCOL 0x800C000DL
54 #define INET_E_SECURITY_PROBLEM 0x800C000EL
55 #define INET_E_CANNOT_LOAD_DATA 0x800C000FL
56 #define INET_E_CANNOT_INSTANTIATE_OBJECT 0x800C0010L
57 #define INET_E_QUERYOPTION_UNKNOWN 0x800C0013L
58 #define INET_E_REDIRECT_FAILED 0x800C0014L
59 #define INET_E_REDIRECT_TO_DIR 0x800C0015L
60 #define INET_E_CANNOT_LOCK_REQUEST 0x800C0016L
61 #define INET_E_USE_EXTEND_BINDING 0x800C0017L
62 #define INET_E_TERMINATED_BIND 0x800C0018L
63 #define INET_E_INVALID_CERTIFICATE 0x800C0019L
64 #define INET_E_CODE_DOWNLOAD_DECLINED 0x800C0100L
65 #define INET_E_RESULT_DISPATCHED 0x800C0200L
66 #define INET_E_CANNOT_REPLACE_SFP_FILE 0x800C0300L
67 #define INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY 0x800C0500L
68 #define INET_E_CODE_INSTALL_SUPPRESSED 0x800C0400L
70 #define REFRESH_NORMAL 0
71 #define REFRESH_COMPLETELY 3
74 BEGIN_EVENT_TABLE(wxWebViewIE
, wxControl
)
75 EVT_ACTIVEX(wxID_ANY
, wxWebViewIE::onActiveXEvent
)
76 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg
)
79 bool wxWebViewIE::Create(wxWindow
* parent
,
87 if (!wxControl::Create(parent
, id
, pos
, size
, style
,
88 wxDefaultValidator
, name
))
94 m_canNavigateBack
= false;
95 m_canNavigateForward
= false;
97 m_historyLoadingFromList
= false;
98 m_historyEnabled
= true;
99 m_historyPosition
= -1;
100 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
102 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
103 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
104 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
106 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
110 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
112 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
113 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
114 //m_webBrowser->put_Silent(VARIANT_FALSE);
116 m_container
= new wxActiveXContainer(this, IID_IWebBrowser2
, m_webBrowser
);
118 SetBackgroundStyle(wxBG_STYLE_PAINT
);
119 SetDoubleBuffered(true);
125 void wxWebViewIE::LoadUrl(const wxString
& url
)
127 m_ie
.CallMethod("Navigate", (BSTR
) url
.wc_str(), NULL
, NULL
, NULL
, NULL
);
130 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
&)
132 LoadUrl("about:blank");
134 // Let the wx events generated for navigation events be processed, so
135 // that the underlying IE component completes its Document object.
136 // FIXME: calling wxYield is not elegant nor very reliable probably
139 // TODO: consider the "baseUrl" parameter if possible
140 // TODO: consider encoding
141 BSTR bstr
= SysAllocString(html
.wc_str());
143 // Creates a new one-dimensional array
144 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
145 if (psaStrings
!= NULL
)
148 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
150 param
->bstrVal
= bstr
;
152 hr
= SafeArrayUnaccessData(psaStrings
);
153 IHTMLDocument2
* document
= GetDocument();
154 document
->write(psaStrings
);
156 // SafeArrayDestroy calls SysFreeString for each BSTR
157 SafeArrayDestroy(psaStrings
);
161 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
166 wxString
wxWebViewIE::GetPageSource()
168 IHTMLDocument2
* document
= GetDocument();
169 IHTMLElement
*bodyTag
= NULL
;
170 IHTMLElement
*htmlTag
= NULL
;
172 HRESULT hr
= document
->get_body(&bodyTag
);
175 hr
= bodyTag
->get_parentElement(&htmlTag
);
178 htmlTag
->get_outerHTML(&bstr
);
185 return wxString(bstr
);
188 wxWebViewZoom
wxWebViewIE::GetZoom()
190 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
191 return GetIEOpticalZoom();
192 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
193 return GetIETextZoom();
199 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
201 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
202 SetIEOpticalZoom(zoom
);
203 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
209 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
211 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
212 //is 0 to 4 so the check is unnecessary, these match exactly with the
215 VariantInit (&zoomVariant
);
216 V_VT(&zoomVariant
) = VT_I4
;
217 V_I4(&zoomVariant
) = level
;
219 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
220 OLECMDEXECOPT_DONTPROMPTUSER
,
222 wxASSERT(result
== S_OK
);
225 wxWebViewZoom
wxWebViewIE::GetIETextZoom()
228 VariantInit (&zoomVariant
);
229 V_VT(&zoomVariant
) = VT_I4
;
231 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
232 OLECMDEXECOPT_DONTPROMPTUSER
,
234 wxASSERT(result
== S_OK
);
236 //We can safely cast here as we know that the range matches our enum
237 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
240 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
242 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
243 //is 10 to 1000 so the check is unnecessary
245 VariantInit (&zoomVariant
);
246 V_VT(&zoomVariant
) = VT_I4
;
248 //We make a somewhat arbitray map here, taken from values used by webkit
251 case wxWEB_VIEW_ZOOM_TINY
:
252 V_I4(&zoomVariant
) = 60;
254 case wxWEB_VIEW_ZOOM_SMALL
:
255 V_I4(&zoomVariant
) = 80;
257 case wxWEB_VIEW_ZOOM_MEDIUM
:
258 V_I4(&zoomVariant
) = 100;
260 case wxWEB_VIEW_ZOOM_LARGE
:
261 V_I4(&zoomVariant
) = 130;
263 case wxWEB_VIEW_ZOOM_LARGEST
:
264 V_I4(&zoomVariant
) = 160;
270 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
271 OLECMDEXECOPT_DODEFAULT
,
274 wxASSERT(result
== S_OK
);
277 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom()
280 VariantInit (&zoomVariant
);
281 V_VT(&zoomVariant
) = VT_I4
;
283 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
284 OLECMDEXECOPT_DODEFAULT
, NULL
,
286 wxASSERT(result
== S_OK
);
288 const int zoom
= V_I4(&zoomVariant
);
290 //We make a somewhat arbitray map here, taken from values used by webkit
293 return wxWEB_VIEW_ZOOM_TINY
;
295 else if (zoom
> 65 && zoom
<= 90)
297 return wxWEB_VIEW_ZOOM_SMALL
;
299 else if (zoom
> 90 && zoom
<= 115)
301 return wxWEB_VIEW_ZOOM_MEDIUM
;
303 else if (zoom
> 115 && zoom
<= 145)
305 return wxWEB_VIEW_ZOOM_LARGE
;
309 return wxWEB_VIEW_ZOOM_LARGEST
;
313 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
318 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
323 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
325 //IE 6 and below only support text zoom, so check the registry to see what
326 //version we actually have
327 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
329 key
.QueryValue("Version", value
);
331 long version
= wxAtoi(value
.Left(1));
332 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
338 void wxWebViewIE::Print()
340 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
341 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
344 bool wxWebViewIE::CanGoBack()
347 return m_historyPosition
> 0;
352 bool wxWebViewIE::CanGoForward()
355 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
360 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
363 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
365 //We compare the actual pointers to find the correct item
366 if(m_historyList
[i
].get() == item
.get())
369 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
370 "invalid history item");
371 m_historyLoadingFromList
= true;
372 LoadUrl(item
->GetUrl());
373 m_historyPosition
= pos
;
376 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetBackwardHistory()
378 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
379 //As we don't have std::copy or an iterator constructor in the wxwidgets
380 //native vector we construct it by hand
381 for(int i
= 0; i
< m_historyPosition
; i
++)
383 backhist
.push_back(m_historyList
[i
]);
388 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetForwardHistory()
390 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
391 //As we don't have std::copy or an iterator constructor in the wxwidgets
392 //native vector we construct it by hand
393 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
395 forwardhist
.push_back(m_historyList
[i
]);
400 void wxWebViewIE::GoBack()
402 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
405 void wxWebViewIE::GoForward()
407 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
410 void wxWebViewIE::Stop()
412 m_ie
.CallMethod("Stop");
415 void wxWebViewIE::ClearHistory()
417 m_historyList
.clear();
418 m_historyPosition
= -1;
421 void wxWebViewIE::EnableHistory(bool enable
)
423 m_historyEnabled
= enable
;
424 m_historyList
.clear();
425 m_historyPosition
= -1;
428 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
432 V_VT(&level
) = VT_I2
;
436 case wxWEB_VIEW_RELOAD_DEFAULT
:
437 V_I2(&level
) = REFRESH_NORMAL
;
439 case wxWEB_VIEW_RELOAD_NO_CACHE
:
440 V_I2(&level
) = REFRESH_COMPLETELY
;
443 wxFAIL_MSG("Unexpected reload type");
446 m_webBrowser
->Refresh2(&level
);
449 bool wxWebViewIE::IsOfflineMode()
451 wxVariant out
= m_ie
.GetProperty("Offline");
453 wxASSERT(out
.GetType() == "bool");
455 return out
.GetBool();
458 void wxWebViewIE::SetOfflineMode(bool offline
)
460 // FIXME: the wxWidgets docs do not really document what the return
461 // parameter of PutProperty is
462 const bool success
= m_ie
.PutProperty("Offline", (offline
?
468 bool wxWebViewIE::IsBusy()
470 if (m_isBusy
) return true;
472 wxVariant out
= m_ie
.GetProperty("Busy");
474 wxASSERT(out
.GetType() == "bool");
476 return out
.GetBool();
479 wxString
wxWebViewIE::GetCurrentURL()
481 wxVariant out
= m_ie
.GetProperty("LocationURL");
483 wxASSERT(out
.GetType() == "string");
484 return out
.GetString();
487 wxString
wxWebViewIE::GetCurrentTitle()
489 IHTMLDocument2
* document
= GetDocument();
492 document
->get_nameProp(&title
);
494 return wxString(title
);
497 bool wxWebViewIE::CanCut()
499 return CanExecCommand("Cut");
502 bool wxWebViewIE::CanCopy()
504 return CanExecCommand("Copy");
506 bool wxWebViewIE::CanPaste()
508 return CanExecCommand("Paste");
511 void wxWebViewIE::Cut()
516 void wxWebViewIE::Copy()
521 void wxWebViewIE::Paste()
523 ExecCommand("Paste");
526 bool wxWebViewIE::CanUndo()
528 return CanExecCommand("Undo");
530 bool wxWebViewIE::CanRedo()
532 return CanExecCommand("Redo");
535 void wxWebViewIE::Undo()
540 void wxWebViewIE::Redo()
545 void wxWebViewIE::SetEditable(bool enable
)
547 IHTMLDocument2
* document
= GetDocument();
549 document
->put_designMode(SysAllocString(L
"On"));
551 document
->put_designMode(SysAllocString(L
"Off"));
556 bool wxWebViewIE::IsEditable()
558 IHTMLDocument2
* document
= GetDocument();
560 document
->get_designMode(&mode
);
561 if(wxString(mode
) == "On")
569 void wxWebViewIE::SelectAll()
571 ExecCommand("SelectAll");
574 bool wxWebViewIE::HasSelection()
576 IHTMLDocument2
* document
= GetDocument();
577 IHTMLSelectionObject
* selection
;
579 HRESULT hr
= document
->get_selection(&selection
);
582 selection
->get_type(&type
);
583 selection
->Release();
586 return wxString(type
) != "None";
589 void wxWebViewIE::DeleteSelection()
591 ExecCommand("Delete");
594 wxString
wxWebViewIE::GetSelectedText()
596 IHTMLDocument2
* document
= GetDocument();
597 IHTMLSelectionObject
* selection
;
599 HRESULT hr
= document
->get_selection(&selection
);
603 hr
= selection
->createRange(&disrange
);
606 IHTMLTxtRange
* range
;
607 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
611 range
->get_text(&text
);
612 selected
= wxString(text
);
617 selection
->Release();
623 wxString
wxWebViewIE::GetSelectedSource()
625 IHTMLDocument2
* document
= GetDocument();
626 IHTMLSelectionObject
* selection
;
628 HRESULT hr
= document
->get_selection(&selection
);
632 hr
= selection
->createRange(&disrange
);
635 IHTMLTxtRange
* range
;
636 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
640 range
->get_htmlText(&text
);
641 selected
= wxString(text
);
646 selection
->Release();
652 wxString
wxWebViewIE::GetPageText()
654 IHTMLDocument2
* document
= GetDocument();
657 HRESULT hr
= document
->get_body(&body
);
660 body
->get_innerText(&out
);
664 return wxString(out
);
667 bool wxWebViewIE::CanExecCommand(wxString command
)
669 IHTMLDocument2
* document
= GetDocument();
670 VARIANT_BOOL enabled
;
672 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
675 return (enabled
== VARIANT_TRUE
);
678 void wxWebViewIE::ExecCommand(wxString command
)
680 IHTMLDocument2
* document
= GetDocument();
681 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
685 IHTMLDocument2
* wxWebViewIE::GetDocument()
687 wxVariant variant
= m_ie
.GetProperty("Document");
688 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
695 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
697 if (m_webBrowser
== NULL
) return;
699 switch (evt
.GetDispatchId())
701 case DISPID_BEFORENAVIGATE2
:
705 wxString url
= evt
[1].GetString();
706 wxString target
= evt
[3].GetString();
708 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
709 GetId(), url
, target
, true);
710 event
.SetEventObject(this);
711 HandleWindowEvent(event
);
713 if (event
.IsVetoed())
715 wxActiveXEventNativeMSW
* nativeParams
=
716 evt
.GetNativeParameters();
717 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
720 // at this point, either the navigation event has been cancelled
721 // and we're not busy, either it was accepted and IWebBrowser2's
722 // Busy property will be true; so we don't need our override
729 case DISPID_NAVIGATECOMPLETE2
:
731 wxString url
= evt
[1].GetString();
732 // TODO: set target parameter if possible
733 wxString target
= wxEmptyString
;
734 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
735 GetId(), url
, target
, false);
736 event
.SetEventObject(this);
737 HandleWindowEvent(event
);
741 case DISPID_PROGRESSCHANGE
:
747 case DISPID_DOCUMENTCOMPLETE
:
749 //Only send a complete even if we are actually finished, this brings
750 //the event in to line with webkit
752 m_webBrowser
->get_ReadyState( &rs
);
753 if(rs
!= READYSTATE_COMPLETE
)
756 wxString url
= evt
[1].GetString();
758 //As we are complete we also add to the history list, but not if the
759 //page is not the main page, ie it is a subframe
760 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
762 //If we are not at the end of the list, then erase everything
763 //between us and the end before adding the new page
764 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
766 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
767 m_historyList
.end());
769 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
770 m_historyList
.push_back(item
);
773 //Reset as we are done now
774 m_historyLoadingFromList
= false;
775 // TODO: set target parameter if possible
776 wxString target
= wxEmptyString
;
777 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
779 event
.SetEventObject(this);
780 HandleWindowEvent(event
);
784 case DISPID_STATUSTEXTCHANGE
:
789 case DISPID_TITLECHANGE
:
794 case DISPID_NAVIGATEERROR
:
796 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
797 wxString errorCode
= "?";
798 switch (evt
[3].GetLong())
800 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
801 errorCode
= "INET_E_INVALID_URL";
802 errorType
= wxWEB_NAV_ERR_REQUEST
;
804 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
805 errorCode
= "INET_E_NO_SESSION";
806 errorType
= wxWEB_NAV_ERR_CONNECTION
;
808 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
809 errorCode
= "INET_E_CANNOT_CONNECT";
810 errorType
= wxWEB_NAV_ERR_CONNECTION
;
812 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
813 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
814 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
816 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
817 errorCode
= "INET_E_OBJECT_NOT_FOUND";
818 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
820 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
821 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
822 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
824 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
825 errorCode
= "INET_E_DOWNLOAD_FAILURE";
826 errorType
= wxWEB_NAV_ERR_CONNECTION
;
828 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
829 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
830 errorType
= wxWEB_NAV_ERR_AUTH
;
832 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
833 errorCode
= "INET_E_NO_VALID_MEDIA";
834 errorType
= wxWEB_NAV_ERR_REQUEST
;
836 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
837 errorCode
= "INET_E_CONNECTION_TIMEOUT";
838 errorType
= wxWEB_NAV_ERR_CONNECTION
;
840 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
841 errorCode
= "INET_E_INVALID_REQUEST";
842 errorType
= wxWEB_NAV_ERR_REQUEST
;
844 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
845 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
846 errorType
= wxWEB_NAV_ERR_REQUEST
;
848 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
849 errorCode
= "INET_E_SECURITY_PROBLEM";
850 errorType
= wxWEB_NAV_ERR_SECURITY
;
852 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
853 errorCode
= "INET_E_CANNOT_LOAD_DATA";
854 errorType
= wxWEB_NAV_ERR_OTHER
;
856 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
857 // CoCreateInstance will return an error code if this happens,
858 // we'll handle this above.
861 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
862 errorCode
= "INET_E_REDIRECT_FAILED";
863 errorType
= wxWEB_NAV_ERR_OTHER
;
865 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
866 errorCode
= "INET_E_REDIRECT_TO_DIR";
867 errorType
= wxWEB_NAV_ERR_REQUEST
;
869 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
870 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
871 errorType
= wxWEB_NAV_ERR_OTHER
;
873 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
874 errorCode
= "INET_E_USE_EXTEND_BINDING";
875 errorType
= wxWEB_NAV_ERR_OTHER
;
877 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
878 errorCode
= "INET_E_TERMINATED_BIND";
879 errorType
= wxWEB_NAV_ERR_OTHER
;
881 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
882 errorCode
= "INET_E_INVALID_CERTIFICATE";
883 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
885 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
886 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
887 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
889 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
890 // cancel request cancelled...
891 errorCode
= "INET_E_RESULT_DISPATCHED";
892 errorType
= wxWEB_NAV_ERR_OTHER
;
894 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
895 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
896 errorType
= wxWEB_NAV_ERR_SECURITY
;
898 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
899 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
900 errorType
= wxWEB_NAV_ERR_SECURITY
;
902 case INET_E_CODE_INSTALL_SUPPRESSED
:
903 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
904 errorType
= wxWEB_NAV_ERR_SECURITY
;
908 wxString url
= evt
[1].GetString();
909 wxString target
= evt
[2].GetString();
910 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
912 event
.SetEventObject(this);
913 event
.SetInt(errorType
);
914 event
.SetString(errorCode
);
915 HandleWindowEvent(event
);
919 case DISPID_COMMANDSTATECHANGE
:
921 long commandId
= evt
[0].GetLong();
922 bool enable
= evt
[1].GetBool();
923 if (commandId
== CSC_NAVIGATEBACK
)
925 m_canNavigateBack
= enable
;
927 else if (commandId
== CSC_NAVIGATEFORWARD
)
929 m_canNavigateForward
= enable
;
933 case DISPID_NEWWINDOW3
:
935 wxString url
= evt
[4].GetString();
937 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
938 GetId(), url
, wxEmptyString
, true);
939 event
.SetEventObject(this);
940 HandleWindowEvent(event
);
942 //If we veto the event then we cancel the new window
943 if (event
.IsVetoed())
945 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
946 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;