RFC --- new scripting extension sketches.

Maksim Orlovich mo85 at cornell.edu
Sun May 16 18:25:24 BST 2010


> 2010/5/12 Maksim Orlovich <mo85 at cornell.edu>:
>> <snip>
>> OK, I went ahead and committed a new version of this extension. I've
>> also
>> ported KHTML to it, and provided a backwards compatibility adapter that
>> bridges things that implement LiveConnectExtension to the new interface.
>
> Awesome work!
> Small nitpick is maybe a constructor for Object/FunctionRef that takes
> all members to make QVariant::setValue an one liner (be it a long
> line).

How would that be different from those that are currently there?

>> Thus far, nspluginviewer seems to work fine, as do the basic methods in
>> kmplayer -- unfortunately it doesn't want to launch knnplayer for me for
>> some reason.
>
> Odd, seem to work fine for me.

Well, I am probably doing something stupid setup-wise --- it seems to want
to use mplayer to play flash (on a swf, not a flv)

> I went ahead with a simple Play/Stop function support for any media.
> It works, but only because I don't need object live time tracking for
> this. The issue I see is when calling 'embedId.Play(), with this as
> debug output:
>
> rootObject
> acquire 0
> KMPlayerScriptableExtension::get 0 Play
> acquire 1
> release 0
> callAsFunction
> callMediaFunction
> release 1
>
> Now the call to 'rootObject' returns object with Id 0 and the 'get'
> for function 'Play', returns objId 1. Objects returned should have
> refCount set to 1

That's not how it's documented right now. Objects start with refcount of 0
--- I can certainly change that, if there is a huge reason to.

> to make it not initial unowned, since the callee
> can't deref the object after returning it.

Ahh. I see. So you want the callee to be able to consistently deref
arguments, so you don't end up with them leaking when it doesn't retain
them permanently? I guess I'll change stuff then when I get a chance.

Perhaps simply stating that you ref values you pass as arguments or
return, deref those that you get as parameters or return value, too?

Hmm, may be worth adding some sort of a helper, too.

e.g.
static void acquireObject(QVariant)/releaseObject(QVariant), that
call the appropriate virtual acquire/release on function/value types.


> At least that is my understanding of it. Here how I implemented the
> function that evaluates a script in the host browser:
>
>     KParts::ScriptableExtension* host = m_scriptableextension->host ();
>     if (host) {
>         QVariant embed = m_scriptableextension->enclosingObject ();
>         if (embed.canConvert <KParts::ScriptableExtension::Object> ()) {
>             quint64 id = embed.value
> <KParts::ScriptableExtension::Object> ().objId;
>             QVariant result = host->evaluateScript
> (m_scriptableextension, id, script);
>             host->release (id);
>             return result.toString ();
>         }
>     }
>     return "undefined";
>
> As you can see, I only released the enclosing object.

Regardless of that you may have to release the value you got, since
it may be an object, too.

Also, from the other mail:

> Shouldn't evaluateScript return a QString, ie the result of the
> evalutation? If I'm not mistaken, ns plugins really depend on the
> string outcome of js script evaluation.

Well, NPN_Evaluate is supposed to return typesafe values. Perhaps we
should add a toString function to the interface to permit both uses?

Thanks,
Maks






More information about the kfm-devel mailing list