Liveconnect bug
Koos Vriezen
koos.vriezen at xs4all.nl
Fri Aug 6 22:43:25 BST 2004
On Fri, Aug 06, 2004 at 08:08:27PM +0200, Koos Vriezen wrote:
> On Fri, Aug 06, 2004 at 01:36:17PM -0400, George Staikos wrote:
> > On Friday 06 August 2004 12:56, you wrote:
> > > Ok, you're were talking only about the stand-alone nspluginviewer then.
> > > BR81401 might indeed be a similar case. Have you thought about making
> > > - QPtrList<NSPluginStreamBase> _streams;
> > > + QValueList<QGuardedPtr<NSPluginStreamBase> > _streams;
> > > or did some debug on construction/destructing these NSPluginStreamBase
> > > objects?
> > > Which liveconnect pointer are you talking about (on what file:line is it
> > > NULL)?
> >
> > The pointer inside KHTMLPart that points to the liveconnect object.
> > m_liveconnect or something like that, IIRC. The request goes across the wire
> > to KHTML, KHTML tries to evaluate but can't because m_liveconnect=0, returns
> > an empty string, and that gets sent back to the plugin which causes it to
> > blow up. The streams are all fine I think, though I'm sure your patch is a
> > good idea too.
>
> (Sorry to mess up the Cc:, forwarded my last one to kfm-devel)
>
> That's not possible, in HTMLObjectBaseElementImpl::liveConnectEvent
> html/html_objectimpl.cpp:154, if liveconnect pointer is 0L no script is
> executed. Another reason for no return value is when a script error occur.
Hmm, not if khtml has to determine the mimetype first which happens
here. I have a fix for this by searching the liveconnect pointer in
KHTMLPart::processObjectRequest (and not in
RenderPartObject::updateWidget) and now it works. However I don't see
any differences with that "Undefined" return and with a 'valid' one. So
I would suggest to go for the nsplugin patch for 3.3 and this new one
for 3.3 too or for 3.3.1. What do you think?
> My patch does solve such a case, btw, by making the return initially to
> "Undefined", which indeed I did see when running that George/Kelly site.
> Note: The patch should have '_retval = 0L;' see newly created patch.
> It could very well be the case that the plugin deletes itself with that
> script. W/o the patch there are certainly corruption, but I didn't see this
> case here though.
> As soon as a plugin gets attached, its liveconnect child should be found. Only
> in case a plugin is framed by an iframe (and not an object/embed), the
> liveconnect is not found. (I only found out about these case recently, see
> 'What if a html page uses a iframe for images?' thread).
> As soon as the plugin detaches, its liveconnect is set to 0L again.
>
> Koos
> Index: plugin_part.cpp
> ===================================================================
> RCS file: /home/kde/kdebase/nsplugins/plugin_part.cpp,v
> retrieving revision 1.56
> diff -u -3 -p -r1.56 plugin_part.cpp
> --- plugin_part.cpp 28 Jul 2004 19:55:03 -0000 1.56
> +++ plugin_part.cpp 6 Aug 2004 17:52:51 -0000
> @@ -29,7 +29,7 @@ public:
>
>
> PluginLiveConnectExtension::PluginLiveConnectExtension(PluginPart* part)
> -: KParts::LiveConnectExtension(part), _part(part) {
> +: KParts::LiveConnectExtension(part), _part(part), _retval(0L) {
> }
>
> PluginLiveConnectExtension::~PluginLiveConnectExtension() {
> @@ -53,8 +53,8 @@ Q_UNUSED(value);
>
> bool PluginLiveConnectExtension::put( const unsigned long, const QString &field, const QString &value) {
> kdDebug(1432) << "PLUGIN:LiveConnect::put " << field << " " << value << endl;
> - if (field == "__nsplugin") {
> - __nsplugin = value;
> + if (_retval && field == "__nsplugin") {
> + *_retval = value;
> return true;
> } else if (field.lower() == "src") {
> _part->changeSrc(value);
> @@ -71,8 +71,11 @@ QString PluginLiveConnectExtension::eval
> jscode.sprintf("this.__nsplugin=eval(\"%s\")", QString(script).replace('\\', "\\\\").replace('"', "\\\"").latin1());
> //kdDebug(1432) << "String is [" << jscode << "]" << endl;
> args.push_back(qMakePair(KParts::LiveConnectExtension::TypeString, jscode));
> + QString nsplugin("Undefined");
> + _retval = &nsplugin;
> emit partEvent(0, "eval", args);
> - return __nsplugin;
> + _retval = 0L;
> + return nsplugin;
> }
>
> extern "C"
> @@ -179,7 +182,8 @@ KAboutData *PluginFactory::aboutData()
>
> PluginPart::PluginPart(QWidget *parentWidget, const char *widgetName, QObject *parent,
> const char *name, const QStringList &args)
> - : KParts::ReadOnlyPart(parent, name), _widget(0), _args(args)
> + : KParts::ReadOnlyPart(parent, name), _widget(0), _args(args),
> + _destructed(0L)
> {
> setInstance(PluginFactory::instance());
> kdDebug(1432) << "PluginPart::PluginPart" << endl;
> @@ -217,6 +221,8 @@ PluginPart::~PluginPart()
>
> delete _callback;
> _loader->release();
> + if (_destructed)
> + *_destructed = true;;
> }
>
>
> @@ -338,10 +344,17 @@ void PluginPart::evalJavaScript(int id,
> {
> kdDebug(1432) <<"evalJavascript: before widget check"<<endl;
> if (_widget) {
> + bool destructed = false;
> + _destructed = &destructed;
> kdDebug(1432) <<"evalJavascript: there is a widget" <<endl;
> QString rc = _liveconnect->evalJavaScript(script);
> + if (destructed)
> + return;
> + _destructed = 0L;
> kdDebug(1432) << "Liveconnect: script [" << script << "] evaluated to [" << rc << "]" << endl;
> - static_cast<NSPluginInstance*>((QWidget*)_widget)->javascriptResult(id, rc);
> + NSPluginInstance *ni = dynamic_cast<NSPluginInstance*>(_widget.operator->());
> + if (ni)
> + ni->javascriptResult(id, rc);
> }
> }
>
> Index: plugin_part.h
> ===================================================================
> RCS file: /home/kde/kdebase/nsplugins/plugin_part.h,v
> retrieving revision 1.27
> diff -u -3 -p -r1.27 plugin_part.h
> --- plugin_part.h 27 Jan 2004 04:08:17 -0000 1.27
> +++ plugin_part.h 6 Aug 2004 17:52:51 -0000
> @@ -108,6 +108,7 @@ private:
> NSPluginCallback *_callback;
> QStringList _args;
> class NSPluginLoader *_loader;
> + bool *_destructed;
> };
>
>
> @@ -127,8 +128,8 @@ signals:
> virtual void partEvent( const unsigned long objid, const QString & event, const KParts::LiveConnectExtension::ArgList & args );
>
> private:
> - QString __nsplugin;
> PluginPart *_part;
> + QString *_retval;
> };
>
>
-------------- next part --------------
Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.1015
diff -u -3 -p -r1.1015 khtml_part.cpp
--- khtml_part.cpp 4 Aug 2004 14:25:48 -0000 1.1015
+++ khtml_part.cpp 6 Aug 2004 21:33:18 -0000
@@ -37,6 +37,7 @@
#include "html/html_baseimpl.h"
#include "html/html_miscimpl.h"
#include "html/html_imageimpl.h"
+#include "html/html_objectimpl.h"
#include "rendering/render_text.h"
#include "rendering/render_frames.h"
#include "rendering/render_layer.h"
@@ -3926,6 +3927,18 @@ bool KHTMLPart::processObjectRequest( kh
checkEmitLoadEvent();
return false;
+ } else if (child->m_frame) {
+ child->m_liveconnect = KParts::LiveConnectExtension::childObject(part);
+ DOM::NodeImpl* elm = child->m_frame->element();
+ if (elm)
+ switch (child->m_frame->element()->id()) {
+ case ID_APPLET:
+ case ID_EMBED:
+ case ID_OBJECT:
+ static_cast<HTMLObjectBaseElementImpl*>(elm)->setLiveConnect(child->m_liveconnect);
+ default:
+ break;
+ }
}
//CRITICAL STUFF
@@ -4003,7 +4016,6 @@ bool KHTMLPart::processObjectRequest( kh
child->m_extension->setBrowserInterface( d->m_extension->browserInterface() );
}
- child->m_liveconnect = KParts::LiveConnectExtension::childObject( part );
}
else if ( child->m_frame && child->m_part &&
child->m_frame->widget() != child->m_part->widget() )
Index: rendering/render_frames.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_frames.cpp,v
retrieving revision 1.183
diff -u -3 -p -r1.183 render_frames.cpp
--- rendering/render_frames.cpp 2 Aug 2004 17:50:12 -0000 1.183
+++ rendering/render_frames.cpp 6 Aug 2004 21:33:18 -0000
@@ -715,8 +715,6 @@ void RenderPartObject::updateWidget()
}
if ((url.isEmpty() && !embed) || !document()->isURLAllowed(url) || !part->requestObject( this, url, serviceType, params ))
objbase->renderAlternative();
- else
- objbase->setLiveConnect(part->liveConnectExtension(this));
}
}
More information about the kfm-devel
mailing list