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
& baseUrl
)
132 BSTR bstr
= SysAllocString(html
.wc_str());
134 // Creates a new one-dimensional array
135 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
136 if (psaStrings
!= NULL
)
140 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
142 param
->bstrVal
= bstr
;
143 hr
= SafeArrayUnaccessData(psaStrings
);
145 IHTMLDocument2
* document
= GetDocument();
146 document
->write(psaStrings
);
149 // SafeArrayDestroy calls SysFreeString for each BSTR
150 SafeArrayDestroy(psaStrings
);
152 //We send the events when we are done to mimic webkit
154 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
155 GetId(), baseUrl
, "", false);
156 event
.SetEventObject(this);
157 HandleWindowEvent(event
);
159 //Document complete event
160 event
.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED
);
161 event
.SetEventObject(this);
162 HandleWindowEvent(event
);
166 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
171 wxString
wxWebViewIE::GetPageSource()
173 IHTMLDocument2
* document
= GetDocument();
174 IHTMLElement
*bodyTag
= NULL
;
175 IHTMLElement
*htmlTag
= NULL
;
177 HRESULT hr
= document
->get_body(&bodyTag
);
180 hr
= bodyTag
->get_parentElement(&htmlTag
);
184 htmlTag
->get_outerHTML(&bstr
);
185 source
= wxString(bstr
);
195 wxWebViewZoom
wxWebViewIE::GetZoom()
197 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
198 return GetIEOpticalZoom();
199 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
200 return GetIETextZoom();
204 //Dummy return to stop compiler warnings
205 return wxWEB_VIEW_ZOOM_MEDIUM
;
209 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
211 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
212 SetIEOpticalZoom(zoom
);
213 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
219 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
221 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
222 //is 0 to 4 so the check is unnecessary, these match exactly with the
225 VariantInit (&zoomVariant
);
226 V_VT(&zoomVariant
) = VT_I4
;
227 V_I4(&zoomVariant
) = level
;
229 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
230 OLECMDEXECOPT_DONTPROMPTUSER
,
232 wxASSERT(result
== S_OK
);
235 wxWebViewZoom
wxWebViewIE::GetIETextZoom()
238 VariantInit (&zoomVariant
);
239 V_VT(&zoomVariant
) = VT_I4
;
241 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
242 OLECMDEXECOPT_DONTPROMPTUSER
,
244 wxASSERT(result
== S_OK
);
246 //We can safely cast here as we know that the range matches our enum
247 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
250 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
252 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
253 //is 10 to 1000 so the check is unnecessary
255 VariantInit (&zoomVariant
);
256 V_VT(&zoomVariant
) = VT_I4
;
258 //We make a somewhat arbitray map here, taken from values used by webkit
261 case wxWEB_VIEW_ZOOM_TINY
:
262 V_I4(&zoomVariant
) = 60;
264 case wxWEB_VIEW_ZOOM_SMALL
:
265 V_I4(&zoomVariant
) = 80;
267 case wxWEB_VIEW_ZOOM_MEDIUM
:
268 V_I4(&zoomVariant
) = 100;
270 case wxWEB_VIEW_ZOOM_LARGE
:
271 V_I4(&zoomVariant
) = 130;
273 case wxWEB_VIEW_ZOOM_LARGEST
:
274 V_I4(&zoomVariant
) = 160;
280 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
281 OLECMDEXECOPT_DODEFAULT
,
284 wxASSERT(result
== S_OK
);
287 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom()
290 VariantInit (&zoomVariant
);
291 V_VT(&zoomVariant
) = VT_I4
;
293 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
294 OLECMDEXECOPT_DODEFAULT
, NULL
,
296 wxASSERT(result
== S_OK
);
298 const int zoom
= V_I4(&zoomVariant
);
300 //We make a somewhat arbitray map here, taken from values used by webkit
303 return wxWEB_VIEW_ZOOM_TINY
;
305 else if (zoom
> 65 && zoom
<= 90)
307 return wxWEB_VIEW_ZOOM_SMALL
;
309 else if (zoom
> 90 && zoom
<= 115)
311 return wxWEB_VIEW_ZOOM_MEDIUM
;
313 else if (zoom
> 115 && zoom
<= 145)
315 return wxWEB_VIEW_ZOOM_LARGE
;
317 else /*if (zoom > 145) */ //Using else removes a compiler warning
319 return wxWEB_VIEW_ZOOM_LARGEST
;
323 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
328 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
333 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
335 //IE 6 and below only support text zoom, so check the registry to see what
336 //version we actually have
337 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
339 key
.QueryValue("Version", value
);
341 long version
= wxAtoi(value
.Left(1));
342 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
348 void wxWebViewIE::Print()
350 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
351 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
354 bool wxWebViewIE::CanGoBack()
357 return m_historyPosition
> 0;
362 bool wxWebViewIE::CanGoForward()
365 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
370 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
373 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
375 //We compare the actual pointers to find the correct item
376 if(m_historyList
[i
].get() == item
.get())
379 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
380 "invalid history item");
381 m_historyLoadingFromList
= true;
382 LoadUrl(item
->GetUrl());
383 m_historyPosition
= pos
;
386 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetBackwardHistory()
388 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
389 //As we don't have std::copy or an iterator constructor in the wxwidgets
390 //native vector we construct it by hand
391 for(int i
= 0; i
< m_historyPosition
; i
++)
393 backhist
.push_back(m_historyList
[i
]);
398 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetForwardHistory()
400 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
401 //As we don't have std::copy or an iterator constructor in the wxwidgets
402 //native vector we construct it by hand
403 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
405 forwardhist
.push_back(m_historyList
[i
]);
410 void wxWebViewIE::GoBack()
412 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
415 void wxWebViewIE::GoForward()
417 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
420 void wxWebViewIE::Stop()
422 m_ie
.CallMethod("Stop");
425 void wxWebViewIE::ClearHistory()
427 m_historyList
.clear();
428 m_historyPosition
= -1;
431 void wxWebViewIE::EnableHistory(bool enable
)
433 m_historyEnabled
= enable
;
434 m_historyList
.clear();
435 m_historyPosition
= -1;
438 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
442 V_VT(&level
) = VT_I2
;
446 case wxWEB_VIEW_RELOAD_DEFAULT
:
447 V_I2(&level
) = REFRESH_NORMAL
;
449 case wxWEB_VIEW_RELOAD_NO_CACHE
:
450 V_I2(&level
) = REFRESH_COMPLETELY
;
453 wxFAIL_MSG("Unexpected reload type");
456 m_webBrowser
->Refresh2(&level
);
459 bool wxWebViewIE::IsOfflineMode()
461 wxVariant out
= m_ie
.GetProperty("Offline");
463 wxASSERT(out
.GetType() == "bool");
465 return out
.GetBool();
468 void wxWebViewIE::SetOfflineMode(bool offline
)
470 // FIXME: the wxWidgets docs do not really document what the return
471 // parameter of PutProperty is
472 const bool success
= m_ie
.PutProperty("Offline", (offline
?
478 bool wxWebViewIE::IsBusy()
480 if (m_isBusy
) return true;
482 wxVariant out
= m_ie
.GetProperty("Busy");
484 wxASSERT(out
.GetType() == "bool");
486 return out
.GetBool();
489 wxString
wxWebViewIE::GetCurrentURL()
491 wxVariant out
= m_ie
.GetProperty("LocationURL");
493 wxASSERT(out
.GetType() == "string");
494 return out
.GetString();
497 wxString
wxWebViewIE::GetCurrentTitle()
499 IHTMLDocument2
* document
= GetDocument();
502 document
->get_nameProp(&title
);
504 return wxString(title
);
507 bool wxWebViewIE::CanCut()
509 return CanExecCommand("Cut");
512 bool wxWebViewIE::CanCopy()
514 return CanExecCommand("Copy");
516 bool wxWebViewIE::CanPaste()
518 return CanExecCommand("Paste");
521 void wxWebViewIE::Cut()
526 void wxWebViewIE::Copy()
531 void wxWebViewIE::Paste()
533 ExecCommand("Paste");
536 bool wxWebViewIE::CanUndo()
538 return CanExecCommand("Undo");
540 bool wxWebViewIE::CanRedo()
542 return CanExecCommand("Redo");
545 void wxWebViewIE::Undo()
550 void wxWebViewIE::Redo()
555 void wxWebViewIE::SetEditable(bool enable
)
557 IHTMLDocument2
* document
= GetDocument();
559 document
->put_designMode(SysAllocString(L
"On"));
561 document
->put_designMode(SysAllocString(L
"Off"));
566 bool wxWebViewIE::IsEditable()
568 IHTMLDocument2
* document
= GetDocument();
570 document
->get_designMode(&mode
);
572 if(wxString(mode
) == "On")
578 void wxWebViewIE::SelectAll()
580 ExecCommand("SelectAll");
583 bool wxWebViewIE::HasSelection()
585 IHTMLDocument2
* document
= GetDocument();
586 IHTMLSelectionObject
* selection
;
588 HRESULT hr
= document
->get_selection(&selection
);
592 selection
->get_type(&type
);
593 sel
= wxString(type
);
594 selection
->Release();
597 return sel
!= "None";
600 void wxWebViewIE::DeleteSelection()
602 ExecCommand("Delete");
605 wxString
wxWebViewIE::GetSelectedText()
607 IHTMLDocument2
* document
= GetDocument();
608 IHTMLSelectionObject
* selection
;
610 HRESULT hr
= document
->get_selection(&selection
);
614 hr
= selection
->createRange(&disrange
);
617 IHTMLTxtRange
* range
;
618 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
622 range
->get_text(&text
);
623 selected
= wxString(text
);
628 selection
->Release();
634 wxString
wxWebViewIE::GetSelectedSource()
636 IHTMLDocument2
* document
= GetDocument();
637 IHTMLSelectionObject
* selection
;
639 HRESULT hr
= document
->get_selection(&selection
);
643 hr
= selection
->createRange(&disrange
);
646 IHTMLTxtRange
* range
;
647 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
651 range
->get_htmlText(&text
);
652 selected
= wxString(text
);
657 selection
->Release();
663 void wxWebViewIE::ClearSelection()
665 IHTMLDocument2
* document
= GetDocument();
666 IHTMLSelectionObject
* selection
;
668 HRESULT hr
= document
->get_selection(&selection
);
672 selection
->Release();
677 wxString
wxWebViewIE::GetPageText()
679 IHTMLDocument2
* document
= GetDocument();
682 HRESULT hr
= document
->get_body(&body
);
686 body
->get_innerText(&out
);
687 text
= wxString(out
);
694 void wxWebViewIE::RunScript(const wxString
& javascript
)
696 IHTMLDocument2
* document
= GetDocument();
697 IHTMLWindow2
* window
;
698 wxString language
= "javascript";
699 HRESULT hr
= document
->get_parentWindow(&window
);
704 V_VT(&level
) = VT_EMPTY
;
705 window
->execScript(SysAllocString(javascript
), SysAllocString(language
), &level
);
710 bool wxWebViewIE::CanExecCommand(wxString command
)
712 IHTMLDocument2
* document
= GetDocument();
713 VARIANT_BOOL enabled
;
715 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
718 return (enabled
== VARIANT_TRUE
);
721 void wxWebViewIE::ExecCommand(wxString command
)
723 IHTMLDocument2
* document
= GetDocument();
724 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
728 IHTMLDocument2
* wxWebViewIE::GetDocument()
730 wxVariant variant
= m_ie
.GetProperty("Document");
731 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
738 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
740 if (m_webBrowser
== NULL
) return;
742 switch (evt
.GetDispatchId())
744 case DISPID_BEFORENAVIGATE2
:
748 wxString url
= evt
[1].GetString();
749 wxString target
= evt
[3].GetString();
751 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
752 GetId(), url
, target
, true);
753 event
.SetEventObject(this);
754 HandleWindowEvent(event
);
756 if (event
.IsVetoed())
758 wxActiveXEventNativeMSW
* nativeParams
=
759 evt
.GetNativeParameters();
760 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
763 // at this point, either the navigation event has been cancelled
764 // and we're not busy, either it was accepted and IWebBrowser2's
765 // Busy property will be true; so we don't need our override
772 case DISPID_NAVIGATECOMPLETE2
:
774 wxString url
= evt
[1].GetString();
775 // TODO: set target parameter if possible
776 wxString target
= wxEmptyString
;
777 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
778 GetId(), url
, target
, false);
779 event
.SetEventObject(this);
780 HandleWindowEvent(event
);
784 case DISPID_PROGRESSCHANGE
:
790 case DISPID_DOCUMENTCOMPLETE
:
792 //Only send a complete even if we are actually finished, this brings
793 //the event in to line with webkit
795 m_webBrowser
->get_ReadyState( &rs
);
796 if(rs
!= READYSTATE_COMPLETE
)
799 wxString url
= evt
[1].GetString();
801 //As we are complete we also add to the history list, but not if the
802 //page is not the main page, ie it is a subframe
803 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
805 //If we are not at the end of the list, then erase everything
806 //between us and the end before adding the new page
807 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
809 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
810 m_historyList
.end());
812 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
813 m_historyList
.push_back(item
);
816 //Reset as we are done now
817 m_historyLoadingFromList
= false;
818 // TODO: set target parameter if possible
819 wxString target
= wxEmptyString
;
820 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
822 event
.SetEventObject(this);
823 HandleWindowEvent(event
);
827 case DISPID_STATUSTEXTCHANGE
:
832 case DISPID_TITLECHANGE
:
837 case DISPID_NAVIGATEERROR
:
839 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
840 wxString errorCode
= "?";
841 switch (evt
[3].GetLong())
843 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
844 errorCode
= "INET_E_INVALID_URL";
845 errorType
= wxWEB_NAV_ERR_REQUEST
;
847 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
848 errorCode
= "INET_E_NO_SESSION";
849 errorType
= wxWEB_NAV_ERR_CONNECTION
;
851 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
852 errorCode
= "INET_E_CANNOT_CONNECT";
853 errorType
= wxWEB_NAV_ERR_CONNECTION
;
855 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
856 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
857 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
859 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
860 errorCode
= "INET_E_OBJECT_NOT_FOUND";
861 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
863 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
864 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
865 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
867 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
868 errorCode
= "INET_E_DOWNLOAD_FAILURE";
869 errorType
= wxWEB_NAV_ERR_CONNECTION
;
871 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
872 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
873 errorType
= wxWEB_NAV_ERR_AUTH
;
875 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
876 errorCode
= "INET_E_NO_VALID_MEDIA";
877 errorType
= wxWEB_NAV_ERR_REQUEST
;
879 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
880 errorCode
= "INET_E_CONNECTION_TIMEOUT";
881 errorType
= wxWEB_NAV_ERR_CONNECTION
;
883 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
884 errorCode
= "INET_E_INVALID_REQUEST";
885 errorType
= wxWEB_NAV_ERR_REQUEST
;
887 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
888 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
889 errorType
= wxWEB_NAV_ERR_REQUEST
;
891 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
892 errorCode
= "INET_E_SECURITY_PROBLEM";
893 errorType
= wxWEB_NAV_ERR_SECURITY
;
895 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
896 errorCode
= "INET_E_CANNOT_LOAD_DATA";
897 errorType
= wxWEB_NAV_ERR_OTHER
;
899 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
900 // CoCreateInstance will return an error code if this happens,
901 // we'll handle this above.
904 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
905 errorCode
= "INET_E_REDIRECT_FAILED";
906 errorType
= wxWEB_NAV_ERR_OTHER
;
908 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
909 errorCode
= "INET_E_REDIRECT_TO_DIR";
910 errorType
= wxWEB_NAV_ERR_REQUEST
;
912 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
913 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
914 errorType
= wxWEB_NAV_ERR_OTHER
;
916 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
917 errorCode
= "INET_E_USE_EXTEND_BINDING";
918 errorType
= wxWEB_NAV_ERR_OTHER
;
920 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
921 errorCode
= "INET_E_TERMINATED_BIND";
922 errorType
= wxWEB_NAV_ERR_OTHER
;
924 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
925 errorCode
= "INET_E_INVALID_CERTIFICATE";
926 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
928 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
929 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
930 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
932 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
933 // cancel request cancelled...
934 errorCode
= "INET_E_RESULT_DISPATCHED";
935 errorType
= wxWEB_NAV_ERR_OTHER
;
937 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
938 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
939 errorType
= wxWEB_NAV_ERR_SECURITY
;
941 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
942 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
943 errorType
= wxWEB_NAV_ERR_SECURITY
;
945 case INET_E_CODE_INSTALL_SUPPRESSED
:
946 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
947 errorType
= wxWEB_NAV_ERR_SECURITY
;
951 wxString url
= evt
[1].GetString();
952 wxString target
= evt
[2].GetString();
953 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
955 event
.SetEventObject(this);
956 event
.SetInt(errorType
);
957 event
.SetString(errorCode
);
958 HandleWindowEvent(event
);
962 case DISPID_COMMANDSTATECHANGE
:
964 long commandId
= evt
[0].GetLong();
965 bool enable
= evt
[1].GetBool();
966 if (commandId
== CSC_NAVIGATEBACK
)
968 m_canNavigateBack
= enable
;
970 else if (commandId
== CSC_NAVIGATEFORWARD
)
972 m_canNavigateForward
= enable
;
976 case DISPID_NEWWINDOW3
:
978 wxString url
= evt
[4].GetString();
980 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
981 GetId(), url
, wxEmptyString
, true);
982 event
.SetEventObject(this);
983 HandleWindowEvent(event
);
985 //If we veto the event then we cancel the new window
986 if (event
.IsVetoed())
988 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
989 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;