- Move frame-related methods from CefBrowser into a new CefFrame class.

- Add CefBrowser::Get*Frame() methods for retrieving the appropriate CefFrame instance.
- Add a CefFrame attribute to CefHandler callback methods where appropriate.
- Add support for V8 JavaScript extensions and values via CefV8Value and CefV8Handler.  Native C++ and user-defined JavaScript object hierarchies may now be created and accessed using the CEF API.
- Remove the CefHandler and CefVariant classes and related CefBrowser methods that have been obsoleted by the addition of CEF V8 support.
- Add the CefRegisterExtension() function for registering system-wide V8 extensions.
- Add the CefHandler::HandleJSBinding() callback method for attaching V8 values to the global frame JavaScript object.  This method replaces the previous technique of calling CefBrowser::AddJSHandler().
- Add new wrapper template methods for simplifying DLL wrapper implementations.
- Move cef_string* files from libcef_dll to libcef so that projects can link libcef statically without errors.
- Fix crashes when CEF exits due to object constructors being executed on non-UI threads if the application is closed while a page is still loading.
- Update the cefclient project to reflect changes and demonstrate the new APIs.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@26 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2009-05-28 00:31:21 +00:00
parent 94dfad49d9
commit c295931b1e
74 changed files with 5168 additions and 4657 deletions

View File

@@ -4,10 +4,8 @@
#include "../precompiled_libcef.h"
#include "ctocpp/browser_ctocpp.h"
#include "ctocpp/request_ctocpp.h"
#include "ctocpp/stream_ctocpp.h"
#include "cpptoc/handler_cpptoc.h"
#include "cpptoc/jshandler_cpptoc.h"
#include "ctocpp/frame_ctocpp.h"
bool CefBrowserCToCpp::CanGoBack()
@@ -58,62 +56,6 @@ void CefBrowserCToCpp::StopLoad()
struct_->stop_load(struct_);
}
void CefBrowserCToCpp::Undo(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, undo))
return;
struct_->undo(struct_, targetFrame);
}
void CefBrowserCToCpp::Redo(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, redo))
return;
struct_->redo(struct_, targetFrame);
}
void CefBrowserCToCpp::Cut(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, cut))
return;
struct_->cut(struct_, targetFrame);
}
void CefBrowserCToCpp::Copy(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, copy))
return;
struct_->copy(struct_, targetFrame);
}
void CefBrowserCToCpp::Paste(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, paste))
return;
struct_->paste(struct_, targetFrame);
}
void CefBrowserCToCpp::Delete(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, del))
return;
struct_->del(struct_, targetFrame);
}
void CefBrowserCToCpp::SelectAll(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, select_all))
return;
struct_->select_all(struct_, targetFrame);
}
void CefBrowserCToCpp::SetFocus(bool enable)
{
if(CEF_MEMBER_MISSING(struct_, set_focus))
@@ -122,155 +64,6 @@ void CefBrowserCToCpp::SetFocus(bool enable)
struct_->set_focus(struct_, enable);
}
void CefBrowserCToCpp::Print(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, print))
return;
struct_->print(struct_, targetFrame);
}
void CefBrowserCToCpp::ViewSource(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, view_source))
return;
struct_->view_source(struct_, targetFrame);
}
std::wstring CefBrowserCToCpp::GetSource(TargetFrame targetFrame)
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_source))
return str;
cef_string_t cef_str = struct_->get_source(struct_, targetFrame);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefBrowserCToCpp::GetText(TargetFrame targetFrame)
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_text))
return str;
cef_string_t cef_str = struct_->get_text(struct_, targetFrame);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefBrowserCToCpp::LoadRequest(CefRefPtr<CefRequest> request)
{
if(CEF_MEMBER_MISSING(struct_, load_request))
return;
CefRequestCToCpp* rp = static_cast<CefRequestCToCpp*>(request.get());
rp->UnderlyingAddRef();
struct_->load_request(struct_, rp->GetStruct());
}
void CefBrowserCToCpp::LoadURL(const std::wstring& url,
const std::wstring& frame)
{
if(CEF_MEMBER_MISSING(struct_, load_url))
return;
struct_->load_url(struct_, url.c_str(), frame.c_str());
}
void CefBrowserCToCpp::LoadString(const std::wstring& string,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_string))
return;
struct_->load_string(struct_, string.c_str(), url.c_str());
}
void CefBrowserCToCpp::LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_stream))
return;
CefStreamReaderCToCpp* sp =
static_cast<CefStreamReaderCToCpp*>(stream.get());
sp->UnderlyingAddRef();
struct_->load_stream(struct_, sp->GetStruct(), url.c_str());
}
void CefBrowserCToCpp::ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line,
TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, execute_javascript))
return;
struct_->execute_javascript(struct_, js_code.c_str(), script_url.c_str(),
start_line, targetFrame);
}
bool CefBrowserCToCpp::AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler)
{
if(CEF_MEMBER_MISSING(struct_, add_jshandler))
return false;
CefJSHandlerCppToC* hp = new CefJSHandlerCppToC(handler);
hp->AddRef();
return struct_->add_jshandler(struct_, classname.c_str(), hp->GetStruct());
return true;
}
bool CefBrowserCToCpp::HasJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, has_jshandler))
return false;
return struct_->has_jshandler(struct_, classname.c_str());
}
CefRefPtr<CefJSHandler> CefBrowserCToCpp::GetJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, get_jshandler))
return NULL;
CefJSHandlerCppToC::Struct* hp =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(
struct_->get_jshandler(struct_, classname.c_str()));
if(hp) {
CefRefPtr<CefJSHandler> handlerPtr(hp->class_->GetClass());
hp->class_->UnderlyingRelease();
return handlerPtr;
}
return NULL;
}
bool CefBrowserCToCpp::RemoveJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, remove_jshandler))
return false;
return struct_->remove_jshandler(struct_, classname.c_str());
}
void CefBrowserCToCpp::RemoveAllJSHandlers()
{
if(CEF_MEMBER_MISSING(struct_, remove_all_jshandlers))
return;
struct_->remove_all_jshandlers(struct_);
}
CefWindowHandle CefBrowserCToCpp::GetWindowHandle()
{
if(CEF_MEMBER_MISSING(struct_, get_window_handle))
@@ -291,33 +84,69 @@ CefRefPtr<CefHandler> CefBrowserCToCpp::GetHandler()
{
if(CEF_MEMBER_MISSING(struct_, get_handler))
return NULL;
CefHandlerCppToC::Struct* hp =
reinterpret_cast<CefHandlerCppToC::Struct*>(
struct_->get_handler(struct_));
if(hp) {
CefRefPtr<CefHandler> handlerPtr(hp->class_->GetClass());
hp->class_->UnderlyingRelease();
return handlerPtr;
}
cef_handler_t* handlerStruct = struct_->get_handler(struct_);
if(handlerStruct)
return CefHandlerCppToC::Unwrap(handlerStruct);
return NULL;
}
std::wstring CefBrowserCToCpp::GetURL()
CefRefPtr<CefFrame> CefBrowserCToCpp::GetMainFrame()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_url))
return str;
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_string_t cef_str = struct_->get_url(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
cef_frame_t* frameStruct = struct_->get_main_frame(struct_);
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
CefRefPtr<CefFrame> CefBrowserCToCpp::GetFocusedFrame()
{
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_frame_t* frameStruct = struct_->get_focused_frame(struct_);
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
CefRefPtr<CefFrame> CefBrowserCToCpp::GetFrame(const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_frame_t* frameStruct = struct_->get_frame(struct_, name.c_str());
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
void CefBrowserCToCpp::GetFrameNames(std::vector<std::wstring>& names)
{
if(CEF_MEMBER_MISSING(struct_, get_frame_names))
return;
cef_string_list_t list = cef_string_list_alloc();
struct_->get_frame_names(struct_, list);
cef_string_t str;
int size = cef_string_list_size(list);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(list, i);
names.push_back(str);
cef_string_free(str);
}
return str;
cef_string_list_free(list);
}
#ifdef _DEBUG
long CefCToCpp<CefBrowser, cef_browser_t>::DebugObjCt = 0;
long CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>::DebugObjCt = 0;
#endif

View File

@@ -16,11 +16,12 @@
// Wrap a C browser structure with a C++ browser class.
// This class may be instantiated and accessed wrapper-side only.
class CefBrowserCToCpp : public CefCToCpp<CefBrowser, cef_browser_t>
class CefBrowserCToCpp
: public CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>
{
public:
CefBrowserCToCpp(cef_browser_t* str)
: CefCToCpp<CefBrowser, cef_browser_t>(str) {}
: CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>(str) {}
virtual ~CefBrowserCToCpp() {}
// CefBrowser methods
@@ -30,37 +31,14 @@ public:
virtual void GoForward();
virtual void Reload();
virtual void StopLoad();
virtual void Undo(TargetFrame targetFrame);
virtual void Redo(TargetFrame targetFrame);
virtual void Cut(TargetFrame targetFrame);
virtual void Copy(TargetFrame targetFrame);
virtual void Paste(TargetFrame targetFrame);
virtual void Delete(TargetFrame targetFrame);
virtual void SelectAll(TargetFrame targetFrame);
virtual void SetFocus(bool enable);
virtual void Print(TargetFrame targetFrame);
virtual void ViewSource(TargetFrame targetFrame);
virtual std::wstring GetSource(TargetFrame targetFrame);
virtual std::wstring GetText(TargetFrame targetFrame);
virtual void LoadRequest(CefRefPtr<CefRequest> request);
virtual void LoadURL(const std::wstring& url, const std::wstring& frame);
virtual void LoadString(const std::wstring& string,
const std::wstring& url);
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
virtual void ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line, TargetFrame targetFrame);
virtual bool AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler);
virtual bool HasJSHandler(const std::wstring& classname);
virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& classname);
virtual bool RemoveJSHandler(const std::wstring& classname);
virtual void RemoveAllJSHandlers();
virtual CefWindowHandle GetWindowHandle();
virtual bool IsPopup();
virtual CefRefPtr<CefHandler> GetHandler();
virtual std::wstring GetURL();
virtual CefRefPtr<CefFrame> GetMainFrame();
virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
virtual void GetFrameNames(std::vector<std::wstring>& names);
};

View File

@@ -10,11 +10,41 @@
#include "../cef_logging.h"
// Wrap a C structure with a C++ class.
template <class ClassName, class StructName>
class CefCToCpp : public CefThreadSafeBase<ClassName>
// 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.
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)
{
@@ -41,12 +71,12 @@ public:
virtual int AddRef()
{
UnderlyingAddRef();
return CefThreadSafeBase<ClassName>::AddRef();
return CefThreadSafeBase<BaseName>::AddRef();
}
virtual int Release()
{
UnderlyingRelease();
return CefThreadSafeBase<ClassName>::Release();
return CefThreadSafeBase<BaseName>::Release();
}
// Increment/decrement reference counts on only the underlying class.
@@ -77,6 +107,87 @@ public:
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

View File

@@ -0,0 +1,203 @@
// 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.
#include "../precompiled_libcef.h"
#include "ctocpp/frame_ctocpp.h"
#include "ctocpp/request_ctocpp.h"
#include "ctocpp/stream_ctocpp.h"
void CefFrameCToCpp::Undo()
{
if(CEF_MEMBER_MISSING(struct_, undo))
return;
struct_->undo(struct_);
}
void CefFrameCToCpp::Redo()
{
if(CEF_MEMBER_MISSING(struct_, redo))
return;
struct_->redo(struct_);
}
void CefFrameCToCpp::Cut()
{
if(CEF_MEMBER_MISSING(struct_, cut))
return;
struct_->cut(struct_);
}
void CefFrameCToCpp::Copy()
{
if(CEF_MEMBER_MISSING(struct_, copy))
return;
struct_->copy(struct_);
}
void CefFrameCToCpp::Paste()
{
if(CEF_MEMBER_MISSING(struct_, paste))
return;
struct_->paste(struct_);
}
void CefFrameCToCpp::Delete()
{
if(CEF_MEMBER_MISSING(struct_, del))
return;
struct_->del(struct_);
}
void CefFrameCToCpp::SelectAll()
{
if(CEF_MEMBER_MISSING(struct_, select_all))
return;
struct_->select_all(struct_);
}
void CefFrameCToCpp::Print()
{
if(CEF_MEMBER_MISSING(struct_, print))
return;
struct_->print(struct_);
}
void CefFrameCToCpp::ViewSource()
{
if(CEF_MEMBER_MISSING(struct_, view_source))
return;
struct_->view_source(struct_);
}
std::wstring CefFrameCToCpp::GetSource()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_source))
return str;
cef_string_t cef_str = struct_->get_source(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefFrameCToCpp::GetText()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_text))
return str;
cef_string_t cef_str = struct_->get_text(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefFrameCToCpp::LoadRequest(CefRefPtr<CefRequest> request)
{
if(CEF_MEMBER_MISSING(struct_, load_request))
return;
struct_->load_request(struct_, CefRequestCToCpp::Unwrap(request));
}
void CefFrameCToCpp::LoadURL(const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_url))
return;
struct_->load_url(struct_, url.c_str());
}
void CefFrameCToCpp::LoadString(const std::wstring& string,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_string))
return;
struct_->load_string(struct_, string.c_str(), url.c_str());
}
void CefFrameCToCpp::LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_stream))
return;
struct_->load_stream(struct_, CefStreamReaderCToCpp::Unwrap(stream),
url.c_str());
}
void CefFrameCToCpp::ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line)
{
if(CEF_MEMBER_MISSING(struct_, execute_javascript))
return;
struct_->execute_javascript(struct_, js_code.c_str(), script_url.c_str(),
start_line);
}
bool CefFrameCToCpp::IsMain()
{
if(CEF_MEMBER_MISSING(struct_, is_main))
return false;
return struct_->is_main(struct_);
}
bool CefFrameCToCpp::IsFocused()
{
if(CEF_MEMBER_MISSING(struct_, is_focused))
return false;
return struct_->is_focused(struct_);
}
std::wstring CefFrameCToCpp::GetName()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_name))
return str;
cef_string_t cef_str = struct_->get_name(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefFrameCToCpp::GetURL()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_url))
return str;
cef_string_t cef_str = struct_->get_url(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
#ifdef _DEBUG
long CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>::DebugObjCt = 0;
#endif

View File

@@ -0,0 +1,55 @@
// 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 _FRAME_CTOCPP_H
#define _FRAME_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C frame structure with a C++ frame class.
// This class may be instantiated and accessed wrapper-side only.
class CefFrameCToCpp : public CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>
{
public:
CefFrameCToCpp(cef_frame_t* str)
: CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>(str) {}
virtual ~CefFrameCToCpp() {}
// CefFrame methods
virtual void Undo();
virtual void Redo();
virtual void Cut();
virtual void Copy();
virtual void Paste();
virtual void Delete();
virtual void SelectAll();
virtual void Print();
virtual void ViewSource();
virtual std::wstring GetSource();
virtual std::wstring GetText();
virtual void LoadRequest(CefRefPtr<CefRequest> request);
virtual void LoadURL(const std::wstring& url);
virtual void LoadString(const std::wstring& string,
const std::wstring& url);
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine);
virtual bool IsMain();
virtual bool IsFocused();
virtual std::wstring GetName();
virtual std::wstring GetURL();
};
#endif // USING_CEF_SHARED
#endif // _FRAME_CTOCPP_H

View File

@@ -4,8 +4,10 @@
#include "../precompiled_libcef.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/frame_cpptoc.h"
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/stream_cpptoc.h"
#include "cpptoc/v8value_cpptoc.h"
#include "ctocpp/handler_ctocpp.h"
#include "transfer_util.h"
@@ -17,38 +19,28 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
if(CEF_MEMBER_MISSING(struct_, handle_before_created))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = NULL;
cef_browser_t* browserStructPtr = NULL;
if(parentBrowser.get()) {
browserPtr = new CefBrowserCppToC(parentBrowser);
browserPtr->AddRef();
browserStructPtr = browserPtr->GetStruct();
}
cef_browser_t* browserStruct = NULL;
if(parentBrowser.get())
browserStruct = CefBrowserCppToC::Wrap(parentBrowser);
CefHandlerCToCpp* handlerPtr = NULL;
cef_handler_t* handlerRet = NULL;
if(handler.get()) {
handlerPtr = static_cast<CefHandlerCToCpp*>(handler.get());
handlerPtr->UnderlyingAddRef();
handlerRet = handlerPtr->GetStruct();
}
cef_handler_t* handlerStruct = NULL;
if(handler.get())
handlerStruct = CefHandlerCToCpp::Unwrap(handler);
cef_handler_t *origHandlerStruct = handlerStruct;
cef_string_t urlRet = NULL;
if(!url.empty())
urlRet = cef_string_alloc(url.c_str());
cef_retval_t rv = struct_->handle_before_created(struct_,
browserStructPtr, &windowInfo, popup, &handlerRet, &urlRet);
browserStruct, &windowInfo, popup, &handlerStruct, &urlRet);
if(handlerPtr && handlerRet != handlerPtr->GetStruct()) {
if(handlerStruct && handlerStruct != origHandlerStruct) {
// The handler was changed.
if(handlerRet) {
CefHandlerCToCpp* hp = new CefHandlerCToCpp(handlerRet);
handler = hp;
hp->UnderlyingRelease();
} else {
if(handlerStruct)
handler = CefHandlerCToCpp::Wrap(handlerStruct);
else
handler = NULL;
}
}
transfer_string_contents(urlRet, url, true);
@@ -62,20 +54,19 @@ CefHandler::RetVal CefHandlerCToCpp::HandleAfterCreated(
if(CEF_MEMBER_MISSING(struct_, handle_after_created))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_after_created(struct_, browserPtr->GetStruct());
return struct_->handle_after_created(struct_,
CefBrowserCppToC::Wrap(browser));
}
CefHandler::RetVal CefHandlerCToCpp::HandleAddressChange(
CefRefPtr<CefBrowser> browser, const std::wstring& url)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, handle_address_change))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_address_change(struct_, browserPtr->GetStruct(),
return struct_->handle_address_change(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
url.c_str());
}
@@ -85,69 +76,64 @@ CefHandler::RetVal CefHandlerCToCpp::HandleTitleChange(
if(CEF_MEMBER_MISSING(struct_, handle_title_change))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_title_change(struct_, browserPtr->GetStruct(),
return struct_->handle_title_change(struct_, CefBrowserCppToC::Wrap(browser),
title.c_str());
}
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeBrowse(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request, NavType navType, bool isRedirect)
{
if(CEF_MEMBER_MISSING(struct_, handle_before_browse))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefRequestCppToC* requestPtr = new CefRequestCppToC(request);
requestPtr->AddRef();
return struct_->handle_before_browse(struct_, browserPtr->GetStruct(),
requestPtr->GetStruct(), navType, isRedirect);
return struct_->handle_before_browse(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), CefRequestCppToC::Wrap(request),
navType, isRedirect);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadStart(
CefRefPtr<CefBrowser> browser)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_start))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_frame_t* frameStruct = NULL;
if(frame.get())
frameStruct = CefFrameCppToC::Wrap(frame);
return struct_->handle_load_start(struct_, browserPtr->GetStruct());
return struct_->handle_load_start(struct_, CefBrowserCppToC::Wrap(browser),
frameStruct);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadEnd(
CefRefPtr<CefBrowser> browser)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_end))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_frame_t* frameStruct = NULL;
if(frame.get())
frameStruct = CefFrameCppToC::Wrap(frame);
return struct_->handle_load_end(struct_, browserPtr->GetStruct());
return struct_->handle_load_end(struct_, CefBrowserCppToC::Wrap(browser),
frameStruct);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadError(
CefRefPtr<CefBrowser> browser, ErrorCode errorCode,
const std::wstring& failedUrl, std::wstring& errorText)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
ErrorCode errorCode, const std::wstring& failedUrl, std::wstring& errorText)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_error))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t errorTextRet = NULL;
if(!errorText.empty())
errorTextRet = cef_string_alloc(errorText.c_str());
cef_retval_t rv = struct_->handle_load_error(struct_, browserPtr->GetStruct(),
errorCode, failedUrl.c_str(), &errorTextRet);
cef_retval_t rv = struct_->handle_load_error(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame), errorCode,
failedUrl.c_str(), &errorTextRet);
transfer_string_contents(errorTextRet, errorText, true);
@@ -162,12 +148,6 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
if(CEF_MEMBER_MISSING(struct_, handle_before_resource_load))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefRequestCppToC* requestPtr = new CefRequestCppToC(request);
requestPtr->AddRef();
cef_string_t redirectUrlRet = NULL;
cef_string_t mimeTypeRet = NULL;
cef_stream_reader_t* streamRet = NULL;
@@ -176,18 +156,14 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
redirectUrlRet = cef_string_alloc(redirectUrl.c_str());
cef_retval_t rv = struct_->handle_before_resource_load(struct_,
browserPtr->GetStruct(), requestPtr->GetStruct(), &redirectUrlRet,
&streamRet, &mimeTypeRet, loadFlags);
CefBrowserCppToC::Wrap(browser), CefRequestCppToC::Wrap(request),
&redirectUrlRet, &streamRet, &mimeTypeRet, loadFlags);
transfer_string_contents(redirectUrlRet, redirectUrl, true);
transfer_string_contents(mimeTypeRet, mimeType, true);
if(streamRet) {
CefStreamReaderCppToC::Struct* sp =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(streamRet);
resourceStream = sp->class_->GetClass();
sp->class_->Release();
}
if(streamRet)
resourceStream = CefStreamReaderCppToC::Unwrap(streamRet);
return rv;
}
@@ -198,10 +174,7 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu(
if(CEF_MEMBER_MISSING(struct_, handle_before_menu))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_before_menu(struct_, browserPtr->GetStruct(),
return struct_->handle_before_menu(struct_, CefBrowserCppToC::Wrap(browser),
&menuInfo);
}
@@ -211,15 +184,12 @@ CefHandler::RetVal CefHandlerCToCpp::HandleGetMenuLabel(
if(CEF_MEMBER_MISSING(struct_, handle_get_menu_label))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t labelRet = NULL;
if(!label.empty())
labelRet = cef_string_alloc(label.c_str());
cef_retval_t rv = struct_->handle_get_menu_label(struct_,
browserPtr->GetStruct(), menuId, &labelRet);
CefBrowserCppToC::Wrap(browser), menuId, &labelRet);
transfer_string_contents(labelRet, label, true);
@@ -232,25 +202,20 @@ CefHandler::RetVal CefHandlerCToCpp::HandleMenuAction(
if(CEF_MEMBER_MISSING(struct_, handle_menu_action))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_menu_action(struct_, browserPtr->GetStruct(), menuId);
return struct_->handle_menu_action(struct_, CefBrowserCppToC::Wrap(browser),
menuId);
}
CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
CefRefPtr<CefBrowser> browser, CefPrintInfo& printInfo,
const std::wstring& url, const std::wstring& title, int currentPage,
int maxPages, std::wstring& topLeft, std::wstring& topCenter,
std::wstring& topRight, std::wstring& bottomLeft,
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo, const std::wstring& url, const std::wstring& title,
int currentPage, int maxPages, std::wstring& topLeft,
std::wstring& topCenter, std::wstring& topRight, std::wstring& bottomLeft,
std::wstring& bottomCenter, std::wstring& bottomRight)
{
if(CEF_MEMBER_MISSING(struct_, handle_print_header_footer))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t topLeftRet = NULL, topCenterRet = NULL, topRightRet = NULL,
bottomLeftRet = NULL, bottomCenterRet = NULL, bottomRightRet = NULL;
@@ -268,9 +233,10 @@ CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
bottomRightRet = cef_string_alloc(bottomRight.c_str());
cef_retval_t rv = struct_->handle_print_header_footer(struct_,
browserPtr->GetStruct(), &printInfo, url.c_str(), title.c_str(),
currentPage, maxPages, &topLeftRet, &topCenterRet, &topRightRet,
&bottomLeftRet, &bottomCenterRet, &bottomRightRet);
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
&printInfo, url.c_str(), title.c_str(), currentPage, maxPages,
&topLeftRet, &topCenterRet, &topRightRet, &bottomLeftRet,
&bottomCenterRet, &bottomRightRet);
transfer_string_contents(topLeftRet, topLeft, true);
transfer_string_contents(topCenterRet, topCenter, true);
@@ -283,50 +249,46 @@ CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSAlert(
CefRefPtr<CefBrowser> browser, const std::wstring& message)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsalert))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_jsalert(struct_, browserPtr->GetStruct(),
message.c_str());
return struct_->handle_jsalert(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), message.c_str());
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSConfirm(
CefRefPtr<CefBrowser> browser, const std::wstring& message, bool& retval)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsconfirm))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
int ret = 0;
cef_retval_t rv = struct_->handle_jsconfirm(struct_, browserPtr->GetStruct(),
cef_retval_t rv = struct_->handle_jsconfirm(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
message.c_str(), &ret);
retval = (ret ? true : false);
return rv;
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSPrompt(
CefRefPtr<CefBrowser> browser, const std::wstring& message,
const std::wstring& defaultValue, bool& retval, std::wstring& result)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message, const std::wstring& defaultValue, bool& retval,
std::wstring& result)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsprompt))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t resultRet = NULL;
if(!result.empty())
resultRet = cef_string_alloc(result.c_str());
int ret = 0;
cef_retval_t rv = struct_->handle_jsprompt(struct_, browserPtr->GetStruct(),
cef_retval_t rv = struct_->handle_jsprompt(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
message.c_str(), defaultValue.c_str(), &ret, &resultRet);
retval = (ret ? true : false);
@@ -341,10 +303,8 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeWindowClose(
if(CEF_MEMBER_MISSING(struct_, handle_before_window_close))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_before_window_close(struct_, browserPtr->GetStruct());
return struct_->handle_before_window_close(struct_,
CefBrowserCppToC::Wrap(browser));
}
CefHandler::RetVal CefHandlerCToCpp::HandleTakeFocus(
@@ -353,12 +313,21 @@ CefHandler::RetVal CefHandlerCToCpp::HandleTakeFocus(
if(CEF_MEMBER_MISSING(struct_, handle_take_focus))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_take_focus(struct_, CefBrowserCppToC::Wrap(browser),
reverse);
}
return struct_->handle_take_focus(struct_, browserPtr->GetStruct(), reverse);
CefHandler::RetVal CefHandlerCToCpp::HandleJSBinding(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsbinding))
return RV_CONTINUE;
return struct_->handle_jsbinding(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), CefV8ValueCppToC::Wrap(object));
}
#ifdef _DEBUG
long CefCToCpp<CefHandler, cef_handler_t>::DebugObjCt = 0;
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
#endif

View File

@@ -16,11 +16,12 @@
// Wrap a C handler structure with a C++ handler class.
// This class may be instantiated and accessed DLL-side only.
class CefHandlerCToCpp : public CefCToCpp<CefHandler, cef_handler_t>
class CefHandlerCToCpp
: public CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>
{
public:
CefHandlerCToCpp(cef_handler_t* str)
: CefCToCpp<CefHandler, cef_handler_t>(str) {}
: CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>(str) {}
virtual ~CefHandlerCToCpp() {}
// CefHandler methods
@@ -30,15 +31,20 @@ public:
std::wstring& url);
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& url);
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
const std::wstring& title);
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect);
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const std::wstring& failedUrl,
std::wstring& errorText);
@@ -55,6 +61,7 @@ public:
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
MenuId menuId);
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo,
const std::wstring& url,
const std::wstring& title,
@@ -66,10 +73,13 @@ public:
std::wstring& bottomCenter,
std::wstring& bottomRight);
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message);
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval);
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message,
const std::wstring& default_value,
bool& retval,
@@ -77,6 +87,9 @@ public:
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser,
bool reverse);
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object);
};

View File

@@ -1,106 +0,0 @@
// 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.
#include "../precompiled_libcef.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/variant_cpptoc.h"
#include "ctocpp/jshandler_ctocpp.h"
bool CefJSHandlerCToCpp::HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->has_method(struct_, browserPtr->GetStruct(), name.c_str());
}
bool CefJSHandlerCToCpp::HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->has_property(struct_, browserPtr->GetStruct(), name.c_str());
}
bool CefJSHandlerCToCpp::SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* valuePtr = new CefVariantCppToC(value);
valuePtr->AddRef();
return struct_->set_property(struct_, browserPtr->GetStruct(), name.c_str(),
valuePtr->GetStruct());
}
bool CefJSHandlerCToCpp::GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* valuePtr = new CefVariantCppToC(value);
valuePtr->AddRef();
return struct_->get_property(struct_, browserPtr->GetStruct(), name.c_str(),
valuePtr->GetStruct());
}
bool CefJSHandlerCToCpp::ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* retvalPtr = new CefVariantCppToC(retval);
retvalPtr->AddRef();
cef_variant_t** argsStructPtr = NULL;
int argsSize = args.size();
if(argsSize > 0) {
CefVariantCppToC* vPtr;
argsStructPtr = new cef_variant_t*[argsSize];
for(int i = 0; i < argsSize; ++i) {
vPtr = new CefVariantCppToC(args[i]);
vPtr->AddRef();
argsStructPtr[i] = vPtr->GetStruct();
}
}
int rv = struct_->execute_method(struct_, browserPtr->GetStruct(),
name.c_str(), argsSize, argsStructPtr, retvalPtr->GetStruct());
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefJSHandler, cef_jshandler_t>::DebugObjCt = 0;
#endif

View File

@@ -1,45 +0,0 @@
// 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 _JSHANDLER_CTOCPP_H
#define _JSHANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C jshandler structure with a C++ jshandler class.
// This class may be instantiated and accessed DLL-side only.
class CefJSHandlerCToCpp : public CefCToCpp<CefJSHandler, cef_jshandler_t>
{
public:
CefJSHandlerCToCpp(cef_jshandler_t* str)
: CefCToCpp<CefJSHandler, cef_jshandler_t>(str) {}
virtual ~CefJSHandlerCToCpp() {}
// CefJSHandler methods
virtual bool HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name);
virtual bool HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name);
virtual bool SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value);
virtual bool GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value);
virtual bool ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval);
};
#endif // BUILDING_CEF_SHARED
#endif // _JSHANDLER_CTOCPP_H

View File

@@ -28,28 +28,6 @@ void CefRequestCToCpp::SetURL(const std::wstring& url)
struct_->set_url(struct_, url.c_str());
}
std::wstring CefRequestCToCpp::GetFrame()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_frame))
return str;
cef_string_t cef_str = struct_->get_frame(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefRequestCToCpp::SetFrame(const std::wstring& frame)
{
if(CEF_MEMBER_MISSING(struct_, set_frame))
return;
struct_->set_frame(struct_, frame.c_str());
}
std::wstring CefRequestCToCpp::GetMethod()
{
std::wstring str;
@@ -78,14 +56,9 @@ CefRefPtr<CefPostData> CefRequestCToCpp::GetPostData()
return NULL;
cef_post_data_t* postDataStruct = struct_->get_post_data(struct_);
if(!postDataStruct)
return NULL;
CefPostDataCToCpp* pdp = new CefPostDataCToCpp(postDataStruct);
CefRefPtr<CefPostData> postDataPtr(pdp);
pdp->UnderlyingRelease();
return postDataPtr;
if(postDataStruct)
return CefPostDataCToCpp::Wrap(postDataStruct);
return NULL;
}
void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
@@ -94,11 +67,9 @@ void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get()) {
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
pdp->UnderlyingAddRef();
postDataStruct = pdp->GetStruct();
}
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
struct_->set_post_data(struct_, postDataStruct);
}
@@ -136,7 +107,6 @@ void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
}
void CefRequestCToCpp::Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
@@ -145,11 +115,8 @@ void CefRequestCToCpp::Set(const std::wstring& url,
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get()) {
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
pdp->UnderlyingAddRef();
postDataStruct = pdp->GetStruct();
}
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
cef_string_map_t map = NULL;
if(!headerMap.empty()) {
@@ -159,15 +126,14 @@ void CefRequestCToCpp::Set(const std::wstring& url,
transfer_string_map_contents(headerMap, map);
}
struct_->set(struct_, url.c_str(), frame.c_str(), method.c_str(),
postDataStruct, map);
struct_->set(struct_, url.c_str(), method.c_str(), postDataStruct, map);
if(map)
cef_string_map_free(map);
}
#ifdef _DEBUG
long CefCToCpp<CefRequest, cef_request_t>::DebugObjCt = 0;
long CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>::DebugObjCt = 0;
#endif
@@ -188,16 +154,10 @@ void CefPostDataCToCpp::GetElements(ElementVector& elements)
int count = (int)GetElementCount();
cef_post_data_element_t* structPtr;
CefPostDataElementCToCpp* pdep;
for(int i = 0; i < count; ++i) {
structPtr = struct_->get_element(struct_, i);
if(!structPtr)
continue;
pdep = new CefPostDataElementCToCpp(structPtr);
CefRefPtr<CefPostDataElement> elementPtr(pdep);
pdep->UnderlyingRelease();
elements.push_back(elementPtr);
if(structPtr)
elements.push_back(CefPostDataElementCToCpp::Wrap(structPtr));
}
}
@@ -207,10 +167,8 @@ bool CefPostDataCToCpp::RemoveElement(CefRefPtr<CefPostDataElement> element)
if(CEF_MEMBER_MISSING(struct_, remove_element) || !element.get())
return false;
CefPostDataElementCToCpp* pdep =
static_cast<CefPostDataElementCToCpp*>(element.get());
pdep->UnderlyingAddRef();
return struct_->remove_element(struct_, pdep->GetStruct());
return struct_->remove_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
@@ -219,10 +177,8 @@ bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
if(CEF_MEMBER_MISSING(struct_, add_element) || !element.get())
return false;
CefPostDataElementCToCpp* pdep =
static_cast<CefPostDataElementCToCpp*>(element.get());
pdep->UnderlyingAddRef();
return struct_->add_element(struct_, pdep->GetStruct());
return struct_->add_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
void CefPostDataCToCpp::RemoveElements()
@@ -234,7 +190,7 @@ void CefPostDataCToCpp::RemoveElements()
}
#ifdef _DEBUG
long CefCToCpp<CefPostData, cef_post_data_t>::DebugObjCt = 0;
long CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>::DebugObjCt = 0;
#endif
@@ -302,5 +258,6 @@ size_t CefPostDataElementCToCpp::GetBytes(size_t size, void *bytes)
}
#ifdef _DEBUG
long CefCToCpp<CefPostDataElement, cef_post_data_element_t>::DebugObjCt = 0;
long CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>::DebugObjCt = 0;
#endif

View File

@@ -16,18 +16,17 @@
// Wrap a C request structure with a C++ request class.
// This class may be instantiated and accessed wrapper-side only.
class CefRequestCToCpp : public CefCToCpp<CefRequest, cef_request_t>
class CefRequestCToCpp
: public CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>
{
public:
CefRequestCToCpp(cef_request_t* str)
: CefCToCpp<CefRequest, cef_request_t>(str) {}
: CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>(str) {}
virtual ~CefRequestCToCpp() {}
// CefRequest methods
virtual std::wstring GetURL();
virtual void SetURL(const std::wstring& url);
virtual std::wstring GetFrame();
virtual void SetFrame(const std::wstring& url);
virtual std::wstring GetMethod();
virtual void SetMethod(const std::wstring& method);
virtual CefRefPtr<CefPostData> GetPostData();
@@ -35,7 +34,6 @@ public:
virtual void GetHeaderMap(HeaderMap& headerMap);
virtual void SetHeaderMap(const HeaderMap& headerMap);
virtual void Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap);
@@ -44,11 +42,12 @@ public:
// Wrap a C post data structure with a C++ post data class.
// This class may be instantiated and accessed wrapper-side only.
class CefPostDataCToCpp : public CefCToCpp<CefPostData, cef_post_data_t>
class CefPostDataCToCpp
: public CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>
{
public:
CefPostDataCToCpp(cef_post_data_t* str)
: CefCToCpp<CefPostData, cef_post_data_t>(str) {}
: CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>(str) {}
virtual ~CefPostDataCToCpp() {}
// CefPostData methods
@@ -62,12 +61,14 @@ public:
// Wrap a C post data element structure with a C++ post data element class.
// This class may be instantiated and accessed wrapper-side only.
class CefPostDataElementCToCpp :
public CefCToCpp<CefPostDataElement, cef_post_data_element_t>
class CefPostDataElementCToCpp
: public CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>
{
public:
CefPostDataElementCToCpp(cef_post_data_element_t* str)
: CefCToCpp<CefPostDataElement, cef_post_data_element_t>(str) {}
: CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>(str) {}
virtual ~CefPostDataElementCToCpp() {}
// CefPostDataElement methods

View File

@@ -39,7 +39,8 @@ int CefStreamReaderCToCpp::Eof()
}
#ifdef _DEBUG
long CefCToCpp<CefStreamReader, cef_stream_reader_t>::DebugObjCt = 0;
long CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>::DebugObjCt = 0;
#endif
@@ -76,5 +77,6 @@ int CefStreamWriterCToCpp::Flush()
}
#ifdef _DEBUG
long CefCToCpp<CefStreamWriter, cef_stream_writer_t>::DebugObjCt = 0;
long CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>::DebugObjCt = 0;
#endif

View File

@@ -16,12 +16,14 @@
// Wrap a C stream reader structure with a C++ stream reader class.
// This class may be instantiated and accessed wrapper-side only.
class CefStreamReaderCToCpp :
public CefCToCpp<CefStreamReader, cef_stream_reader_t>
class CefStreamReaderCToCpp
: public CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>
{
public:
CefStreamReaderCToCpp(cef_stream_reader_t* str)
: CefCToCpp<CefStreamReader, cef_stream_reader_t>(str) {}
: CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>(str) {}
virtual ~CefStreamReaderCToCpp() {}
// CefStreamReader methods
@@ -34,12 +36,14 @@ public:
// Wrap a C stream writer structure with a C++ stream writer class.
// This class may be instantiated and accessed wrapper-side only.
class CefStreamWriterCToCpp :
public CefCToCpp<CefStreamWriter, cef_stream_writer_t>
class CefStreamWriterCToCpp
: public CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>
{
public:
CefStreamWriterCToCpp(cef_stream_writer_t* str)
: CefCToCpp<CefStreamWriter, cef_stream_writer_t>(str) {}
: CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>(str) {}
virtual ~CefStreamWriterCToCpp() {}
// CefStreamWriter methods

View File

@@ -0,0 +1,49 @@
// 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.
#include "../precompiled_libcef.h"
#include "ctocpp/v8handler_ctocpp.h"
#include "cpptoc/v8value_cpptoc.h"
bool CefV8HandlerCToCpp::Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(CEF_MEMBER_MISSING(struct_, execute))
return RV_CONTINUE;
cef_v8value_t** argsStructPtr = NULL;
int argsSize = arguments.size();
if(argsSize > 0) {
argsStructPtr = new cef_v8value_t*[argsSize];
for(int i = 0; i < argsSize; ++i)
argsStructPtr[i] = CefV8ValueCppToC::Wrap(arguments[i]);
}
cef_v8value_t* retvalStruct = NULL;
cef_string_t exceptionStr = NULL;
int rv = struct_->execute(struct_, name.c_str(),
CefV8ValueCppToC::Wrap(object), argsSize, argsStructPtr, &retvalStruct,
&exceptionStr);
if(retvalStruct)
retval = CefV8ValueCppToC::Unwrap(retvalStruct);
if(exceptionStr) {
exception = exceptionStr;
cef_string_free(exceptionStr);
}
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>::DebugObjCt
= 0;
#endif

View File

@@ -0,0 +1,37 @@
// 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 _V8HANDLER_CTOCPP_H
#define _V8HANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C v8handler structure with a C++ v8handler class.
// This class may be instantiated and accessed DLL-side only.
class CefV8HandlerCToCpp
: public CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>
{
public:
CefV8HandlerCToCpp(cef_v8handler_t* str)
: CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>(str) {}
virtual ~CefV8HandlerCToCpp() {}
// CefV8Handler methods
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
};
#endif // BUILDING_CEF_SHARED
#endif // _V8HANDLER_CTOCPP_H

View File

@@ -0,0 +1,293 @@
// 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.
#include "../precompiled_libcef.h"
#include "cpptoc/v8handler_cpptoc.h"
#include "ctocpp/v8value_ctocpp.h"
bool CefV8ValueCToCpp::IsUndefined()
{
if(CEF_MEMBER_MISSING(struct_, is_undefined))
return false;
return struct_->is_undefined(struct_);
}
bool CefV8ValueCToCpp::IsNull()
{
if(CEF_MEMBER_MISSING(struct_, is_null))
return false;
return struct_->is_null(struct_);
}
bool CefV8ValueCToCpp::IsBool()
{
if(CEF_MEMBER_MISSING(struct_, is_bool))
return false;
return struct_->is_bool(struct_);
}
bool CefV8ValueCToCpp::IsInt()
{
if(CEF_MEMBER_MISSING(struct_, is_int))
return false;
return struct_->is_int(struct_);
}
bool CefV8ValueCToCpp::IsDouble()
{
if(CEF_MEMBER_MISSING(struct_, is_double))
return false;
return struct_->is_double(struct_);
}
bool CefV8ValueCToCpp::IsString()
{
if(CEF_MEMBER_MISSING(struct_, is_string))
return false;
return struct_->is_string(struct_);
}
bool CefV8ValueCToCpp::IsObject()
{
if(CEF_MEMBER_MISSING(struct_, is_object))
return false;
return struct_->is_object(struct_);
}
bool CefV8ValueCToCpp::IsArray()
{
if(CEF_MEMBER_MISSING(struct_, is_array))
return false;
return struct_->is_array(struct_);
}
bool CefV8ValueCToCpp::IsFunction()
{
if(CEF_MEMBER_MISSING(struct_, is_function))
return false;
return struct_->is_function(struct_);
}
bool CefV8ValueCToCpp::GetBoolValue()
{
if(CEF_MEMBER_MISSING(struct_, get_bool_value))
return false;
return struct_->get_bool_value(struct_);
}
int CefV8ValueCToCpp::GetIntValue()
{
if(CEF_MEMBER_MISSING(struct_, get_int_value))
return 0;
return struct_->get_int_value(struct_);
}
double CefV8ValueCToCpp::GetDoubleValue()
{
if(CEF_MEMBER_MISSING(struct_, get_double_value))
return 0.;
return struct_->get_double_value(struct_);
}
std::wstring CefV8ValueCToCpp::GetStringValue()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_string_value))
return str;
cef_string_t cef_str = struct_->get_string_value(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
bool CefV8ValueCToCpp::HasValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, has_value_bykey))
return false;
return struct_->has_value_bykey(struct_, key.c_str());
}
bool CefV8ValueCToCpp::HasValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, has_value_byindex))
return false;
return struct_->has_value_byindex(struct_, index);
}
bool CefV8ValueCToCpp::DeleteValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, delete_value_bykey))
return false;
return struct_->delete_value_bykey(struct_, key.c_str());
}
bool CefV8ValueCToCpp::DeleteValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, delete_value_byindex))
return false;
return struct_->delete_value_byindex(struct_, index);
}
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, get_value_bykey))
return false;
cef_v8value_t* valueStruct = struct_->get_value_bykey(struct_, key.c_str());
if(valueStruct)
return CefV8ValueCToCpp::Wrap(valueStruct);
return NULL;
}
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, get_value_byindex))
return false;
cef_v8value_t* valueStruct = struct_->get_value_byindex(struct_, index);
if(valueStruct)
return CefV8ValueCToCpp::Wrap(valueStruct);
return NULL;
}
bool CefV8ValueCToCpp::SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value)
{
if(CEF_MEMBER_MISSING(struct_, set_value_bykey))
return false;
return struct_->set_value_bykey(struct_, key.c_str(),
CefV8ValueCToCpp::Unwrap(value));
}
bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr<CefV8Value> value)
{
if(CEF_MEMBER_MISSING(struct_, set_value_byindex))
return false;
return struct_->set_value_byindex(struct_, index,
CefV8ValueCToCpp::Unwrap(value));
}
bool CefV8ValueCToCpp::GetKeys(std::vector<std::wstring>& keys)
{
if(CEF_MEMBER_MISSING(struct_, get_keys))
return false;
cef_string_list_t list = cef_string_list_alloc();
if(struct_->get_keys(struct_, list)) {
cef_string_t str;
int size = cef_string_list_size(list);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(list, i);
keys.push_back(str);
cef_string_free(str);
}
cef_string_list_free(list);
return true;
}
return false;
}
CefRefPtr<CefBase> CefV8ValueCToCpp::GetUserData()
{
if(CEF_MEMBER_MISSING(struct_, get_user_data))
return false;
cef_base_t* baseStruct = struct_->get_user_data(struct_);
if(baseStruct)
return CefBaseCppToC::Unwrap(baseStruct);
return NULL;
}
int CefV8ValueCToCpp::GetArrayLength()
{
if(CEF_MEMBER_MISSING(struct_, get_array_length))
return 0;
return struct_->get_array_length(struct_);
}
std::wstring CefV8ValueCToCpp::GetFunctionName()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_function_name))
return str;
cef_string_t cef_str = struct_->get_function_name(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
CefRefPtr<CefV8Handler> CefV8ValueCToCpp::GetFunctionHandler()
{
if(CEF_MEMBER_MISSING(struct_, get_function_handler))
return false;
cef_v8handler_t* handlerStruct = struct_->get_function_handler(struct_);
if(handlerStruct)
return CefV8HandlerCppToC::Unwrap(handlerStruct);
return NULL;
}
bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(CEF_MEMBER_MISSING(struct_, execute_function))
return RV_CONTINUE;
cef_v8value_t** argsStructPtr = NULL;
int argsSize = arguments.size();
if(argsSize > 0) {
argsStructPtr = new cef_v8value_t*[argsSize];
for(int i = 0; i < argsSize; ++i)
argsStructPtr[i] = CefV8ValueCToCpp::Unwrap(arguments[i]);
}
cef_v8value_t* retvalStruct = NULL;
cef_string_t exceptionStr = NULL;
int rv = struct_->execute_function(struct_, CefV8ValueCToCpp::Unwrap(object),
argsSize, argsStructPtr, &retvalStruct, &exceptionStr);
if(retvalStruct)
retval = CefV8ValueCToCpp::Wrap(retvalStruct);
if(exceptionStr) {
exception = exceptionStr;
cef_string_free(exceptionStr);
}
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>::DebugObjCt = 0;
#endif

View File

@@ -0,0 +1,62 @@
// 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 _V8VALUE_CTOCPP_H
#define _V8VALUE_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C v8value structure with a C++ v8value class.
// This class may be instantiated and accessed DLL-side only.
class CefV8ValueCToCpp
: public CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>
{
public:
CefV8ValueCToCpp(cef_v8value_t* str)
: CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>(str) {}
virtual ~CefV8ValueCToCpp() {}
// CefV8Value methods
virtual bool IsUndefined();
virtual bool IsNull();
virtual bool IsBool();
virtual bool IsInt();
virtual bool IsDouble();
virtual bool IsString();
virtual bool IsObject();
virtual bool IsArray();
virtual bool IsFunction();
virtual bool GetBoolValue();
virtual int GetIntValue();
virtual double GetDoubleValue();
virtual std::wstring GetStringValue();
virtual bool HasValue(const std::wstring& key);
virtual bool HasValue(int index);
virtual bool DeleteValue(const std::wstring& key);
virtual bool DeleteValue(int index);
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key);
virtual CefRefPtr<CefV8Value> GetValue(int index);
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value);
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
virtual bool GetKeys(std::vector<std::wstring>& keys);
virtual CefRefPtr<CefBase> GetUserData();
virtual int GetArrayLength();
virtual std::wstring GetFunctionName();
virtual CefRefPtr<CefV8Handler> GetFunctionHandler();
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
};
#endif // USING_CEF_SHARED
#endif // _V8VALUE_CTOCPP_H

View File

@@ -1,300 +0,0 @@
// 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.
#include "../precompiled_libcef.h"
#include "ctocpp/variant_ctocpp.h"
CefVariant::Type CefVariantCToCpp::GetType()
{
if(CEF_MEMBER_MISSING(struct_, get_type))
return VARIANT_TYPE_NULL;
return struct_->get_type(struct_);
}
void CefVariantCToCpp::SetNull()
{
if(CEF_MEMBER_MISSING(struct_, set_null))
return;
return struct_->set_null(struct_);
}
void CefVariantCToCpp::SetBool(bool val)
{
if(CEF_MEMBER_MISSING(struct_, set_bool))
return;
return struct_->set_bool(struct_, val);
}
void CefVariantCToCpp::SetInt(int val)
{
if(CEF_MEMBER_MISSING(struct_, set_int))
return;
return struct_->set_int(struct_, val);
}
void CefVariantCToCpp::SetDouble(double val)
{
if(CEF_MEMBER_MISSING(struct_, set_double))
return;
return struct_->set_double(struct_, val);
}
void CefVariantCToCpp::SetString(const std::wstring& val)
{
if(CEF_MEMBER_MISSING(struct_, set_string))
return;
return struct_->set_string(struct_, val.c_str());
}
void CefVariantCToCpp::SetBoolArray(const std::vector<bool>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_bool_array))
return;
int valSize = (int)val.size();
int* valArray = NULL;
if(valSize > 0) {
valArray = new int[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_bool_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetIntArray(const std::vector<int>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_int_array))
return;
int valSize = (int)val.size();
int* valArray = NULL;
if(valSize > 0) {
valArray = new int[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_int_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetDoubleArray(const std::vector<double>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_double_array))
return;
int valSize = (int)val.size();
double* valArray = NULL;
if(valSize > 0) {
valArray = new double[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_double_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetStringArray(const std::vector<std::wstring>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_string_array))
return;
int valSize = (int)val.size();
cef_string_t* valArray = NULL;
if(valSize > 0) {
valArray = new cef_string_t[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = cef_string_alloc(val[i].c_str());
}
}
struct_->set_string_array(struct_, valSize, valArray);
if(valArray) {
for(int i = 0; i < valSize; ++i) {
cef_string_free(valArray[i]);
}
delete [] valArray;
}
}
bool CefVariantCToCpp::GetBool()
{
if(CEF_MEMBER_MISSING(struct_, get_bool))
return false;
return struct_->get_bool(struct_);
}
int CefVariantCToCpp::GetInt()
{
if(CEF_MEMBER_MISSING(struct_, get_int))
return 0;
return struct_->get_int(struct_);
}
double CefVariantCToCpp::GetDouble()
{
if(CEF_MEMBER_MISSING(struct_, get_double))
return 0;
return struct_->get_double(struct_);
}
std::wstring CefVariantCToCpp::GetString()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_string))
return str;
cef_string_t cef_str = struct_->get_string(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
bool CefVariantCToCpp::GetBoolArray(std::vector<bool>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_bool_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
int* valArray = new int[valSize];
if(!valArray)
return false;
bool rv = struct_->get_bool_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i] ? true : false);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetIntArray(std::vector<int>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_int_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
int* valArray = new int[valSize];
if(!valArray)
return false;
bool rv = struct_->get_int_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i]);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetDoubleArray(std::vector<double>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_double_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
double* valArray = new double[valSize];
if(!valArray)
return false;
bool rv = struct_->get_double_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i]);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetStringArray(std::vector<std::wstring>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_string_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
cef_string_t* valArray = new cef_string_t[valSize];
if(!valArray)
return false;
bool rv = struct_->get_string_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i) {
val.push_back(valArray[i]);
cef_string_free(valArray[i]);
}
}
delete [] valArray;
return rv;
}
int CefVariantCToCpp::GetArraySize()
{
if(CEF_MEMBER_MISSING(struct_, get_array_size))
return -1;
return struct_->get_array_size(struct_);
}
#ifdef _DEBUG
long CefCToCpp<CefVariant, cef_variant_t>::DebugObjCt = 0;
#endif

View File

@@ -1,50 +0,0 @@
// 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 _VARIANT_CTOCPP_H
#define _VARIANT_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C variant structure with a C++ variant class.
// This class may be instantiated and accessed wrapper-side only.
class CefVariantCToCpp : public CefCToCpp<CefVariant, cef_variant_t>
{
public:
CefVariantCToCpp(cef_variant_t* str)
: CefCToCpp<CefVariant, cef_variant_t>(str) {}
virtual ~CefVariantCToCpp() {}
// CefVariant methods
virtual Type GetType();
virtual void SetNull();
virtual void SetBool(bool val);
virtual void SetInt(int val);
virtual void SetDouble(double val);
virtual void SetString(const std::wstring& val);
virtual void SetBoolArray(const std::vector<bool>& val);
virtual void SetIntArray(const std::vector<int>& val);
virtual void SetDoubleArray(const std::vector<double>& val);
virtual void SetStringArray(const std::vector<std::wstring>& val);
virtual bool GetBool();
virtual int GetInt();
virtual double GetDouble();
virtual std::wstring GetString();
virtual bool GetBoolArray(std::vector<bool>& val);
virtual bool GetIntArray(std::vector<int>& val);
virtual bool GetDoubleArray(std::vector<double>& val);
virtual bool GetStringArray(std::vector<std::wstring>& val);
virtual int GetArraySize();
};
#endif // USING_CEF_SHARED
#endif // _VARIANT_CTOCPP_H