2 This is an encapsulation of the Netscape plugin API.
4 Copyright (c) 2000 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
5 Stefan Schimanski <1Stein@gmx.de>
6 2003-2005 George Staikos <staikos@kde.org>
7 2007, 2008 Maksim Orlovich <maksim@kde.org>
8 2006, 2007, 2008 Apple Inc.
10 2008 Sebastian Sauer <mail@dipe.org>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #ifndef __NS_PLUGIN_H__
28 #define __NS_PLUGIN_H__
39 #include <kparts/browserextension.h> // for OpenUrlArguments
41 #include <QDBusObjectPath>
43 #include <QX11EmbedWidget>
47 #include "sdk/npupp.h"
49 typedef char* NP_GetMIMEDescriptionUPP(void);
50 typedef NPError
NP_InitializeUPP(NPNetscapeFuncs
*, NPPluginFuncs
*);
51 typedef NPError
NP_ShutdownUPP(void);
53 #include <X11/Intrinsic.h>
58 class OrgKdeNspluginsCallBackInterface
;
63 class NSPluginStreamBase
: public QObject
66 friend class NSPluginInstance
;
68 NSPluginStreamBase( class NSPluginInstance
*instance
);
69 ~NSPluginStreamBase();
71 KUrl
url() { return _url
; }
72 int pos() { return _pos
; }
76 void finished( NSPluginStreamBase
*strm
);
79 void finish( bool err
);
81 bool error() { return _error
; }
82 void queue( const QByteArray
&data
);
83 bool create( const QString
& url
, const QString
& mimeType
, void *notify
, bool forceNotify
= false );
84 int tries() { return _tries
; }
86 void updateURL( const KUrl
& newUrl
);
88 class NSPluginInstance
*_instance
;
96 class KTemporaryFile
*_tempFile
;
99 int process( const QByteArray
&data
, int start
);
112 class NSPluginStream
: public NSPluginStreamBase
117 NSPluginStream( class NSPluginInstance
*instance
);
120 bool get(const QString
& url
, const QString
& mimeType
, void *notifyData
, bool reload
= false);
121 bool post(const QString
& url
, const QByteArray
& data
, const QString
& mimeType
, void *notifyData
,
122 const KParts::OpenUrlArguments
& args
,
123 const KParts::BrowserArguments
& browserArgs
);
126 void data(KIO::Job
*job
, const QByteArray
&data
);
127 void totalSize(KJob
*job
, qulonglong size
);
128 void mimetype(KIO::Job
* job
, const QString
&mimeType
);
129 void result(KJob
*job
);
130 void redirection(KIO::Job
*job
, const KUrl
& url
);
134 QPointer
<KIO::TransferJob
> _job
;
135 QTimer
*_resumeTimer
;
139 class NSPluginBufStream
: public NSPluginStreamBase
144 NSPluginBufStream( class NSPluginInstance
*instance
);
145 ~NSPluginBufStream();
147 bool get( const QString
& url
, const QString
& mimeType
, const QByteArray
&buf
, void *notifyData
, bool singleShot
=false );
159 class NSPluginInstance
: public QObject
165 // constructor, destructor
166 NSPluginInstance( NPP privateData
, NPPluginFuncs
*pluginFuncs
, KLibrary
*handle
,
167 const QString
&src
, const QString
&mime
,
168 const QString
&appId
, const QString
&callbackId
, bool embed
,
172 // DBus-exported functions
174 void setupWindow(int winId
, int w
, int h
);
175 void resizePlugin(int clientWinId
, int w
, int h
);
176 void javascriptResult(int id
, const QString
&result
);
180 // last via NSPluginClass::newInstance() produced NSPluginInstance instance.
181 static NSPluginInstance
* lastPluginInstance();
182 static void setLastPluginInstance(NSPluginInstance
*);
185 NPError
NPGetValue(NPPVariable variable
, void *value
);
186 NPError
NPSetValue(NPNVariable variable
, void *value
);
189 NPError
NPSetWindow(NPWindow
*window
);
192 NPError
NPDestroyStream(NPStream
*stream
, NPReason reason
);
193 NPError
NPNewStream(NPMIMEType type
, NPStream
*stream
, NPBool seekable
, uint16
*stype
);
194 void NPStreamAsFile(NPStream
*stream
, const char *fname
);
195 int32
NPWrite(NPStream
*stream
, int32 offset
, int32 len
, void *buf
);
196 int32
NPWriteReady(NPStream
*stream
);
199 void NPURLNotify(const QString
&url
, NPReason reason
, void *notifyData
);
202 uint16
HandleEvent(void *event
);
205 void emitStatus( const QString
&message
);
206 void requestURL( const QString
&url
, const QString
&mime
,
207 const QString
&target
, void *notify
, bool forceNotify
= false, bool reload
= false );
208 void postURL( const QString
&url
, const QByteArray
& data
, const QString
&mime
,
209 const QString
&target
, void *notify
, const KParts::OpenUrlArguments
& args
,
210 const KParts::BrowserArguments
& browserArgs
, bool forceNotify
= false );
212 QString
normalizedURL(const QString
& url
) const;
216 void streamFinished( NSPluginStreamBase
*strm
);
221 friend class NSPluginStreamBase
;
227 void addTempFile(KTemporaryFile
*tmpFile
);
228 QList
<KTemporaryFile
*> _tempFiles
;
229 OrgKdeNspluginsCallBackInterface
*_callback
;
230 QList
<NSPluginStreamBase
*> _streams
;
235 NPPluginFuncs _pluginFuncs
;
237 PluginHost
* _pluginHost
; // Manages embedding of the plugin into us
238 int _width
, _height
; // last size we used;
245 Request( const QString
&_url
, const QString
&_mime
,
246 const QString
&_target
, void *_notify
, bool _forceNotify
= false,
247 bool _reload
= false)
248 { url
=_url
; mime
=_mime
; target
=_target
; notify
=_notify
; post
=false; forceNotify
= _forceNotify
; reload
= _reload
; }
251 Request( const QString
&_url
, const QByteArray
& _data
,
252 const QString
&_mime
, const QString
&_target
, void *_notify
,
253 const KParts::OpenUrlArguments
& _args
,
254 const KParts::BrowserArguments
& _browserArgs
,
255 bool _forceNotify
= false)
257 url
=_url
; mime
=_mime
; target
=_target
;
258 notify
=_notify
; post
=true; data
=_data
; args
=_args
; browserArgs
=_browserArgs
;
259 forceNotify
= _forceNotify
;
270 KParts::OpenUrlArguments args
;
271 KParts::BrowserArguments browserArgs
;
274 QQueue
<Request
*> _waitingRequests
;
275 QMap
<int, Request
*> _jsrequests
;
277 static NSPluginInstance
* s_lastPluginInstance
;
281 class NSPluginClass
: public QObject
286 NSPluginClass( const QString
&library
, QObject
*parent
);
289 QString
getMIMEDescription();
290 QDBusObjectPath
newInstance(const QString
&url
, const QString
&mimeType
, bool embed
,
291 const QStringList
&argn
, const QStringList
&argv
,
292 const QString
&appId
, const QString
&callbackId
, bool reload
);
293 void destroyInstance( NSPluginInstance
* inst
);
294 bool error() { return _error
; }
296 void setApp(const QByteArray
& app
) { _app
= app
; }
297 const QByteArray
& app() const { return _app
; }
312 NP_GetMIMEDescriptionUPP
*_NP_GetMIMEDescription
;
313 NP_InitializeUPP
*_NP_Initialize
;
314 NP_ShutdownUPP
*_NP_Shutdown
;
316 QList
<NSPluginInstance
*> _instances
;
317 QList
<NSPluginInstance
*> _trash
;
320 NPPluginFuncs _pluginFuncs
;
321 NPNetscapeFuncs _nsFuncs
;
323 // If plugins use gtk, we call the gtk_init function for them ---
324 // but only do it once.
325 static bool s_initedGTK
;
329 class NSPluginViewer
: public QObject
333 NSPluginViewer( QObject
*parent
);
334 virtual ~NSPluginViewer();
337 QDBusObjectPath
newClass( const QString
& plugin
, const QString
& senderId
);
340 void appChanged( const QString
& id
, const QString
& oldOwner
, const QString
& newOwner
);
343 QMap
<QString
, NSPluginClass
*> _classes
;