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
))
76 m_historyLoadingFromList
= false;
77 m_historyEnabled
= true;
78 m_historyPosition
= -1;
79 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
81 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
82 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
83 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
85 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
89 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
91 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
92 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
93 //m_webBrowser->put_Silent(VARIANT_FALSE);
95 //We register a custom handler for the file protocol so we can handle
96 //Virtual file systems
97 ClassFactory
* cf
= new ClassFactory
;
98 IInternetSession
* session
;
99 if(CoInternetGetSession(0, &session
, 0) != S_OK
)
101 HRESULT hr
= session
->RegisterNameSpace(cf
, CLSID_FileProtocol
, L
"file", 0, NULL
, 0);
105 m_container
= new wxActiveXContainer(this, IID_IWebBrowser2
, m_webBrowser
);
107 SetBackgroundStyle(wxBG_STYLE_PAINT
);
108 SetDoubleBuffered(true);
114 void wxWebViewIE::LoadUrl(const wxString
& url
)
116 m_ie
.CallMethod("Navigate", (BSTR
) url
.wc_str(), NULL
, NULL
, NULL
, NULL
);
119 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
& baseUrl
)
121 BSTR bstr
= SysAllocString(html
.wc_str());
123 // Creates a new one-dimensional array
124 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
125 if (psaStrings
!= NULL
)
129 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
131 param
->bstrVal
= bstr
;
132 hr
= SafeArrayUnaccessData(psaStrings
);
134 IHTMLDocument2
* 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 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
144 GetId(), baseUrl
, "", false);
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 wxString
wxWebViewIE::GetPageSource()
162 IHTMLDocument2
* document
= GetDocument();
163 IHTMLElement
*bodyTag
= NULL
;
164 IHTMLElement
*htmlTag
= NULL
;
166 HRESULT hr
= document
->get_body(&bodyTag
);
169 hr
= bodyTag
->get_parentElement(&htmlTag
);
173 htmlTag
->get_outerHTML(&bstr
);
174 source
= wxString(bstr
);
184 wxWebViewZoom
wxWebViewIE::GetZoom()
186 if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
187 return GetIEOpticalZoom();
188 else if(m_zoomType
== wxWEB_VIEW_ZOOM_TYPE_TEXT
)
189 return GetIETextZoom();
193 //Dummy return to stop compiler warnings
194 return wxWEB_VIEW_ZOOM_MEDIUM
;
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
;
306 else /*if (zoom > 145) */ //Using else removes a compiler warning
308 return wxWEB_VIEW_ZOOM_LARGEST
;
312 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
317 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
322 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
324 //IE 6 and below only support text zoom, so check the registry to see what
325 //version we actually have
326 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
328 key
.QueryValue("Version", value
);
330 long version
= wxAtoi(value
.Left(1));
331 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
337 void wxWebViewIE::Print()
339 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
340 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
343 bool wxWebViewIE::CanGoBack()
346 return m_historyPosition
> 0;
351 bool wxWebViewIE::CanGoForward()
354 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
359 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
362 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
364 //We compare the actual pointers to find the correct item
365 if(m_historyList
[i
].get() == item
.get())
368 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
369 "invalid history item");
370 m_historyLoadingFromList
= true;
371 LoadUrl(item
->GetUrl());
372 m_historyPosition
= pos
;
375 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetBackwardHistory()
377 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
378 //As we don't have std::copy or an iterator constructor in the wxwidgets
379 //native vector we construct it by hand
380 for(int i
= 0; i
< m_historyPosition
; i
++)
382 backhist
.push_back(m_historyList
[i
]);
387 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewIE::GetForwardHistory()
389 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
390 //As we don't have std::copy or an iterator constructor in the wxwidgets
391 //native vector we construct it by hand
392 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
394 forwardhist
.push_back(m_historyList
[i
]);
399 void wxWebViewIE::GoBack()
401 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
404 void wxWebViewIE::GoForward()
406 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
409 void wxWebViewIE::Stop()
411 m_ie
.CallMethod("Stop");
414 void wxWebViewIE::ClearHistory()
416 m_historyList
.clear();
417 m_historyPosition
= -1;
420 void wxWebViewIE::EnableHistory(bool enable
)
422 m_historyEnabled
= enable
;
423 m_historyList
.clear();
424 m_historyPosition
= -1;
427 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
431 V_VT(&level
) = VT_I2
;
435 case wxWEB_VIEW_RELOAD_DEFAULT
:
436 V_I2(&level
) = REFRESH_NORMAL
;
438 case wxWEB_VIEW_RELOAD_NO_CACHE
:
439 V_I2(&level
) = REFRESH_COMPLETELY
;
442 wxFAIL_MSG("Unexpected reload type");
445 m_webBrowser
->Refresh2(&level
);
448 bool wxWebViewIE::IsOfflineMode()
450 wxVariant out
= m_ie
.GetProperty("Offline");
452 wxASSERT(out
.GetType() == "bool");
454 return out
.GetBool();
457 void wxWebViewIE::SetOfflineMode(bool offline
)
459 // FIXME: the wxWidgets docs do not really document what the return
460 // parameter of PutProperty is
461 const bool success
= m_ie
.PutProperty("Offline", (offline
?
467 bool wxWebViewIE::IsBusy()
469 if (m_isBusy
) return true;
471 wxVariant out
= m_ie
.GetProperty("Busy");
473 wxASSERT(out
.GetType() == "bool");
475 return out
.GetBool();
478 wxString
wxWebViewIE::GetCurrentURL()
480 wxVariant out
= m_ie
.GetProperty("LocationURL");
482 wxASSERT(out
.GetType() == "string");
483 return out
.GetString();
486 wxString
wxWebViewIE::GetCurrentTitle()
488 IHTMLDocument2
* document
= GetDocument();
491 document
->get_nameProp(&title
);
493 return wxString(title
);
496 bool wxWebViewIE::CanCut()
498 return CanExecCommand("Cut");
501 bool wxWebViewIE::CanCopy()
503 return CanExecCommand("Copy");
505 bool wxWebViewIE::CanPaste()
507 return CanExecCommand("Paste");
510 void wxWebViewIE::Cut()
515 void wxWebViewIE::Copy()
520 void wxWebViewIE::Paste()
522 ExecCommand("Paste");
525 bool wxWebViewIE::CanUndo()
527 return CanExecCommand("Undo");
529 bool wxWebViewIE::CanRedo()
531 return CanExecCommand("Redo");
534 void wxWebViewIE::Undo()
539 void wxWebViewIE::Redo()
544 void wxWebViewIE::SetEditable(bool enable
)
546 IHTMLDocument2
* document
= GetDocument();
548 document
->put_designMode(SysAllocString(L
"On"));
550 document
->put_designMode(SysAllocString(L
"Off"));
555 bool wxWebViewIE::IsEditable()
557 IHTMLDocument2
* document
= GetDocument();
559 document
->get_designMode(&mode
);
561 if(wxString(mode
) == "On")
567 void wxWebViewIE::SelectAll()
569 ExecCommand("SelectAll");
572 bool wxWebViewIE::HasSelection()
574 IHTMLDocument2
* document
= GetDocument();
575 IHTMLSelectionObject
* selection
;
577 HRESULT hr
= document
->get_selection(&selection
);
581 selection
->get_type(&type
);
582 sel
= wxString(type
);
583 selection
->Release();
586 return sel
!= "None";
589 void wxWebViewIE::DeleteSelection()
591 ExecCommand("Delete");
594 wxString
wxWebViewIE::GetSelectedText()
596 IHTMLDocument2
* document
= GetDocument();
597 IHTMLSelectionObject
* selection
;
599 HRESULT hr
= document
->get_selection(&selection
);
603 hr
= selection
->createRange(&disrange
);
606 IHTMLTxtRange
* range
;
607 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
611 range
->get_text(&text
);
612 selected
= wxString(text
);
617 selection
->Release();
623 wxString
wxWebViewIE::GetSelectedSource()
625 IHTMLDocument2
* document
= GetDocument();
626 IHTMLSelectionObject
* selection
;
628 HRESULT hr
= document
->get_selection(&selection
);
632 hr
= selection
->createRange(&disrange
);
635 IHTMLTxtRange
* range
;
636 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
640 range
->get_htmlText(&text
);
641 selected
= wxString(text
);
646 selection
->Release();
652 void wxWebViewIE::ClearSelection()
654 IHTMLDocument2
* document
= GetDocument();
655 IHTMLSelectionObject
* selection
;
657 HRESULT hr
= document
->get_selection(&selection
);
661 selection
->Release();
666 wxString
wxWebViewIE::GetPageText()
668 IHTMLDocument2
* document
= GetDocument();
671 HRESULT hr
= document
->get_body(&body
);
675 body
->get_innerText(&out
);
676 text
= wxString(out
);
683 void wxWebViewIE::RunScript(const wxString
& javascript
)
685 IHTMLDocument2
* document
= GetDocument();
686 IHTMLWindow2
* window
;
687 wxString language
= "javascript";
688 HRESULT hr
= document
->get_parentWindow(&window
);
693 V_VT(&level
) = VT_EMPTY
;
694 window
->execScript(SysAllocString(javascript
), SysAllocString(language
), &level
);
699 bool wxWebViewIE::CanExecCommand(wxString command
)
701 IHTMLDocument2
* document
= GetDocument();
702 VARIANT_BOOL enabled
;
704 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
707 return (enabled
== VARIANT_TRUE
);
710 void wxWebViewIE::ExecCommand(wxString command
)
712 IHTMLDocument2
* document
= GetDocument();
713 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
717 IHTMLDocument2
* wxWebViewIE::GetDocument()
719 wxVariant variant
= m_ie
.GetProperty("Document");
720 IHTMLDocument2
* document
= (IHTMLDocument2
*)variant
.GetVoidPtr();
727 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
729 if (m_webBrowser
== NULL
) return;
731 switch (evt
.GetDispatchId())
733 case DISPID_BEFORENAVIGATE2
:
737 wxString url
= evt
[1].GetString();
738 wxString target
= evt
[3].GetString();
740 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
741 GetId(), url
, target
, true);
742 event
.SetEventObject(this);
743 HandleWindowEvent(event
);
745 if (event
.IsVetoed())
747 wxActiveXEventNativeMSW
* nativeParams
=
748 evt
.GetNativeParameters();
749 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
752 // at this point, either the navigation event has been cancelled
753 // and we're not busy, either it was accepted and IWebBrowser2's
754 // Busy property will be true; so we don't need our override
761 case DISPID_NAVIGATECOMPLETE2
:
763 wxString url
= evt
[1].GetString();
764 // TODO: set target parameter if possible
765 wxString target
= wxEmptyString
;
766 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
767 GetId(), url
, target
, false);
768 event
.SetEventObject(this);
769 HandleWindowEvent(event
);
773 case DISPID_PROGRESSCHANGE
:
779 case DISPID_DOCUMENTCOMPLETE
:
781 //Only send a complete even if we are actually finished, this brings
782 //the event in to line with webkit
784 m_webBrowser
->get_ReadyState( &rs
);
785 if(rs
!= READYSTATE_COMPLETE
)
788 wxString url
= evt
[1].GetString();
790 //As we are complete we also add to the history list, but not if the
791 //page is not the main page, ie it is a subframe
792 if(m_historyEnabled
&& !m_historyLoadingFromList
&& url
== GetCurrentURL())
794 //If we are not at the end of the list, then erase everything
795 //between us and the end before adding the new page
796 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
798 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
799 m_historyList
.end());
801 wxSharedPtr
<wxWebHistoryItem
> item(new wxWebHistoryItem(url
, GetCurrentTitle()));
802 m_historyList
.push_back(item
);
805 //Reset as we are done now
806 m_historyLoadingFromList
= false;
807 // TODO: set target parameter if possible
808 wxString target
= wxEmptyString
;
809 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
811 event
.SetEventObject(this);
812 HandleWindowEvent(event
);
816 case DISPID_STATUSTEXTCHANGE
:
821 case DISPID_TITLECHANGE
:
826 case DISPID_NAVIGATEERROR
:
828 wxWebNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
829 wxString errorCode
= "?";
830 switch (evt
[3].GetLong())
832 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
833 errorCode
= "INET_E_INVALID_URL";
834 errorType
= wxWEB_NAV_ERR_REQUEST
;
836 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
837 errorCode
= "INET_E_NO_SESSION";
838 errorType
= wxWEB_NAV_ERR_CONNECTION
;
840 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
841 errorCode
= "INET_E_CANNOT_CONNECT";
842 errorType
= wxWEB_NAV_ERR_CONNECTION
;
844 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
845 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
846 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
848 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
849 errorCode
= "INET_E_OBJECT_NOT_FOUND";
850 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
852 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
853 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
854 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
856 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
857 errorCode
= "INET_E_DOWNLOAD_FAILURE";
858 errorType
= wxWEB_NAV_ERR_CONNECTION
;
860 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
861 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
862 errorType
= wxWEB_NAV_ERR_AUTH
;
864 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
865 errorCode
= "INET_E_NO_VALID_MEDIA";
866 errorType
= wxWEB_NAV_ERR_REQUEST
;
868 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
869 errorCode
= "INET_E_CONNECTION_TIMEOUT";
870 errorType
= wxWEB_NAV_ERR_CONNECTION
;
872 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
873 errorCode
= "INET_E_INVALID_REQUEST";
874 errorType
= wxWEB_NAV_ERR_REQUEST
;
876 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
877 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
878 errorType
= wxWEB_NAV_ERR_REQUEST
;
880 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
881 errorCode
= "INET_E_SECURITY_PROBLEM";
882 errorType
= wxWEB_NAV_ERR_SECURITY
;
884 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
885 errorCode
= "INET_E_CANNOT_LOAD_DATA";
886 errorType
= wxWEB_NAV_ERR_OTHER
;
888 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
889 // CoCreateInstance will return an error code if this happens,
890 // we'll handle this above.
893 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
894 errorCode
= "INET_E_REDIRECT_FAILED";
895 errorType
= wxWEB_NAV_ERR_OTHER
;
897 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
898 errorCode
= "INET_E_REDIRECT_TO_DIR";
899 errorType
= wxWEB_NAV_ERR_REQUEST
;
901 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
902 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
903 errorType
= wxWEB_NAV_ERR_OTHER
;
905 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
906 errorCode
= "INET_E_USE_EXTEND_BINDING";
907 errorType
= wxWEB_NAV_ERR_OTHER
;
909 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
910 errorCode
= "INET_E_TERMINATED_BIND";
911 errorType
= wxWEB_NAV_ERR_OTHER
;
913 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
914 errorCode
= "INET_E_INVALID_CERTIFICATE";
915 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
917 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
918 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
919 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
921 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
922 // cancel request cancelled...
923 errorCode
= "INET_E_RESULT_DISPATCHED";
924 errorType
= wxWEB_NAV_ERR_OTHER
;
926 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
927 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
928 errorType
= wxWEB_NAV_ERR_SECURITY
;
930 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
931 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
932 errorType
= wxWEB_NAV_ERR_SECURITY
;
934 case INET_E_CODE_INSTALL_SUPPRESSED
:
935 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
936 errorType
= wxWEB_NAV_ERR_SECURITY
;
940 wxString url
= evt
[1].GetString();
941 wxString target
= evt
[2].GetString();
942 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
944 event
.SetEventObject(this);
945 event
.SetInt(errorType
);
946 event
.SetString(errorCode
);
947 HandleWindowEvent(event
);
950 case DISPID_NEWWINDOW3
:
952 wxString url
= evt
[4].GetString();
954 wxWebNavigationEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
955 GetId(), url
, wxEmptyString
, true);
956 event
.SetEventObject(this);
957 HandleWindowEvent(event
);
959 //We always cancel this event otherwise an Internet Exporer window
960 //is opened for the url
961 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
962 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;
970 VirtualProtocol::VirtualProtocol()
974 m_fileSys
= new wxFileSystem
;
977 VirtualProtocol::~VirtualProtocol()
982 ULONG
VirtualProtocol::AddRef()
988 HRESULT
VirtualProtocol::QueryInterface(REFIID riid
, void **ppvObject
)
990 if ((riid
== IID_IUnknown
) || (riid
== IID_IInternetProtocol
)
991 || (riid
== IID_IInternetProtocolRoot
))
1004 ULONG
VirtualProtocol::Release()
1018 HRESULT
VirtualProtocol::Start(LPCWSTR szUrl
, IInternetProtocolSink
*pOIProtSink
,
1019 IInternetBindInfo
*pOIBindInfo
, DWORD grfPI
,
1020 HANDLE_PTR dwReserved
)
1022 m_protocolSink
= pOIProtSink
;
1023 //We have to clean up incoming paths from the webview control as they are
1024 //not properly escaped, see also the comment in filesys.cpp line 668
1025 wxString path
= wxString(szUrl
).BeforeFirst(':') + ":" +
1026 EscapeFileNameCharsInURL(wxString(szUrl
).AfterFirst(':'));
1027 path
.Replace("///", "/");
1028 m_file
= m_fileSys
->OpenFile(path
);
1031 return INET_E_RESOURCE_NOT_FOUND
;
1033 //We return the stream length for current and total size as we can always
1034 //read the whole file from the stream
1035 m_protocolSink
->ReportData(BSCF_FIRSTDATANOTIFICATION
|
1036 BSCF_DATAFULLYAVAILABLE
|
1037 BSCF_LASTDATANOTIFICATION
,
1038 m_file
->GetStream()->GetLength(),
1039 m_file
->GetStream()->GetLength());
1043 HRESULT
VirtualProtocol::Read(void *pv
, ULONG cb
, ULONG
*pcbRead
)
1045 //If the file is null we return false to indicte it is finished
1049 wxStreamError err
= m_file
->GetStream()->Read(pv
, cb
).GetLastError();
1050 *pcbRead
= m_file
->GetStream()->LastRead();
1052 if(err
== wxSTREAM_NO_ERROR
)
1057 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1059 //As we are not eof there is more data
1062 else if(err
== wxSTREAM_EOF
)
1065 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1066 //We are eof and so finished
1069 else if(err
== wxSTREAM_READ_ERROR
)
1072 return INET_E_DOWNLOAD_FAILURE
;
1076 HRESULT
ClassFactory::CreateInstance(IUnknown
* pUnkOuter
, REFIID riid
,
1080 return CLASS_E_NOAGGREGATION
;
1081 VirtualProtocol
* vp
= new VirtualProtocol
;
1083 HRESULT hr
= vp
->QueryInterface(riid
, ppvObject
);
1089 STDMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
1095 ULONG
ClassFactory::AddRef(void)
1101 HRESULT
ClassFactory::QueryInterface(REFIID riid
, void **ppvObject
)
1103 if ((riid
== IID_IUnknown
) || (riid
== IID_IClassFactory
))
1117 ULONG
ClassFactory::Release(void)