From 2da742afd01cd96c02aa9f4c42c635ac7febe68b Mon Sep 17 00:00:00 2001 From: Maks Orlovich Date: Sat, 14 Mar 2009 20:00:06 +0000 Subject: [PATCH] Merged revision 939403: Block handling of normal I/O streams until javascript: queries are handled. Fixes the problem with opening of local flash files reported by KMess developers, and hopefully the ocassional white windows on web flash stuff as well CCBUG: 169626 svn path=/trunk/KDE/kdebase/apps/; revision=939405 --- nsplugins/viewer/nsplugin.cpp | 24 +++++++++++++++++++++--- nsplugins/viewer/nsplugin.h | 4 +++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/nsplugins/viewer/nsplugin.cpp b/nsplugins/viewer/nsplugin.cpp index 654acc591d..77289eff48 100644 --- a/nsplugins/viewer/nsplugin.cpp +++ b/nsplugins/viewer/nsplugin.cpp @@ -644,6 +644,7 @@ NSPluginInstance::NSPluginInstance(NPP privateData, NPPluginFuncs *pluginFuncs, _destroyed = false; _handle = handle; _callback = new org::kde::nsplugins::CallBack( appId, callbackId, QDBusConnection::sessionBus() ); + _numJSRequests = 0; KUrl base(src); base.setFileName( QString() ); @@ -742,6 +743,10 @@ void NSPluginInstance::shutdown() } } +bool NSPluginInstance::hasPendingJSRequests() const +{ + return _numJSRequests > 0; +} void NSPluginInstance::timer() { @@ -762,6 +767,8 @@ void NSPluginInstance::timer() QString url; + // Note: sync javascript: handling with requestURL + // make absolute url if ( req.url.left(11).toLower()=="javascript:" ) url = req.url; @@ -809,9 +816,10 @@ void NSPluginInstance::timer() } else if (url.toLower().startsWith("javascript:")){ if (_callback) { static int _jsrequestid = 0; - _jsrequests.insert(_jsrequestid, new Request(req)); + _jsrequests.insert(_jsrequestid, new Request(req)); _callback->evalJavaScript(_jsrequestid++, url.mid(11)); } else { + --_numJSRequests; kDebug() << "No callback for javascript: url!"; } } else { @@ -868,8 +876,12 @@ void NSPluginInstance::requestURL( const QString &url, const QString &mime, if (nurl.isNull()) { return; } + + // We dispatch JS events in target for empty target GET only.(see timer()); + if (target.isEmpty() && nurl.left(11).toLower()=="javascript:") + ++_numJSRequests; - kDebug(1431) << "NSPluginInstance::requestURL url=" << nurl << " target=" << target << " notify=" << notify; + kDebug(1431) << "NSPluginInstance::requestURL url=" << nurl << " target=" << target << " notify=" << notify << "JS jobs now:" << _numJSRequests; _waitingRequests.enqueue( new Request( nurl, mime, target, notify, forceNotify, reload ) ); _timer->setSingleShot( true ); _timer->start( 100 ); @@ -943,6 +955,8 @@ void NSPluginInstance::resizePlugin(int clientWinId, int w, int h) void NSPluginInstance::javascriptResult(int id, const QString &result) { QMap::iterator i = _jsrequests.find( id ); if (i != _jsrequests.end()) { + --_numJSRequests; + Request *req = i.value(); _jsrequests.erase( i ); NSPluginStream *s = new NSPluginStream( this ); @@ -952,7 +966,7 @@ void NSPluginInstance::javascriptResult(int id, const QString &result) { int len = result.length(); s->create( req->url, QString("text/plain"), req->notify, req->forceNotify ); - kDebug(1431) << "javascriptResult has been called with: "< 0) { QByteArray data(len + 1, 0); memcpy(data.data(), result.toLatin1(), len); @@ -1634,6 +1648,10 @@ bool NSPluginStreamBase::pump() inform(); + // Suspend until JS handled.. + if (_instance->hasPendingJSRequests()) + return false; + if ( _queuePos<_queue.size() ) { int newPos; diff --git a/nsplugins/viewer/nsplugin.h b/nsplugins/viewer/nsplugin.h index 8e523ca636..0989b92036 100644 --- a/nsplugins/viewer/nsplugin.h +++ b/nsplugins/viewer/nsplugin.h @@ -210,7 +210,8 @@ public: const KParts::BrowserArguments& browserArgs, bool forceNotify = false ); QString normalizedURL(const QString& url) const; - + + bool hasPendingJSRequests() const; public Q_SLOTS: void streamFinished( NSPluginStreamBase *strm ); @@ -273,6 +274,7 @@ private: QQueue _waitingRequests; QMap _jsrequests; + int _numJSRequests; // entered in earlier than _jsrequests. static NSPluginInstance* s_lastPluginInstance; };