Javascript for nspluginviewer

Koos Vriezen koos.vriezen at xs4all.nl
Fri Nov 21 13:31:41 GMT 2003


On Fri, 21 Nov 2003, Koos Vriezen wrote:

> Hi,
>
> Supporting js plugin->khtml isn't that hard (see patch, makes
> javascript:history.back not needed anymore), but (like mentioned earlier)
> how to get the result back to the plugin puzzles me (see totally
> wrong _mybuf attempt).
> Eg. for a locale page myswf.html, I get
> javascript:window.location+"__flashplugin_unique__" and evalJavaScript
> returns file:/home/koos/public_html/myswf.html__flashplugin_unique__.
> Also tried it in NSPluginInstance::requestURL, so that its sync, but
> didn't work.

Ok, this one works. I had to make a new stream and put the js result in
there.

>
> Koos
>
-------------- next part --------------
Index: plugin_part.cpp
===================================================================
RCS file: /home/kde/kdebase/nsplugins/plugin_part.cpp,v
retrieving revision 1.51
diff -u -3 -p -r1.51 plugin_part.cpp
--- plugin_part.cpp	26 Sep 2003 19:38:36 -0000	1.51
+++ plugin_part.cpp	21 Nov 2003 13:28:28 -0000
@@ -67,7 +67,7 @@ QString PluginLiveConnectExtension::eval
     kdDebug(1432) << "PLUGIN:LiveConnect::evalJavaScript " << script << endl;
     ArgList args;
     QString jscode;
-    jscode.sprintf("this.__nsplugin=eval(\"%s\")", script.latin1());
+    jscode.sprintf("this.__nsplugin=eval(\"%s\")",  QString(script).replace('\\', "\\\\").replace('"', "\\\"").latin1());
     args.push_back(qMakePair(KParts::LiveConnectExtension::TypeString, jscode));
     emit partEvent(0, "eval", args);
     return __nsplugin;
@@ -316,11 +316,6 @@ void PluginPart::requestURL(const QStrin
     kdDebug(1432) << "PluginPart::requestURL( url=" << url
                   << ", target=" << target << endl;
 
-    if (url.startsWith("javascript:history.back")) {
-        _extension->browserInterface()->callMethod("goHistory(int)", -1);
-        return;
-    }
-
     KURL new_url(this->url(), url);
     KParts::URLArgs args;
     args.frameName = target;
Index: viewer/nsplugin.cpp
===================================================================
RCS file: /home/kde/kdebase/nsplugins/viewer/nsplugin.cpp,v
retrieving revision 1.103
diff -u -3 -p -r1.103 nsplugin.cpp
--- viewer/nsplugin.cpp	26 Sep 2003 19:38:38 -0000	1.103
+++ viewer/nsplugin.cpp	21 Nov 2003 13:28:29 -0000
@@ -710,11 +710,15 @@ void NSPluginInstance::timer()
                     QByteArray buf;
                     buf.setRawData( _baseURL.latin1(), _baseURL.length()+1 );
                     s->get( url, "text/html", buf, req.notify, true );
-                } else if (url.lower().startsWith("javascript:history.back")){
+                } else if (url.lower().startsWith("javascript:")){
                     if (_callback) {
-                        _callback->requestURL( url, req.target );
-                        if ( req.notify )
-                            NPURLNotify( req.url, NPRES_DONE, req.notify );
+                        QString result = _callback->evalJavaScript( url.mid(11) );
+                        NSPluginStream *s = new NSPluginStream( this );
+                        s->create( url, QString("text/plain"), req.notify );
+                        QCString bytes(result.latin1());
+                        s->process(bytes, 0);
+                        s->stop();
+                        delete s;
                     }
                 } else {
                     // create stream
@@ -1029,6 +1033,7 @@ int32 NSPluginInstance::NPWriteReady(NPS
 
 void NSPluginInstance::NPURLNotify(QString url, NPReason reason, void *notifyData)
 {
+   kdDebug(1431) << "NSPluginInstance::NPURLNotify " << url << " " << notifyData << " " << _pluginFuncs.urlnotify << endl;
    if (!_pluginFuncs.urlnotify)
       return;
 
Index: viewer/nsplugin.h
===================================================================
RCS file: /home/kde/kdebase/nsplugins/viewer/nsplugin.h,v
retrieving revision 1.38
diff -u -3 -p -r1.38 nsplugin.h
--- viewer/nsplugin.h	13 Jun 2003 00:00:00 -0000	1.38
+++ viewer/nsplugin.h	21 Nov 2003 13:28:29 -0000
@@ -63,7 +63,7 @@ class QTimer;
 class NSPluginStreamBase : public QObject
 {
 Q_OBJECT
-
+friend class NSPluginInstance;
 public:
   NSPluginStreamBase( class NSPluginInstance *instance );
   ~NSPluginStreamBase();


More information about the kfm-devel mailing list