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);
40 DEFINE_GUID(wxIID_IDocHostUIHandler
, 0xbd3f23c0, 0xd43e, 0x11cf, 0x89, 0x3b, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x1a);
44 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewIE
, wxWebView
);
46 BEGIN_EVENT_TABLE(wxWebViewIE
, wxControl
)
47 EVT_ACTIVEX(wxID_ANY
, wxWebViewIE::onActiveXEvent
)
48 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg
)
51 bool wxWebViewIE::Create(wxWindow
* parent
,
59 if (!wxControl::Create(parent
, id
, pos
, size
, style
,
60 wxDefaultValidator
, name
))
67 m_historyLoadingFromList
= false;
68 m_historyEnabled
= true;
69 m_historyPosition
= -1;
70 m_zoomType
= wxWEB_VIEW_ZOOM_TYPE_TEXT
;
72 if (::CoCreateInstance(CLSID_WebBrowser
, NULL
,
73 CLSCTX_INPROC_SERVER
, // CLSCTX_INPROC,
74 IID_IWebBrowser2
, (void**)&m_webBrowser
) != 0)
76 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
80 m_ie
.SetDispatchPtr(m_webBrowser
); // wxAutomationObject will release itself
82 m_webBrowser
->put_RegisterAsBrowser(VARIANT_TRUE
);
83 m_webBrowser
->put_RegisterAsDropTarget(VARIANT_TRUE
);
85 m_uiHandler
= new DocHostUIHandler
;
86 m_uiHandler
->AddRef();
88 m_container
= new wxIEContainer(this, IID_IWebBrowser2
, m_webBrowser
, m_uiHandler
);
90 EnableControlFeature(21 /* FEATURE_DISABLE_NAVIGATION_SOUNDS */);
96 wxWebViewIE::~wxWebViewIE()
98 for(unsigned int i
= 0; i
< m_factories
.size(); i
++)
100 m_factories
[i
]->Release();
103 m_uiHandler
->Release();
106 void wxWebViewIE::LoadURL(const wxString
& url
)
108 m_ie
.CallMethod("Navigate", wxConvertStringToOle(url
));
111 void wxWebViewIE::SetPage(const wxString
& html
, const wxString
& baseUrl
)
113 BSTR bstr
= SysAllocString(OLESTR(""));
114 SAFEARRAY
*psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
115 if (psaStrings
!= NULL
)
118 HRESULT hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
120 param
->bstrVal
= bstr
;
122 hr
= SafeArrayUnaccessData(psaStrings
);
124 IHTMLDocument2
* document
= GetDocument();
129 document
->write(psaStrings
);
133 SafeArrayDestroy(psaStrings
);
135 bstr
= SysAllocString(html
.wc_str());
137 // Creates a new one-dimensional array
138 psaStrings
= SafeArrayCreateVector(VT_VARIANT
, 0, 1);
139 if (psaStrings
!= NULL
)
141 hr
= SafeArrayAccessData(psaStrings
, (LPVOID
*)¶m
);
143 param
->bstrVal
= bstr
;
144 hr
= SafeArrayUnaccessData(psaStrings
);
146 document
= GetDocument();
151 document
->write(psaStrings
);
154 // SafeArrayDestroy calls SysFreeString for each BSTR
155 SafeArrayDestroy(psaStrings
);
157 //We send the events when we are done to mimic webkit
159 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
160 GetId(), baseUrl
, "");
161 event
.SetEventObject(this);
162 HandleWindowEvent(event
);
164 //Document complete event
165 event
.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED
);
166 event
.SetEventObject(this);
167 HandleWindowEvent(event
);
171 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
176 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL during clear");
180 wxString
wxWebViewIE::GetPageSource() const
182 IHTMLDocument2
* document
= GetDocument();
186 IHTMLElement
*bodyTag
= NULL
;
187 IHTMLElement
*htmlTag
= NULL
;
189 HRESULT hr
= document
->get_body(&bodyTag
);
192 hr
= bodyTag
->get_parentElement(&htmlTag
);
196 htmlTag
->get_outerHTML(&bstr
);
197 source
= wxString(bstr
);
212 wxWebViewZoom
wxWebViewIE::GetZoom() const
216 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
217 return GetIEOpticalZoom();
218 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
219 return GetIETextZoom();
224 //Dummy return to stop compiler warnings
225 return wxWEB_VIEW_ZOOM_MEDIUM
;
229 void wxWebViewIE::SetZoom(wxWebViewZoom zoom
)
233 case wxWEB_VIEW_ZOOM_TYPE_LAYOUT
:
234 SetIEOpticalZoom(zoom
);
236 case wxWEB_VIEW_ZOOM_TYPE_TEXT
:
244 void wxWebViewIE::SetIETextZoom(wxWebViewZoom level
)
246 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
247 //is 0 to 4 so the check is unnecessary, these match exactly with the
250 VariantInit (&zoomVariant
);
251 V_VT(&zoomVariant
) = VT_I4
;
252 V_I4(&zoomVariant
) = level
;
257 m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
258 OLECMDEXECOPT_DONTPROMPTUSER
,
260 wxASSERT(result
== S_OK
);
263 wxWebViewZoom
wxWebViewIE::GetIETextZoom() const
266 VariantInit (&zoomVariant
);
267 V_VT(&zoomVariant
) = VT_I4
;
272 m_webBrowser
->ExecWB(OLECMDID_ZOOM
,
273 OLECMDEXECOPT_DONTPROMPTUSER
,
275 wxASSERT(result
== S_OK
);
277 //We can safely cast here as we know that the range matches our enum
278 return static_cast<wxWebViewZoom
>(V_I4(&zoomVariant
));
281 void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level
)
283 //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
284 //is 10 to 1000 so the check is unnecessary
286 VariantInit (&zoomVariant
);
287 V_VT(&zoomVariant
) = VT_I4
;
289 //We make a somewhat arbitray map here, taken from values used by webkit
292 case wxWEB_VIEW_ZOOM_TINY
:
293 V_I4(&zoomVariant
) = 60;
295 case wxWEB_VIEW_ZOOM_SMALL
:
296 V_I4(&zoomVariant
) = 80;
298 case wxWEB_VIEW_ZOOM_MEDIUM
:
299 V_I4(&zoomVariant
) = 100;
301 case wxWEB_VIEW_ZOOM_LARGE
:
302 V_I4(&zoomVariant
) = 130;
304 case wxWEB_VIEW_ZOOM_LARGEST
:
305 V_I4(&zoomVariant
) = 160;
314 m_webBrowser
->ExecWB((OLECMDID
)63 /*OLECMDID_OPTICAL_ZOOM*/,
315 OLECMDEXECOPT_DODEFAULT
,
318 wxASSERT(result
== S_OK
);
321 wxWebViewZoom
wxWebViewIE::GetIEOpticalZoom() const
324 VariantInit (&zoomVariant
);
325 V_VT(&zoomVariant
) = VT_I4
;
330 m_webBrowser
->ExecWB((OLECMDID
)63 /*OLECMDID_OPTICAL_ZOOM*/,
331 OLECMDEXECOPT_DODEFAULT
, NULL
,
333 wxASSERT(result
== S_OK
);
335 const int zoom
= V_I4(&zoomVariant
);
337 //We make a somewhat arbitray map here, taken from values used by webkit
340 return wxWEB_VIEW_ZOOM_TINY
;
342 else if (zoom
> 65 && zoom
<= 90)
344 return wxWEB_VIEW_ZOOM_SMALL
;
346 else if (zoom
> 90 && zoom
<= 115)
348 return wxWEB_VIEW_ZOOM_MEDIUM
;
350 else if (zoom
> 115 && zoom
<= 145)
352 return wxWEB_VIEW_ZOOM_LARGE
;
354 else /*if (zoom > 145) */ //Using else removes a compiler warning
356 return wxWEB_VIEW_ZOOM_LARGEST
;
360 void wxWebViewIE::SetZoomType(wxWebViewZoomType type
)
365 wxWebViewZoomType
wxWebViewIE::GetZoomType() const
370 bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type
) const
372 //IE 6 and below only support text zoom, so check the registry to see what
373 //version we actually have
374 wxRegKey
key(wxRegKey::HKLM
, "Software\\Microsoft\\Internet Explorer");
376 key
.QueryValue("Version", value
);
378 long version
= wxAtoi(value
.Left(1));
379 if(version
<= 6 && type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
)
385 void wxWebViewIE::Print()
387 m_webBrowser
->ExecWB(OLECMDID_PRINTPREVIEW
,
388 OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
391 bool wxWebViewIE::CanGoBack() const
394 return m_historyPosition
> 0;
399 bool wxWebViewIE::CanGoForward() const
402 return m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1;
407 void wxWebViewIE::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
410 for(unsigned int i
= 0; i
< m_historyList
.size(); i
++)
412 //We compare the actual pointers to find the correct item
413 if(m_historyList
[i
].get() == item
.get())
416 wxASSERT_MSG(pos
!= static_cast<int>(m_historyList
.size()),
417 "invalid history item");
418 m_historyLoadingFromList
= true;
419 LoadURL(item
->GetUrl());
420 m_historyPosition
= pos
;
423 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewIE::GetBackwardHistory()
425 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
426 //As we don't have std::copy or an iterator constructor in the wxwidgets
427 //native vector we construct it by hand
428 for(int i
= 0; i
< m_historyPosition
; i
++)
430 backhist
.push_back(m_historyList
[i
]);
435 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewIE::GetForwardHistory()
437 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
438 //As we don't have std::copy or an iterator constructor in the wxwidgets
439 //native vector we construct it by hand
440 for(int i
= m_historyPosition
+ 1; i
< static_cast<int>(m_historyList
.size()); i
++)
442 forwardhist
.push_back(m_historyList
[i
]);
447 void wxWebViewIE::GoBack()
449 LoadHistoryItem(m_historyList
[m_historyPosition
- 1]);
452 void wxWebViewIE::GoForward()
454 LoadHistoryItem(m_historyList
[m_historyPosition
+ 1]);
457 void wxWebViewIE::Stop()
459 m_ie
.CallMethod("Stop");
462 void wxWebViewIE::ClearHistory()
464 m_historyList
.clear();
465 m_historyPosition
= -1;
468 void wxWebViewIE::EnableHistory(bool enable
)
470 m_historyEnabled
= enable
;
471 m_historyList
.clear();
472 m_historyPosition
= -1;
475 void wxWebViewIE::Reload(wxWebViewReloadFlags flags
)
479 V_VT(&level
) = VT_I2
;
483 case wxWEB_VIEW_RELOAD_DEFAULT
:
484 V_I2(&level
) = REFRESH_NORMAL
;
486 case wxWEB_VIEW_RELOAD_NO_CACHE
:
487 V_I2(&level
) = REFRESH_COMPLETELY
;
490 wxFAIL_MSG("Unexpected reload type");
493 m_webBrowser
->Refresh2(&level
);
496 bool wxWebViewIE::IsOfflineMode()
498 wxVariant out
= m_ie
.GetProperty("Offline");
500 wxASSERT(out
.GetType() == "bool");
502 return out
.GetBool();
505 void wxWebViewIE::SetOfflineMode(bool offline
)
507 // FIXME: the wxWidgets docs do not really document what the return
508 // parameter of PutProperty is
512 m_ie
.PutProperty("Offline", (offline
?
518 bool wxWebViewIE::IsBusy() const
520 if (m_isBusy
) return true;
522 wxVariant out
= m_ie
.GetProperty("Busy");
524 wxASSERT(out
.GetType() == "bool");
526 return out
.GetBool();
529 wxString
wxWebViewIE::GetCurrentURL() const
531 wxVariant out
= m_ie
.GetProperty("LocationURL");
533 wxASSERT(out
.GetType() == "string");
534 return out
.GetString();
537 wxString
wxWebViewIE::GetCurrentTitle() const
539 IHTMLDocument2
* document
= GetDocument();
544 document
->get_nameProp(&title
);
546 return wxString(title
);
554 bool wxWebViewIE::CanCut() const
556 return CanExecCommand("Cut");
559 bool wxWebViewIE::CanCopy() const
561 return CanExecCommand("Copy");
564 bool wxWebViewIE::CanPaste() const
566 return CanExecCommand("Paste");
569 void wxWebViewIE::Cut()
574 void wxWebViewIE::Copy()
579 void wxWebViewIE::Paste()
581 ExecCommand("Paste");
584 bool wxWebViewIE::CanUndo() const
586 return CanExecCommand("Undo");
589 bool wxWebViewIE::CanRedo() const
591 return CanExecCommand("Redo");
594 void wxWebViewIE::Undo()
599 void wxWebViewIE::Redo()
604 void wxWebViewIE::SetEditable(bool enable
)
606 IHTMLDocument2
* document
= GetDocument();
611 document
->put_designMode(SysAllocString(L
"On"));
613 document
->put_designMode(SysAllocString(L
"Off"));
619 bool wxWebViewIE::IsEditable() const
621 IHTMLDocument2
* document
= GetDocument();
626 document
->get_designMode(&mode
);
628 if(wxString(mode
) == "On")
639 void wxWebViewIE::SelectAll()
641 ExecCommand("SelectAll");
644 bool wxWebViewIE::HasSelection() const
646 IHTMLDocument2
* document
= GetDocument();
650 IHTMLSelectionObject
* selection
;
652 HRESULT hr
= document
->get_selection(&selection
);
656 selection
->get_type(&type
);
657 sel
= wxString(type
);
658 selection
->Release();
661 return sel
!= "None";
669 void wxWebViewIE::DeleteSelection()
671 ExecCommand("Delete");
674 wxString
wxWebViewIE::GetSelectedText() const
676 IHTMLDocument2
* document
= GetDocument();
680 IHTMLSelectionObject
* selection
;
682 HRESULT hr
= document
->get_selection(&selection
);
686 hr
= selection
->createRange(&disrange
);
689 IHTMLTxtRange
* range
;
690 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
694 range
->get_text(&text
);
695 selected
= wxString(text
);
700 selection
->Release();
711 wxString
wxWebViewIE::GetSelectedSource() const
713 IHTMLDocument2
* document
= GetDocument();
717 IHTMLSelectionObject
* selection
;
719 HRESULT hr
= document
->get_selection(&selection
);
723 hr
= selection
->createRange(&disrange
);
726 IHTMLTxtRange
* range
;
727 hr
= disrange
->QueryInterface(IID_IHTMLTxtRange
, (void**)&range
);
731 range
->get_htmlText(&text
);
732 selected
= wxString(text
);
737 selection
->Release();
748 void wxWebViewIE::ClearSelection()
750 IHTMLDocument2
* document
= GetDocument();
754 IHTMLSelectionObject
* selection
;
756 HRESULT hr
= document
->get_selection(&selection
);
760 selection
->Release();
766 wxString
wxWebViewIE::GetPageText() const
768 IHTMLDocument2
* document
= GetDocument();
774 HRESULT hr
= document
->get_body(&body
);
778 body
->get_innerText(&out
);
779 text
= wxString(out
);
791 void wxWebViewIE::RunScript(const wxString
& javascript
)
793 IHTMLDocument2
* document
= GetDocument();
797 IHTMLWindow2
* window
;
798 wxString language
= "javascript";
799 HRESULT hr
= document
->get_parentWindow(&window
);
804 V_VT(&level
) = VT_EMPTY
;
805 window
->execScript(SysAllocString(javascript
.wc_str()),
806 SysAllocString(language
.wc_str()),
813 void wxWebViewIE::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
815 wxDynamicLibrary
urlMon(wxT("urlmon.dll"));
816 if(urlMon
.HasSymbol(wxT("CoInternetGetSession")))
818 typedef HRESULT (WINAPI
*CoInternetGetSession_t
)(DWORD
, wxIInternetSession
**, DWORD
);
819 wxDYNLIB_FUNCTION(CoInternetGetSession_t
, CoInternetGetSession
, urlMon
);
821 ClassFactory
* cf
= new ClassFactory(handler
);
822 wxIInternetSession
* session
;
823 HRESULT res
= (*pfnCoInternetGetSession
)(0, &session
, 0);
826 wxFAIL_MSG("Could not retrive internet session");
829 HRESULT hr
= session
->RegisterNameSpace(cf
, CLSID_FileProtocol
,
830 handler
->GetName().wc_str(),
834 wxFAIL_MSG("Could not register protocol");
836 m_factories
.push_back(cf
);
840 wxFAIL_MSG("urlmon does not contain CoInternetGetSession");
844 bool wxWebViewIE::CanExecCommand(wxString command
) const
846 IHTMLDocument2
* document
= GetDocument();
850 VARIANT_BOOL enabled
;
852 document
->queryCommandEnabled(SysAllocString(command
.wc_str()), &enabled
);
855 return (enabled
== VARIANT_TRUE
);
864 void wxWebViewIE::ExecCommand(wxString command
)
866 IHTMLDocument2
* document
= GetDocument();
870 document
->execCommand(SysAllocString(command
.wc_str()), VARIANT_FALSE
, VARIANT(), NULL
);
875 IHTMLDocument2
* wxWebViewIE::GetDocument() const
877 IDispatch
* dispatch
= NULL
;
878 HRESULT result
= m_webBrowser
->get_Document(&dispatch
);
879 if(dispatch
&& SUCCEEDED(result
))
881 IHTMLDocument2
* document
;
882 dispatch
->QueryInterface(IID_IHTMLDocument2
, (void**)&document
);
884 //document is set to null automatically if the interface isn't supported
893 bool wxWebViewIE::EnableControlFeature(long flag
, bool enable
)
895 #if wxUSE_DYNLIB_CLASS
897 wxDynamicLibrary
urlMon(wxT("urlmon.dll"));
898 if( urlMon
.IsLoaded() &&
899 urlMon
.HasSymbol("CoInternetSetFeatureEnabled") &&
900 urlMon
.HasSymbol("CoInternetIsFeatureEnabled"))
902 typedef HRESULT (WINAPI
*CoInternetSetFeatureEnabled_t
)(DWORD
, DWORD
, BOOL
);
903 typedef HRESULT (WINAPI
*CoInternetIsFeatureEnabled_t
)(DWORD
, DWORD
);
905 wxDYNLIB_FUNCTION(CoInternetSetFeatureEnabled_t
, CoInternetSetFeatureEnabled
, urlMon
);
906 wxDYNLIB_FUNCTION(CoInternetIsFeatureEnabled_t
, CoInternetIsFeatureEnabled
, urlMon
);
908 HRESULT hr
= (*pfnCoInternetIsFeatureEnabled
)(flag
,
909 0x2 /* SET_FEATURE_ON_PROCESS */);
910 if((hr
== S_OK
&& enable
) || (hr
== S_FALSE
&& !enable
))
913 hr
= (*pfnCoInternetSetFeatureEnabled
)(flag
,
914 0x2/* SET_FEATURE_ON_PROCESS */,
915 (enable
? TRUE
: FALSE
));
918 wxLogApiError(wxT("CoInternetSetFeatureEnabled"), hr
);
928 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS
931 void wxWebViewIE::onActiveXEvent(wxActiveXEvent
& evt
)
933 if (m_webBrowser
== NULL
) return;
935 switch (evt
.GetDispatchId())
937 case DISPID_BEFORENAVIGATE2
:
941 wxString url
= evt
[1].GetString();
942 wxString target
= evt
[3].GetString();
944 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
945 GetId(), url
, target
);
947 //skip empty javascript events.
948 if(url
== "javascript:\"\"" && target
.IsEmpty())
954 event
.SetEventObject(this);
955 HandleWindowEvent(event
);
958 if (!event
.IsAllowed())
960 wxActiveXEventNativeMSW
* nativeParams
=
961 evt
.GetNativeParameters();
962 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[0]) = VARIANT_TRUE
;
965 // at this point, either the navigation event has been cancelled
966 // and we're not busy, either it was accepted and IWebBrowser2's
967 // Busy property will be true; so we don't need our override
974 case DISPID_NAVIGATECOMPLETE2
:
976 wxString url
= evt
[1].GetString();
977 // TODO: set target parameter if possible
978 wxString target
= wxEmptyString
;
979 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
980 GetId(), url
, target
);
981 event
.SetEventObject(this);
982 HandleWindowEvent(event
);
986 case DISPID_PROGRESSCHANGE
:
992 case DISPID_DOCUMENTCOMPLETE
:
994 //Only send a complete even if we are actually finished, this brings
995 //the event in to line with webkit
997 m_webBrowser
->get_ReadyState( &rs
);
998 if(rs
!= READYSTATE_COMPLETE
)
1001 wxString url
= evt
[1].GetString();
1003 //As we are complete we also add to the history list, but not if the
1004 //page is not the main page, ie it is a subframe
1005 //We also have to check if we are loading a file:// url, if so we
1006 //need to change the comparison as ie passes back a different style
1008 if(m_historyEnabled
&& !m_historyLoadingFromList
&&
1009 (url
== GetCurrentURL() ||
1010 (GetCurrentURL().substr(0, 4) == "file" &&
1011 wxFileSystem::URLToFileName(GetCurrentURL()).GetFullPath() == url
)))
1013 //If we are not at the end of the list, then erase everything
1014 //between us and the end before adding the new page
1015 if(m_historyPosition
!= static_cast<int>(m_historyList
.size()) - 1)
1017 m_historyList
.erase(m_historyList
.begin() + m_historyPosition
+ 1,
1018 m_historyList
.end());
1020 wxSharedPtr
<wxWebViewHistoryItem
> item(new wxWebViewHistoryItem(url
, GetCurrentTitle()));
1021 m_historyList
.push_back(item
);
1022 m_historyPosition
++;
1024 //Reset as we are done now
1025 m_historyLoadingFromList
= false;
1026 // TODO: set target parameter if possible
1027 wxString target
= wxEmptyString
;
1028 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
, GetId(),
1030 event
.SetEventObject(this);
1031 HandleWindowEvent(event
);
1035 case DISPID_STATUSTEXTCHANGE
:
1040 case DISPID_TITLECHANGE
:
1042 wxString title
= evt
[0].GetString();
1044 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
1045 GetId(), GetCurrentURL(), "");
1046 event
.SetString(title
);
1047 event
.SetEventObject(this);
1048 HandleWindowEvent(event
);
1052 case DISPID_NAVIGATEERROR
:
1054 wxWebViewNavigationError errorType
= wxWEB_NAV_ERR_OTHER
;
1055 wxString errorCode
= "?";
1056 switch (evt
[3].GetLong())
1058 case INET_E_INVALID_URL
: // (0x800C0002L or -2146697214)
1059 errorCode
= "INET_E_INVALID_URL";
1060 errorType
= wxWEB_NAV_ERR_REQUEST
;
1062 case INET_E_NO_SESSION
: // (0x800C0003L or -2146697213)
1063 errorCode
= "INET_E_NO_SESSION";
1064 errorType
= wxWEB_NAV_ERR_CONNECTION
;
1066 case INET_E_CANNOT_CONNECT
: // (0x800C0004L or -2146697212)
1067 errorCode
= "INET_E_CANNOT_CONNECT";
1068 errorType
= wxWEB_NAV_ERR_CONNECTION
;
1070 case INET_E_RESOURCE_NOT_FOUND
: // (0x800C0005L or -2146697211)
1071 errorCode
= "INET_E_RESOURCE_NOT_FOUND";
1072 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
1074 case INET_E_OBJECT_NOT_FOUND
: // (0x800C0006L or -2146697210)
1075 errorCode
= "INET_E_OBJECT_NOT_FOUND";
1076 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
1078 case INET_E_DATA_NOT_AVAILABLE
: // (0x800C0007L or -2146697209)
1079 errorCode
= "INET_E_DATA_NOT_AVAILABLE";
1080 errorType
= wxWEB_NAV_ERR_NOT_FOUND
;
1082 case INET_E_DOWNLOAD_FAILURE
: // (0x800C0008L or -2146697208)
1083 errorCode
= "INET_E_DOWNLOAD_FAILURE";
1084 errorType
= wxWEB_NAV_ERR_CONNECTION
;
1086 case INET_E_AUTHENTICATION_REQUIRED
: // (0x800C0009L or -2146697207)
1087 errorCode
= "INET_E_AUTHENTICATION_REQUIRED";
1088 errorType
= wxWEB_NAV_ERR_AUTH
;
1090 case INET_E_NO_VALID_MEDIA
: // (0x800C000AL or -2146697206)
1091 errorCode
= "INET_E_NO_VALID_MEDIA";
1092 errorType
= wxWEB_NAV_ERR_REQUEST
;
1094 case INET_E_CONNECTION_TIMEOUT
: // (0x800C000BL or -2146697205)
1095 errorCode
= "INET_E_CONNECTION_TIMEOUT";
1096 errorType
= wxWEB_NAV_ERR_CONNECTION
;
1098 case INET_E_INVALID_REQUEST
: // (0x800C000CL or -2146697204)
1099 errorCode
= "INET_E_INVALID_REQUEST";
1100 errorType
= wxWEB_NAV_ERR_REQUEST
;
1102 case INET_E_UNKNOWN_PROTOCOL
: // (0x800C000DL or -2146697203)
1103 errorCode
= "INET_E_UNKNOWN_PROTOCOL";
1104 errorType
= wxWEB_NAV_ERR_REQUEST
;
1106 case INET_E_SECURITY_PROBLEM
: // (0x800C000EL or -2146697202)
1107 errorCode
= "INET_E_SECURITY_PROBLEM";
1108 errorType
= wxWEB_NAV_ERR_SECURITY
;
1110 case INET_E_CANNOT_LOAD_DATA
: // (0x800C000FL or -2146697201)
1111 errorCode
= "INET_E_CANNOT_LOAD_DATA";
1112 errorType
= wxWEB_NAV_ERR_OTHER
;
1114 case INET_E_CANNOT_INSTANTIATE_OBJECT
:
1115 // CoCreateInstance will return an error code if this happens,
1116 // we'll handle this above.
1119 case INET_E_REDIRECT_FAILED
: // (0x800C0014L or -2146697196)
1120 errorCode
= "INET_E_REDIRECT_FAILED";
1121 errorType
= wxWEB_NAV_ERR_OTHER
;
1123 case INET_E_REDIRECT_TO_DIR
: // (0x800C0015L or -2146697195)
1124 errorCode
= "INET_E_REDIRECT_TO_DIR";
1125 errorType
= wxWEB_NAV_ERR_REQUEST
;
1127 case INET_E_CANNOT_LOCK_REQUEST
: // (0x800C0016L or -2146697194)
1128 errorCode
= "INET_E_CANNOT_LOCK_REQUEST";
1129 errorType
= wxWEB_NAV_ERR_OTHER
;
1131 case INET_E_USE_EXTEND_BINDING
: // (0x800C0017L or -2146697193)
1132 errorCode
= "INET_E_USE_EXTEND_BINDING";
1133 errorType
= wxWEB_NAV_ERR_OTHER
;
1135 case INET_E_TERMINATED_BIND
: // (0x800C0018L or -2146697192)
1136 errorCode
= "INET_E_TERMINATED_BIND";
1137 errorType
= wxWEB_NAV_ERR_OTHER
;
1139 case INET_E_INVALID_CERTIFICATE
: // (0x800C0019L or -2146697191)
1140 errorCode
= "INET_E_INVALID_CERTIFICATE";
1141 errorType
= wxWEB_NAV_ERR_CERTIFICATE
;
1143 case INET_E_CODE_DOWNLOAD_DECLINED
: // (0x800C0100L or -2146696960)
1144 errorCode
= "INET_E_CODE_DOWNLOAD_DECLINED";
1145 errorType
= wxWEB_NAV_ERR_USER_CANCELLED
;
1147 case INET_E_RESULT_DISPATCHED
: // (0x800C0200L or -2146696704)
1148 // cancel request cancelled...
1149 errorCode
= "INET_E_RESULT_DISPATCHED";
1150 errorType
= wxWEB_NAV_ERR_OTHER
;
1152 case INET_E_CANNOT_REPLACE_SFP_FILE
: // (0x800C0300L or -2146696448)
1153 errorCode
= "INET_E_CANNOT_REPLACE_SFP_FILE";
1154 errorType
= wxWEB_NAV_ERR_SECURITY
;
1156 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
:
1157 errorCode
= "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
1158 errorType
= wxWEB_NAV_ERR_SECURITY
;
1160 case INET_E_CODE_INSTALL_SUPPRESSED
:
1161 errorCode
= "INET_E_CODE_INSTALL_SUPPRESSED";
1162 errorType
= wxWEB_NAV_ERR_SECURITY
;
1166 wxString url
= evt
[1].GetString();
1167 wxString target
= evt
[2].GetString();
1168 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
, GetId(),
1170 event
.SetEventObject(this);
1171 event
.SetInt(errorType
);
1172 event
.SetString(errorCode
);
1173 HandleWindowEvent(event
);
1176 case DISPID_NEWWINDOW3
:
1178 wxString url
= evt
[4].GetString();
1180 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
1181 GetId(), url
, wxEmptyString
);
1182 event
.SetEventObject(this);
1183 HandleWindowEvent(event
);
1185 //We always cancel this event otherwise an Internet Exporer window
1186 //is opened for the url
1187 wxActiveXEventNativeMSW
* nativeParams
= evt
.GetNativeParameters();
1188 *V_BOOLREF(&nativeParams
->pDispParams
->rgvarg
[3]) = VARIANT_TRUE
;
1196 VirtualProtocol::VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
)
1199 m_handler
= handler
;
1202 BEGIN_IID_TABLE(VirtualProtocol
)
1204 ADD_RAW_IID(wxIID_IInternetProtocolRoot
)
1205 ADD_RAW_IID(wxIID_IInternetProtocol
)
1208 IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol
)
1210 HRESULT
VirtualProtocol::Start(LPCWSTR szUrl
, wxIInternetProtocolSink
*pOIProtSink
,
1211 wxIInternetBindInfo
*pOIBindInfo
, DWORD grfPI
,
1212 HANDLE_PTR dwReserved
)
1215 wxUnusedVar(pOIBindInfo
);
1217 wxUnusedVar(dwReserved
);
1218 m_protocolSink
= pOIProtSink
;
1220 //We get the file itself from the protocol handler
1221 m_file
= m_handler
->GetFile(szUrl
);
1225 return INET_E_RESOURCE_NOT_FOUND
;
1227 //We return the stream length for current and total size as we can always
1228 //read the whole file from the stream
1229 wxFileOffset length
= m_file
->GetStream()->GetLength();
1230 m_protocolSink
->ReportData(wxBSCF_FIRSTDATANOTIFICATION
|
1231 wxBSCF_DATAFULLYAVAILABLE
|
1232 wxBSCF_LASTDATANOTIFICATION
,
1237 HRESULT
VirtualProtocol::Read(void *pv
, ULONG cb
, ULONG
*pcbRead
)
1239 //If the file is null we return false to indicte it is finished
1243 wxStreamError err
= m_file
->GetStream()->Read(pv
, cb
).GetLastError();
1244 *pcbRead
= m_file
->GetStream()->LastRead();
1246 if(err
== wxSTREAM_NO_ERROR
)
1251 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1253 //As we are not eof there is more data
1256 else if(err
== wxSTREAM_EOF
)
1259 m_protocolSink
->ReportResult(S_OK
, 0, NULL
);
1260 //We are eof and so finished
1263 else if(err
== wxSTREAM_READ_ERROR
)
1266 return INET_E_DOWNLOAD_FAILURE
;
1270 //Dummy return to surpress a compiler warning
1272 return INET_E_DOWNLOAD_FAILURE
;
1276 BEGIN_IID_TABLE(ClassFactory
)
1278 ADD_IID(ClassFactory
)
1281 IMPLEMENT_IUNKNOWN_METHODS(ClassFactory
)
1283 HRESULT
ClassFactory::CreateInstance(IUnknown
* pUnkOuter
, REFIID riid
,
1287 return CLASS_E_NOAGGREGATION
;
1288 VirtualProtocol
* vp
= new VirtualProtocol(m_handler
);
1290 HRESULT hr
= vp
->QueryInterface(riid
, ppvObject
);
1296 STDMETHODIMP
ClassFactory::LockServer(BOOL fLock
)
1302 wxIEContainer::wxIEContainer(wxWindow
*parent
, REFIID iid
, IUnknown
*pUnk
,
1303 DocHostUIHandler
* uiHandler
) :
1304 wxActiveXContainer(parent
,iid
,pUnk
)
1306 m_uiHandler
= uiHandler
;
1309 wxIEContainer::~wxIEContainer()
1313 bool wxIEContainer::QueryClientSiteInterface(REFIID iid
, void **_interface
,
1316 if (m_uiHandler
&& IsEqualIID(iid
, wxIID_IDocHostUIHandler
))
1318 *_interface
= (IUnknown
*) (wxIDocHostUIHandler
*) m_uiHandler
;
1319 desc
= "IDocHostUIHandler";
1325 HRESULT
DocHostUIHandler::ShowContextMenu(DWORD dwID
, POINT
*ppt
,
1326 IUnknown
*pcmdtReserved
,
1327 IDispatch
*pdispReserved
)
1331 wxUnusedVar(pcmdtReserved
);
1332 wxUnusedVar(pdispReserved
);
1336 HRESULT
DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO
*pInfo
)
1338 //don't show 3d border and enable themes.
1339 pInfo
->dwFlags
= pInfo
->dwFlags
| DOCHOSTUIFLAG_NO3DBORDER
| DOCHOSTUIFLAG_THEME
;
1343 HRESULT
DocHostUIHandler::ShowUI(DWORD dwID
,
1344 IOleInPlaceActiveObject
*pActiveObject
,
1345 IOleCommandTarget
*pCommandTarget
,
1346 IOleInPlaceFrame
*pFrame
,
1347 IOleInPlaceUIWindow
*pDoc
)
1350 wxUnusedVar(pActiveObject
);
1351 wxUnusedVar(pCommandTarget
);
1352 wxUnusedVar(pFrame
);
1357 HRESULT
DocHostUIHandler::HideUI(void)
1362 HRESULT
DocHostUIHandler::UpdateUI(void)
1367 HRESULT
DocHostUIHandler::EnableModeless(BOOL fEnable
)
1369 wxUnusedVar(fEnable
);
1373 HRESULT
DocHostUIHandler::OnDocWindowActivate(BOOL fActivate
)
1375 wxUnusedVar(fActivate
);
1379 HRESULT
DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate
)
1381 wxUnusedVar(fActivate
);
1385 HRESULT
DocHostUIHandler::ResizeBorder(LPCRECT prcBorder
,
1386 IOleInPlaceUIWindow
*pUIWindow
,
1389 wxUnusedVar(prcBorder
);
1390 wxUnusedVar(pUIWindow
);
1391 wxUnusedVar(fFrameWindow
);
1395 HRESULT
DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg
,
1396 const GUID
*pguidCmdGroup
,
1399 if(lpMsg
&& lpMsg
->message
== WM_KEYDOWN
)
1402 if((GetKeyState(VK_CONTROL
) & 0x8000 ))
1404 //skip the accelerators used by the control
1405 switch(lpMsg
->wParam
)
1416 if(lpMsg
->wParam
== VK_F5
)
1422 wxUnusedVar(pguidCmdGroup
);
1423 wxUnusedVar(nCmdID
);
1427 HRESULT
DocHostUIHandler::GetOptionKeyPath(LPOLESTR
*pchKey
,DWORD dw
)
1429 wxUnusedVar(pchKey
);
1434 HRESULT
DocHostUIHandler::GetDropTarget(IDropTarget
*pDropTarget
,
1435 IDropTarget
**ppDropTarget
)
1437 wxUnusedVar(pDropTarget
);
1438 wxUnusedVar(ppDropTarget
);
1442 HRESULT
DocHostUIHandler::GetExternal(IDispatch
**ppDispatch
)
1444 wxUnusedVar(ppDispatch
);
1448 HRESULT
DocHostUIHandler::TranslateUrl(DWORD dwTranslate
,
1450 OLECHAR
**ppchURLOut
)
1452 wxUnusedVar(dwTranslate
);
1453 wxUnusedVar(pchURLIn
);
1454 wxUnusedVar(ppchURLOut
);
1458 HRESULT
DocHostUIHandler::FilterDataObject(IDataObject
*pDO
, IDataObject
**ppDORet
)
1461 wxUnusedVar(ppDORet
);
1465 BEGIN_IID_TABLE(DocHostUIHandler
)
1467 ADD_RAW_IID(wxIID_IDocHostUIHandler
)
1470 IMPLEMENT_IUNKNOWN_METHODS(DocHostUIHandler
)
1472 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE