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"
26 #include "wx/msw/registry.h"
27 #include "wx/msw/missing.h"
28 #include "wx/filesys.h"
30 //Taken from wx/filesys.cpp
31 static wxString
EscapeFileNameCharsInURL(const char *in
)
35 for ( const unsigned char *p
= (const unsigned char*)in
; *p
; ++p
)
37 const unsigned char c
= *p
;
39 if ( c
== '/' || c
== '-' || c
== '.' || c
== '_' || c
== '~' ||
40 (c
>= '0' && c
<= '9') ||
41 (c
>= 'a' && c
<= 'z') ||
42 (c
>= 'A' && c
<= 'Z') )
48 s
<< wxString::Format("%%%02x", c
);
55 BEGIN_EVENT_TABLE(wxWebViewIE
, wxControl
)
56 EVT_ACTIVEX(wxID_ANY
, wxWebViewIE::onActiveXEvent
)
57 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg
)
60 bool wxWebViewIE::Create(wxWindow
* parent
,
68 if (!wxControl::Create(parent
, id
, pos
, size
, style
,
69 wxDefaultValidator
, name
))
75 m_canNavigateBack
= false;
76 m_canNavigateForward
= false;
78 m_historyLoadingFromList
= false;
79 m_historyEnabled
= true;
80 m_historyPosition
= -1;
81 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
83 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
84 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
85 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
87 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
91 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
93 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
94 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
95 //m_webBrowser->put_Silent(VARIANT_FALSE);
97 //We register a custom handler for the file protocol so we can handle
98 //Virtual file systems
99 ClassFactory
* cf
= new ClassFactory
;
100 IInternetSession
* session
;
101 if(CoInternetGetSession(0, &session
, 0) != S_OK
)
103 HRESULT hr
= session
->RegisterNameSpace(cf
, CLSID_FileProtocol
, L
"file", 0, NULL
, 0);
107 m_container
= new wxActiveXContainer(this, IID_IWebBrowser2
, m_webBrowser
);
109 SetBackgroundStyle(wxBG_STYLE_PAINT
);
110 SetDoubleBuffered(true);
116 void wxWebViewIE::LoadUrl(const wxString
& url
)
118 m_ie
.CallMethod("Navigate", (BSTR
) url
.wc_str(), NULL
, NULL
, NULL
, NULL
);
121 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
& baseUrl
)
123 BSTR bstr
= SysAllocString(html
.wc_str());
125 // Creates a new one-dimensional array
126 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
127 if (psaStrings
!= NULL
)
131 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
133 param
->bstrVal
= bstr
;
134 hr
= SafeArrayUnaccessData(psaStrings
);
136 IHTMLDocument2
* document
= GetDocument();
137 document
->write(psaStrings
);
140 // SafeArrayDestroy calls SysFreeString for each BSTR
141 SafeArrayDestroy(psaStrings
);
143 //We send the events when we are done to mimic webkit
145 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
146 GetId(), baseUrl
, "", false);
147 event
.SetEventObject(this);
148 HandleWindowEvent(event
);
150 //Document complete event
151 event
.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED
);
152 event
.SetEventObject(this);
153 HandleWindowEvent(event
);
157 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
162 wxString
wxWebViewIE::GetPageSource()
164 IHTMLDocument2
* document
= GetDocument();
165 IHTMLElement
*bodyTag
= NULL
;
166 IHTMLElement
*htmlTag
= NULL
;
168 HRESULT hr
= document
->get_body(&bodyTag
);
171 hr
= bodyTag
->get_parentElement(&htmlTag
);
175 htmlTag
->get_outerHTML(&bstr
);
176 source
= wxString(bstr
);
186 wxWebViewZoom
wxWebViewIE::GetZoom()
188 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
189 return GetIEOpticalZoom();
190 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
191 return GetIETextZoom();
195 //Dummy return to stop compiler warnings
196 return wxWEB_VIEW_ZOOM_MEDIUM
;
200 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
202 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
203 SetIEOpticalZoom(zoom
);
204 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
210 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
212 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
213 //is 0 to 4 so the check is unnecessary, these match exactly with the
216 VariantInit (&zoomVariant
);
217 V_VT(&zoomVariant
) = VT_I4
;
218 V_I4(&zoomVariant
) = level
;
220 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
221 OLECMDEXECOPT_DONTPROMPTUSER
,
223 wxASSERT(result
== S_OK
);
226 wxWebViewZoom
wxWebViewIE::GetIETextZoom()
229 VariantInit (&zoomVariant
);
230 V_VT(&zoomVariant
) = VT_I4
;
232 HRESULT result
= m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
233 OLECMDEXECOPT_DONTPROMPTUSER
,
235 wxASSERT(result
== S_OK
);
237 //We can safely cast here as we know that the range matches our enum
238 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
241 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
243 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
244 //is 10 to 1000 so the check is unnecessary
246 VariantInit (&zoomVariant
);
247 V_VT(&zoomVariant
) = VT_I4
;
249 //We make a somewhat arbitray map here, taken from values used by webkit
252 case wxWEB_VIEW_ZOOM_TINY
:
253 V_I4(&zoomVariant
) = 60;
255 case wxWEB_VIEW_ZOOM_SMALL
:
256 V_I4(&zoomVariant
) = 80;
258 case wxWEB_VIEW_ZOOM_MEDIUM
:
259 V_I4(&zoomVariant
) = 100;
261 case wxWEB_VIEW_ZOOM_LARGE
:
262 V_I4(&zoomVariant
) = 130;
264 case wxWEB_VIEW_ZOOM_LARGEST
:
265 V_I4(&zoomVariant
) = 160;
271 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
272 OLECMDEXECOPT_DODEFAULT
,
275 wxASSERT(result
== S_OK
);
278 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom()
281 VariantInit (&zoomVariant
);
282 V_VT(&zoomVariant
) = VT_I4
;
284 HRESULT result
= m_webBrowser
->ExecWB((OLECMDID
)OLECMDID_OPTICAL_ZOOM
,
285 OLECMDEXECOPT_DODEFAULT
, NULL
,
287 wxASSERT(result
== S_OK
);
289 const int zoom
= V_I4(&zoomVariant
);
291 //We make a somewhat arbitray map here, taken from values used by webkit
294 return wxWEB_VIEW_ZOOM_TINY
;
296 else if (zoom
> 65 && zoom
<= 90)
298 return wxWEB_VIEW_ZOOM_SMALL
;
300 else if (zoom
> 90 && zoom
<= 115)
302 return wxWEB_VIEW_ZOOM_MEDIUM
;
304 else if (zoom
> 115 && zoom
<= 145)
306 return wxWEB_VIEW_ZOOM_LARGE
;
308 else /*if (zoom > 145) */ //Using else removes a compiler warning
310 return wxWEB_VIEW_ZOOM_LARGEST
;
314 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
319 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
324 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
326 //IE 6 and below only support text zoom, so check the registry to see what
327 //version we actually have
328 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
330 key
.QueryValue("Version", value
);
332 long version
= wxAtoi(value
.Left(1));
333 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
339 void wxWebViewIE::Print()
341 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
342 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
345 bool wxWebViewIE::CanGoBack()
348 return m_historyPosition
> 0;
353 bool wxWebViewIE::CanGoForward()
356 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
361 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
364 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
366 //We compare the actual pointers to find the correct item
367 if(m_historyList
[i
].get() == item
.get())
370 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
371 "invalid history item");
372 m_historyLoadingFromList
= true;
373 LoadUrl(item
->GetUrl());
374 m_historyPosition
= pos
;
377 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetBackwardHistory()
379 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
380 //As we don't have std::copy or an iterator constructor in the wxwidgets
381 //native vector we construct it by hand
382 for(int i
= 0; i
< m_historyPosition
; i
++)
384 backhist
.push_back(m_historyList
[i
]);
389 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetForwardHistory()
391 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
392 //As we don't have std::copy or an iterator constructor in the wxwidgets
393 //native vector we construct it by hand
394 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
396 forwardhist
.push_back(m_historyList
[i
]);
401 void wxWebViewIE::GoBack()
403 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
406 void wxWebViewIE::GoForward()
408 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
411 void wxWebViewIE::Stop()
413 m_ie
.CallMethod("Stop");
416 void wxWebViewIE::ClearHistory()
418 m_historyList
.clear();
419 m_historyPosition
= -1;
422 void wxWebViewIE::EnableHistory(bool enable
)
424 m_historyEnabled
= enable
;
425 m_historyList
.clear();
426 m_historyPosition
= -1;
429 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
433 V_VT(&level
) = VT_I2
;
437 case wxWEB_VIEW_RELOAD_DEFAULT
:
438 V_I2(&level
) = REFRESH_NORMAL
;
440 case wxWEB_VIEW_RELOAD_NO_CACHE
:
441 V_I2(&level
) = REFRESH_COMPLETELY
;
444 wxFAIL_MSG("Unexpected reload type");
447 m_webBrowser
->Refresh2(&level
);
450 bool wxWebViewIE::IsOfflineMode()
452 wxVariant out
= m_ie
.GetProperty("Offline");
454 wxASSERT(out
.GetType() == "bool");
456 return out
.GetBool();
459 void wxWebViewIE::SetOfflineMode(bool offline
)
461 // FIXME: the wxWidgets docs do not really document what the return
462 // parameter of PutProperty is
463 const bool success
= m_ie
.PutProperty("Offline", (offline
?
469 bool wxWebViewIE::IsBusy()
471 if (m_isBusy
) return true;
473 wxVariant out
= m_ie
.GetProperty("Busy");
475 wxASSERT(out
.GetType() == "bool");
477 return out
.GetBool();
480 wxString
wxWebViewIE::GetCurrentURL()
482 wxVariant out
= m_ie
.GetProperty("LocationURL");
484 wxASSERT(out
.GetType() == "string");
485 return out
.GetString();
488 wxString
wxWebViewIE::GetCurrentTitle()
490 IHTMLDocument2
* document
= GetDocument();
493 document
->get_nameProp(&title
);
495 return wxString(title
);
498 bool wxWebViewIE::CanCut()
500 return CanExecCommand("Cut");
503 bool wxWebViewIE::CanCopy()
505 return CanExecCommand("Copy");
507 bool wxWebViewIE::CanPaste()
509 return CanExecCommand("Paste");
512 void wxWebViewIE::Cut()
517 void wxWebViewIE::Copy()
522 void wxWebViewIE::Paste()
524 ExecCommand("Paste");
527 bool wxWebViewIE::CanUndo()
529 return CanExecCommand("Undo");
531 bool wxWebViewIE::CanRedo()
533 return CanExecCommand("Redo");
536 void wxWebViewIE::Undo()
541 void wxWebViewIE::Redo()
546 void wxWebViewIE::SetEditable(bool enable
)
548 IHTMLDocument2
* document
= GetDocument();
550 document
->put_designMode(SysAllocString(L
"On"));
552 document
->put_designMode(SysAllocString(L
"Off"));
557 bool wxWebViewIE::IsEditable()
559 IHTMLDocument2
* document
= GetDocument();
561 document
->get_designMode(&mode
);
563 if(wxString(mode
) == "On")
569 void wxWebViewIE::SelectAll()
571 ExecCommand("SelectAll");
574 bool wxWebViewIE::HasSelection()
576 IHTMLDocument2
* document
= GetDocument();
577 IHTMLSelectionObject
* selection
;
579 HRESULT hr
= document
->get_selection(&selection
);
583 selection
->get_type(&type
);
584 sel
= wxString(type
);
585 selection
->Release();
588 return sel
!= "None";
591 void wxWebViewIE::DeleteSelection()
593 ExecCommand("Delete");
596 wxString
wxWebViewIE::GetSelectedText()
598 IHTMLDocument2
* document
= GetDocument();
599 IHTMLSelectionObject
* selection
;
601 HRESULT hr
= document
->get_selection(&selection
);
605 hr
= selection
->createRange(&disrange
);
608 IHTMLTxtRange
* range
;
609 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
613 range
->get_text(&text
);
614 selected
= wxString(text
);
619 selection
->Release();
625 wxString
wxWebViewIE::GetSelectedSource()
627 IHTMLDocument2
* document
= GetDocument();
628 IHTMLSelectionObject
* selection
;
630 HRESULT hr
= document
->get_selection(&selection
);
634 hr
= selection
->createRange(&disrange
);
637 IHTMLTxtRange
* range
;
638 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
642 range
->get_htmlText(&text
);
643 selected
= wxString(text
);
648 selection
->Release();
654 void wxWebViewIE::ClearSelection()
656 IHTMLDocument2
* document
= GetDocument();
657 IHTMLSelectionObject
* selection
;
659 HRESULT hr
= document
->get_selection(&selection
);
663 selection
->Release();
668 wxString
wxWebViewIE::GetPageText()
670 IHTMLDocument2
* document
= GetDocument();
673 HRESULT hr
= document
->get_body(&body
);
677 body
->get_innerText(&out
);
678 text
= wxString(out
);
685 void wxWebViewIE::RunScript(const wxString
& javascript
)
687 IHTMLDocument2
* document
= GetDocument();
688 IHTMLWindow2
* window
;
689 wxString language
= "javascript";
690 HRESULT hr
= document
->get_parentWindow(&window
);
695 V_VT(&level
) = VT_EMPTY
;
696 window
->execScript(SysAllocString(javascript
), SysAllocString(language
), &level
);
701 bool wxWebViewIE::CanExecCommand(wxString command
)
703 IHTMLDocument2
* document
= GetDocument();
704 VARIANT_BOOL enabled
;
706 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
709 return (enabled
== VARIANT_TRUE
);
712 void wxWebViewIE::ExecCommand(wxString command
)
714 IHTMLDocument2
* document
= GetDocument();
715 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
719 IHTMLDocument2
* wxWebViewIE::GetDocument()
721 wxVariant variant
= m_ie
.GetProperty("Document");
722 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
729 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
731 if (m_webBrowser
== NULL
) return;
733 switch (evt
.GetDispatchId())
735 case DISPID_BEFORENAVIGATE2
:
739 wxString url
= evt
[1].GetString();
740 wxString target
= evt
[3].GetString();
742 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
743 GetId(), url
, target
, true);
744 event
.SetEventObject(this);
745 HandleWindowEvent(event
);
747 if (event
.IsVetoed())
749 wxActiveXEventNativeMSW
* nativeParams
=
750 evt
.GetNativeParameters();
751 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
754 // at this point, either the navigation event has been cancelled
755 // and we're not busy, either it was accepted and IWebBrowser2's
756 // Busy property will be true; so we don't need our override
763 case DISPID_NAVIGATECOMPLETE2
:
765 wxString url
= evt
[1].GetString();
766 // TODO: set target parameter if possible
767 wxString target
= wxEmptyString
;
768 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
769 GetId(), url
, target
, false);
770 event
.SetEventObject(this);
771 HandleWindowEvent(event
);
775 case DISPID_PROGRESSCHANGE
:
781 case DISPID_DOCUMENTCOMPLETE
:
783 //Only send a complete even if we are actually finished, this brings
784 //the event in to line with webkit
786 m_webBrowser
->get_ReadyState( &rs
);
787 if(rs
!= READYSTATE_COMPLETE
)
790 wxString url
= evt
[1].GetString();
792 //As we are complete we also add to the history list, but not if the
793 //page is not the main page, ie it is a subframe
794 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
796 //If we are not at the end of the list, then erase everything
797 //between us and the end before adding the new page
798 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
800 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
801 m_historyList
.end());
803 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
804 m_historyList
.push_back(item
);
807 //Reset as we are done now
808 m_historyLoadingFromList
= false;
809 // TODO: set target parameter if possible
810 wxString target
= wxEmptyString
;
811 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
813 event
.SetEventObject(this);
814 HandleWindowEvent(event
);
818 case DISPID_STATUSTEXTCHANGE
:
823 case DISPID_TITLECHANGE
:
828 case DISPID_NAVIGATEERROR
:
830 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
831 wxString errorCode
= "?";
832 switch (evt
[3].GetLong())
834 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
835 errorCode
= "INET_E_INVALID_URL";
836 errorType
= wxWEB_NAV_ERR_REQUEST
;
838 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
839 errorCode
= "INET_E_NO_SESSION";
840 errorType
= wxWEB_NAV_ERR_CONNECTION
;
842 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
843 errorCode
= "INET_E_CANNOT_CONNECT";
844 errorType
= wxWEB_NAV_ERR_CONNECTION
;
846 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
847 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
848 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
850 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
851 errorCode
= "INET_E_OBJECT_NOT_FOUND";
852 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
854 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
855 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
856 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
858 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
859 errorCode
= "INET_E_DOWNLOAD_FAILURE";
860 errorType
= wxWEB_NAV_ERR_CONNECTION
;
862 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
863 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
864 errorType
= wxWEB_NAV_ERR_AUTH
;
866 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
867 errorCode
= "INET_E_NO_VALID_MEDIA";
868 errorType
= wxWEB_NAV_ERR_REQUEST
;
870 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
871 errorCode
= "INET_E_CONNECTION_TIMEOUT";
872 errorType
= wxWEB_NAV_ERR_CONNECTION
;
874 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
875 errorCode
= "INET_E_INVALID_REQUEST";
876 errorType
= wxWEB_NAV_ERR_REQUEST
;
878 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
879 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
880 errorType
= wxWEB_NAV_ERR_REQUEST
;
882 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
883 errorCode
= "INET_E_SECURITY_PROBLEM";
884 errorType
= wxWEB_NAV_ERR_SECURITY
;
886 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
887 errorCode
= "INET_E_CANNOT_LOAD_DATA";
888 errorType
= wxWEB_NAV_ERR_OTHER
;
890 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
891 // CoCreateInstance will return an error code if this happens,
892 // we'll handle this above.
895 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
896 errorCode
= "INET_E_REDIRECT_FAILED";
897 errorType
= wxWEB_NAV_ERR_OTHER
;
899 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
900 errorCode
= "INET_E_REDIRECT_TO_DIR";
901 errorType
= wxWEB_NAV_ERR_REQUEST
;
903 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
904 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
905 errorType
= wxWEB_NAV_ERR_OTHER
;
907 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
908 errorCode
= "INET_E_USE_EXTEND_BINDING";
909 errorType
= wxWEB_NAV_ERR_OTHER
;
911 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
912 errorCode
= "INET_E_TERMINATED_BIND";
913 errorType
= wxWEB_NAV_ERR_OTHER
;
915 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
916 errorCode
= "INET_E_INVALID_CERTIFICATE";
917 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
919 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
920 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
921 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
923 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
924 // cancel request cancelled...
925 errorCode
= "INET_E_RESULT_DISPATCHED";
926 errorType
= wxWEB_NAV_ERR_OTHER
;
928 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
929 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
930 errorType
= wxWEB_NAV_ERR_SECURITY
;
932 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
933 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
934 errorType
= wxWEB_NAV_ERR_SECURITY
;
936 case INET_E_CODE_INSTALL_SUPPRESSED
:
937 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
938 errorType
= wxWEB_NAV_ERR_SECURITY
;
942 wxString url
= evt
[1].GetString();
943 wxString target
= evt
[2].GetString();
944 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
946 event
.SetEventObject(this);
947 event
.SetInt(errorType
);
948 event
.SetString(errorCode
);
949 HandleWindowEvent(event
);
953 case DISPID_COMMANDSTATECHANGE
:
955 long commandId
= evt
[0].GetLong();
956 bool enable
= evt
[1].GetBool();
957 if (commandId
== CSC_NAVIGATEBACK
)
959 m_canNavigateBack
= enable
;
961 else if (commandId
== CSC_NAVIGATEFORWARD
)
963 m_canNavigateForward
= enable
;
967 case DISPID_NEWWINDOW3
:
969 wxString url
= evt
[4].GetString();
971 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
972 GetId(), url
, wxEmptyString
, true);
973 event
.SetEventObject(this);
974 HandleWindowEvent(event
);
976 //If we veto the event then we cancel the new window
977 if (event
.IsVetoed())
979 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
980 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;
989 VirtualProtocol::VirtualProtocol()
993 m_fileSys
= new wxFileSystem
;
996 VirtualProtocol::~VirtualProtocol()
1001 ULONG
VirtualProtocol::AddRef()
1007 HRESULT
VirtualProtocol::QueryInterface(REFIID riid
, void **ppvObject
)
1009 if ((riid
== IID_IUnknown
) || (riid
== IID_IInternetProtocol
)
1010 || (riid
== IID_IInternetProtocolRoot
))
1023 ULONG
VirtualProtocol::Release()
1037 HRESULT
VirtualProtocol::Start(LPCWSTR szUrl
, IInternetProtocolSink
*pOIProtSink
,
1038 IInternetBindInfo
*pOIBindInfo
, DWORD grfPI
,
1039 HANDLE_PTR dwReserved
)
1041 m_protocolSink
= pOIProtSink
;
1042 //We have to clean up incoming paths from the webview control as they are
1043 //not properly escaped, see also the comment in filesys.cpp line 668
1044 wxString path
= wxString(szUrl
).BeforeFirst(':') + ":" +
1045 EscapeFileNameCharsInURL(wxString(szUrl
).AfterFirst(':'));
1046 path
.Replace("///", "/");
1047 m_file
= m_fileSys
->OpenFile(path
);
1050 return INET_E_RESOURCE_NOT_FOUND
;
1052 //We return the stream length for current and total size as we can always
1053 //read the whole file from the stream
1054 m_protocolSink
->ReportData(BSCF_FIRSTDATANOTIFICATION
|
1055 BSCF_DATAFULLYAVAILABLE
|
1056 BSCF_LASTDATANOTIFICATION
,
1057 m_file
->GetStream()->GetLength(),
1058 m_file
->GetStream()->GetLength());
1062 HRESULT
VirtualProtocol::Read(void *pv
, ULONG cb
, ULONG
*pcbRead
)
1064 //If the file is null we return false to indicte it is finished
1068 wxStreamError err
= m_file
->GetStream()->Read(pv
, cb
).GetLastError();
1069 *pcbRead
= m_file
->GetStream()->LastRead();
1071 if(err
== wxSTREAM_NO_ERROR
)
1076 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1078 //As we are not eof there is more data
1081 else if(err
== wxSTREAM_EOF
)
1084 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1085 //We are eof and so finished
1088 else if(err
== wxSTREAM_READ_ERROR
)
1091 return INET_E_DOWNLOAD_FAILURE
;
1095 HRESULT
ClassFactory::CreateInstance(IUnknown
* pUnkOuter
, REFIID riid
,
1099 return CLASS_E_NOAGGREGATION
;
1100 VirtualProtocol
* vp
= new VirtualProtocol
;
1102 HRESULT hr
= vp
->QueryInterface(riid
, ppvObject
);
1108 STDMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
1114 ULONG
ClassFactory::AddRef(void)
1120 HRESULT
ClassFactory::QueryInterface(REFIID riid
, void **ppvObject
)
1122 if ((riid
== IID_IUnknown
) || (riid
== IID_IClassFactory
))
1136 ULONG
ClassFactory::Release(void)