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