1 // SODispatchInterceptor.cpp : Implementation of CHelpApp and DLL registration.
5 #include "so_activex.h"
7 #include "SODispatchInterceptor.h"
8 #include "com_uno_helper.h"
10 /////////////////////////////////////////////////////////////////////////////
13 STDMETHODIMP
SODispatchInterceptor::InterfaceSupportsErrorInfo(REFIID riid
)
15 static const IID
* arr
[] =
17 &IID_ISODispatchInterceptor
,
20 for (int i
=0;i
<sizeof(arr
)/sizeof(arr
[0]);i
++)
22 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
23 if (InlineIsEqualGUID(*arr
[i
],riid
))
25 if (::ATL::InlineIsEqualGUID(*arr
[i
],riid
))
32 STDMETHODIMP
SODispatchInterceptor::queryDispatch( IDispatch FAR
* aURL
,
33 BSTR aTargetFrameName
,
35 IDispatch FAR
* FAR
* retVal
)
37 if ( !aURL
|| !retVal
) return E_FAIL
;
39 CComVariant aTargetUrl
;
40 OLECHAR
* sURLMemberName
= L
"Complete";
42 HRESULT hr
= aURL
->GetIDsOfNames( IID_NULL
, &sURLMemberName
, 1, LOCALE_USER_DEFAULT
, &nURLID
);
43 if( !SUCCEEDED( hr
) ) return hr
;
45 hr
= CComDispatchDriver::GetProperty( aURL
, nURLID
, &aTargetUrl
);
46 if( !SUCCEEDED( hr
) ) return hr
;
48 if( aTargetUrl
.vt
!= VT_BSTR
) return E_FAIL
;
51 if( !strncmp( OLE2T( aTargetUrl
.bstrVal
), ".uno:OpenHyperlink", 18 ) )
53 CComQIPtr
< IDispatch
, &IID_IDispatch
> pIDisp( this );
70 aArgs
[0] = CComVariant( nSearchFlags
);
71 aArgs
[1] = CComVariant( aTargetFrameName
);
72 aArgs
[2] = CComVariant( aURL
);
74 hr
= ExecuteFunc( m_xSlave
, L
"queryDispatch", aArgs
, 3, &aResult
);
75 if( !SUCCEEDED( hr
) || aResult
.vt
!= VT_DISPATCH
|| aResult
.pdispVal
== NULL
)
81 *retVal
= aResult
.pdispVal
;
83 CComQIPtr
< IUnknown
, &IID_IUnknown
> pIUnk( *retVal
);
91 STDMETHODIMP
SODispatchInterceptor::queryDispatches( SAFEARRAY FAR
* aDescripts
, SAFEARRAY FAR
* FAR
* retVal
)
93 if ( !aDescripts
|| !retVal
|| SafeArrayGetDim( aDescripts
) != 1 )
98 HRESULT hr
= SafeArrayGetLBound( aDescripts
, 1, &nLB
);
99 if( !SUCCEEDED( hr
) ) return hr
;
101 hr
= SafeArrayGetUBound( aDescripts
, 1, &nUB
);
102 if( !SUCCEEDED( hr
) ) return hr
;
103 if( nUB
< nLB
) return E_FAIL
;
105 *retVal
= SafeArrayCreateVector( VT_DISPATCH
, 0, nUB
- nLB
);
107 for ( long ind
= nLB
; ind
<= nUB
; ind
++ )
109 CComPtr
<IDispatch
> pElem
;
110 SafeArrayGetElement( aDescripts
, &ind
, pElem
);
113 OLECHAR
* pMemberNames
[3] = { L
"FeatureURL", L
"FrameName", L
"SearchFlags" };
114 CComVariant pValues
[3];
115 hr
= GetPropertiesFromIDisp( pElem
, pMemberNames
, pValues
, 3 );
116 if( !SUCCEEDED( hr
) ) return hr
;
117 if( pValues
[0].vt
!= VT_DISPATCH
|| pValues
[0].pdispVal
== NULL
118 || pValues
[1].vt
!= VT_BSTR
|| pValues
[2].vt
!= VT_I4
)
121 CComPtr
<IDispatch
> aRes
;
122 hr
= queryDispatch( pValues
[0].pdispVal
, pValues
[1].bstrVal
, pValues
[2].lVal
, &aRes
);
123 SafeArrayPutElement( *retVal
, &ind
, aRes
);
131 STDMETHODIMP
SODispatchInterceptor::dispatch( IDispatch FAR
* aURL
, SAFEARRAY FAR
* aArgs
)
134 OLECHAR
* pUrlName
= L
"Complete";
136 HRESULT hr
= GetPropertiesFromIDisp( aURL
, &pUrlName
, &pValue
, 1 );
137 if( !SUCCEEDED( hr
) ) return hr
;
138 if( pValue
.vt
!= VT_BSTR
|| pValue
.bstrVal
== NULL
)
142 if( !strncmp( OLE2T( pValue
.bstrVal
), ".uno:OpenHyperlink", 18 ) )
144 long nLB
= 0, nUB
= 0;
145 // long nDim = SafeArrayGetDim( aArgs );
147 hr
= SafeArrayGetLBound( aArgs
, 1, &nLB
);
148 if( !SUCCEEDED( hr
) ) return hr
;
150 hr
= SafeArrayGetUBound( aArgs
, 1, &nUB
);
151 if( !SUCCEEDED( hr
) ) return hr
;
152 if( nUB
< nLB
) return E_FAIL
;
154 for ( long ind
= nLB
; ind
<= nUB
; ind
++ )
156 CComVariant pVarElem
;
157 SafeArrayGetElement( aArgs
, &ind
, &pVarElem
);
158 if( pVarElem
.vt
== VT_DISPATCH
&& pVarElem
.pdispVal
!= NULL
)
160 OLECHAR
* pMemberNames
[2] = { L
"Name", L
"Value" };
161 CComVariant pValues
[2];
162 hr
= GetPropertiesFromIDisp( pVarElem
.pdispVal
, pMemberNames
, pValues
, 2 );
163 if( !SUCCEEDED( hr
) ) return hr
;
165 if( pValues
[0].vt
== VT_BSTR
&& pValues
[1].vt
== VT_BSTR
)
168 if( !strncmp( OLE2T( pValues
[0].bstrVal
), "URL", 3 ) )
170 EnterCriticalSection( &mMutex
);
171 if( m_xParentControl
)
173 // call GetUrl to the browser instance
174 m_xParentControl
->GetURL( pValues
[1].bstrVal
, L
"_self" );
176 LeaveCriticalSection( &mMutex
);
188 STDMETHODIMP
SODispatchInterceptor::addStatusListener( IDispatch FAR
* /*xControl*/, IDispatch FAR
* /*aURL*/)
194 STDMETHODIMP
SODispatchInterceptor::removeStatusListener( IDispatch FAR
* /*xControl*/, IDispatch FAR
* /*aURL*/)
200 STDMETHODIMP
SODispatchInterceptor::getInterceptedURLs( SAFEARRAY FAR
* FAR
* pVal
)
202 *pVal
= SafeArrayCreateVector( VT_BSTR
, 0, 3 );
208 CComBSTR
aPattern( OLESTR( "ftp://*" ) );
209 SafeArrayPutElement( *pVal
, &ix
, aPattern
);
212 aPattern
= CComBSTR( OLESTR( "http://*" ) );
213 SafeArrayPutElement( *pVal
, &ix
, aPattern
);
216 aPattern
= CComBSTR( OLESTR( "file://*" ) );
217 SafeArrayPutElement( *pVal
, &ix
, aPattern
);