1*520fa265SAndrew Rist /**************************************************************
2*520fa265SAndrew Rist *
3*520fa265SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*520fa265SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*520fa265SAndrew Rist * distributed with this work for additional information
6*520fa265SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*520fa265SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*520fa265SAndrew Rist * "License"); you may not use this file except in compliance
9*520fa265SAndrew Rist * with the License. You may obtain a copy of the License at
10*520fa265SAndrew Rist *
11*520fa265SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*520fa265SAndrew Rist *
13*520fa265SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*520fa265SAndrew Rist * software distributed under the License is distributed on an
15*520fa265SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*520fa265SAndrew Rist * KIND, either express or implied. See the License for the
17*520fa265SAndrew Rist * specific language governing permissions and limitations
18*520fa265SAndrew Rist * under the License.
19*520fa265SAndrew Rist *
20*520fa265SAndrew Rist *************************************************************/
21*520fa265SAndrew Rist
22cdf0e10cSrcweir // SODispatchInterceptor.cpp : Implementation of CHelpApp and DLL registration.
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "stdio.h"
25cdf0e10cSrcweir #include "stdafx2.h"
26cdf0e10cSrcweir #include "so_activex.h"
27cdf0e10cSrcweir #include "SOActiveX.h"
28cdf0e10cSrcweir #include "SODispatchInterceptor.h"
29cdf0e10cSrcweir #include "com_uno_helper.h"
30cdf0e10cSrcweir
31cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////
32cdf0e10cSrcweir //
33cdf0e10cSrcweir
InterfaceSupportsErrorInfo(REFIID riid)34cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::InterfaceSupportsErrorInfo(REFIID riid)
35cdf0e10cSrcweir {
36cdf0e10cSrcweir static const IID* arr[] =
37cdf0e10cSrcweir {
38cdf0e10cSrcweir &IID_ISODispatchInterceptor,
39cdf0e10cSrcweir };
40cdf0e10cSrcweir
41cdf0e10cSrcweir for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir #if defined(_MSC_VER) && (_MSC_VER >= 1300)
44cdf0e10cSrcweir if (InlineIsEqualGUID(*arr[i],riid))
45cdf0e10cSrcweir #else
46cdf0e10cSrcweir if (::ATL::InlineIsEqualGUID(*arr[i],riid))
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir return S_OK;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir return S_FALSE;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir
queryDispatch(IDispatch FAR * aURL,BSTR aTargetFrameName,long nSearchFlags,IDispatch FAR * FAR * retVal)53cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::queryDispatch( IDispatch FAR* aURL,
54cdf0e10cSrcweir BSTR aTargetFrameName,
55cdf0e10cSrcweir long nSearchFlags,
56cdf0e10cSrcweir IDispatch FAR* FAR* retVal )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir if ( !aURL || !retVal ) return E_FAIL;
59cdf0e10cSrcweir
60cdf0e10cSrcweir CComVariant aTargetUrl;
61cdf0e10cSrcweir OLECHAR* sURLMemberName = L"Complete";
62cdf0e10cSrcweir DISPID nURLID;
63cdf0e10cSrcweir HRESULT hr = aURL->GetIDsOfNames( IID_NULL, &sURLMemberName, 1, LOCALE_USER_DEFAULT, &nURLID );
64cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
65cdf0e10cSrcweir
66cdf0e10cSrcweir hr = CComDispatchDriver::GetProperty( aURL, nURLID, &aTargetUrl );
67cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
68cdf0e10cSrcweir
69cdf0e10cSrcweir if( aTargetUrl.vt != VT_BSTR ) return E_FAIL;
70cdf0e10cSrcweir
71cdf0e10cSrcweir USES_CONVERSION;
72cdf0e10cSrcweir if( !strncmp( OLE2T( aTargetUrl.bstrVal ), ".uno:OpenHyperlink", 18 ) )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir CComQIPtr< IDispatch, &IID_IDispatch > pIDisp( this );
75cdf0e10cSrcweir if( pIDisp )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir this->AddRef();
78cdf0e10cSrcweir *retVal = pIDisp;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir else
82cdf0e10cSrcweir {
83cdf0e10cSrcweir if( !m_xSlave )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir *retVal = NULL;
86cdf0e10cSrcweir return S_OK;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir CComVariant aResult;
90cdf0e10cSrcweir CComVariant aArgs[3];
91cdf0e10cSrcweir aArgs[0] = CComVariant( nSearchFlags );
92cdf0e10cSrcweir aArgs[1] = CComVariant( aTargetFrameName );
93cdf0e10cSrcweir aArgs[2] = CComVariant( aURL );
94cdf0e10cSrcweir
95cdf0e10cSrcweir hr = ExecuteFunc( m_xSlave, L"queryDispatch", aArgs, 3, &aResult );
96cdf0e10cSrcweir if( !SUCCEEDED( hr ) || aResult.vt != VT_DISPATCH || aResult.pdispVal == NULL )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir *retVal = NULL;
99cdf0e10cSrcweir return S_OK;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir *retVal = aResult.pdispVal;
103cdf0e10cSrcweir
104cdf0e10cSrcweir CComQIPtr< IUnknown, &IID_IUnknown > pIUnk( *retVal );
105cdf0e10cSrcweir if( pIUnk )
106cdf0e10cSrcweir (*retVal)->AddRef();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir return S_OK;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
queryDispatches(SAFEARRAY FAR * aDescripts,SAFEARRAY FAR * FAR * retVal)112cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::queryDispatches( SAFEARRAY FAR* aDescripts, SAFEARRAY FAR* FAR* retVal)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir if ( !aDescripts || !retVal || SafeArrayGetDim( aDescripts ) != 1 )
115cdf0e10cSrcweir return E_FAIL;
116cdf0e10cSrcweir
117cdf0e10cSrcweir long nLB, nUB;
118cdf0e10cSrcweir
119cdf0e10cSrcweir HRESULT hr = SafeArrayGetLBound( aDescripts, 1, &nLB );
120cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
121cdf0e10cSrcweir
122cdf0e10cSrcweir hr = SafeArrayGetUBound( aDescripts, 1, &nUB );
123cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
124cdf0e10cSrcweir if( nUB < nLB ) return E_FAIL;
125cdf0e10cSrcweir
126cdf0e10cSrcweir *retVal = SafeArrayCreateVector( VT_DISPATCH, 0, nUB - nLB );
127cdf0e10cSrcweir
128cdf0e10cSrcweir for ( long ind = nLB; ind <= nUB; ind ++ )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir CComPtr<IDispatch> pElem;
131cdf0e10cSrcweir SafeArrayGetElement( aDescripts, &ind, pElem );
132cdf0e10cSrcweir if( pElem )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir OLECHAR* pMemberNames[3] = { L"FeatureURL", L"FrameName", L"SearchFlags" };
135cdf0e10cSrcweir CComVariant pValues[3];
136cdf0e10cSrcweir hr = GetPropertiesFromIDisp( pElem, pMemberNames, pValues, 3 );
137cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
138cdf0e10cSrcweir if( pValues[0].vt != VT_DISPATCH || pValues[0].pdispVal == NULL
139cdf0e10cSrcweir || pValues[1].vt != VT_BSTR || pValues[2].vt != VT_I4 )
140cdf0e10cSrcweir return E_FAIL;
141cdf0e10cSrcweir
142cdf0e10cSrcweir CComPtr<IDispatch> aRes;
143cdf0e10cSrcweir hr = queryDispatch( pValues[0].pdispVal, pValues[1].bstrVal, pValues[2].lVal, &aRes );
144cdf0e10cSrcweir SafeArrayPutElement( *retVal, &ind, aRes );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir return S_OK;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir
dispatch(IDispatch FAR * aURL,SAFEARRAY FAR * aArgs)152cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::dispatch( IDispatch FAR* aURL, SAFEARRAY FAR* aArgs)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir // get url from aURL
155cdf0e10cSrcweir OLECHAR* pUrlName = L"Complete";
156cdf0e10cSrcweir CComVariant pValue;
157cdf0e10cSrcweir HRESULT hr = GetPropertiesFromIDisp( aURL, &pUrlName, &pValue, 1 );
158cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
159cdf0e10cSrcweir if( pValue.vt != VT_BSTR || pValue.bstrVal == NULL )
160cdf0e10cSrcweir return E_FAIL;
161cdf0e10cSrcweir
162cdf0e10cSrcweir USES_CONVERSION;
163cdf0e10cSrcweir if( !strncmp( OLE2T( pValue.bstrVal ), ".uno:OpenHyperlink", 18 ) )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir long nLB = 0, nUB = 0;
166cdf0e10cSrcweir // long nDim = SafeArrayGetDim( aArgs );
167cdf0e10cSrcweir
168cdf0e10cSrcweir hr = SafeArrayGetLBound( aArgs, 1, &nLB );
169cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
170cdf0e10cSrcweir
171cdf0e10cSrcweir hr = SafeArrayGetUBound( aArgs, 1, &nUB );
172cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
173cdf0e10cSrcweir if( nUB < nLB ) return E_FAIL;
174cdf0e10cSrcweir
175cdf0e10cSrcweir for ( long ind = nLB; ind <= nUB; ind ++ )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir CComVariant pVarElem;
178cdf0e10cSrcweir SafeArrayGetElement( aArgs, &ind, &pVarElem );
179cdf0e10cSrcweir if( pVarElem.vt == VT_DISPATCH && pVarElem.pdispVal != NULL )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir OLECHAR* pMemberNames[2] = { L"Name", L"Value" };
182cdf0e10cSrcweir CComVariant pValues[2];
183cdf0e10cSrcweir hr = GetPropertiesFromIDisp( pVarElem.pdispVal, pMemberNames, pValues, 2 );
184cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr;
185cdf0e10cSrcweir
186cdf0e10cSrcweir if( pValues[0].vt == VT_BSTR && pValues[1].vt == VT_BSTR )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir USES_CONVERSION;
189cdf0e10cSrcweir if( !strncmp( OLE2T( pValues[0].bstrVal ), "URL", 3 ) )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir EnterCriticalSection( &mMutex );
192cdf0e10cSrcweir if( m_xParentControl )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir // call GetUrl to the browser instance
195cdf0e10cSrcweir m_xParentControl->GetURL( pValues[1].bstrVal, L"_self" );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir LeaveCriticalSection( &mMutex );
198cdf0e10cSrcweir
199cdf0e10cSrcweir break;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir }
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir return S_OK;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
addStatusListener(IDispatch FAR *,IDispatch FAR *)209cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::addStatusListener( IDispatch FAR* /*xControl*/, IDispatch FAR* /*aURL*/)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir // not implemented
212cdf0e10cSrcweir return S_OK;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
removeStatusListener(IDispatch FAR *,IDispatch FAR *)215cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::removeStatusListener( IDispatch FAR* /*xControl*/, IDispatch FAR* /*aURL*/)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir // not implemented
218cdf0e10cSrcweir return S_OK;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir
getInterceptedURLs(SAFEARRAY FAR * FAR * pVal)221cdf0e10cSrcweir STDMETHODIMP SODispatchInterceptor::getInterceptedURLs( SAFEARRAY FAR* FAR* pVal )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir *pVal = SafeArrayCreateVector( VT_BSTR, 0, 3 );
224cdf0e10cSrcweir
225cdf0e10cSrcweir if( !*pVal )
226cdf0e10cSrcweir return E_FAIL;
227cdf0e10cSrcweir
228cdf0e10cSrcweir long ix = 0;
229cdf0e10cSrcweir CComBSTR aPattern( OLESTR( "ftp://*" ) );
230cdf0e10cSrcweir SafeArrayPutElement( *pVal, &ix, aPattern );
231cdf0e10cSrcweir
232cdf0e10cSrcweir ix = 1;
233cdf0e10cSrcweir aPattern = CComBSTR( OLESTR( "http://*" ) );
234cdf0e10cSrcweir SafeArrayPutElement( *pVal, &ix, aPattern );
235cdf0e10cSrcweir
236cdf0e10cSrcweir ix = 2;
237cdf0e10cSrcweir aPattern = CComBSTR( OLESTR( "file://*" ) );
238cdf0e10cSrcweir SafeArrayPutElement( *pVal, &ix, aPattern );
239cdf0e10cSrcweir
240cdf0e10cSrcweir return S_OK;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir
244