Patch: Using kpart's KJS::Interpreter (was Re: XML, XSL, XSLT, XPath support?)

Koos Vriezen koos.vriezen at xs4all.nl
Sat Apr 9 14:05:48 BST 2005


On Sat, Apr 09, 2005 at 12:43:28AM +0200, Koos Vriezen wrote:
> On Fri, Apr 08, 2005 at 07:12:26PM +0200, Koos Vriezen wrote:
> 
> > Lets wait if David/Harry think it's possible. I can already implement
> > it, because it can work w/ current liveconnect. Just check for a
> > liveconnect extension first and if that fails try the kjs global thingy
> > or vica versa.
> 
> Redraw that one, would mean every kjsbinding kpart would be given a way
> to have it accessed from unknown sources.
> Actually, knowing that it works with frames it's probably not so
> difficult, once having the interpreter there were EmbedLiveConnect is
> now.
> Probably better to use a signal if such a possibility would be made
> available by the part.

Indeed, works almost out of the box. Attached a patch that makes
KHTMLPart listen to 'useInterpreter( KJS::Interpreter* interp)' signals
from KJS::BrowserExtension. If there comes a tryGet request on an
embedded object, than first it checks if the kpart did emit such an
interp. If so, that one will be returned. Because non of excisting
kparts will emit such a signal yet, I've made KHTMLPart itself emit it
when the KJSProxy object is created. (unlike my first though, this is
also created for pages not having scripts).

Also three small html files to test this. With this patch, this will
output "No scripting".

dcop konqueror-6816 html-widget2 evalJS
""+document.applets[0].window.document.firstChild.lastChild.innerHTML

Comments?

Koos
-------------- next part --------------
Index: kparts/browserextension.h
===================================================================
RCS file: /home/kde/kdelibs/kparts/browserextension.h,v
retrieving revision 1.121
diff -u -3 -p -r1.121 browserextension.h
--- kparts/browserextension.h	3 Jan 2005 20:10:16 -0000	1.121
+++ kparts/browserextension.h	9 Apr 2005 12:51:34 -0000
@@ -36,6 +36,10 @@ class KFileItem;
 typedef QPtrList<KFileItem> KFileItemList;
 class QString;
 
+namespace KJS {
+    class Interpreter;
+}
+
 namespace KParts {
 
 class BrowserInterface;
@@ -657,6 +661,11 @@ signals:
    */
   void setPageSecurity( int );
 
+  /**
+   * Allow public script access through interpreter
+   */
+  void useInterpreter( KJS::Interpreter* interp);
+
 private slots:
   void slotCompleted();
   void slotOpenURLRequest( const KURL &url, const KParts::URLArgs &args );
Index: khtml/khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.1100
diff -u -3 -p -r1.1100 khtml_part.cpp
--- khtml/khtml_part.cpp	6 Apr 2005 15:40:14 -0000	1.1100
+++ khtml/khtml_part.cpp	9 Apr 2005 12:51:35 -0000
@@ -1010,9 +1010,11 @@ KJSProxy *KHTMLPart::jScript()
       if ( !d->m_frame )
         return 0;
   }
-  if ( !d->m_frame->m_jscript )
+  if ( !d->m_frame->m_jscript ) {
     if (!createJScript(d->m_frame))
       return 0;
+    emit d->m_extension->useInterpreter (d->m_frame->m_jscript->interpreter());
+  }
   if (d->m_bJScriptDebugEnabled)
     d->m_frame->m_jscript->setDebugEnabled(true);
 
@@ -4185,6 +4187,14 @@ KParts::LiveConnectExtension *KHTMLPart:
     return 0L;
 }
 
+KJS::Interpreter *KHTMLPart::partInterpreter( const khtml::RenderPart *frame) const {
+    const ConstFrameIt end = d->m_objects.end();
+    for(ConstFrameIt it = d->m_objects.begin(); it != end; ++it )
+        if ((*it)->m_frame == frame)
+            return (*it)->m_interp;
+    return 0L;
+}
+
 bool KHTMLPart::requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
                               const QStringList &params, bool isIFrame )
 {
@@ -4446,6 +4456,9 @@ bool KHTMLPart::processObjectRequest( kh
       connect( child->m_extension, SIGNAL( requestFocus( KParts::ReadOnlyPart * ) ),
                this, SLOT( slotRequestFocus( KParts::ReadOnlyPart * ) ) );
 
+      connect( child->m_extension, SIGNAL( useInterpreter( KJS::Interpreter* ) ),
+               this, SLOT (slotUsePartInterpreter( KJS::Interpreter* ) ) );
+
       child->m_extension->setBrowserInterface( d->m_extension->browserInterface() );
     }
   }
@@ -5026,6 +5039,12 @@ void KHTMLPart::slotRequestFocus( KParts
   emit d->m_extension->requestFocus(this);
 }
 
+void KHTMLPart::slotUsePartInterpreter( KJS::Interpreter* interp ) {
+    khtml::ChildFrame *childframe = frame( sender()->parent() );
+    if (childframe)
+        childframe->m_interp = interp;
+}
+
 khtml::ChildFrame *KHTMLPart::frame( const QObject *obj )
 {
     assert( obj->inherits( "KParts::ReadOnlyPart" ) );
Index: khtml/khtml_part.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.h,v
retrieving revision 1.283
diff -u -3 -p -r1.283 khtml_part.h
--- khtml/khtml_part.h	6 Apr 2005 15:31:38 -0000	1.283
+++ khtml/khtml_part.h	9 Apr 2005 12:51:35 -0000
@@ -296,6 +296,7 @@ public:
    */
   KParts::BrowserExtension *browserExtension() const;
   KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
+  KJS::Interpreter *partInterpreter( const khtml::RenderPart * ) const;
   KParts::BrowserHostExtension *browserHostExtension() const;
 
   /**
@@ -1407,6 +1408,7 @@ private slots:
    * @internal
    */
   void slotRequestFocus( KParts::ReadOnlyPart * );
+  void slotUsePartInterpreter( KJS::Interpreter* );
   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
   void checkCompleted();
Index: khtml/khtmlpart_p.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlpart_p.h,v
retrieving revision 1.63
diff -u -3 -p -r1.63 khtmlpart_p.h
--- khtml/khtmlpart_p.h	6 Apr 2005 15:40:14 -0000	1.63
+++ khtml/khtmlpart_p.h	9 Apr 2005 12:51:35 -0000
@@ -68,6 +68,11 @@ namespace KParts
   class StatusBarExtension;
 }
 
+namespace KJS
+{
+  class Interpreter;
+}
+
 namespace khtml
 {
   class ChildFrame : public QObject
@@ -79,6 +84,7 @@ namespace khtml
       ChildFrame() : QObject (0L, "khtml_child_frame") {
           m_jscript = 0L;
           m_kjs_lib = 0;
+          m_interp = 0L;
           m_bCompleted = false; m_bPreloaded = false; m_type = Frame; m_bNotify = false;
           m_bPendingRedirection = false;
       }
@@ -98,6 +104,7 @@ namespace khtml
     QString m_serviceType;
     KJSProxy *m_jscript;
     KLibrary *m_kjs_lib;
+    KJS::Interpreter *m_interp;
     bool m_bCompleted;
     QString m_name;
     KParts::URLArgs m_args;
Index: khtml/ecma/kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.281
diff -u -3 -p -r1.281 kjs_html.cpp
--- khtml/ecma/kjs_html.cpp	3 Apr 2005 16:24:14 -0000	1.281
+++ khtml/ecma/kjs_html.cpp	9 Apr 2005 12:51:36 -0000
@@ -1174,6 +1174,13 @@ Value KJS::HTMLElement::tryGet(ExecState
     case ID_APPLET:
     case ID_OBJECT:
     case ID_EMBED: {
+      DOM::HTMLDocument doc = element.ownerDocument();
+      KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
+      if (view && element.handle()) {
+        KJS::Interpreter *interp = view->part()->partInterpreter(static_cast<khtml::RenderPart*>(element.handle()->renderer()));
+        if (interp)
+          return interp->globalObject();
+      }
       KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
       QString rvalue;
       KParts::LiveConnectExtension::Type rtype;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20050409/496aa635/attachment.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20050409/496aa635/attachment-0001.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20050409/496aa635/attachment-0002.html>


More information about the kfm-devel mailing list