diff options
Diffstat (limited to 'extensions/source/plugin/base')
-rw-r--r-- | extensions/source/plugin/base/context.cxx | 364 | ||||
-rw-r--r-- | extensions/source/plugin/base/evtlstnr.cxx | 95 | ||||
-rw-r--r-- | extensions/source/plugin/base/makefile.mk | 159 | ||||
-rw-r--r-- | extensions/source/plugin/base/manager.cxx | 316 | ||||
-rw-r--r-- | extensions/source/plugin/base/multiplx.cxx | 391 | ||||
-rw-r--r-- | extensions/source/plugin/base/nfuncs.cxx | 576 | ||||
-rw-r--r-- | extensions/source/plugin/base/plcom.cxx | 90 | ||||
-rw-r--r-- | extensions/source/plugin/base/plctrl.cxx | 373 | ||||
-rw-r--r-- | extensions/source/plugin/base/plmodel.cxx | 243 | ||||
-rw-r--r-- | extensions/source/plugin/base/service.cxx | 206 | ||||
-rw-r--r-- | extensions/source/plugin/base/xplugin.cxx | 888 |
11 files changed, 3701 insertions, 0 deletions
diff --git a/extensions/source/plugin/base/context.cxx b/extensions/source/plugin/base/context.cxx new file mode 100644 index 000000000000..0ad3c7c1baed --- /dev/null +++ b/extensions/source/plugin/base/context.cxx @@ -0,0 +1,364 @@ +/************************************************************************* + * + * $RCSfile: context.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <plugin/impl.hxx> + +#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAGS_HPP_ +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ +#include <com/sun/star/frame/XComponentLoader.hpp> +#endif +#include <tools/fsys.hxx> +#include <tools/urlobj.hxx> + +#include <cppuhelper/implbase1.hxx> + +namespace ext_plug { + +class FileSink : public ::cppu::WeakAggImplHelper1< ::com::sun::star::io::XOutputStream > +{ +private: + Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + FILE* fp; + Reference< ::com::sun::star::plugin::XPlugin > m_xPlugin; + ::rtl::OUString m_aMIMEType; + ::rtl::OUString m_aTarget; + ::rtl::OUString m_aFileName; + +public: + FileSink( const Reference< ::com::sun::star::lang::XMultiServiceFactory > &, + const Reference< ::com::sun::star::plugin::XPlugin > & plugin, + const ::rtl::OUString& mimetype, + const ::rtl::OUString& target, + const Reference< ::com::sun::star::io::XActiveDataSource > & source ); + virtual ~FileSink(); + + // ::com::sun::star::io::XOutputStream + virtual void SAL_CALL writeBytes( const Sequence<sal_Int8>& ); + virtual void SAL_CALL flush(); + virtual void SAL_CALL closeOutput(); +}; + +} +using namespace ext_plug; + +class XPluginContext_Impl : public ::cppu::WeakAggImplHelper1< ::com::sun::star::plugin::XPluginContext > +{ + Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + rtl_TextEncoding m_aEncoding; +public: + + XPluginContext_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ); + virtual ~XPluginContext_Impl(); + + + virtual ::rtl::OUString SAL_CALL getValue(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, ::com::sun::star::plugin::PluginVariable variable) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL getURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL newStream(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& mimetype, const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual void SAL_CALL displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& message) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); + virtual ::rtl::OUString SAL_CALL getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & plugin) throw( ::com::sun::star::plugin::PluginException, RuntimeException ); +}; + +Reference< ::com::sun::star::plugin::XPluginContext > XPluginManager_Impl::createPluginContext() +{ + return new XPluginContext_Impl( m_xSMgr ); +} + +XPluginContext_Impl::XPluginContext_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + : m_xSMgr( rSMgr ), + m_aEncoding( gsl_getSystemTextEncoding() ) +{ +} + +XPluginContext_Impl::~XPluginContext_Impl() +{ +} + +::rtl::OUString XPluginContext_Impl::getValue( const Reference< ::com::sun::star::plugin::XPlugin > & plugin, ::com::sun::star::plugin::PluginVariable variable ) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + return ::rtl::OUString(); +} + + +void XPluginContext_Impl::getURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target) throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + Reference< XInterface > xInst = m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ); + if( ! xInst.is() ) + return; + + if( ! target.len() ) + { + INetURLObject aURL; + aURL.SetSmartProtocol( INET_PROT_FILE ); + aURL.SetSmartURL( ::rtl::OUStringToOString( url, m_aEncoding ) ); + + Reference< ::com::sun::star::lang::XMultiServiceFactory > xFact( m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.DataSourceFactory" ) ), UNO_QUERY ); + if ( xFact.is() ) + { + Sequence < Any > aArgs(1); + ::rtl::OUString aUURL( aURL.GetMainURL() ); + aArgs.getArray()[0] <<= aUURL; + ::rtl::OUString aProt( INetURLObject::GetScheme( aURL.GetProtocol() ) ); + Reference< ::com::sun::star::io::XActiveDataSource > aSource( xFact->createInstanceWithArguments( aProt, aArgs ), UNO_QUERY ); + if ( aSource.is() ) + { + // the mimetype cannot be specified + plugin->provideNewStream( ::rtl::OUString(), + aSource, + aUURL, + 0, 0, sal_False ); + } + } + return; + } + + Reference< ::com::sun::star::frame::XComponentLoader > xLoader( xInst, UNO_QUERY ); + XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin ); + + if( xLoader.is() && pPlugin ) + { + ::com::sun::star::beans::PropertyValue aValue; + aValue.Name = ::rtl::OUString::createFromAscii( "Referer" ); + aValue.Value <<= pPlugin->getRefererURL(); + + Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 ); + Reference< ::com::sun::star::lang::XComponent > xComp = + xLoader->loadComponentFromURL( + url, + target, + ::com::sun::star::frame::FrameSearchFlag::PARENT | + ::com::sun::star::frame::FrameSearchFlag::SELF | + ::com::sun::star::frame::FrameSearchFlag::CHILDREN | + ::com::sun::star::frame::FrameSearchFlag::SIBLINGS | + ::com::sun::star::frame::FrameSearchFlag::TASKS | + ::com::sun::star::frame::FrameSearchFlag::CREATE, + aArgs + ); + } +} + +void XPluginContext_Impl::getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener ) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + getURL( plugin, url, target ); + if( listener.is() ) + listener->disposing( ::com::sun::star::lang::EventObject() ); +} + +::rtl::OUString XPluginContext_Impl::getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & plugin) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + return ::rtl::OUString::createFromAscii( "Mozilla 3.0" ); +} + +void XPluginContext_Impl::displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& message) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ +} + +void XPluginContext_Impl::postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + Sequence< sal_Int8 > aBuf; + + if( file ) + { + String aFileName( (char*)buf.getConstArray(), m_aEncoding ); + INetURLObject aFilePath( aFileName ); + aFileName = aFilePath.PathToFileName(); + SvFileStream aStream( aFileName, STREAM_READ ); + if( aStream.IsOpen() ) + { + int nBytes = 0; + aStream.Seek( STREAM_SEEK_TO_END ); + aBuf = Sequence<sal_Int8>( nBytes = aStream.Tell() ); + aStream.Seek( STREAM_SEEK_TO_BEGIN ); + aStream.Read( aBuf.getArray(), nBytes ); + aStream.Close(); + DirEntry( aFileName ).Kill(); + } + } + + Reference< XInterface > xInst = m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ); + if( ! xInst.is() ) + return ; + + Reference< ::com::sun::star::frame::XComponentLoader > xLoader( xInst, UNO_QUERY ); + XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin ); + if( xLoader.is() && pPlugin ) + { + ::com::sun::star::beans::PropertyValue aValues[2]; + aValues[0].Name = ::rtl::OUString::createFromAscii( "Referer" ); + aValues[0].Value <<= pPlugin->getRefererURL(); + + aValues[1].Name = ::rtl::OUString::createFromAscii( "PostString" ); + aValues[1].Value <<= ::rtl::OStringToOUString( (char*)( file ? aBuf : buf ).getConstArray(), m_aEncoding ); + Sequence< ::com::sun::star::beans::PropertyValue > aArgs( aValues, 2 ); + Reference< ::com::sun::star::lang::XComponent > xComp = + xLoader->loadComponentFromURL( + url, + target, + ::com::sun::star::frame::FrameSearchFlag::PARENT | + ::com::sun::star::frame::FrameSearchFlag::SELF | + ::com::sun::star::frame::FrameSearchFlag::CHILDREN | + ::com::sun::star::frame::FrameSearchFlag::SIBLINGS | + ::com::sun::star::frame::FrameSearchFlag::TASKS | + ::com::sun::star::frame::FrameSearchFlag::CREATE, + aArgs + ); + } +} + +void XPluginContext_Impl::postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener ) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + postURL( plugin, url, target, buf, file ); + if( listener.is() ) + listener->disposing( ::com::sun::star::lang::EventObject() ); +} + +void XPluginContext_Impl::newStream( const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& mimetype, const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source ) + throw( ::com::sun::star::plugin::PluginException, RuntimeException ) +{ + FileSink* pNewSink = new FileSink( m_xSMgr, plugin, mimetype, target, source ); + pNewSink->acquire(); +} + + + +FileSink::FileSink( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr, const Reference< ::com::sun::star::plugin::XPlugin > & plugin, + const ::rtl::OUString& mimetype, + const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source ) : + m_xSMgr( rSMgr ), + m_aMIMEType( mimetype ), + m_aTarget( target ), + m_xPlugin( plugin ) +{ + DirEntry aEntry; + m_aFileName = aEntry.TempName().GetFull(); + ::rtl::OString aFile = ::rtl::OUStringToOString( m_aFileName, gsl_getSystemTextEncoding() ); + fp = fopen( aFile.getStr() , "wb" ); + + Reference< ::com::sun::star::io::XActiveDataControl > xControl( source, UNO_QUERY ); + + source->setOutputStream( Reference< ::com::sun::star::io::XOutputStream > ( this ) ); + if( xControl.is() ) + xControl->start(); +} + +FileSink::~FileSink() +{ + DirEntry aEntry( m_aFileName ); + aEntry.Kill(); +} + +void FileSink::closeOutput() +{ + if( fp ) + fclose( fp ); + + Reference< XInterface > xInst = m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ); + Reference< ::com::sun::star::frame::XComponentLoader > xLoader( xInst, UNO_QUERY ); + XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( m_xPlugin ); + + if( xLoader.is() && pPlugin ) + { + ::com::sun::star::beans::PropertyValue aValue; + aValue.Name = ::rtl::OUString::createFromAscii( "Referer" ); + aValue.Value <<= pPlugin->getRefererURL(); + + Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 ); + Reference< ::com::sun::star::lang::XComponent > xComp = + xLoader->loadComponentFromURL( + m_aFileName, + m_aTarget, + ::com::sun::star::frame::FrameSearchFlag::PARENT | + ::com::sun::star::frame::FrameSearchFlag::SELF | + ::com::sun::star::frame::FrameSearchFlag::CHILDREN | + ::com::sun::star::frame::FrameSearchFlag::SIBLINGS | + ::com::sun::star::frame::FrameSearchFlag::TASKS | + ::com::sun::star::frame::FrameSearchFlag::CREATE, + aArgs + ); + } + release(); +} + +void FileSink::writeBytes( const Sequence<sal_Int8>& Buffer ) +{ + if( fp ) + fwrite( Buffer.getConstArray(), 1, Buffer.getLength(), fp ); +} + +void FileSink::flush() +{ + if( fp ) + fflush( fp ); +} diff --git a/extensions/source/plugin/base/evtlstnr.cxx b/extensions/source/plugin/base/evtlstnr.cxx new file mode 100644 index 000000000000..0579e7c09105 --- /dev/null +++ b/extensions/source/plugin/base/evtlstnr.cxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * $RCSfile: evtlstnr.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <plugin/impl.hxx> + +PluginEventListener::PluginEventListener( XPlugin_Impl* pPlugin, + const char* url, + const char* normurl, + void* notifyData ) : + m_pPlugin( pPlugin ), + m_xPlugin( pPlugin ), + m_pUrl( strdup( url ) ), + m_pNormalizedUrl( strdup( normurl ) ), + m_pNotifyData( notifyData ) +{ +} + +PluginEventListener::~PluginEventListener() +{ + if( m_pUrl ) + free( m_pUrl ); + if( m_pNormalizedUrl ) + free( m_pNormalizedUrl ); +} + +void PluginEventListener::disposing( const ::com::sun::star::lang::EventObject& rEvt ) +{ + m_pPlugin->getPluginComm()-> + NPP_URLNotify( m_pPlugin->getNPPInstance(), + m_pUrl, + NPRES_DONE, + m_pNotifyData ); +} diff --git a/extensions/source/plugin/base/makefile.mk b/extensions/source/plugin/base/makefile.mk new file mode 100644 index 000000000000..56d73938ec1c --- /dev/null +++ b/extensions/source/plugin/base/makefile.mk @@ -0,0 +1,159 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=plugin +TARGET=plbase +ENABLE_EXCEPTIONS=TRUE + +.INCLUDE : ..$/util$/makefile.pmk + +# --- Types ------------------------------------- + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc$/$(PRJNAME) +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES=\ + com.sun.star.awt.PosSize \ + com.sun.star.awt.MouseButton \ + com.sun.star.awt.FocusChangeReason \ + com.sun.star.awt.KeyFunction \ + com.sun.star.awt.Key \ + com.sun.star.awt.KeyModifier \ + com.sun.star.awt.KeyGroup \ + com.sun.star.awt.XAdjustmentListener \ + com.sun.star.awt.XActionListener \ + com.sun.star.awt.XTextListener \ + com.sun.star.awt.XSpinListener \ + com.sun.star.awt.XItemListener \ + com.sun.star.awt.XVclContainerListener \ + com.sun.star.awt.XVclContainerPeer \ + com.sun.star.awt.XVclContainer \ + com.sun.star.awt.XVclWindowPeer \ + com.sun.star.awt.VclWindowPeerAttribute \ + com.sun.star.awt.XActivateListener \ + com.sun.star.awt.XTopWindowListener \ + com.sun.star.awt.XKeyListener \ + com.sun.star.awt.XTopWindow \ + com.sun.star.awt.XControl \ + com.sun.star.awt.XControlModel \ + com.sun.star.awt.XUnoControlContainer \ + com.sun.star.beans.PropertyValues \ + com.sun.star.beans.PropertyAttribute \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertyAccess \ + com.sun.star.beans.XPropertyContainer \ + com.sun.star.beans.XPropertyChangeListener \ + com.sun.star.beans.XPropertyStateChangeListener \ + com.sun.star.plugin.PluginMode \ + com.sun.star.plugin.XPluginManager \ + com.sun.star.io.XConnectable \ + com.sun.star.io.XActiveDataSource \ + com.sun.star.io.XActiveDataSink \ + com.sun.star.io.XActiveDataControl \ + com.sun.star.io.XDataOutputStream \ + com.sun.star.io.XDataInputStream \ + com.sun.star.io.XObjectInputStream \ + com.sun.star.io.XMarkableStream \ + com.sun.star.lang.XServiceName \ + com.sun.star.lang.XServiceInfo \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.loader.XImplementationLoader \ + com.sun.star.container.XSet \ + com.sun.star.container.XNameAccess \ + com.sun.star.container.XIndexAccess \ + com.sun.star.frame.XComponentLoader \ + com.sun.star.frame.FrameSearchFlag \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XAggregation \ + com.sun.star.uno.XWeak + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/plctrl.obj \ + $(SLO)$/service.obj \ + $(SLO)$/xplugin.obj \ + $(SLO)$/nfuncs.obj \ + $(SLO)$/manager.obj \ + $(SLO)$/context.obj \ + $(SLO)$/evtlstnr.obj \ + $(SLO)$/plcom.obj \ + $(SLO)$/multiplx.obj \ + $(SLO)$/plmodel.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.INCLUDE : ..$/util$/target.pmk diff --git a/extensions/source/plugin/base/manager.cxx b/extensions/source/plugin/base/manager.cxx new file mode 100644 index 000000000000..1a6b14887759 --- /dev/null +++ b/extensions/source/plugin/base/manager.cxx @@ -0,0 +1,316 @@ +/************************************************************************* + * + * $RCSfile: manager.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <plugin/impl.hxx> +#include <osl/mutex.hxx> +#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_ +#include <com/sun/star/container/XEnumerationAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_ +#include <com/sun/star/container/XEnumeration.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XELEMENTACCESS_HPP_ +#include <com/sun/star/container/XElementAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ +#include <com/sun/star/container/XIndexAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_LOADER_XIMPLEMENTATIONLOADER_HPP_ +#include <com/sun/star/loader/XImplementationLoader.hpp> +#endif +#ifndef _COM_SUN_STAR_LOADER_CANNOTACTIVATEFACTORYEXCEPTION_HPP_ +#include <com/sun/star/loader/CannotActivateFactoryException.hpp> +#endif + +PluginManager* PluginManager::pManager = NULL; + +PluginManager& PluginManager::get() +{ + if( ! pManager ) + pManager = new PluginManager(); + return *pManager; +} + +void PluginManager::setServiceFactory( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) +{ + PluginManager& rManager = get(); + if( ! rManager.m_xSMgr.is() ) + rManager.m_xSMgr = xFactory; +} + +PluginManager::PluginManager() +{ +} + +PluginManager::~PluginManager() +{ +} + +const Sequence< ::rtl::OUString >& PluginManager::getAdditionalSearchPaths() +{ + static Sequence< ::rtl::OUString > aPaths; + + if( ! aPaths.getLength() ) + { + Reference< XInterface > xInst = get().m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Settings" ) ); + Reference< ::com::sun::star::container::XNameAccess > xAccess( xInst, UNO_QUERY ); + if( xAccess.is() ) + { + Any aValue = xAccess->getByName( ::rtl::OUString::createFromAscii( "PathSettings" ) ); + Reference< ::com::sun::star::beans::XPropertySet > xProp; + if( aValue.hasValue() ) + aValue >>= xProp; + if( xProp.is() ) + { + aValue = xProp->getPropertyValue( ::rtl::OUString::createFromAscii( "Plugins" ) ); + if( aValue.getValueType().getTypeClass() == TypeClass_STRING ) + + { + ::rtl::OUString sValue; + aValue >>= sValue; + sal_Int32 nTokens = sValue.getTokenCount(); + aPaths = Sequence< ::rtl::OUString >( nTokens ); + while( nTokens-- ) + aPaths.getArray()[nTokens] = sValue.getToken( nTokens ); + } + else if( aValue.getValueType().equals( ::getCppuType( (Sequence< ::rtl::OUString >*)0 ) ) ) + + { + Sequence< ::rtl::OUString > aArr; + aValue >>= aArr; + sal_Int32 nGlobalTokens = 0; + int i = 0; + for( i = 0; i < aArr.getLength(); i++ ) + nGlobalTokens += aArr.getConstArray()[i].getTokenCount(); + aPaths = Sequence< ::rtl::OUString >( nGlobalTokens ); + for( i = aArr.getLength()-1; i >= 0; i-- ) + { + sal_Int32 nTokens = aArr.getConstArray()[i].getTokenCount(); + while( nTokens-- ) + aPaths.getArray()[--nGlobalTokens] = + aArr.getConstArray()[i].getToken( nTokens ); + } + } + } + } + } + + return aPaths; +} + +//================================================================================================== +Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) throw( Exception ) +{ + Reference< XInterface > xService = *new XPluginManager_Impl( rSMgr ); + return xService; +} + +// ::com::sun::star::lang::XServiceInfo +::rtl::OUString XPluginManager_Impl::getImplementationName() throw( ) + +{ + return getImplementationName_Static(); + +} + +// ::com::sun::star::lang::XServiceInfo +sal_Bool XPluginManager_Impl::supportsService(const ::rtl::OUString& ServiceName) throw( ) +{ + Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString * pArray = aSNL.getConstArray(); + for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) + if( pArray[i] == ServiceName ) + return sal_True; + return sal_False; +} + +// ::com::sun::star::lang::XServiceInfo +Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames(void) throw( ) +{ + return getSupportedServiceNames_Static(); +} + +// XPluginManager_Impl +Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames_Static(void) throw( ) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ); + return aSNS; +} + +XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) +: m_xSMgr( rSMgr ) +{ + PluginManager::setServiceFactory( rSMgr ); +} + +XPluginManager_Impl::~XPluginManager_Impl() +{ +} + +XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance ) +{ + ::std::list<XPlugin_Impl*>::iterator iter; + for( iter = PluginManager::get().getPlugins().begin(); + iter != PluginManager::get().getPlugins().end(); ++iter ) + { + if( (*iter)->getNPPInstance() == instance ) + return *iter; + } + + return NULL; +} + +XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin ) +{ + ::std::list<XPlugin_Impl*>::iterator iter; + for( iter = PluginManager::get().getPlugins().begin(); + iter != PluginManager::get().getPlugins().end(); ++iter ) + { + if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) ) + return *iter; + } + + return NULL; +} + +XPlugin_Impl* XPluginManager_Impl::getFirstXPlugin() +{ + if( PluginManager::get().getPlugins().begin() == PluginManager::get().getPlugins().end() ) + return NULL; + + return *PluginManager::get().getPlugins().begin(); +} + +Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPlugin( const Reference< ::com::sun::star::plugin::XPluginContext >& acontext, INT16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const ::com::sun::star::plugin::PluginDescription& plugintype) + throw( RuntimeException,::com::sun::star::plugin::PluginException ) +{ + XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr ); + pImpl->setPluginContext( acontext ); + + PluginManager::get().getPlugins().push_back( pImpl ); + + pImpl->initInstance( plugintype, + argn, + argv, + mode ); + + return pImpl; +} + +Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPluginFromURL( const Reference< ::com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const Reference< ::com::sun::star::awt::XToolkit > & toolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & parent, const ::rtl::OUString& url ) +{ + XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr ); + Reference< ::com::sun::star::plugin::XPlugin > xRef = pImpl; // festhalten... + + pImpl->setPluginContext( acontext ); + + PluginManager::get().getPlugins().push_back( pImpl ); + + int nDescr = -1; + Sequence< ::com::sun::star::plugin::PluginDescription > aDescrs = getPluginDescriptions(); + const ::com::sun::star::plugin::PluginDescription* pDescrs = aDescrs.getConstArray(); + + int nPos = url.lastIndexOf( (sal_Unicode)'.' ); + if( nPos != -1 ) + { + ::rtl::OUString aExt = url.copy( nPos ).toLowerCase(); + for( int i = 0; i < aDescrs.getLength(); i++ ) + { + if( pDescrs[ i ].Extension.equalsIgnoreCase( aExt ) != STRING_NOTFOUND ) + { + nDescr = i; + break; + } + } + } + + pImpl->initInstance( (nDescr != -1) ? pDescrs[ nDescr ] : ::com::sun::star::plugin::PluginDescription(), + argn, + argv, + mode ); + + pImpl->createPeer( toolkit, parent ); + + Reference< ::com::sun::star::beans::XPropertySet > xProperty( pImpl->getModel(), UNO_QUERY ); + if( xProperty.is() ) + { + Any aAny; + aAny <<= url; + xProperty->setPropertyValue( ::rtl::OUString::createFromAscii( "URL" ), aAny ); + } + + if( ! pImpl->getPluginComm() ) + { + pImpl->dispose(); + xRef = NULL; + } + + return xRef; +} + diff --git a/extensions/source/plugin/base/multiplx.cxx b/extensions/source/plugin/base/multiplx.cxx new file mode 100644 index 000000000000..d2ba82df78d7 --- /dev/null +++ b/extensions/source/plugin/base/multiplx.cxx @@ -0,0 +1,391 @@ +/************************************************************************* + * + * $RCSfile: multiplx.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <vos/diagnose.hxx> +#include <plugin/multiplx.hxx> + +// --------------------------------------------------------------------- +// class MRCListenerMultiplexerHelper +// --------------------------------------------------------------------- +MRCListenerMultiplexerHelper::MRCListenerMultiplexerHelper +( + const Reference< ::com::sun::star::awt::XWindow > & rControl + , const Reference< ::com::sun::star::awt::XWindow > & rPeer +) + : aListenerHolder( aMutex ) + , xPeer( rPeer ) + , xControl( Reference< ::com::sun::star::awt::XControl >( rControl, UNO_QUERY ) ) +{ +} + + +void MRCListenerMultiplexerHelper::setPeer( const Reference< ::com::sun::star::awt::XWindow > & rPeer ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( aMutex ); + if( xPeer != rPeer ) + { + if( xPeer.is() ) + { + // get all uiks from the listener added to the peer + Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes(); + const Type* pArray = aContainedTypes.getConstArray(); + sal_Int32 nCount = aContainedTypes.getLength(); + // loop over all listener types and remove the listeners from the peer + for( sal_Int32 i = 0; i < nCount; i++ ) + unadviseFromPeer( xPeer, pArray[i] ); + } + xPeer = rPeer; + if( xPeer.is() ) + { + // get all uiks from the listener added to the peer + Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes(); + const Type * pArray = aContainedTypes.getConstArray(); + sal_Int32 nCount = aContainedTypes.getLength(); + // loop over all listener types and add the listeners to the peer + for( sal_Int32 i = 0; i < nCount; i++ ) + adviseToPeer( xPeer, pArray[i] ); + } + } +} + +// MRCListenerMultiplexerHelper +void MRCListenerMultiplexerHelper::disposeAndClear() +{ + ::com::sun::star::lang::EventObject aEvt; + aEvt.Source = xControl; + aListenerHolder.disposeAndClear( aEvt ); +} + +// MRCListenerMultiplexerHelper +void MRCListenerMultiplexerHelper::adviseToPeer( const Reference< ::com::sun::star::awt::XWindow > & rPeer, const Type & type ) +{ + // add a listener to the source (peer) + if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) ) + rPeer->addWindowListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) ) + rPeer->addKeyListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) ) + rPeer->addFocusListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) ) + rPeer->addMouseListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) ) + rPeer->addMouseMotionListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) ) + rPeer->addPaintListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) ) + { + Reference< ::com::sun::star::awt::XTopWindow > xTop( rPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->addTopWindowListener( this ); + } + else + { + VOS_ENSHURE( sal_False, "unknown listener" ); + } +} + +// MRCListenerMultiplexerHelper +void MRCListenerMultiplexerHelper::unadviseFromPeer( const Reference< ::com::sun::star::awt::XWindow > & rPeer, const Type & type ) +{ + // the last listener is removed, remove the listener from the source (peer) + if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) ) + rPeer->removeWindowListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) ) + rPeer->removeKeyListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) ) + rPeer->removeFocusListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) ) + rPeer->removeMouseListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) ) + rPeer->removeMouseMotionListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) ) + rPeer->removePaintListener( this ); + else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) ) + { + Reference< ::com::sun::star::awt::XTopWindow > xTop( rPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->removeTopWindowListener( this ); + } + else + { + VOS_ENSHURE( sal_False, "unknown listener" ); + } +} + +// MRCListenerMultiplexerHelper +void MRCListenerMultiplexerHelper::advise( const Type & type, const Reference< XInterface > & listener) +{ + ::osl::Guard< ::osl::Mutex > aGuard( aMutex ); + if( 1 == aListenerHolder.addInterface( type, listener ) ) + { + // the first listener is added + if( xPeer.is() ) + adviseToPeer( xPeer, type ); + } +} + +// MRCListenerMultiplexerHelper +void MRCListenerMultiplexerHelper::unadvise(const Type & type, const Reference< XInterface > & listener) +{ + ::osl::Guard< ::osl::Mutex > aGuard( aMutex ); + ::cppu::OInterfaceContainerHelper * pCont = aListenerHolder.getContainer( type ); + if( pCont ) + { + if( 0 == pCont->removeInterface( listener ) && xPeer.is() ) + // the last listener is removed + unadviseFromPeer( xPeer, type ); + } +} + +// ::com::sun::star::lang::XEventListener +void MRCListenerMultiplexerHelper::disposing(const ::com::sun::star::lang::EventObject& ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( aMutex ); + // peer is disposed, clear the reference + xPeer = Reference< ::com::sun::star::awt::XWindow > (); +} + +#define MULTIPLEX( InterfaceName, MethodName, EventName ) \ +::cppu::OInterfaceContainerHelper * pCont; \ +pCont = aListenerHolder.getContainer( ::getCppuType((const Reference< InterfaceName >*)0) ); \ +if( pCont ) \ +{ \ + ::cppu::OInterfaceIteratorHelper aIt( *pCont ); \ + EventName aEvt = e; \ + /* Remark: The control is the event source not the peer. We must change */ \ + /* the source of the event */ \ + aEvt.Source = xControl;\ + /*.is the control not destroyed */ \ + if( aEvt.Source.is() ) \ + { \ + if( aIt.hasMoreElements() ) \ + { \ + InterfaceName * pListener = (InterfaceName *)aIt.next(); \ + try \ + { \ + pListener->MethodName( aEvt ); \ + } \ + catch( RuntimeException& ) \ + { \ + /* ignore all usr system exceptions from the listener */ \ + } \ + } \ + } \ +} + +// ::com::sun::star::awt::XFocusListener +void MRCListenerMultiplexerHelper::focusGained(const ::com::sun::star::awt::FocusEvent& e) +{ +/* + OInterfaceContainerHelper * pCont = aListenerHolder.getContainer( ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) ); + if( pCont ) + { + OInterfaceIteratorHelper aIt( *pCont ); + ::com::sun::star::awt::FocusEvent aEvt = e; + // Reamark: The control is the event source not the peer. We must change + // the source of the event + xControl.queryHardRef( ((XInterface*)NULL)->getSmartUik(), aEvt.Source ); + //.is the control not destroyed + if( aEvt.Source.is() ) + { + if( aIt.hasMoreElements() ) + { + ::com::sun::star::awt::XFocusListener * pListener = (::com::sun::star::awt::XFocusListener *)aIt.next(); + TRY + { + pListener->focusGained( aEvt ); + } + CATCH( RuntimeException, e ) + { + // ignore all usr system exceptions from the listener + } + END_CATCH; + } + } + } +*/ + MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusGained, ::com::sun::star::awt::FocusEvent ) +} + +// ::com::sun::star::awt::XFocusListener +void MRCListenerMultiplexerHelper::focusLost(const ::com::sun::star::awt::FocusEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusLost, ::com::sun::star::awt::FocusEvent ) +} + +// ::com::sun::star::awt::XWindowListener +void MRCListenerMultiplexerHelper::windowResized(const ::com::sun::star::awt::WindowEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowResized, ::com::sun::star::awt::WindowEvent ) +} + +// ::com::sun::star::awt::XWindowListener +void MRCListenerMultiplexerHelper::windowMoved(const ::com::sun::star::awt::WindowEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowMoved, ::com::sun::star::awt::WindowEvent ) +} + +// ::com::sun::star::awt::XWindowListener +void MRCListenerMultiplexerHelper::windowShown(const ::com::sun::star::lang::EventObject& e) +{ + MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowShown, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XWindowListener +void MRCListenerMultiplexerHelper::windowHidden(const ::com::sun::star::lang::EventObject& e) +{ + MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowHidden, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XKeyListener +void MRCListenerMultiplexerHelper::keyPressed(const ::com::sun::star::awt::KeyEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyPressed, ::com::sun::star::awt::KeyEvent ) +} + +// ::com::sun::star::awt::XKeyListener +void MRCListenerMultiplexerHelper::keyReleased(const ::com::sun::star::awt::KeyEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyReleased, ::com::sun::star::awt::KeyEvent ) +} + +// ::com::sun::star::awt::XMouseListener +void MRCListenerMultiplexerHelper::mousePressed(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseListener, mousePressed, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XMouseListener +void MRCListenerMultiplexerHelper::mouseReleased(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseReleased, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XMouseListener +void MRCListenerMultiplexerHelper::mouseEntered(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseEntered, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XMouseListener +void MRCListenerMultiplexerHelper::mouseExited(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseExited, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XMouseMotionListener +void MRCListenerMultiplexerHelper::mouseDragged(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseDragged, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XMouseMotionListener +void MRCListenerMultiplexerHelper::mouseMoved(const ::com::sun::star::awt::MouseEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseMoved, ::com::sun::star::awt::MouseEvent ) +} + +// ::com::sun::star::awt::XPaintListener +void MRCListenerMultiplexerHelper::windowPaint(const ::com::sun::star::awt::PaintEvent& e) +{ + MULTIPLEX( ::com::sun::star::awt::XPaintListener, windowPaint, ::com::sun::star::awt::PaintEvent ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowOpened(const ::com::sun::star::lang::EventObject& e) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowOpened, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowClosing( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosing, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowClosed( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosed, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowMinimized( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowMinimized, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowNormalized( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowNormalized, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowActivated( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowActivated, ::com::sun::star::lang::EventObject ) +} + +// ::com::sun::star::awt::XTopWindowListener +void MRCListenerMultiplexerHelper::windowDeactivated( const ::com::sun::star::lang::EventObject& e ) +{ + MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowDeactivated, ::com::sun::star::lang::EventObject ) +} diff --git a/extensions/source/plugin/base/nfuncs.cxx b/extensions/source/plugin/base/nfuncs.cxx new file mode 100644 index 000000000000..b90c002e82b9 --- /dev/null +++ b/extensions/source/plugin/base/nfuncs.cxx @@ -0,0 +1,576 @@ +/************************************************************************* + * + * $RCSfile: nfuncs.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <stl/list> + +#ifdef USE_NAMESPACE +using namespace std; +#endif + + +#include <plugin/impl.hxx> + +// #define TRACE(x) DBG_ERROR( (x) ) +#define TRACE(x) + + +NPNetscapeFuncs aNPNFuncs = +{ + sizeof( NPNetscapeFuncs ), + (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR, + NPN_GetURL, + NPN_PostURL, + NPN_RequestRead, + NPN_NewStream, + NPN_Write, + NPN_DestroyStream, + NPN_Status, + NPN_UserAgent, + NPN_MemAlloc, + NPN_MemFree, + NPN_MemFlush, + NPN_ReloadPlugins, + NPN_GetJavaEnv, + NPN_GetJavaPeer, + NPN_GetURLNotify, + NPN_PostURLNotify, + NPN_GetValue, + NPN_SetValue, + NPN_InvalidateRect, + NPN_InvalidateRegion, + NPN_ForceRedraw +}; + +static ::rtl::OString normalizeURL( XPlugin_Impl* plugin, const ::rtl::OString& url ) +{ + ::rtl::OString aLoadURL; + if( url.indexOf( ":/" ) == -1 ) + { + aLoadURL = ::rtl::OUStringToOString( plugin->getCreationURL(), plugin->getTextEncoding() ); + int nPos; + if( ( nPos = aLoadURL.indexOf( "://" ) ) != -1 ) + { + if( url.getLength() && url.getStr()[ 0 ] == '/' || url.indexOf( '/' ) != -1 ) + { + // this means same server but new path + nPos = aLoadURL.indexOf( '/', nPos+3 ); + + if( nPos != -1 ) + aLoadURL = aLoadURL.copy( 0, url.getStr()[0] == '/' ? nPos : nPos+1 ); + } + else + { + // same server but new file + nPos = aLoadURL.lastIndexOf( '/' ); + aLoadURL = aLoadURL.copy( 0, nPos+1 ); + } + aLoadURL += url; + } + else + aLoadURL = url; + } + else + aLoadURL = url; + + return aLoadURL; +} + + +extern "C" { + + void* SAL_CALL NP_LOADDS NPN_MemAlloc( uint32 nBytes ) + { + TRACE( "NPN_MemAlloc" ); + void* pMem = malloc( nBytes ); + return pMem; + } + + void SAL_CALL NP_LOADDS NPN_MemFree( void* pMem ) + { + TRACE( "NPN_MemFree" ); + free( pMem ); + } + + uint32 SAL_CALL NP_LOADDS NPN_MemFlush( uint32 nSize ) + { + TRACE( "NPN_MemFlush" ); + return 0; + } + + NPError SAL_CALL NP_LOADDS NPN_DestroyStream( NPP instance, NPStream* stream, NPError reason ) + { + TRACE( "NPN_DestroyStream" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + PluginStream* pStream = pImpl->getStreamFromNPStream( stream ); + if( pStream ) + delete pStream; + + return NPERR_NO_ERROR; + } + + const JRIEnvInterface** SAL_CALL NP_LOADDS NPN_GetJavaEnv() + { + TRACE( "NPN_GetJavaEnv" ); + // no java in this program + return NULL; + } + + void* SAL_CALL NP_LOADDS NPN_GetJavaPeer( NPP instance ) + { + TRACE( "NPN_GetJavaPeer" ); + return NULL; + } + + NPError SAL_CALL NP_LOADDS NPN_GetURL( NPP instance, const char* url, const char* window ) + { + TRACE( "NPN_GetURL" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + ::rtl::OString aLoadURL = normalizeURL( pImpl, url ); + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + getURL( pImpl, + ::rtl::OStringToOUString( aLoadURL, pImpl->getTextEncoding() ), + ::rtl::OStringToOUString( window, pImpl->getTextEncoding() ) + ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; + } + + NPError SAL_CALL NP_LOADDS NPN_GetURLNotify( NPP instance, const char* url, const char* target, + void* notifyData ) + { + TRACE( "NPN_GetURLNotify" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + ::rtl::OString aLoadURL = normalizeURL( pImpl, url ); + PluginEventListener* pListener = + new PluginEventListener( pImpl, url, aLoadURL.getStr(), notifyData ); + if( ! target || ! *target ) + { + // stream will be fed back to plugin, + // notify immediately after destruction of stream + pImpl->addPluginEventListener( pListener ); + pListener = NULL; + } + + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + getURLNotify( pImpl, + ::rtl::OStringToOUString( aLoadURL, pImpl->getTextEncoding() ), + ::rtl::OStringToOUString( target, pImpl->getTextEncoding() ), + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > ( pListener ) ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; + } + + NPError SAL_CALL NP_LOADDS NPN_NewStream( NPP instance, NPMIMEType type, const char* target, + NPStream** stream ) + // stream is a return value + { + TRACE( "NPN_NewStream" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + PluginOutputStream* pStream = new PluginOutputStream( pImpl, + "", 0, 0 ); + *stream = pStream->getStream(); + + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + newStream( + pImpl, + ::rtl::OStringToOUString( type, pImpl->getTextEncoding () ), + ::rtl::OStringToOUString( target, pImpl->getTextEncoding() ), + ::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSource > ( pStream->getOutputStream(), UNO_QUERY ) + ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; + } + + NPError SAL_CALL NP_LOADDS NPN_PostURLNotify( NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData ) + { + TRACE( "NPN_PostURLNotify" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + ::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buf, len ); + + ::rtl::OString aPostURL = normalizeURL( pImpl, url ); + PluginEventListener* pListener = + new PluginEventListener( pImpl, url, aPostURL.getStr(), notifyData ); + + if( ! target || ! *target ) + { + // stream will be fed back to plugin, + // notify immediately after destruction of stream + pImpl->addPluginEventListener( pListener ); + pListener = NULL; + } + + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + postURLNotify( pImpl, + ::rtl::OStringToOUString( aPostURL, pImpl->getTextEncoding() ), + ::rtl::OStringToOUString( target, pImpl->getTextEncoding() ), + Bytes, + file, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > ( pListener ) ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; + } + + NPError SAL_CALL NP_LOADDS NPN_PostURL( NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file ) + { + TRACE( "NPN_PostURL" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return NPERR_INVALID_INSTANCE_ERROR; + + ::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buf, len ); + ::rtl::OString aPostURL = normalizeURL( pImpl, url ); + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + postURL( pImpl, + ::rtl::OStringToOUString( aPostURL, pImpl->getTextEncoding() ), + ::rtl::OStringToOUString( window, pImpl->getTextEncoding () ), + Bytes, + file ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; + } + + NPError SAL_CALL NP_LOADDS NPN_RequestRead( NPStream* stream, NPByteRange* rangeList ) + { + TRACE( "NPN_RequestRead" ); + if( ! rangeList ) + return NPERR_NO_ERROR; + + ::std::list<XPlugin_Impl*>& rList = PluginManager::get().getPlugins(); + ::std::list<XPlugin_Impl*>::iterator iter; + XPlugin_Impl* pPlugin = NULL; + PluginStream* pStream = NULL; + for( iter = rList.begin(); iter!= rList.end(); ++iter ) + if( ( pStream = (*iter)->getStreamFromNPStream( stream ) ) ) + { + pPlugin = *iter; + break; + } + if( ! pPlugin ) + return NPERR_INVALID_INSTANCE_ERROR; + if( ! pStream || pStream->getStreamType() != InputStream ) + return NPERR_FILE_NOT_FOUND; + + PluginInputStream* pInputStream = (PluginInputStream*)pStream; + sal_Int8* pBytes = NULL; + int nBytes = 0; + pPlugin->enterPluginCallback(); + while( rangeList ) + { + if( pBytes && nBytes < rangeList->length ) + { + delete pBytes; + pBytes = NULL; + } + if( ! pBytes ) + pBytes = new sal_Int8[ nBytes = rangeList->length ]; + int nRead = + pInputStream->read( rangeList->offset, pBytes, rangeList->length ); + int nPos = 0; + int nNow; + do + { + nNow = pPlugin->getPluginComm()-> + NPP_WriteReady( pPlugin->getNPPInstance(), + stream ); + pPlugin->getPluginComm()-> + NPP_Write( pPlugin->getNPPInstance(), + stream, + rangeList->offset + nPos, + nNow, + pBytes+nPos ); + nPos += nNow; + nRead -= nNow; + } while( nRead > 0 && nNow ); + rangeList = rangeList->next; + } + pPlugin->leavePluginCallback(); + + return NPERR_NO_ERROR; + } + + void SAL_CALL NP_LOADDS NPN_Status( NPP instance, const char* message ) + { + TRACE( "NPN_Status" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return; + + try + { + pImpl->enterPluginCallback(); + pImpl->getPluginContext()-> + displayStatusText( pImpl, ::rtl::OStringToOUString( message, pImpl->getTextEncoding() ) ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& ) + { + pImpl->leavePluginCallback(); + return; + } + } + + const char* SAL_CALL NP_LOADDS NPN_UserAgent( NPP instance ) + { + TRACE( "NPN_UserAgent" ); + static char* pAgent = strdup( "Mozilla" ); + + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return pAgent; + + ::rtl::OUString UserAgent; + try + { + pImpl->enterPluginCallback(); + UserAgent = pImpl->getPluginContext()-> + getUserAgent( pImpl ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& ) + { + pImpl->leavePluginCallback(); + return pAgent; + } + + if( pAgent ) + free( pAgent ); + pAgent = strdup( ::rtl::OUStringToOString( UserAgent, pImpl->getTextEncoding() ).getStr() ); + + return pAgent; + } + +void SAL_CALL NP_LOADDS NPN_Version( int* major, int* minor, int* net_major, int* net_minor ) +{ + TRACE( "NPN_Version" ); + *major = 4; + *minor = 0; + *net_major = 4; + *net_minor = 5; +} + +int32 SAL_CALL NP_LOADDS NPN_Write( NPP instance, NPStream* stream, int32 len, + void* buffer ) +{ + TRACE( "NPN_Write" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + if( ! pImpl ) + return 0; + + PluginStream* pStream = pImpl->getStreamFromNPStream( stream ); + if( ! pStream || pStream->getStreamType() != OutputStream ) + return 0; + + pImpl->enterPluginCallback(); + ::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buffer, len ); + ((PluginOutputStream*)pStream)->getOutputStream()->writeBytes( Bytes ); + pImpl->leavePluginCallback(); + + return len; +} + + +NPError SAL_CALL NP_LOADDS NPN_GetValue( NPP instance, NPNVariable variable, void* value ) +{ + TRACE( "NPN_GetValue" ); + XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance ); + +#ifdef UNX + // some special unix variables + XPlugin_Impl* pInstance = pImpl ? pImpl : XPluginManager_Impl::getFirstXPlugin(); + if( ! pInstance ) + return NULL; + + switch( variable ) + { + case NPNVxDisplay: + *((Display**)value) = pInstance->getAppDisplay(); +#ifdef DEBUG + fprintf( stderr, "NPN_GetValue of display\n" ); +#endif + return NPERR_NO_ERROR; + break; + case NPNVxtAppContext: + *((XtAppContext*)value) = pInstance->getAppContext(); +#ifdef DEBUG + fprintf( stderr, "NPN_GetValue of application context\n" ); +#endif + return NPERR_NO_ERROR; + } +#endif + + if( ! pImpl ) + return 0; + + ::rtl::OUString aValue; + try + { + pImpl->enterPluginCallback(); + aValue = pImpl->getPluginContext()-> + getValue( pImpl, (::com::sun::star::plugin::PluginVariable)variable ); + pImpl->leavePluginCallback(); + } + catch( ::com::sun::star::plugin::PluginException& e ) + { + pImpl->leavePluginCallback(); + return e.ErrorCode; + } + + return NPERR_NO_ERROR; +} + +void SAL_CALL NP_LOADDS NPN_ReloadPlugins(NPBool reloadPages) +{ + TRACE( "NPN_ReloadPlugins" ); +} + + +NPError SAL_CALL NP_LOADDS NPN_SetValue(NPP instance, NPPVariable variable, + void *value) +{ + TRACE( "NPN_SetValue" ); + return 0; +} + +void SAL_CALL NP_LOADDS NPN_InvalidateRect(NPP instance, NPRect *invalidRect) +{ + TRACE( "NPN_InvalidateRect" ); +} + +void SAL_CALL NP_LOADDS NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion) +{ + TRACE( "NPN_InvalidateRegion" ); +} + +void SAL_CALL NP_LOADDS NPN_ForceRedraw(NPP instance) +{ + TRACE( "NPN_ForceRedraw" ); +} + +} diff --git a/extensions/source/plugin/base/plcom.cxx b/extensions/source/plugin/base/plcom.cxx new file mode 100644 index 000000000000..98a16023737e --- /dev/null +++ b/extensions/source/plugin/base/plcom.cxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * $RCSfile: plcom.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifdef SOLARIS +#include <limits> +#endif + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <tools/fsys.hxx> +#include <plugin/impl.hxx> + +PluginComm::PluginComm( const ::rtl::OString& rLibName ) : + m_nRefCount( 0 ), + m_aLibName( rLibName ) +{ + PluginManager::get().getPluginComms().push_back( this ); +} + +PluginComm::~PluginComm() +{ + PluginManager::get().getPluginComms().remove( this ); + while( m_aFilesToDelete.size() ) + { + String aFile = m_aFilesToDelete.front(); + m_aFilesToDelete.pop_front(); + DirEntry aEntry( aFile ); + aEntry.Kill(); + } +} diff --git a/extensions/source/plugin/base/plctrl.cxx b/extensions/source/plugin/base/plctrl.cxx new file mode 100644 index 000000000000..e65c47570e9b --- /dev/null +++ b/extensions/source/plugin/base/plctrl.cxx @@ -0,0 +1,373 @@ +/************************************************************************* + * + * $RCSfile: plctrl.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_AWT_XADJUSTMENTLISTENER_HPP_ +#include <com/sun/star/awt/XAdjustmentListener.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XACTIONLISTENER_HPP_ +#include <com/sun/star/awt/XActionListener.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XTEXTLISTENER_HPP_ +#include <com/sun/star/awt/XTextListener.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XSPINLISTENER_HPP_ +#include <com/sun/star/awt/XSpinListener.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XITEMLISTENER_HPP_ +#include <com/sun/star/awt/XItemListener.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XVCLCONTAINERLISTENER_HPP_ +#include <com/sun/star/awt/XVclContainerListener.hpp> +#endif + +#include <plugin/plctrl.hxx> +#include <vcl/syschild.hxx> +#include <toolkit/helper/vclunohelper.hxx> + + +//-------------------------------------------------------------------------------------------------- +PluginControl_Impl::PluginControl_Impl() : + _pMultiplexer( NULL ) + , _bVisible( sal_False ) + , _bInDesignMode( sal_False ) + , _bEnable( sal_True ) + , _nX( 0 ) + , _nY( 0 ) + , _nWidth( 100 ) + , _nHeight( 100 ) + , _nFlags( WINDOW_POSSIZE_ALL ) +{ +} + +//-------------------------------------------------------------------------------------------------- +PluginControl_Impl::~PluginControl_Impl() +{ +} + +MRCListenerMultiplexerHelper* PluginControl_Impl::getMultiplexer() +{ + if( ! _pMultiplexer ) + _pMultiplexer = new MRCListenerMultiplexerHelper( this, _xPeerWindow ); + return _pMultiplexer; +} +//================================================================================================== +Reference< XInterface > PluginControl_Impl_NewInstance() +{ + return (::cppu::OWeakObject*)new PluginControl_Impl(); +} + +//-------------------------------------------------------------------------------------------------- + +void PluginControl_Impl::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) + throw( RuntimeException ) +{ + _aDisposeListeners.push_back( l ); +} + +//---- ::com::sun::star::lang::XComponent ---------------------------------------------------------------------------------- +void PluginControl_Impl::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) + throw( RuntimeException ) +{ + _aDisposeListeners.remove( l ); +} + +//---- ::com::sun::star::lang::XComponent ---------------------------------------------------------------------------------- +void PluginControl_Impl::dispose(void) + throw( RuntimeException ) +{ + // send disposing events + ::com::sun::star::lang::EventObject aEvt; + if( getMultiplexer() ) + getMultiplexer()->disposeAndClear(); + + // release context + _xContext = Reference< XInterface > (); + releasePeer(); +} + + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) + throw( RuntimeException ) +{ + _nX = nX_ >=0 ? nX_ : 0; + _nY = nY_ >=0 ? nY_ : 0; + _nWidth = nWidth_ >=0 ? nWidth_ : 0; + _nHeight = nHeight_ >=0 ? nHeight_ : 0; + _nFlags = nFlags; + + if (_xPeerWindow.is()) + _xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, nFlags ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +::com::sun::star::awt::Rectangle PluginControl_Impl::getPosSize(void) + throw( RuntimeException ) +{ + return _xPeerWindow->getPosSize(); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::setVisible( sal_Bool bVisible ) + throw( RuntimeException ) +{ + _bVisible = bVisible; + if (_xPeerWindow.is()) + _xPeerWindow->setVisible( _bVisible && !_bInDesignMode ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::setEnable( sal_Bool bEnable ) + throw( RuntimeException ) +{ + _bEnable = bEnable; + if (_xPeerWindow.is()) + _xPeerWindow->setEnable( _bEnable ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::setFocus(void) throw( RuntimeException ) +{ + if (_xPeerWindow.is()) + _xPeerWindow->setFocus(); +} + + +//-------------------------------------------------------------------------------------------------- +void PluginControl_Impl::releasePeer() +{ + if (_xPeer.is()) + { + _xParentWindow->removeFocusListener( this ); + _xPeerWindow->dispose(); + _pSysChild = NULL; + _xPeerWindow = Reference< ::com::sun::star::awt::XWindow > (); + _xPeer = Reference< ::com::sun::star::awt::XWindowPeer > (); + getMultiplexer()->setPeer( Reference< ::com::sun::star::awt::XWindow > () ); + } +} + +//---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------ +void PluginControl_Impl::createPeer( const Reference< ::com::sun::star::awt::XToolkit > & xToolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & xParentPeer ) + throw( RuntimeException ) +{ + if (_xPeer.is()) + { + DBG_ERROR( "### Peer is already set!" ); + return; + } + + _xParentPeer = xParentPeer; + _xParentWindow = Reference< ::com::sun::star::awt::XWindow > ( xParentPeer, UNO_QUERY ); + DBG_ASSERT( _xParentWindow.is(), "### no parent peer window!" ); + + Window* pImpl = VCLUnoHelper::GetWindow( xParentPeer ); + if (pImpl) + { + _pSysChild = new SystemChildWindow( pImpl, WB_CLIPCHILDREN ); +// _pSysChild->Show(); + if (pImpl->HasFocus()) + _pSysChild->GrabFocus(); + + // get peer + _xPeer = Reference< ::com::sun::star::awt::XWindowPeer > ( _pSysChild->GetComponentInterface() ); + _xPeerWindow = Reference< ::com::sun::star::awt::XWindow > ( _xPeer, UNO_QUERY ); + // !_BOTH_ MUST BE VALID! + DBG_ASSERT( (_xPeer.is() && _xPeerWindow.is()), "### no peer!" ); + + _xParentWindow->addFocusListener( this ); + _xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, _nFlags ); + _xPeerWindow->setEnable( _bEnable ); + _xPeerWindow->setVisible( _bVisible && !_bInDesignMode ); + } + else + { + DBG_ERROR( "### cannot get implementation of parent peer!" ); + } + + getMultiplexer()->setPeer( _xPeerWindow ); +} + +//---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------ +void PluginControl_Impl::setDesignMode( sal_Bool bOn ) + throw( RuntimeException ) +{ + _bInDesignMode = bOn; + if (_xPeerWindow.is()) + _xPeerWindow->setVisible( _bVisible && !_bInDesignMode ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addPaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removePaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addWindowListener( const Reference< ::com::sun::star::awt::XWindowListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removeWindowListener( const Reference< ::com::sun::star::awt::XWindowListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removeFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removeKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removeMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0), l ); +} + +//---- ::com::sun::star::awt::XWindow ------------------------------------------------------------------------------------- +void PluginControl_Impl::removeMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) + throw( RuntimeException ) +{ + getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0), l ); +} + + +//---- ::com::sun::star::awt::XView --------------------------------------------------------------------------------------- +void PluginControl_Impl::draw( sal_Int32 x, sal_Int32 y ) + throw( RuntimeException ) +{ + // has to be done by further implementation of control +} + +//---- ::com::sun::star::awt::XView --------------------------------------------------------------------------------------- +void PluginControl_Impl::setZoom( float ZoomX, float ZoomY ) + throw( RuntimeException ) +{ + // has to be done by further implementation of control +} + +//---- ::com::sun::star::lang::XEventListener ------------------------------------------------------------------------------ +void PluginControl_Impl::disposing( const ::com::sun::star::lang::EventObject & rSource ) + throw( RuntimeException ) +{ +} +//---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------ +void PluginControl_Impl::focusGained( const ::com::sun::star::awt::FocusEvent & rEvt ) + throw( RuntimeException ) +{ + if (_xPeerWindow.is()) + _xPeerWindow->setFocus(); +} +//---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------ +void PluginControl_Impl::focusLost( const ::com::sun::star::awt::FocusEvent & rEvt ) + throw( RuntimeException ) +{ +} + diff --git a/extensions/source/plugin/base/plmodel.cxx b/extensions/source/plugin/base/plmodel.cxx new file mode 100644 index 000000000000..702699f36ad1 --- /dev/null +++ b/extensions/source/plugin/base/plmodel.cxx @@ -0,0 +1,243 @@ +/************************************************************************* + * + * $RCSfile: plmodel.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <plugin/model.hxx> + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + +using namespace com::sun::star::uno; + +//================================================================================================== +Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception ) +{ + Reference< XInterface > xService = *new PluginModel(); + return xService; +} + +Any PluginModel::queryAggregation( const Type& type ) +{ + Any aRet( ::cppu::queryInterface( type, + static_cast< ::com::sun::star::lang::XComponent* >(this), + static_cast< ::com::sun::star::io::XPersistObject* >(this ), + static_cast< ::com::sun::star::awt::XControlModel* >(this), + static_cast< ::com::sun::star::beans::XPropertySet* >(this), + static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this), + static_cast< ::com::sun::star::beans::XFastPropertySet* >(this) + ) ); + return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type ); +} + + +// ::com::sun::star::lang::XServiceInfo +::rtl::OUString PluginModel::getImplementationName() throw( ) + +{ + return getImplementationName_Static(); +} + +// ::com::sun::star::lang::XServiceInfo +sal_Bool PluginModel::supportsService(const ::rtl::OUString& ServiceName) throw( ) +{ + Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString * pArray = aSNL.getConstArray(); + for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) + if( pArray[i] == ServiceName ) + return sal_True; + return sal_False; +} + +// ::com::sun::star::lang::XServiceInfo +Sequence< ::rtl::OUString > PluginModel::getSupportedServiceNames(void) throw( ) +{ + return getSupportedServiceNames_Static(); +} + +// XPluginManager_Impl +Sequence< ::rtl::OUString > PluginModel::getSupportedServiceNames_Static(void) throw( ) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" ); + return aSNS; +} + + +static char* aCreationURL = "URL"; + +static ::osl::Mutex aPropertyMutex; + +static ::com::sun::star::beans::Property aProps[] = +{ + ::com::sun::star::beans::Property( + ::rtl::OUString::createFromAscii( aCreationURL ), + -1, + ::getCppuType((const ::rtl::OUString*)0), + ::com::sun::star::beans::PropertyAttribute::BOUND ) +}; + +PluginModel::PluginModel() : + BroadcasterHelperHolder( aPropertyMutex ), + OPropertySetHelper( m_aHelper ), + OPropertyArrayHelper( aProps, 1 ) +{ +} + +PluginModel::PluginModel(const ::rtl::OUString& rURL) : + BroadcasterHelperHolder( aPropertyMutex ), + OPropertySetHelper( m_aHelper ), + OPropertyArrayHelper( aProps, 1 ), + m_aCreationURL( rURL ) +{ +} + +PluginModel::~PluginModel() +{ +} + +Reference< ::com::sun::star::beans::XPropertySetInfo > PluginModel::getPropertySetInfo() +{ + static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo = + createPropertySetInfo( *this ); + return aInfo; +} + +::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper() +{ + return *this; +} + +sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) +{ + if( rValue.getValueTypeClass() == typelib_TypeClass_STRING ) + + { + rConvertedValue = rValue; + rOldValue <<= m_aCreationURL; + return sal_True; + } + return sal_False; +} + +void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, + const Any& rValue ) + throw( ::com::sun::star::lang::IllegalArgumentException ) +{ + if( rValue.getValueTypeClass() == typelib_TypeClass_STRING ) + + { + rValue >>= m_aCreationURL; + } + else + throw ::com::sun::star::lang::IllegalArgumentException(); +} + +void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const +{ + rValue <<= m_aCreationURL; +} + +//---- ::com::sun::star::lang::XComponent ---------------------------------------------------------------------------------- +void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) +{ + m_aDisposeListeners.push_back( l ); +} + +//---- ::com::sun::star::lang::XComponent ---------------------------------------------------------------------------------- +void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) +{ + m_aDisposeListeners.remove( l ); +} + +//---- ::com::sun::star::lang::XComponent ---------------------------------------------------------------------------------- +void PluginModel::dispose(void) +{ + // send disposing events + ::com::sun::star::lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + ::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners; + for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin(); + it != aLocalListeners.end(); ++it ) + (*it)->disposing( aEvt ); + + m_aDisposeListeners.clear(); + + disposing(); +} + + +// ::com::sun::star::io::XPersistObject +::rtl::OUString PluginModel::getServiceName() +{ + return ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" ); +} + +void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) +{ + OutStream->writeUTF( m_aCreationURL ); +} + +void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) +{ + m_aCreationURL = InStream->readUTF(); +} diff --git a/extensions/source/plugin/base/service.cxx b/extensions/source/plugin/base/service.cxx new file mode 100644 index 000000000000..09049a332690 --- /dev/null +++ b/extensions/source/plugin/base/service.cxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * $RCSfile: service.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#include <plugin/impl.hxx> +#include <tools/debug.hxx> +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XSET_HPP_ +#include <com/sun/star/container/XSet.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#include <uno/dispatcher.h> // declaration of generic uno interface +#include <uno/mapping.hxx> // mapping stuff + +#include <cppuhelper/factory.hxx> + +using namespace cppu; + +//================================================================================================== +void registerPluginService( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMgr ) +{ + if (! xMgr.is()) + return; + + Reference< ::com::sun::star::container::XSet > xReg( xMgr, UNO_QUERY ); + if(xReg.is()) + { + Any aAny; + Reference< ::com::sun::star::lang::XSingleServiceFactory > xF; + xF = createSingleFactory( xMgr, PluginModel::getImplementationName_Static(), + + PluginModel_CreateInstance, + PluginModel::getSupportedServiceNames_Static() ); + aAny <<= xF; + xReg->insert( aAny ); + xF = createSingleFactory( xMgr, XPluginManager_Impl::getImplementationName_Static(), + + PluginManager_CreateInstance, + XPluginManager_Impl::getSupportedServiceNames_Static() ); + aAny <<= xF; + xReg->insert( aAny ); + } +} + +extern "C" { + void SAL_CALL component_getImplementationEnvironment( + const sal_Char** ppEnvTypeName, + uno_Environment** ppEnv ) + { + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + sal_Bool SAL_CALL component_writeInfo( void* pServiceManager, void* pXUnoKey ) + { + if( pXUnoKey ) + { + try + { + Reference< ::com::sun::star::registry::XRegistryKey > xKey( reinterpret_cast< ::com::sun::star::registry::XRegistryKey* >( pXUnoKey ) ); + + ::rtl::OUString aImplName = ::rtl::OUString::createFromAscii( "/" ); + aImplName += XPluginManager_Impl::getImplementationName_Static(); + aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginManager" ); + xKey->createKey( aImplName ); + + aImplName = ::rtl::OUString::createFromAscii( "/" ); + aImplName += PluginModel::getImplementationName_Static(); + aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginModel" ); + xKey->createKey( aImplName ); + + return sal_True; + } + catch( ::com::sun::star::registry::InvalidRegistryException& ) + { + } + } + return sal_False; + } + + void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pXUnoSMgr, + void* pXUnoKey + ) + { + void* pRet = 0; + + ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) ); + + if( pXUnoSMgr ) + { + Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr( + reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pXUnoSMgr ) + ); + Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory; + if( aImplName.equals( XPluginManager_Impl::getImplementationName_Static() ) ) + { + xFactory = ::cppu::createSingleFactory( + xMgr, aImplName, PluginManager_CreateInstance, + XPluginManager_Impl::getSupportedServiceNames_Static() ); + } + else if( aImplName.equals( PluginModel::getImplementationName_Static() ) ) + { + xFactory = ::cppu::createSingleFactory( + xMgr, aImplName, PluginModel_CreateInstance, + PluginModel::getSupportedServiceNames_Static() ); + } + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + return pRet; + } + +/** special registration procedure for the staroffice player */ + void SAL_CALL exService_getSmartFactory( const sal_Char* implementationName, const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr, Reference< ::com::sun::star::lang::XSingleServiceFactory > & xFactory ) + { + ::rtl::OUString aImplementationName( ::rtl::OUString::createFromAscii(implementationName)); + + if (aImplementationName == PluginModel::getImplementationName_Static() ) + + { + xFactory = createSingleFactory( rSMgr, aImplementationName, + PluginModel_CreateInstance, + PluginModel::getSupportedServiceNames_Static() ); + } + else if (aImplementationName == XPluginManager_Impl::getImplementationName_Static() ) + + { + xFactory = createSingleFactory( rSMgr, aImplementationName, + PluginManager_CreateInstance, + XPluginManager_Impl::getSupportedServiceNames_Static() ); + } + } +} /* extern "C" */ diff --git a/extensions/source/plugin/base/xplugin.cxx b/extensions/source/plugin/base/xplugin.cxx new file mode 100644 index 000000000000..b8692b7c656f --- /dev/null +++ b/extensions/source/plugin/base/xplugin.cxx @@ -0,0 +1,888 @@ +/************************************************************************* + * + * $RCSfile: xplugin.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:16:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <string> // workaround for SUNPRO workshop include conflicts + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LOADER_XIMPLEMENTATIONLOADER_HPP_ +#include <com/sun/star/loader/XImplementationLoader.hpp> +#endif +#ifndef _COM_SUN_STAR_LOADER_CANNOTACTIVATEFACTORYEXCEPTION_HPP_ +#include <com/sun/star/loader/CannotActivateFactoryException.hpp> +#endif + +#include <plugin/impl.hxx> +#include <tools/fsys.hxx> + +#include <tools/urlobj.hxx> +#include <tools/string.hxx> +#include <vcl/svapp.hxx> +#include <vos/timer.hxx> + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +class PluginDisposer : public ::vos::OTimer +{ +private: + XPlugin_Impl* m_pPlugin; + + virtual void SAL_CALL onShot(); +public: + PluginDisposer( XPlugin_Impl* pPlugin ) : + OTimer( ::vos::TTimeValue( 2, 0 ), + ::vos::TTimeValue( 2, 0 ) ), + m_pPlugin( pPlugin ) + { start(); } + ~PluginDisposer() {} +}; + +void PluginDisposer::onShot() +{ + if( m_pPlugin ) + { + if( m_pPlugin->isDisposable() ) + { + sal_uInt32 nEvent; + Application::PostUserEvent( nEvent, LINK( m_pPlugin, XPlugin_Impl, secondLevelDispose ), (void*)m_pPlugin ); + } + } + else + release(); +} + +//================================================================================================== + +//================================================================================================== +// const Reference< ::com::sun::star::reflection::XIdlClass > & XPlugin_Impl::staticGetIdlClass() +// { +// static Reference< ::com::sun::star::reflection::XIdlClass > aClass = createStandardClass( L"Plugin", +// OWeakAggObject::getStaticIdlClass(), 6, +// ::getCppuType((const ::com::sun::star::awt::XControl*)0), +// ::getCppuType((const ::com::sun::star::awt::XControlModel*)0), +// ::getCppuType((const ::com::sun::star::awt::XWindow*)0), +// ::getCppuType((const ::com::sun::star::lang::XComponent*)0), +// ::getCppuType((const ::com::sun::star::awt::XView*)0), +// ::getCppuType((const ::com::sun::star::plugin::XPlugin*)0) ); +// return aClass; +// } + +Any XPlugin_Impl::queryInterface( const Type& type ) + +{ + return OWeakAggObject::queryInterface( type ); +} + +Any XPlugin_Impl::queryAggregation( const Type& type ) +{ + Any aRet( ::cppu::queryInterface( type, static_cast< ::com::sun::star::plugin::XPlugin* >(this) ) ); + if( ! aRet.hasValue() ) + aRet = PluginControl_Impl::queryAggregation( type ); + return aRet; +} + + +XPlugin_Impl::XPlugin_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) : + m_xSMgr( rSMgr ), + PluginControl_Impl(), + m_pPluginComm( NULL ), + m_pArgn( NULL ), + m_pArgv( NULL ), + m_nArgs( 0 ), + m_aPluginMode( NP_FULL ), + m_nProvidingState( PROVIDING_NONE ), + m_nCalledFromPlugin( 0 ), + m_pDisposer( NULL ), + m_bIsDisposed( sal_False ), + m_aEncoding( gsl_getSystemTextEncoding() ) +{ + memset( &m_aInstance, 0, sizeof( m_aInstance ) ); + memset( &m_aNPWindow, 0, sizeof( m_aNPWindow ) ); +#ifdef UNX + m_aAppContext = NULL; + m_pDisplay = NULL; + memset( &m_aWSInfo, 0, sizeof( m_aWSInfo ) ); +#endif + + m_xModel = new PluginModel(); + Reference< ::com::sun::star::beans::XPropertySet > xPS( m_xModel, UNO_QUERY ); + xPS->addPropertyChangeListener( ::rtl::OUString(), this ); + + ::osl::Guard< ::osl::Mutex > aGuard( PluginManager::get().getPluginMutex() ); + PluginManager::get().getPlugins().push_back( this ); +} + +void XPlugin_Impl::destroyInstance() +{ + NPSavedData* pSavedData = NULL; + + destroyStreams(); + if( getPluginComm() ) + { + getPluginComm()->NPP_Destroy( getNPPInstance(), + &pSavedData ); + getPluginComm()->decRef(); + m_pPluginComm = NULL; + } + + if( m_nArgs > 0 ) + { + for( ; m_nArgs--; ) + { + free( (void*)m_pArgn[m_nArgs] ); + free( (void*)m_pArgv[m_nArgs] ); + } + delete m_pArgn; + delete m_pArgv; + } + while( m_aPEventListeners.size() ) + { + delete *m_aPEventListeners.begin(); + m_aPEventListeners.pop_front(); + } +} + +XPlugin_Impl::~XPlugin_Impl() +{ + destroyInstance(); +} + +void XPlugin_Impl::checkListeners( const char* normalizedURL ) +{ + if( ! normalizedURL ) + return; + + ::std::list<PluginEventListener*>::iterator iter; + for( iter = m_aPEventListeners.begin(); + iter != m_aPEventListeners.end(); + ++iter ) + { + if( ! strcmp( normalizedURL, (*iter)->getURL() ) || + ! strcmp( normalizedURL, (*iter)->getNormalizedURL() ) ) + { + (*iter)->disposing( ::com::sun::star::lang::EventObject() ); + delete *iter; + m_aPEventListeners.remove( *iter ); + return; + } + } +} + +IMPL_LINK( XPlugin_Impl, secondLevelDispose, XPlugin_Impl*, pThis ) +{ + // may have become undisposable between PostUserEvent and here + // or may have disposed and receive a second UserEvent + ::std::list<XPlugin_Impl*>& rList = PluginManager::get().getPlugins(); + ::std::list<XPlugin_Impl*>::iterator iter; + + { + ::osl::Guard< ::osl::Mutex > aGuard( PluginManager::get().getPluginMutex() ); + for( iter = rList.begin(); iter != rList.end(); ++iter ) + { + if( *iter == this ) + break; + } + if( iter == rList.end() || ! isDisposable() ) + return 0; + } + + if (m_pDisposer) + { + m_pDisposer->release(); + m_pDisposer = NULL; + } + + Reference< ::com::sun::star::plugin::XPlugin > xProtection( this ); + Reference< ::com::sun::star::beans::XPropertySet > xPS( m_xModel, UNO_QUERY ); + xPS->removePropertyChangeListener( ::rtl::OUString(), this ); + { + ::osl::Guard< ::osl::Mutex > aGuard( PluginManager::get().getPluginMutex() ); + rList.remove( this ); + } + m_aNPWindow.window = NULL; +#ifndef UNX + // acrobat does an unconditional XtParent on the windows widget + getPluginComm()-> + NPP_SetWindow( getNPPInstance(), &m_aNPWindow ); +#endif + destroyInstance(); + PluginControl_Impl::dispose(); + return 0; +} + +void XPlugin_Impl::dispose() +{ + if (m_bIsDisposed || !getPluginComm()) + return; + m_bIsDisposed = sal_True; + + if( isDisposable() ) + secondLevelDispose( this ); + else + { + m_pDisposer = new PluginDisposer( this ); + m_pDisposer->acquire(); + } +} + +void XPlugin_Impl::initInstance( const ::com::sun::star::plugin::PluginDescription& rDescription, + const Sequence< ::rtl::OUString >& argn, + const Sequence< ::rtl::OUString >& argv, + sal_Int16 mode ) +{ + m_aDescription = rDescription; + + // #69333# special for pdf + m_aPluginMode = mode; + if( m_aDescription.Mimetype.compareToAscii( "application/pdf" ) ) + m_aPluginMode = ::com::sun::star::plugin::PluginMode::FULL; + + m_nArgs = argn.getLength(); + m_pArgn = new const char*[m_nArgs]; + m_pArgv = new const char*[m_nArgs]; + const ::rtl::OUString* pUArgn = argn.getConstArray(); + const ::rtl::OUString* pUArgv = argv.getConstArray(); + for( int i = 0; i < m_nArgs; i++ ) + { + m_pArgn[i] = strdup( + ::rtl::OUStringToOString( pUArgn[i], m_aEncoding ).getStr() + ); + m_pArgv[i] = strdup( + ::rtl::OUStringToOString( pUArgv[i], m_aEncoding ).getStr() + ); + } +} + +void XPlugin_Impl::modelChanged() +{ + m_nProvidingState = PROVIDING_MODEL_UPDATE; + + // empty description is only set when created by createPluginFromURL + if( m_aDescription.Mimetype.getLength() ) + destroyInstance(); + + Reference< ::com::sun::star::plugin::XPluginManager > xPMgr( m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ) ), UNO_QUERY ); + if( !xPMgr.is() ) + { + m_nProvidingState = PROVIDING_NONE; + return; + } + + int nDescr = -1; + Sequence< ::com::sun::star::plugin::PluginDescription > aDescrs = xPMgr->getPluginDescriptions(); + const ::com::sun::star::plugin::PluginDescription* pDescrs = aDescrs.getConstArray(); + + ::rtl::OUString aURL = getCreationURL(); + int nPos = aURL.lastIndexOf( (sal_Unicode)'.' ); + ::rtl::OUString aExt = aURL.copy( nPos ).toLowerCase(); + if( nPos != -1 ) + { + for( int i = 0; i < aDescrs.getLength(); i++ ) + { + ::rtl::OUString aThisExt = pDescrs[ i ].Extension.toLowerCase(); + if( aThisExt.indexOf( aExt ) != -1 ) + { + nDescr = i; + break; + } + } + } + + if( nDescr != -1 ) + { + INetURLObject aURL; + aURL.SetSmartProtocol( INET_PROT_FILE ); + aURL.SetSmartURL( ::rtl::OUStringToOString( getCreationURL(), m_aEncoding ) ); + + Reference< ::com::sun::star::lang::XMultiServiceFactory > xFact( m_xSMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.DataSourceFactory" ) ), UNO_QUERY ); + if ( xFact.is() ) + { + Sequence < Any > aArgs(1); + aArgs.getArray()[0] <<= ::rtl::OUString( aURL.GetMainURL() ); + ::rtl::OUString aProt( INetURLObject::GetScheme( aURL.GetProtocol() ) ); + Reference< ::com::sun::star::io::XActiveDataSource > xSource( xFact->createInstanceWithArguments( aProt, aArgs ), UNO_QUERY ); + if ( xSource.is() ) + { + m_aDescription = pDescrs[ nDescr ]; + provideNewStream( m_aDescription.Mimetype, + xSource, + getRefererURL(), + 0, 0, sal_False ); + } + } + } + m_nProvidingState = PROVIDING_NONE; +} + +::rtl::OUString XPlugin_Impl::getCreationURL() +{ + ::rtl::OUString aRet; + Reference< ::com::sun::star::beans::XPropertySet > xPS( m_xModel, UNO_QUERY ); + if( xPS.is() ) + { + Any aValue = xPS->getPropertyValue( ::rtl::OUString::createFromAscii( "URL" ) ); + aValue >>= aRet; + } + return aRet; +} + + +sal_Bool XPlugin_Impl::setModel( const Reference< ::com::sun::star::awt::XControlModel > & Model ) + throw( RuntimeException ) +{ + Reference< ::com::sun::star::beans::XPropertySet > xPS( Model, UNO_QUERY ); + if( ! xPS.is() ) + return sal_False; + + if( getCreationURL().getLength() ) + { + m_xModel = Model; + modelChanged(); + xPS->addPropertyChangeListener( ::rtl::OUString(), this ); + return sal_True; + } + return sal_False; +} + +void XPlugin_Impl::createPeer( const Reference< ::com::sun::star::awt::XToolkit > & xToolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & Parent ) + throw( RuntimeException ) +{ + if( ! _xPeer.is() ) + { + if( ! Parent.is() ) + throw RuntimeException(); + PluginControl_Impl::createPeer( xToolkit, Parent ); + } +} + +void XPlugin_Impl::loadPlugin() +{ + ::std::list<PluginComm*>::iterator iter; + for( iter = PluginManager::get().getPluginComms().begin(); + iter != PluginManager::get().getPluginComms().end(); ++iter ) + { + if( ::rtl::OStringToOUString( (*iter)->getLibName(), m_aEncoding ) == m_aDescription.PluginName ) + { + setPluginComm( *iter ); + break; + } + } + const SystemEnvData* pEnvData = getSysChildSysData(); +#ifdef UNX + XSync( (Display*)pEnvData->pDisplay, False ); +#endif + if( ! getPluginComm() ) + { +#ifdef UNX + m_pDisplay = (Display*)pEnvData->pDisplay; + m_aAppContext = (XtAppContext)pEnvData->pAppContext; + // need a new PluginComm + PluginComm* pComm = new UnxPluginComm( ::rtl::OUStringToOString( m_aDescription.PluginName, gsl_getSystemTextEncoding() ) ); +#elif (defined WNT || defined OS2) + PluginComm* pComm = new PluginComm_Impl( m_aDescription.Mimetype, + m_aDescription.PluginName, + (HWND)pEnvData->hWnd ); +#endif + setPluginComm( pComm ); + } + + NPError aError = getPluginComm()-> + NPP_New( (char*)::rtl::OUStringToOString( m_aDescription.Mimetype, + m_aEncoding).getStr(), + getNPPInstance(), + m_aPluginMode, + m_nArgs, + (char**)(m_nArgs ? m_pArgn : NULL), + (char**)(m_nArgs ? m_pArgv : NULL), + NULL ); + +#ifdef UNX + XSync( (Display*)pEnvData->pDisplay, False ); +#endif +#ifdef UNX + m_aNPWindow.window = (void*)pEnvData->aWindow; + m_aNPWindow.ws_info = &m_aWSInfo; + + m_aWSInfo.type = NP_SETWINDOW; + m_aWSInfo.display = (Display*)pEnvData->pDisplay; + m_aWSInfo.visual = (Visual*)pEnvData->pVisual; + m_aWSInfo.colormap = (Colormap)pEnvData->aColormap; + m_aWSInfo.depth = pEnvData->nDepth; +#else + m_aNPWindow.window = (void*)pEnvData->hWnd; +#endif + ::com::sun::star::awt::Rectangle aPosSize = getPosSize(); + + m_aNPWindow.clipRect.top = 0; + m_aNPWindow.clipRect.left = 0; + m_aNPWindow.clipRect.bottom = 0; + m_aNPWindow.clipRect.right = 0; + m_aNPWindow.type = NPWindowTypeWindow; + + m_aNPWindow.x = aPosSize.X; + m_aNPWindow.y = aPosSize.Y; + m_aNPWindow.width = aPosSize.Width ? aPosSize.Width : 600; + m_aNPWindow.height = aPosSize.Height ? aPosSize.Height : 600; + + aError = getPluginComm()-> + NPP_SetWindow( getNPPInstance(), &m_aNPWindow ); +} + +void XPlugin_Impl::destroyStreams() +{ + // streams remove themselves from this list when deleted + while( m_aOutputStreams.size() ) + delete *m_aOutputStreams.begin(); + + // input streams are XOutputStreams, they cannot be simply deleted + ::std::list<PluginInputStream*> aLocalList( m_aInputStreams ); + for( ::std::list<PluginInputStream*>::iterator it = aLocalList.begin(); + it != aLocalList.end(); ++it ) + (*it)->setMode( -1 ); +} + +PluginStream* XPlugin_Impl::getStreamFromNPStream( NPStream* stream ) +{ + ::std::list<PluginInputStream*>::iterator iter; + for( iter = m_aInputStreams.begin(); iter != m_aInputStreams.end(); ++iter ) + if( (*iter)->getStream() == stream ) + return *iter; + + ::std::list<PluginOutputStream*>::iterator iter2; + for( iter2 = m_aOutputStreams.begin(); iter2 != m_aOutputStreams.end(); ++iter2 ) + if( (*iter2)->getStream() == stream ) + return *iter2; + + return NULL; +} + +sal_Bool XPlugin_Impl::provideNewStream(const ::rtl::OUString& mimetype, + const Reference< ::com::sun::star::io::XActiveDataSource > & stream, + const ::rtl::OUString& url, sal_Int32 length, + sal_Int32 lastmodified, sal_Bool isfile) + +{ + if( m_nProvidingState == PROVIDING_NONE ) + { + m_nProvidingState = PROVIDING_NOW; + Any aAny; + aAny <<= url; + Reference< ::com::sun::star::beans::XPropertySet > xPS( m_xModel, UNO_QUERY ); + xPS->setPropertyValue( ::rtl::OUString::createFromAscii( "URL" ), aAny ); + } + + m_nProvidingState = PROVIDING_NOW; + if( ! m_pPluginComm ) + loadPlugin(); + + ::rtl::OString aMIME; + if( mimetype.len() ) + aMIME = ::rtl::OUStringToOString( mimetype, m_aEncoding ); + else + // Notnagel + aMIME = ::rtl::OUStringToOString( m_aDescription.Mimetype, m_aEncoding ); + + ::rtl::OString aURL = ::rtl::OUStringToOString( url, m_aEncoding ); + + // check wether there is a notifylistener for this stream + // this means that the strema is created from the plugin + // via NPN_GetURLNotify or NPN_PostURLNotify + ::std::list<PluginEventListener*>::iterator iter; + for( iter = m_aPEventListeners.begin(); + iter != m_aPEventListeners.end(); + ++iter ) + { + if( (*iter)->getNormalizedURL() == aURL ) + { + aURL = (*iter)->getURL(); + break; + } + } + + if( iter == m_aPEventListeners.end() ) + { + // e.g. plugger.so does not like file:/// + if( ! aURL.compareTo( "file://", 7 ) ) + { + INetURLObject aPath( url ); + aURL = ::rtl::OUStringToOString( aPath.PathToFileName(), m_aEncoding ); + } + } + + PluginInputStream* pStream = new PluginInputStream( this, aURL.getStr(), + length, lastmodified ); + Reference< ::com::sun::star::io::XOutputStream > xNewStream( pStream ); + + if( iter != m_aPEventListeners.end() ) + pStream->getStream()->notifyData = (*iter)->getNotifyData(); + + uint16 stype = 0; + + // sal_False in the following statement should logically be isfile + // but e.g. the acrobat reader plugin does not WANT a file + // NP_ASFILE or NP_ASFILEONLY if the new stream is seekable + // the reason for this behaviour is unknown +#ifdef DEBUG + fprintf( stderr, "new stream \"%s\" of MIMEType \"%s\"\nfor plugin \"%s\"\n", aURL.getStr(), aMIME.getStr(), getPluginComm()->getLibName().getStr() ); + +#endif + if( ! m_pPluginComm->NPP_NewStream( &m_aInstance, (char*)aMIME.getStr(), + pStream->getStream(), sal_False, + &stype ) ) + { + getPluginComm()->NPP_SetWindow( getNPPInstance(), &m_aNPWindow ); +#ifdef DEBUG + char* pType; + switch( stype ) + { + case NP_NORMAL: pType = "NP_NORMAL";break; + case NP_SEEK: pType = "NP_SEEK";break; + case NP_ASFILE: pType = "NP_ASFILE";break; + case NP_ASFILEONLY: pType = "NP_ASFILEONLY";break; + default: pType = "unknown!!!"; + } + fprintf( stderr, "Plugin wants it in Mode %s\n", pType ); +#endif + if( isfile && stype == NP_ASFILEONLY ) + { + m_pPluginComm-> + NPP_StreamAsFile( &m_aInstance, + pStream->getStream(), + pStream->getStream()->url ); + m_nProvidingState = PROVIDING_NONE; + return sal_True; + } + + if( ! stream.is() ) + { + m_pPluginComm-> + NPP_DestroyStream( &m_aInstance, + pStream->getStream(), + NPRES_NETWORK_ERR ); + m_nProvidingState = PROVIDING_NONE; + throw RuntimeException(); + } + pStream->setMode( stype ); + Reference< ::com::sun::star::io::XConnectable > xConnectable( stream, UNO_QUERY ); + pStream->setPredecessor( xConnectable ); + if( xConnectable.is() ) + { + xConnectable->setSuccessor( static_cast< ::com::sun::star::io::XConnectable* >(pStream) ); + while( xConnectable->getPredecessor().is() ) + xConnectable = xConnectable->getPredecessor(); + } + stream->setOutputStream( xNewStream ); + pStream->setSource( stream ); + Reference< ::com::sun::star::io::XActiveDataControl > xController; + if( xConnectable.is() ) + xController = Reference< ::com::sun::star::io::XActiveDataControl >( xConnectable, UNO_QUERY ); + else + xController = Reference< ::com::sun::star::io::XActiveDataControl >( stream, UNO_QUERY ); + + if( xController.is() ) + xController->start(); + } + + m_nProvidingState = PROVIDING_NONE; + + return sal_False; +} + +void XPlugin_Impl::disposing( const ::com::sun::star::lang::EventObject& rSource ) +{ +} + +void XPlugin_Impl::propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvent ) +{ + if( ! rEvent.PropertyName.compareToAscii( "URL" ) ) + { + ::rtl::OUString aStr; + rEvent.NewValue >>= aStr; + if( m_nProvidingState == PROVIDING_NONE ) + { + if( aStr != m_aURL ) + { + m_aURL = aStr; + modelChanged(); + } + } + } +} + +void XPlugin_Impl::setPluginContext( const Reference< ::com::sun::star::plugin::XPluginContext > & rContext ) +{ + m_rBrowserContext = rContext; +} + +void XPlugin_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) + throw( RuntimeException ) +{ +#ifdef DEBUG + fprintf( stderr, "XPlugin_Impl::setPosSize( %d, %d, %d, %d, %d )\n", + nX_, nY_, nWidth_, nHeight_, nFlags ); +#endif + + PluginControl_Impl::setPosSize(nX_, nY_, nWidth_, nHeight_, nFlags); + m_aNPWindow.x = nX_; + m_aNPWindow.y = nY_; + m_aNPWindow.width = nWidth_; + m_aNPWindow.height = nHeight_; + + if(getPluginComm()) + getPluginComm()->NPP_SetWindow( getNPPInstance(), &m_aNPWindow ); +} + +PluginStream::PluginStream( XPlugin_Impl* pPlugin, + const char* url, sal_uInt32 len, sal_uInt32 lastmod ) : + m_pPlugin( pPlugin ) +{ + memset( &m_aNPStream, 0, sizeof( m_aNPStream ) ); + m_aNPStream.url = strdup( url ); + m_aNPStream.end = len; + m_aNPStream.lastmodified = lastmod; +} + +PluginStream::~PluginStream() +{ + if( m_pPlugin && m_pPlugin->getPluginComm() ) + { + m_pPlugin->getPluginComm()->NPP_DestroyStream( m_pPlugin->getNPPInstance(), + &m_aNPStream, NPRES_DONE ); + m_pPlugin->checkListeners( m_aNPStream.url ); + m_pPlugin->getPluginComm()-> + NPP_SetWindow( m_pPlugin->getNPPInstance(), + m_pPlugin->getNPWindow()); + } + ::free( (void*)m_aNPStream.url ); +} + +PluginInputStream::PluginInputStream( XPlugin_Impl* pPlugin, + const char* url, + sal_uInt32 len, + sal_uInt32 lastmod ) : + PluginStream( pPlugin, url, len, lastmod ), + m_nMode( NP_NORMAL ), + m_nWritePos( 0 ) +{ + m_pPlugin->getInputStreams().push_back( this ); + DirEntry aEntry; + aEntry = aEntry.TempName(); + + // set correct extension, some plugins need that + DirEntry aName( String( m_aNPStream.url, m_pPlugin->getTextEncoding() ) ); + String aExtension = aName.GetExtension(); + if( aExtension.Len() ) + aEntry.SetExtension( aExtension ); + m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE ); + if( ! m_aFileStream.IsOpen() ) + { + // #74808# might be that the extension scrambled the whole filename + aEntry = aEntry.TempName(); + m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE ); + } +} + +PluginInputStream::~PluginInputStream() +{ + String aFile( m_aFileStream.GetFileName() ); + m_aFileStream.Close(); + if( m_pPlugin ) + { + ByteString aFileName( aFile, m_pPlugin->getTextEncoding() ); + if( m_pPlugin->getPluginComm() && m_nMode != -1 ) + // mode -1 means either an error occured, + // or the plugin is already disposing + { + m_pPlugin->getPluginComm()->addFileToDelete( aFile ); + if( m_nMode == NP_ASFILE ) + { + m_pPlugin->getPluginComm()-> + NPP_StreamAsFile( m_pPlugin->getNPPInstance(), + &m_aNPStream, + aFileName.GetBuffer() ); + } + m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin->getNPPInstance(), m_pPlugin->getNPWindow()); + m_pPlugin->getInputStreams().remove( this ); + } + else + DirEntry( m_aFileStream.GetFileName() ).Kill(); + } + else + DirEntry( m_aFileStream.GetFileName() ).Kill(); +} + +PluginStreamType PluginInputStream::getStreamType() +{ + return InputStream; +} + +void PluginInputStream::setMode( sal_uInt32 nMode ) +{ + m_nMode = nMode; + + // invalidation by plugin + if( m_nMode == -1 && m_pPlugin ) + { + m_pPlugin->getInputStreams().remove( this ); + m_pPlugin = NULL; + } +} + +void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) +{ + if( m_nMode == -1 ) + return; + + m_aFileStream.Seek( STREAM_SEEK_TO_END ); + m_aFileStream.Write( Buffer.getConstArray(), Buffer.getLength() ); + + int nPos = m_aFileStream.Tell(); + int nBytes = 0; + while( m_nMode != NP_SEEK && m_nMode != NP_ASFILEONLY && + ( nBytes = m_pPlugin->getPluginComm()-> + NPP_WriteReady( m_pPlugin->getNPPInstance(), + &m_aNPStream ) ) > 0 && + m_nWritePos < nPos ) + { + nBytes = nBytes > nPos - m_nWritePos ? nPos - m_nWritePos : nBytes; + + char* pBuffer = new char[ nBytes ]; + m_aFileStream.Seek( m_nWritePos ); + nBytes = m_aFileStream.Read( pBuffer, nBytes ); + + int nBytesRead = 0; + try + { + nBytesRead = m_pPlugin->getPluginComm()-> + NPP_Write( m_pPlugin->getNPPInstance(), + &m_aNPStream, + m_nWritePos, + nBytes, + pBuffer ); + delete pBuffer; + } + catch( ... ) + { + delete pBuffer; + return; + } + + if( nBytesRead < 0 ) + { + m_nMode = -1; + return; + } + + m_nWritePos += nBytesRead; + } + + m_pPlugin->getPluginComm()-> + NPP_SetWindow( m_pPlugin->getNPPInstance(), + m_pPlugin->getNPWindow()); +} + +void PluginInputStream::closeOutput() +{ + flush(); + m_xSource = Reference< ::com::sun::star::io::XActiveDataSource >(); +} + +sal_uInt32 PluginInputStream::read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size ) +{ + if( m_nMode != NP_SEEK ) + return 0; + + m_aFileStream.Seek( offset ); + int nBytes = m_aFileStream.Read( buffer, size ); + + return nBytes; +} + +void PluginInputStream::flush(void) +{ +} + +PluginOutputStream::PluginOutputStream( XPlugin_Impl* pPlugin, + const char* url, + sal_uInt32 len, + sal_uInt32 lastmod ) : + PluginStream( pPlugin, url, len, lastmod ), + m_xStream( pPlugin->getServiceManager()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.DataOutputStream" ) ), UNO_QUERY ) +{ + m_pPlugin->getOutputStreams().push_back( this ); +} + +PluginOutputStream::~PluginOutputStream() +{ + m_pPlugin->getOutputStreams().remove( this ); +} + +PluginStreamType PluginOutputStream::getStreamType() +{ + return OutputStream; +} + |