cef/libcef_dll/cpptoc/jshandler_cpptoc.cc
Marshall Greenblatt 35e21da884 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
2009-03-05 01:10:06 +00:00

156 lines
4.4 KiB
C++

// 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/jshandler_cpptoc.h"
#include "ctocpp/browser_ctocpp.h"
#include "ctocpp/variant_ctocpp.h"
#include "base/logging.h"
bool CEF_CALLBACK jshandler_has_method(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
return impl->class_->GetClass()->HasMethod(browserPtr, nameStr);
}
bool CEF_CALLBACK jshandler_has_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
return impl->class_->GetClass()->HasProperty(browserPtr, nameStr);
}
bool CEF_CALLBACK jshandler_set_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(value);
CefRefPtr<CefVariant> valuePtr(vp);
vp->UnderlyingRelease();
return impl->class_->GetClass()->SetProperty(browserPtr, nameStr, valuePtr);
}
bool CEF_CALLBACK jshandler_get_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(value);
CefRefPtr<CefVariant> valuePtr(vp);
vp->UnderlyingRelease();
return impl->class_->GetClass()->GetProperty(browserPtr, nameStr, valuePtr);
}
bool CEF_CALLBACK jshandler_execute_method(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name, size_t numargs,
struct _cef_variant_t** args, struct _cef_variant_t* retval)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(retval);
CefRefPtr<CefVariant> retvalPtr(vp);
vp->UnderlyingRelease();
CefJSHandler::VariantVector vec;
for(int i = 0; i < (int)numargs; ++i) {
vp = new CefVariantCToCpp(args[i]);
CefRefPtr<CefVariant> argPtr(vp);
vp->UnderlyingRelease();
vec.push_back(argPtr);
}
return impl->class_->GetClass()->ExecuteMethod(browserPtr, nameStr, vec,
retvalPtr);
}
CefJSHandlerCppToC::CefJSHandlerCppToC(CefRefPtr<CefJSHandler> cls)
: CefCppToC<CefJSHandler, cef_jshandler_t>(cls)
{
struct_.struct_.has_method = jshandler_has_method;
struct_.struct_.has_property = jshandler_has_property;
struct_.struct_.set_property = jshandler_set_property;
struct_.struct_.get_property = jshandler_get_property;
struct_.struct_.execute_method = jshandler_execute_method;
}