[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: nsplugins patch (KDE4)
From: Sergey Saukh <thelich () yandex ! ru>
Date: 2008-04-29 1:51:39
Message-ID: 200804290851.54068.thelich () yandex ! ru
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hello,
> > well... crash on exit problem is still not solved (nspluginviewer just
> > was silently exitting because of recursive calls in NSPluginInstance
> > destructor). Now when there is no recursive calls - it crashes again,
> > because of call to XtRemoveTimeOut from flashplayer library, when we call
> > _pluginFuncs.destroy in NSPluginInstance::destroy().
> >
> > A wierd solution to this - is to set UserAgent to "firefox" for
> > nspluginviewer. This can be done in konq settings.
>
> Really strange. I remeber some developer has written about such a behavior.
> This is of course not the solution; the user does not have to change that.
> Can we hardcode that in the code, so it will work all the time (of course
> only for the flashplugin)?
I've come to more wierd solution, while trying to hardcode UserAgent for
flashplugin. I don't know how to explain such behaviour, but I think this is
the way how flashplugin initializes itself.
When flashplugin executes "setWindow" (or "Initialize", I don't know for sure)
it calls NPN_UserAgent with NPP set to NULL. At this point I return an empty
string. Subsecuent calls to useragent are ok (NPP is set and function returns
string configured in browser, (default "... KHTML, blablabla", for exapmple).
This time crash-on-exit problem is totally gone...
Please, review the new patch and say what do you think about it.
--
Best regards,
Sergey A Saukh
["nsplugins.diff" (text/x-diff)]
diff -ubEr kdebase.orig/apps/nsplugins/CMakeLists.txt \
kdebase/apps/nsplugins/CMakeLists.txt
--- kdebase.orig/apps/nsplugins/CMakeLists.txt 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/CMakeLists.txt 2008-04-28 10:01:47.000000000 \
+0700 @@ -26,7 +26,7 @@
kde4_add_plugin(libnsplugin ${nsplugins_PART_SRCS})
- target_link_libraries(libnsplugin ${KDE4_KDE3SUPPORT_LIBS} \
${KDE4_KPARTS_LIBS} ${QT_QT3SUPPORT_LIBRARY} ${QT_QTGUI_LIBRARY} ) + \
target_link_libraries(libnsplugin ${KDE4_KPARTS_LIBS} ${QT_QTGUI_LIBRARY}) \
install(TARGETS libnsplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
@@ -38,7 +38,7 @@
kde4_add_plugin(kcminit_nsplugins WITH_PREFIX \
${kcminit_nsplugins_SRCS})
- target_link_libraries(kcminit_nsplugins ${KDE4_KDE3SUPPORT_LIBS} \
${KDE4_KDECORE_LIBS} ) + target_link_libraries(kcminit_nsplugins \
${KDE4_KDECORE_LIBS} )
install(TARGETS kcminit_nsplugins DESTINATION ${PLUGIN_INSTALL_DIR} )
@@ -68,7 +68,3 @@
message(STATUS "libXt not found - browser plugin support disabled")
endif (X11_Xt_LIB)
-
-
-
-
diff -ubEr kdebase.orig/apps/nsplugins/nspluginloader.cpp \
kdebase/apps/nsplugins/nspluginloader.cpp
--- kdebase.orig/apps/nsplugins/nspluginloader.cpp 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/nspluginloader.cpp 2008-04-28 10:01:47.000000000 \
+0700 @@ -32,7 +32,7 @@
#include <kapplication.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
@@ -174,11 +174,9 @@
NSPluginLoader::NSPluginLoader()
- : QObject(), _mapping(7, false), _viewer(0)
+ : QObject(), _mapping(), _viewer(0)
{
scanPlugins();
- _mapping.setAutoDelete( true );
- _filetype.setAutoDelete(true);
}
@@ -250,7 +248,7 @@
if (!mime.isEmpty())
{
// insert the mimetype -> plugin mapping
- _mapping.insert(mime, new QString(plugin));
+ _mapping.insert(mime, QString(plugin).toLower());
// insert the suffix -> mimetype mapping
QStringList::Iterator suffix;
@@ -266,8 +264,8 @@
stripped = stripped.right( stripped.length()-p );
// add filetype to list
- if ( !stripped.isEmpty() && !_filetype.find(stripped) )
- _filetype.insert( stripped, new QString(mime));
+ if ( !stripped.isEmpty() && !_filetype.contains(stripped) )
+ _filetype.insert( stripped, QString(mime));
}
}
}
@@ -276,23 +274,26 @@
QString NSPluginLoader::lookupMimeType(const QString &url)
{
- Q3DictIterator<QString> dit2(_filetype);
- while (dit2.current())
- {
- QString ext = QString(".")+dit2.currentKey();
- if (url.right(ext.length()) == ext)
- return *dit2.current();
- ++dit2;
+ QString result;
+ QHashIterator<QString, QString> dit2(_filetype);
+ while ( dit2.hasNext() ) {
+ dit2.next();
+ QString ext = QString(".")+dit2.key();
+ if (url.right(ext.length()) == ext) {
+ result = dit2.value();
+ break;
+ }
}
- return QString();
+
+ return result;
}
QString NSPluginLoader::lookup(const QString &mimeType)
{
QString plugin;
- if ( _mapping[mimeType] )
- plugin = *_mapping[mimeType];
+ if ( _mapping.contains(mimeType) )
+ plugin = _mapping.value(mimeType);
kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << \
plugin;
@@ -304,35 +305,32 @@
{
kDebug() << "NSPluginLoader::loadViewer";
- _process = new K3Process;
-
+ _process.clearProgram();
// get the dbus app id
int pid = (int)getpid();
QString tmp;
tmp.sprintf("org.kde.nspluginviewer-%d",pid);
_viewerDBusId =tmp.toLatin1();
- connect( _process, SIGNAL(processExited(K3Process*)),
- this, SLOT(processTerminated(K3Process*)) );
+ connect( &_process, SIGNAL(finished(int, QProcess::ExitStatus)),
+ this, SLOT(processTerminated(int , QProcess::ExitStatus)) );
// find the external viewer process
QString viewer = KGlobal::dirs()->findExe("nspluginviewer");
if (viewer.isEmpty())
{
kDebug() << "can't find nspluginviewer";
- delete _process;
return false;
}
- *_process << viewer;
+ _process << viewer;
- // tell the process it's parameters
- *_process << "-dbusservice";
- *_process << _viewerDBusId;
+ _process << "-dbusservice";
+ _process << _viewerDBusId;
// run the process
kDebug() << "Running nspluginviewer";
- _process->start();
+ _process.start();
// wait for the process to run
int cnt = 0;
@@ -352,14 +350,13 @@
#endif
{
kDebug() << "timeout";
- delete _process;
+ _process.kill();
return false;
}
- if (!_process->isRunning())
+ if (_process.state() == QProcess::NotRunning)
{
kDebug() << "nspluginviewer terminated";
- delete _process;
return false;
}
}
@@ -380,9 +377,8 @@
_viewer->shutdown();
kDebug() << "Shutdown viewer";
delete _viewer;
- delete _process;
+ _process.kill();
_viewer = 0;
- _process = 0;
}
kDebug() << "<- NSPluginLoader::unloadViewer";
@@ -391,16 +387,11 @@
-void NSPluginLoader::processTerminated(K3Process *proc)
+void NSPluginLoader::processTerminated(int exitCode, QProcess::ExitStatus \
exitStatus) {
- if ( _process == proc)
- {
kDebug() << "Viewer process terminated";
delete _viewer;
- delete _process;
_viewer = 0;
- _process = 0;
- }
}
diff -ubEr kdebase.orig/apps/nsplugins/nspluginloader.h \
kdebase/apps/nsplugins/nspluginloader.h
--- kdebase.orig/apps/nsplugins/nspluginloader.h 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/nspluginloader.h 2008-04-28 10:01:47.000000000 \
+0700 @@ -24,24 +24,20 @@
*/
-#ifndef __NS_PLUGINLOADER_H__
-#define __NS_PLUGINLOADER_H__
+#ifndef NS_PLUGINLOADER_H
+#define NS_PLUGINLOADER_H
-
-
-#include <Qt3Support/Q3Dict>
+#include <QHash>
#include <QObject>
#include <QWidget>
#include <QtGui/QX11EmbedContainer>
-//Added by qt3to4:
-#include <QGridLayout>
-#include <QResizeEvent>
+
#include <kdemacros.h>
+#include <kprocess.h>
#define EMBEDCLASS QX11EmbedContainer
class OrgKdeNspluginsViewerInterface;
-class K3Process;
class QPushButton;
class QGridLayout;
class OrgKdeNspluginsInstanceInterface;
@@ -104,13 +100,14 @@
void unloadViewer();
protected Q_SLOTS:
- void processTerminated( K3Process *proc );
+ void processTerminated( int exitCode, QProcess::ExitStatus exitStatus );
private:
QStringList _searchPaths;
- Q3Dict<QString> _mapping, _filetype;
+ QMultiHash<QString, QString> _mapping;
+ QHash<QString, QString> _filetype;
- K3Process *_process;
+ KProcess _process;
QString _viewerDBusId;
OrgKdeNspluginsViewerInterface *_viewer;
diff -ubEr kdebase.orig/apps/nsplugins/test/testnsplugin.cpp \
kdebase/apps/nsplugins/test/testnsplugin.cpp
--- kdebase.orig/apps/nsplugins/test/testnsplugin.cpp 2008-03-09 \
19:39:08.000000000 +0600
+++ kdebase/apps/nsplugins/test/testnsplugin.cpp 2008-04-28 \
10:01:47.000000000 +0700 @@ -24,8 +24,9 @@
#include <stdio.h>
+#include <QHBoxLayout>
+
#include <kactioncollection.h>
-//Added by qt3to4:
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kdebug.h>
@@ -107,7 +108,7 @@
QWidget *win = m_plugins.last();
if ( win )
{
- m_plugins.remove( win );
+ m_plugins.removeAll( win );
delete win;
} else
{
@@ -119,7 +120,7 @@
void TestNSPlugin::viewDestroyed( NSPluginInstance *inst )
{
kDebug() << "TestNSPlugin::viewDestroyed";
- m_plugins.remove( inst );
+ m_plugins.removeAll( inst );
}
diff -ubEr kdebase.orig/apps/nsplugins/test/testnsplugin.h \
kdebase/apps/nsplugins/test/testnsplugin.h
--- kdebase.orig/apps/nsplugins/test/testnsplugin.h 2008-03-09 \
19:39:08.000000000 +0600
+++ kdebase/apps/nsplugins/test/testnsplugin.h 2008-04-28 \
10:01:47.000000000 +0700 @@ -20,11 +20,10 @@
*/
-#ifndef __TESTNSPLUGIN_H__
-#define __TESTNSPLUGIN_H__
+#ifndef TESTNSPLUGIN_H
+#define TESTNSPLUGIN_H
#include <QWidget>
-#include <Q3PtrList>
#include <kxmlguiwindow.h>
#include <QList>
@@ -47,7 +46,7 @@
protected:
NSPluginLoader *m_loader;
- Q3PtrList<QWidget> m_plugins;
+ QList<QWidget *> m_plugins;
QWidget *m_client;
QBoxLayout *m_layout;
};
diff -ubEr kdebase.orig/apps/nsplugins/viewer/nsplugin.cpp \
kdebase/apps/nsplugins/viewer/nsplugin.cpp
--- kdebase.orig/apps/nsplugins/viewer/nsplugin.cpp 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/nsplugin.cpp 2008-04-28 \
16:09:37.000000000 +0700 @@ -37,7 +37,6 @@
#include <stdlib.h>
#include <unistd.h>
-#include <Qt3Support/Q3Dict>
#include <QDir>
#include <QFile>
#include <QTimer>
@@ -501,15 +500,20 @@
static QByteArray uaStore;
+static QByteArray uaEmpty;
// inquire user agent
-const char *g_NPN_UserAgent(NPP /*instance*/)
+const char *g_NPN_UserAgent(NPP instance)
{
+ if (!instance)
+ return uaEmpty.data();
+
if (uaStore.isEmpty()) {
KProtocolManager kpm;
QString agent = kpm.userAgentForHost("nspluginviewer");
uaStore = agent.toLatin1();
}
+
kDebug(1431) << "g_NPN_UserAgent() = " << uaStore;
return uaStore.data();
}
@@ -611,9 +615,6 @@
_npp->ndata = this;
_destroyed = false;
_handle = handle;
- _tempFiles.setAutoDelete( true );
- _streams.setAutoDelete( true );
- _waitingRequests.setAutoDelete( true );
_callback = new org::kde::nsplugins::CallBack( appId, callbackId, \
QDBusConnection::sessionBus() );
KUrl base(src);
@@ -653,23 +654,21 @@
kDebug(1431) << "<- ~NSPluginInstance";
}
-
void NSPluginInstance::destroy()
{
if ( !_destroyed ) {
kDebug(1431) << "delete streams";
- _waitingRequests.clear();
+ qDeleteAll( _waitingRequests );
- shutdown();
-
- for( NSPluginStreamBase *s=_streams.first(); s!=0; ) {
- NSPluginStreamBase *next = _streams.next();
+ while ( !_streams.isEmpty() ) {
+ NSPluginStreamBase *s = _streams.takeFirst();
s->stop();
- s = next;
+ delete s;
}
- _streams.clear();
+ kDebug(1431) << "delete tempfiles";
+ qDeleteAll( _tempFiles );
kDebug(1431) << "delete callbacks";
delete _callback;
@@ -728,10 +727,10 @@
// start queued requests
kDebug(1431) << "looking for waiting requests";
- while ( _waitingRequests.head() ) {
+ while ( !_waitingRequests.isEmpty() ) {
kDebug(1431) << "request found";
Request req( *_waitingRequests.head() );
- _waitingRequests.remove();
+ delete _waitingRequests.dequeue();
QString url;
@@ -880,9 +879,7 @@
{
kDebug(1431) << "-> NSPluginInstance::streamFinished";
emitStatus( QString() );
- _streams.setAutoDelete(false);
- _streams.remove(strm);
- _streams.setAutoDelete(true);
+ _streams.removeOne(strm);
strm->deleteLater();
_timer->setSingleShot( true );
_timer->start( 100 );
@@ -1219,7 +1216,6 @@
_libname = library;
_constructed = false;
_error = true;
- _instances.setAutoDelete( true );
_NP_GetMIMEDescription = 0;
_NP_Initialize = 0;
_NP_Shutdown = 0;
@@ -1274,8 +1270,9 @@
NSPluginClass::~NSPluginClass()
{
- _instances.clear();
- _trash.clear();
+ qDeleteAll( _instances );
+ qDeleteAll( _trash );
+
shutdown();
if (_handle)
_handle->unload();
@@ -1285,10 +1282,14 @@
void NSPluginClass::timer()
{
// delete instances
- for ( NSPluginInstance *it=_trash.first(); it!=0; it=_trash.next() )
- _instances.remove(it);
-
- _trash.clear();
+ while ( !_trash.isEmpty() ) {
+ NSPluginInstance *it = _trash.takeFirst();
+ int i = _instances.indexOf(it);
+ if ( i != -1 )
+ delete _instances.takeAt(i);
+ else // there should be no instansces in trash, which are not in \
_instances + delete it;
+ }
}
diff -ubEr kdebase.orig/apps/nsplugins/viewer/nsplugin.h \
kdebase/apps/nsplugins/viewer/nsplugin.h
--- kdebase.orig/apps/nsplugins/viewer/nsplugin.h 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/nsplugin.h 2008-04-28 15:47:39.000000000 \
+0700 @@ -28,12 +28,10 @@
#include <QObject>
-#include <Qt3Support/Q3PtrQueue>
#include <QMap>
-#include <Qt3Support/Q3IntDict>
#include <QPointer>
-//Added by qt3to4:
-#include <Q3PtrList>
+#include <QQueue>
+#include <QList>
#include <KDebug>
@@ -208,6 +206,7 @@
QString normalizedURL(const QString& url) const;
+
public Q_SLOTS:
void streamFinished( NSPluginStreamBase *strm );
@@ -221,9 +220,9 @@
bool _destroyed;
bool _embedded;
void addTempFile(KTemporaryFile *tmpFile);
- Q3PtrList<KTemporaryFile> _tempFiles;
+ QList<KTemporaryFile *> _tempFiles;
OrgKdeNspluginsCallBackInterface *_callback;
- Q3PtrList<NSPluginStreamBase> _streams;
+ QList<NSPluginStreamBase *> _streams;
KLibrary *_handle;
QTimer *_timer;
@@ -267,7 +266,7 @@
KParts::BrowserArguments browserArgs;
};
- Q3PtrQueue<Request> _waitingRequests;
+ QQueue<Request *> _waitingRequests;
QMap<int, Request*> _jsrequests;
};
@@ -307,8 +306,8 @@
NP_InitializeUPP *_NP_Initialize;
NP_ShutdownUPP *_NP_Shutdown;
- Q3PtrList<NSPluginInstance> _instances;
- Q3PtrList<NSPluginInstance> _trash;
+ QList<NSPluginInstance *> _instances;
+ QList<NSPluginInstance *> _trash;
QByteArray _app;
NPPluginFuncs _pluginFuncs;
diff -ubEr kdebase.orig/apps/nsplugins/viewer/pluginhost_xt.cpp \
kdebase/apps/nsplugins/viewer/pluginhost_xt.cpp
--- kdebase.orig/apps/nsplugins/viewer/pluginhost_xt.cpp 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/pluginhost_xt.cpp 2008-04-28 \
10:01:47.000000000 +0700 @@ -52,7 +52,8 @@
PluginHostXt::PluginHostXt(NSPluginInstance* plugin):
_plugin(plugin), _outside(0), _toplevel(0), _form(0)
-{}
+{
+}
void PluginHostXt::setupWindow(int winId, int width, int height)
diff -ubEr kdebase.orig/apps/nsplugins/viewer/qxteventloop.cpp \
kdebase/apps/nsplugins/viewer/qxteventloop.cpp
--- kdebase.orig/apps/nsplugins/viewer/qxteventloop.cpp 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/qxteventloop.cpp 2008-04-28 \
10:01:47.000000000 +0700 @@ -41,9 +41,8 @@
#include <kglobal.h>
#include <qwidgetintdict.h>
-//Added by qt3to4:
-#include <QEventLoop>
-#include <Q3MemArray>
+#include <QVector>
+#include <QHash>
// resolve the conflict between X11's FocusIn and QEvent::FocusIn
const int XFocusOut = FocusOut;
@@ -67,10 +66,10 @@
void unhook();
XtAppContext appContext, ownContext;
- Q3MemArray<XtEventDispatchProc> dispatchers;
+ QVector<XtEventDispatchProc> dispatchers;
QWidgetIntDict mapper;
- Q3IntDict<QSocketNotifier> socknotDict;
+ QHash<int, QSocketNotifier> socknotDict;
bool activate_timers;
XtIntervalId timerid;
@@ -354,7 +353,7 @@
void qmotif_socknot_handler( XtPointer pointer, int *, XtInputId *id )
{
QXtEventLoop *eventloop = (QXtEventLoop *) pointer;
- QSocketNotifier *socknot = static_d->socknotDict.find( *id );
+ QSocketNotifier *socknot = static_d->socknotDict.value( *id );
if ( ! socknot ) // this shouldn't happen
return;
eventloop->setSocketNotifierPending( socknot );
@@ -395,17 +394,16 @@
*/
void QXtEventLoop::unregisterSocketNotifier( QSocketNotifier *notifier )
{
- Q3IntDictIterator<QSocketNotifier> it( d->socknotDict );
- while ( it.current() && notifier != it.current() )
- ++it;
- if ( ! it.current() ) {
+
+ int key = d->socknotDict.key(notifier);
+ if ( ! key ) {
// this shouldn't happen
qWarning( "QXtEventLoopEventLoop: failed to unregister socket notifier" \
); return;
}
- XtRemoveInput( it.currentKey() );
- d->socknotDict.remove( it.currentKey() );
+ XtRemoveInput( key );
+ d->socknotDict.remove( key );
QEventLoop::unregisterSocketNotifier( notifier );
}
diff -ubEr kdebase.orig/apps/nsplugins/viewer/viewer.cpp \
kdebase/apps/nsplugins/viewer/viewer.cpp
--- kdebase.orig/apps/nsplugins/viewer/viewer.cpp 2008-03-09 \
19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/viewer.cpp 2008-04-28 10:01:47.000000000 \
+0700 @@ -35,10 +35,8 @@
#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
-#include <Qt3Support/Q3PtrList>
#include <QSocketNotifier>
-//Added by qt3to4:
-#include <QEvent>
+
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/time.h>
["signature.asc" (application/pgp-signature)]
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic