2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: nfuncs.cxx,v $
|
|
|
|
*
|
2004-03-17 09:13:54 +00:00
|
|
|
* $Revision: 1.10 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2004-03-17 09:13:54 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2004-03-17 10:13:54 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2000-11-23 21:18:20 +00:00
|
|
|
#include <list>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
#include <plugin/impl.hxx>
|
2003-05-28 11:37:29 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2003-04-15 15:17:20 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-12-07 09:54:52 +00:00
|
|
|
#include <osl/thread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
static FILE * s_file = 0;
|
|
|
|
void TRACE( char const * s )
|
|
|
|
{
|
|
|
|
if (! s_file)
|
2003-05-28 11:37:29 +00:00
|
|
|
s_file = stderr;
|
2001-12-07 10:10:15 +00:00
|
|
|
if (s_file)
|
|
|
|
{
|
|
|
|
oslThreadIdentifier t = osl_getThreadIdentifier(0);
|
|
|
|
fprintf( s_file, "log [t_id=%d]: %s\n", t, s );
|
|
|
|
fflush( s_file );
|
|
|
|
}
|
2001-12-07 09:54:52 +00:00
|
|
|
}
|
2001-12-07 10:10:15 +00:00
|
|
|
void TRACEN( char const * s, long n )
|
2001-12-07 09:54:52 +00:00
|
|
|
{
|
|
|
|
if (! s_file)
|
2003-05-28 11:37:29 +00:00
|
|
|
s_file = stderr;
|
2001-12-07 10:10:15 +00:00
|
|
|
if (s_file)
|
|
|
|
{
|
|
|
|
oslThreadIdentifier t = osl_getThreadIdentifier(0);
|
|
|
|
fprintf( s_file, "log [t_id=%d]: %s%d\n", t, s, n );
|
|
|
|
fflush( s_file );
|
|
|
|
}
|
2001-12-07 09:54:52 +00:00
|
|
|
}
|
2003-05-28 11:37:29 +00:00
|
|
|
void TRACES( char const* s, char const* s2 )
|
|
|
|
{
|
|
|
|
if (! s_file)
|
|
|
|
s_file = stderr;
|
|
|
|
if (s_file)
|
|
|
|
{
|
|
|
|
oslThreadIdentifier t = osl_getThreadIdentifier(0);
|
|
|
|
fprintf( s_file, "log [t_id=%d]: %s %s\n", t, s, s2 );
|
|
|
|
fflush( s_file );
|
|
|
|
}
|
|
|
|
}
|
2001-12-07 09:54:52 +00:00
|
|
|
#else
|
2000-09-18 15:18:56 +00:00
|
|
|
#define TRACE(x)
|
2001-12-07 10:10:15 +00:00
|
|
|
#define TRACEN(x,n)
|
2003-05-28 11:37:29 +00:00
|
|
|
#define TRACES(x,s)
|
2001-12-07 09:54:52 +00:00
|
|
|
#endif
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
using namespace rtl;
|
|
|
|
using namespace com::sun::star::lang;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
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;
|
2003-04-17 14:13:58 +00:00
|
|
|
if( url.indexOf( ":" ) == -1 )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2003-04-17 14:13:58 +00:00
|
|
|
else if( url.indexOf( ":/" ) != -1 )
|
2000-09-18 15:18:56 +00:00
|
|
|
aLoadURL = url;
|
|
|
|
|
|
|
|
return aLoadURL;
|
|
|
|
}
|
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
struct AsynchronousGetURL
|
|
|
|
{
|
|
|
|
OUString aUrl;
|
|
|
|
OUString aTarget;
|
|
|
|
Reference< XEventListener > xListener;
|
|
|
|
|
|
|
|
DECL_LINK( getURL, XPlugin_Impl* );
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPL_LINK( AsynchronousGetURL, getURL, XPlugin_Impl*, pImpl )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pImpl->enterPluginCallback();
|
|
|
|
if( xListener.is() )
|
|
|
|
pImpl->getPluginContext()->
|
|
|
|
getURLNotify( pImpl,
|
|
|
|
aUrl,
|
|
|
|
aTarget,
|
|
|
|
xListener );
|
|
|
|
else
|
|
|
|
pImpl->getPluginContext()->
|
|
|
|
getURL( pImpl,
|
|
|
|
aUrl,
|
|
|
|
aTarget );
|
|
|
|
}
|
|
|
|
catch( ::com::sun::star::plugin::PluginException& e )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
pImpl->leavePluginCallback();
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
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 )
|
2004-03-17 09:13:54 +00:00
|
|
|
{
|
|
|
|
if( pStream->getStreamType() == InputStream )
|
|
|
|
static_cast<PluginInputStream*>(pStream)->releaseSelf();
|
|
|
|
else
|
|
|
|
delete pStream;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2003-05-28 11:37:29 +00:00
|
|
|
TRACES( "NPN_GetURL", url );
|
2000-09-18 15:18:56 +00:00
|
|
|
XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
|
|
|
|
if( ! pImpl )
|
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
AsynchronousGetURL* pAsync = new AsynchronousGetURL();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
OString aLoadURL = normalizeURL( pImpl, url );
|
|
|
|
TRACES( "NPN_GetURL", aLoadURL.getStr() );
|
|
|
|
pAsync->aUrl = OStringToOUString( aLoadURL, pImpl->getTextEncoding() );
|
|
|
|
pAsync->aTarget = OStringToOUString( window, pImpl->getTextEncoding() );
|
|
|
|
pImpl->setLastGetUrl( aLoadURL );
|
|
|
|
Application::PostUserEvent( LINK( pAsync, AsynchronousGetURL, getURL ), pImpl );
|
2000-09-18 15:18:56 +00:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPError SAL_CALL NP_LOADDS NPN_GetURLNotify( NPP instance, const char* url, const char* target,
|
|
|
|
void* notifyData )
|
|
|
|
{
|
2003-05-28 11:37:29 +00:00
|
|
|
TRACES( "NPN_GetURLNotify", url );
|
2000-09-18 15:18:56 +00:00
|
|
|
XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
|
|
|
|
if( ! pImpl )
|
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
OString aLoadURL = normalizeURL( pImpl, url );
|
2003-04-17 14:13:58 +00:00
|
|
|
if( !aLoadURL.getLength() )
|
|
|
|
return NPERR_INVALID_URL;
|
|
|
|
|
2003-05-28 11:37:29 +00:00
|
|
|
AsynchronousGetURL* pAsync = new AsynchronousGetURL();
|
2000-09-18 15:18:56 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-05-28 11:37:29 +00:00
|
|
|
pAsync->aUrl = OStringToOUString( aLoadURL, pImpl->getTextEncoding() );
|
|
|
|
pAsync->aTarget = OStringToOUString( target, pImpl->getTextEncoding() );
|
|
|
|
pAsync->xListener = pListener;
|
|
|
|
pImpl->setLastGetUrl( aLoadURL );
|
|
|
|
Application::PostUserEvent( LINK( pAsync, AsynchronousGetURL, getURL ), pImpl );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2000-12-07 18:29:03 +00:00
|
|
|
if( pBytes && nBytes < (int)rangeList->length )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2003-05-28 11:37:29 +00:00
|
|
|
delete [] pBytes;
|
|
|
|
pBytes = NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
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 );
|
2004-03-17 09:13:54 +00:00
|
|
|
nNow = pPlugin->getPluginComm()->
|
2000-09-18 15:18:56 +00:00
|
|
|
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 );
|
|
|
|
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|