Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "scripthandler.hxx"
21 : :
22 : : #include <osl/mutex.hxx>
23 : :
24 : : #include <com/sun/star/frame/DispatchResultEvent.hpp>
25 : : #include <com/sun/star/frame/DispatchResultState.hpp>
26 : : #include <com/sun/star/frame/XController.hpp>
27 : : #include <com/sun/star/frame/XModel.hpp>
28 : :
29 : : #include <com/sun/star/document/XEmbeddedScripts.hpp>
30 : : #include <com/sun/star/document/XScriptInvocationContext.hpp>
31 : :
32 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
33 : :
34 : : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
35 : : #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
36 : : #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
37 : :
38 : : #include <sfx2/objsh.hxx>
39 : : #include <sfx2/frame.hxx>
40 : : #include <sfx2/sfxdlg.hxx>
41 : : #include <vcl/abstdlg.hxx>
42 : : #include <tools/diagnose_ex.h>
43 : :
44 : : #include <cppuhelper/factory.hxx>
45 : : #include <cppuhelper/exc_hlp.hxx>
46 : : #include <util/util.hxx>
47 : : #include <framework/documentundoguard.hxx>
48 : :
49 : : #include "com/sun/star/uno/XComponentContext.hpp"
50 : : #include "com/sun/star/uri/XUriReference.hpp"
51 : : #include "com/sun/star/uri/XUriReferenceFactory.hpp"
52 : : #include "com/sun/star/uri/XVndSunStarScriptUrl.hpp"
53 : : #include "com/sun/star/beans/XPropertySet.hpp"
54 : :
55 : : using namespace ::com::sun::star;
56 : : using namespace ::com::sun::star::uno;
57 : : using namespace ::com::sun::star::frame;
58 : : using namespace ::com::sun::star::util;
59 : : using namespace ::com::sun::star::beans;
60 : : using namespace ::com::sun::star::lang;
61 : : using namespace ::com::sun::star::script;
62 : : using namespace ::com::sun::star::script::provider;
63 : : using namespace ::com::sun::star::document;
64 : :
65 : : namespace scripting_protocolhandler
66 : : {
67 : :
68 : : const sal_Char * const MYSERVICENAME = "com.sun.star.frame.ProtocolHandler";
69 : : const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler";
70 : : const sal_Char * MYSCHEME = "vnd.sun.star.script";
71 : : const sal_Int32 MYSCHEME_LEN = 20;
72 : :
73 : 8 : void SAL_CALL ScriptProtocolHandler::initialize(
74 : : const css::uno::Sequence < css::uno::Any >& aArguments )
75 : : throw ( css::uno::Exception )
76 : : {
77 [ - + ]: 8 : if ( m_bInitialised )
78 : : {
79 : 8 : return ;
80 : : }
81 : :
82 : : // first argument contains a reference to the frame (may be empty or the desktop,
83 : : // but usually it's a "real" frame)
84 [ + - - + ]: 16 : if ( aArguments.getLength() &&
[ - + ]
85 : 8 : sal_False == ( aArguments[ 0 ] >>= m_xFrame ) )
86 : : {
87 [ # # ]: 0 : ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::initialize: could not extract reference to the frame" );
88 [ # # ]: 0 : throw RuntimeException( temp, Reference< XInterface >() );
89 : : }
90 : :
91 [ - + ][ # # ]: 8 : ENSURE_OR_THROW( m_xFactory.is(), "ScriptProtocolHandler::initialize: No Service Manager available" );
[ # # ][ # # ]
92 : 8 : m_bInitialised = true;
93 : : }
94 : :
95 : 8 : Reference< XDispatch > SAL_CALL ScriptProtocolHandler::queryDispatch(
96 : : const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
97 : : throw( ::com::sun::star::uno::RuntimeException )
98 : : {
99 : : (void)sTargetFrameName;
100 : : (void)nSearchFlags;
101 : :
102 : 8 : Reference< XDispatch > xDispatcher;
103 : : // get scheme of url
104 : :
105 : : Reference< uri::XUriReferenceFactory > xFac (
106 [ + - ]: 8 : m_xFactory->createInstance( rtl::OUString(
107 [ + - ][ + - ]: 8 : "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY );
108 [ + - ]: 8 : if ( xFac.is() )
109 : : {
110 : : Reference< uri::XUriReference > uriRef(
111 [ + - ][ + - ]: 8 : xFac->parse( aURL.Complete ), UNO_QUERY );
[ + - ]
112 [ + - ]: 8 : if ( uriRef.is() )
113 : : {
114 [ + - ][ + - ]: 8 : if ( uriRef->getScheme().equals( ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYSCHEME ) ) )
[ + - ]
115 : : {
116 [ + - ]: 8 : xDispatcher = this;
117 : : }
118 : 8 : }
119 : : }
120 : :
121 : 8 : return xDispatcher;
122 : : }
123 : :
124 : : Sequence< Reference< XDispatch > > SAL_CALL
125 : 0 : ScriptProtocolHandler::queryDispatches(
126 : : const Sequence < DispatchDescriptor >& seqDescriptor )
127 : : throw( RuntimeException )
128 : : {
129 : 0 : sal_Int32 nCount = seqDescriptor.getLength();
130 : 0 : Sequence< Reference< XDispatch > > lDispatcher( nCount );
131 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
132 : : {
133 [ # # ]: 0 : lDispatcher[ i ] = this->queryDispatch( seqDescriptor[ i ].FeatureURL,
134 : 0 : seqDescriptor[ i ].FrameName,
135 [ # # ][ # # ]: 0 : seqDescriptor[ i ].SearchFlags );
136 : : }
137 : 0 : return lDispatcher;
138 : : }
139 : :
140 : 8 : void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
141 : : const URL& aURL, const Sequence < PropertyValue >& lArgs,
142 : : const Reference< XDispatchResultListener >& xListener )
143 : : throw ( RuntimeException )
144 : : {
145 : :
146 : 8 : sal_Bool bSuccess = sal_False;
147 : 8 : Any invokeResult;
148 : 8 : bool bCaughtException = sal_False;
149 : 8 : Any aException;
150 : :
151 [ + - ]: 8 : if ( m_bInitialised )
152 : : {
153 : : try
154 : : {
155 : 8 : bool bIsDocumentScript = ( aURL.Complete.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "document" ) ) !=-1 );
156 : : // TODO: isn't this somewhat strange? This should be a test for a location=document parameter, shouldn't it?
157 : :
158 [ + - ]: 8 : if ( bIsDocumentScript )
159 : : {
160 : : // obtain the component for our security check
161 : 8 : Reference< XEmbeddedScripts > xDocumentScripts;
162 [ + - ][ + - ]: 8 : if ( getScriptInvocation() )
163 [ + - ][ + - ]: 8 : xDocumentScripts.set( m_xScriptInvocation->getScriptContainer(), UNO_SET_THROW );
[ + - ]
164 : :
165 : : OSL_ENSURE( xDocumentScripts.is(), "ScriptProtocolHandler::dispatchWithNotification: can't do the security check!" );
166 [ + - ][ + - ]: 8 : if ( !xDocumentScripts.is() || !xDocumentScripts->getAllowMacroExecution() )
[ + - ][ - + ]
[ - + ]
167 [ + - ]: 16 : return;
168 : : }
169 : :
170 : : // Creates a ScriptProvider ( if one is not created allready )
171 [ + - ]: 8 : createScriptProvider();
172 : :
173 : : Reference< provider::XScript > xFunc =
174 [ + - ][ + - ]: 8 : m_xScriptProvider->getScript( aURL.Complete );
175 [ - + ][ # # ]: 8 : ENSURE_OR_THROW( xFunc.is(),
[ # # ][ # # ]
176 : : "ScriptProtocolHandler::dispatchWithNotification: validate xFunc - unable to obtain XScript interface" );
177 : :
178 : :
179 [ + - ]: 8 : Sequence< Any > inArgs( 0 );
180 [ + - ]: 8 : Sequence< Any > outArgs( 0 );
181 [ + - ]: 8 : Sequence< sal_Int16 > outIndex;
182 : :
183 [ + + ]: 8 : if ( lArgs.getLength() > 0 )
184 : : {
185 : 2 : int argCount = 0;
186 [ + + ]: 4 : for ( int index = 0; index < lArgs.getLength(); index++ )
187 : : {
188 : : // Sometimes we get a propertyval with name = "Referer"
189 : : // this is not an argument to be passed to script, so
190 : : // ignore.
191 [ - + # # ]: 2 : if ( lArgs[ index ].Name.compareToAscii("Referer") != 0 ||
[ + - ]
192 : 0 : lArgs[ index ].Name.isEmpty() )
193 : : {
194 [ + - ]: 2 : inArgs.realloc( ++argCount );
195 [ + - ]: 2 : inArgs[ argCount - 1 ] = lArgs[ index ].Value;
196 : : }
197 : : }
198 : : }
199 : :
200 : : // attempt to protect the document against the script tampering with its Undo Context
201 : 8 : ::std::auto_ptr< ::framework::DocumentUndoGuard > pUndoGuard;
202 [ + - ]: 8 : if ( bIsDocumentScript )
203 [ + - ][ + - ]: 8 : pUndoGuard.reset( new ::framework::DocumentUndoGuard( m_xScriptInvocation ) );
204 : :
205 : 8 : bSuccess = sal_False;
206 [ + + ]: 16 : while ( !bSuccess )
207 : : {
208 : 8 : Any aFirstCaughtException;
209 : : try
210 : : {
211 [ + - ][ + - ]: 8 : invokeResult = xFunc->invoke( inArgs, outIndex, outArgs );
212 : 8 : bSuccess = sal_True;
213 : : }
214 [ # # # # ]: 0 : catch( const provider::ScriptFrameworkErrorException& se )
215 : : {
216 [ # # ]: 0 : if ( !aFirstCaughtException.hasValue() )
217 [ # # ]: 0 : aFirstCaughtException = ::cppu::getCaughtException();
218 : :
219 [ # # ]: 0 : if ( se.errorType != provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT )
220 : : // the only condition which allows us to retry is if there is no method with the
221 : : // given name/signature
222 [ # # ]: 0 : ::cppu::throwException( aFirstCaughtException );
223 : :
224 [ # # ]: 0 : if ( inArgs.getLength() == 0 )
225 : : // no chance to retry if we can't strip more in-args
226 [ # # ]: 0 : ::cppu::throwException( aFirstCaughtException );
227 : :
228 : : // strip one argument, then retry
229 [ # # ]: 0 : inArgs.realloc( inArgs.getLength() - 1 );
230 : : }
231 [ + - ][ + - ]: 16 : }
[ + - ][ + - ]
232 : : }
233 : : // Office doesn't handle exceptions rethrown here very well, it cores,
234 : : // all we can is log them and then set fail for the dispatch event!
235 : : // (if there is a listener of course)
236 [ # # # # ]: 0 : catch ( const Exception & e )
237 : : {
238 [ # # ]: 0 : aException = ::cppu::getCaughtException();
239 : :
240 : 0 : ::rtl::OUString reason = ::rtl::OUString( "ScriptProtocolHandler::dispatch: caught " );
241 : :
242 [ # # ]: 0 : invokeResult <<= reason.concat( aException.getValueTypeName() ).concat( e.Message );
243 : :
244 : 0 : bCaughtException = sal_True;
245 : : }
246 : : }
247 : : else
248 : : {
249 : : ::rtl::OUString reason(
250 : : "ScriptProtocolHandler::dispatchWithNotification failed, ScriptProtocolHandler not initialised"
251 : 0 : );
252 [ # # ]: 0 : invokeResult <<= reason;
253 : : }
254 : :
255 [ - + ]: 8 : if ( bCaughtException )
256 : : {
257 [ # # ]: 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
258 : :
259 [ # # ]: 0 : if ( pFact != NULL )
260 : : {
261 : : VclAbstractDialog* pDlg =
262 [ # # ][ # # ]: 0 : pFact->CreateScriptErrorDialog( NULL, aException );
263 : :
264 [ # # ]: 0 : if ( pDlg != NULL )
265 : : {
266 [ # # ]: 0 : pDlg->Execute();
267 [ # # ][ # # ]: 0 : delete pDlg;
268 : : }
269 : : }
270 : : }
271 : :
272 [ + + ]: 8 : if ( xListener.is() )
273 : : {
274 : : // always call dispatchFinished(), because we didn't load a document but
275 : : // executed a macro instead!
276 [ + - ]: 2 : ::com::sun::star::frame::DispatchResultEvent aEvent;
277 : :
278 [ + - ]: 2 : aEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
279 : 2 : aEvent.Result = invokeResult;
280 [ + - ]: 2 : if ( bSuccess )
281 : : {
282 : 2 : aEvent.State = ::com::sun::star::frame::DispatchResultState::SUCCESS;
283 : : }
284 : : else
285 : : {
286 : 0 : aEvent.State = ::com::sun::star::frame::DispatchResultState::FAILURE;
287 : : }
288 : :
289 : : try
290 : : {
291 [ + - ][ + - ]: 2 : xListener->dispatchFinished( aEvent ) ;
292 : : }
293 [ # # ]: 0 : catch(const RuntimeException & e)
294 : : {
295 : : OSL_TRACE(
296 : : "ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException"
297 : : "while dispatchFinished %s",
298 : : ::rtl::OUStringToOString( e.Message,
299 : : RTL_TEXTENCODING_ASCII_US ).pData->buffer );
300 [ + - ]: 8 : }
301 [ - + ][ + - ]: 8 : }
302 : : }
303 : :
304 : 6 : void SAL_CALL ScriptProtocolHandler::dispatch(
305 : : const URL& aURL, const Sequence< PropertyValue >& lArgs )
306 : : throw ( RuntimeException )
307 : : {
308 [ + - ]: 6 : dispatchWithNotification( aURL, lArgs, Reference< XDispatchResultListener >() );
309 : 6 : }
310 : :
311 : 0 : void SAL_CALL ScriptProtocolHandler::addStatusListener(
312 : : const Reference< XStatusListener >& xControl, const URL& aURL )
313 : : throw ( RuntimeException )
314 : : {
315 : : (void)xControl;
316 : : (void)aURL;
317 : :
318 : : // implement if status is supported
319 : 0 : }
320 : :
321 : 0 : void SAL_CALL ScriptProtocolHandler::removeStatusListener(
322 : : const Reference< XStatusListener >& xControl, const URL& aURL )
323 : : throw ( RuntimeException )
324 : : {
325 : : (void)xControl;
326 : : (void)aURL;
327 : 0 : }
328 : :
329 : : bool
330 : 16 : ScriptProtocolHandler::getScriptInvocation()
331 : : {
332 [ + + ][ + - ]: 16 : if ( !m_xScriptInvocation.is() && m_xFrame.is() )
[ + + ]
333 : : {
334 [ + - ][ + - ]: 8 : Reference< XController > xController = m_xFrame->getController();
335 [ + - ]: 8 : if ( xController .is() )
336 : : {
337 : : // try to obtain an XScriptInvocationContext interface, preferred from the
338 : : // mode, then from the controller
339 [ + - ][ + - ]: 8 : if ( !m_xScriptInvocation.set( xController->getModel(), UNO_QUERY ) )
[ + - ][ - + ]
340 [ # # ]: 0 : m_xScriptInvocation.set( xController, UNO_QUERY );
341 : 8 : }
342 : : }
343 : 16 : return m_xScriptInvocation.is();
344 : : }
345 : :
346 : 8 : void ScriptProtocolHandler::createScriptProvider()
347 : : {
348 [ - + ]: 8 : if ( m_xScriptProvider.is() )
349 : 8 : return;
350 : :
351 : : try
352 : : {
353 : : // first, ask the component supporting the XScriptInvocationContext interface
354 : : // (if there is one) for a script provider
355 [ + - ][ + - ]: 8 : if ( getScriptInvocation() )
356 : : {
357 [ + - ]: 8 : Reference< XScriptProviderSupplier > xSPS( m_xScriptInvocation, UNO_QUERY );
358 [ + - ]: 8 : if ( xSPS.is() )
359 [ + - ][ + - ]: 8 : m_xScriptProvider = xSPS->getScriptProvider();
[ + - ]
360 : : }
361 : :
362 : : // second, ask the model in our frame
363 [ - + ][ # # ]: 8 : if ( !m_xScriptProvider.is() && m_xFrame.is() )
[ - + ]
364 : : {
365 [ # # ][ # # ]: 0 : Reference< XController > xController = m_xFrame->getController();
366 [ # # ]: 0 : if ( xController .is() )
367 : : {
368 [ # # ][ # # ]: 0 : Reference< XScriptProviderSupplier > xSPS( xController->getModel(), UNO_QUERY );
[ # # ]
369 [ # # ]: 0 : if ( xSPS.is() )
370 [ # # ][ # # ]: 0 : m_xScriptProvider = xSPS->getScriptProvider();
[ # # ]
371 : 0 : }
372 : : }
373 : :
374 : :
375 : : // as a fallback, ask the controller
376 [ - + ][ # # ]: 8 : if ( !m_xScriptProvider.is() && m_xFrame.is() )
[ - + ]
377 : : {
378 [ # # ][ # # ]: 0 : Reference< XScriptProviderSupplier > xSPS( m_xFrame->getController(), UNO_QUERY );
[ # # ]
379 [ # # ]: 0 : if ( xSPS.is() )
380 [ # # ][ # # ]: 0 : m_xScriptProvider = xSPS->getScriptProvider();
[ # # ]
381 : : }
382 : :
383 : : // if nothing of this is successful, use the master script provider
384 [ - + ]: 8 : if ( !m_xScriptProvider.is() )
385 : : {
386 [ # # ]: 0 : Reference< XPropertySet > xProps( m_xFactory, UNO_QUERY_THROW );
387 : :
388 : : ::rtl::OUString dc(
389 : 0 : "DefaultContext" );
390 : :
391 : : Reference< XComponentContext > xCtx(
392 [ # # ][ # # ]: 0 : xProps->getPropertyValue( dc ), UNO_QUERY_THROW );
[ # # ]
393 : :
394 : : ::rtl::OUString tmspf(
395 : 0 : "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory");
396 : :
397 : : Reference< provider::XScriptProviderFactory > xFac(
398 [ # # ][ # # ]: 0 : xCtx->getValueByName( tmspf ), UNO_QUERY_THROW );
[ # # ]
399 : :
400 : 0 : Any aContext;
401 [ # # ][ # # ]: 0 : if ( getScriptInvocation() )
402 [ # # ]: 0 : aContext = makeAny( m_xScriptInvocation );
403 : : m_xScriptProvider = Reference< provider::XScriptProvider > (
404 [ # # ][ # # ]: 0 : xFac->createScriptProvider( aContext ), UNO_QUERY_THROW );
[ # # ][ # # ]
405 : : }
406 : : }
407 : 0 : catch ( const RuntimeException & e )
408 : : {
409 [ # # ]: 0 : ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::createScriptProvider(), " );
410 [ # # ]: 0 : throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
411 : : }
412 [ # # # ]: 0 : catch ( const Exception & e )
413 : : {
414 [ # # ]: 0 : ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::createScriptProvider: " );
415 [ # # ]: 0 : throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
416 : : }
417 : : }
418 : :
419 : 8 : ScriptProtocolHandler::ScriptProtocolHandler(
420 : : Reference< css::lang::XMultiServiceFactory > const& rFact ) :
421 : 8 : m_bInitialised( false ), m_xFactory( rFact )
422 : : {
423 : 8 : }
424 : :
425 : 8 : ScriptProtocolHandler::~ScriptProtocolHandler()
426 : : {
427 [ - + ]: 16 : }
428 : :
429 : : /* XServiceInfo */
430 : 0 : ::rtl::OUString SAL_CALL ScriptProtocolHandler::getImplementationName( )
431 : : throw( RuntimeException )
432 : : {
433 : 0 : return impl_getStaticImplementationName();
434 : : }
435 : :
436 : : /* XServiceInfo */
437 : 0 : sal_Bool SAL_CALL ScriptProtocolHandler::supportsService(
438 : : const ::rtl::OUString& sServiceName )
439 : : throw( RuntimeException )
440 : : {
441 [ # # ]: 0 : Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames();
442 : 0 : const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
443 [ # # ]: 0 : for ( sal_Int32 nCounter = 0; nCounter < seqServiceNames.getLength(); nCounter++ )
444 : : {
445 [ # # ]: 0 : if ( pArray[ nCounter ] == sServiceName )
446 : : {
447 : 0 : return sal_True ;
448 : : }
449 : : }
450 : :
451 [ # # ]: 0 : return sal_False ;
452 : : }
453 : :
454 : : /* XServiceInfo */
455 : 0 : Sequence< ::rtl::OUString > SAL_CALL ScriptProtocolHandler::getSupportedServiceNames()
456 : : throw( RuntimeException )
457 : : {
458 : 0 : return impl_getStaticSupportedServiceNames();
459 : : }
460 : :
461 : : /* Helper for XServiceInfo */
462 : 4 : Sequence< ::rtl::OUString > ScriptProtocolHandler::impl_getStaticSupportedServiceNames()
463 : : {
464 [ + - ][ + - ]: 4 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
465 [ + - ]: 4 : Sequence< ::rtl::OUString > seqServiceNames( 1 );
466 : : seqServiceNames.getArray() [ 0 ] =
467 [ + - ]: 4 : ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYSERVICENAME );
468 [ + - ]: 4 : return seqServiceNames ;
469 : : }
470 : :
471 : : /* Helper for XServiceInfo */
472 : 8 : ::rtl::OUString ScriptProtocolHandler::impl_getStaticImplementationName()
473 : : {
474 : 8 : return ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYIMPLNAME );
475 : : }
476 : :
477 : : /* Helper for registry */
478 : 8 : Reference< XInterface > SAL_CALL ScriptProtocolHandler::impl_createInstance(
479 : : const Reference< css::lang::XMultiServiceFactory >& xServiceManager )
480 : : throw( RuntimeException )
481 : : {
482 [ + - ]: 8 : return Reference< XInterface > ( *new ScriptProtocolHandler( xServiceManager ) );
483 : : }
484 : :
485 : : /* Factory for registration */
486 : 4 : Reference< XSingleServiceFactory > ScriptProtocolHandler::impl_createFactory(
487 : : const Reference< XMultiServiceFactory >& xServiceManager )
488 : : {
489 : : Reference< XSingleServiceFactory > xReturn (
490 : : cppu::createSingleFactory( xServiceManager,
491 : : ScriptProtocolHandler::impl_getStaticImplementationName(),
492 : : ScriptProtocolHandler::impl_createInstance,
493 : : ScriptProtocolHandler::impl_getStaticSupportedServiceNames() )
494 [ + - ][ + - ]: 4 : );
495 : 4 : return xReturn;
496 : : }
497 : :
498 : : } // namespace scripting_protocolhandler
499 : :
500 : : extern "C"
501 : : {
502 : :
503 : : namespace css = ::com::sun::star;
504 : :
505 : 4 : SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char * pImplementationName ,
506 : : void * pServiceManager ,
507 : : void * pRegistryKey )
508 : : {
509 : : (void)pRegistryKey;
510 : :
511 : : // Set default return value for this operation - if it failed.
512 : 4 : void * pReturn = NULL ;
513 : :
514 [ + - ][ + - ]: 4 : if (
515 : : ( pImplementationName != NULL ) &&
516 : : ( pServiceManager != NULL )
517 : : )
518 : : {
519 : : // Define variables which are used in following macros.
520 : : ::com::sun::star::uno::Reference<
521 : 4 : ::com::sun::star::lang::XSingleServiceFactory > xFactory ;
522 : : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
523 : : xServiceManager( reinterpret_cast<
524 [ + - ]: 4 : ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ;
525 : :
526 [ + - ]: 4 : if ( ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName().equals(
527 : 4 : ::rtl::OUString::createFromAscii( pImplementationName ) ) )
528 : : {
529 [ + - ][ + - ]: 4 : xFactory = ::scripting_protocolhandler::ScriptProtocolHandler::impl_createFactory( xServiceManager );
530 : : }
531 : :
532 : : // Factory is valid - service was found.
533 [ + - ]: 4 : if ( xFactory.is() )
534 : : {
535 [ + - ]: 4 : xFactory->acquire();
536 [ + - ]: 4 : pReturn = xFactory.get();
537 : 4 : }
538 : : }
539 : :
540 : : // Return with result of this operation.
541 : 4 : return pReturn ;
542 : : }
543 : : } // extern "C"
544 : :
545 : :
546 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|