3 This is an encapsulation of the Netscape plugin API.
5 Copyright (c) 2000 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
6 Stefan Schimanski <1Stein@gmx.de>
7 Copyright (c) 2003-2005 George Staikos <staikos@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef __NS_PLUGIN_H__
27 #define __NS_PLUGIN_H__
31 #include <Qt3Support/Q3PtrQueue>
33 #include <Qt3Support/Q3IntDict>
40 #include <kparts/browserextension.h> // for OpenUrlArguments
42 #include <QDBusObjectPath>
44 #include <QX11EmbedWidget>
48 #include "sdk/npupp.h"
50 typedef char* NP_GetMIMEDescriptionUPP(void);
51 typedef NPError
NP_InitializeUPP(NPNetscapeFuncs
*, NPPluginFuncs
*);
52 typedef NPError
NP_ShutdownUPP(void);
54 #include <X11/Intrinsic.h>
59 class OrgKdeNspluginsCallBackInterface
;
64 class NSPluginStreamBase
: public QObject
67 friend class NSPluginInstance
;
69 NSPluginStreamBase( class NSPluginInstance
*instance
);
70 ~NSPluginStreamBase();
72 KUrl
url() { return _url
; }
73 int pos() { return _pos
; }
77 void finished( NSPluginStreamBase
*strm
);
80 void finish( bool err
);
82 bool error() { return _error
; }
83 void queue( const QByteArray
&data
);
84 bool create( const QString
& url
, const QString
& mimeType
, void *notify
, bool forceNotify
= false );
85 int tries() { return _tries
; }
87 void updateURL( const KUrl
& newUrl
);
89 class NSPluginInstance
*_instance
;
97 class KTemporaryFile
*_tempFile
;
100 int process( const QByteArray
&data
, int start
);
113 class NSPluginStream
: public NSPluginStreamBase
118 NSPluginStream( class NSPluginInstance
*instance
);
121 bool get(const QString
& url
, const QString
& mimeType
, void *notifyData
, bool reload
= false);
122 bool post(const QString
& url
, const QByteArray
& data
, const QString
& mimeType
, void *notifyData
,
123 const KParts::OpenUrlArguments
& args
,
124 const KParts::BrowserArguments
& browserArgs
);
127 void data(KIO::Job
*job
, const QByteArray
&data
);
128 void totalSize(KJob
*job
, qulonglong size
);
129 void mimetype(KIO::Job
* job
, const QString
&mimeType
);
130 void result(KJob
*job
);
131 void redirection(KIO::Job
*job
, const KUrl
& url
);
135 QPointer
<KIO::TransferJob
> _job
;
136 QTimer
*_resumeTimer
;
140 class NSPluginBufStream
: public NSPluginStreamBase
145 NSPluginBufStream( class NSPluginInstance
*instance
);
146 ~NSPluginBufStream();
148 bool get( const QString
& url
, const QString
& mimeType
, const QByteArray
&buf
, void *notifyData
, bool singleShot
=false );
160 class NSPluginInstance
: public QObject
166 // constructor, destructor
167 NSPluginInstance( NPP privateData
, NPPluginFuncs
*pluginFuncs
, KLibrary
*handle
,
168 const QString
&src
, const QString
&mime
,
169 const QString
&appId
, const QString
&callbackId
, bool embed
,
173 // DBus-exported functions
175 void setupWindow(int winId
, int w
, int h
);
176 void resizePlugin(int clientWinId
, int w
, int h
);
177 void javascriptResult(int id
, const QString
&result
);
182 NPError
NPGetValue(NPPVariable variable
, void *value
);
183 NPError
NPSetValue(NPNVariable variable
, void *value
);
186 NPError
NPSetWindow(NPWindow
*window
);
189 NPError
NPDestroyStream(NPStream
*stream
, NPReason reason
);
190 NPError
NPNewStream(NPMIMEType type
, NPStream
*stream
, NPBool seekable
, uint16
*stype
);
191 void NPStreamAsFile(NPStream
*stream
, const char *fname
);
192 int32
NPWrite(NPStream
*stream
, int32 offset
, int32 len
, void *buf
);
193 int32
NPWriteReady(NPStream
*stream
);
196 void NPURLNotify(const QString
&url
, NPReason reason
, void *notifyData
);
199 uint16
HandleEvent(void *event
);
202 void emitStatus( const QString
&message
);
203 void requestURL( const QString
&url
, const QString
&mime
,
204 const QString
&target
, void *notify
, bool forceNotify
= false, bool reload
= false );
205 void postURL( const QString
&url
, const QByteArray
& data
, const QString
&mime
,
206 const QString
&target
, void *notify
, const KParts::OpenUrlArguments
& args
,
207 const KParts::BrowserArguments
& browserArgs
, bool forceNotify
= false );
209 QString
normalizedURL(const QString
& url
) const;
212 void streamFinished( NSPluginStreamBase
*strm
);
217 friend class NSPluginStreamBase
;
223 void addTempFile(KTemporaryFile
*tmpFile
);
224 Q3PtrList
<KTemporaryFile
> _tempFiles
;
225 OrgKdeNspluginsCallBackInterface
*_callback
;
226 Q3PtrList
<NSPluginStreamBase
> _streams
;
231 NPPluginFuncs _pluginFuncs
;
233 PluginHost
* _pluginHost
; // Manages embedding of the plugin into us
234 int _width
, _height
; // last size we used;
241 Request( const QString
&_url
, const QString
&_mime
,
242 const QString
&_target
, void *_notify
, bool _forceNotify
= false,
243 bool _reload
= false)
244 { url
=_url
; mime
=_mime
; target
=_target
; notify
=_notify
; post
=false; forceNotify
= _forceNotify
; reload
= _reload
; }
247 Request( const QString
&_url
, const QByteArray
& _data
,
248 const QString
&_mime
, const QString
&_target
, void *_notify
,
249 const KParts::OpenUrlArguments
& _args
,
250 const KParts::BrowserArguments
& _browserArgs
,
251 bool _forceNotify
= false)
253 url
=_url
; mime
=_mime
; target
=_target
;
254 notify
=_notify
; post
=true; data
=_data
; args
=_args
; browserArgs
=_browserArgs
;
255 forceNotify
= _forceNotify
;
266 KParts::OpenUrlArguments args
;
267 KParts::BrowserArguments browserArgs
;
270 Q3PtrQueue
<Request
> _waitingRequests
;
271 QMap
<int, Request
*> _jsrequests
;
275 class NSPluginClass
: public QObject
280 NSPluginClass( const QString
&library
, QObject
*parent
);
283 QString
getMIMEDescription();
284 QDBusObjectPath
newInstance(const QString
&url
, const QString
&mimeType
, bool embed
,
285 const QStringList
&argn
, const QStringList
&argv
,
286 const QString
&appId
, const QString
&callbackId
, bool reload
);
287 void destroyInstance( NSPluginInstance
* inst
);
288 bool error() { return _error
; }
290 void setApp(const QByteArray
& app
) { _app
= app
; }
291 const QByteArray
& app() const { return _app
; }
306 NP_GetMIMEDescriptionUPP
*_NP_GetMIMEDescription
;
307 NP_InitializeUPP
*_NP_Initialize
;
308 NP_ShutdownUPP
*_NP_Shutdown
;
310 Q3PtrList
<NSPluginInstance
> _instances
;
311 Q3PtrList
<NSPluginInstance
> _trash
;
314 NPPluginFuncs _pluginFuncs
;
315 NPNetscapeFuncs _nsFuncs
;
317 // If plugins use gtk, we call the gtk_init function for them ---
318 // but only do it once.
319 static bool s_initedGTK
;
323 class NSPluginViewer
: public QObject
327 NSPluginViewer( QObject
*parent
);
328 virtual ~NSPluginViewer();
331 QDBusObjectPath
newClass( const QString
& plugin
, const QString
& senderId
);
334 void appUnregistered(const QString
& id
);
337 QMap
<QString
, NSPluginClass
*> _classes
;