can CefV8Value be inherited without build cef

Think CEF could benefit from a new feature or capability? Discuss CEF feature requests here.

can CefV8Value be inherited without build cef

Postby jx12nd » Wed Jan 12, 2011 3:18 am

i want to embed cef in my windows application, every thing is ok, but when i try to give the javascript the ability of manipulate COM object, i found it should to wrap IDispatch in the CefV8ValueImpl for reference count.

i didn't have a powerful machine to bulid all cef library with chrominume, is there has some way to inherit CefV8Value or CefV8ValueImpl without build cef?

thanks a lot.
jx12nd
Newbie
 
Posts: 3
Joined: Wed Jan 12, 2011 3:15 am

Re: can CefV8Value be inherited without build cef

Postby magreenblatt » Wed Jan 12, 2011 10:43 am

It is not possible to inherit CefV8Value or CefV8ValueImpl without rebuilding CEF. Nor should you need to -- instead, design a COM object that wraps the CefV8Value object. Create a CefV8Handler implementation that provides access to your COM object and wraps/unwraps the CefV8Value objects as appropriate. Your COM wrapper object can then manage the reference life span. This is similar to the approach used by the C / C++ translation layer.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: can CefV8Value be inherited without build cef

Postby jx12nd » Wed Jan 12, 2011 9:16 pm

thanks for you reply.

it seemed this is the only way to do this. a little bits of work will be done by javascript programmer.

when i check the CefV8Value interface design, it provide a method named GetUserData, and a static method CreateObject(CefRefPtr<CefBase> user_data)
it is helpful to attach a external object to CefV8Value, like other script embed language (python, lua, etc), this can be called LIGHT attach.
can the CreateObject(CefRefPtr<CefBase> user_data) is adjusted with CreateObject(CefRefPtr<CefBase> user_data, user_data_operator operator)
the user_data_operator is a function pointer type such as

typedef (user_data_operator*)(int op_type, CefRefPtr<CefBase> user_data);

the CefV8Value hold the function pointer, when the CefV8Value object to be deleted, it call the function pointer, then give the cef user a chance to control the user data. for the more, when CefV8Value is copied or deepcopied. wrap other close needed objects (db connection, file object, etc), this will be helpful.

thanks.
jx12nd
Newbie
 
Posts: 3
Joined: Wed Jan 12, 2011 3:15 am

Re: can CefV8Value be inherited without build cef

Postby magreenblatt » Wed Jan 12, 2011 10:02 pm

An approach more consistent with CEF would be changing |user_data| to an interface with the necessary event handler methods. That said, are there any additional events that you think are needed? Deletion of the CefV8Value will be at the whim of the V8 garbage collector so you're likely better off having the JS user explicitly close any resources by directly calling a JS method that you define for that purpose.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: can CefV8Value be inherited without build cef

Postby jx12nd » Thu Jan 13, 2011 12:29 am

thanks for reply.
use the user_data as a object is a good idea, since user_data is a CefBase, i think it adjust the RefCount of user_data is helpful.

for example
Code: Select all
   var a = new SomeObject();
   var b = a;

if it can AddRef of user_data when do a object copy, it will be fine for |a| |b| share some resource such as db connection or file handle. but when need a deepcopy, this will not enough, so
Code: Select all
class CefUserData : public CefBase
{
public:
    // CefBase methods
    virtual int AddRef() =0;
    virtual int Release() =0;
    virtual int GetRefCt() = 0;

    // CefUserData methods
    virtual CefRefPtr<CefBase> Clone(){
        if (this is a shared user data){
            this->AddRef();
            return this;
        }
        else{
            return new CefUserData(*this);
        }
    }

    virtual void Gc(){
    }
};

call |Clone| when do JS assignmetn, call |AddRef| when CefV8ValueImpl create and call |Release| when CefV8ValueImpl destory.
i'm not sure whether should has a Gc method, if the object should to delete itself when RefCount == 0, the Gc method can be move to the implement of Release.
i'm not sure whether has other events that fired by framework used control object life circle, if has this events, it will be helpful to add to CefUserData.

thanks.
jx12nd
Newbie
 
Posts: 3
Joined: Wed Jan 12, 2011 3:15 am

Re: can CefV8Value be inherited without build cef

Postby magreenblatt » Thu Jan 13, 2011 9:43 am

CefV8ValueImpl doesn't currently get notified of assignment. You'll have to explore V8 to figure out how to make that possible.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Feature Request Forum

Who is online

Users browsing this forum: No registered users and 45 guests