mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add DLL build support and wrapper that allows clients to transparently switch between static and dynamic CEF builds.
- The libcef project now builds libcef_static.lib instead of libcef.lib. - The libcef_dll project builds libcef.lib and libcef.dll. This DLL exports the new CEF C API defined in cef_capi.h, cef_nplugin_capi.h, cef_string.h and cef_string_map.h. - The libcef_dll_wrapper project builds libcef_dll_wrapper.lib. This static library wraps the new C API calls with an implementation of the CEF C++ interface as defined in cef.h and cef_nplugin.h. - The cefclient project now uses the DLL instead of the static library. - Type definitions have been moved from cef.h to cef_types.h so that they can be shared by both cef.h and cef_capi.h. This change required some enumeration member name modifications throughout the code base. - Fixed variable naming inconsistencies. - Added CefVariant::GetArraySize() method and _NPN_ArrayObjectGetVectorSize() function. - Remove the ProjectSection(WebsiteProperties) sections from cef.sln to improve VS2005 performance. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@16 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
312
libcef_dll/ctocpp/browser_ctocpp.cc
Normal file
312
libcef_dll/ctocpp/browser_ctocpp.cc
Normal file
@@ -0,0 +1,312 @@
|
||||
// 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/browser_ctocpp.h"
|
||||
#include "ctocpp/request_ctocpp.h"
|
||||
#include "ctocpp/stream_ctocpp.h"
|
||||
#include "cpptoc/handler_cpptoc.h"
|
||||
#include "cpptoc/jshandler_cpptoc.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
|
||||
bool CefBrowserCToCpp::CanGoBack()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, can_go_back))
|
||||
return false;
|
||||
|
||||
return struct_->can_go_back(struct_) ? true : false;
|
||||
}
|
||||
|
||||
void CefBrowserCToCpp::GoBack()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, go_back))
|
||||
return;
|
||||
|
||||
struct_->go_back(struct_);
|
||||
}
|
||||
|
||||
bool CefBrowserCToCpp::CanGoForward()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, can_go_forward))
|
||||
return false;
|
||||
|
||||
return struct_->can_go_forward(struct_);
|
||||
}
|
||||
|
||||
void CefBrowserCToCpp::GoForward()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, go_forward))
|
||||
return;
|
||||
|
||||
struct_->go_forward(struct_);
|
||||
}
|
||||
|
||||
void CefBrowserCToCpp::Reload()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, reload))
|
||||
return;
|
||||
|
||||
struct_->reload(struct_);
|
||||
}
|
||||
|
||||
void CefBrowserCToCpp::StopLoad()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, stop_load))
|
||||
return;
|
||||
|
||||
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::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))
|
||||
return 0;
|
||||
|
||||
return struct_->get_window_handle(struct_);
|
||||
}
|
||||
|
||||
bool CefBrowserCToCpp::IsPopup()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, is_popup))
|
||||
return false;
|
||||
|
||||
return struct_->is_popup(struct_);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::wstring CefBrowserCToCpp::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;
|
||||
}
|
67
libcef_dll/ctocpp/browser_ctocpp.h
Normal file
67
libcef_dll/ctocpp/browser_ctocpp.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 _BROWSER_CTOCPP_H
|
||||
#define _BROWSER_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 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>
|
||||
{
|
||||
public:
|
||||
CefBrowserCToCpp(cef_browser_t* str)
|
||||
: CefCToCpp<CefBrowser, cef_browser_t>(str) {}
|
||||
virtual ~CefBrowserCToCpp() {}
|
||||
|
||||
// CefBrowser methods
|
||||
virtual bool CanGoBack();
|
||||
virtual void GoBack();
|
||||
virtual bool CanGoForward();
|
||||
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 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();
|
||||
};
|
||||
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _BROWSER_CTOCPP_H
|
64
libcef_dll/ctocpp/ctocpp.h
Normal file
64
libcef_dll/ctocpp/ctocpp.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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 "base/logging.h"
|
||||
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
template <class ClassName, class StructName>
|
||||
class CefCToCpp : public CefThreadSafeBase<ClassName>
|
||||
{
|
||||
public:
|
||||
CefCToCpp(StructName* str)
|
||||
: struct_(str)
|
||||
{
|
||||
DCHECK(str);
|
||||
}
|
||||
virtual ~CefCToCpp()
|
||||
{
|
||||
}
|
||||
|
||||
// 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<ClassName>::AddRef();
|
||||
}
|
||||
virtual int Release()
|
||||
{
|
||||
UnderlyingRelease();
|
||||
return CefThreadSafeBase<ClassName>::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);
|
||||
}
|
||||
|
||||
protected:
|
||||
StructName* struct_;
|
||||
};
|
||||
|
||||
|
||||
#endif // _CTOCPP_H
|
337
libcef_dll/ctocpp/handler_ctocpp.cc
Normal file
337
libcef_dll/ctocpp/handler_ctocpp.cc
Normal file
@@ -0,0 +1,337 @@
|
||||
// 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/request_cpptoc.h"
|
||||
#include "cpptoc/stream_cpptoc.h"
|
||||
#include "ctocpp/handler_ctocpp.h"
|
||||
#include "transfer_util.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
|
||||
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler>& handler, std::wstring& url)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
CefHandlerCToCpp* handlerPtr = NULL;
|
||||
cef_handler_t* handlerRet = NULL;
|
||||
if(handler.get()) {
|
||||
handlerPtr = static_cast<CefHandlerCToCpp*>(handler.get());
|
||||
handlerPtr->UnderlyingAddRef();
|
||||
handlerRet = handlerPtr->GetStruct();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(handlerPtr && handlerRet != handlerPtr->GetStruct()) {
|
||||
// The handler was changed.
|
||||
if(handlerRet) {
|
||||
CefHandlerCToCpp* hp = new CefHandlerCToCpp(handlerRet);
|
||||
handler = hp;
|
||||
hp->UnderlyingRelease();
|
||||
} else {
|
||||
handler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
transfer_string_contents(urlRet, url, true);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleAfterCreated(
|
||||
CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, 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(),
|
||||
url.c_str());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleTitleChange(
|
||||
CefRefPtr<CefBrowser> browser, const std::wstring& title)
|
||||
{
|
||||
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(),
|
||||
title.c_str());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeBrowse(
|
||||
CefRefPtr<CefBrowser> browser, 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);
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleLoadStart(
|
||||
CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, handle_load_start))
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
|
||||
browserPtr->AddRef();
|
||||
|
||||
return struct_->handle_load_start(struct_, browserPtr->GetStruct());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleLoadEnd(
|
||||
CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, handle_load_end))
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
|
||||
browserPtr->AddRef();
|
||||
|
||||
return struct_->handle_load_end(struct_, browserPtr->GetStruct());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleLoadError(
|
||||
CefRefPtr<CefBrowser> browser, 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);
|
||||
|
||||
transfer_string_contents(errorTextRet, errorText, true);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType, int loadFlags)
|
||||
{
|
||||
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;
|
||||
|
||||
if(!redirectUrl.empty())
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu(
|
||||
CefRefPtr<CefBrowser> browser, const MenuInfo& menuInfo)
|
||||
{
|
||||
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(),
|
||||
&menuInfo);
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleGetMenuLabel(
|
||||
CefRefPtr<CefBrowser> browser, MenuId menuId, std::wstring& label)
|
||||
{
|
||||
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);
|
||||
|
||||
transfer_string_contents(labelRet, label, true);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleMenuAction(
|
||||
CefRefPtr<CefBrowser> browser, MenuId menuId)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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,
|
||||
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;
|
||||
|
||||
if(!topLeft.empty())
|
||||
topLeftRet = cef_string_alloc(topLeft.c_str());
|
||||
if(!topCenter.empty())
|
||||
topCenterRet = cef_string_alloc(topCenter.c_str());
|
||||
if(!topRight.empty())
|
||||
topRightRet = cef_string_alloc(topRight.c_str());
|
||||
if(!bottomLeft.empty())
|
||||
bottomLeftRet = cef_string_alloc(bottomLeft.c_str());
|
||||
if(!bottomCenter.empty())
|
||||
bottomCenterRet = cef_string_alloc(bottomCenter.c_str());
|
||||
if(!bottomRight.empty())
|
||||
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);
|
||||
|
||||
transfer_string_contents(topLeftRet, topLeft, true);
|
||||
transfer_string_contents(topCenterRet, topCenter, true);
|
||||
transfer_string_contents(topRightRet, topRight, true);
|
||||
transfer_string_contents(bottomLeftRet, bottomLeft, true);
|
||||
transfer_string_contents(bottomCenterRet, bottomCenter, true);
|
||||
transfer_string_contents(bottomRightRet, bottomRight, true);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleJSAlert(
|
||||
CefRefPtr<CefBrowser> browser, 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());
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleJSConfirm(
|
||||
CefRefPtr<CefBrowser> browser, 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(),
|
||||
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)
|
||||
{
|
||||
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(),
|
||||
message.c_str(), defaultValue.c_str(), &ret, &resultRet);
|
||||
retval = (ret ? true : false);
|
||||
|
||||
transfer_string_contents(resultRet, result, true);
|
||||
|
||||
return rv;
|
||||
}
|
81
libcef_dll/ctocpp/handler_ctocpp.h
Normal file
81
libcef_dll/ctocpp/handler_ctocpp.h
Normal file
@@ -0,0 +1,81 @@
|
||||
// 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 _HANDLER_CTOCPP_H
|
||||
#define _HANDLER_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 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>
|
||||
{
|
||||
public:
|
||||
CefHandlerCToCpp(cef_handler_t* str)
|
||||
: CefCToCpp<CefHandler, cef_handler_t>(str) {}
|
||||
virtual ~CefHandlerCToCpp() {}
|
||||
|
||||
// CefHandler methods
|
||||
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler>& handler,
|
||||
std::wstring& url);
|
||||
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
|
||||
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& url);
|
||||
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& title);
|
||||
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType, bool isRedirect);
|
||||
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser);
|
||||
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser);
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
ErrorCode errorCode,
|
||||
const std::wstring& failedUrl,
|
||||
std::wstring& errorText);
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
std::wstring& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
std::wstring& mimeType,
|
||||
int loadFlags);
|
||||
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
|
||||
const MenuInfo& menuInfo);
|
||||
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId, std::wstring& label);
|
||||
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId);
|
||||
virtual RetVal 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,
|
||||
std::wstring& bottomCenter,
|
||||
std::wstring& bottomRight);
|
||||
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& message);
|
||||
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& message, bool& retval);
|
||||
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
|
||||
const std::wstring& message,
|
||||
const std::wstring& default_value,
|
||||
bool& retval,
|
||||
std::wstring& result);
|
||||
};
|
||||
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
#endif // _HANDLER_CTOCPP_H
|
103
libcef_dll/ctocpp/jshandler_ctocpp.cc
Normal file
103
libcef_dll/ctocpp/jshandler_ctocpp.cc
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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"
|
||||
#include "base/logging.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;
|
||||
}
|
45
libcef_dll/ctocpp/jshandler_ctocpp.h
Normal file
45
libcef_dll/ctocpp/jshandler_ctocpp.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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
|
297
libcef_dll/ctocpp/request_ctocpp.cc
Normal file
297
libcef_dll/ctocpp/request_ctocpp.cc
Normal file
@@ -0,0 +1,297 @@
|
||||
// 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/request_ctocpp.h"
|
||||
#include "transfer_util.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
|
||||
std::wstring CefRequestCToCpp::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;
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::SetURL(const std::wstring& url)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_url))
|
||||
return;
|
||||
|
||||
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;
|
||||
if(CEF_MEMBER_MISSING(struct_, get_method))
|
||||
return str;
|
||||
|
||||
cef_string_t cef_str = struct_->get_method(struct_);
|
||||
if(cef_str) {
|
||||
str = cef_str;
|
||||
cef_string_free(cef_str);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::SetMethod(const std::wstring& method)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_method))
|
||||
return;
|
||||
|
||||
struct_->set_method(struct_, method.c_str());
|
||||
}
|
||||
|
||||
CefRefPtr<CefPostData> CefRequestCToCpp::GetPostData()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_post_data))
|
||||
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;
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_post_data))
|
||||
return;
|
||||
|
||||
cef_post_data_t* postDataStruct = NULL;
|
||||
if(postData.get()) {
|
||||
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
|
||||
pdp->UnderlyingAddRef();
|
||||
postDataStruct = pdp->GetStruct();
|
||||
}
|
||||
struct_->set_post_data(struct_, postDataStruct);
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::GetHeaderMap(HeaderMap& headerMap)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_header_map))
|
||||
return;
|
||||
|
||||
cef_string_map_t map = cef_string_map_alloc();
|
||||
if(!map)
|
||||
return;
|
||||
|
||||
struct_->get_header_map(struct_, map);
|
||||
transfer_string_map_contents(map, headerMap);
|
||||
cef_string_map_free(map);
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_header_map))
|
||||
return;
|
||||
|
||||
cef_string_map_t map = NULL;
|
||||
if(!headerMap.empty()) {
|
||||
map = cef_string_map_alloc();
|
||||
if(!map)
|
||||
return;
|
||||
transfer_string_map_contents(headerMap, map);
|
||||
}
|
||||
|
||||
struct_->set_header_map(struct_, map);
|
||||
|
||||
if(map)
|
||||
cef_string_map_free(map);
|
||||
}
|
||||
|
||||
void CefRequestCToCpp::Set(const std::wstring& url,
|
||||
const std::wstring& frame,
|
||||
const std::wstring& method,
|
||||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set))
|
||||
return;
|
||||
|
||||
cef_post_data_t* postDataStruct = NULL;
|
||||
if(postData.get()) {
|
||||
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
|
||||
pdp->UnderlyingAddRef();
|
||||
postDataStruct = pdp->GetStruct();
|
||||
}
|
||||
|
||||
cef_string_map_t map = NULL;
|
||||
if(!headerMap.empty()) {
|
||||
map = cef_string_map_alloc();
|
||||
if(!map)
|
||||
return;
|
||||
transfer_string_map_contents(headerMap, map);
|
||||
}
|
||||
|
||||
struct_->set(struct_, url.c_str(), frame.c_str(), method.c_str(),
|
||||
postDataStruct, map);
|
||||
|
||||
if(map)
|
||||
cef_string_map_free(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t CefPostDataCToCpp::GetElementCount()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_element_count))
|
||||
return 0;
|
||||
|
||||
return struct_->get_element_count(struct_);
|
||||
}
|
||||
|
||||
void CefPostDataCToCpp::GetElements(ElementVector& elements)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_element))
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool CefPostDataCToCpp::RemoveElement(CefRefPtr<CefPostDataElement> element)
|
||||
{
|
||||
DCHECK(element.get());
|
||||
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());
|
||||
}
|
||||
|
||||
bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
|
||||
{
|
||||
DCHECK(element.get());
|
||||
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());
|
||||
}
|
||||
|
||||
void CefPostDataCToCpp::RemoveElements()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, remove_elements))
|
||||
return;
|
||||
|
||||
return struct_->remove_elements(struct_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CefPostDataElementCToCpp::SetToEmpty()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_to_empty))
|
||||
return;
|
||||
|
||||
return struct_->set_to_empty(struct_);
|
||||
}
|
||||
|
||||
void CefPostDataElementCToCpp::SetToFile(const std::wstring& fileName)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_to_file))
|
||||
return;
|
||||
|
||||
return struct_->set_to_file(struct_, fileName.c_str());
|
||||
}
|
||||
|
||||
void CefPostDataElementCToCpp::SetToBytes(size_t size, const void* bytes)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_to_bytes))
|
||||
return;
|
||||
|
||||
return struct_->set_to_bytes(struct_, size, bytes);
|
||||
}
|
||||
|
||||
CefPostDataElement::Type CefPostDataElementCToCpp::GetType()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_type))
|
||||
return PDE_TYPE_EMPTY;
|
||||
|
||||
return struct_->get_type(struct_);
|
||||
}
|
||||
|
||||
std::wstring CefPostDataElementCToCpp::GetFile()
|
||||
{
|
||||
std::wstring str;
|
||||
if(CEF_MEMBER_MISSING(struct_, get_file))
|
||||
return str;
|
||||
|
||||
cef_string_t cef_str = struct_->get_file(struct_);
|
||||
if(cef_str) {
|
||||
str = cef_str;
|
||||
cef_string_free(cef_str);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t CefPostDataElementCToCpp::GetBytesCount()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_bytes_count))
|
||||
return 0;
|
||||
|
||||
return struct_->get_bytes_count(struct_);
|
||||
}
|
||||
|
||||
size_t CefPostDataElementCToCpp::GetBytes(size_t size, void *bytes)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_bytes))
|
||||
return 0;
|
||||
|
||||
return struct_->get_bytes(struct_, size, bytes);
|
||||
}
|
85
libcef_dll/ctocpp/request_ctocpp.h
Normal file
85
libcef_dll/ctocpp/request_ctocpp.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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 _REQUEST_CTOCPP_H
|
||||
#define _REQUEST_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 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>
|
||||
{
|
||||
public:
|
||||
CefRequestCToCpp(cef_request_t* str)
|
||||
: CefCToCpp<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();
|
||||
virtual void SetPostData(CefRefPtr<CefPostData> postData);
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
// 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>
|
||||
{
|
||||
public:
|
||||
CefPostDataCToCpp(cef_post_data_t* str)
|
||||
: CefCToCpp<CefPostData, cef_post_data_t>(str) {}
|
||||
virtual ~CefPostDataCToCpp() {}
|
||||
|
||||
// CefPostData methods
|
||||
virtual size_t GetElementCount();
|
||||
virtual void GetElements(ElementVector& elements);
|
||||
virtual bool RemoveElement(CefRefPtr<CefPostDataElement> element);
|
||||
virtual bool AddElement(CefRefPtr<CefPostDataElement> element);
|
||||
virtual void RemoveElements();
|
||||
};
|
||||
|
||||
|
||||
// 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>
|
||||
{
|
||||
public:
|
||||
CefPostDataElementCToCpp(cef_post_data_element_t* str)
|
||||
: CefCToCpp<CefPostDataElement, cef_post_data_element_t>(str) {}
|
||||
virtual ~CefPostDataElementCToCpp() {}
|
||||
|
||||
// CefPostDataElement methods
|
||||
virtual void SetToEmpty();
|
||||
virtual void SetToFile(const std::wstring& fileName);
|
||||
virtual void SetToBytes(size_t size, const void* bytes);
|
||||
virtual Type GetType();
|
||||
virtual std::wstring GetFile();
|
||||
virtual size_t GetBytesCount();
|
||||
virtual size_t GetBytes(size_t size, void *bytes);
|
||||
};
|
||||
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _REQUEST_CTOCPP_H
|
73
libcef_dll/ctocpp/stream_ctocpp.cc
Normal file
73
libcef_dll/ctocpp/stream_ctocpp.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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/stream_ctocpp.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
|
||||
size_t CefStreamReaderCToCpp::Read(void *ptr, size_t size, size_t n)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, read))
|
||||
return 0;
|
||||
|
||||
return struct_->read(struct_, ptr, size, n);
|
||||
}
|
||||
|
||||
int CefStreamReaderCToCpp::Seek(long offset, int whence)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, seek))
|
||||
return 0;
|
||||
|
||||
return struct_->seek(struct_, offset, whence);
|
||||
}
|
||||
|
||||
long CefStreamReaderCToCpp::Tell()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, tell))
|
||||
return 0;
|
||||
|
||||
return struct_->tell(struct_);
|
||||
}
|
||||
|
||||
int CefStreamReaderCToCpp::Eof()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, eof))
|
||||
return 0;
|
||||
|
||||
return struct_->eof(struct_);
|
||||
}
|
||||
|
||||
|
||||
size_t CefStreamWriterCToCpp::Write(const void *ptr, size_t size, size_t n)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, write))
|
||||
return 0;
|
||||
|
||||
return struct_->write(struct_, ptr, size, n);
|
||||
}
|
||||
|
||||
int CefStreamWriterCToCpp::Seek(long offset, int whence)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, seek))
|
||||
return 0;
|
||||
|
||||
return struct_->seek(struct_, offset, whence);
|
||||
}
|
||||
|
||||
long CefStreamWriterCToCpp::Tell()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, tell))
|
||||
return 0;
|
||||
|
||||
return struct_->tell(struct_);
|
||||
}
|
||||
|
||||
int CefStreamWriterCToCpp::Flush()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, flush))
|
||||
return 0;
|
||||
|
||||
return struct_->flush(struct_);
|
||||
}
|
54
libcef_dll/ctocpp/stream_ctocpp.h
Normal file
54
libcef_dll/ctocpp/stream_ctocpp.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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 _STREAM_CTOCPP_H
|
||||
#define _STREAM_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 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>
|
||||
{
|
||||
public:
|
||||
CefStreamReaderCToCpp(cef_stream_reader_t* str)
|
||||
: CefCToCpp<CefStreamReader, cef_stream_reader_t>(str) {}
|
||||
virtual ~CefStreamReaderCToCpp() {}
|
||||
|
||||
// CefStreamReader methods
|
||||
virtual size_t Read(void *ptr, size_t size, size_t n);
|
||||
virtual int Seek(long offset, int whence);
|
||||
virtual long Tell();
|
||||
virtual int Eof();
|
||||
};
|
||||
|
||||
|
||||
// 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>
|
||||
{
|
||||
public:
|
||||
CefStreamWriterCToCpp(cef_stream_writer_t* str)
|
||||
: CefCToCpp<CefStreamWriter, cef_stream_writer_t>(str) {}
|
||||
virtual ~CefStreamWriterCToCpp() {}
|
||||
|
||||
// CefStreamWriter methods
|
||||
virtual size_t Write(const void *ptr, size_t size, size_t n);
|
||||
virtual int Seek(long offset, int whence);
|
||||
virtual long Tell();
|
||||
virtual int Flush();
|
||||
};
|
||||
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _STREAM_CTOCPP_H
|
297
libcef_dll/ctocpp/variant_ctocpp.cc
Normal file
297
libcef_dll/ctocpp/variant_ctocpp.cc
Normal file
@@ -0,0 +1,297 @@
|
||||
// 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"
|
||||
#include "base/logging.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_);
|
||||
}
|
50
libcef_dll/ctocpp/variant_ctocpp.h
Normal file
50
libcef_dll/ctocpp/variant_ctocpp.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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
|
Reference in New Issue
Block a user