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
);
179 htmlTag
->get_outerHTML(&bstr
);
180 source
= wxString(bstr
);
190 wxWebViewZoom wxWebViewIE
::GetZoom()
192 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
193 return GetIEOpticalZoom();
194 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
195 return GetIETextZoom();
199 //Dummy return to stop compiler warnings
200 return wxWEB_VIEW_ZOOM_MEDIUM
;
204 void wxWebViewIE
::SetZoom(wxWebViewZoom zoom
)
206 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
207 SetIEOpticalZoom(zoom
);
208 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
214 void wxWebViewIE
::SetIETextZoom(wxWebViewZoom level
)
216 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
217 //is 0 to 4 so the check is unnecessary, these match exactly with the
220 VariantInit (&zoomVariant
);
221 V_VT(&zoomVariant
) = VT_I4
;
222 V_I4(&zoomVariant
) = level
;
224 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
225 OLECMDEXECOPT_DONTPROMPTUSER
,
227 wxASSERT(result
== S_OK
);
230 wxWebViewZoom wxWebViewIE
::GetIETextZoom()
233 VariantInit (&zoomVariant
);
234 V_VT(&zoomVariant
) = VT_I4
;
236 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
237 OLECMDEXECOPT_DONTPROMPTUSER
,
239 wxASSERT(result
== S_OK
);
241 //We can safely cast here as we know that the range matches our enum
242 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
245 void wxWebViewIE
::SetIEOpticalZoom(wxWebViewZoom level
)
247 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
248 //is 10 to 1000 so the check is unnecessary
250 VariantInit (&zoomVariant
);
251 V_VT(&zoomVariant
) = VT_I4
;
253 //We make a somewhat arbitray map here, taken from values used by webkit
256 case wxWEB_VIEW_ZOOM_TINY
:
257 V_I4(&zoomVariant
) = 60;
259 case wxWEB_VIEW_ZOOM_SMALL
:
260 V_I4(&zoomVariant
) = 80;
262 case wxWEB_VIEW_ZOOM_MEDIUM
:
263 V_I4(&zoomVariant
) = 100;
265 case wxWEB_VIEW_ZOOM_LARGE
:
266 V_I4(&zoomVariant
) = 130;
268 case wxWEB_VIEW_ZOOM_LARGEST
:
269 V_I4(&zoomVariant
) = 160;
275 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
276 OLECMDEXECOPT_DODEFAULT
,
279 wxASSERT(result
== S_OK
);
282 wxWebViewZoom wxWebViewIE
::GetIEOpticalZoom()
285 VariantInit (&zoomVariant
);
286 V_VT(&zoomVariant
) = VT_I4
;
288 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
289 OLECMDEXECOPT_DODEFAULT
, NULL
,
291 wxASSERT(result
== S_OK
);
293 const int zoom
= V_I4(&zoomVariant
);
295 //We make a somewhat arbitray map here, taken from values used by webkit
298 return wxWEB_VIEW_ZOOM_TINY
;
300 else if (zoom
> 65 && zoom
<= 90)
302 return wxWEB_VIEW_ZOOM_SMALL
;
304 else if (zoom
> 90 && zoom
<= 115)
306 return wxWEB_VIEW_ZOOM_MEDIUM
;
308 else if (zoom
> 115 && zoom
<= 145)
310 return wxWEB_VIEW_ZOOM_LARGE
;
312 else /*if (zoom > 145) */ //Using else removes a compiler warning
314 return wxWEB_VIEW_ZOOM_LARGEST
;
318 void wxWebViewIE
::SetZoomType(wxWebViewZoomType type
)
323 wxWebViewZoomType wxWebViewIE
::GetZoomType() const
328 bool wxWebViewIE
::CanSetZoomType(wxWebViewZoomType type
) const
330 //IE 6 and below only support text zoom, so check the registry to see what
331 //version we actually have
332 wxRegKey
key(wxRegKey
::HKLM
, "Software\\Microsoft\\Internet Explorer");
334 key
.QueryValue("Version", value
);
336 long version
= wxAtoi(value
.Left(1));
337 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
343 void wxWebViewIE
::Print()
345 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
346 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
349 bool wxWebViewIE
::CanGoBack()
352 return m_historyPosition
> 0;
357 bool wxWebViewIE
::CanGoForward()
360 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
365 void wxWebViewIE
::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
368 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
370 //We compare the actual pointers to find the correct item
371 if(m_historyList
[i
].get() == item
.get())
374 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
375 "invalid history item");
376 m_historyLoadingFromList
= true;
377 LoadUrl(item
->GetUrl());
378 m_historyPosition
= pos
;
381 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE
::GetBackwardHistory()
383 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
384 //As we don't have std::copy or an iterator constructor in the wxwidgets
385 //native vector we construct it by hand
386 for(int i
= 0; i
< m_historyPosition
; i
++)
388 backhist
.push_back(m_historyList
[i
]);
393 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE
::GetForwardHistory()
395 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
396 //As we don't have std::copy or an iterator constructor in the wxwidgets
397 //native vector we construct it by hand
398 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
400 forwardhist
.push_back(m_historyList
[i
]);
405 void wxWebViewIE
::GoBack()
407 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
410 void wxWebViewIE
::GoForward()
412 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
415 void wxWebViewIE
::Stop()
417 m_ie
.CallMethod("Stop");
420 void wxWebViewIE
::ClearHistory()
422 m_historyList
.clear();
423 m_historyPosition
= -1;
426 void wxWebViewIE
::EnableHistory(bool enable
)
428 m_historyEnabled
= enable
;
429 m_historyList
.clear();
430 m_historyPosition
= -1;
433 void wxWebViewIE
::Reload(wxWebViewReloadFlags flags
)
437 V_VT(&level
) = VT_I2
;
441 case wxWEB_VIEW_RELOAD_DEFAULT
:
442 V_I2(&level
) = REFRESH_NORMAL
;
444 case wxWEB_VIEW_RELOAD_NO_CACHE
:
445 V_I2(&level
) = REFRESH_COMPLETELY
;
448 wxFAIL_MSG("Unexpected reload type");
451 m_webBrowser
->Refresh2(&level
);
454 bool wxWebViewIE
::IsOfflineMode()
456 wxVariant out
= m_ie
.GetProperty("Offline");
458 wxASSERT(out
.GetType() == "bool");
460 return out
.GetBool();
463 void wxWebViewIE
::SetOfflineMode(bool offline
)
465 // FIXME: the wxWidgets docs do not really document what the return
466 // parameter of PutProperty is
467 const bool success
= m_ie
.PutProperty("Offline", (offline ?
473 bool wxWebViewIE
::IsBusy()
475 if (m_isBusy
) return true;
477 wxVariant out
= m_ie
.GetProperty("Busy");
479 wxASSERT(out
.GetType() == "bool");
481 return out
.GetBool();
484 wxString wxWebViewIE
::GetCurrentURL()
486 wxVariant out
= m_ie
.GetProperty("LocationURL");
488 wxASSERT(out
.GetType() == "string");
489 return out
.GetString();
492 wxString wxWebViewIE
::GetCurrentTitle()
494 IHTMLDocument2
* document
= GetDocument();
497 document
->get_nameProp(&title
);
499 return wxString(title
);
502 bool wxWebViewIE
::CanCut()
504 return CanExecCommand("Cut");
507 bool wxWebViewIE
::CanCopy()
509 return CanExecCommand("Copy");
511 bool wxWebViewIE
::CanPaste()
513 return CanExecCommand("Paste");
516 void wxWebViewIE
::Cut()
521 void wxWebViewIE
::Copy()
526 void wxWebViewIE
::Paste()
528 ExecCommand("Paste");
531 bool wxWebViewIE
::CanUndo()
533 return CanExecCommand("Undo");
535 bool wxWebViewIE
::CanRedo()
537 return CanExecCommand("Redo");
540 void wxWebViewIE
::Undo()
545 void wxWebViewIE
::Redo()
550 void wxWebViewIE
::SetEditable(bool enable
)
552 IHTMLDocument2
* document
= GetDocument();
554 document
->put_designMode(SysAllocString(L
"On"));
556 document
->put_designMode(SysAllocString(L
"Off"));
561 bool wxWebViewIE
::IsEditable()
563 IHTMLDocument2
* document
= GetDocument();
565 document
->get_designMode(&mode
);
567 if(wxString(mode
) == "On")
573 void wxWebViewIE
::SelectAll()
575 ExecCommand("SelectAll");
578 bool wxWebViewIE
::HasSelection()
580 IHTMLDocument2
* document
= GetDocument();
581 IHTMLSelectionObject
* selection
;
583 HRESULT hr
= document
->get_selection(&selection
);
587 selection
->get_type(&type
);
588 sel
= wxString(type
);
589 selection
->Release();
592 return sel
!= "None";
595 void wxWebViewIE
::DeleteSelection()
597 ExecCommand("Delete");
600 wxString wxWebViewIE
::GetSelectedText()
602 IHTMLDocument2
* document
= GetDocument();
603 IHTMLSelectionObject
* selection
;
605 HRESULT hr
= document
->get_selection(&selection
);
609 hr
= selection
->createRange(&disrange
);
612 IHTMLTxtRange
* range
;
613 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
617 range
->get_text(&text
);
618 selected
= wxString(text
);
623 selection
->Release();
629 wxString wxWebViewIE
::GetSelectedSource()
631 IHTMLDocument2
* document
= GetDocument();
632 IHTMLSelectionObject
* selection
;
634 HRESULT hr
= document
->get_selection(&selection
);
638 hr
= selection
->createRange(&disrange
);
641 IHTMLTxtRange
* range
;
642 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
646 range
->get_htmlText(&text
);
647 selected
= wxString(text
);
652 selection
->Release();
658 wxString wxWebViewIE
::GetPageText()
660 IHTMLDocument2
* document
= GetDocument();
663 HRESULT hr
= document
->get_body(&body
);
667 body
->get_innerText(&out
);
668 text
= wxString(out
);
675 bool wxWebViewIE
::CanExecCommand(wxString command
)
677 IHTMLDocument2
* document
= GetDocument();
678 VARIANT_BOOL enabled
;
680 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
683 return (enabled
== VARIANT_TRUE
);
686 void wxWebViewIE
::ExecCommand(wxString command
)
688 IHTMLDocument2
* document
= GetDocument();
689 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
693 IHTMLDocument2
* wxWebViewIE
::GetDocument()
695 wxVariant variant
= m_ie
.GetProperty("Document");
696 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
703 void wxWebViewIE
::onActiveXEvent(wxActiveXEvent
& evt
)
705 if (m_webBrowser
== NULL
) return;
707 switch (evt
.GetDispatchId())
709 case DISPID_BEFORENAVIGATE2
:
713 wxString url
= evt
[1].GetString();
714 wxString target
= evt
[3].GetString();
716 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
717 GetId(), url
, target
, true);
718 event
.SetEventObject(this);
719 HandleWindowEvent(event
);
721 if (event
.IsVetoed())
723 wxActiveXEventNativeMSW
* nativeParams
=
724 evt
.GetNativeParameters();
725 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
728 // at this point, either the navigation event has been cancelled
729 // and we're not busy, either it was accepted and IWebBrowser2's
730 // Busy property will be true; so we don't need our override
737 case DISPID_NAVIGATECOMPLETE2
:
739 wxString url
= evt
[1].GetString();
740 // TODO: set target parameter if possible
741 wxString target
= wxEmptyString
;
742 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
743 GetId(), url
, target
, false);
744 event
.SetEventObject(this);
745 HandleWindowEvent(event
);
749 case DISPID_PROGRESSCHANGE
:
755 case DISPID_DOCUMENTCOMPLETE
:
757 //Only send a complete even if we are actually finished, this brings
758 //the event in to line with webkit
760 m_webBrowser
->get_ReadyState( &rs
);
761 if(rs
!= READYSTATE_COMPLETE
)
764 wxString url
= evt
[1].GetString();
766 //As we are complete we also add to the history list, but not if the
767 //page is not the main page, ie it is a subframe
768 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
770 //If we are not at the end of the list, then erase everything
771 //between us and the end before adding the new page
772 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
774 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
775 m_historyList
.end());
777 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
778 m_historyList
.push_back(item
);
781 //Reset as we are done now
782 m_historyLoadingFromList
= false;
783 // TODO: set target parameter if possible
784 wxString target
= wxEmptyString
;
785 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
787 event
.SetEventObject(this);
788 HandleWindowEvent(event
);
792 case DISPID_STATUSTEXTCHANGE
:
797 case DISPID_TITLECHANGE
:
802 case DISPID_NAVIGATEERROR
:
804 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
805 wxString errorCode
= "?";
806 switch (evt
[3].GetLong())
808 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
809 errorCode
= "INET_E_INVALID_URL";
810 errorType
= wxWEB_NAV_ERR_REQUEST
;
812 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
813 errorCode
= "INET_E_NO_SESSION";
814 errorType
= wxWEB_NAV_ERR_CONNECTION
;
816 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
817 errorCode
= "INET_E_CANNOT_CONNECT";
818 errorType
= wxWEB_NAV_ERR_CONNECTION
;
820 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
821 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
822 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
824 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
825 errorCode
= "INET_E_OBJECT_NOT_FOUND";
826 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
828 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
829 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
830 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
832 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
833 errorCode
= "INET_E_DOWNLOAD_FAILURE";
834 errorType
= wxWEB_NAV_ERR_CONNECTION
;
836 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
837 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
838 errorType
= wxWEB_NAV_ERR_AUTH
;
840 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
841 errorCode
= "INET_E_NO_VALID_MEDIA";
842 errorType
= wxWEB_NAV_ERR_REQUEST
;
844 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
845 errorCode
= "INET_E_CONNECTION_TIMEOUT";
846 errorType
= wxWEB_NAV_ERR_CONNECTION
;
848 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
849 errorCode
= "INET_E_INVALID_REQUEST";
850 errorType
= wxWEB_NAV_ERR_REQUEST
;
852 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
853 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
854 errorType
= wxWEB_NAV_ERR_REQUEST
;
856 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
857 errorCode
= "INET_E_SECURITY_PROBLEM";
858 errorType
= wxWEB_NAV_ERR_SECURITY
;
860 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
861 errorCode
= "INET_E_CANNOT_LOAD_DATA";
862 errorType
= wxWEB_NAV_ERR_OTHER
;
864 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
865 // CoCreateInstance will return an error code if this happens,
866 // we'll handle this above.
869 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
870 errorCode
= "INET_E_REDIRECT_FAILED";
871 errorType
= wxWEB_NAV_ERR_OTHER
;
873 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
874 errorCode
= "INET_E_REDIRECT_TO_DIR";
875 errorType
= wxWEB_NAV_ERR_REQUEST
;
877 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
878 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
879 errorType
= wxWEB_NAV_ERR_OTHER
;
881 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
882 errorCode
= "INET_E_USE_EXTEND_BINDING";
883 errorType
= wxWEB_NAV_ERR_OTHER
;
885 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
886 errorCode
= "INET_E_TERMINATED_BIND";
887 errorType
= wxWEB_NAV_ERR_OTHER
;
889 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
890 errorCode
= "INET_E_INVALID_CERTIFICATE";
891 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
893 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
894 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
895 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
897 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
898 // cancel request cancelled...
899 errorCode
= "INET_E_RESULT_DISPATCHED";
900 errorType
= wxWEB_NAV_ERR_OTHER
;
902 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
903 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
904 errorType
= wxWEB_NAV_ERR_SECURITY
;
906 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
907 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
908 errorType
= wxWEB_NAV_ERR_SECURITY
;
910 case INET_E_CODE_INSTALL_SUPPRESSED
:
911 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
912 errorType
= wxWEB_NAV_ERR_SECURITY
;
916 wxString url
= evt
[1].GetString();
917 wxString target
= evt
[2].GetString();
918 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
920 event
.SetEventObject(this);
921 event
.SetInt(errorType
);
922 event
.SetString(errorCode
);
923 HandleWindowEvent(event
);
927 case DISPID_COMMANDSTATECHANGE
:
929 long commandId
= evt
[0].GetLong();
930 bool enable
= evt
[1].GetBool();
931 if (commandId
== CSC_NAVIGATEBACK
)
933 m_canNavigateBack
= enable
;
935 else if (commandId
== CSC_NAVIGATEFORWARD
)
937 m_canNavigateForward
= enable
;
941 case DISPID_NEWWINDOW3
:
943 wxString url
= evt
[4].GetString();
945 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
946 GetId(), url
, wxEmptyString
, true);
947 event
.SetEventObject(this);
948 HandleWindowEvent(event
);
950 //If we veto the event then we cancel the new window
951 if (event
.IsVetoed())
953 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
954 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;