Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : ************************************************************************/
28 : #ifndef INCLUDED_EXTENSIONS_SOURCE_PLUGIN_INC_PLUGIN_UNX_PLUGCON_HXX
29 : #define INCLUDED_EXTENSIONS_SOURCE_PLUGIN_INC_PLUGIN_UNX_PLUGCON_HXX
30 :
31 : #include <stdarg.h>
32 : #include <string.h>
33 :
34 : #include <list>
35 : #include <vector>
36 : #include <plugin/unx/mediator.hxx>
37 :
38 : #include <prex.h>
39 :
40 : #include <X11/Xlib.h>
41 : extern "C" {
42 : #include <X11/Intrinsic.h>
43 : }
44 : #include <X11/Shell.h>
45 : #include <X11/IntrinsicP.h> /* Intrinsics Definitions*/
46 : #include <X11/StringDefs.h> /* Standard Name-String definitions*/
47 : #if defined USE_MOTIF
48 : #include <Xm/DrawingA.h>
49 : #else
50 : #include <X11/Composite.h>
51 : #endif
52 : #include <X11/Xatom.h>
53 : #ifndef XP_UNIX
54 : # define XP_UNIX
55 : #endif
56 : #define MOZ_X11
57 : #include <stdio.h>
58 : #ifdef SYSTEM_MOZILLA
59 : #ifndef OJI
60 : # define OJI
61 : #endif
62 : #define MOZ_X11
63 : #endif
64 :
65 : #if ! defined ( _NPAPI_H_) && ! defined (npapi_h_)
66 : extern "C" {
67 : #include <npsdk/npupp.h>
68 : }
69 : #include "npapi.h"
70 :
71 : #if NP_VERSION_MINOR < 17
72 : // compatibility hack: compile with older NPN api header, but define
73 : // some later introduced constants
74 : // for gcc 3
75 : #define NP_ABI_MASK 0x10000000
76 : #define NPNVSupportsXEmbedBool ((NPNVariable)14)
77 : #define NPPVpluginNeedsXEmbed ((NPPVariable)14)
78 : #define NPNVToolkit ((int)(13 | NP_ABI_MASK))
79 : #define NPNVGtk12 1
80 : #define NPNVGtk2 2
81 : #endif
82 : #endif
83 :
84 : #include <config_vclplug.h>
85 :
86 : #if ENABLE_GTK
87 : #define GLIB_DISABLE_DEPRECATION_WARNINGS
88 : #include <gtk/gtk.h>
89 : #include <gdk/gdkx.h>
90 : #else
91 : #define GtkWidget void
92 : #endif
93 :
94 : #include <postx.h>
95 :
96 : #include <tools/solar.h>
97 :
98 : class ConnectorInstance
99 : {
100 : public:
101 : NPP instance;
102 : NPWindow window;
103 : NPSetWindowCallbackStruct ws_info;
104 : char* pMimeType;
105 : void* pShell;
106 : void* pWidget;
107 : void* pForm;
108 :
109 : GtkWidget* pGtkWindow;
110 : GtkWidget* pGtkWidget;
111 :
112 : bool bShouldUseXEmbed;
113 :
114 : int nArg;
115 : char** argn;
116 : char** argv;
117 : char* pArgnBuf;
118 : char* pArgvBuf;
119 : NPSavedData aData;
120 :
121 : ConnectorInstance( NPP inst, char* type,
122 : int args, char* pargnbuf, sal_uLong nargnbytes,
123 : char* pargvbuf, sal_uLong nargvbytes,
124 : char* savedata, sal_uLong savebytes );
125 : ~ConnectorInstance();
126 : };
127 :
128 : class PluginConnector : public Mediator
129 : {
130 : protected:
131 : osl::Mutex m_aUserEventMutex;
132 :
133 : static std::vector<PluginConnector*> allConnectors;
134 :
135 : DECL_LINK( NewMessageHdl, Mediator* );
136 : DECL_LINK( WorkOnNewMessageHdl, Mediator* );
137 :
138 : std::vector<NPStream*> m_aNPWrapStreams;
139 : std::vector<ConnectorInstance*> m_aInstances;
140 :
141 : static sal_uLong FillBuffer( char*&, const char*, sal_uLong, va_list );
142 : public:
143 : PluginConnector( int nSocket );
144 : virtual ~PluginConnector();
145 :
146 : virtual MediatorMessage* WaitForAnswer( sal_uLong nMessageID ) SAL_OVERRIDE;
147 : MediatorMessage* Transact( const char*, sal_uLong, ... );
148 : MediatorMessage* Transact( sal_uInt32, ... );
149 : void Respond( sal_uLong nID, char*, sal_uLong, ... );
150 : sal_uLong Send( sal_uInt32, ... );
151 :
152 : static const sal_uInt32 UnknownStreamID = 0xffffffff;
153 : static const sal_uInt32 UnknownNPPID = 0xffffffff;
154 :
155 : sal_uInt32 GetStreamID( NPStream* pStream );
156 : sal_uInt32 GetNPPID( NPP );
157 :
158 0 : std::vector<NPStream*>& getStreamList() { return m_aNPWrapStreams; }
159 :
160 0 : static NPError GetNPError( MediatorMessage* pMes )
161 : {
162 0 : NPError* pErr = static_cast<NPError*>(pMes->GetBytes());
163 0 : NPError aErr = *pErr;
164 0 : delete [] pErr;
165 0 : return aErr;
166 : }
167 :
168 0 : void CallWorkHandler()
169 : {
170 : LINK( this, PluginConnector, WorkOnNewMessageHdl ).
171 0 : Call( static_cast<Mediator*>(this) );
172 0 : }
173 : };
174 :
175 : enum CommandAtoms
176 : {
177 : eNPN_GetURL,
178 : eNPN_GetURLNotify,
179 : eNPN_DestroyStream,
180 : eNPN_NewStream,
181 : eNPN_PostURLNotify,
182 : eNPN_PostURL,
183 : eNPN_RequestRead,
184 : eNPN_Status,
185 : eNPN_Version,
186 : eNPN_Write,
187 : eNPN_UserAgent,
188 :
189 : eNPP_DestroyStream,
190 : eNPP_Destroy,
191 : eNPP_DestroyPhase2,
192 : eNPP_NewStream,
193 : eNPP_New,
194 : eNPP_SetWindow,
195 : eNPP_StreamAsFile,
196 : eNPP_URLNotify,
197 : eNPP_WriteReady,
198 : eNPP_Write,
199 : eNPP_GetMIMEDescription,
200 : eNPP_Initialize,
201 : eNPP_Shutdown,
202 :
203 : eMaxCommand
204 : };
205 :
206 : const char* GetCommandName( CommandAtoms );
207 :
208 : #define POST_NONCONST_STRING( x ) x ? x : const_cast<char*>(""), x ? strlen(x) : 1
209 : #define POST_STRING( x ) x ? x : "", x ? strlen(x) : 1
210 :
211 : #endif // INCLUDED_EXTENSIONS_SOURCE_PLUGIN_INC_PLUGIN_UNX_PLUGCON_HXX
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|