1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: plugcon.cxx,v $
10 * $Revision: 1.8.90.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <plugin/unx/plugcon.hxx>
38 UINT32
PluginConnector::GetStreamID( NPStream
* pStream
)
40 size_t nLen
= m_aNPWrapStreams
.size();
41 for( size_t i
= 0; i
< nLen
; i
++ )
42 if( m_aNPWrapStreams
[ i
] == pStream
)
43 return static_cast<UINT32
>(i
);
44 medDebug( 1, "Error: NPStream has no ID\n" );
45 return UnknownStreamID
;
48 UINT32
PluginConnector::GetNPPID( NPP instance
)
50 size_t nLen
= m_aInstances
.size();
51 for( size_t i
=0; i
<nLen
; i
++ )
52 if( m_aInstances
[ i
]->instance
== instance
)
53 return static_cast<UINT32
>(i
);
54 medDebug( 1, "Error: NPP has no ID\n" );
59 ConnectorInstance
* PluginConnector::getInstance( NPP instance
)
61 size_t nLen
= m_aInstances
.size();
62 for( size_t i
=0; i
<nLen
; i
++ )
64 ConnectorInstance
* pInst
= m_aInstances
[i
];
65 if( pInst
->instance
== instance
)
71 ConnectorInstance
* PluginConnector::getInstanceById( UINT32 nInstanceID
)
73 return nInstanceID
< static_cast<UINT32
>(m_aInstances
.size()) ? m_aInstances
[ nInstanceID
] : NULL
;
81 PtrStruct( char* i_pData
, ULONG i_nBytes
)
82 : pData( i_pData
), nBytes( i_nBytes
) {}
85 ULONG
PluginConnector::FillBuffer( char*& rpBuffer
,
86 const char* pFunction
,
90 std::vector
< PtrStruct
> aList
;
93 ULONG nDataSize
= nFunctionLen
+ sizeof( ULONG
);
97 pNext
= va_arg( ap
, char* );
100 aList
.push_back( PtrStruct( pNext
, va_arg( ap
, ULONG
) ) );
101 nDataSize
+= aList
.back().nBytes
+ sizeof(ULONG
);
105 rpBuffer
= new char[ nDataSize
];
106 char* pRun
= rpBuffer
;
107 memcpy( pRun
, &nFunctionLen
, sizeof( nFunctionLen
) );
108 pRun
+= sizeof( nFunctionLen
);
109 memcpy( pRun
, pFunction
, nFunctionLen
);
110 pRun
+= nFunctionLen
;
112 for( std::vector
<PtrStruct
>::const_iterator it
= aList
.begin(); it
!= aList
.end(); ++it
)
114 memcpy( pRun
, &it
->nBytes
, sizeof( ULONG
) );
115 pRun
+= sizeof( ULONG
);
116 memcpy( pRun
, it
->pData
, it
->nBytes
);
122 MediatorMessage
* PluginConnector::Transact( const char* pFunction
,
123 ULONG nFunctionLen
, ... )
128 va_start( ap
, nFunctionLen
);
129 ULONG nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
131 return TransactMessage( nSize
, pBuffer
);
134 MediatorMessage
* PluginConnector::Transact( UINT32 nFunction
, ... )
139 va_start( ap
, nFunction
);
140 ULONG nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
142 return TransactMessage( nSize
, pBuffer
);
145 ULONG
PluginConnector::Send( UINT32 nFunction
, ... )
150 va_start( ap
, nFunction
);
151 ULONG nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
153 return SendMessage( nSize
, pBuffer
);
156 void PluginConnector::Respond( ULONG nID
,
158 ULONG nFunctionLen
, ... )
163 va_start( ap
, nFunctionLen
);
164 ULONG nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
166 SendMessage( nSize
, pBuffer
, nID
| ( 1 << 24 ) );
169 MediatorMessage
* PluginConnector::WaitForAnswer( ULONG nMessageID
)
174 nMessageID
&= 0x00ffffff;
178 NAMESPACE_VOS(OGuard
) aGuard( m_aQueueMutex
);
179 for( size_t i
= 0; i
< m_aMessageQueue
.size(); i
++ )
181 MediatorMessage
* pMessage
= m_aMessageQueue
[ i
];
182 ULONG nID
= pMessage
->m_nID
;
183 if( ( nID
& 0xff000000 ) &&
184 ( ( nID
& 0x00ffffff ) == nMessageID
) )
186 m_aMessageQueue
.erase( m_aMessageQueue
.begin() + i
);
191 if( ! m_aMessageQueue
.empty() )
193 WaitForMessage( 2000 );
198 ConnectorInstance::ConnectorInstance( NPP inst
, char* type
,
199 int args
, char* pargnbuf
, ULONG nargnbytes
,
200 char* pargvbuf
, ULONG nargvbytes
,
201 char* savedata
, ULONG savebytes
) :
208 bShouldUseXEmbed( false ),
210 pArgnBuf( pargnbuf
),
213 memset( &window
, 0, sizeof(window
) );
214 pMimeType
= new char[ strlen( type
) + 1 ];
215 strcpy( pMimeType
, type
);
216 aData
.len
= savebytes
;
217 aData
.buf
= savedata
;
218 argn
= new char*[ nArg
];
219 argv
= new char*[ nArg
];
221 char* pRun
= pArgnBuf
;
222 for( i
= 0; i
< nArg
; i
++ )
225 while( *pRun
!= 0 && (ULONG
)(pRun
- pArgnBuf
) < nargnbytes
)
227 if( (ULONG
)(pRun
- pArgnBuf
) < nargnbytes
)
231 for( i
= 0; i
< nArg
; i
++ )
234 while( *pRun
!= 0 && (ULONG
)(pRun
- pArgvBuf
) < nargvbytes
)
236 if( (ULONG
)(pRun
- pArgvBuf
) < nargvbytes
)
241 ConnectorInstance::~ConnectorInstance()
248 delete [] (char*)aData
.buf
;
251 const char* GetCommandName( CommandAtoms eCommand
)
255 case eNPN_GetURL
: return "NPN_GetURL";
256 case eNPN_GetURLNotify
: return "NPN_GetURLNotify";
257 case eNPN_DestroyStream
: return "NPN_DestroyStream";
258 case eNPN_NewStream
: return "NPN_NewStream";
259 case eNPN_PostURLNotify
: return "NPN_PostURLNotify";
260 case eNPN_PostURL
: return "NPN_PostURL";
261 case eNPN_RequestRead
: return "NPN_RequestRead";
262 case eNPN_Status
: return "NPN_Status";
263 case eNPN_Version
: return "NPN_Version";
264 case eNPN_Write
: return "NPN_Write";
265 case eNPN_UserAgent
: return "NPN_UserAgent";
267 case eNPP_DestroyStream
: return "NPP_DestroyStream";
268 case eNPP_Destroy
: return "NPP_Destroy";
269 case eNPP_DestroyPhase2
: return "NPP_DestroyPhase2";
270 case eNPP_NewStream
: return "NPP_NewStream";
271 case eNPP_New
: return "NPP_New";
272 case eNPP_SetWindow
: return "NPP_SetWindow";
273 case eNPP_StreamAsFile
: return "NPP_StreamAsFile";
274 case eNPP_URLNotify
: return "NPP_URLNotify";
275 case eNPP_WriteReady
: return "NPP_WriteReady";
276 case eNPP_Write
: return "NPP_Write";
277 case eNPP_GetMIMEDescription
: return "NPP_GetMIMEDescription";
278 case eNPP_Initialize
: return "NPP_Initialize";
279 case eNPP_Shutdown
: return "NPP_Shutdown";
281 case eMaxCommand
: return "eMaxCommand";
282 default: return "unknown command";