]> git.saurik.com Git - wxWidgets.git/blame - src/msw/webview_ie.cpp
Bring osx class naming into line with the other ports.
[wxWidgets.git] / src / msw / webview_ie.cpp
CommitLineData
61b98a2d 1/////////////////////////////////////////////////////////////////////////////
8290e3cd 2// Name: src/msw/webview_ie.cpp
61b98a2d
SL
3// Purpose: wxMSW wxWebViewIE class implementation for web view component
4// Author: Marianne Gagnon
5// Id: $Id$
74af0b13 6// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
61b98a2d
SL
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
384b8d9f
SL
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if defined(__BORLANDC__)
14 #pragma hdrstop
15#endif
16
8290e3cd 17#include "wx/msw/webview_ie.h"
61b98a2d 18
66f2aa61 19#if wxUSE_WEBVIEW_IE
61b98a2d
SL
20
21#include <olectl.h>
22#include <oleidl.h>
23#include <exdispid.h>
24#include <exdisp.h>
25#include <mshtml.h>
26
726cc869 27// Various definitions are missing from mingw
97ad1425 28#ifdef __MINGW32__
61b98a2d
SL
29typedef enum CommandStateChangeConstants {
30 CSC_UPDATECOMMANDS = (int) 0xFFFFFFFF,
31 CSC_NAVIGATEFORWARD = 0x1,
32 CSC_NAVIGATEBACK = 0x2
33} CommandStateChangeConstants;
34
726cc869
SL
35#define DISPID_COMMANDSTATECHANGE 105
36#define DISPID_NAVIGATECOMPLETE2 252
37#define DISPID_NAVIGATEERROR 271
38#define DISPID_NEWWINDOW3 273
39#define OLECMDID_OPTICAL_ZOOM 63
61b98a2d
SL
40#define INET_E_ERROR_FIRST 0x800C0002L
41#define INET_E_INVALID_URL 0x800C0002L
42#define INET_E_NO_SESSION 0x800C0003L
43#define INET_E_CANNOT_CONNECT 0x800C0004L
44#define INET_E_RESOURCE_NOT_FOUND 0x800C0005L
45#define INET_E_OBJECT_NOT_FOUND 0x800C0006L
46#define INET_E_DATA_NOT_AVAILABLE 0x800C0007L
47#define INET_E_DOWNLOAD_FAILURE 0x800C0008L
48#define INET_E_AUTHENTICATION_REQUIRED 0x800C0009L
49#define INET_E_NO_VALID_MEDIA 0x800C000AL
50#define INET_E_CONNECTION_TIMEOUT 0x800C000BL
51#define INET_E_INVALID_REQUEST 0x800C000CL
52#define INET_E_UNKNOWN_PROTOCOL 0x800C000DL
53#define INET_E_SECURITY_PROBLEM 0x800C000EL
54#define INET_E_CANNOT_LOAD_DATA 0x800C000FL
55#define INET_E_CANNOT_INSTANTIATE_OBJECT 0x800C0010L
56#define INET_E_QUERYOPTION_UNKNOWN 0x800C0013L
57#define INET_E_REDIRECT_FAILED 0x800C0014L
58#define INET_E_REDIRECT_TO_DIR 0x800C0015L
59#define INET_E_CANNOT_LOCK_REQUEST 0x800C0016L
60#define INET_E_USE_EXTEND_BINDING 0x800C0017L
61#define INET_E_TERMINATED_BIND 0x800C0018L
62#define INET_E_INVALID_CERTIFICATE 0x800C0019L
63#define INET_E_CODE_DOWNLOAD_DECLINED 0x800C0100L
64#define INET_E_RESULT_DISPATCHED 0x800C0200L
65#define INET_E_CANNOT_REPLACE_SFP_FILE 0x800C0300L
66#define INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY 0x800C0500L
67#define INET_E_CODE_INSTALL_SUPPRESSED 0x800C0400L
68
726cc869 69#define REFRESH_NORMAL 0
61b98a2d 70#define REFRESH_COMPLETELY 3
97ad1425 71#endif
61b98a2d
SL
72
73BEGIN_EVENT_TABLE(wxWebViewIE, wxControl)
97ad1425
SL
74 EVT_ACTIVEX(wxID_ANY, wxWebViewIE::onActiveXEvent)
75 EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg)
61b98a2d
SL
76END_EVENT_TABLE()
77
78bool wxWebViewIE::Create(wxWindow* parent,
79 wxWindowID id,
80 const wxString& url,
81 const wxPoint& pos,
82 const wxSize& size,
83 long style,
84 const wxString& name)
85{
86 if (!wxControl::Create(parent, id, pos, size, style,
87 wxDefaultValidator, name))
88 {
89 return false;
90 }
91
92 m_webBrowser = NULL;
93 m_canNavigateBack = false;
94 m_canNavigateForward = false;
95 m_isBusy = false;
74af0b13
SL
96 m_historyLoadingFromList = false;
97 m_historyEnabled = true;
98 m_historyPosition = -1;
61b98a2d
SL
99
100 if (::CoCreateInstance(CLSID_WebBrowser, NULL,
101 CLSCTX_INPROC_SERVER, // CLSCTX_INPROC,
102 IID_IWebBrowser2 , (void**)&m_webBrowser) != 0)
103 {
104 wxLogError("Failed to initialize IE, CoCreateInstance returned an error");
105 return false;
106 }
107
108 m_ie.SetDispatchPtr(m_webBrowser); // wxAutomationObject will release itself
109
110 m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE);
111 m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
112 //m_webBrowser->put_Silent(VARIANT_FALSE);
113
114 m_container = new wxActiveXContainer(this, IID_IWebBrowser2, m_webBrowser);
115
116 SetBackgroundStyle(wxBG_STYLE_PAINT);
117 SetDoubleBuffered(true);
9ef101cd 118 LoadUrl(url);
61b98a2d
SL
119 return true;
120}
121
122
123void wxWebViewIE::LoadUrl(const wxString& url)
124{
125 wxVariant out = m_ie.CallMethod("Navigate", (BSTR) url.wc_str(),
126 NULL, NULL, NULL, NULL);
127
128 // FIXME: why is out value null??
129 //(HRESULT)(out.GetLong()) == S_OK;
130}
131
132void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
133{
134 LoadUrl("about:blank");
135
136 // Let the wx events generated for navigation events be processed, so
137 // that the underlying IE component completes its Document object.
138 // FIXME: calling wxYield is not elegant nor very reliable probably
139 wxYield();
140
61b98a2d
SL
141 // TODO: consider the "baseUrl" parameter if possible
142 // TODO: consider encoding
143 BSTR bstr = SysAllocString(html.wc_str());
144
145 // Creates a new one-dimensional array
146 SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
147 if (psaStrings != NULL)
148 {
149 VARIANT *param;
150 HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)&param);
151 param->vt = VT_BSTR;
152 param->bstrVal = bstr;
153
154 hr = SafeArrayUnaccessData(psaStrings);
617227c3 155 IHTMLDocument2* document = GetDocument();
61b98a2d
SL
156 document->write(psaStrings);
157
158 // SafeArrayDestroy calls SysFreeString for each BSTR
159 SafeArrayDestroy(psaStrings);
160 }
161 else
162 {
163 wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
164 }
165
166}
167
168wxString wxWebViewIE::GetPageSource()
169{
617227c3 170 IHTMLDocument2* document = GetDocument();
61b98a2d
SL
171 IHTMLElement *bodyTag = NULL;
172 IHTMLElement *htmlTag = NULL;
173 document->get_body(&bodyTag);
174 wxASSERT(bodyTag != NULL);
175
176 document->Release();
177 bodyTag->get_parentElement(&htmlTag);
178 wxASSERT(htmlTag != NULL);
179
180 BSTR bstr;
181 htmlTag->get_outerHTML(&bstr);
182
183 bodyTag->Release();
184 htmlTag->Release();
185
186 //wxMessageBox(wxString(bstr));
187
188 // TODO: check encoding
189 return wxString(bstr);
190}
191
192// FIXME? retrieve OLECMDID_GETZOOMRANGE instead of hardcoding range 0-4
193wxWebViewZoom wxWebViewIE::GetZoom()
194{
195 const int zoom = GetIETextZoom();
196
197 switch (zoom)
198 {
199 case 0:
200 return wxWEB_VIEW_ZOOM_TINY;
201 break;
202 case 1:
203 return wxWEB_VIEW_ZOOM_SMALL;
204 break;
205 case 2:
206 return wxWEB_VIEW_ZOOM_MEDIUM;
207 break;
208 case 3:
209 return wxWEB_VIEW_ZOOM_LARGE;
210 break;
211 case 4:
212 return wxWEB_VIEW_ZOOM_LARGEST;
213 break;
214 default:
215 wxASSERT(false);
216 return wxWEB_VIEW_ZOOM_MEDIUM;
217 }
218}
219void wxWebViewIE::SetZoom(wxWebViewZoom zoom)
220{
221 // I know I could cast from enum to int since wxWebViewZoom happens to
222 // match with IE's zoom levels, but I don't like doing that, what if enum
223 // values change...
224 switch (zoom)
225 {
226 case wxWEB_VIEW_ZOOM_TINY:
227 SetIETextZoom(0);
228 break;
229 case wxWEB_VIEW_ZOOM_SMALL:
230 SetIETextZoom(1);
231 break;
232 case wxWEB_VIEW_ZOOM_MEDIUM:
233 SetIETextZoom(2);
234 break;
235 case wxWEB_VIEW_ZOOM_LARGE:
236 SetIETextZoom(3);
237 break;
238 case wxWEB_VIEW_ZOOM_LARGEST:
239 SetIETextZoom(4);
240 break;
241 default:
242 wxASSERT(false);
243 }
244}
245
246void wxWebViewIE::SetIETextZoom(int level)
247{
248 VARIANT zoomVariant;
249 VariantInit (&zoomVariant);
250 V_VT(&zoomVariant) = VT_I4;
251 V_I4(&zoomVariant) = level;
252
253 HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
254 OLECMDEXECOPT_DONTPROMPTUSER,
255 &zoomVariant, NULL);
256 wxASSERT (result == S_OK);
257
258 VariantClear (&zoomVariant);
259}
260
261int wxWebViewIE::GetIETextZoom()
262{
263 VARIANT zoomVariant;
264 VariantInit (&zoomVariant);
265 V_VT(&zoomVariant) = VT_I4;
266 V_I4(&zoomVariant) = 4;
267
268 HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
269 OLECMDEXECOPT_DONTPROMPTUSER,
270 NULL, &zoomVariant);
271 wxASSERT (result == S_OK);
272
273 int zoom = V_I4(&zoomVariant);
274 // wxMessageBox(wxString::Format("Zoom : %i", zoom));
275 VariantClear (&zoomVariant);
276
277 return zoom;
278}
279
280void wxWebViewIE::SetIEOpticalZoom(float zoom)
281{
282 // TODO: add support for optical zoom (IE7+ only)
283
284 // TODO: get range from OLECMDID_OPTICAL_GETZOOMRANGE instead of hardcoding?
285 wxASSERT(zoom >= 10.0f);
286 wxASSERT(zoom <= 1000.0f);
287
288 VARIANT zoomVariant;
289 VariantInit (&zoomVariant);
290 V_VT(&zoomVariant) = VT_I4;
291 V_I4(&zoomVariant) = (zoom * 100.0f);
292
293 HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
294 OLECMDEXECOPT_DODEFAULT,
295 &zoomVariant,
296 NULL);
297 wxASSERT (result == S_OK);
298}
299
300float wxWebViewIE::GetIEOpticalZoom()
301{
302 // TODO: add support for optical zoom (IE7+ only)
303
304 VARIANT zoomVariant;
305 VariantInit (&zoomVariant);
306 V_VT(&zoomVariant) = VT_I4;
307 V_I4(&zoomVariant) = -1;
308
309 HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
310 OLECMDEXECOPT_DODEFAULT, NULL,
311 &zoomVariant);
312 wxASSERT (result == S_OK);
313
314 const int zoom = V_I4(&zoomVariant);
315 VariantClear (&zoomVariant);
316
317 return zoom / 100.0f;
318}
319
320void wxWebViewIE::SetZoomType(wxWebViewZoomType)
321{
322 // TODO: add support for optical zoom (IE7+ only)
323 wxASSERT(false);
324}
325
326wxWebViewZoomType wxWebViewIE::GetZoomType() const
327{
328 // TODO: add support for optical zoom (IE7+ only)
329 return wxWEB_VIEW_ZOOM_TYPE_TEXT;
330}
331
332bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType) const
333{
334 // both are supported
335 // TODO: IE6 only supports text zoom, check if it's IE6 first
336 return true;
337}
338
339void wxWebViewIE::Print()
340{
341 m_webBrowser->ExecWB(OLECMDID_PRINTPREVIEW,
342 OLECMDEXECOPT_DODEFAULT, NULL, NULL);
343}
344
74af0b13 345bool wxWebViewIE::CanGoBack()
61b98a2d 346{
74af0b13
SL
347 if(m_historyEnabled)
348 return m_historyPosition > 0;
349 else
350 return false;
351}
61b98a2d 352
74af0b13
SL
353bool wxWebViewIE::CanGoForward()
354{
355 if(m_historyEnabled)
356 return m_historyPosition != m_historyList.size() - 1;
357 else
358 return false;
61b98a2d
SL
359}
360
3e7968c2 361void wxWebViewIE::LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item)
61b98a2d 362{
74af0b13
SL
363 int pos = -1;
364 for(unsigned int i = 0; i < m_historyList.size(); i++)
365 {
3e7968c2
SL
366 //We compare the actual pointers to find the correct item
367 if(m_historyList[i].get() == item.get())
74af0b13
SL
368 pos = i;
369 }
60ec2829 370 wxASSERT_MSG(pos != m_historyList.size(), "invalid history item");
74af0b13
SL
371 m_historyLoadingFromList = true;
372 LoadUrl(item->GetUrl());
373 m_historyPosition = pos;
374}
61b98a2d 375
5cbda74b
SL
376wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewIE::GetBackwardHistory()
377{
378 wxVector<wxSharedPtr<wxWebHistoryItem> > backhist;
379 //As we don't have std::copy or an iterator constructor in the wxwidgets
380 //native vector we construct it by hand
381 for(int i = 0; i < m_historyPosition; i++)
382 {
383 backhist.push_back(m_historyList[i]);
384 }
385 return backhist;
386}
387
388wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewIE::GetForwardHistory()
389{
390 wxVector<wxSharedPtr<wxWebHistoryItem> > forwardhist;
391 //As we don't have std::copy or an iterator constructor in the wxwidgets
392 //native vector we construct it by hand
393 for(int i = m_historyPosition + 1; i < m_historyList.size(); i++)
394 {
395 forwardhist.push_back(m_historyList[i]);
396 }
397 return forwardhist;
398}
399
74af0b13
SL
400void wxWebViewIE::GoBack()
401{
3e7968c2 402 LoadHistoryItem(m_historyList[m_historyPosition - 1]);
74af0b13
SL
403}
404
405void wxWebViewIE::GoForward()
406{
3e7968c2 407 LoadHistoryItem(m_historyList[m_historyPosition + 1]);
61b98a2d
SL
408}
409
410void wxWebViewIE::Stop()
411{
412 wxVariant out = m_ie.CallMethod("Stop");
413
414 // FIXME: why is out value null??
415 //return (HRESULT)(out.GetLong()) == S_OK;
416}
417
74af0b13
SL
418void wxWebViewIE::ClearHistory()
419{
420 m_historyList.clear();
421 m_historyPosition = -1;
422}
423
424void wxWebViewIE::EnableHistory(bool enable)
425{
426 m_historyEnabled = enable;
427 m_historyList.clear();
428 m_historyPosition = -1;
429}
61b98a2d
SL
430
431void wxWebViewIE::Reload(wxWebViewReloadFlags flags)
432{
7aa18fc7
SL
433 VARIANTARG level;
434 VariantInit(&level);
435 V_VT(&level) = VT_I2;
61b98a2d 436
7aa18fc7 437 switch(flags)
61b98a2d 438 {
7aa18fc7
SL
439 case wxWEB_VIEW_RELOAD_DEFAULT:
440 V_I2(&level) = REFRESH_NORMAL;
441 break;
442 case wxWEB_VIEW_RELOAD_NO_CACHE:
443 V_I2(&level) = REFRESH_COMPLETELY;
444 break;
445 default:
446 wxFAIL_MSG("Unexpected reload type");
61b98a2d
SL
447 }
448
7aa18fc7 449 m_webBrowser->Refresh2(&level);
61b98a2d
SL
450}
451
452bool wxWebViewIE::IsOfflineMode()
453{
454 wxVariant out = m_ie.GetProperty("Offline");
455
456 wxASSERT(out.GetType() == "bool");
457
458 return out.GetBool();
459}
460
461void wxWebViewIE::SetOfflineMode(bool offline)
462{
463 // FIXME: the wxWidgets docs do not really document what the return
464 // parameter of PutProperty is
465 const bool success = m_ie.PutProperty("Offline", (offline ?
466 VARIANT_TRUE :
467 VARIANT_FALSE));
468 wxASSERT(success);
469}
470
471bool wxWebViewIE::IsBusy()
472{
473 if (m_isBusy) return true;
474
475 wxVariant out = m_ie.GetProperty("Busy");
476
477 wxASSERT(out.GetType() == "bool");
478
479 return out.GetBool();
480}
481
482wxString wxWebViewIE::GetCurrentURL()
483{
484 wxVariant out = m_ie.GetProperty("LocationURL");
485
486 wxASSERT(out.GetType() == "string");
487 return out.GetString();
488}
489
490wxString wxWebViewIE::GetCurrentTitle()
491{
617227c3 492 IHTMLDocument2* document = GetDocument();
977c5320
SL
493
494 BSTR title;
495 document->get_nameProp(&title);
496 return wxString(title);
61b98a2d
SL
497}
498
4681a3ea
SL
499bool wxWebViewIE::CanCut()
500{
501 return CanExecCommand("Cut");
502}
503
504bool wxWebViewIE::CanCopy()
505{
506 return CanExecCommand("Copy");
507}
508bool wxWebViewIE::CanPaste()
509{
510 return CanExecCommand("Paste");
511}
512
513void wxWebViewIE::Cut()
514{
515 ExecCommand("Cut");
516}
517
518void wxWebViewIE::Copy()
519{
520 ExecCommand("Copy");
521}
522
523void wxWebViewIE::Paste()
524{
525 ExecCommand("Paste");
526}
527
97e49559
SL
528bool wxWebViewIE::CanUndo()
529{
530 return CanExecCommand("Undo");
531}
532bool wxWebViewIE::CanRedo()
533{
534 return CanExecCommand("Redo");
535}
536
537void wxWebViewIE::Undo()
538{
539 ExecCommand("Undo");
540}
541
542void wxWebViewIE::Redo()
543{
544 ExecCommand("Redo");
545}
546
4681a3ea
SL
547bool wxWebViewIE::CanExecCommand(wxString command)
548{
617227c3 549 IHTMLDocument2* document = GetDocument();
4681a3ea
SL
550
551 VARIANT_BOOL enabled;
552 document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
553
554 return (enabled == VARIANT_TRUE);
555}
556
557void wxWebViewIE::ExecCommand(wxString command)
558{
617227c3
SL
559 IHTMLDocument2* document = GetDocument();
560 document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
561}
4681a3ea 562
617227c3
SL
563IHTMLDocument2* wxWebViewIE::GetDocument()
564{
565 wxVariant variant = m_ie.GetProperty("Document");
566 IHTMLDocument2* document = (IHTMLDocument2*)variant.GetVoidPtr();
4681a3ea 567
617227c3
SL
568 wxASSERT(document);
569
570 return document;
4681a3ea
SL
571}
572
61b98a2d
SL
573void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
574{
575 if (m_webBrowser == NULL) return;
576
577 switch (evt.GetDispatchId())
578 {
579 case DISPID_BEFORENAVIGATE2:
580 {
581 m_isBusy = true;
582
583 wxString url = evt[1].GetString();
584 wxString target = evt[3].GetString();
585
586 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
587 GetId(), url, target, true);
588 event.SetEventObject(this);
589 HandleWindowEvent(event);
590
591 if (event.IsVetoed())
592 {
593 wxActiveXEventNativeMSW* nativeParams =
594 evt.GetNativeParameters();
595 *V_BOOLREF(&nativeParams->pDispParams->rgvarg[0]) = VARIANT_TRUE;
596 }
597
598 // at this point, either the navigation event has been cancelled
599 // and we're not busy, either it was accepted and IWebBrowser2's
600 // Busy property will be true; so we don't need our override
601 // flag anymore.
602 m_isBusy = false;
603
604 break;
605 }
606
607 case DISPID_NAVIGATECOMPLETE2:
608 {
609 wxString url = evt[1].GetString();
610 // TODO: set target parameter if possible
611 wxString target = wxEmptyString;
612 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
613 GetId(), url, target, false);
614 event.SetEventObject(this);
615 HandleWindowEvent(event);
616 break;
617 }
618
619 case DISPID_PROGRESSCHANGE:
620 {
621 // download progress
622 break;
623 }
624
625 case DISPID_DOCUMENTCOMPLETE:
626 {
3ee442ff
SL
627 //Only send a complete even if we are actually finished, this brings
628 //the event in to line with webkit
629 READYSTATE rs;
630 m_webBrowser->get_ReadyState( &rs );
631 if(rs != READYSTATE_COMPLETE)
632 break;
633
61b98a2d 634 wxString url = evt[1].GetString();
113e0a92
SL
635
636 //As we are complete we also add to the history list, but not if the
637 //page is not the main page, ie it is a subframe
638 if(m_historyEnabled && !m_historyLoadingFromList && url == GetCurrentURL())
74af0b13
SL
639 {
640 //If we are not at the end of the list, then erase everything
641 //between us and the end before adding the new page
642 if(m_historyPosition != m_historyList.size() - 1)
643 {
644 m_historyList.erase(m_historyList.begin() + m_historyPosition + 1,
645 m_historyList.end());
646 }
647 wxSharedPtr<wxWebHistoryItem> item(new wxWebHistoryItem(url, GetCurrentTitle()));
648 m_historyList.push_back(item);
649 m_historyPosition++;
650 }
651 //Reset as we are done now
652 m_historyLoadingFromList = false;
61b98a2d
SL
653 // TODO: set target parameter if possible
654 wxString target = wxEmptyString;
655 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_LOADED, GetId(),
656 url, target, false);
657 event.SetEventObject(this);
658 HandleWindowEvent(event);
659 break;
660 }
661
662 case DISPID_STATUSTEXTCHANGE:
663 {
664 break;
665 }
666
667 case DISPID_TITLECHANGE:
668 {
669 break;
670 }
671
672 case DISPID_NAVIGATEERROR:
673 {
674 wxWebNavigationError errorType = wxWEB_NAV_ERR_OTHER;
675 wxString errorCode = "?";
676 switch (evt[3].GetLong())
677 {
678 case INET_E_INVALID_URL: // (0x800C0002L or -2146697214)
679 errorCode = "INET_E_INVALID_URL";
680 errorType = wxWEB_NAV_ERR_REQUEST;
681 break;
682 case INET_E_NO_SESSION: // (0x800C0003L or -2146697213)
683 errorCode = "INET_E_NO_SESSION";
684 errorType = wxWEB_NAV_ERR_CONNECTION;
685 break;
686 case INET_E_CANNOT_CONNECT: // (0x800C0004L or -2146697212)
687 errorCode = "INET_E_CANNOT_CONNECT";
688 errorType = wxWEB_NAV_ERR_CONNECTION;
689 break;
690 case INET_E_RESOURCE_NOT_FOUND: // (0x800C0005L or -2146697211)
691 errorCode = "INET_E_RESOURCE_NOT_FOUND";
692 errorType = wxWEB_NAV_ERR_NOT_FOUND;
693 break;
694 case INET_E_OBJECT_NOT_FOUND: // (0x800C0006L or -2146697210)
695 errorCode = "INET_E_OBJECT_NOT_FOUND";
696 errorType = wxWEB_NAV_ERR_NOT_FOUND;
697 break;
698 case INET_E_DATA_NOT_AVAILABLE: // (0x800C0007L or -2146697209)
699 errorCode = "INET_E_DATA_NOT_AVAILABLE";
700 errorType = wxWEB_NAV_ERR_NOT_FOUND;
701 break;
702 case INET_E_DOWNLOAD_FAILURE: // (0x800C0008L or -2146697208)
703 errorCode = "INET_E_DOWNLOAD_FAILURE";
704 errorType = wxWEB_NAV_ERR_CONNECTION;
705 break;
706 case INET_E_AUTHENTICATION_REQUIRED: // (0x800C0009L or -2146697207)
707 errorCode = "INET_E_AUTHENTICATION_REQUIRED";
708 errorType = wxWEB_NAV_ERR_AUTH;
709 break;
710 case INET_E_NO_VALID_MEDIA: // (0x800C000AL or -2146697206)
711 errorCode = "INET_E_NO_VALID_MEDIA";
712 errorType = wxWEB_NAV_ERR_REQUEST;
713 break;
714 case INET_E_CONNECTION_TIMEOUT: // (0x800C000BL or -2146697205)
715 errorCode = "INET_E_CONNECTION_TIMEOUT";
716 errorType = wxWEB_NAV_ERR_CONNECTION;
717 break;
718 case INET_E_INVALID_REQUEST: // (0x800C000CL or -2146697204)
719 errorCode = "INET_E_INVALID_REQUEST";
720 errorType = wxWEB_NAV_ERR_REQUEST;
721 break;
722 case INET_E_UNKNOWN_PROTOCOL: // (0x800C000DL or -2146697203)
723 errorCode = "INET_E_UNKNOWN_PROTOCOL";
724 errorType = wxWEB_NAV_ERR_REQUEST;
725 break;
726 case INET_E_SECURITY_PROBLEM: // (0x800C000EL or -2146697202)
727 errorCode = "INET_E_SECURITY_PROBLEM";
728 errorType = wxWEB_NAV_ERR_SECURITY;
729 break;
730 case INET_E_CANNOT_LOAD_DATA: // (0x800C000FL or -2146697201)
731 errorCode = "INET_E_CANNOT_LOAD_DATA";
732 errorType = wxWEB_NAV_ERR_OTHER;
733 break;
734 case INET_E_CANNOT_INSTANTIATE_OBJECT:
735 // CoCreateInstance will return an error code if this happens,
736 // we'll handle this above.
737 return;
738 break;
739 case INET_E_REDIRECT_FAILED: // (0x800C0014L or -2146697196)
740 errorCode = "INET_E_REDIRECT_FAILED";
741 errorType = wxWEB_NAV_ERR_OTHER;
742 break;
743 case INET_E_REDIRECT_TO_DIR: // (0x800C0015L or -2146697195)
744 errorCode = "INET_E_REDIRECT_TO_DIR";
745 errorType = wxWEB_NAV_ERR_REQUEST;
746 break;
747 case INET_E_CANNOT_LOCK_REQUEST: // (0x800C0016L or -2146697194)
748 errorCode = "INET_E_CANNOT_LOCK_REQUEST";
749 errorType = wxWEB_NAV_ERR_OTHER;
750 break;
751 case INET_E_USE_EXTEND_BINDING: // (0x800C0017L or -2146697193)
752 errorCode = "INET_E_USE_EXTEND_BINDING";
753 errorType = wxWEB_NAV_ERR_OTHER;
754 break;
755 case INET_E_TERMINATED_BIND: // (0x800C0018L or -2146697192)
756 errorCode = "INET_E_TERMINATED_BIND";
757 errorType = wxWEB_NAV_ERR_OTHER;
758 break;
759 case INET_E_INVALID_CERTIFICATE: // (0x800C0019L or -2146697191)
760 errorCode = "INET_E_INVALID_CERTIFICATE";
761 errorType = wxWEB_NAV_ERR_CERTIFICATE;
762 break;
763 case INET_E_CODE_DOWNLOAD_DECLINED: // (0x800C0100L or -2146696960)
764 errorCode = "INET_E_CODE_DOWNLOAD_DECLINED";
765 errorType = wxWEB_NAV_ERR_USER_CANCELLED;
766 break;
767 case INET_E_RESULT_DISPATCHED: // (0x800C0200L or -2146696704)
768 // cancel request cancelled...
769 errorCode = "INET_E_RESULT_DISPATCHED";
770 errorType = wxWEB_NAV_ERR_OTHER;
771 break;
772 case INET_E_CANNOT_REPLACE_SFP_FILE: // (0x800C0300L or -2146696448)
773 errorCode = "INET_E_CANNOT_REPLACE_SFP_FILE";
774 errorType = wxWEB_NAV_ERR_SECURITY;
775 break;
776 case INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY:
777 errorCode = "INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY";
778 errorType = wxWEB_NAV_ERR_SECURITY;
779 break;
780 case INET_E_CODE_INSTALL_SUPPRESSED:
781 errorCode = "INET_E_CODE_INSTALL_SUPPRESSED";
782 errorType = wxWEB_NAV_ERR_SECURITY;
783 break;
784 }
785
786 wxString url = evt[1].GetString();
787 wxString target = evt[2].GetString();
788 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_ERROR, GetId(),
789 url, target, false);
790 event.SetEventObject(this);
791 event.SetInt(errorType);
792 event.SetString(errorCode);
793 HandleWindowEvent(event);
794 break;
795 }
796
797 case DISPID_COMMANDSTATECHANGE:
798 {
799 long commandId = evt[0].GetLong();
800 bool enable = evt[1].GetBool();
801 if (commandId == CSC_NAVIGATEBACK)
802 {
803 m_canNavigateBack = enable;
804 }
805 else if (commandId == CSC_NAVIGATEFORWARD)
806 {
807 m_canNavigateForward = enable;
808 }
be19c556 809 break;
61b98a2d 810 }
853b6cd0 811 case DISPID_NEWWINDOW3:
61b98a2d 812 {
853b6cd0
SL
813 wxString url = evt[4].GetString();
814
815 wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
816 GetId(), url, wxEmptyString, true);
817 event.SetEventObject(this);
818 HandleWindowEvent(event);
819
820 //If we veto the event then we cancel the new window
821 if (event.IsVetoed())
822 {
823 wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters();
824 *V_BOOLREF(&nativeParams->pDispParams->rgvarg[3]) = VARIANT_TRUE;
825 }
be19c556
SL
826 break;
827 }
61b98a2d
SL
828 }
829
830 evt.Skip();
831}
832
833#endif