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, 2011 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"
19 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE
26 #include "wx/msw/registry.h"
27 #include "wx/msw/missing.h"
28 #include "wx/filesys.h"
29 #include "wx/dynlib.h"
32 /* These GUID definitions are our own implementation to support interfaces
33 * normally in urlmon.h. See include/wx/msw/webview_ie.h
38 DEFINE_GUID(wxIID_IInternetProtocolRoot
,0x79eac9e3,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb);
39 DEFINE_GUID(wxIID_IInternetProtocol
,0x79eac9e4,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb);
43 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewIE
, wxWebView
);
45 BEGIN_EVENT_TABLE(wxWebViewIE
, wxControl
)
46 EVT_ACTIVEX(wxID_ANY
, wxWebViewIE::onActiveXEvent
)
47 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg
)
50 bool wxWebViewIE::Create(wxWindow
* parent
,
58 if (!wxControl::Create(parent
, id
, pos
, size
, style
,
59 wxDefaultValidator
, name
))
66 m_historyLoadingFromList
= false;
67 m_historyEnabled
= true;
68 m_historyPosition
= -1;
69 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
71 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
72 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
73 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
75 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
79 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
81 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
82 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
84 m_container
= new wxActiveXContainer(this, IID_IWebBrowser2
, m_webBrowser
);
90 wxWebViewIE::~wxWebViewIE()
92 for(unsigned int i
= 0; i
< m_factories
.size(); i
++)
94 m_factories
[i
]->Release();
98 void wxWebViewIE::LoadURL(const wxString
& url
)
100 m_ie
.CallMethod("Navigate", wxConvertStringToOle(url
));
103 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
& baseUrl
)
105 BSTR bstr
= SysAllocString(OLESTR(""));
106 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
107 if (psaStrings
!= NULL
)
110 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
112 param
->bstrVal
= bstr
;
114 hr
= SafeArrayUnaccessData(psaStrings
);
116 IHTMLDocument2
* document
= GetDocument();
117 document
->write(psaStrings
);
121 SafeArrayDestroy(psaStrings
);
123 bstr
= SysAllocString(html
.wc_str());
125 // Creates a new one-dimensional array
126 psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
127 if (psaStrings
!= NULL
)
129 hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
131 param
->bstrVal
= bstr
;
132 hr
= SafeArrayUnaccessData(psaStrings
);
134 document
= GetDocument();
135 document
->write(psaStrings
);
138 // SafeArrayDestroy calls SysFreeString for each BSTR
139 SafeArrayDestroy(psaStrings
);
141 //We send the events when we are done to mimic webkit
143 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
144 GetId(), baseUrl
, "");
145 event
.SetEventObject(this);
146 HandleWindowEvent(event
);
148 //Document complete event
149 event
.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED
);
150 event
.SetEventObject(this);
151 HandleWindowEvent(event
);
155 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
160 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL during clear");
164 wxString
wxWebViewIE::GetPageSource() const
166 IHTMLDocument2
* document
= GetDocument();
167 IHTMLElement
*bodyTag
= NULL
;
168 IHTMLElement
*htmlTag
= NULL
;
170 HRESULT hr
= document
->get_body(&bodyTag
);
173 hr
= bodyTag
->get_parentElement(&htmlTag
);
177 htmlTag
->get_outerHTML(&bstr
);
178 source
= wxString(bstr
);
188 wxWebViewZoom
wxWebViewIE::GetZoom() const
192 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
193 return GetIEOpticalZoom();
194 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
195 return GetIETextZoom();
200 //Dummy return to stop compiler warnings
201 return wxWEB_VIEW_ZOOM_MEDIUM
;
205 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
209 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
210 SetIEOpticalZoom(zoom
);
212 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
220 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
222 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
223 //is 0 to 4 so the check is unnecessary, these match exactly with the
226 VariantInit (&zoomVariant
);
227 V_VT(&zoomVariant
) = VT_I4
;
228 V_I4(&zoomVariant
) = level
;
233 m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
234 OLECMDEXECOPT_DONTPROMPTUSER
,
236 wxASSERT(result
== S_OK
);
239 wxWebViewZoom
wxWebViewIE::GetIETextZoom() const
242 VariantInit (&zoomVariant
);
243 V_VT(&zoomVariant
) = VT_I4
;
248 m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
249 OLECMDEXECOPT_DONTPROMPTUSER
,
251 wxASSERT(result
== S_OK
);
253 //We can safely cast here as we know that the range matches our enum
254 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
257 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
259 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
260 //is 10 to 1000 so the check is unnecessary
262 VariantInit (&zoomVariant
);
263 V_VT(&zoomVariant
) = VT_I4
;
265 //We make a somewhat arbitray map here, taken from values used by webkit
268 case wxWEB_VIEW_ZOOM_TINY
:
269 V_I4(&zoomVariant
) = 60;
271 case wxWEB_VIEW_ZOOM_SMALL
:
272 V_I4(&zoomVariant
) = 80;
274 case wxWEB_VIEW_ZOOM_MEDIUM
:
275 V_I4(&zoomVariant
) = 100;
277 case wxWEB_VIEW_ZOOM_LARGE
:
278 V_I4(&zoomVariant
) = 130;
280 case wxWEB_VIEW_ZOOM_LARGEST
:
281 V_I4(&zoomVariant
) = 160;
290 m_webBrowser
->ExecWB((OLECMDID
)63 /*OLECMDID_OPTICAL_ZOOM*/,
291 OLECMDEXECOPT_DODEFAULT
,
294 wxASSERT(result
== S_OK
);
297 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom() const
300 VariantInit (&zoomVariant
);
301 V_VT(&zoomVariant
) = VT_I4
;
306 m_webBrowser
->ExecWB((OLECMDID
)63 /*OLECMDID_OPTICAL_ZOOM*/,
307 OLECMDEXECOPT_DODEFAULT
, NULL
,
309 wxASSERT(result
== S_OK
);
311 const int zoom
= V_I4(&zoomVariant
);
313 //We make a somewhat arbitray map here, taken from values used by webkit
316 return wxWEB_VIEW_ZOOM_TINY
;
318 else if (zoom
> 65 && zoom
<= 90)
320 return wxWEB_VIEW_ZOOM_SMALL
;
322 else if (zoom
> 90 && zoom
<= 115)
324 return wxWEB_VIEW_ZOOM_MEDIUM
;
326 else if (zoom
> 115 && zoom
<= 145)
328 return wxWEB_VIEW_ZOOM_LARGE
;
330 else /*if (zoom > 145) */ //Using else removes a compiler warning
332 return wxWEB_VIEW_ZOOM_LARGEST
;
336 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
341 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
346 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
348 //IE 6 and below only support text zoom, so check the registry to see what
349 //version we actually have
350 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
352 key
.QueryValue("Version", value
);
354 long version
= wxAtoi(value
.Left(1));
355 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
361 void wxWebViewIE::Print()
363 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
364 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
367 bool wxWebViewIE::CanGoBack() const
370 return m_historyPosition
> 0;
375 bool wxWebViewIE::CanGoForward() const
378 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
383 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
386 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
388 //We compare the actual pointers to find the correct item
389 if(m_historyList
[i
].get() == item
.get())
392 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
393 "invalid history item");
394 m_historyLoadingFromList
= true;
395 LoadURL(item
->GetUrl());
396 m_historyPosition
= pos
;
399 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewIE::GetBackwardHistory()
401 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
402 //As we don't have std::copy or an iterator constructor in the wxwidgets
403 //native vector we construct it by hand
404 for(int i
= 0; i
< m_historyPosition
; i
++)
406 backhist
.push_back(m_historyList
[i
]);
411 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewIE::GetForwardHistory()
413 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
414 //As we don't have std::copy or an iterator constructor in the wxwidgets
415 //native vector we construct it by hand
416 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
418 forwardhist
.push_back(m_historyList
[i
]);
423 void wxWebViewIE::GoBack()
425 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
428 void wxWebViewIE::GoForward()
430 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
433 void wxWebViewIE::Stop()
435 m_ie
.CallMethod("Stop");
438 void wxWebViewIE::ClearHistory()
440 m_historyList
.clear();
441 m_historyPosition
= -1;
444 void wxWebViewIE::EnableHistory(bool enable
)
446 m_historyEnabled
= enable
;
447 m_historyList
.clear();
448 m_historyPosition
= -1;
451 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
455 V_VT(&level
) = VT_I2
;
459 case wxWEB_VIEW_RELOAD_DEFAULT
:
460 V_I2(&level
) = REFRESH_NORMAL
;
462 case wxWEB_VIEW_RELOAD_NO_CACHE
:
463 V_I2(&level
) = REFRESH_COMPLETELY
;
466 wxFAIL_MSG("Unexpected reload type");
469 m_webBrowser
->Refresh2(&level
);
472 bool wxWebViewIE::IsOfflineMode()
474 wxVariant out
= m_ie
.GetProperty("Offline");
476 wxASSERT(out
.GetType() == "bool");
478 return out
.GetBool();
481 void wxWebViewIE::SetOfflineMode(bool offline
)
483 // FIXME: the wxWidgets docs do not really document what the return
484 // parameter of PutProperty is
488 m_ie
.PutProperty("Offline", (offline
?
494 bool wxWebViewIE::IsBusy() const
496 if (m_isBusy
) return true;
498 wxVariant out
= m_ie
.GetProperty("Busy");
500 wxASSERT(out
.GetType() == "bool");
502 return out
.GetBool();
505 wxString
wxWebViewIE::GetCurrentURL() const
507 wxVariant out
= m_ie
.GetProperty("LocationURL");
509 wxASSERT(out
.GetType() == "string");
510 return out
.GetString();
513 wxString
wxWebViewIE::GetCurrentTitle() const
515 IHTMLDocument2
* document
= GetDocument();
518 document
->get_nameProp(&title
);
520 return wxString(title
);
523 bool wxWebViewIE::CanCut() const
525 return CanExecCommand("Cut");
528 bool wxWebViewIE::CanCopy() const
530 return CanExecCommand("Copy");
532 bool wxWebViewIE::CanPaste() const
534 return CanExecCommand("Paste");
537 void wxWebViewIE::Cut()
542 void wxWebViewIE::Copy()
547 void wxWebViewIE::Paste()
549 ExecCommand("Paste");
552 bool wxWebViewIE::CanUndo() const
554 return CanExecCommand("Undo");
556 bool wxWebViewIE::CanRedo() const
558 return CanExecCommand("Redo");
561 void wxWebViewIE::Undo()
566 void wxWebViewIE::Redo()
571 void wxWebViewIE::SetEditable(bool enable
)
573 IHTMLDocument2
* document
= GetDocument();
575 document
->put_designMode(SysAllocString(L
"On"));
577 document
->put_designMode(SysAllocString(L
"Off"));
582 bool wxWebViewIE::IsEditable() const
584 IHTMLDocument2
* document
= GetDocument();
586 document
->get_designMode(&mode
);
588 if(wxString(mode
) == "On")
594 void wxWebViewIE::SelectAll()
596 ExecCommand("SelectAll");
599 bool wxWebViewIE::HasSelection() const
601 IHTMLDocument2
* document
= GetDocument();
602 IHTMLSelectionObject
* selection
;
604 HRESULT hr
= document
->get_selection(&selection
);
608 selection
->get_type(&type
);
609 sel
= wxString(type
);
610 selection
->Release();
613 return sel
!= "None";
616 void wxWebViewIE::DeleteSelection()
618 ExecCommand("Delete");
621 wxString
wxWebViewIE::GetSelectedText() const
623 IHTMLDocument2
* document
= GetDocument();
624 IHTMLSelectionObject
* selection
;
626 HRESULT hr
= document
->get_selection(&selection
);
630 hr
= selection
->createRange(&disrange
);
633 IHTMLTxtRange
* range
;
634 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
638 range
->get_text(&text
);
639 selected
= wxString(text
);
644 selection
->Release();
650 wxString
wxWebViewIE::GetSelectedSource() const
652 IHTMLDocument2
* document
= GetDocument();
653 IHTMLSelectionObject
* selection
;
655 HRESULT hr
= document
->get_selection(&selection
);
659 hr
= selection
->createRange(&disrange
);
662 IHTMLTxtRange
* range
;
663 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
667 range
->get_htmlText(&text
);
668 selected
= wxString(text
);
673 selection
->Release();
679 void wxWebViewIE::ClearSelection()
681 IHTMLDocument2
* document
= GetDocument();
682 IHTMLSelectionObject
* selection
;
684 HRESULT hr
= document
->get_selection(&selection
);
688 selection
->Release();
693 wxString
wxWebViewIE::GetPageText() const
695 IHTMLDocument2
* document
= GetDocument();
698 HRESULT hr
= document
->get_body(&body
);
702 body
->get_innerText(&out
);
703 text
= wxString(out
);
710 void wxWebViewIE::RunScript(const wxString
& javascript
)
712 IHTMLDocument2
* document
= GetDocument();
713 IHTMLWindow2
* window
;
714 wxString language
= "javascript";
715 HRESULT hr
= document
->get_parentWindow(&window
);
720 V_VT(&level
) = VT_EMPTY
;
721 window
->execScript(SysAllocString(javascript
.wc_str()),
722 SysAllocString(language
.wc_str()),
728 void wxWebViewIE::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
730 wxDynamicLibrary
urlMon(wxT("urlmon.dll"));
731 if(urlMon
.HasSymbol(wxT("CoInternetGetSession")))
733 typedef HRESULT (WINAPI
*CoInternetGetSession_t
)(DWORD
, wxIInternetSession
**, DWORD
);
734 wxDYNLIB_FUNCTION(CoInternetGetSession_t
, CoInternetGetSession
, urlMon
);
736 ClassFactory
* cf
= new ClassFactory(handler
);
737 wxIInternetSession
* session
;
738 HRESULT res
= (*pfnCoInternetGetSession
)(0, &session
, 0);
741 wxFAIL_MSG("Could not retrive internet session");
744 HRESULT hr
= session
->RegisterNameSpace(cf
, CLSID_FileProtocol
,
745 handler
->GetName().wc_str(),
749 wxFAIL_MSG("Could not register protocol");
751 m_factories
.push_back(cf
);
755 wxFAIL_MSG("urlmon does not contain CoInternetGetSession");
759 bool wxWebViewIE::CanExecCommand(wxString command
) const
761 IHTMLDocument2
* document
= GetDocument();
762 VARIANT_BOOL enabled
;
764 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
767 return (enabled
== VARIANT_TRUE
);
770 void wxWebViewIE::ExecCommand(wxString command
)
772 IHTMLDocument2
* document
= GetDocument();
773 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
777 IHTMLDocument2
* wxWebViewIE::GetDocument() const
779 wxVariant variant
= m_ie
.GetProperty("Document");
780 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
787 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
789 if (m_webBrowser
== NULL
) return;
791 switch (evt
.GetDispatchId())
793 case DISPID_BEFORENAVIGATE2
:
797 wxString url
= evt
[1].GetString();
798 wxString target
= evt
[3].GetString();
800 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
801 GetId(), url
, target
);
803 //skip empty javascript events.
804 if(url
== "javascript:\"\"" && target
.IsEmpty())
810 event
.SetEventObject(this);
811 HandleWindowEvent(event
);
814 if (!event
.IsAllowed())
816 wxActiveXEventNativeMSW
* nativeParams
=
817 evt
.GetNativeParameters();
818 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
821 // at this point, either the navigation event has been cancelled
822 // and we're not busy, either it was accepted and IWebBrowser2's
823 // Busy property will be true; so we don't need our override
830 case DISPID_NAVIGATECOMPLETE2
:
832 wxString url
= evt
[1].GetString();
833 // TODO: set target parameter if possible
834 wxString target
= wxEmptyString
;
835 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
836 GetId(), url
, target
);
837 event
.SetEventObject(this);
838 HandleWindowEvent(event
);
842 case DISPID_PROGRESSCHANGE
:
848 case DISPID_DOCUMENTCOMPLETE
:
850 //Only send a complete even if we are actually finished, this brings
851 //the event in to line with webkit
853 m_webBrowser
->get_ReadyState( &rs
);
854 if(rs
!= READYSTATE_COMPLETE
)
857 wxString url
= evt
[1].GetString();
859 //As we are complete we also add to the history list, but not if the
860 //page is not the main page, ie it is a subframe
861 //We also have to check if we are loading a file:// url, if so we
862 //need to change the comparison as ie passes back a different style
864 if(m_historyEnabled
&& !m_historyLoadingFromList
&&
865 (url
== GetCurrentURL() ||
866 (GetCurrentURL().substr(0, 4) == "file" &&
867 wxFileSystem::URLToFileName(GetCurrentURL()).GetFullPath() == url
)))
869 //If we are not at the end of the list, then erase everything
870 //between us and the end before adding the new page
871 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
873 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
874 m_historyList
.end());
876 wxSharedPtr
<wxWebViewHistoryItem
> item(new wxWebViewHistoryItem(url
, GetCurrentTitle()));
877 m_historyList
.push_back(item
);
880 //Reset as we are done now
881 m_historyLoadingFromList
= false;
882 // TODO: set target parameter if possible
883 wxString target
= wxEmptyString
;
884 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
886 event
.SetEventObject(this);
887 HandleWindowEvent(event
);
891 case DISPID_STATUSTEXTCHANGE
:
896 case DISPID_TITLECHANGE
:
898 wxString title
= evt
[0].GetString();
900 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
901 GetId(), GetCurrentURL(), "");
902 event
.SetString(title
);
903 event
.SetEventObject(this);
904 HandleWindowEvent(event
);
908 case DISPID_NAVIGATEERROR
:
910 wxWebViewNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
911 wxString errorCode
= "?";
912 switch (evt
[3].GetLong())
914 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
915 errorCode
= "INET_E_INVALID_URL";
916 errorType
= wxWEB_NAV_ERR_REQUEST
;
918 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
919 errorCode
= "INET_E_NO_SESSION";
920 errorType
= wxWEB_NAV_ERR_CONNECTION
;
922 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
923 errorCode
= "INET_E_CANNOT_CONNECT";
924 errorType
= wxWEB_NAV_ERR_CONNECTION
;
926 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
927 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
928 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
930 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
931 errorCode
= "INET_E_OBJECT_NOT_FOUND";
932 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
934 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
935 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
936 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
938 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
939 errorCode
= "INET_E_DOWNLOAD_FAILURE";
940 errorType
= wxWEB_NAV_ERR_CONNECTION
;
942 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
943 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
944 errorType
= wxWEB_NAV_ERR_AUTH
;
946 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
947 errorCode
= "INET_E_NO_VALID_MEDIA";
948 errorType
= wxWEB_NAV_ERR_REQUEST
;
950 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
951 errorCode
= "INET_E_CONNECTION_TIMEOUT";
952 errorType
= wxWEB_NAV_ERR_CONNECTION
;
954 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
955 errorCode
= "INET_E_INVALID_REQUEST";
956 errorType
= wxWEB_NAV_ERR_REQUEST
;
958 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
959 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
960 errorType
= wxWEB_NAV_ERR_REQUEST
;
962 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
963 errorCode
= "INET_E_SECURITY_PROBLEM";
964 errorType
= wxWEB_NAV_ERR_SECURITY
;
966 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
967 errorCode
= "INET_E_CANNOT_LOAD_DATA";
968 errorType
= wxWEB_NAV_ERR_OTHER
;
970 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
971 // CoCreateInstance will return an error code if this happens,
972 // we'll handle this above.
975 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
976 errorCode
= "INET_E_REDIRECT_FAILED";
977 errorType
= wxWEB_NAV_ERR_OTHER
;
979 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
980 errorCode
= "INET_E_REDIRECT_TO_DIR";
981 errorType
= wxWEB_NAV_ERR_REQUEST
;
983 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
984 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
985 errorType
= wxWEB_NAV_ERR_OTHER
;
987 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
988 errorCode
= "INET_E_USE_EXTEND_BINDING";
989 errorType
= wxWEB_NAV_ERR_OTHER
;
991 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
992 errorCode
= "INET_E_TERMINATED_BIND";
993 errorType
= wxWEB_NAV_ERR_OTHER
;
995 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
996 errorCode
= "INET_E_INVALID_CERTIFICATE";
997 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
999 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
1000 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
1001 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
1003 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
1004 // cancel request cancelled...
1005 errorCode
= "INET_E_RESULT_DISPATCHED";
1006 errorType
= wxWEB_NAV_ERR_OTHER
;
1008 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
1009 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
1010 errorType
= wxWEB_NAV_ERR_SECURITY
;
1012 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
1013 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
1014 errorType
= wxWEB_NAV_ERR_SECURITY
;
1016 case INET_E_CODE_INSTALL_SUPPRESSED
:
1017 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
1018 errorType
= wxWEB_NAV_ERR_SECURITY
;
1022 wxString url
= evt
[1].GetString();
1023 wxString target
= evt
[2].GetString();
1024 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
1026 event
.SetEventObject(this);
1027 event
.SetInt(errorType
);
1028 event
.SetString(errorCode
);
1029 HandleWindowEvent(event
);
1032 case DISPID_NEWWINDOW3
:
1034 wxString url
= evt
[4].GetString();
1036 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
1037 GetId(), url
, wxEmptyString
);
1038 event
.SetEventObject(this);
1039 HandleWindowEvent(event
);
1041 //We always cancel this event otherwise an Internet Exporer window
1042 //is opened for the url
1043 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
1044 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;
1052 VirtualProtocol::VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
)
1055 m_handler
= handler
;
1058 BEGIN_IID_TABLE(VirtualProtocol
)
1060 ADD_RAW_IID(wxIID_IInternetProtocolRoot
)
1061 ADD_RAW_IID(wxIID_IInternetProtocol
)
1064 IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol
)
1066 HRESULT
VirtualProtocol::Start(LPCWSTR szUrl
, wxIInternetProtocolSink
*pOIProtSink
,
1067 wxIInternetBindInfo
*pOIBindInfo
, DWORD grfPI
,
1068 HANDLE_PTR dwReserved
)
1071 wxUnusedVar(pOIBindInfo
);
1073 wxUnusedVar(dwReserved
);
1074 m_protocolSink
= pOIProtSink
;
1076 //We get the file itself from the protocol handler
1077 m_file
= m_handler
->GetFile(szUrl
);
1081 return INET_E_RESOURCE_NOT_FOUND
;
1083 //We return the stream length for current and total size as we can always
1084 //read the whole file from the stream
1085 wxFileOffset length
= m_file
->GetStream()->GetLength();
1086 m_protocolSink
->ReportData(wxBSCF_FIRSTDATANOTIFICATION
|
1087 wxBSCF_DATAFULLYAVAILABLE
|
1088 wxBSCF_LASTDATANOTIFICATION
,
1093 HRESULT
VirtualProtocol::Read(void *pv
, ULONG cb
, ULONG
*pcbRead
)
1095 //If the file is null we return false to indicte it is finished
1099 wxStreamError err
= m_file
->GetStream()->Read(pv
, cb
).GetLastError();
1100 *pcbRead
= m_file
->GetStream()->LastRead();
1102 if(err
== wxSTREAM_NO_ERROR
)
1107 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1109 //As we are not eof there is more data
1112 else if(err
== wxSTREAM_EOF
)
1115 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1116 //We are eof and so finished
1119 else if(err
== wxSTREAM_READ_ERROR
)
1122 return INET_E_DOWNLOAD_FAILURE
;
1126 //Dummy return to surpress a compiler warning
1128 return INET_E_DOWNLOAD_FAILURE
;
1132 BEGIN_IID_TABLE(ClassFactory
)
1134 ADD_IID(ClassFactory
)
1137 IMPLEMENT_IUNKNOWN_METHODS(ClassFactory
)
1139 HRESULT
ClassFactory::CreateInstance(IUnknown
* pUnkOuter
, REFIID riid
,
1143 return CLASS_E_NOAGGREGATION
;
1144 VirtualProtocol
* vp
= new VirtualProtocol(m_handler
);
1146 HRESULT hr
= vp
->QueryInterface(riid
, ppvObject
);
1152 STDMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
1158 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE