Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / nsplugins / viewer / nsplugin.h
blob5bf959851cc8d98364cd77e86874d4e1fe814835
1 /*
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__
29 #include <QObject>
31 #include <Qt3Support/Q3PtrQueue>
32 #include <QMap>
33 #include <Qt3Support/Q3IntDict>
34 #include <QPointer>
35 //Added by qt3to4:
36 #include <Q3PtrList>
38 #include <KDebug>
40 #include <kparts/browserextension.h> // for OpenUrlArguments
41 #include <kio/job.h>
42 #include <QDBusObjectPath>
44 #include <QX11EmbedWidget>
46 #define XP_UNIX
47 #define MOZ_X11
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>
55 #include <fixx11h.h>
57 void quitXt();
59 class OrgKdeNspluginsCallBackInterface;
60 class KLibrary;
61 class QTimer;
64 class NSPluginStreamBase : public QObject
66 Q_OBJECT
67 friend class NSPluginInstance;
68 public:
69 NSPluginStreamBase( class NSPluginInstance *instance );
70 ~NSPluginStreamBase();
72 KUrl url() { return _url; }
73 int pos() { return _pos; }
74 void stop();
76 Q_SIGNALS:
77 void finished( NSPluginStreamBase *strm );
79 protected:
80 void finish( bool err );
81 bool pump();
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; }
86 void inform( );
87 void updateURL( const KUrl& newUrl );
89 class NSPluginInstance *_instance;
90 uint16 _streamType;
91 NPStream *_stream;
92 void *_notifyData;
93 KUrl _url;
94 QString _fileURL;
95 QString _mimeType;
96 QByteArray _data;
97 class KTemporaryFile *_tempFile;
99 private:
100 int process( const QByteArray &data, int start );
102 unsigned int _pos;
103 QByteArray _queue;
104 int _queuePos;
105 int _tries;
106 bool _onlyAsFile;
107 bool _error;
108 bool _informed;
109 bool _forceNotify;
113 class NSPluginStream : public NSPluginStreamBase
115 Q_OBJECT
117 public:
118 NSPluginStream( class NSPluginInstance *instance );
119 ~NSPluginStream();
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);
126 protected Q_SLOTS:
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);
132 void resume();
134 protected:
135 QPointer<KIO::TransferJob> _job;
136 QTimer *_resumeTimer;
140 class NSPluginBufStream : public NSPluginStreamBase
142 Q_OBJECT
144 public:
145 NSPluginBufStream( class NSPluginInstance *instance );
146 ~NSPluginBufStream();
148 bool get( const QString& url, const QString& mimeType, const QByteArray &buf, void *notifyData, bool singleShot=false );
150 protected Q_SLOTS:
151 void timer();
153 protected:
154 QTimer *_timer;
155 bool _singleShot;
158 class PluginHost;
160 class NSPluginInstance : public QObject
162 Q_OBJECT
164 public:
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,
170 QObject *parent );
171 ~NSPluginInstance();
173 // DBus-exported functions
174 void shutdown();
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);
178 void gotFocusIn();
179 void gotFocusOut();
181 // value handling
182 NPError NPGetValue(NPPVariable variable, void *value);
183 NPError NPSetValue(NPNVariable variable, void *value);
185 // window handling
186 NPError NPSetWindow(NPWindow *window);
188 // stream functions
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);
195 // URL functions
196 void NPURLNotify(const QString &url, NPReason reason, void *notifyData);
198 // Event handling
199 uint16 HandleEvent(void *event);
201 // signal emitters
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;
211 public Q_SLOTS:
212 void streamFinished( NSPluginStreamBase *strm );
214 void timer();
216 private:
217 friend class NSPluginStreamBase;
219 void destroy();
221 bool _destroyed;
222 bool _embedded;
223 void addTempFile(KTemporaryFile *tmpFile);
224 Q3PtrList<KTemporaryFile> _tempFiles;
225 OrgKdeNspluginsCallBackInterface *_callback;
226 Q3PtrList<NSPluginStreamBase> _streams;
227 KLibrary *_handle;
228 QTimer *_timer;
230 NPP _npp;
231 NPPluginFuncs _pluginFuncs;
233 PluginHost* _pluginHost; // Manages embedding of the plugin into us
234 int _width, _height; // last size we used;
236 QString _baseURL;
238 struct Request
240 // A GET request
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; }
246 // A POST request
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;
258 QString url;
259 QString mime;
260 QString target;
261 QByteArray data;
262 bool post;
263 bool forceNotify;
264 bool reload;
265 void *notify;
266 KParts::OpenUrlArguments args;
267 KParts::BrowserArguments browserArgs;
270 Q3PtrQueue<Request> _waitingRequests;
271 QMap<int, Request*> _jsrequests;
275 class NSPluginClass : public QObject
277 Q_OBJECT
278 public:
280 NSPluginClass( const QString &library, QObject *parent );
281 ~NSPluginClass();
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; }
293 protected Q_SLOTS:
294 void timer();
296 private:
297 int initialize();
298 void shutdown();
300 KLibrary *_handle;
301 QString _libname;
302 bool _constructed;
303 bool _error;
304 QTimer *_timer;
306 NP_GetMIMEDescriptionUPP *_NP_GetMIMEDescription;
307 NP_InitializeUPP *_NP_Initialize;
308 NP_ShutdownUPP *_NP_Shutdown;
310 Q3PtrList<NSPluginInstance> _instances;
311 Q3PtrList<NSPluginInstance> _trash;
313 QByteArray _app;
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
325 Q_OBJECT
326 public:
327 NSPluginViewer( QObject *parent );
328 virtual ~NSPluginViewer();
330 void shutdown();
331 QDBusObjectPath newClass( const QString& plugin, const QString& senderId );
333 private Q_SLOTS:
334 void appUnregistered(const QString& id);
336 private:
337 QMap<QString, NSPluginClass *> _classes;
341 #endif