Patch: Using kpart's KJS::Interpreter (was Re: XML, XSL, XSLT, XPath support?)
Koos Vriezen
koos.vriezen at xs4all.nl
Mon Apr 11 22:27:32 BST 2005
On Sun, Apr 10, 2005 at 11:33:29PM +0200, Koos Vriezen wrote:
> There are two issues I want to point at, and one is the
> interp->globalObject is returned in ecma's tryGet. This means one extra
> redirection, myembed.window.document vs. myembed.document, not sure what
> would be preferable. Obviously, how it is now, needs hardly any code and
> w/o it would mean to return a 'get' call on this object and likewise for
> 'put' and 'call'.
Ok, thought about it a bit more and it really makes sense to call 'get'
on the interpreter's global object and so for 'put'. This means it would
become (so w/o the 'window' redirection):
document.applets[0].document.firstChild.lastChild.innerHTML
This means that this is exactly how it is with frames. Maybe one
might be able to merge some of it, but no intension atm.
For 'call' it doesn't make really sense, only if a part has one function
as global object. Likewise for 'toString', one want still see the
'[object HTMLObjectElement]' and not the attached object I think.
So this is a more powerful liveconnect than we have now, like member
iterations, cross document possibilities etc.
Shall I just commit this (see attachment)?
> 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 11 Apr 2005 21:14:25 -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 11 Apr 2005 21:14:26 -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 ¶ms, 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 11 Apr 2005 21:14:26 -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 11 Apr 2005 21:14:26 -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 11 Apr 2005 21:14:26 -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().get(exec, propertyName);
+ }
KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
QString rvalue;
KParts::LiveConnectExtension::Type rtype;
@@ -2340,6 +2347,13 @@ void KJS::HTMLElement::tryPut(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().put(exec, propertyName, value);
+ }
KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
if (lc && lc->put(0, propertyName.qstring(), value.toString(exec).qstring()))
return;
More information about the kfm-devel
mailing list