1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include <plugin/unx/plugcon.hxx>
35 sal_uInt32
PluginConnector::GetStreamID( NPStream
* pStream
)
37 size_t nLen
= m_aNPWrapStreams
.size();
38 for( size_t i
= 0; i
< nLen
; i
++ )
39 if( m_aNPWrapStreams
[ i
] == pStream
)
40 return static_cast<sal_uInt32
>(i
);
41 medDebug( 1, "Error: NPStream has no ID\n" );
42 return UnknownStreamID
;
45 sal_uInt32
PluginConnector::GetNPPID( NPP instance
)
47 size_t nLen
= m_aInstances
.size();
48 for( size_t i
=0; i
<nLen
; i
++ )
49 if( m_aInstances
[ i
]->instance
== instance
)
50 return static_cast<sal_uInt32
>(i
);
51 medDebug( 1, "Error: NPP has no ID\n" );
56 ConnectorInstance
* PluginConnector::getInstance( NPP instance
)
58 size_t nLen
= m_aInstances
.size();
59 for( size_t i
=0; i
<nLen
; i
++ )
61 ConnectorInstance
* pInst
= m_aInstances
[i
];
62 if( pInst
->instance
== instance
)
68 ConnectorInstance
* PluginConnector::getInstanceById( sal_uInt32 nInstanceID
)
70 return nInstanceID
< static_cast<sal_uInt32
>(m_aInstances
.size()) ? m_aInstances
[ nInstanceID
] : NULL
;
78 PtrStruct( char* i_pData
, sal_uLong i_nBytes
)
79 : pData( i_pData
), nBytes( i_nBytes
) {}
82 sal_uLong
PluginConnector::FillBuffer( char*& rpBuffer
,
83 const char* pFunction
,
84 sal_uLong nFunctionLen
,
87 std::vector
< PtrStruct
> aList
;
90 sal_uLong nDataSize
= nFunctionLen
+ sizeof( sal_uLong
);
94 pNext
= va_arg( ap
, char* );
97 aList
.push_back( PtrStruct( pNext
, va_arg( ap
, sal_uLong
) ) );
98 nDataSize
+= aList
.back().nBytes
+ sizeof(sal_uLong
);
102 rpBuffer
= new char[ nDataSize
];
103 char* pRun
= rpBuffer
;
104 memcpy( pRun
, &nFunctionLen
, sizeof( nFunctionLen
) );
105 pRun
+= sizeof( nFunctionLen
);
106 memcpy( pRun
, pFunction
, nFunctionLen
);
107 pRun
+= nFunctionLen
;
109 for( std::vector
<PtrStruct
>::const_iterator it
= aList
.begin(); it
!= aList
.end(); ++it
)
111 memcpy( pRun
, &it
->nBytes
, sizeof( sal_uLong
) );
112 pRun
+= sizeof( sal_uLong
);
113 memcpy( pRun
, it
->pData
, it
->nBytes
);
119 MediatorMessage
* PluginConnector::Transact( const char* pFunction
,
120 sal_uLong nFunctionLen
, ... )
125 va_start( ap
, nFunctionLen
);
126 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
128 return TransactMessage( nSize
, pBuffer
);
131 MediatorMessage
* PluginConnector::Transact( sal_uInt32 nFunction
, ... )
136 va_start( ap
, nFunction
);
137 sal_uLong nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
139 return TransactMessage( nSize
, pBuffer
);
142 sal_uLong
PluginConnector::Send( sal_uInt32 nFunction
, ... )
147 va_start( ap
, nFunction
);
148 sal_uLong nSize
= FillBuffer( pBuffer
, (char*)&nFunction
, sizeof( nFunction
), ap
);
150 return SendMessage( nSize
, pBuffer
);
153 void PluginConnector::Respond( sal_uLong nID
,
155 sal_uLong nFunctionLen
, ... )
160 va_start( ap
, nFunctionLen
);
161 sal_uLong nSize
= FillBuffer( pBuffer
, pFunction
, nFunctionLen
, ap
);
163 SendMessage( nSize
, pBuffer
, nID
| ( 1 << 24 ) );
166 MediatorMessage
* PluginConnector::WaitForAnswer( sal_uLong nMessageID
)
171 nMessageID
&= 0x00ffffff;
175 vos::OGuard
aGuard( m_aQueueMutex
);
176 for( size_t i
= 0; i
< m_aMessageQueue
.size(); i
++ )
178 MediatorMessage
* pMessage
= m_aMessageQueue
[ i
];
179 sal_uLong nID
= pMessage
->m_nID
;
180 if( ( nID
& 0xff000000 ) &&
181 ( ( nID
& 0x00ffffff ) == nMessageID
) )
183 m_aMessageQueue
.erase( m_aMessageQueue
.begin() + i
);
188 if( ! m_aMessageQueue
.empty() )
190 WaitForMessage( 2000 );
195 ConnectorInstance::ConnectorInstance( NPP inst
, char* type
,
196 int args
, char* pargnbuf
, sal_uLong nargnbytes
,
197 char* pargvbuf
, sal_uLong nargvbytes
,
198 char* savedata
, sal_uLong savebytes
) :
205 bShouldUseXEmbed( false ),
207 pArgnBuf( pargnbuf
),
210 memset( &window
, 0, sizeof(window
) );
211 pMimeType
= new char[ strlen( type
) + 1 ];
212 strcpy( pMimeType
, type
);
213 aData
.len
= savebytes
;
214 aData
.buf
= savedata
;
215 argn
= new char*[ nArg
];
216 argv
= new char*[ nArg
];
218 char* pRun
= pArgnBuf
;
219 for( i
= 0; i
< nArg
; i
++ )
222 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
224 if( (sal_uLong
)(pRun
- pArgnBuf
) < nargnbytes
)
228 for( i
= 0; i
< nArg
; i
++ )
231 while( *pRun
!= 0 && (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
233 if( (sal_uLong
)(pRun
- pArgvBuf
) < nargvbytes
)
238 ConnectorInstance::~ConnectorInstance()
245 delete [] (char*)aData
.buf
;
248 const char* GetCommandName( CommandAtoms eCommand
)
252 case eNPN_GetURL
: return "NPN_GetURL";
253 case eNPN_GetURLNotify
: return "NPN_GetURLNotify";
254 case eNPN_DestroyStream
: return "NPN_DestroyStream";
255 case eNPN_NewStream
: return "NPN_NewStream";
256 case eNPN_PostURLNotify
: return "NPN_PostURLNotify";
257 case eNPN_PostURL
: return "NPN_PostURL";
258 case eNPN_RequestRead
: return "NPN_RequestRead";
259 case eNPN_Status
: return "NPN_Status";
260 case eNPN_Version
: return "NPN_Version";
261 case eNPN_Write
: return "NPN_Write";
262 case eNPN_UserAgent
: return "NPN_UserAgent";
264 case eNPP_DestroyStream
: return "NPP_DestroyStream";
265 case eNPP_Destroy
: return "NPP_Destroy";
266 case eNPP_DestroyPhase2
: return "NPP_DestroyPhase2";
267 case eNPP_NewStream
: return "NPP_NewStream";
268 case eNPP_New
: return "NPP_New";
269 case eNPP_SetWindow
: return "NPP_SetWindow";
270 case eNPP_StreamAsFile
: return "NPP_StreamAsFile";
271 case eNPP_URLNotify
: return "NPP_URLNotify";
272 case eNPP_WriteReady
: return "NPP_WriteReady";
273 case eNPP_Write
: return "NPP_Write";
274 case eNPP_GetMIMEDescription
: return "NPP_GetMIMEDescription";
275 case eNPP_Initialize
: return "NPP_Initialize";
276 case eNPP_Shutdown
: return "NPP_Shutdown";
278 case eMaxCommand
: return "eMaxCommand";
279 default: return "unknown command";