Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / extensions / source / activex / SODispatchInterceptor.cxx
blobaf3d69e02ea9c064a14513e22394ea809020399a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // SODispatchInterceptor.cpp : Implementation of CHelpApp and DLL registration.
22 #include <sal/config.h>
24 #include <cstddef>
26 #include <stdio.h>
27 #include "StdAfx2.h"
28 #include <so_activex.h>
29 #include "SOActiveX.h"
30 #include "SODispatchInterceptor.h"
31 #include "com_uno_helper.h"
32 #include <sal/macros.h>
34 COM_DECLSPEC_NOTHROW STDMETHODIMP SODispatchInterceptor::InterfaceSupportsErrorInfo(REFIID riid)
36 static const IID* arr[] =
38 &IID_ISODispatchInterceptor,
41 for (auto const &i : arr)
43 if (InlineIsEqualGUID(*i,riid))
44 return S_OK;
46 return S_FALSE;
49 STDMETHODIMP SODispatchInterceptor::queryDispatch(IDispatch* aURL, BSTR aTargetFrameName,
50 long nSearchFlags, IDispatch** retVal)
52 if ( !aURL || !retVal ) return E_FAIL;
54 CComVariant aTargetUrl;
55 OLECHAR const * sURLMemberName = L"Complete";
56 DISPID nURLID;
57 HRESULT hr = aURL->GetIDsOfNames( IID_NULL, const_cast<OLECHAR **>(&sURLMemberName), 1, LOCALE_USER_DEFAULT, &nURLID );
58 if( !SUCCEEDED( hr ) ) return hr;
60 hr = CComDispatchDriver::GetProperty( aURL, nURLID, &aTargetUrl );
61 if( !SUCCEEDED( hr ) ) return hr;
63 if( aTargetUrl.vt != VT_BSTR ) return E_FAIL;
65 if (!wcsncmp(aTargetUrl.bstrVal, L".uno:OpenHyperlink", 18))
67 CComQIPtr< IDispatch, &IID_IDispatch > pIDisp( this );
68 if( pIDisp )
70 this->AddRef();
71 *retVal = pIDisp;
74 else
76 if( !m_xSlave )
78 *retVal = nullptr;
79 return S_OK;
82 CComVariant aResult;
83 CComVariant aArgs[3];
84 aArgs[0] = CComVariant( nSearchFlags );
85 aArgs[1] = CComVariant( aTargetFrameName );
86 aArgs[2] = CComVariant( aURL );
88 hr = ExecuteFunc( m_xSlave, L"queryDispatch", aArgs, 3, &aResult );
89 if( !SUCCEEDED( hr ) || aResult.vt != VT_DISPATCH || aResult.pdispVal == nullptr )
91 *retVal = nullptr;
92 return S_OK;
95 *retVal = aResult.pdispVal;
97 CComQIPtr< IUnknown, &IID_IUnknown > pIUnk( *retVal );
98 if( pIUnk )
99 (*retVal)->AddRef();
102 return S_OK;
105 STDMETHODIMP SODispatchInterceptor::queryDispatches(SAFEARRAY* aDescripts, SAFEARRAY** retVal)
107 if ( !aDescripts || !retVal || SafeArrayGetDim( aDescripts ) != 1 )
108 return E_FAIL;
110 LONG nLB, nUB;
112 HRESULT hr = SafeArrayGetLBound( aDescripts, 1, &nLB );
113 if( !SUCCEEDED( hr ) ) return hr;
115 hr = SafeArrayGetUBound( aDescripts, 1, &nUB );
116 if( !SUCCEEDED( hr ) ) return hr;
117 if( nUB < nLB ) return E_FAIL;
119 *retVal = SafeArrayCreateVector( VT_DISPATCH, 0, nUB - nLB );
121 for ( LONG ind = nLB; ind <= nUB; ind ++ )
123 CComPtr<IDispatch> pElem;
124 SafeArrayGetElement( aDescripts, &ind, pElem );
125 if( pElem )
127 OLECHAR const * pMemberNames[3] = { L"FeatureURL", L"FrameName", L"SearchFlags" };
128 CComVariant pValues[3];
129 hr = GetPropertiesFromIDisp( pElem, pMemberNames, pValues, 3 );
130 if( !SUCCEEDED( hr ) ) return hr;
131 if( pValues[0].vt != VT_DISPATCH || pValues[0].pdispVal == nullptr
132 || pValues[1].vt != VT_BSTR || pValues[2].vt != VT_I4 )
133 return E_FAIL;
135 CComPtr<IDispatch> aRes;
136 hr = queryDispatch( pValues[0].pdispVal, pValues[1].bstrVal, pValues[2].lVal, &aRes );
137 SafeArrayPutElement( *retVal, &ind, aRes );
141 return S_OK;
145 STDMETHODIMP SODispatchInterceptor::dispatch(IDispatch* aURL, SAFEARRAY* aArgs)
147 // get url from aURL
148 OLECHAR const * pUrlName = L"Complete";
149 CComVariant pValue;
150 HRESULT hr = GetPropertiesFromIDisp( aURL, &pUrlName, &pValue, 1 );
151 if( !SUCCEEDED( hr ) ) return hr;
152 if( pValue.vt != VT_BSTR || pValue.bstrVal == nullptr )
153 return E_FAIL;
155 if (!wcsncmp(pValue.bstrVal, L".uno:OpenHyperlink", 18))
157 LONG nLB = 0, nUB = 0;
158 // long nDim = SafeArrayGetDim( aArgs );
160 hr = SafeArrayGetLBound( aArgs, 1, &nLB );
161 if( !SUCCEEDED( hr ) ) return hr;
163 hr = SafeArrayGetUBound( aArgs, 1, &nUB );
164 if( !SUCCEEDED( hr ) ) return hr;
165 if( nUB < nLB ) return E_FAIL;
167 for ( LONG ind = nLB; ind <= nUB; ind ++ )
169 CComVariant pVarElem;
170 SafeArrayGetElement( aArgs, &ind, &pVarElem );
171 if( pVarElem.vt == VT_DISPATCH && pVarElem.pdispVal != nullptr )
173 OLECHAR const * pMemberNames[2] = { L"Name", L"Value" };
174 CComVariant pValues[2];
175 hr = GetPropertiesFromIDisp( pVarElem.pdispVal, pMemberNames, pValues, 2 );
176 if( !SUCCEEDED( hr ) ) return hr;
178 if( pValues[0].vt == VT_BSTR && pValues[1].vt == VT_BSTR )
180 if (!wcsncmp(pValues[0].bstrVal, L"URL", 3))
182 EnterCriticalSection( &mMutex );
183 if( m_xParentControl )
185 // call GetUrl to the browser instance
186 m_xParentControl->GetURL( pValues[1].bstrVal, L"_self" );
188 LeaveCriticalSection( &mMutex );
190 break;
197 return S_OK;
200 STDMETHODIMP SODispatchInterceptor::addStatusListener(IDispatch* /*xControl*/, IDispatch* /*aURL*/)
202 // not implemented
203 return S_OK;
206 STDMETHODIMP SODispatchInterceptor::removeStatusListener(IDispatch* /*xControl*/,
207 IDispatch* /*aURL*/)
209 // not implemented
210 return S_OK;
213 STDMETHODIMP SODispatchInterceptor::getInterceptedURLs(SAFEARRAY** pVal)
215 *pVal = SafeArrayCreateVector( VT_BSTR, 0, 3 );
217 if( !*pVal )
218 return E_FAIL;
220 LONG ix = 0;
221 CComBSTR aPattern( OLESTR( "ftp://*" ) );
222 SafeArrayPutElement( *pVal, &ix, aPattern );
224 ix = 1;
225 aPattern = CComBSTR( OLESTR( "http://*" ) );
226 SafeArrayPutElement( *pVal, &ix, aPattern );
228 ix = 2;
229 aPattern = CComBSTR( OLESTR( "file://*" ) );
230 SafeArrayPutElement( *pVal, &ix, aPattern );
232 return S_OK;
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */