mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add support for entering a V8 context asynchronously (issue #203).
- Add support for V8 accessors (issue #203). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@215 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
4
cef.gyp
4
cef.gyp
@ -359,6 +359,8 @@
|
|||||||
'libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h',
|
'libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/task_ctocpp.cc',
|
'libcef_dll/ctocpp/task_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/task_ctocpp.h',
|
'libcef_dll/ctocpp/task_ctocpp.h',
|
||||||
|
'libcef_dll/ctocpp/v8accessor_ctocpp.cc',
|
||||||
|
'libcef_dll/ctocpp/v8accessor_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/v8handler_ctocpp.cc',
|
'libcef_dll/ctocpp/v8handler_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/v8handler_ctocpp.h',
|
'libcef_dll/ctocpp/v8handler_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc',
|
'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc',
|
||||||
@ -430,6 +432,8 @@
|
|||||||
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h',
|
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/task_cpptoc.cc',
|
'libcef_dll/cpptoc/task_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/task_cpptoc.h',
|
'libcef_dll/cpptoc/task_cpptoc.h',
|
||||||
|
'libcef_dll/cpptoc/v8accessor_cpptoc.cc',
|
||||||
|
'libcef_dll/cpptoc/v8accessor_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/v8handler_cpptoc.cc',
|
'libcef_dll/cpptoc/v8handler_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/v8handler_cpptoc.h',
|
'libcef_dll/cpptoc/v8handler_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc',
|
'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc',
|
||||||
|
@ -1390,6 +1390,19 @@ public:
|
|||||||
// Returns the global object for this context.
|
// Returns the global object for this context.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual CefRefPtr<CefV8Value> GetGlobal() =0;
|
virtual CefRefPtr<CefV8Value> GetGlobal() =0;
|
||||||
|
|
||||||
|
// Enter this context. A context must be explicitly entered before creating a
|
||||||
|
// V8 Object, Array or Function asynchronously. Exit() must be called the same
|
||||||
|
// number of times as Enter() before releasing this context. V8 objects belong
|
||||||
|
// to the context in which they are created. Returns true if the scope was
|
||||||
|
// entered successfully.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool Enter() =0;
|
||||||
|
|
||||||
|
// Exit this context. Call this method only after calling Enter(). Returns
|
||||||
|
// true if the scope was exited successfully.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool Exit() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1413,6 +1426,31 @@ public:
|
|||||||
CefString& exception) =0;
|
CefString& exception) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Interface that should be implemented to handle V8 accessor calls. Accessor
|
||||||
|
// identifiers are registered by calling CefV8Value::SetValue(). The methods
|
||||||
|
// of this class will always be called on the UI thread.
|
||||||
|
/*--cef(source=client)--*/
|
||||||
|
class CefV8Accessor : public CefBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Called to get an accessor value. |name| is the name of the property being
|
||||||
|
// accessed. |object| is the This() object from V8's AccessorInfo structure.
|
||||||
|
// |retval| is the value to return for this property. Return true if handled.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool Get(const CefString& name,
|
||||||
|
const CefRefPtr<CefV8Value> object,
|
||||||
|
CefRefPtr<CefV8Value>& retval) =0;
|
||||||
|
|
||||||
|
// Called to set an accessor value. |name| is the name of the property being
|
||||||
|
// accessed. |value| is the new value being assigned to this property.
|
||||||
|
// |object| is the This() object from V8's AccessorInfo structure. Return true
|
||||||
|
// if handled.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool Set(const CefString& name,
|
||||||
|
const CefRefPtr<CefV8Value> object,
|
||||||
|
const CefRefPtr<CefV8Value> value) =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Class representing a V8 value. The methods of this class should only be
|
// Class representing a V8 value. The methods of this class should only be
|
||||||
// called on the UI thread.
|
// called on the UI thread.
|
||||||
@ -1420,6 +1458,9 @@ public:
|
|||||||
class CefV8Value : public CefBase
|
class CefV8Value : public CefBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef cef_v8_accesscontrol_t AccessControl;
|
||||||
|
typedef cef_v8_propertyattribute_t PropertyAttribute;
|
||||||
|
|
||||||
// Create a new CefV8Value object of the specified type.
|
// Create a new CefV8Value object of the specified type.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
static CefRefPtr<CefV8Value> CreateUndefined();
|
static CefRefPtr<CefV8Value> CreateUndefined();
|
||||||
@ -1435,6 +1476,9 @@ public:
|
|||||||
static CefRefPtr<CefV8Value> CreateString(const CefString& value);
|
static CefRefPtr<CefV8Value> CreateString(const CefString& value);
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefBase> user_data);
|
static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefBase> user_data);
|
||||||
|
/*--cef(capi_name=cef_v8value_create_object_with_accessor)--*/
|
||||||
|
static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefBase> user_data,
|
||||||
|
CefRefPtr<CefV8Accessor> accessor);
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
static CefRefPtr<CefV8Value> CreateArray();
|
static CefRefPtr<CefV8Value> CreateArray();
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
@ -1460,6 +1504,11 @@ public:
|
|||||||
virtual bool IsArray() =0;
|
virtual bool IsArray() =0;
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual bool IsFunction() =0;
|
virtual bool IsFunction() =0;
|
||||||
|
|
||||||
|
// Returns true if this object is pointing to the same handle as |that|
|
||||||
|
// object.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool IsSame(CefRefPtr<CefV8Value> that) =0;
|
||||||
|
|
||||||
// Return a primitive value type. The underlying data will be converted to
|
// Return a primitive value type. The underlying data will be converted to
|
||||||
// the requested type if necessary.
|
// the requested type if necessary.
|
||||||
@ -1496,12 +1545,18 @@ public:
|
|||||||
/*--cef(capi_name=get_value_byindex)--*/
|
/*--cef(capi_name=get_value_byindex)--*/
|
||||||
virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
|
virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
|
||||||
|
|
||||||
// Associate value with the specified identifier.
|
// Associate a value with the specified identifier.
|
||||||
/*--cef(capi_name=set_value_bykey)--*/
|
/*--cef(capi_name=set_value_bykey)--*/
|
||||||
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value) =0;
|
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value) =0;
|
||||||
/*--cef(capi_name=set_value_byindex)--*/
|
/*--cef(capi_name=set_value_byindex)--*/
|
||||||
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
|
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
|
||||||
|
|
||||||
|
// Register an identifier whose access will be forwarded to the CefV8Accessor
|
||||||
|
// instance passed to CefV8Value::CreateObject().
|
||||||
|
/*--cef(capi_name=set_value_byaccessor)--*/
|
||||||
|
virtual bool SetValue(const CefString& key, AccessControl settings,
|
||||||
|
PropertyAttribute attribute) =0;
|
||||||
|
|
||||||
// Read the keys for the object's values into the specified vector. Integer-
|
// Read the keys for the object's values into the specified vector. Integer-
|
||||||
// based keys will also be returned as strings.
|
// based keys will also be returned as strings.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
|
@ -1124,6 +1124,17 @@ typedef struct _cef_v8context_t
|
|||||||
struct _cef_v8value_t* (CEF_CALLBACK *get_global)(
|
struct _cef_v8value_t* (CEF_CALLBACK *get_global)(
|
||||||
struct _cef_v8context_t* self);
|
struct _cef_v8context_t* self);
|
||||||
|
|
||||||
|
// Enter this context. A context must be explicitly entered before creating a
|
||||||
|
// V8 Object, Array or Function asynchronously. exit() must be called the same
|
||||||
|
// number of times as enter() before releasing this context. V8 objects belong
|
||||||
|
// to the context in which they are created. Returns true (1) if the scope was
|
||||||
|
// entered successfully.
|
||||||
|
int (CEF_CALLBACK *enter)(struct _cef_v8context_t* self);
|
||||||
|
|
||||||
|
// Exit this context. Call this function only after calling enter(). Returns
|
||||||
|
// true (1) if the scope was exited successfully.
|
||||||
|
int (CEF_CALLBACK *exit)(struct _cef_v8context_t* self);
|
||||||
|
|
||||||
} cef_v8context_t;
|
} cef_v8context_t;
|
||||||
|
|
||||||
|
|
||||||
@ -1153,6 +1164,33 @@ typedef struct _cef_v8handler_t
|
|||||||
} cef_v8handler_t;
|
} cef_v8handler_t;
|
||||||
|
|
||||||
|
|
||||||
|
// Structure that should be implemented to handle V8 accessor calls. Accessor
|
||||||
|
// identifiers are registered by calling cef_v8value_t::set_value(). The
|
||||||
|
// functions of this structure will always be called on the UI thread.
|
||||||
|
typedef struct _cef_v8accessor_t
|
||||||
|
{
|
||||||
|
// Base structure.
|
||||||
|
cef_base_t base;
|
||||||
|
|
||||||
|
// Called to get an accessor value. |name| is the name of the property being
|
||||||
|
// accessed. |object| is the This() object from V8's AccessorInfo structure.
|
||||||
|
// |retval| is the value to return for this property. Return true (1) if
|
||||||
|
// handled.
|
||||||
|
int (CEF_CALLBACK *get)(struct _cef_v8accessor_t* self,
|
||||||
|
const cef_string_t* name, struct _cef_v8value_t* object,
|
||||||
|
struct _cef_v8value_t** retval);
|
||||||
|
|
||||||
|
// Called to set an accessor value. |name| is the name of the property being
|
||||||
|
// accessed. |value| is the new value being assigned to this property.
|
||||||
|
// |object| is the This() object from V8's AccessorInfo structure. Return true
|
||||||
|
// (1) if handled.
|
||||||
|
int (CEF_CALLBACK *set)(struct _cef_v8accessor_t* self,
|
||||||
|
const cef_string_t* name, struct _cef_v8value_t* object,
|
||||||
|
struct _cef_v8value_t* value);
|
||||||
|
|
||||||
|
} cef_v8accessor_t;
|
||||||
|
|
||||||
|
|
||||||
// Structure representing a V8 value. The functions of this structure should
|
// Structure representing a V8 value. The functions of this structure should
|
||||||
// only be called on the UI thread.
|
// only be called on the UI thread.
|
||||||
typedef struct _cef_v8value_t
|
typedef struct _cef_v8value_t
|
||||||
@ -1171,6 +1209,11 @@ typedef struct _cef_v8value_t
|
|||||||
int (CEF_CALLBACK *is_array)(struct _cef_v8value_t* self);
|
int (CEF_CALLBACK *is_array)(struct _cef_v8value_t* self);
|
||||||
int (CEF_CALLBACK *is_function)(struct _cef_v8value_t* self);
|
int (CEF_CALLBACK *is_function)(struct _cef_v8value_t* self);
|
||||||
|
|
||||||
|
// Returns true (1) if this object is pointing to the same handle as |that|
|
||||||
|
// object.
|
||||||
|
int (CEF_CALLBACK *is_same)(struct _cef_v8value_t* self,
|
||||||
|
struct _cef_v8value_t* that);
|
||||||
|
|
||||||
// Return a primitive value type. The underlying data will be converted to
|
// Return a primitive value type. The underlying data will be converted to
|
||||||
// the requested type if necessary.
|
// the requested type if necessary.
|
||||||
int (CEF_CALLBACK *get_bool_value)(struct _cef_v8value_t* self);
|
int (CEF_CALLBACK *get_bool_value)(struct _cef_v8value_t* self);
|
||||||
@ -1203,12 +1246,19 @@ typedef struct _cef_v8value_t
|
|||||||
struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)(
|
struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)(
|
||||||
struct _cef_v8value_t* self, int index);
|
struct _cef_v8value_t* self, int index);
|
||||||
|
|
||||||
// Associate value with the specified identifier.
|
// Associate a value with the specified identifier.
|
||||||
int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* self,
|
int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* self,
|
||||||
const cef_string_t* key, struct _cef_v8value_t* value);
|
const cef_string_t* key, struct _cef_v8value_t* value);
|
||||||
int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index,
|
int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index,
|
||||||
struct _cef_v8value_t* value);
|
struct _cef_v8value_t* value);
|
||||||
|
|
||||||
|
// Register an identifier whose access will be forwarded to the
|
||||||
|
// cef_v8accessor_t instance passed to
|
||||||
|
// cef_v8value_t::cef_v8value_create_object_with_accessor().
|
||||||
|
int (CEF_CALLBACK *set_value_byaccessor)(struct _cef_v8value_t* self,
|
||||||
|
const cef_string_t* key, enum cef_v8_accesscontrol_t settings,
|
||||||
|
enum cef_v8_propertyattribute_t attribute);
|
||||||
|
|
||||||
// Read the keys for the object's values into the specified vector. Integer-
|
// Read the keys for the object's values into the specified vector. Integer-
|
||||||
// based keys will also be returned as strings.
|
// based keys will also be returned as strings.
|
||||||
int (CEF_CALLBACK *get_keys)(struct _cef_v8value_t* self,
|
int (CEF_CALLBACK *get_keys)(struct _cef_v8value_t* self,
|
||||||
@ -1259,6 +1309,8 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int value);
|
|||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_double(double value);
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_double(double value);
|
||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value);
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value);
|
||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_base_t* user_data);
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_base_t* user_data);
|
||||||
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_object_with_accessor(
|
||||||
|
cef_base_t* user_data, cef_v8accessor_t* accessor);
|
||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_array();
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_array();
|
||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_function(const cef_string_t* name,
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_function(const cef_string_t* name,
|
||||||
cef_v8handler_t* handler);
|
cef_v8handler_t* handler);
|
||||||
|
@ -361,6 +361,25 @@ enum cef_handler_errorcode_t
|
|||||||
ERR_INSECURE_RESPONSE = -501,
|
ERR_INSECURE_RESPONSE = -501,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// V8 access control values.
|
||||||
|
enum cef_v8_accesscontrol_t
|
||||||
|
{
|
||||||
|
V8_ACCESS_CONTROL_DEFAULT = 0,
|
||||||
|
V8_ACCESS_CONTROL_ALL_CAN_READ = 1,
|
||||||
|
V8_ACCESS_CONTROL_ALL_CAN_WRITE = 1 << 1,
|
||||||
|
V8_ACCESS_CONTROL_PROHIBITS_OVERWRITING = 1 << 2
|
||||||
|
};
|
||||||
|
|
||||||
|
// V8 property attribute values.
|
||||||
|
enum cef_v8_propertyattribute_t
|
||||||
|
{
|
||||||
|
V8_PROPERTY_ATTRIBUTE_NONE = 0, // Writeable, Enumerable,
|
||||||
|
// Configurable
|
||||||
|
V8_PROPERTY_ATTRIBUTE_READONLY = 1 << 0, // Not writeable
|
||||||
|
V8_PROPERTY_ATTRIBUTE_DONTENUM = 1 << 1, // Not enumerable
|
||||||
|
V8_PROPERTY_ATTRIBUTE_DONTDELETE = 1 << 2 // Not configurable
|
||||||
|
};
|
||||||
|
|
||||||
// Structure representing menu information.
|
// Structure representing menu information.
|
||||||
typedef struct _cef_handler_menuinfo_t
|
typedef struct _cef_handler_menuinfo_t
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,17 @@ protected:
|
|||||||
CefRefPtr<CefBase> base_;
|
CefRefPtr<CefBase> base_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TrackBase2 : public TrackBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TrackBase2(CefBase* base, CefBase* base2): TrackBase(base) {
|
||||||
|
base2_ = base2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CefRefPtr<CefBase> base2_;
|
||||||
|
};
|
||||||
|
|
||||||
class TrackString : public CefTrackObject
|
class TrackString : public CefTrackObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -140,6 +151,57 @@ v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// V8 Accessor callbacks
|
||||||
|
v8::Handle<v8::Value> AccessorGetterCallbackImpl(v8::Local<v8::String> property,
|
||||||
|
const v8::AccessorInfo& info)
|
||||||
|
{
|
||||||
|
v8::HandleScope handle_scope;
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> value = v8::Undefined();
|
||||||
|
v8::Handle<v8::Object> obj = info.This();
|
||||||
|
v8::Handle<v8::String> key = v8::String::New("Cef::Accessor");
|
||||||
|
|
||||||
|
CefV8Accessor* accessorPtr = NULL;
|
||||||
|
if (obj->Has(key)) {
|
||||||
|
accessorPtr = static_cast<CefV8Accessor*>(v8::External::Unwrap(
|
||||||
|
obj->Get(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessorPtr) {
|
||||||
|
CefRefPtr<CefV8Value> retval;
|
||||||
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(obj);
|
||||||
|
CefString name = GetString(property);
|
||||||
|
if (accessorPtr->Get(name, object, retval)) {
|
||||||
|
CefV8ValueImpl* rv = static_cast<CefV8ValueImpl*>(retval.get());
|
||||||
|
if (rv)
|
||||||
|
value = rv->GetHandle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccessorSetterCallbackImpl(v8::Local<v8::String> property,
|
||||||
|
v8::Local<v8::Value> value,
|
||||||
|
const v8::AccessorInfo& info)
|
||||||
|
{
|
||||||
|
v8::HandleScope handle_scope;
|
||||||
|
|
||||||
|
v8::Handle<v8::Object> obj = info.This();
|
||||||
|
v8::Handle<v8::String> key = v8::String::New("Cef::Accessor");
|
||||||
|
|
||||||
|
CefV8Accessor* accessorPtr = NULL;
|
||||||
|
if (obj->Has(key)) {
|
||||||
|
accessorPtr = static_cast<CefV8Accessor*>(v8::External::Unwrap(
|
||||||
|
obj->Get(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessorPtr) {
|
||||||
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(obj);
|
||||||
|
CefRefPtr<CefV8Value> cefValue = new CefV8ValueImpl(value);
|
||||||
|
CefString name = GetString(property);
|
||||||
|
accessorPtr->Set(name, object, cefValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// V8 extension registration.
|
// V8 extension registration.
|
||||||
|
|
||||||
@ -231,12 +293,16 @@ CefRefPtr<CefV8Context> CefV8Context::GetEnteredContext()
|
|||||||
// CefV8ContextImpl
|
// CefV8ContextImpl
|
||||||
|
|
||||||
CefV8ContextImpl::CefV8ContextImpl(v8::Handle<v8::Context> context)
|
CefV8ContextImpl::CefV8ContextImpl(v8::Handle<v8::Context> context)
|
||||||
|
#ifdef _DEBUG
|
||||||
|
: enter_count_(0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
v8_context_ = new CefV8ContextHandle(context);
|
v8_context_ = new CefV8ContextHandle(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
CefV8ContextImpl::~CefV8ContextImpl()
|
CefV8ContextImpl::~CefV8ContextImpl()
|
||||||
{
|
{
|
||||||
|
DLOG_ASSERT(0 == enter_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CefRefPtr<CefBrowser> CefV8ContextImpl::GetBrowser()
|
CefRefPtr<CefBrowser> CefV8ContextImpl::GetBrowser()
|
||||||
@ -276,6 +342,27 @@ CefRefPtr<CefV8Value> CefV8ContextImpl::GetGlobal()
|
|||||||
return new CefV8ValueImpl(v8_context_->GetHandle()->Global());
|
return new CefV8ValueImpl(v8_context_->GetHandle()->Global());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ContextImpl::Enter()
|
||||||
|
{
|
||||||
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
|
v8_context_->GetHandle()->Enter();
|
||||||
|
#ifdef _DEBUG
|
||||||
|
++enter_count_;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CefV8ContextImpl::Exit()
|
||||||
|
{
|
||||||
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
|
DLOG_ASSERT(enter_count_ > 0);
|
||||||
|
v8_context_->GetHandle()->Exit();
|
||||||
|
#ifdef _DEBUG
|
||||||
|
--enter_count_;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Context> CefV8ContextImpl::GetContext()
|
v8::Local<v8::Context> CefV8ContextImpl::GetContext()
|
||||||
{
|
{
|
||||||
return v8::Local<v8::Context>::New(v8_context_->GetHandle());
|
return v8::Local<v8::Context>::New(v8_context_->GetHandle());
|
||||||
@ -361,6 +448,14 @@ CefRefPtr<CefV8Value> CefV8Value::CreateString(const CefString& value)
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
|
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
|
||||||
|
{
|
||||||
|
CefRefPtr<CefV8Accessor> no_accessor;
|
||||||
|
return CreateObject(user_data, no_accessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
CefRefPtr<CefV8Value> CefV8Value::CreateObject(
|
||||||
|
CefRefPtr<CefBase> user_data, CefRefPtr<CefV8Accessor> accessor)
|
||||||
{
|
{
|
||||||
CEF_REQUIRE_VALID_CONTEXT(NULL);
|
CEF_REQUIRE_VALID_CONTEXT(NULL);
|
||||||
CEF_REQUIRE_UI_THREAD(NULL);
|
CEF_REQUIRE_UI_THREAD(NULL);
|
||||||
@ -370,15 +465,26 @@ CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
|
|||||||
// Create the new V8 object.
|
// Create the new V8 object.
|
||||||
v8::Local<v8::Object> obj = v8::Object::New();
|
v8::Local<v8::Object> obj = v8::Object::New();
|
||||||
|
|
||||||
|
// Provide a tracker object that will cause the user data and/or accessor
|
||||||
|
// reference to be released when the V8 object is destroyed.
|
||||||
TrackBase *tracker = NULL;
|
TrackBase *tracker = NULL;
|
||||||
|
if (user_data.get() && accessor.get()) {
|
||||||
|
tracker = new TrackBase2(user_data, accessor);
|
||||||
|
} else if (user_data.get() || accessor.get()) {
|
||||||
|
tracker = new TrackBase(user_data.get() ?
|
||||||
|
user_data : CefRefPtr<CefBase>(accessor.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach the user data to the V8 object.
|
||||||
if (user_data.get()) {
|
if (user_data.get()) {
|
||||||
// Attach the user data to the V8 object.
|
|
||||||
v8::Local<v8::Value> data = v8::External::Wrap(user_data.get());
|
v8::Local<v8::Value> data = v8::External::Wrap(user_data.get());
|
||||||
obj->Set(v8::String::New("Cef::UserData"), data);
|
obj->Set(v8::String::New("Cef::UserData"), data);
|
||||||
|
}
|
||||||
|
|
||||||
// Provide a tracker object that will cause the user data reference to be
|
// Attach the accessor to the V8 object.
|
||||||
// released when the V8 object is destroyed.
|
if (accessor.get()) {
|
||||||
tracker = new TrackBase(user_data);
|
v8::Local<v8::Value> data = v8::External::Wrap(accessor.get());
|
||||||
|
obj->Set(v8::String::New("Cef::Accessor"), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CefV8ValueImpl(obj, tracker);
|
return new CefV8ValueImpl(obj, tracker);
|
||||||
@ -491,6 +597,22 @@ bool CefV8ValueImpl::IsFunction()
|
|||||||
return GetHandle()->IsFunction();
|
return GetHandle()->IsFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ValueImpl::IsSame(CefRefPtr<CefV8Value> that)
|
||||||
|
{
|
||||||
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
|
|
||||||
|
v8::HandleScope handle_scope;
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> thatHandle;
|
||||||
|
v8::Handle<v8::Value> thisHandle = GetHandle();
|
||||||
|
|
||||||
|
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(that.get());
|
||||||
|
if (impl)
|
||||||
|
thatHandle = impl->GetHandle();
|
||||||
|
|
||||||
|
return (thisHandle == thatHandle);
|
||||||
|
}
|
||||||
|
|
||||||
bool CefV8ValueImpl::GetBoolValue()
|
bool CefV8ValueImpl::GetBoolValue()
|
||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD(false);
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
@ -655,6 +777,28 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
|
||||||
|
PropertyAttribute attribute)
|
||||||
|
{
|
||||||
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
|
if(!GetHandle()->IsObject()) {
|
||||||
|
NOTREACHED();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::HandleScope handle_scope;
|
||||||
|
v8::Local<v8::Object> obj = GetHandle()->ToObject();
|
||||||
|
|
||||||
|
v8::AccessorGetter getter = AccessorGetterCallbackImpl;
|
||||||
|
v8::AccessorSetter setter = (attribute & V8_PROPERTY_ATTRIBUTE_READONLY) ?
|
||||||
|
NULL : AccessorSetterCallbackImpl;
|
||||||
|
|
||||||
|
bool rv = obj->SetAccessor(GetV8String(key), getter, setter, obj,
|
||||||
|
static_cast<v8::AccessControl>(settings),
|
||||||
|
static_cast<v8::PropertyAttribute>(attribute));
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
bool CefV8ValueImpl::GetKeys(std::vector<CefString>& keys)
|
bool CefV8ValueImpl::GetKeys(std::vector<CefString>& keys)
|
||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD(false);
|
CEF_REQUIRE_UI_THREAD(false);
|
||||||
|
@ -68,12 +68,19 @@ public:
|
|||||||
virtual CefRefPtr<CefBrowser> GetBrowser();
|
virtual CefRefPtr<CefBrowser> GetBrowser();
|
||||||
virtual CefRefPtr<CefFrame> GetFrame();
|
virtual CefRefPtr<CefFrame> GetFrame();
|
||||||
virtual CefRefPtr<CefV8Value> GetGlobal();
|
virtual CefRefPtr<CefV8Value> GetGlobal();
|
||||||
|
virtual bool Enter();
|
||||||
|
virtual bool Exit();
|
||||||
|
|
||||||
v8::Local<v8::Context> GetContext();
|
v8::Local<v8::Context> GetContext();
|
||||||
WebKit::WebFrame* GetWebFrame();
|
WebKit::WebFrame* GetWebFrame();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
scoped_refptr<CefV8ContextHandle> v8_context_;
|
scoped_refptr<CefV8ContextHandle> v8_context_;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Used in debug builds to catch missing Exits in destructor.
|
||||||
|
int enter_count_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special class for a v8::Value to ensure that it is deleted from the UI
|
// Special class for a v8::Value to ensure that it is deleted from the UI
|
||||||
@ -109,6 +116,7 @@ public:
|
|||||||
virtual bool IsObject();
|
virtual bool IsObject();
|
||||||
virtual bool IsArray();
|
virtual bool IsArray();
|
||||||
virtual bool IsFunction();
|
virtual bool IsFunction();
|
||||||
|
virtual bool IsSame(CefRefPtr<CefV8Value> value);
|
||||||
virtual bool GetBoolValue();
|
virtual bool GetBoolValue();
|
||||||
virtual int GetIntValue();
|
virtual int GetIntValue();
|
||||||
virtual double GetDoubleValue();
|
virtual double GetDoubleValue();
|
||||||
@ -121,6 +129,8 @@ public:
|
|||||||
virtual CefRefPtr<CefV8Value> GetValue(int index);
|
virtual CefRefPtr<CefV8Value> GetValue(int index);
|
||||||
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value);
|
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value);
|
||||||
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
|
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
|
||||||
|
virtual bool SetValue(const CefString& key, AccessControl settings,
|
||||||
|
PropertyAttribute attribute);
|
||||||
virtual bool GetKeys(std::vector<CefString>& keys);
|
virtual bool GetKeys(std::vector<CefString>& keys);
|
||||||
virtual CefRefPtr<CefBase> GetUserData();
|
virtual CefRefPtr<CefBase> GetUserData();
|
||||||
virtual int GetArrayLength();
|
virtual int GetArrayLength();
|
||||||
|
77
libcef_dll/cpptoc/v8accessor_cpptoc.cc
Normal file
77
libcef_dll/cpptoc/v8accessor_cpptoc.cc
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing function
|
||||||
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
|
// for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8accessor_get(struct _cef_v8accessor_t* self,
|
||||||
|
const cef_string_t* name, struct _cef_v8value_t* object,
|
||||||
|
struct _cef_v8value_t** retval)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> objectPtr;
|
||||||
|
if(object)
|
||||||
|
objectPtr = CefV8ValueCToCpp::Wrap(object);
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> retValPtr;
|
||||||
|
bool rv = CefV8AccessorCppToC::Get(self)->Get(CefString(name), objectPtr,
|
||||||
|
retValPtr);
|
||||||
|
if(rv) {
|
||||||
|
if(retValPtr.get() && retval)
|
||||||
|
*retval = CefV8ValueCToCpp::Unwrap(retValPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8accessor_set(struct _cef_v8accessor_t* self,
|
||||||
|
const cef_string_t* name, struct _cef_v8value_t* object,
|
||||||
|
struct _cef_v8value_t* value)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> objectPtr;
|
||||||
|
if(object)
|
||||||
|
objectPtr = CefV8ValueCToCpp::Wrap(object);
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> valuePtr;
|
||||||
|
if(value)
|
||||||
|
valuePtr = CefV8ValueCToCpp::Wrap(value);
|
||||||
|
|
||||||
|
bool rv = CefV8AccessorCppToC::Get(self)->Set(CefString(name), objectPtr,
|
||||||
|
valuePtr);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
|
CefV8AccessorCppToC::CefV8AccessorCppToC(CefV8Accessor* cls)
|
||||||
|
: CefCppToC<CefV8AccessorCppToC, CefV8Accessor, cef_v8accessor_t>(cls)
|
||||||
|
{
|
||||||
|
struct_.struct_.get = v8accessor_get;
|
||||||
|
struct_.struct_.set = v8accessor_set;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCppToC<CefV8AccessorCppToC, CefV8Accessor,
|
||||||
|
cef_v8accessor_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
34
libcef_dll/cpptoc/v8accessor_cpptoc.h
Normal file
34
libcef_dll/cpptoc/v8accessor_cpptoc.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
#ifndef _V8ACCESSOR_CPPTOC_H
|
||||||
|
#define _V8ACCESSOR_CPPTOC_H
|
||||||
|
|
||||||
|
#ifndef USING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||||
|
#else // USING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/cpptoc/cpptoc.h"
|
||||||
|
|
||||||
|
// Wrap a C++ class with a C structure.
|
||||||
|
// This class may be instantiated and accessed wrapper-side only.
|
||||||
|
class CefV8AccessorCppToC
|
||||||
|
: public CefCppToC<CefV8AccessorCppToC, CefV8Accessor, cef_v8accessor_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefV8AccessorCppToC(CefV8Accessor* cls);
|
||||||
|
virtual ~CefV8AccessorCppToC() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USING_CEF_SHARED
|
||||||
|
#endif // _V8ACCESSOR_CPPTOC_H
|
||||||
|
|
@ -79,6 +79,26 @@ struct _cef_v8value_t* CEF_CALLBACK v8context_get_global(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8context_enter(struct _cef_v8context_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Context> contextPtr = CefV8ContextCppToC::Get(self);
|
||||||
|
return contextPtr->Enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8context_exit(struct _cef_v8context_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Context> contextPtr = CefV8ContextCppToC::Get(self);
|
||||||
|
return contextPtr->Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
@ -88,6 +108,8 @@ CefV8ContextCppToC::CefV8ContextCppToC(CefV8Context* cls)
|
|||||||
struct_.struct_.get_browser = v8context_get_browser;
|
struct_.struct_.get_browser = v8context_get_browser;
|
||||||
struct_.struct_.get_frame = v8context_get_frame;
|
struct_.struct_.get_frame = v8context_get_frame;
|
||||||
struct_.struct_.get_global = v8context_get_global;
|
struct_.struct_.get_global = v8context_get_global;
|
||||||
|
struct_.struct_.enter = v8context_enter;
|
||||||
|
struct_.struct_.exit = v8context_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
|
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
|
||||||
#include "libcef_dll/ctocpp/base_ctocpp.h"
|
#include "libcef_dll/ctocpp/base_ctocpp.h"
|
||||||
|
#include "libcef_dll/ctocpp/v8accessor_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/v8handler_ctocpp.h"
|
#include "libcef_dll/ctocpp/v8handler_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
@ -78,6 +79,23 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_base_t* user_data)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_object_with_accessor(
|
||||||
|
cef_base_t* user_data, cef_v8accessor_t* accessor)
|
||||||
|
{
|
||||||
|
CefRefPtr<CefBase> basePtr;
|
||||||
|
if(user_data)
|
||||||
|
basePtr = CefBaseCToCpp::Wrap(user_data);
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Accessor> accessorPtr;
|
||||||
|
if(accessor)
|
||||||
|
accessorPtr = CefV8AccessorCToCpp::Wrap(accessor);
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> impl = CefV8Value::CreateObject(basePtr, accessorPtr);
|
||||||
|
if(impl.get())
|
||||||
|
return CefV8ValueCppToC::Wrap(impl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CEF_EXPORT cef_v8value_t* cef_v8value_create_array()
|
CEF_EXPORT cef_v8value_t* cef_v8value_create_array()
|
||||||
{
|
{
|
||||||
CefRefPtr<CefV8Value> impl = CefV8Value::CreateArray();
|
CefRefPtr<CefV8Value> impl = CefV8Value::CreateArray();
|
||||||
@ -184,6 +202,17 @@ int CEF_CALLBACK v8value_is_function(struct _cef_v8value_t* self)
|
|||||||
return CefV8ValueCppToC::Get(self)->IsFunction();
|
return CefV8ValueCppToC::Get(self)->IsFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8value_is_same(struct _cef_v8value_t* self,
|
||||||
|
struct _cef_v8value_t* that)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> thatPtr = CefV8ValueCppToC::Unwrap(that);
|
||||||
|
return CefV8ValueCppToC::Get(self)->IsSame(thatPtr);
|
||||||
|
}
|
||||||
|
|
||||||
int CEF_CALLBACK v8value_get_bool_value(struct _cef_v8value_t* self)
|
int CEF_CALLBACK v8value_get_bool_value(struct _cef_v8value_t* self)
|
||||||
{
|
{
|
||||||
DCHECK(self);
|
DCHECK(self);
|
||||||
@ -308,6 +337,18 @@ int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* self,
|
|||||||
return CefV8ValueCppToC::Get(self)->SetValue(index, valuePtr);
|
return CefV8ValueCppToC::Get(self)->SetValue(index, valuePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK v8value_set_value_byaccessor(struct _cef_v8value_t* self,
|
||||||
|
const cef_string_t* key, enum cef_v8_accesscontrol_t settings,
|
||||||
|
enum cef_v8_propertyattribute_t attribute)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return CefV8ValueCppToC::Get(self)->SetValue(CefString(key),
|
||||||
|
settings, attribute);
|
||||||
|
}
|
||||||
|
|
||||||
int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* self,
|
int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* self,
|
||||||
cef_string_list_t keys)
|
cef_string_list_t keys)
|
||||||
{
|
{
|
||||||
@ -442,6 +483,7 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls)
|
|||||||
struct_.struct_.is_object = v8value_is_object;
|
struct_.struct_.is_object = v8value_is_object;
|
||||||
struct_.struct_.is_array = v8value_is_array;
|
struct_.struct_.is_array = v8value_is_array;
|
||||||
struct_.struct_.is_function = v8value_is_function;
|
struct_.struct_.is_function = v8value_is_function;
|
||||||
|
struct_.struct_.is_same = v8value_is_same;
|
||||||
struct_.struct_.get_bool_value = v8value_get_bool_value;
|
struct_.struct_.get_bool_value = v8value_get_bool_value;
|
||||||
struct_.struct_.get_int_value = v8value_get_int_value;
|
struct_.struct_.get_int_value = v8value_get_int_value;
|
||||||
struct_.struct_.get_double_value = v8value_get_double_value;
|
struct_.struct_.get_double_value = v8value_get_double_value;
|
||||||
@ -454,6 +496,7 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls)
|
|||||||
struct_.struct_.get_value_byindex = v8value_get_value_byindex;
|
struct_.struct_.get_value_byindex = v8value_get_value_byindex;
|
||||||
struct_.struct_.set_value_bykey = v8value_set_value_bykey;
|
struct_.struct_.set_value_bykey = v8value_set_value_bykey;
|
||||||
struct_.struct_.set_value_byindex = v8value_set_value_byindex;
|
struct_.struct_.set_value_byindex = v8value_set_value_byindex;
|
||||||
|
struct_.struct_.set_value_byaccessor = v8value_set_value_byaccessor;
|
||||||
struct_.struct_.get_keys = v8value_get_keys;
|
struct_.struct_.get_keys = v8value_get_keys;
|
||||||
struct_.struct_.get_user_data = v8value_get_user_data;
|
struct_.struct_.get_user_data = v8value_get_user_data;
|
||||||
struct_.struct_.get_array_length = v8value_get_array_length;
|
struct_.struct_.get_array_length = v8value_get_array_length;
|
||||||
|
53
libcef_dll/ctocpp/v8accessor_ctocpp.cc
Normal file
53
libcef_dll/ctocpp/v8accessor_ctocpp.cc
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing static and
|
||||||
|
// virtual method implementations. See the translator.README.txt file in the
|
||||||
|
// tools directory for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/v8accessor_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
|
bool CefV8AccessorCToCpp::Get(const CefString& name,
|
||||||
|
const CefRefPtr<CefV8Value> object, CefRefPtr<CefV8Value>& retval)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, get))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cef_v8value_t* retvalStruct = NULL;
|
||||||
|
|
||||||
|
int rv = struct_->get(struct_, name.GetStruct(),
|
||||||
|
CefV8ValueCppToC::Wrap(object), &retvalStruct);
|
||||||
|
if(retvalStruct)
|
||||||
|
retval = CefV8ValueCppToC::Unwrap(retvalStruct);
|
||||||
|
|
||||||
|
return rv ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CefV8AccessorCToCpp::Set(const CefString& name,
|
||||||
|
const CefRefPtr<CefV8Value> object, const CefRefPtr<CefV8Value> value)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, set))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int rv = struct_->set(struct_, name.GetStruct(),
|
||||||
|
CefV8ValueCppToC::Wrap(object),
|
||||||
|
CefV8ValueCppToC::Wrap(value));
|
||||||
|
|
||||||
|
return rv ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCToCpp<CefV8AccessorCToCpp, CefV8Accessor,
|
||||||
|
cef_v8accessor_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
42
libcef_dll/ctocpp/v8accessor_ctocpp.h
Normal file
42
libcef_dll/ctocpp/v8accessor_ctocpp.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||||
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
|
// can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _V8ACCESSOR_CTOCPP_H
|
||||||
|
#define _V8ACCESSOR_CTOCPP_H
|
||||||
|
|
||||||
|
#ifndef BUILDING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||||
|
#else // BUILDING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||||
|
|
||||||
|
// Wrap a C structure with a C++ class.
|
||||||
|
// This class may be instantiated and accessed DLL-side only.
|
||||||
|
class CefV8AccessorCToCpp
|
||||||
|
: public CefCToCpp<CefV8AccessorCToCpp, CefV8Accessor, cef_v8accessor_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefV8AccessorCToCpp(cef_v8accessor_t* str)
|
||||||
|
: CefCToCpp<CefV8AccessorCToCpp, CefV8Accessor, cef_v8accessor_t>(str) {}
|
||||||
|
virtual ~CefV8AccessorCToCpp() {}
|
||||||
|
|
||||||
|
// CefV8Accessor methods
|
||||||
|
virtual bool Get(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
CefRefPtr<CefV8Value>& retval);
|
||||||
|
virtual bool Set(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
const CefRefPtr<CefV8Value> value);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BUILDING_CEF_SHARED
|
||||||
|
#endif // _V8ACCESSOR_CTOCPP_H
|
||||||
|
|
@ -73,6 +73,22 @@ CefRefPtr<CefV8Value> CefV8ContextCToCpp::GetGlobal()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ContextCToCpp::Enter()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, enter))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return struct_->enter(struct_)?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CefV8ContextCToCpp::Exit()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, exit))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return struct_->exit(struct_)?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
template<> long CefCToCpp<CefV8ContextCToCpp, CefV8Context,
|
template<> long CefCToCpp<CefV8ContextCToCpp, CefV8Context,
|
||||||
|
@ -34,6 +34,8 @@ public:
|
|||||||
virtual CefRefPtr<CefBrowser> GetBrowser();
|
virtual CefRefPtr<CefBrowser> GetBrowser();
|
||||||
virtual CefRefPtr<CefFrame> GetFrame();
|
virtual CefRefPtr<CefFrame> GetFrame();
|
||||||
virtual CefRefPtr<CefV8Value> GetGlobal();
|
virtual CefRefPtr<CefV8Value> GetGlobal();
|
||||||
|
virtual bool Enter();
|
||||||
|
virtual bool Exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USING_CEF_SHARED
|
#endif // USING_CEF_SHARED
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/cpptoc/base_cpptoc.h"
|
#include "libcef_dll/cpptoc/base_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
|
||||||
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
|
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
|
||||||
@ -79,6 +80,24 @@ CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data,
|
||||||
|
CefRefPtr<CefV8Accessor> accessor)
|
||||||
|
{
|
||||||
|
cef_base_t* baseStruct = NULL;
|
||||||
|
if(user_data)
|
||||||
|
baseStruct = CefBaseCppToC::Wrap(user_data);
|
||||||
|
|
||||||
|
cef_v8accessor_t* accessorStruct = NULL;
|
||||||
|
if(accessor)
|
||||||
|
accessorStruct = CefV8AccessorCppToC::Wrap(accessor);
|
||||||
|
|
||||||
|
cef_v8value_t* impl = cef_v8value_create_object_with_accessor(baseStruct,
|
||||||
|
accessorStruct);
|
||||||
|
if(impl)
|
||||||
|
return CefV8ValueCToCpp::Wrap(impl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CefRefPtr<CefV8Value> CefV8Value::CreateArray()
|
CefRefPtr<CefV8Value> CefV8Value::CreateArray()
|
||||||
{
|
{
|
||||||
cef_v8value_t* impl = cef_v8value_create_array();
|
cef_v8value_t* impl = cef_v8value_create_array();
|
||||||
@ -176,6 +195,14 @@ bool CefV8ValueCToCpp::IsFunction()
|
|||||||
return struct_->is_function(struct_)?true:false;
|
return struct_->is_function(struct_)?true:false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ValueCToCpp::IsSame(CefRefPtr<CefV8Value> that)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, is_same))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return struct_->is_same(struct_, CefV8ValueCToCpp::Unwrap(that))?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CefV8ValueCToCpp::GetBoolValue()
|
bool CefV8ValueCToCpp::GetBoolValue()
|
||||||
{
|
{
|
||||||
if(CEF_MEMBER_MISSING(struct_, get_bool_value))
|
if(CEF_MEMBER_MISSING(struct_, get_bool_value))
|
||||||
@ -285,6 +312,16 @@ bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr<CefV8Value> value)
|
|||||||
CefV8ValueCToCpp::Unwrap(value))?true:false;
|
CefV8ValueCToCpp::Unwrap(value))?true:false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefV8ValueCToCpp::SetValue(const CefString& key, AccessControl settings,
|
||||||
|
PropertyAttribute attribute)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, set_value_byaccessor))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return struct_->set_value_byaccessor(struct_, key.GetStruct(),
|
||||||
|
settings, attribute)?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CefV8ValueCToCpp::GetKeys(std::vector<CefString>& keys)
|
bool CefV8ValueCToCpp::GetKeys(std::vector<CefString>& keys)
|
||||||
{
|
{
|
||||||
if(CEF_MEMBER_MISSING(struct_, get_keys))
|
if(CEF_MEMBER_MISSING(struct_, get_keys))
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
virtual bool IsObject();
|
virtual bool IsObject();
|
||||||
virtual bool IsArray();
|
virtual bool IsArray();
|
||||||
virtual bool IsFunction();
|
virtual bool IsFunction();
|
||||||
|
virtual bool IsSame(CefRefPtr<CefV8Value> that);
|
||||||
virtual bool GetBoolValue();
|
virtual bool GetBoolValue();
|
||||||
virtual int GetIntValue();
|
virtual int GetIntValue();
|
||||||
virtual double GetDoubleValue();
|
virtual double GetDoubleValue();
|
||||||
@ -52,6 +53,8 @@ public:
|
|||||||
virtual CefRefPtr<CefV8Value> GetValue(int index);
|
virtual CefRefPtr<CefV8Value> GetValue(int index);
|
||||||
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value);
|
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value);
|
||||||
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
|
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
|
||||||
|
virtual bool SetValue(const CefString& key, AccessControl settings,
|
||||||
|
PropertyAttribute attribute);
|
||||||
virtual bool GetKeys(std::vector<CefString>& keys);
|
virtual bool GetKeys(std::vector<CefString>& keys);
|
||||||
virtual CefRefPtr<CefBase> GetUserData();
|
virtual CefRefPtr<CefBase> GetUserData();
|
||||||
virtual int GetArrayLength();
|
virtual int GetArrayLength();
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "cpptoc/request_cpptoc.h"
|
#include "cpptoc/request_cpptoc.h"
|
||||||
#include "cpptoc/stream_reader_cpptoc.h"
|
#include "cpptoc/stream_reader_cpptoc.h"
|
||||||
#include "cpptoc/stream_writer_cpptoc.h"
|
#include "cpptoc/stream_writer_cpptoc.h"
|
||||||
|
#include "cpptoc/v8context_cpptoc.h"
|
||||||
#include "cpptoc/v8value_cpptoc.h"
|
#include "cpptoc/v8value_cpptoc.h"
|
||||||
#include "cpptoc/web_urlrequest_cpptoc.h"
|
#include "cpptoc/web_urlrequest_cpptoc.h"
|
||||||
#include "cpptoc/xml_reader_cpptoc.h"
|
#include "cpptoc/xml_reader_cpptoc.h"
|
||||||
@ -28,6 +29,7 @@
|
|||||||
#include "ctocpp/scheme_handler_ctocpp.h"
|
#include "ctocpp/scheme_handler_ctocpp.h"
|
||||||
#include "ctocpp/scheme_handler_factory_ctocpp.h"
|
#include "ctocpp/scheme_handler_factory_ctocpp.h"
|
||||||
#include "ctocpp/task_ctocpp.h"
|
#include "ctocpp/task_ctocpp.h"
|
||||||
|
#include "ctocpp/v8accessor_ctocpp.h"
|
||||||
#include "ctocpp/v8handler_ctocpp.h"
|
#include "ctocpp/v8handler_ctocpp.h"
|
||||||
#include "ctocpp/web_urlrequest_client_ctocpp.h"
|
#include "ctocpp/web_urlrequest_client_ctocpp.h"
|
||||||
#include "ctocpp/write_handler_ctocpp.h"
|
#include "ctocpp/write_handler_ctocpp.h"
|
||||||
@ -70,6 +72,7 @@ CEF_EXPORT void cef_shutdown()
|
|||||||
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
|
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
|
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
|
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
|
||||||
|
DCHECK(CefV8ContextCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
|
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefWebURLRequestCppToC::DebugObjCt == 0);
|
DCHECK(CefWebURLRequestCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefXmlReaderCppToC::DebugObjCt == 0);
|
DCHECK(CefXmlReaderCppToC::DebugObjCt == 0);
|
||||||
@ -80,6 +83,7 @@ CEF_EXPORT void cef_shutdown()
|
|||||||
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
|
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
|
||||||
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
|
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
|
||||||
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
|
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
|
||||||
|
DCHECK(CefV8AccessorCToCpp::DebugObjCt == 0);
|
||||||
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
|
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
|
||||||
DCHECK(CefWebURLRequestClientCToCpp::DebugObjCt == 0);
|
DCHECK(CefWebURLRequestClientCToCpp::DebugObjCt == 0);
|
||||||
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
|
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h"
|
#include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/task_cpptoc.h"
|
#include "libcef_dll/cpptoc/task_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
|
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/write_handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/write_handler_cpptoc.h"
|
||||||
@ -51,6 +52,7 @@ void CefShutdown()
|
|||||||
DCHECK(CefReadHandlerCppToC::DebugObjCt == 0);
|
DCHECK(CefReadHandlerCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefSchemeHandlerCppToC::DebugObjCt == 0);
|
DCHECK(CefSchemeHandlerCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefSchemeHandlerFactoryCppToC::DebugObjCt == 0);
|
DCHECK(CefSchemeHandlerFactoryCppToC::DebugObjCt == 0);
|
||||||
|
DCHECK(CefV8AccessorCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
|
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefWebURLRequestClientCppToC::DebugObjCt == 0);
|
DCHECK(CefWebURLRequestClientCppToC::DebugObjCt == 0);
|
||||||
DCHECK(CefWriteHandlerCppToC::DebugObjCt == 0);
|
DCHECK(CefWriteHandlerCppToC::DebugObjCt == 0);
|
||||||
|
@ -368,6 +368,12 @@ public:
|
|||||||
const CefV8ValueList& arguments,
|
const CefV8ValueList& arguments,
|
||||||
CefRefPtr<CefV8Value>& retval,
|
CefRefPtr<CefV8Value>& retval,
|
||||||
CefString& exception) = 0;
|
CefString& exception) = 0;
|
||||||
|
|
||||||
|
virtual bool Get(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
CefRefPtr<CefV8Value>& retval) = 0;
|
||||||
|
|
||||||
|
virtual bool Set(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
const CefRefPtr<CefV8Value> value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DelegatingV8Handler : public CefThreadSafeBase<CefV8Handler>
|
class DelegatingV8Handler : public CefThreadSafeBase<CefV8Handler>
|
||||||
@ -393,6 +399,28 @@ private:
|
|||||||
CefV8HandlerDelegate *delegate_;
|
CefV8HandlerDelegate *delegate_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DelegatingV8Accessor: public CefThreadSafeBase<CefV8Accessor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DelegatingV8Accessor(CefV8HandlerDelegate *delegate)
|
||||||
|
: delegate_(delegate) { }
|
||||||
|
|
||||||
|
bool Get(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
CefRefPtr<CefV8Value>& retval)
|
||||||
|
{
|
||||||
|
return delegate_->Get(name, object, retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Set(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
const CefRefPtr<CefV8Value> value)
|
||||||
|
{
|
||||||
|
return delegate_->Set(name, object, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CefV8HandlerDelegate *delegate_;
|
||||||
|
};
|
||||||
|
|
||||||
class TestContextHandler: public TestHandler, public CefV8HandlerDelegate
|
class TestContextHandler: public TestHandler, public CefV8HandlerDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -426,12 +454,26 @@ public:
|
|||||||
// based loading of "end.html".
|
// based loading of "end.html".
|
||||||
// 9. end.html calls "end()" in the execute handler.
|
// 9. end.html calls "end()" in the execute handler.
|
||||||
// which concludes the test.
|
// which concludes the test.
|
||||||
|
|
||||||
|
y_ = 0;
|
||||||
|
|
||||||
std::stringstream mainHtml;
|
std::stringstream mainHtml;
|
||||||
mainHtml <<
|
mainHtml <<
|
||||||
"<html><body>"
|
"<html><body>"
|
||||||
"<h1>Hello From Main Frame</h1>"
|
"<h1>Hello From Main Frame</h1>"
|
||||||
"<script language=\"JavaScript\">"
|
"<script language=\"JavaScript\">"
|
||||||
|
"aaa = function(){}; bbb = function(a){ a=1; };"
|
||||||
|
"comp(false,{},{});\n"
|
||||||
|
"comp(true,aaa,aaa);\n"
|
||||||
|
"comp(true,bbb,bbb);\n"
|
||||||
|
"comp(false,aaa,bbb);\n"
|
||||||
|
"comp(false,{},bbb);\n"
|
||||||
|
"comp(false,{},bbb);\n"
|
||||||
|
"comp(true,0,0);\n"
|
||||||
|
"comp(true,\"a\",\"a\");\n"
|
||||||
|
"comp(false,\"a\",\"b\");\n"
|
||||||
|
"try { point.x = -1; } catch(e) { }\n" // should not have any effect.
|
||||||
|
"try { point.y = point.x; theY = point.y; } catch(e) { point.y = 4321; }\n"
|
||||||
"hello(\"main\", callIFrame);"
|
"hello(\"main\", callIFrame);"
|
||||||
"function callIFrame() {"
|
"function callIFrame() {"
|
||||||
" var iframe = document.getElementById('iframe');"
|
" var iframe = document.getElementById('iframe');"
|
||||||
@ -463,7 +505,7 @@ public:
|
|||||||
"<h1>V8 Context Test</h1>"
|
"<h1>V8 Context Test</h1>"
|
||||||
"<script language=\"JavaScript\">"
|
"<script language=\"JavaScript\">"
|
||||||
"function TestException() { throw('My Exception'); }"
|
"function TestException() { throw('My Exception'); }"
|
||||||
"function TestNavigate(a) { document.location = a; }"
|
"function TestNavigate(a) { document.location = a.url; }"
|
||||||
"begin(TestException, TestNavigate);"
|
"begin(TestException, TestNavigate);"
|
||||||
"</script>"
|
"</script>"
|
||||||
"</body></html>";
|
"</body></html>";
|
||||||
@ -521,6 +563,22 @@ public:
|
|||||||
CefRefPtr<CefV8Value> doneFunc =
|
CefRefPtr<CefV8Value> doneFunc =
|
||||||
CefV8Value::CreateFunction("end", funcHandler);
|
CefV8Value::CreateFunction("end", funcHandler);
|
||||||
object->SetValue("end", doneFunc);
|
object->SetValue("end", doneFunc);
|
||||||
|
|
||||||
|
CefRefPtr<CefV8Value> compFunc =
|
||||||
|
CefV8Value::CreateFunction("comp", funcHandler);
|
||||||
|
object->SetValue("comp", compFunc);
|
||||||
|
|
||||||
|
// Create an object with accessor based properties:
|
||||||
|
CefRefPtr<CefBase> blankBase;
|
||||||
|
CefRefPtr<CefV8Accessor> accessor(new DelegatingV8Accessor(this));
|
||||||
|
CefRefPtr<CefV8Value> point = CefV8Value::CreateObject(blankBase, accessor);
|
||||||
|
|
||||||
|
point->SetValue("x", V8_ACCESS_CONTROL_DEFAULT,
|
||||||
|
V8_PROPERTY_ATTRIBUTE_READONLY);
|
||||||
|
point->SetValue("y", V8_ACCESS_CONTROL_DEFAULT,
|
||||||
|
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||||
|
|
||||||
|
object->SetValue("point", point);
|
||||||
|
|
||||||
return RV_HANDLED;
|
return RV_HANDLED;
|
||||||
}
|
}
|
||||||
@ -581,15 +639,37 @@ public:
|
|||||||
void AsyncTestNavigation(CefRefPtr<CefV8Context> context,
|
void AsyncTestNavigation(CefRefPtr<CefV8Context> context,
|
||||||
CefRefPtr<CefV8Value> func)
|
CefRefPtr<CefV8Value> func)
|
||||||
{
|
{
|
||||||
CefV8ValueList args;
|
|
||||||
args.push_back(CefV8Value::CreateString("http://tests/end.html"));
|
|
||||||
CefRefPtr<CefV8Value> rv;
|
|
||||||
CefString exception;
|
CefString exception;
|
||||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
CefV8ValueList args;
|
||||||
ASSERT_TRUE(func->ExecuteFunctionWithContext(context, global, args, rv,
|
CefRefPtr<CefV8Value> rv, obj, url;
|
||||||
exception));
|
|
||||||
if(exception.empty())
|
// Need to enter the context in order to create an Object,
|
||||||
got_navigation_.yes();
|
// Array, or Function. Simple types like String, Int,
|
||||||
|
// Boolean, and Double don't require you to be in the
|
||||||
|
// context before creating them.
|
||||||
|
if ( context->Enter() ) {
|
||||||
|
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||||
|
CefRefPtr<CefV8Value> anArray = CefV8Value::CreateArray();
|
||||||
|
CefRefPtr<CefV8Handler> funcHandler(new DelegatingV8Handler(this));
|
||||||
|
CefRefPtr<CefV8Value> foobarFunc =
|
||||||
|
CefV8Value::CreateFunction("foobar", funcHandler);
|
||||||
|
|
||||||
|
obj = CefV8Value::CreateObject(NULL);
|
||||||
|
url = CefV8Value::CreateString("http://tests/end.html");
|
||||||
|
|
||||||
|
obj->SetValue("url", url);
|
||||||
|
obj->SetValue("foobar", foobarFunc);
|
||||||
|
obj->SetValue("anArray", anArray);
|
||||||
|
|
||||||
|
args.push_back(obj);
|
||||||
|
|
||||||
|
ASSERT_TRUE(func->ExecuteFunctionWithContext(context, global, args, rv,
|
||||||
|
exception));
|
||||||
|
if(exception.empty())
|
||||||
|
got_navigation_.yes();
|
||||||
|
|
||||||
|
context->Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Execute(const CefString& name,
|
bool Execute(const CefString& name,
|
||||||
@ -666,6 +746,25 @@ public:
|
|||||||
&TestContextHandler::AsyncTestNavigation, cc, funcNavigate));
|
&TestContextHandler::AsyncTestNavigation, cc, funcNavigate));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (name == "comp") {
|
||||||
|
if(arguments.size() == 3)
|
||||||
|
{
|
||||||
|
CefRefPtr<CefV8Value> expected = arguments[0];
|
||||||
|
CefRefPtr<CefV8Value> one = arguments[1];
|
||||||
|
CefRefPtr<CefV8Value> two = arguments[2];
|
||||||
|
|
||||||
|
bool bExpected = expected->GetBoolValue();
|
||||||
|
bool bOne2Two = one->IsSame(two);
|
||||||
|
bool bTwo2One = two->IsSame(one);
|
||||||
|
|
||||||
|
// IsSame should match the expected
|
||||||
|
if ( bExpected != bOne2Two || bExpected != bTwo2One)
|
||||||
|
got_bad_is_same_.yes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
got_bad_is_same_.yes();
|
||||||
|
}
|
||||||
} else if (name == "end") {
|
} else if (name == "end") {
|
||||||
got_testcomplete_.yes();
|
got_testcomplete_.yes();
|
||||||
DestroyTest();
|
DestroyTest();
|
||||||
@ -673,13 +772,44 @@ public:
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Get(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
CefRefPtr<CefV8Value>& retval)
|
||||||
|
{
|
||||||
|
if(name == "x") {
|
||||||
|
got_point_x_read_.yes();
|
||||||
|
retval = CefV8Value::CreateInt(1234);
|
||||||
|
return true;
|
||||||
|
} else if(name == "y") {
|
||||||
|
got_point_y_read_.yes();
|
||||||
|
retval = CefV8Value::CreateInt(y_);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Set(const CefString& name, const CefRefPtr<CefV8Value> object,
|
||||||
|
const CefRefPtr<CefV8Value> value)
|
||||||
|
{
|
||||||
|
if(name == "y") {
|
||||||
|
y_ = value->GetIntValue();
|
||||||
|
if( y_ == 1234)
|
||||||
|
got_point_y_write_.yes();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// This function we will be called later to make it call into the
|
// This function we will be called later to make it call into the
|
||||||
// IFRAME, which then calls "fromIFrame" so that we can check the
|
// IFRAME, which then calls "fromIFrame" so that we can check the
|
||||||
// entered vs current contexts are working as expected.
|
// entered vs current contexts are working as expected.
|
||||||
CefRefPtr<CefV8Context> contextIFrame_;
|
CefRefPtr<CefV8Context> contextIFrame_;
|
||||||
CefRefPtr<CefV8Value> funcIFrame_;
|
CefRefPtr<CefV8Value> funcIFrame_;
|
||||||
|
|
||||||
|
TrackCallback got_point_x_read_;
|
||||||
|
TrackCallback got_point_y_read_;
|
||||||
|
TrackCallback got_point_y_write_;
|
||||||
|
TrackCallback got_bad_is_same_;
|
||||||
TrackCallback got_hello_main_;
|
TrackCallback got_hello_main_;
|
||||||
TrackCallback got_hello_iframe_;
|
TrackCallback got_hello_iframe_;
|
||||||
TrackCallback got_correct_entered_url_;
|
TrackCallback got_correct_entered_url_;
|
||||||
@ -689,6 +819,8 @@ public:
|
|||||||
TrackCallback got_exception_;
|
TrackCallback got_exception_;
|
||||||
TrackCallback got_navigation_;
|
TrackCallback got_navigation_;
|
||||||
TrackCallback got_testcomplete_;
|
TrackCallback got_testcomplete_;
|
||||||
|
|
||||||
|
int y_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -699,6 +831,10 @@ TEST(V8Test, Context)
|
|||||||
CefRefPtr<TestContextHandler> handler = new TestContextHandler();
|
CefRefPtr<TestContextHandler> handler = new TestContextHandler();
|
||||||
handler->ExecuteTest();
|
handler->ExecuteTest();
|
||||||
|
|
||||||
|
EXPECT_TRUE(handler->got_point_x_read_);
|
||||||
|
EXPECT_TRUE(handler->got_point_y_read_);
|
||||||
|
EXPECT_TRUE(handler->got_point_y_write_);
|
||||||
|
EXPECT_FALSE(handler->got_bad_is_same_);
|
||||||
EXPECT_TRUE(handler->got_hello_main_);
|
EXPECT_TRUE(handler->got_hello_main_);
|
||||||
EXPECT_TRUE(handler->got_hello_iframe_);
|
EXPECT_TRUE(handler->got_hello_iframe_);
|
||||||
EXPECT_TRUE(handler->got_no_context_);
|
EXPECT_TRUE(handler->got_no_context_);
|
||||||
|
Reference in New Issue
Block a user