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 // Various definitions are missing from mingw
29 typedef enum CommandStateChangeConstants
{
30 CSC_UPDATECOMMANDS
= (int) 0xFFFFFFFF,
31 CSC_NAVIGATEFORWARD
= 0x1,
32 CSC_NAVIGATEBACK
= 0x2
33 } CommandStateChangeConstants
;
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
69 #define REFRESH_NORMAL 0
70 #define REFRESH_COMPLETELY 3
73 BEGIN_EVENT_TABLE(wxWebViewIE
, wxControl
)
74 EVT_ACTIVEX(wxID_ANY
, wxWebViewIE::onActiveXEvent
)
75 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg
)
78 bool wxWebViewIE::Create(wxWindow
* parent
,
86 if (!wxControl::Create(parent
, id
, pos
, size
, style
,
87 wxDefaultValidator
, name
))
93 m_canNavigateBack
= false;
94 m_canNavigateForward
= false;
96 m_historyLoadingFromList
= false;
97 m_historyEnabled
= true;
98 m_historyPosition
= -1;
99 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
101 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
102 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
103 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
105 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
109 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
111 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
112 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
113 //m_webBrowser->put_Silent(VARIANT_FALSE);
115 m_container
= new wxActiveXContainer(this, IID_IWebBrowser2
, m_webBrowser
);
117 SetBackgroundStyle(wxBG_STYLE_PAINT
);
118 SetDoubleBuffered(true);
124 void wxWebViewIE::LoadUrl(const wxString
& url
)
126 m_ie
.CallMethod("Navigate", (BSTR
) url
.wc_str(), NULL
, NULL
, NULL
, NULL
);
129 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
&)
131 LoadUrl("about:blank");
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
138 // TODO: consider the "baseUrl" parameter if possible
139 // TODO: consider encoding
140 BSTR bstr
= SysAllocString(html
.wc_str());
142 // Creates a new one-dimensional array
143 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
144 if (psaStrings
!= NULL
)
147 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
149 param
->bstrVal
= bstr
;
151 hr
= SafeArrayUnaccessData(psaStrings
);
152 IHTMLDocument2
* document
= GetDocument();
153 document
->write(psaStrings
);
155 // SafeArrayDestroy calls SysFreeString for each BSTR
156 SafeArrayDestroy(psaStrings
);
160 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
165 wxString
wxWebViewIE::GetPageSource()
167 IHTMLDocument2
* document
= GetDocument();
168 IHTMLElement
*bodyTag
= NULL
;
169 IHTMLElement
*htmlTag
= NULL
;
171 HRESULT hr
= document
->get_body(&bodyTag
);
174 hr
= bodyTag
->get_parentElement(&htmlTag
);
177 htmlTag
->get_outerHTML(&bstr
);
184 return wxString(bstr
);
187 wxWebViewZoom
wxWebViewIE::GetZoom()
189 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
190 return GetIEOpticalZoom();
191 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
192 return GetIETextZoom();
198 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
200 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
201 SetIEOpticalZoom(zoom
);
202 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
208 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
210 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
211 //is 0 to 4 so the check is unnecessary, these match exactly with the
214 VariantInit (&zoomVariant
);
215 V_VT(&zoomVariant
) = VT_I4
;
216 V_I4(&zoomVariant
) = level
;
218 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
219 OLECMDEXECOPT_DONTPROMPTUSER
,
221 wxASSERT(result
== S_OK
);
224 wxWebViewZoom
wxWebViewIE::GetIETextZoom()
227 VariantInit (&zoomVariant
);
228 V_VT(&zoomVariant
) = VT_I4
;
230 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
231 OLECMDEXECOPT_DONTPROMPTUSER
,
233 wxASSERT(result
== S_OK
);
235 //We can safely cast here as we know that the range matches our enum
236 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
239 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
241 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
242 //is 10 to 1000 so the check is unnecessary
244 VariantInit (&zoomVariant
);
245 V_VT(&zoomVariant
) = VT_I4
;
247 //We make a somewhat arbitray map here, taken from values used by webkit
250 case wxWEB_VIEW_ZOOM_TINY
:
251 V_I4(&zoomVariant
) = 60;
253 case wxWEB_VIEW_ZOOM_SMALL
:
254 V_I4(&zoomVariant
) = 80;
256 case wxWEB_VIEW_ZOOM_MEDIUM
:
257 V_I4(&zoomVariant
) = 100;
259 case wxWEB_VIEW_ZOOM_LARGE
:
260 V_I4(&zoomVariant
) = 130;
262 case wxWEB_VIEW_ZOOM_LARGEST
:
263 V_I4(&zoomVariant
) = 160;
269 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
270 OLECMDEXECOPT_DODEFAULT
,
273 wxASSERT(result
== S_OK
);
276 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom()
279 VariantInit (&zoomVariant
);
280 V_VT(&zoomVariant
) = VT_I4
;
282 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
283 OLECMDEXECOPT_DODEFAULT
, NULL
,
285 wxASSERT(result
== S_OK
);
287 const int zoom
= V_I4(&zoomVariant
);
289 //We make a somewhat arbitray map here, taken from values used by webkit
292 return wxWEB_VIEW_ZOOM_TINY
;
294 else if (zoom
> 65 && zoom
<= 90)
296 return wxWEB_VIEW_ZOOM_SMALL
;
298 else if (zoom
> 90 && zoom
<= 115)
300 return wxWEB_VIEW_ZOOM_MEDIUM
;
302 else if (zoom
> 115 && zoom
<= 145)
304 return wxWEB_VIEW_ZOOM_LARGE
;
308 return wxWEB_VIEW_ZOOM_LARGEST
;
312 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
317 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
322 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType
) const
324 // both are supported
325 // TODO: IE6 only supports text zoom, check if it's IE6 first
329 void wxWebViewIE::Print()
331 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
332 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
335 bool wxWebViewIE::CanGoBack()
338 return m_historyPosition
> 0;
343 bool wxWebViewIE::CanGoForward()
346 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
351 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
354 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
356 //We compare the actual pointers to find the correct item
357 if(m_historyList
[i
].get() == item
.get())
360 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
361 "invalid history item");
362 m_historyLoadingFromList
= true;
363 LoadUrl(item
->GetUrl());
364 m_historyPosition
= pos
;
367 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetBackwardHistory()
369 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
370 //As we don't have std::copy or an iterator constructor in the wxwidgets
371 //native vector we construct it by hand
372 for(int i
= 0; i
< m_historyPosition
; i
++)
374 backhist
.push_back(m_historyList
[i
]);
379 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetForwardHistory()
381 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
382 //As we don't have std::copy or an iterator constructor in the wxwidgets
383 //native vector we construct it by hand
384 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
386 forwardhist
.push_back(m_historyList
[i
]);
391 void wxWebViewIE::GoBack()
393 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
396 void wxWebViewIE::GoForward()
398 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
401 void wxWebViewIE::Stop()
403 m_ie
.CallMethod("Stop");
406 void wxWebViewIE::ClearHistory()
408 m_historyList
.clear();
409 m_historyPosition
= -1;
412 void wxWebViewIE::EnableHistory(bool enable
)
414 m_historyEnabled
= enable
;
415 m_historyList
.clear();
416 m_historyPosition
= -1;
419 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
423 V_VT(&level
) = VT_I2
;
427 case wxWEB_VIEW_RELOAD_DEFAULT
:
428 V_I2(&level
) = REFRESH_NORMAL
;
430 case wxWEB_VIEW_RELOAD_NO_CACHE
:
431 V_I2(&level
) = REFRESH_COMPLETELY
;
434 wxFAIL_MSG("Unexpected reload type");
437 m_webBrowser
->Refresh2(&level
);
440 bool wxWebViewIE::IsOfflineMode()
442 wxVariant out
= m_ie
.GetProperty("Offline");
444 wxASSERT(out
.GetType() == "bool");
446 return out
.GetBool();
449 void wxWebViewIE::SetOfflineMode(bool offline
)
451 // FIXME: the wxWidgets docs do not really document what the return
452 // parameter of PutProperty is
453 const bool success
= m_ie
.PutProperty("Offline", (offline
?
459 bool wxWebViewIE::IsBusy()
461 if (m_isBusy
) return true;
463 wxVariant out
= m_ie
.GetProperty("Busy");
465 wxASSERT(out
.GetType() == "bool");
467 return out
.GetBool();
470 wxString
wxWebViewIE::GetCurrentURL()
472 wxVariant out
= m_ie
.GetProperty("LocationURL");
474 wxASSERT(out
.GetType() == "string");
475 return out
.GetString();
478 wxString
wxWebViewIE::GetCurrentTitle()
480 IHTMLDocument2
* document
= GetDocument();
483 document
->get_nameProp(&title
);
485 return wxString(title
);
488 bool wxWebViewIE::CanCut()
490 return CanExecCommand("Cut");
493 bool wxWebViewIE::CanCopy()
495 return CanExecCommand("Copy");
497 bool wxWebViewIE::CanPaste()
499 return CanExecCommand("Paste");
502 void wxWebViewIE::Cut()
507 void wxWebViewIE::Copy()
512 void wxWebViewIE::Paste()
514 ExecCommand("Paste");
517 bool wxWebViewIE::CanUndo()
519 return CanExecCommand("Undo");
521 bool wxWebViewIE::CanRedo()
523 return CanExecCommand("Redo");
526 void wxWebViewIE::Undo()
531 void wxWebViewIE::Redo()
536 void wxWebViewIE::SetEditable(bool enable
)
538 IHTMLDocument2
* document
= GetDocument();
540 document
->put_designMode(SysAllocString(L
"On"));
542 document
->put_designMode(SysAllocString(L
"Off"));
547 bool wxWebViewIE::IsEditable()
549 IHTMLDocument2
* document
= GetDocument();
551 document
->get_designMode(&mode
);
552 if(wxString(mode
) == "On")
560 void wxWebViewIE::SelectAll()
562 ExecCommand("SelectAll");
565 bool wxWebViewIE::HasSelection()
567 IHTMLDocument2
* document
= GetDocument();
568 IHTMLSelectionObject
* selection
;
570 HRESULT hr
= document
->get_selection(&selection
);
573 selection
->get_type(&type
);
574 selection
->Release();
577 return wxString(type
) != "None";
580 void wxWebViewIE::DeleteSelection()
582 ExecCommand("Delete");
585 wxString
wxWebViewIE::GetSelectedText()
587 IHTMLDocument2
* document
= GetDocument();
588 IHTMLSelectionObject
* selection
;
590 HRESULT hr
= document
->get_selection(&selection
);
594 hr
= selection
->createRange(&disrange
);
597 IHTMLTxtRange
* range
;
598 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
602 range
->get_text(&text
);
603 selected
= wxString(text
);
608 selection
->Release();
614 wxString
wxWebViewIE::GetSelectedSource()
616 IHTMLDocument2
* document
= GetDocument();
617 IHTMLSelectionObject
* selection
;
619 HRESULT hr
= document
->get_selection(&selection
);
623 hr
= selection
->createRange(&disrange
);
626 IHTMLTxtRange
* range
;
627 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
631 range
->get_htmlText(&text
);
632 selected
= wxString(text
);
637 selection
->Release();
643 wxString
wxWebViewIE::GetPageText()
645 IHTMLDocument2
* document
= GetDocument();
648 HRESULT hr
= document
->get_body(&body
);
651 body
->get_innerText(&out
);
655 return wxString(out
);
658 bool wxWebViewIE::CanExecCommand(wxString command
)
660 IHTMLDocument2
* document
= GetDocument();
661 VARIANT_BOOL enabled
;
663 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
666 return (enabled
== VARIANT_TRUE
);
669 void wxWebViewIE::ExecCommand(wxString command
)
671 IHTMLDocument2
* document
= GetDocument();
672 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
676 IHTMLDocument2
* wxWebViewIE::GetDocument()
678 wxVariant variant
= m_ie
.GetProperty("Document");
679 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
686 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
688 if (m_webBrowser
== NULL
) return;
690 switch (evt
.GetDispatchId())
692 case DISPID_BEFORENAVIGATE2
:
696 wxString url
= evt
[1].GetString();
697 wxString target
= evt
[3].GetString();
699 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
700 GetId(), url
, target
, true);
701 event
.SetEventObject(this);
702 HandleWindowEvent(event
);
704 if (event
.IsVetoed())
706 wxActiveXEventNativeMSW
* nativeParams
=
707 evt
.GetNativeParameters();
708 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
711 // at this point, either the navigation event has been cancelled
712 // and we're not busy, either it was accepted and IWebBrowser2's
713 // Busy property will be true; so we don't need our override
720 case DISPID_NAVIGATECOMPLETE2
:
722 wxString url
= evt
[1].GetString();
723 // TODO: set target parameter if possible
724 wxString target
= wxEmptyString
;
725 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
726 GetId(), url
, target
, false);
727 event
.SetEventObject(this);
728 HandleWindowEvent(event
);
732 case DISPID_PROGRESSCHANGE
:
738 case DISPID_DOCUMENTCOMPLETE
:
740 //Only send a complete even if we are actually finished, this brings
741 //the event in to line with webkit
743 m_webBrowser
->get_ReadyState( &rs
);
744 if(rs
!= READYSTATE_COMPLETE
)
747 wxString url
= evt
[1].GetString();
749 //As we are complete we also add to the history list, but not if the
750 //page is not the main page, ie it is a subframe
751 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
753 //If we are not at the end of the list, then erase everything
754 //between us and the end before adding the new page
755 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
757 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
758 m_historyList
.end());
760 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
761 m_historyList
.push_back(item
);
764 //Reset as we are done now
765 m_historyLoadingFromList
= false;
766 // TODO: set target parameter if possible
767 wxString target
= wxEmptyString
;
768 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
770 event
.SetEventObject(this);
771 HandleWindowEvent(event
);
775 case DISPID_STATUSTEXTCHANGE
:
780 case DISPID_TITLECHANGE
:
785 case DISPID_NAVIGATEERROR
:
787 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
788 wxString errorCode
= "?";
789 switch (evt
[3].GetLong())
791 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
792 errorCode
= "INET_E_INVALID_URL";
793 errorType
= wxWEB_NAV_ERR_REQUEST
;
795 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
796 errorCode
= "INET_E_NO_SESSION";
797 errorType
= wxWEB_NAV_ERR_CONNECTION
;
799 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
800 errorCode
= "INET_E_CANNOT_CONNECT";
801 errorType
= wxWEB_NAV_ERR_CONNECTION
;
803 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
804 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
805 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
807 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
808 errorCode
= "INET_E_OBJECT_NOT_FOUND";
809 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
811 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
812 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
813 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
815 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
816 errorCode
= "INET_E_DOWNLOAD_FAILURE";
817 errorType
= wxWEB_NAV_ERR_CONNECTION
;
819 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
820 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
821 errorType
= wxWEB_NAV_ERR_AUTH
;
823 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
824 errorCode
= "INET_E_NO_VALID_MEDIA";
825 errorType
= wxWEB_NAV_ERR_REQUEST
;
827 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
828 errorCode
= "INET_E_CONNECTION_TIMEOUT";
829 errorType
= wxWEB_NAV_ERR_CONNECTION
;
831 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
832 errorCode
= "INET_E_INVALID_REQUEST";
833 errorType
= wxWEB_NAV_ERR_REQUEST
;
835 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
836 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
837 errorType
= wxWEB_NAV_ERR_REQUEST
;
839 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
840 errorCode
= "INET_E_SECURITY_PROBLEM";
841 errorType
= wxWEB_NAV_ERR_SECURITY
;
843 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
844 errorCode
= "INET_E_CANNOT_LOAD_DATA";
845 errorType
= wxWEB_NAV_ERR_OTHER
;
847 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
848 // CoCreateInstance will return an error code if this happens,
849 // we'll handle this above.
852 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
853 errorCode
= "INET_E_REDIRECT_FAILED";
854 errorType
= wxWEB_NAV_ERR_OTHER
;
856 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
857 errorCode
= "INET_E_REDIRECT_TO_DIR";
858 errorType
= wxWEB_NAV_ERR_REQUEST
;
860 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
861 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
862 errorType
= wxWEB_NAV_ERR_OTHER
;
864 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
865 errorCode
= "INET_E_USE_EXTEND_BINDING";
866 errorType
= wxWEB_NAV_ERR_OTHER
;
868 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
869 errorCode
= "INET_E_TERMINATED_BIND";
870 errorType
= wxWEB_NAV_ERR_OTHER
;
872 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
873 errorCode
= "INET_E_INVALID_CERTIFICATE";
874 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
876 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
877 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
878 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
880 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
881 // cancel request cancelled...
882 errorCode
= "INET_E_RESULT_DISPATCHED";
883 errorType
= wxWEB_NAV_ERR_OTHER
;
885 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
886 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
887 errorType
= wxWEB_NAV_ERR_SECURITY
;
889 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
890 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
891 errorType
= wxWEB_NAV_ERR_SECURITY
;
893 case INET_E_CODE_INSTALL_SUPPRESSED
:
894 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
895 errorType
= wxWEB_NAV_ERR_SECURITY
;
899 wxString url
= evt
[1].GetString();
900 wxString target
= evt
[2].GetString();
901 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
903 event
.SetEventObject(this);
904 event
.SetInt(errorType
);
905 event
.SetString(errorCode
);
906 HandleWindowEvent(event
);
910 case DISPID_COMMANDSTATECHANGE
:
912 long commandId
= evt
[0].GetLong();
913 bool enable
= evt
[1].GetBool();
914 if (commandId
== CSC_NAVIGATEBACK
)
916 m_canNavigateBack
= enable
;
918 else if (commandId
== CSC_NAVIGATEFORWARD
)
920 m_canNavigateForward
= enable
;
924 case DISPID_NEWWINDOW3
:
926 wxString url
= evt
[4].GetString();
928 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
929 GetId(), url
, wxEmptyString
, true);
930 event
.SetEventObject(this);
931 HandleWindowEvent(event
);
933 //If we veto the event then we cancel the new window
934 if (event
.IsVetoed())
936 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
937 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;