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
);
86 SetBackgroundStyle(wxBG_STYLE_PAINT
);
87 SetDoubleBuffered(true);
92 wxWebViewIE::~wxWebViewIE()
94 for(unsigned int i
= 0; i
< m_factories
.size(); i
++)
96 m_factories
[i
]->Release();
100 void wxWebViewIE::LoadURL(const wxString
& url
)
102 m_ie
.CallMethod("Navigate", wxConvertStringToOle(url
));
105 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
& baseUrl
)
107 BSTR bstr
= SysAllocString(html
.wc_str());
109 // Creates a new one-dimensional array
110 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
111 if (psaStrings
!= NULL
)
115 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
117 param
->bstrVal
= bstr
;
118 hr
= SafeArrayUnaccessData(psaStrings
);
120 IHTMLDocument2
* document
= GetDocument();
121 document
->write(psaStrings
);
124 // SafeArrayDestroy calls SysFreeString for each BSTR
125 SafeArrayDestroy(psaStrings
);
127 //We send the events when we are done to mimic webkit
129 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
130 GetId(), baseUrl
, "");
131 event
.SetEventObject(this);
132 HandleWindowEvent(event
);
134 //Document complete event
135 event
.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED
);
136 event
.SetEventObject(this);
137 HandleWindowEvent(event
);
141 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
146 wxString
wxWebViewIE::GetPageSource() const
148 IHTMLDocument2
* document
= GetDocument();
149 IHTMLElement
*bodyTag
= NULL
;
150 IHTMLElement
*htmlTag
= NULL
;
152 HRESULT hr
= document
->get_body(&bodyTag
);
155 hr
= bodyTag
->get_parentElement(&htmlTag
);
159 htmlTag
->get_outerHTML(&bstr
);
160 source
= wxString(bstr
);
170 wxWebViewZoom
wxWebViewIE::GetZoom() const
174 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
175 return GetIEOpticalZoom();
176 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
177 return GetIETextZoom();
182 //Dummy return to stop compiler warnings
183 return wxWEB_VIEW_ZOOM_MEDIUM
;
187 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
191 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
192 SetIEOpticalZoom(zoom
);
194 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
202 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
204 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
205 //is 0 to 4 so the check is unnecessary, these match exactly with the
208 VariantInit (&zoomVariant
);
209 V_VT(&zoomVariant
) = VT_I4
;
210 V_I4(&zoomVariant
) = level
;
215 m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
216 OLECMDEXECOPT_DONTPROMPTUSER
,
218 wxASSERT(result
== S_OK
);
221 wxWebViewZoom
wxWebViewIE::GetIETextZoom() const
224 VariantInit (&zoomVariant
);
225 V_VT(&zoomVariant
) = VT_I4
;
230 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;
272 m_webBrowser
->ExecWB((OLECMDID
)63 /*OLECMDID_OPTICAL_ZOOM*/,
273 OLECMDEXECOPT_DODEFAULT
,
276 wxASSERT(result
== S_OK
);
279 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom() const
282 VariantInit (&zoomVariant
);
283 V_VT(&zoomVariant
) = VT_I4
;
288 m_webBrowser
->ExecWB((OLECMDID
)63 /*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() const
352 return m_historyPosition
> 0;
357 bool wxWebViewIE::CanGoForward() const
360 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
365 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> 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
<wxWebViewHistoryItem
> > wxWebViewIE::GetBackwardHistory()
383 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > 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
<wxWebViewHistoryItem
> > wxWebViewIE::GetForwardHistory()
395 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > 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
470 m_ie
.PutProperty("Offline", (offline
?
476 bool wxWebViewIE::IsBusy() const
478 if (m_isBusy
) return true;
480 wxVariant out
= m_ie
.GetProperty("Busy");
482 wxASSERT(out
.GetType() == "bool");
484 return out
.GetBool();
487 wxString
wxWebViewIE::GetCurrentURL() const
489 wxVariant out
= m_ie
.GetProperty("LocationURL");
491 wxASSERT(out
.GetType() == "string");
492 return out
.GetString();
495 wxString
wxWebViewIE::GetCurrentTitle() const
497 IHTMLDocument2
* document
= GetDocument();
500 document
->get_nameProp(&title
);
502 return wxString(title
);
505 bool wxWebViewIE::CanCut() const
507 return CanExecCommand("Cut");
510 bool wxWebViewIE::CanCopy() const
512 return CanExecCommand("Copy");
514 bool wxWebViewIE::CanPaste() const
516 return CanExecCommand("Paste");
519 void wxWebViewIE::Cut()
524 void wxWebViewIE::Copy()
529 void wxWebViewIE::Paste()
531 ExecCommand("Paste");
534 bool wxWebViewIE::CanUndo() const
536 return CanExecCommand("Undo");
538 bool wxWebViewIE::CanRedo() const
540 return CanExecCommand("Redo");
543 void wxWebViewIE::Undo()
548 void wxWebViewIE::Redo()
553 void wxWebViewIE::SetEditable(bool enable
)
555 IHTMLDocument2
* document
= GetDocument();
557 document
->put_designMode(SysAllocString(L
"On"));
559 document
->put_designMode(SysAllocString(L
"Off"));
564 bool wxWebViewIE::IsEditable() const
566 IHTMLDocument2
* document
= GetDocument();
568 document
->get_designMode(&mode
);
570 if(wxString(mode
) == "On")
576 void wxWebViewIE::SelectAll()
578 ExecCommand("SelectAll");
581 bool wxWebViewIE::HasSelection() const
583 IHTMLDocument2
* document
= GetDocument();
584 IHTMLSelectionObject
* selection
;
586 HRESULT hr
= document
->get_selection(&selection
);
590 selection
->get_type(&type
);
591 sel
= wxString(type
);
592 selection
->Release();
595 return sel
!= "None";
598 void wxWebViewIE::DeleteSelection()
600 ExecCommand("Delete");
603 wxString
wxWebViewIE::GetSelectedText() const
605 IHTMLDocument2
* document
= GetDocument();
606 IHTMLSelectionObject
* selection
;
608 HRESULT hr
= document
->get_selection(&selection
);
612 hr
= selection
->createRange(&disrange
);
615 IHTMLTxtRange
* range
;
616 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
620 range
->get_text(&text
);
621 selected
= wxString(text
);
626 selection
->Release();
632 wxString
wxWebViewIE::GetSelectedSource() const
634 IHTMLDocument2
* document
= GetDocument();
635 IHTMLSelectionObject
* selection
;
637 HRESULT hr
= document
->get_selection(&selection
);
641 hr
= selection
->createRange(&disrange
);
644 IHTMLTxtRange
* range
;
645 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
649 range
->get_htmlText(&text
);
650 selected
= wxString(text
);
655 selection
->Release();
661 void wxWebViewIE::ClearSelection()
663 IHTMLDocument2
* document
= GetDocument();
664 IHTMLSelectionObject
* selection
;
666 HRESULT hr
= document
->get_selection(&selection
);
670 selection
->Release();
675 wxString
wxWebViewIE::GetPageText() const
677 IHTMLDocument2
* document
= GetDocument();
680 HRESULT hr
= document
->get_body(&body
);
684 body
->get_innerText(&out
);
685 text
= wxString(out
);
692 void wxWebViewIE::RunScript(const wxString
& javascript
)
694 IHTMLDocument2
* document
= GetDocument();
695 IHTMLWindow2
* window
;
696 wxString language
= "javascript";
697 HRESULT hr
= document
->get_parentWindow(&window
);
702 V_VT(&level
) = VT_EMPTY
;
703 window
->execScript(SysAllocString(javascript
), SysAllocString(language
), &level
);
708 void wxWebViewIE::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
710 wxDynamicLibrary
urlMon(wxT("urlmon.dll"));
711 if(urlMon
.HasSymbol(wxT("CoInternetGetSession")))
713 typedef HRESULT (WINAPI
*CoInternetGetSession_t
)(DWORD
, wxIInternetSession
**, DWORD
);
714 wxDYNLIB_FUNCTION(CoInternetGetSession_t
, CoInternetGetSession
, urlMon
);
716 ClassFactory
* cf
= new ClassFactory(handler
);
717 wxIInternetSession
* session
;
718 HRESULT res
= (*pfnCoInternetGetSession
)(0, &session
, 0);
721 wxFAIL_MSG("Could not retrive internet session");
724 HRESULT hr
= session
->RegisterNameSpace(cf
, CLSID_FileProtocol
, handler
->GetName(), 0, NULL
, 0);
727 wxFAIL_MSG("Could not register protocol");
729 m_factories
.push_back(cf
);
733 wxFAIL_MSG("urlmon does not contain CoInternetGetSession");
737 bool wxWebViewIE::CanExecCommand(wxString command
) const
739 IHTMLDocument2
* document
= GetDocument();
740 VARIANT_BOOL enabled
;
742 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
745 return (enabled
== VARIANT_TRUE
);
748 void wxWebViewIE::ExecCommand(wxString command
)
750 IHTMLDocument2
* document
= GetDocument();
751 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
755 IHTMLDocument2
* wxWebViewIE::GetDocument() const
757 wxVariant variant
= m_ie
.GetProperty("Document");
758 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
765 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
767 if (m_webBrowser
== NULL
) return;
769 switch (evt
.GetDispatchId())
771 case DISPID_BEFORENAVIGATE2
:
775 wxString url
= evt
[1].GetString();
776 wxString target
= evt
[3].GetString();
778 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
779 GetId(), url
, target
);
781 //skip empty javascript events.
782 if(url
== "javascript:\"\"" && target
.IsEmpty())
788 event
.SetEventObject(this);
789 HandleWindowEvent(event
);
792 if (!event
.IsAllowed())
794 wxActiveXEventNativeMSW
* nativeParams
=
795 evt
.GetNativeParameters();
796 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
799 // at this point, either the navigation event has been cancelled
800 // and we're not busy, either it was accepted and IWebBrowser2's
801 // Busy property will be true; so we don't need our override
808 case DISPID_NAVIGATECOMPLETE2
:
810 wxString url
= evt
[1].GetString();
811 // TODO: set target parameter if possible
812 wxString target
= wxEmptyString
;
813 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
814 GetId(), url
, target
);
815 event
.SetEventObject(this);
816 HandleWindowEvent(event
);
820 case DISPID_PROGRESSCHANGE
:
826 case DISPID_DOCUMENTCOMPLETE
:
828 //Only send a complete even if we are actually finished, this brings
829 //the event in to line with webkit
831 m_webBrowser
->get_ReadyState( &rs
);
832 if(rs
!= READYSTATE_COMPLETE
)
835 wxString url
= evt
[1].GetString();
837 //As we are complete we also add to the history list, but not if the
838 //page is not the main page, ie it is a subframe
839 //We also have to check if we are loading a file:// url, if so we
840 //need to change the comparison as ie passes back a different style
842 if(m_historyEnabled
&& !m_historyLoadingFromList
&&
843 (url
== GetCurrentURL() ||
844 (GetCurrentURL().substr(0, 4) == "file" &&
845 wxFileSystem::URLToFileName(GetCurrentURL()).GetFullPath() == url
)))
847 //If we are not at the end of the list, then erase everything
848 //between us and the end before adding the new page
849 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
851 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
852 m_historyList
.end());
854 wxSharedPtr
<wxWebViewHistoryItem
> item(new wxWebViewHistoryItem(url
, GetCurrentTitle()));
855 m_historyList
.push_back(item
);
858 //Reset as we are done now
859 m_historyLoadingFromList
= false;
860 // TODO: set target parameter if possible
861 wxString target
= wxEmptyString
;
862 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
864 event
.SetEventObject(this);
865 HandleWindowEvent(event
);
869 case DISPID_STATUSTEXTCHANGE
:
874 case DISPID_TITLECHANGE
:
876 wxString title
= evt
[0].GetString();
878 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
879 GetId(), GetCurrentURL(), "");
880 event
.SetString(title
);
881 event
.SetEventObject(this);
882 HandleWindowEvent(event
);
886 case DISPID_NAVIGATEERROR
:
888 wxWebViewNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
889 wxString errorCode
= "?";
890 switch (evt
[3].GetLong())
892 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
893 errorCode
= "INET_E_INVALID_URL";
894 errorType
= wxWEB_NAV_ERR_REQUEST
;
896 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
897 errorCode
= "INET_E_NO_SESSION";
898 errorType
= wxWEB_NAV_ERR_CONNECTION
;
900 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
901 errorCode
= "INET_E_CANNOT_CONNECT";
902 errorType
= wxWEB_NAV_ERR_CONNECTION
;
904 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
905 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
906 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
908 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
909 errorCode
= "INET_E_OBJECT_NOT_FOUND";
910 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
912 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
913 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
914 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
916 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
917 errorCode
= "INET_E_DOWNLOAD_FAILURE";
918 errorType
= wxWEB_NAV_ERR_CONNECTION
;
920 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
921 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
922 errorType
= wxWEB_NAV_ERR_AUTH
;
924 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
925 errorCode
= "INET_E_NO_VALID_MEDIA";
926 errorType
= wxWEB_NAV_ERR_REQUEST
;
928 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
929 errorCode
= "INET_E_CONNECTION_TIMEOUT";
930 errorType
= wxWEB_NAV_ERR_CONNECTION
;
932 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
933 errorCode
= "INET_E_INVALID_REQUEST";
934 errorType
= wxWEB_NAV_ERR_REQUEST
;
936 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
937 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
938 errorType
= wxWEB_NAV_ERR_REQUEST
;
940 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
941 errorCode
= "INET_E_SECURITY_PROBLEM";
942 errorType
= wxWEB_NAV_ERR_SECURITY
;
944 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
945 errorCode
= "INET_E_CANNOT_LOAD_DATA";
946 errorType
= wxWEB_NAV_ERR_OTHER
;
948 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
949 // CoCreateInstance will return an error code if this happens,
950 // we'll handle this above.
953 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
954 errorCode
= "INET_E_REDIRECT_FAILED";
955 errorType
= wxWEB_NAV_ERR_OTHER
;
957 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
958 errorCode
= "INET_E_REDIRECT_TO_DIR";
959 errorType
= wxWEB_NAV_ERR_REQUEST
;
961 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
962 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
963 errorType
= wxWEB_NAV_ERR_OTHER
;
965 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
966 errorCode
= "INET_E_USE_EXTEND_BINDING";
967 errorType
= wxWEB_NAV_ERR_OTHER
;
969 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
970 errorCode
= "INET_E_TERMINATED_BIND";
971 errorType
= wxWEB_NAV_ERR_OTHER
;
973 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
974 errorCode
= "INET_E_INVALID_CERTIFICATE";
975 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
977 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
978 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
979 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
981 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
982 // cancel request cancelled...
983 errorCode
= "INET_E_RESULT_DISPATCHED";
984 errorType
= wxWEB_NAV_ERR_OTHER
;
986 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
987 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
988 errorType
= wxWEB_NAV_ERR_SECURITY
;
990 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
991 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
992 errorType
= wxWEB_NAV_ERR_SECURITY
;
994 case INET_E_CODE_INSTALL_SUPPRESSED
:
995 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
996 errorType
= wxWEB_NAV_ERR_SECURITY
;
1000 wxString url
= evt
[1].GetString();
1001 wxString target
= evt
[2].GetString();
1002 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
1004 event
.SetEventObject(this);
1005 event
.SetInt(errorType
);
1006 event
.SetString(errorCode
);
1007 HandleWindowEvent(event
);
1010 case DISPID_NEWWINDOW3
:
1012 wxString url
= evt
[4].GetString();
1014 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
1015 GetId(), url
, wxEmptyString
);
1016 event
.SetEventObject(this);
1017 HandleWindowEvent(event
);
1019 //We always cancel this event otherwise an Internet Exporer window
1020 //is opened for the url
1021 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
1022 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;
1030 VirtualProtocol::VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
)
1034 m_handler
= handler
;
1037 VirtualProtocol::~VirtualProtocol()
1041 ULONG
VirtualProtocol::AddRef()
1047 HRESULT
VirtualProtocol::QueryInterface(REFIID riid
, void **ppvObject
)
1049 if(riid
== IID_IUnknown
|| riid
== wxIID_IInternetProtocolRoot
||
1050 riid
== wxIID_IInternetProtocol
)
1052 *ppvObject
= (wxIInternetProtocol
*)this;
1063 ULONG
VirtualProtocol::Release()
1077 HRESULT
VirtualProtocol::Start(LPCWSTR szUrl
, wxIInternetProtocolSink
*pOIProtSink
,
1078 wxIInternetBindInfo
*pOIBindInfo
, DWORD grfPI
,
1079 HANDLE_PTR dwReserved
)
1082 wxUnusedVar(pOIBindInfo
);
1084 wxUnusedVar(dwReserved
);
1085 m_protocolSink
= pOIProtSink
;
1087 //We get the file itself from the protocol handler
1088 m_file
= m_handler
->GetFile(szUrl
);
1092 return INET_E_RESOURCE_NOT_FOUND
;
1094 //We return the stream length for current and total size as we can always
1095 //read the whole file from the stream
1096 wxFileOffset length
= m_file
->GetStream()->GetLength();
1097 m_protocolSink
->ReportData(wxBSCF_FIRSTDATANOTIFICATION
|
1098 wxBSCF_DATAFULLYAVAILABLE
|
1099 wxBSCF_LASTDATANOTIFICATION
,
1104 HRESULT
VirtualProtocol::Read(void *pv
, ULONG cb
, ULONG
*pcbRead
)
1106 //If the file is null we return false to indicte it is finished
1110 wxStreamError err
= m_file
->GetStream()->Read(pv
, cb
).GetLastError();
1111 *pcbRead
= m_file
->GetStream()->LastRead();
1113 if(err
== wxSTREAM_NO_ERROR
)
1118 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1120 //As we are not eof there is more data
1123 else if(err
== wxSTREAM_EOF
)
1126 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1127 //We are eof and so finished
1130 else if(err
== wxSTREAM_READ_ERROR
)
1133 return INET_E_DOWNLOAD_FAILURE
;
1137 //Dummy return to surpress a compiler warning
1139 return INET_E_DOWNLOAD_FAILURE
;
1143 HRESULT
ClassFactory::CreateInstance(IUnknown
* pUnkOuter
, REFIID riid
,
1147 return CLASS_E_NOAGGREGATION
;
1148 VirtualProtocol
* vp
= new VirtualProtocol(m_handler
);
1150 HRESULT hr
= vp
->QueryInterface(riid
, ppvObject
);
1156 STDMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
1162 ULONG
ClassFactory::AddRef(void)
1168 HRESULT
ClassFactory::QueryInterface(REFIID riid
, void **ppvObject
)
1170 if ((riid
== IID_IUnknown
) || (riid
== IID_IClassFactory
))
1184 ULONG
ClassFactory::Release(void)
1199 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE