mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add the CEF translator tool for generating the C API header and cpptoc/ctocpp wrapper files.
- Update to files generated by the CEF translator tool. This introduces minor changes in cef.h and cef_capi.h for naming and translation consistency. - C API global function names that were previously in the cef_create_classname*() format are now in the cef_classname_create*() format. - cef_frame_t::get_frame_names() now returns void instead of size_t. - cef_frame_t::execute_javascript() has been renamed to cef_frame_t::execute_java_script(). - The 'arguments' attribute of CefV8Handler::Execute() and CefV8Value::ExecuteFunction() is now const. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@30 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -1,193 +1,111 @@
|
||||
// Copyright (c) 2009 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.
|
||||
|
||||
#ifndef _CTOCPP_H
|
||||
#define _CTOCPP_H
|
||||
|
||||
#include "cef.h"
|
||||
// Copyright (c) 2009 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.
|
||||
|
||||
#ifndef _CTOCPP_H
|
||||
#define _CTOCPP_H
|
||||
|
||||
#include "cef.h"
|
||||
#include "cef_capi.h"
|
||||
#include "../cef_logging.h"
|
||||
|
||||
|
||||
// Wrap a C structure with a C++ class. This is used when the implementation
|
||||
// exists on the other side of the DLL boundary but will have methods called on
|
||||
// this side of the DLL boundary.
|
||||
#include "../cef_logging.h"
|
||||
|
||||
|
||||
// Wrap a C structure with a C++ class. This is used when the implementation
|
||||
// exists on the other side of the DLL boundary but will have methods called on
|
||||
// this side of the DLL boundary.
|
||||
template <class ClassName, class BaseName, class StructName>
|
||||
class CefCToCpp : public CefThreadSafeBase<BaseName>
|
||||
{
|
||||
public:
|
||||
// Use this method to create a wrapper class instance for a structure
|
||||
// received from the other side.
|
||||
static CefRefPtr<BaseName> Wrap(StructName* s)
|
||||
{
|
||||
// Wrap their structure with the CefCToCpp object.
|
||||
public:
|
||||
// Use this method to create a wrapper class instance for a structure
|
||||
// received from the other side.
|
||||
static CefRefPtr<BaseName> Wrap(StructName* s)
|
||||
{
|
||||
// Wrap their structure with the CefCToCpp object.
|
||||
ClassName* wrapper = new ClassName(s);
|
||||
// Put the wrapper object in a smart pointer.
|
||||
CefRefPtr<BaseName> wrapperPtr(wrapper);
|
||||
// Release the reference that was added to the CefCppToC wrapper object on
|
||||
// the other side before their structure was passed to us.
|
||||
wrapper->UnderlyingRelease();
|
||||
// Return the smart pointer.
|
||||
return wrapperPtr;
|
||||
}
|
||||
|
||||
// Use this method to retrieve the underlying structure from a wrapper class
|
||||
// instance for return back to the other side.
|
||||
static StructName* Unwrap(CefRefPtr<BaseName> c)
|
||||
{
|
||||
// Cast the object to our wrapper class type.
|
||||
ClassName* wrapper = static_cast<ClassName*>(c.get());
|
||||
// Add a reference to the CefCppToC wrapper object on the other side that
|
||||
// will be released once the structure is received.
|
||||
wrapper->UnderlyingAddRef();
|
||||
// Return their original structure.
|
||||
return wrapper->GetStruct();
|
||||
}
|
||||
|
||||
CefCToCpp(StructName* str)
|
||||
: struct_(str)
|
||||
{
|
||||
DCHECK(str);
|
||||
|
||||
#ifdef _DEBUG
|
||||
CefAtomicIncrement(&DebugObjCt);
|
||||
#endif
|
||||
}
|
||||
virtual ~CefCToCpp()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
CefAtomicDecrement(&DebugObjCt);
|
||||
#endif
|
||||
}
|
||||
|
||||
// If returning the structure across the DLL boundary you should call
|
||||
// UnderlyingAddRef() on this wrapping CefCToCpp object. On the other side of
|
||||
// the DLL boundary, call Release() on the CefCppToC object.
|
||||
StructName* GetStruct() { return struct_; }
|
||||
|
||||
// CefBase methods increment/decrement reference counts on both this object
|
||||
// and the underlying wrapped structure.
|
||||
CefRefPtr<BaseName> wrapperPtr(wrapper);
|
||||
// Release the reference that was added to the CefCppToC wrapper object on
|
||||
// the other side before their structure was passed to us.
|
||||
wrapper->UnderlyingRelease();
|
||||
// Return the smart pointer.
|
||||
return wrapperPtr;
|
||||
}
|
||||
|
||||
// Use this method to retrieve the underlying structure from a wrapper class
|
||||
// instance for return back to the other side.
|
||||
static StructName* Unwrap(CefRefPtr<BaseName> c)
|
||||
{
|
||||
// Cast the object to our wrapper class type.
|
||||
ClassName* wrapper = static_cast<ClassName*>(c.get());
|
||||
// Add a reference to the CefCppToC wrapper object on the other side that
|
||||
// will be released once the structure is received.
|
||||
wrapper->UnderlyingAddRef();
|
||||
// Return their original structure.
|
||||
return wrapper->GetStruct();
|
||||
}
|
||||
|
||||
CefCToCpp(StructName* str)
|
||||
: struct_(str)
|
||||
{
|
||||
DCHECK(str);
|
||||
|
||||
#ifdef _DEBUG
|
||||
CefAtomicIncrement(&DebugObjCt);
|
||||
#endif
|
||||
}
|
||||
virtual ~CefCToCpp()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
CefAtomicDecrement(&DebugObjCt);
|
||||
#endif
|
||||
}
|
||||
|
||||
// If returning the structure across the DLL boundary you should call
|
||||
// UnderlyingAddRef() on this wrapping CefCToCpp object. On the other side of
|
||||
// the DLL boundary, call Release() on the CefCppToC object.
|
||||
StructName* GetStruct() { return struct_; }
|
||||
|
||||
// CefBase methods increment/decrement reference counts on both this object
|
||||
// and the underlying wrapped structure.
|
||||
virtual int AddRef()
|
||||
{
|
||||
UnderlyingAddRef();
|
||||
return CefThreadSafeBase<BaseName>::AddRef();
|
||||
}
|
||||
virtual int Release()
|
||||
{
|
||||
virtual int Release()
|
||||
{
|
||||
UnderlyingRelease();
|
||||
return CefThreadSafeBase<BaseName>::Release();
|
||||
}
|
||||
|
||||
// Increment/decrement reference counts on only the underlying class.
|
||||
int UnderlyingAddRef()
|
||||
{
|
||||
return CefThreadSafeBase<BaseName>::Release();
|
||||
}
|
||||
|
||||
// Increment/decrement reference counts on only the underlying class.
|
||||
int UnderlyingAddRef()
|
||||
{
|
||||
if(!struct_->base.add_ref)
|
||||
return 0;
|
||||
return struct_->base.add_ref(&struct_->base);
|
||||
}
|
||||
int UnderlyingRelease()
|
||||
{
|
||||
if(!struct_->base.release)
|
||||
return 0;
|
||||
return struct_->base.release(&struct_->base);
|
||||
}
|
||||
int UnderlyingGetRefCt()
|
||||
{
|
||||
if(!struct_->base.get_refct)
|
||||
return 0;
|
||||
return struct_->base.get_refct(&struct_->base);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Simple tracking of allocated objects.
|
||||
static long DebugObjCt;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
StructName* struct_;
|
||||
return struct_->base.add_ref(&struct_->base);
|
||||
}
|
||||
int UnderlyingRelease()
|
||||
{
|
||||
if(!struct_->base.release)
|
||||
return 0;
|
||||
return struct_->base.release(&struct_->base);
|
||||
}
|
||||
int UnderlyingGetRefCt()
|
||||
{
|
||||
if(!struct_->base.get_refct)
|
||||
return 0;
|
||||
return struct_->base.get_refct(&struct_->base);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Simple tracking of allocated objects.
|
||||
static long DebugObjCt;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
StructName* struct_;
|
||||
};
|
||||
|
||||
// CefCToCpp implementation for CefBase.
|
||||
class CefBaseCToCpp : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
// Use this method to create a wrapper class instance for a structure
|
||||
// received from the other side.
|
||||
static CefRefPtr<CefBase> Wrap(cef_base_t* s)
|
||||
{
|
||||
// Wrap their structure with the CefCToCpp object.
|
||||
CefBaseCToCpp* wrapper = new CefBaseCToCpp(s);
|
||||
// Put the wrapper object in a smart pointer.
|
||||
CefRefPtr<CefBase> wrapperPtr(wrapper);
|
||||
// Release the reference that was added to the CefCppToC wrapper object on
|
||||
// the other side before their structure was passed to us.
|
||||
wrapper->UnderlyingRelease();
|
||||
// Return the smart pointer.
|
||||
return wrapperPtr;
|
||||
}
|
||||
|
||||
// Use this method to retrieve the underlying structure from a wrapper class
|
||||
// instance for return back to the other side.
|
||||
static cef_base_t* Unwrap(CefRefPtr<CefBase> c)
|
||||
{
|
||||
// Cast the object to our wrapper class type.
|
||||
CefBaseCToCpp* wrapper = static_cast<CefBaseCToCpp*>(c.get());
|
||||
// Add a reference to the CefCppToC wrapper object on the other side that
|
||||
// will be released once the structure is received.
|
||||
wrapper->UnderlyingAddRef();
|
||||
// Return their original structure.
|
||||
return wrapper->GetStruct();
|
||||
}
|
||||
|
||||
CefBaseCToCpp(cef_base_t* str)
|
||||
: struct_(str)
|
||||
{
|
||||
DCHECK(str);
|
||||
}
|
||||
virtual ~CefBaseCToCpp() {}
|
||||
|
||||
// If returning the structure across the DLL boundary you should call
|
||||
// UnderlyingAddRef() on this wrapping CefCToCpp object. On the other side of
|
||||
// the DLL boundary, call Release() on the CefCppToC object.
|
||||
cef_base_t* GetStruct() { return struct_; }
|
||||
|
||||
// CefBase methods increment/decrement reference counts on both this object
|
||||
// and the underlying wrapped structure.
|
||||
virtual int AddRef()
|
||||
{
|
||||
UnderlyingAddRef();
|
||||
return CefThreadSafeBase<CefBase>::AddRef();
|
||||
}
|
||||
virtual int Release()
|
||||
{
|
||||
UnderlyingRelease();
|
||||
return CefThreadSafeBase<CefBase>::Release();
|
||||
}
|
||||
|
||||
// Increment/decrement reference counts on only the underlying class.
|
||||
int UnderlyingAddRef()
|
||||
{
|
||||
if(!struct_->add_ref)
|
||||
return 0;
|
||||
return struct_->add_ref(struct_);
|
||||
}
|
||||
int UnderlyingRelease()
|
||||
{
|
||||
if(!struct_->release)
|
||||
return 0;
|
||||
return struct_->release(struct_);
|
||||
}
|
||||
int UnderlyingGetRefCt()
|
||||
{
|
||||
if(!struct_->get_refct)
|
||||
return 0;
|
||||
return struct_->get_refct(struct_);
|
||||
}
|
||||
|
||||
protected:
|
||||
cef_base_t* struct_;
|
||||
};
|
||||
|
||||
|
||||
#endif // _CTOCPP_H
|
||||
#endif // _CTOCPP_H
|
||||
|
Reference in New Issue
Block a user