- 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:
Marshall Greenblatt
2011-04-07 01:58:49 +00:00
parent 36f3f3d021
commit 7ec29b5d87
19 changed files with 772 additions and 17 deletions

View 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

View 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

View File

@@ -79,6 +79,26 @@ struct _cef_v8value_t* CEF_CALLBACK v8context_get_global(
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.
@@ -88,6 +108,8 @@ CefV8ContextCppToC::CefV8ContextCppToC(CefV8Context* cls)
struct_.struct_.get_browser = v8context_get_browser;
struct_.struct_.get_frame = v8context_get_frame;
struct_.struct_.get_global = v8context_get_global;
struct_.struct_.enter = v8context_enter;
struct_.struct_.exit = v8context_exit;
}
#ifdef _DEBUG

View File

@@ -13,6 +13,7 @@
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
#include "libcef_dll/ctocpp/base_ctocpp.h"
#include "libcef_dll/ctocpp/v8accessor_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;
}
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()
{
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();
}
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)
{
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);
}
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,
cef_string_list_t keys)
{
@@ -442,6 +483,7 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls)
struct_.struct_.is_object = v8value_is_object;
struct_.struct_.is_array = v8value_is_array;
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_int_value = v8value_get_int_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_.set_value_bykey = v8value_set_value_bykey;
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_user_data = v8value_get_user_data;
struct_.struct_.get_array_length = v8value_get_array_length;

View 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

View 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

View File

@@ -73,6 +73,22 @@ CefRefPtr<CefV8Value> CefV8ContextCToCpp::GetGlobal()
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
template<> long CefCToCpp<CefV8ContextCToCpp, CefV8Context,

View File

@@ -34,6 +34,8 @@ public:
virtual CefRefPtr<CefBrowser> GetBrowser();
virtual CefRefPtr<CefFrame> GetFrame();
virtual CefRefPtr<CefV8Value> GetGlobal();
virtual bool Enter();
virtual bool Exit();
};
#endif // USING_CEF_SHARED

View File

@@ -11,6 +11,7 @@
//
#include "libcef_dll/cpptoc/base_cpptoc.h"
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
@@ -79,6 +80,24 @@ CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
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()
{
cef_v8value_t* impl = cef_v8value_create_array();
@@ -176,6 +195,14 @@ bool CefV8ValueCToCpp::IsFunction()
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()
{
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;
}
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)
{
if(CEF_MEMBER_MISSING(struct_, get_keys))

View File

@@ -40,6 +40,7 @@ public:
virtual bool IsObject();
virtual bool IsArray();
virtual bool IsFunction();
virtual bool IsSame(CefRefPtr<CefV8Value> that);
virtual bool GetBoolValue();
virtual int GetIntValue();
virtual double GetDoubleValue();
@@ -52,6 +53,8 @@ public:
virtual CefRefPtr<CefV8Value> GetValue(int index);
virtual bool SetValue(const CefString& key, 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 CefRefPtr<CefBase> GetUserData();
virtual int GetArrayLength();

View File

@@ -16,6 +16,7 @@
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/stream_reader_cpptoc.h"
#include "cpptoc/stream_writer_cpptoc.h"
#include "cpptoc/v8context_cpptoc.h"
#include "cpptoc/v8value_cpptoc.h"
#include "cpptoc/web_urlrequest_cpptoc.h"
#include "cpptoc/xml_reader_cpptoc.h"
@@ -28,6 +29,7 @@
#include "ctocpp/scheme_handler_ctocpp.h"
#include "ctocpp/scheme_handler_factory_ctocpp.h"
#include "ctocpp/task_ctocpp.h"
#include "ctocpp/v8accessor_ctocpp.h"
#include "ctocpp/v8handler_ctocpp.h"
#include "ctocpp/web_urlrequest_client_ctocpp.h"
#include "ctocpp/write_handler_ctocpp.h"
@@ -70,6 +72,7 @@ CEF_EXPORT void cef_shutdown()
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
DCHECK(CefV8ContextCppToC::DebugObjCt == 0);
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
DCHECK(CefWebURLRequestCppToC::DebugObjCt == 0);
DCHECK(CefXmlReaderCppToC::DebugObjCt == 0);
@@ -80,6 +83,7 @@ CEF_EXPORT void cef_shutdown()
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
DCHECK(CefV8AccessorCToCpp::DebugObjCt == 0);
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
DCHECK(CefWebURLRequestClientCToCpp::DebugObjCt == 0);
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);

View File

@@ -14,6 +14,7 @@
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
#include "libcef_dll/cpptoc/scheme_handler_factory_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/web_urlrequest_client_cpptoc.h"
#include "libcef_dll/cpptoc/write_handler_cpptoc.h"
@@ -51,6 +52,7 @@ void CefShutdown()
DCHECK(CefReadHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerFactoryCppToC::DebugObjCt == 0);
DCHECK(CefV8AccessorCppToC::DebugObjCt == 0);
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
DCHECK(CefWebURLRequestClientCppToC::DebugObjCt == 0);
DCHECK(CefWriteHandlerCppToC::DebugObjCt == 0);