LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/plugin/base - xplugin.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 550 0.0 %
Date: 2012-12-27 Functions: 0 50 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      12             :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13             :  * it under the terms of the GNU Lesser General Public License version 3
      14             :  * only, as published by the Free Software Foundation.
      15             :  *
      16             :  * OpenOffice.org is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU Lesser General Public License version 3 for more details
      20             :  * (a copy is included in the LICENSE file that accompanied this code).
      21             :  *
      22             :  * You should have received a copy of the GNU Lesser General Public License
      23             :  * version 3 along with OpenOffice.org.  If not, see
      24             :  * <http://www.openoffice.org/license.html>
      25             :  * for a copy of the LGPLv3 License.
      26             :  *
      27             :  ************************************************************************/
      28             : 
      29             : #ifdef AIX
      30             : #define _LINUX_SOURCE_COMPAT
      31             : #include <sys/timer.h>
      32             : #undef _LINUX_SOURCE_COMPAT
      33             : #endif
      34             : 
      35             : #ifdef WNT
      36             : #include <prewin.h>
      37             : #include <postwin.h>
      38             : #undef OPTIONAL
      39             : #endif
      40             : 
      41             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      42             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      43             : #include <com/sun/star/loader/XImplementationLoader.hpp>
      44             : #include <com/sun/star/plugin/PluginManager.hpp>
      45             : 
      46             : #include <comphelper/processfactory.hxx>
      47             : #include <plugin/impl.hxx>
      48             : #include <tools/fsys.hxx>
      49             : #include <ucbhelper/content.hxx>
      50             : #include <tools/urlobj.hxx>
      51             : #include <tools/string.hxx>
      52             : #include <vcl/svapp.hxx>
      53             : #include <salhelper/timer.hxx>
      54             : #include <osl/file.hxx>
      55             : 
      56             : #ifdef UNX
      57             : #include <sys/types.h>
      58             : #include <sys/socket.h>
      59             : #endif
      60             : 
      61             : #if OSL_DEBUG_LEVEL > 1
      62             : #include <stdio.h>
      63             : #endif
      64             : 
      65             : using namespace com::sun::star;
      66             : using namespace com::sun::star::io;
      67             : using namespace com::sun::star::beans;
      68             : using namespace com::sun::star::plugin;
      69             : using namespace osl;
      70             : 
      71             : using ::rtl::OUString;
      72             : using ::rtl::OString;
      73             : 
      74             : class PluginDisposer : public salhelper::Timer
      75             : {
      76             : private:
      77             :     XPlugin_Impl*       m_pPlugin;
      78             : 
      79             :     virtual void SAL_CALL onShot();
      80             : public:
      81           0 :     PluginDisposer( XPlugin_Impl* pPlugin ) :
      82             :         salhelper::Timer( salhelper::TTimeValue( 2, 0 ),
      83             :                           salhelper::TTimeValue( 2, 0 ) ),
      84           0 :         m_pPlugin( pPlugin )
      85           0 :         { start(); }
      86           0 :     ~PluginDisposer() {}
      87             : };
      88             : 
      89           0 : void PluginDisposer::onShot()
      90             : {
      91           0 :     if( m_pPlugin )
      92             :     {
      93           0 :         if( m_pPlugin->isDisposable() )
      94             :         {
      95             :             sal_uLong nEvent;
      96           0 :             Application::PostUserEvent( nEvent, LINK( m_pPlugin, XPlugin_Impl, secondLevelDispose ), (void*)m_pPlugin );
      97             :         }
      98             :     }
      99             :     else
     100           0 :         release();
     101           0 : }
     102             : 
     103             : //==================================================================================================
     104             : 
     105           0 : Any XPlugin_Impl::queryInterface( const Type& type ) throw( RuntimeException )
     106             : {
     107           0 :     return OWeakAggObject::queryInterface( type );
     108             : }
     109             : 
     110           0 : Any XPlugin_Impl::queryAggregation( const Type& type ) throw( RuntimeException )
     111             : {
     112           0 :     Any aRet( cppu::queryInterface( type, static_cast< XPlugin* >(this) ) );
     113           0 :     if( ! aRet.hasValue() )
     114           0 :         aRet = PluginControl_Impl::queryAggregation( type );
     115           0 :     return aRet;
     116             : }
     117             : 
     118             : 
     119           0 : XPlugin_Impl::XPlugin_Impl( const uno::Reference< com::sun::star::lang::XMultiServiceFactory >  & rSMgr) :
     120             :         PluginControl_Impl(),
     121             :         m_xSMgr( rSMgr ),
     122             :         m_pPluginComm( NULL ),
     123             :         m_pSysPlugData( CreateSysPlugData() ),
     124           0 :         m_aEncoding( osl_getThreadTextEncoding() ),
     125             :         m_pArgv( NULL ),
     126             :         m_pArgn( NULL ),
     127             :         m_nArgs( 0 ),
     128             :         m_aPluginMode( NP_FULL ),
     129             :         m_nProvidingState( PROVIDING_NONE ),
     130             :         m_nCalledFromPlugin( 0 ),
     131             :         m_pDisposer( NULL ),
     132           0 :         m_bIsDisposed( sal_False )
     133             : {
     134           0 :     memset( &m_aInstance, 0, sizeof( m_aInstance ) );
     135           0 :     memset( &m_aNPWindow, 0, sizeof( m_aNPWindow ) );
     136             : 
     137           0 :     m_xModel = new PluginModel();
     138           0 :     uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
     139           0 :     xPS->addPropertyChangeListener( OUString(), this );
     140             : 
     141           0 :     Guard< Mutex > aGuard( ::PluginManager::get().getPluginMutex() );
     142           0 :     ::PluginManager::get().getPlugins().push_back( this );
     143           0 : }
     144             : 
     145           0 : void XPlugin_Impl::destroyInstance()
     146             : {
     147           0 :     Guard< Mutex > aGuard( m_aMutex );
     148             : 
     149           0 :     NPSavedData* pSavedData = NULL;
     150             : 
     151           0 :     destroyStreams();
     152           0 :     if( getPluginComm() )
     153             :     {
     154           0 :         getPluginComm()->NPP_Destroy( this, &pSavedData );
     155           0 :         getPluginComm()->decRef();
     156           0 :         m_pPluginComm = NULL;
     157             :     }
     158             : 
     159           0 :     freeArgs();
     160             : 
     161           0 :     while( m_aPEventListeners.size() )
     162             :     {
     163           0 :         delete *m_aPEventListeners.begin();
     164           0 :         m_aPEventListeners.pop_front();
     165           0 :     }
     166           0 : }
     167             : 
     168           0 : XPlugin_Impl::~XPlugin_Impl()
     169             : {
     170           0 :     destroyInstance();
     171           0 : }
     172             : 
     173           0 : void XPlugin_Impl::checkListeners( const char* normalizedURL )
     174             : {
     175           0 :     if( ! normalizedURL )
     176             :         return;
     177             : 
     178           0 :     Guard< Mutex > aGuard( m_aMutex );
     179             : 
     180           0 :     std::list<PluginEventListener*>::iterator iter;
     181           0 :     for( iter = m_aPEventListeners.begin();
     182           0 :          iter != m_aPEventListeners.end();
     183             :          ++iter )
     184             :     {
     185           0 :         if( ! strcmp( normalizedURL, (*iter)->getURL() ) ||
     186           0 :             ! strcmp( normalizedURL, (*iter)->getNormalizedURL() ) )
     187             :         {
     188           0 :             (*iter)->disposing( com::sun::star::lang::EventObject() );
     189           0 :             delete *iter;
     190           0 :             m_aPEventListeners.remove( *iter );
     191             :             return;
     192             :         }
     193           0 :     }
     194             : }
     195             : 
     196           0 : IMPL_LINK( XPlugin_Impl, secondLevelDispose, XPlugin_Impl*, /*pThis*/ )
     197             : {
     198           0 :     Guard< Mutex > aGuard( m_aMutex );
     199             : 
     200             :     // may have become undisposable between PostUserEvent and here
     201             :     // or may have disposed and receive a second UserEvent
     202           0 :     std::list<XPlugin_Impl*>& rList = ::PluginManager::get().getPlugins();
     203           0 :     std::list<XPlugin_Impl*>::iterator iter;
     204             : 
     205             :     {
     206           0 :         Guard< Mutex > aPluginGuard( ::PluginManager::get().getPluginMutex() );
     207           0 :         for( iter = rList.begin(); iter != rList.end(); ++iter )
     208             :         {
     209           0 :             if( *iter == this )
     210           0 :                 break;
     211             :         }
     212           0 :         if( iter == rList.end() || ! isDisposable() )
     213           0 :             return 0;
     214             :     }
     215             : 
     216           0 :     if (m_pDisposer)
     217             :     {
     218           0 :         m_pDisposer->release();
     219           0 :         m_pDisposer = NULL;
     220             :     }
     221             : 
     222           0 :     uno::Reference< XPlugin >  xProtection( this );
     223           0 :     uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
     224           0 :     xPS->removePropertyChangeListener( OUString(), this );
     225             :     {
     226           0 :         Guard< Mutex > aPluginGuard( ::PluginManager::get().getPluginMutex() );
     227           0 :         rList.remove( this );
     228             :     }
     229           0 :     m_aNPWindow.window = NULL;
     230             : #ifndef UNX
     231             :     // acrobat does an unconditional XtParent on the windows widget
     232             :     getPluginComm()->NPP_SetWindow( this );
     233             : #endif
     234           0 :     destroyInstance();
     235           0 :     PluginControl_Impl::dispose();
     236           0 :     return 0;
     237             : }
     238             : 
     239           0 : void XPlugin_Impl::dispose() throw()
     240             : {
     241           0 :     Guard< Mutex > aGuard( m_aMutex );
     242             : 
     243           0 :     if (m_bIsDisposed || !getPluginComm())
     244           0 :         return;
     245           0 :     m_bIsDisposed = sal_True;
     246             : 
     247           0 :     if( isDisposable() )
     248           0 :         secondLevelDispose( this );
     249             :     else
     250             :     {
     251           0 :         m_pDisposer = new PluginDisposer( this );
     252           0 :         m_pDisposer->acquire();
     253           0 :     }
     254             : }
     255             : 
     256           0 : void XPlugin_Impl::initArgs( const Sequence< OUString >& argn,
     257             :                              const Sequence< OUString >& argv,
     258             :                              sal_Int16 mode )
     259             : {
     260           0 :     m_aPluginMode = mode;
     261             : 
     262           0 :     m_nArgs = argn.getLength();
     263           0 :     m_pArgn = new const char*[m_nArgs];
     264           0 :     m_pArgv = new const char*[m_nArgs];
     265           0 :     const OUString* pUArgn = argn.getConstArray();
     266           0 :     const OUString* pUArgv = argv.getConstArray();
     267           0 :     for( int i = 0; i < m_nArgs; i++ )
     268             :     {
     269           0 :         m_pArgn[i] = strdup(
     270           0 :             OUStringToOString( pUArgn[i], m_aEncoding ).getStr()
     271           0 :             );
     272           0 :         m_pArgv[i] = strdup(
     273           0 :             OUStringToOString( pUArgv[i], m_aEncoding ).getStr()
     274           0 :             );
     275             :     }
     276           0 : }
     277             : 
     278           0 : void XPlugin_Impl::freeArgs()
     279             : {
     280           0 :     if( m_nArgs > 0 )
     281             :     {
     282           0 :         for( ; m_nArgs--; )
     283             :         {
     284           0 :             free( (void*)m_pArgn[m_nArgs] );
     285           0 :             free( (void*)m_pArgv[m_nArgs] );
     286             :         }
     287           0 :         delete [] m_pArgn;
     288           0 :         delete [] m_pArgv;
     289             :     }
     290           0 : }
     291             : 
     292           0 : void XPlugin_Impl::prependArg( const char* pName, const char* pValue )
     293             : {
     294           0 :     const char** pNewNames      = new const char*[m_nArgs+1];
     295           0 :     const char** pNewValues = new const char*[m_nArgs+1];
     296             : 
     297           0 :     pNewNames[0]        = strdup( pName );
     298           0 :     pNewValues[0]       = strdup( pValue );
     299           0 :     for( int nIndex = 0; nIndex < m_nArgs; ++nIndex )
     300             :     {
     301           0 :         pNewNames[nIndex+1] = m_pArgn[nIndex];
     302           0 :         pNewValues[nIndex+1]= m_pArgv[nIndex];
     303             :     }
     304             :     // free old arrays
     305           0 :     delete [] m_pArgn;
     306           0 :     delete [] m_pArgv;
     307             :     // set new arrays
     308           0 :     m_pArgn = pNewNames;
     309           0 :     m_pArgv = pNewValues;
     310             :     // set new number of arguments
     311           0 :     m_nArgs++;
     312             : #if OSL_DEBUG_LEVEL > 1
     313             :     fprintf( stderr, "inserted %s=%s\n", pNewNames[0], pNewValues[0] );
     314             : #endif
     315           0 : }
     316             : 
     317           0 : void XPlugin_Impl::handleSpecialArgs()
     318             : {
     319             :     // special handling for real audio which needs a lot of parameters
     320             :     // or won't function at all
     321           0 :     if( ! m_aDescription.Mimetype.compareToAscii( "audio/x-pn-realaudio-plugin" ) && m_nArgs < 1 )
     322             :     {
     323           0 :         OUString aURL;
     324           0 :         if( m_xModel.is() )
     325             :         {
     326             :             try
     327             :             {
     328           0 :                 uno::Reference< XPropertySet > xProp( m_xModel, UNO_QUERY );
     329           0 :                 Any aProp = xProp->getPropertyValue( OUString(  "URL"  ) );
     330           0 :                 aProp >>= aURL;
     331             :             }
     332           0 :             catch(const UnknownPropertyException &)
     333             :             {
     334             :             }
     335             :         }
     336             : 
     337           0 :         if( !aURL.isEmpty() )
     338             :         {
     339             :             // set new args, old args need not be freed as there were none set
     340           0 :             m_nArgs = 6;
     341           0 :             m_pArgn = new const char*[m_nArgs];
     342           0 :             m_pArgv = new const char*[m_nArgs];
     343             : 
     344             :             // SRC
     345           0 :             m_pArgn[0]      = strdup( "SRC" );
     346           0 :             m_pArgv[0]      = strdup( OUStringToOString( aURL, m_aEncoding ).getStr() );
     347             :             // WIDTH
     348           0 :             m_pArgn[1]      = strdup( "WIDTH" );
     349           0 :             m_pArgv[1]      = strdup( "200" );
     350             :             // HEIGHT
     351           0 :             m_pArgn[2]      = strdup( "HEIGHT" );
     352           0 :             m_pArgv[2]      = strdup( "200" );
     353             :             // CONTROLS
     354           0 :             m_pArgn[3]      = strdup( "CONTROLS" );
     355           0 :             m_pArgv[3]      = strdup( "PlayButton,StopButton,ImageWindow" );
     356             :             // AUTOSTART
     357           0 :             m_pArgn[4]      = strdup( "AUTOSTART" );
     358           0 :             m_pArgv[4]      = strdup( "TRUE" );
     359             :             // NOJAVA
     360           0 :             m_pArgn[5]      = strdup( "NOJAVA" );
     361           0 :             m_pArgv[5]      = strdup( "TRUE" );
     362           0 :         }
     363             :     }
     364             :     // #69333# special for pdf
     365           0 :     else if( ! m_aDescription.Mimetype.compareToAscii( "application/pdf" ) )
     366           0 :         m_aPluginMode = PluginMode::FULL;
     367             : 
     368             :     // see if we have a TYPE tag
     369             :     int nIndex;
     370           0 :     for( nIndex = 0; nIndex < m_nArgs; ++nIndex )
     371           0 :         if( m_pArgn[nIndex][0] == 'T' &&
     372           0 :             m_pArgn[nIndex][1] == 'Y' &&
     373           0 :             m_pArgn[nIndex][2] == 'P' &&
     374           0 :             m_pArgn[nIndex][3] == 'E' &&
     375           0 :             m_pArgn[nIndex][4] == 0 )
     376           0 :             break;
     377           0 :     if( nIndex >= m_nArgs )
     378             :     {
     379             :         // TYPE
     380           0 :         prependArg( "TYPE", OUStringToOString( m_aDescription.Mimetype, m_aEncoding ).getStr() );
     381             :     }
     382             : 
     383             :     // see if we have a SRC tag
     384           0 :     for( nIndex = 0; nIndex < m_nArgs; ++nIndex )
     385           0 :         if( m_pArgn[nIndex][0] == 'S' &&
     386           0 :             m_pArgn[nIndex][1] == 'R' &&
     387           0 :             m_pArgn[nIndex][2] == 'C' &&
     388           0 :             m_pArgn[nIndex][3] == 0 )
     389           0 :             break;
     390           0 :     if( nIndex >= m_nArgs )
     391             :     {
     392             :         // need a SRC parameter (as all browser set one on the plugin
     393           0 :         OUString aURL;
     394           0 :         if( m_xModel.is() )
     395             :         {
     396             :             try
     397             :             {
     398           0 :                 uno::Reference< XPropertySet > xProp( m_xModel, UNO_QUERY );
     399           0 :                 Any aProp = xProp->getPropertyValue( OUString(  "URL"  ) );
     400           0 :                 aProp >>= aURL;
     401             :             }
     402           0 :             catch(const UnknownPropertyException &)
     403             :             {
     404             :             }
     405             :         }
     406             : 
     407           0 :         if( !aURL.isEmpty() )
     408             :         {
     409             :             // SRC
     410           0 :             prependArg( "SRC", OUStringToOString( aURL, m_aEncoding ).getStr() );
     411           0 :         }
     412             :     }
     413           0 : }
     414             : 
     415           0 : void XPlugin_Impl::initInstance( const PluginDescription& rDescription,
     416             :                                  const Sequence< OUString >& argn,
     417             :                                  const Sequence< OUString >& argv,
     418             :                                  sal_Int16 mode )
     419             : {
     420           0 :     Guard< Mutex > aGuard( m_aMutex );
     421             : 
     422           0 :     m_aDescription = rDescription;
     423           0 :     initArgs( argn, argv, mode );
     424           0 :     handleSpecialArgs();
     425           0 : }
     426             : 
     427           0 : void XPlugin_Impl::initInstance( const OUString& rURL,
     428             :                                  const Sequence< OUString >& argn,
     429             :                                  const Sequence< OUString >& argv,
     430             :                                  sal_Int16 mode )
     431             : {
     432           0 :     Guard< Mutex > aGuard( m_aMutex );
     433             : 
     434           0 :     initArgs( argn, argv, mode );
     435           0 :     m_aDescription = fitDescription( rURL );
     436             : 
     437           0 :     m_xModel = new PluginModel( rURL, m_aDescription.Mimetype );
     438           0 :     handleSpecialArgs();
     439           0 : }
     440             : 
     441           0 : void XPlugin_Impl::modelChanged()
     442             : {
     443           0 :     Guard< Mutex > aGuard( m_aMutex );
     444             : 
     445           0 :     m_nProvidingState = PROVIDING_MODEL_UPDATE;
     446             : 
     447           0 :     destroyInstance();
     448             : 
     449           0 :     m_aDescription = fitDescription( getCreationURL() );
     450           0 :     if( m_aDescription.Mimetype.isEmpty() )
     451             :     {
     452           0 :         m_nProvidingState = PROVIDING_NONE;
     453           0 :         return;
     454             :     }
     455             : 
     456           0 :     OUString aURL = getCreationURL();
     457             :     provideNewStream( m_aDescription.Mimetype,
     458             :                       uno::Reference< XActiveDataSource >(),
     459             :                       aURL,
     460           0 :                       0, 0, (sal_Bool)(aURL.compareToAscii( "file:", 5 ) == 0) );
     461           0 :     m_nProvidingState = PROVIDING_NONE;
     462             : }
     463             : 
     464           0 : OUString XPlugin_Impl::getCreationURL()
     465             : {
     466           0 :     Guard< Mutex > aGuard( m_aMutex );
     467             : 
     468           0 :     OUString aRet;
     469           0 :     uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
     470           0 :     if( xPS.is() )
     471             :     {
     472           0 :         Any aValue = xPS->getPropertyValue( OUString("URL") );
     473           0 :         aValue >>= aRet;
     474             :     }
     475           0 :     return aRet;
     476             : }
     477             : 
     478             : 
     479           0 : sal_Bool XPlugin_Impl::setModel( const uno::Reference< com::sun::star::awt::XControlModel > & Model )
     480             :     throw( RuntimeException )
     481             : {
     482           0 :     Guard< Mutex > aGuard( m_aMutex );
     483             : 
     484           0 :     uno::Reference< com::sun::star::beans::XPropertySet >  xPS( Model, UNO_QUERY );
     485           0 :     if( ! xPS.is() )
     486           0 :         return sal_False;
     487             : 
     488           0 :     if( !getCreationURL().isEmpty() )
     489             :     {
     490           0 :         m_xModel = Model;
     491           0 :         modelChanged();
     492           0 :         xPS->addPropertyChangeListener( OUString(), this );
     493           0 :         return sal_True;
     494             :     }
     495           0 :     return sal_False;
     496             : }
     497             : 
     498           0 : void XPlugin_Impl::createPeer( const uno::Reference< com::sun::star::awt::XToolkit > & xToolkit, const uno::Reference< com::sun::star::awt::XWindowPeer > & Parent )
     499             :     throw( RuntimeException )
     500             : {
     501           0 :     Guard< Mutex > aGuard( m_aMutex );
     502             : 
     503           0 :     if( ! _xPeer.is() )
     504             :     {
     505           0 :         if( ! Parent.is() )
     506           0 :             throw  RuntimeException();
     507           0 :         PluginControl_Impl::createPeer( xToolkit, Parent );
     508           0 :     }
     509           0 : }
     510             : 
     511           0 : void XPlugin_Impl::loadPlugin()
     512             : {
     513           0 :     Guard< Mutex > aGuard( m_aMutex );
     514             : 
     515           0 :     std::list<PluginComm*>::iterator iter;
     516           0 :     for( iter = ::PluginManager::get().getPluginComms().begin();
     517           0 :          iter != ::PluginManager::get().getPluginComms().end(); ++iter )
     518             :     {
     519           0 :         if( OStringToOUString( (*iter)->getLibName(), m_aEncoding ) == m_aDescription.PluginName )
     520             :         {
     521           0 :             setPluginComm( *iter );
     522           0 :             break;
     523             :         }
     524             :     }
     525           0 :     const SystemEnvData* pEnvData = getSysChildSysData();
     526             : #if defined( UNX ) && !(defined(QUARTZ))
     527           0 :     if (pEnvData->pDisplay) // headless?
     528             :     {
     529           0 :         XSync( (Display*)pEnvData->pDisplay, False );
     530             :     }
     531             : #endif
     532           0 :     if( ! getPluginComm() )
     533             :     {
     534           0 :         if( !m_aDescription.PluginName.isEmpty() )
     535             :         {
     536             : #if defined QUARTZ
     537             :             PluginComm* pComm = new MacPluginComm( m_aDescription.Mimetype,
     538             :                                                    m_aDescription.PluginName,
     539             :                                                    pEnvData->pView );
     540             : #elif defined UNX
     541             :             // need a new PluginComm
     542           0 :             PluginComm* pComm = NULL;
     543             :             int sv[2];
     544           0 :             if( !socketpair( AF_UNIX, SOCK_STREAM, 0, sv ) )
     545             :                 pComm = new UnxPluginComm( m_aDescription.Mimetype,
     546             :                                            m_aDescription.PluginName,
     547             :                                            (XLIB_Window)pEnvData->aWindow,
     548             :                                            sv[0],
     549             :                                            sv[1]
     550           0 :                                            );
     551             : #elif defined WNT
     552             :             PluginComm* pComm = new PluginComm_Impl( m_aDescription.Mimetype,
     553             :                                                      m_aDescription.PluginName,
     554             :                                                      (HWND)pEnvData->hWnd );
     555             : #endif
     556           0 :             setPluginComm( pComm );
     557             :         }
     558             :         else
     559           0 :             return;
     560             :     }
     561             : 
     562           0 :     getPluginComm()->
     563             :         NPP_New( (char*)OUStringToOString( m_aDescription.Mimetype,
     564           0 :                                                   m_aEncoding).getStr(),
     565             :                  getNPPInstance(),
     566             :                  m_aPluginMode == PluginMode::FULL ? NP_FULL : NP_EMBED,
     567           0 :                  ::sal::static_int_cast< int16_t, int >( m_nArgs ),
     568             :                  (char**)(m_nArgs ? m_pArgn : NULL),
     569             :                  (char**)(m_nArgs ? m_pArgv : NULL),
     570           0 :                  NULL );
     571             : #ifdef QUARTZ
     572             :     // m_aNPWindow is set up in the MacPluginComm from the view
     573             :     SetSysPlugDataParentView(*pEnvData);
     574             : #elif defined( UNX )
     575           0 :     if (pEnvData->pDisplay) // headless?
     576             :     {
     577           0 :         XSync( (Display*)pEnvData->pDisplay, False );
     578           0 :         m_aNPWindow.window  = (void*)pEnvData->aWindow;
     579             :     }
     580             :     else
     581             :     {
     582           0 :         m_aNPWindow.window  = NULL;
     583             :     }
     584           0 :     m_aNPWindow.ws_info     = NULL;
     585             : #else
     586             :     m_aNPWindow.window = (void*)pEnvData->hWnd;
     587             : #endif
     588           0 :     com::sun::star::awt::Rectangle aPosSize = getPosSize();
     589             : 
     590           0 :     for( int i = 0; i < m_nArgs; i++ )
     591             :     {
     592           0 :         OString aName( m_pArgn[i] );
     593           0 :         if( aName.equalsIgnoreAsciiCase( "width" ) )
     594             :         {
     595           0 :             OString aValue( m_pArgv[i] );
     596           0 :             aPosSize.Width = aValue.toInt32();
     597             :         }
     598           0 :         else if( aName.equalsIgnoreAsciiCase( "height" ) )
     599             :         {
     600           0 :             OString aValue( m_pArgv[i] );
     601           0 :             aPosSize.Height = aValue.toInt32();
     602             :         }
     603           0 :     }
     604             : 
     605           0 :     m_aNPWindow.clipRect.top        = 0;
     606           0 :     m_aNPWindow.clipRect.left       = 0;
     607           0 :     m_aNPWindow.clipRect.bottom     = ::sal::static_int_cast< uint16_t, sal_Int32 >( aPosSize.Height );
     608           0 :     m_aNPWindow.clipRect.right      = ::sal::static_int_cast< uint16_t, sal_Int32 >( aPosSize.Width );
     609           0 :     m_aNPWindow.type = NPWindowTypeWindow;
     610             : 
     611           0 :     m_aNPWindow.x       = 0;
     612           0 :     m_aNPWindow.y       = 0;
     613           0 :     m_aNPWindow.width   = aPosSize.Width ? aPosSize.Width : 600;
     614           0 :     m_aNPWindow.height  = aPosSize.Height ? aPosSize.Height : 600;
     615             : 
     616           0 :     getPluginComm()->NPP_SetWindow( this );
     617             : }
     618             : 
     619           0 : void XPlugin_Impl::destroyStreams()
     620             : {
     621           0 :     Guard< Mutex > aGuard( m_aMutex );
     622             : 
     623             :     // streams remove themselves from this list when deleted
     624           0 :     while( m_aOutputStreams.size() )
     625           0 :         delete *m_aOutputStreams.begin();
     626             : 
     627             :     // input streams are XOutputStreams, they cannot be simply deleted
     628           0 :     std::list<PluginInputStream*> aLocalList( m_aInputStreams );
     629           0 :     for( std::list<PluginInputStream*>::iterator it = aLocalList.begin();
     630           0 :          it != aLocalList.end(); ++it )
     631           0 :         (*it)->setMode( -1 );
     632           0 : }
     633             : 
     634           0 : PluginStream* XPlugin_Impl::getStreamFromNPStream( NPStream* stream )
     635             : {
     636           0 :     Guard< Mutex > aGuard( m_aMutex );
     637             : 
     638           0 :     std::list<PluginInputStream*>::iterator iter;
     639           0 :     for( iter = m_aInputStreams.begin(); iter != m_aInputStreams.end(); ++iter )
     640           0 :         if( (*iter)->getStream() == stream )
     641           0 :             return *iter;
     642             : 
     643           0 :     std::list<PluginOutputStream*>::iterator iter2;
     644           0 :     for( iter2 = m_aOutputStreams.begin(); iter2 != m_aOutputStreams.end(); ++iter2 )
     645           0 :         if( (*iter2)->getStream() == stream )
     646           0 :             return *iter2;
     647             : 
     648           0 :     return NULL;
     649             : }
     650             : 
     651           0 : sal_Bool XPlugin_Impl::provideNewStream(const OUString& mimetype,
     652             :                                         const uno::Reference< com::sun::star::io::XActiveDataSource > & stream,
     653             :                                         const OUString& url, sal_Int32 length,
     654             :                                         sal_Int32 lastmodified, sal_Bool isfile) throw()
     655             : 
     656             : {
     657           0 :     Guard< Mutex > aGuard( m_aMutex );
     658           0 :     sal_Bool bRet = sal_False;
     659             : 
     660           0 :     if( m_nProvidingState != PROVIDING_NONE )
     661             :     {
     662           0 :         m_nProvidingState = PROVIDING_NOW;
     663           0 :         Any aAny;
     664           0 :         aAny <<= url;
     665           0 :         uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
     666           0 :         if( xPS.is() )
     667             :         {
     668             :             try
     669             :             {
     670           0 :                 xPS->setPropertyValue( OUString("URL"), aAny );
     671           0 :                 aAny <<= mimetype;
     672           0 :                 xPS->setPropertyValue( OUString("TYPE"), aAny );
     673             :             }
     674           0 :             catch(...)
     675             :             {
     676             :             }
     677           0 :         }
     678             :     }
     679           0 :     m_nProvidingState = PROVIDING_NOW;
     680             : 
     681           0 :     OString aMIME;
     682           0 :     if( !mimetype.isEmpty() )
     683           0 :         aMIME = OUStringToOString( mimetype, m_aEncoding );
     684             :     else
     685           0 :         aMIME = OUStringToOString( m_aDescription.Mimetype, m_aEncoding );
     686             : 
     687           0 :     OString aURL  = OUStringToOString( url, m_aEncoding );
     688             : 
     689             :     // check whether there is a notifylistener for this stream
     690             :     // this means that the strema is created from the plugin
     691             :     // via NPN_GetURLNotify or NPN_PostURLNotify
     692           0 :     std::list<PluginEventListener*>::iterator iter;
     693           0 :     for( iter = m_aPEventListeners.begin();
     694           0 :          iter != m_aPEventListeners.end();
     695             :          ++iter )
     696             :     {
     697           0 :         if( (*iter)->getNormalizedURL() == aURL )
     698             :         {
     699           0 :             aURL = (*iter)->getURL();
     700           0 :             break;
     701             :         }
     702             :     }
     703             : 
     704           0 :     if( ! m_pPluginComm )
     705             :     {
     706           0 :         loadPlugin();
     707           0 :         if( !m_aLastGetUrl.isEmpty() && m_aLastGetUrl == aURL )
     708             :         {
     709             :             // plugin is pulling data, don't push the same stream;
     710             :             // this complicated method could have been avoided if
     711             :             // all plugins respected the SRC parameter; but e.g.
     712             :             // acrobat reader plugin does not
     713           0 :             m_nProvidingState = PROVIDING_NONE;
     714           0 :             return sal_True;
     715             :         }
     716             :     }
     717           0 :      if( ! m_pPluginComm )
     718           0 :         return sal_False;
     719             : 
     720           0 :      if(  url.isEmpty() )
     721             :          // this is valid if the plugin is supposed to
     722             :          // pull data (via e.g. NPN_GetURL)
     723           0 :          return sal_True;
     724             : 
     725             :      // set mimetype on model
     726             :      {
     727           0 :          uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
     728           0 :          if( xPS.is() )
     729             :          {
     730             :              try
     731             :              {
     732           0 :                  Any aAny;
     733           0 :                  aAny <<= m_aDescription.Mimetype;
     734           0 :                  xPS->setPropertyValue( OUString("TYPE"), aAny );
     735             :              }
     736           0 :              catch(...)
     737             :              {
     738             :              }
     739           0 :          }
     740             :      }
     741             : 
     742             :      // there may be plugins that can use the file length information,
     743             :      // but currently none are known. Since this file opening/seeking/closing
     744             :      // is rather costly, it is not implemented. If there are plugins known to
     745             :      // make use of the file length, simply put it in
     746             : 
     747             :      PluginInputStream* pStream = new PluginInputStream( this, aURL.getStr(),
     748           0 :                                                         length, lastmodified );
     749           0 :      uno::Reference< com::sun::star::io::XOutputStream > xNewStream( pStream );
     750             : 
     751           0 :      if( iter != m_aPEventListeners.end() )
     752           0 :          pStream->getStream()->notifyData = (*iter)->getNotifyData();
     753             : 
     754           0 :     uint16_t stype = 0;
     755             : 
     756             :     // special handling acrobat reader
     757             :     // presenting a seekable stream to it does not seem to work correctly
     758           0 :     if( aMIME.equals( "application/pdf" ) )
     759           0 :         isfile = sal_False;
     760             : 
     761             : #if OSL_DEBUG_LEVEL > 1
     762             :     fprintf( stderr,
     763             :              "new stream \"%s\" of MIMEType \"%s\"\n"
     764             :              "for plugin \"%s\"\n"
     765             :              "seekable = %s, length = %" SAL_PRIdINT32 "\n",
     766             :              aURL.getStr(), aMIME.getStr(), getPluginComm()->getLibName().getStr(),
     767             :              isfile ? "true" : "false", length );
     768             : 
     769             : #endif
     770           0 :     if( ! m_pPluginComm->NPP_NewStream( &m_aInstance,
     771           0 :                                         (char*)aMIME.getStr(),
     772             :                                         pStream->getStream(), isfile,
     773           0 :                                         &stype ) )
     774             :     {
     775             : #if OSL_DEBUG_LEVEL > 1
     776             :         const char* pType;
     777             :         switch( stype )
     778             :         {
     779             :             case NP_NORMAL:     pType = "NP_NORMAL";break;
     780             :             case NP_SEEK:       pType = "NP_SEEK";break;
     781             :             case NP_ASFILE:     pType = "NP_ASFILE";break;
     782             :             case NP_ASFILEONLY: pType = "NP_ASFILEONLY";break;
     783             :             default:            pType = "unknown!!!";
     784             :         }
     785             :         fprintf( stderr, "Plugin wants it in Mode %s\n", pType );
     786             : #endif
     787           0 :         if( isfile && stype == NP_ASFILEONLY )
     788             :         {
     789           0 :             rtl::OString aFileName;
     790           0 :             if( url.compareToAscii( "file:", 5 ) == 0 )
     791             :             {
     792           0 :                 OUString aSysName;
     793           0 :                 osl_getSystemPathFromFileURL( url.pData, &aSysName.pData );
     794           0 :                 aFileName = rtl::OUStringToOString( aSysName, m_aEncoding );
     795             :             }
     796             :             else
     797           0 :                 aFileName = rtl::OUStringToOString( url, m_aEncoding );
     798             :             m_pPluginComm->
     799             :                 NPP_StreamAsFile( &m_aInstance,
     800             :                                   pStream->getStream(),
     801           0 :                                   aFileName.getStr() );
     802             :         }
     803             :         else
     804             :         {
     805           0 :             pStream->setMode( stype );
     806             : 
     807           0 :             if( ! stream.is() )
     808             :             {
     809             :                 // stream has to be loaded by PluginStream itself via UCB
     810           0 :                 pStream->load();
     811             :             }
     812             :             else
     813             :             {
     814           0 :                 uno::Reference< com::sun::star::io::XConnectable > xConnectable( stream, UNO_QUERY );
     815           0 :                 pStream->setPredecessor( xConnectable );
     816           0 :                 if( xConnectable.is() )
     817             :                 {
     818           0 :                     xConnectable->setSuccessor( static_cast< com::sun::star::io::XConnectable* >(pStream) );
     819           0 :                     while( xConnectable->getPredecessor().is() )
     820           0 :                         xConnectable = xConnectable->getPredecessor();
     821             :                 }
     822           0 :                 stream->setOutputStream( xNewStream );
     823           0 :                 pStream->setSource( stream );
     824           0 :                 uno::Reference< com::sun::star::io::XActiveDataControl > xController;
     825           0 :                 if( xConnectable.is() )
     826           0 :                     xController = uno::Reference< com::sun::star::io::XActiveDataControl >( xConnectable, UNO_QUERY );
     827             :                 else
     828           0 :                     xController = uno::Reference< com::sun::star::io::XActiveDataControl >( stream, UNO_QUERY );
     829             : 
     830           0 :                 if( xController.is() )
     831           0 :                     xController->start();
     832             :             }
     833             :         }
     834           0 :         bRet = sal_True;
     835             :     }
     836             : 
     837           0 :     m_nProvidingState = PROVIDING_NONE;
     838             : 
     839           0 :     return bRet;
     840             : }
     841             : 
     842           0 : void XPlugin_Impl::disposing( const com::sun::star::lang::EventObject& /*rSource*/ ) throw()
     843             : {
     844           0 : }
     845             : 
     846           0 : void XPlugin_Impl::propertyChange( const com::sun::star::beans::PropertyChangeEvent& rEvent ) throw()
     847             : {
     848           0 :     Guard< Mutex > aGuard( m_aMutex );
     849             : 
     850           0 :     if( ! rEvent.PropertyName.compareToAscii( "URL" ) )
     851             :     {
     852           0 :         OUString aStr;
     853           0 :         rEvent.NewValue >>= aStr;
     854           0 :         if( m_nProvidingState == PROVIDING_NONE )
     855             :         {
     856           0 :             if( aStr != m_aURL )
     857             :             {
     858           0 :                 m_aURL = aStr;
     859           0 :                 modelChanged();
     860             :             }
     861           0 :         }
     862           0 :     }
     863           0 : }
     864             : 
     865           0 : void XPlugin_Impl::setPluginContext( const uno::Reference< XPluginContext > & rContext )
     866             : {
     867           0 :     m_rBrowserContext = rContext;
     868           0 : }
     869             : 
     870           0 : void XPlugin_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags )
     871             :         throw( RuntimeException )
     872             : {
     873           0 :     Guard< Mutex > aGuard( m_aMutex );
     874             : 
     875             : #if OSL_DEBUG_LEVEL > 1
     876             :     fprintf( stderr, "XPlugin_Impl::setPosSize( %" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ", %d )\n",
     877             :              nX_, nY_, nWidth_, nHeight_, nFlags );
     878             : #endif
     879             : 
     880           0 :     PluginControl_Impl::setPosSize(nX_, nY_, nWidth_, nHeight_, nFlags);
     881             : 
     882           0 :     m_aNPWindow.x                   = 0;
     883           0 :     m_aNPWindow.y                   = 0;
     884           0 :     m_aNPWindow.width               = nWidth_;
     885           0 :     m_aNPWindow.height              = nHeight_;
     886           0 :     m_aNPWindow.clipRect.top        = 0;
     887           0 :     m_aNPWindow.clipRect.left       = 0;
     888           0 :     m_aNPWindow.clipRect.right      = ::sal::static_int_cast< uint16_t, sal_Int32 >( nWidth_ );
     889           0 :     m_aNPWindow.clipRect.bottom     = ::sal::static_int_cast< uint16_t, sal_Int32 >( nHeight_ );
     890             : 
     891           0 :     if( getPluginComm() )
     892           0 :         getPluginComm()->NPP_SetWindow( this );
     893           0 : }
     894             : 
     895           0 : PluginDescription XPlugin_Impl::fitDescription( const OUString& rURL )
     896             : {
     897           0 :     uno::Reference< XPluginManager >  xPMgr( plugin::PluginManager::create(comphelper::getComponentContext(m_xSMgr)) );
     898             : 
     899           0 :     Sequence< PluginDescription > aDescrs = xPMgr->getPluginDescriptions();
     900           0 :     const PluginDescription* pDescrs = aDescrs.getConstArray();
     901             : 
     902           0 :     for( int nArg = 0; nArg < m_nArgs; nArg++ )
     903             :     {
     904           0 :         if( strncmp( m_pArgn[nArg], "TYPE", 4 ) == 0 &&
     905           0 :             m_pArgn[nArg][4] == 0 )
     906             :         {
     907           0 :             for( int i = 0; i < aDescrs.getLength(); i++ )
     908             :             {
     909           0 :                 if( pDescrs[i].Mimetype.compareToAscii( m_pArgv[nArg] ) == 0 )
     910           0 :                     return pDescrs[i];
     911             :             }
     912             :         }
     913             :     }
     914             : 
     915           0 :     int nPos = rURL.lastIndexOf( (sal_Unicode)'.' );
     916           0 :     if( nPos != -1 )
     917             :     {
     918           0 :         OUString const aExt = rURL.copy( nPos ).toAsciiLowerCase();
     919           0 :         for( int i = 0; i < aDescrs.getLength(); i++ )
     920             :         {
     921           0 :             OUString aThisExt = pDescrs[ i ].Extension.toAsciiLowerCase();
     922           0 :             if( aThisExt.indexOf( aExt ) != -1 )
     923             :             {
     924           0 :                 return pDescrs[i];
     925             :             }
     926           0 :         }
     927             :     }
     928           0 :     return PluginDescription();
     929             : }
     930             : 
     931             : 
     932           0 : PluginStream::PluginStream( XPlugin_Impl* pPlugin,
     933             :                             const char* url, sal_uInt32 len, sal_uInt32 lastmod ) :
     934           0 :         m_pPlugin( pPlugin )
     935             : {
     936           0 :     memset( &m_aNPStream, 0, sizeof( m_aNPStream ) );
     937           0 :     m_aNPStream.url             = strdup( url );
     938           0 :     m_aNPStream.end             = len;
     939           0 :     m_aNPStream.lastmodified    = lastmod;
     940           0 : }
     941             : 
     942           0 : PluginStream::~PluginStream()
     943             : {
     944           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
     945             : 
     946           0 :     if( m_pPlugin && m_pPlugin->getPluginComm() )
     947             :     {
     948           0 :         m_pPlugin->getPluginComm()->NPP_DestroyStream( m_pPlugin->getNPPInstance(),
     949           0 :                                                        &m_aNPStream, NPRES_DONE );
     950           0 :         m_pPlugin->checkListeners( m_aNPStream.url );
     951           0 :         m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
     952             :     }
     953           0 :     ::free( (void*)m_aNPStream.url );
     954           0 : }
     955             : 
     956           0 : PluginInputStream::PluginInputStream( XPlugin_Impl* pPlugin,
     957             :                                       const char* url,
     958             :                                       sal_uInt32 len,
     959             :                                       sal_uInt32 lastmod ) :
     960             :         PluginStream( pPlugin, url, len, lastmod ),
     961             :         m_pContent( NULL ),
     962             :         m_nMode( NP_NORMAL ),
     963           0 :         m_nWritePos( 0 )
     964             : {
     965           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
     966             : 
     967           0 :     m_pPlugin->getInputStreams().push_back( this );
     968           0 :     DirEntry aEntry;
     969           0 :     aEntry = aEntry.TempName();
     970             : 
     971             :     // set correct extension, some plugins need that
     972           0 :     DirEntry aName( String( m_aNPStream.url, m_pPlugin->getTextEncoding() ) );
     973           0 :     String aExtension = aName.GetExtension();
     974           0 :     if( aExtension.Len() )
     975           0 :         aEntry.SetExtension( aExtension );
     976           0 :     m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE );
     977           0 :     if( ! m_aFileStream.IsOpen() )
     978             :     {
     979             :         // #74808# might be that the extension scrambled the whole filename
     980           0 :         aEntry = aEntry.TempName();
     981           0 :         m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE );
     982           0 :     }
     983           0 : }
     984             : 
     985           0 : PluginInputStream::~PluginInputStream()
     986             : {
     987           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
     988             : 
     989           0 :     m_pPlugin->getInputStreams().remove( this );
     990             : 
     991           0 :     String aFile( m_aFileStream.GetFileName() );
     992             : 
     993           0 :     m_aFileStream.Close();
     994           0 :     if( m_pPlugin )
     995             :     {
     996           0 :         rtl::OString aFileName(rtl::OUStringToOString(aFile, m_pPlugin->getTextEncoding()));
     997           0 :         if( m_pPlugin->getPluginComm() && m_nMode != -1 )
     998             :             // mode -1 means either an error occurred,
     999             :             // or the plugin is already disposing
    1000             :         {
    1001           0 :             m_pPlugin->getPluginComm()->addFileToDelete( aFile );
    1002           0 :             if( m_nMode == NP_ASFILE )
    1003             :             {
    1004           0 :                 m_pPlugin->getPluginComm()->
    1005             :                     NPP_StreamAsFile( m_pPlugin->getNPPInstance(),
    1006             :                                       &m_aNPStream,
    1007           0 :                                       aFileName.getStr() );
    1008             :             }
    1009           0 :             m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
    1010           0 :             m_pPlugin->getInputStreams().remove( this );
    1011             :         }
    1012             :         else
    1013           0 :             DirEntry( m_aFileStream.GetFileName() ).Kill();
    1014             :     }
    1015             :     else
    1016           0 :         DirEntry( m_aFileStream.GetFileName() ).Kill();
    1017           0 :     if( m_pContent )
    1018           0 :         delete m_pContent;
    1019           0 : }
    1020             : 
    1021           0 : PluginStreamType PluginInputStream::getStreamType()
    1022             : {
    1023           0 :     return InputStream;
    1024             : }
    1025             : 
    1026           0 : void PluginInputStream::load()
    1027             : {
    1028           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1029             : 
    1030           0 :     INetURLObject aUrl;
    1031           0 :     aUrl.SetSmartProtocol( INET_PROT_FILE );
    1032             :     aUrl.SetSmartURL(
    1033           0 :         String( getStream()->url,
    1034           0 :                 ::sal::static_int_cast< sal_uInt16, size_t >( strlen( getStream()->url ) ),
    1035             :                 RTL_TEXTENCODING_MS_1252
    1036           0 :             ) );
    1037             :     try
    1038             :     {
    1039             :         m_pContent =
    1040             :             new ::ucbhelper::Content(
    1041             :                                aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI),
    1042             :                                uno::Reference< com::sun::star::ucb::XCommandEnvironment >(),
    1043             :                                comphelper::getProcessComponentContext()
    1044           0 :                                );
    1045           0 :         m_pContent->openStream( static_cast< XOutputStream* >( this ) );
    1046             :     }
    1047           0 :     catch(const com::sun::star::uno::Exception &)
    1048             :     {
    1049           0 :     }
    1050           0 : }
    1051             : 
    1052           0 : void PluginInputStream::setMode( sal_Int32 nMode )
    1053             : {
    1054           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1055             : 
    1056           0 :     m_nMode = nMode;
    1057             : 
    1058             :     // invalidation by plugin
    1059           0 :     if( m_nMode == -1 && m_pPlugin )
    1060             :     {
    1061           0 :         m_pPlugin->getInputStreams().remove( this );
    1062           0 :         m_pPlugin = NULL;
    1063           0 :     }
    1064           0 : }
    1065             : 
    1066           0 : void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) throw()
    1067             : {
    1068           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1069             : 
    1070           0 :     m_aFileStream.Seek( STREAM_SEEK_TO_END );
    1071           0 :     m_aFileStream.Write( Buffer.getConstArray(), Buffer.getLength() );
    1072             : 
    1073           0 :     if( m_nMode == NP_SEEK )
    1074             :         // hold reference, streem gets destroyed in NPN_DestroyStream
    1075           0 :         m_xSelf = this;
    1076             : 
    1077           0 :     if( m_nMode == -1 || !m_pPlugin->getPluginComm() )
    1078             :         return;
    1079             : 
    1080           0 :     sal_uInt32 nPos = m_aFileStream.Tell();
    1081           0 :     sal_uInt32 nBytes = 0;
    1082           0 :     while( m_nMode != NP_ASFILEONLY &&
    1083             :            m_nWritePos < nPos &&
    1084           0 :            (nBytes = m_pPlugin->getPluginComm()-> NPP_WriteReady(
    1085           0 :                m_pPlugin->getNPPInstance(), &m_aNPStream )) > 0 )
    1086             :     {
    1087           0 :         nBytes = (nBytes > nPos - m_nWritePos) ? nPos - m_nWritePos : nBytes;
    1088             : 
    1089           0 :         char* pBuffer = new char[ nBytes ];
    1090           0 :         m_aFileStream.Seek( m_nWritePos );
    1091           0 :         nBytes = m_aFileStream.Read( pBuffer, nBytes );
    1092             : 
    1093           0 :         int32_t nBytesRead = 0;
    1094             :         try
    1095             :         {
    1096           0 :             nBytesRead = m_pPlugin->getPluginComm()->NPP_Write(
    1097           0 :                 m_pPlugin->getNPPInstance(), &m_aNPStream, m_nWritePos, nBytes, pBuffer );
    1098             :         }
    1099           0 :         catch( ... )
    1100             :         {
    1101           0 :             nBytesRead = 0;
    1102             :         }
    1103           0 :         delete [] pBuffer;
    1104             : 
    1105           0 :         if( nBytesRead < 0 )
    1106             :         {
    1107           0 :             m_nMode = -1;
    1108             :             return;
    1109             :         }
    1110             : 
    1111           0 :         m_nWritePos += nBytesRead;
    1112           0 :     }
    1113             : }
    1114             : 
    1115           0 : void PluginInputStream::closeOutput() throw()
    1116             : {
    1117           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1118             : 
    1119           0 :     flush();
    1120           0 :     m_xSource = uno::Reference< com::sun::star::io::XActiveDataSource >();
    1121           0 : }
    1122             : 
    1123           0 : sal_uInt32 PluginInputStream::read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size )
    1124             : {
    1125           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1126             : 
    1127           0 :     if( m_nMode != NP_SEEK )
    1128           0 :         return 0;
    1129             : 
    1130           0 :     m_aFileStream.Seek( offset );
    1131           0 :     return m_aFileStream.Read( buffer, size );
    1132             : }
    1133             : 
    1134           0 : void PluginInputStream::flush(void) throw()
    1135             : {
    1136           0 : }
    1137             : 
    1138           0 : PluginOutputStream::PluginOutputStream( XPlugin_Impl* pPlugin,
    1139             :                                         const char* url,
    1140             :                                         sal_uInt32 len,
    1141             :                                         sal_uInt32 lastmod ) :
    1142             :         PluginStream( pPlugin, url, len, lastmod ),
    1143           0 :         m_xStream( pPlugin->getServiceManager()->createInstance( OUString("com.sun.star.io.DataOutputStream") ), UNO_QUERY )
    1144             : {
    1145           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1146             : 
    1147           0 :     m_pPlugin->getOutputStreams().push_back( this );
    1148           0 : }
    1149             : 
    1150           0 : PluginOutputStream::~PluginOutputStream()
    1151             : {
    1152           0 :     Guard< Mutex > aGuard( m_pPlugin->getMutex() );
    1153             : 
    1154           0 :     m_pPlugin->getOutputStreams().remove( this );
    1155           0 : }
    1156             : 
    1157           0 : PluginStreamType PluginOutputStream::getStreamType()
    1158             : {
    1159           0 :     return OutputStream;
    1160             : }
    1161             : 
    1162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10