Add V8 interceptor support (issue #1159)

This commit is contained in:
Marshall Greenblatt
2016-10-27 13:23:56 -04:00
parent 917b4a0de5
commit e006ec0ab5
17 changed files with 1454 additions and 37 deletions

View File

@@ -281,6 +281,74 @@ class CefV8Accessor : public virtual CefBase {
CefString& exception) =0;
};
///
// Interface that should be implemented to handle V8 interceptor calls. The
// methods of this class will be called on the thread associated with the V8
// interceptor. Interceptor's named property handlers (with first argument of
// type CefString) are called when object is indexed by string. Indexed property
// handlers (with first argument of type int) are called when object is indexed
// by integer.
///
/*--cef(source=client)--*/
class CefV8Interceptor : public virtual CefBase {
public:
///
// Handle retrieval of the interceptor value identified by |name|. |object| is
// the receiver ('this' object) of the interceptor. If retrieval succeeds, set
// |retval| to the return value. If the requested value does not exist, don't
// set either |retval| or |exception|. If retrieval fails, set |exception| to
// the exception that will be thrown. If the property has an associated
// accessor, it will be called only if you don't set |retval|.
// Return true if interceptor retrieval was handled, false otherwise.
///
/*--cef(capi_name=get_byname)--*/
virtual bool Get(const CefString& name,
const CefRefPtr<CefV8Value> object,
CefRefPtr<CefV8Value>& retval,
CefString& exception) =0;
///
// Handle retrieval of the interceptor value identified by |index|. |object|
// is the receiver ('this' object) of the interceptor. If retrieval succeeds,
// set |retval| to the return value. If the requested value does not exist,
// don't set either |retval| or |exception|. If retrieval fails, set
// |exception| to the exception that will be thrown.
// Return true if interceptor retrieval was handled, false otherwise.
///
/*--cef(capi_name=get_byindex,index_param=index)--*/
virtual bool Get(int index,
const CefRefPtr<CefV8Value> object,
CefRefPtr<CefV8Value>& retval,
CefString& exception) =0;
///
// Handle assignment of the interceptor value identified by |name|. |object|
// is the receiver ('this' object) of the interceptor. |value| is the new
// value being assigned to the interceptor. If assignment fails, set
// |exception| to the exception that will be thrown. This setter will always
// be called, even when the property has an associated accessor.
// Return true if interceptor assignment was handled, false otherwise.
///
/*--cef(capi_name=set_byname)--*/
virtual bool Set(const CefString& name,
const CefRefPtr<CefV8Value> object,
const CefRefPtr<CefV8Value> value,
CefString& exception) =0;
///
// Handle assignment of the interceptor value identified by |index|. |object|
// is the receiver ('this' object) of the interceptor. |value| is the new
// value being assigned to the interceptor. If assignment fails, set
// |exception| to the exception that will be thrown.
// Return true if interceptor assignment was handled, false otherwise.
///
/*--cef(capi_name=set_byindex,index_param=index)--*/
virtual bool Set(int index,
const CefRefPtr<CefV8Value> object,
const CefRefPtr<CefV8Value> value,
CefString& exception) =0;
};
///
// Class representing a V8 exception. The methods of this class may be called on
// any render process thread.
@@ -408,14 +476,16 @@ class CefV8Value : public virtual CefBase {
static CefRefPtr<CefV8Value> CreateString(const CefString& value);
///
// Create a new CefV8Value object of type object with optional accessor. This
// method should only be called from within the scope of a
// Create a new CefV8Value object of type object with optional accessor and/or
// interceptor. This method should only be called from within the scope of a
// CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in
// combination with calling Enter() and Exit() on a stored CefV8Context
// reference.
///
/*--cef(optional_param=accessor)--*/
static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefV8Accessor> accessor);
/*--cef(optional_param=accessor, optional_param=interceptor)--*/
static CefRefPtr<CefV8Value> CreateObject(
CefRefPtr<CefV8Accessor> accessor,
CefRefPtr<CefV8Interceptor> interceptor);
///
// Create a new CefV8Value object of type array with the specified |length|.