mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- 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:
@ -4,10 +4,8 @@
|
||||
|
||||
#include "../precompiled_libcef.h"
|
||||
#include "cpptoc/browser_cpptoc.h"
|
||||
#include "cpptoc/request_cpptoc.h"
|
||||
#include "cpptoc/stream_cpptoc.h"
|
||||
#include "cpptoc/frame_cpptoc.h"
|
||||
#include "ctocpp/handler_ctocpp.h"
|
||||
#include "ctocpp/jshandler_ctocpp.h"
|
||||
|
||||
|
||||
int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
|
||||
@ -16,9 +14,7 @@ int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
return impl->class_->GetClass()->CanGoBack();
|
||||
return CefBrowserCppToC::Get(browser)->CanGoBack();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_go_back(cef_browser_t* browser)
|
||||
@ -27,9 +23,7 @@ void CEF_CALLBACK browser_go_back(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->GoBack();
|
||||
CefBrowserCppToC::Get(browser)->GoBack();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_can_go_forward(cef_browser_t* browser)
|
||||
@ -38,9 +32,7 @@ int CEF_CALLBACK browser_can_go_forward(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
return impl->class_->GetClass()->CanGoForward();
|
||||
return CefBrowserCppToC::Get(browser)->CanGoForward();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_go_forward(cef_browser_t* browser)
|
||||
@ -49,9 +41,7 @@ void CEF_CALLBACK browser_go_forward(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->GoForward();
|
||||
CefBrowserCppToC::Get(browser)->GoForward();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_reload(cef_browser_t* browser)
|
||||
@ -60,9 +50,7 @@ void CEF_CALLBACK browser_reload(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Reload();
|
||||
CefBrowserCppToC::Get(browser)->Reload();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_stop_load(cef_browser_t* browser)
|
||||
@ -71,93 +59,7 @@ void CEF_CALLBACK browser_stop_load(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->StopLoad();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_undo(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Undo(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_redo(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Redo(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_cut(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Cut(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_copy(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Copy(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_paste(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Paste(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_delete(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Delete(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_select_all(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->SelectAll(targetFrame);
|
||||
CefBrowserCppToC::Get(browser)->StopLoad();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
|
||||
@ -166,254 +68,7 @@ void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->SetFocus(enable ? true : false);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_print(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->Print(targetFrame);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_view_source(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
impl->class_->GetClass()->ViewSource(targetFrame);
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK browser_get_source(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring sourceStr = impl->class_->GetClass()->GetSource(targetFrame);
|
||||
if(sourceStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(sourceStr.c_str());
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK browser_get_text(cef_browser_t* browser,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring textStr = impl->class_->GetClass()->GetText(targetFrame);
|
||||
if(textStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(textStr.c_str());
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_load_request(cef_browser_t* browser,
|
||||
cef_request_t* request)
|
||||
{
|
||||
DCHECK(browser);
|
||||
DCHECK(request);
|
||||
if(!browser || !request)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
CefRequestCppToC::Struct* structPtr =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
CefRefPtr<CefRequest> requestPtr(structPtr->class_->GetClass());
|
||||
structPtr->class_->Release();
|
||||
impl->class_->GetClass()->LoadRequest(requestPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_load_url(cef_browser_t* browser, const wchar_t* url,
|
||||
const wchar_t* frame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring urlStr, frameStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
if(frame)
|
||||
frameStr = frame;
|
||||
impl->class_->GetClass()->LoadURL(urlStr, frameStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_load_string(cef_browser_t* browser,
|
||||
const wchar_t* string,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring stringStr, urlStr;
|
||||
if(string)
|
||||
stringStr = string;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
impl->class_->GetClass()->LoadString(stringStr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_load_stream(cef_browser_t* browser,
|
||||
cef_stream_reader_t* stream,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(browser);
|
||||
DCHECK(stream);
|
||||
if(!browser || !stream)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
CefStreamReaderCppToC::Struct* structPtr =
|
||||
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
|
||||
CefRefPtr<CefStreamReader> streamPtr(structPtr->class_->GetClass());
|
||||
structPtr->class_->Release();
|
||||
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
impl->class_->GetClass()->LoadStream(streamPtr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_execute_javascript(cef_browser_t* browser,
|
||||
const wchar_t* jsCode,
|
||||
const wchar_t* scriptUrl,
|
||||
int startLine,
|
||||
enum cef_targetframe_t targetFrame)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring jsCodeStr, scriptUrlStr;
|
||||
if(jsCode)
|
||||
jsCodeStr = jsCode;
|
||||
if(scriptUrl)
|
||||
scriptUrlStr = scriptUrl;
|
||||
|
||||
impl->class_->GetClass()->ExecuteJavaScript(jsCodeStr, scriptUrlStr,
|
||||
startLine, targetFrame);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_add_jshandler(cef_browser_t* browser,
|
||||
const wchar_t* classname,
|
||||
cef_jshandler_t* handler)
|
||||
{
|
||||
DCHECK(browser);
|
||||
DCHECK(handler);
|
||||
if(!browser || !handler)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
CefJSHandlerCToCpp* hp = new CefJSHandlerCToCpp(handler);
|
||||
CefRefPtr<CefJSHandler> handlerPtr(hp);
|
||||
hp->UnderlyingRelease();
|
||||
|
||||
std::wstring classnameStr;
|
||||
if(classname)
|
||||
classnameStr = classname;
|
||||
return impl->class_->GetClass()->AddJSHandler(classnameStr, handlerPtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_has_jshandler(cef_browser_t* browser,
|
||||
const wchar_t* classname)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring classnameStr;
|
||||
if(classname)
|
||||
classnameStr = classname;
|
||||
return impl->class_->GetClass()->HasJSHandler(classnameStr);
|
||||
}
|
||||
|
||||
cef_jshandler_t* CEF_CALLBACK browser_get_jshandler(cef_browser_t* browser,
|
||||
const wchar_t* classname)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring classnameStr;
|
||||
if(classname)
|
||||
classnameStr = classname;
|
||||
CefRefPtr<CefJSHandler> handler =
|
||||
impl->class_->GetClass()->GetJSHandler(classnameStr);
|
||||
if(handler.get()) {
|
||||
CefJSHandlerCToCpp* hp = static_cast<CefJSHandlerCToCpp*>(handler.get());
|
||||
hp->UnderlyingAddRef();
|
||||
return hp->GetStruct();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_remove_jshandler(cef_browser_t* browser,
|
||||
const wchar_t* classname)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring classnameStr;
|
||||
if(classname)
|
||||
classnameStr = classname;
|
||||
return impl->class_->GetClass()->RemoveJSHandler(classnameStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_remove_all_jshandlers(cef_browser_t* browser)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
return impl->class_->GetClass()->RemoveAllJSHandlers();
|
||||
CefBrowserCppToC::Get(browser)->SetFocus(enable ? true : false);
|
||||
}
|
||||
|
||||
cef_window_handle_t CEF_CALLBACK browser_get_window_handle(cef_browser_t* browser)
|
||||
@ -422,9 +77,7 @@ cef_window_handle_t CEF_CALLBACK browser_get_window_handle(cef_browser_t* browse
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
return impl->class_->GetClass()->GetWindowHandle();
|
||||
return CefBrowserCppToC::Get(browser)->GetWindowHandle();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_is_popup(cef_browser_t* browser)
|
||||
@ -433,9 +86,7 @@ int CEF_CALLBACK browser_is_popup(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return 0;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
return impl->class_->GetClass()->IsPopup();
|
||||
return CefBrowserCppToC::Get(browser)->IsPopup();
|
||||
}
|
||||
|
||||
cef_handler_t* CEF_CALLBACK browser_get_handler(cef_browser_t* browser)
|
||||
@ -444,35 +95,81 @@ cef_handler_t* CEF_CALLBACK browser_get_handler(cef_browser_t* browser)
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
CefRefPtr<CefHandler> handler = impl->class_->GetClass()->GetHandler();
|
||||
if(handler.get()) {
|
||||
CefHandlerCToCpp* hp = static_cast<CefHandlerCToCpp*>(handler.get());
|
||||
hp->UnderlyingAddRef();
|
||||
return hp->GetStruct();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
||||
CefRefPtr<CefHandler> handlerPtr = browserPtr->GetHandler();
|
||||
if(handlerPtr.get())
|
||||
return CefHandlerCToCpp::Unwrap(handlerPtr);
|
||||
|
||||
cef_string_t CEF_CALLBACK browser_get_url(cef_browser_t* browser)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _cef_frame_t* CEF_CALLBACK browser_get_main_frame(
|
||||
struct _cef_browser_t* browser)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
CefBrowserCppToC::Struct* impl =
|
||||
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
|
||||
|
||||
std::wstring urlStr = impl->class_->GetClass()->GetURL();
|
||||
if(urlStr.empty())
|
||||
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
||||
CefRefPtr<CefFrame> framePtr = browserPtr->GetMainFrame();
|
||||
if(framePtr.get())
|
||||
return CefFrameCppToC::Wrap(framePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _cef_frame_t* CEF_CALLBACK browser_get_focused_frame(
|
||||
struct _cef_browser_t* browser)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
return cef_string_alloc(urlStr.c_str());
|
||||
|
||||
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
||||
CefRefPtr<CefFrame> framePtr = browserPtr->GetFocusedFrame();
|
||||
if(framePtr.get())
|
||||
return CefFrameCppToC::Wrap(framePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _cef_frame_t* CEF_CALLBACK browser_get_frame(
|
||||
struct _cef_browser_t* browser, const wchar_t* name)
|
||||
{
|
||||
DCHECK(browser);
|
||||
if(!browser)
|
||||
return NULL;
|
||||
|
||||
std::wstring nameStr;
|
||||
if(name)
|
||||
nameStr = name;
|
||||
if(nameStr.empty())
|
||||
return NULL;
|
||||
|
||||
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
||||
CefRefPtr<CefFrame> framePtr = browserPtr->GetFrame(nameStr);
|
||||
if(framePtr.get())
|
||||
return CefFrameCppToC::Wrap(framePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK browser_get_frame_names(struct _cef_browser_t* browser,
|
||||
cef_string_list_t list)
|
||||
{
|
||||
DCHECK(browser);
|
||||
DCHECK(list);
|
||||
if(!browser || !list)
|
||||
return NULL;
|
||||
|
||||
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
||||
std::vector<std::wstring> stringList;
|
||||
browserPtr->GetFrameNames(stringList);
|
||||
size_t size = stringList.size();
|
||||
for(size_t i = 0; i < size; ++i)
|
||||
cef_string_list_append(list, stringList[i].c_str());
|
||||
return size;
|
||||
}
|
||||
|
||||
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
||||
: CefCppToC<CefBrowser, cef_browser_t>(cls)
|
||||
: CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>(cls)
|
||||
{
|
||||
struct_.struct_.can_go_back = browser_can_go_back;
|
||||
struct_.struct_.go_back = browser_go_back;
|
||||
@ -480,34 +177,16 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
||||
struct_.struct_.go_forward = browser_go_forward;
|
||||
struct_.struct_.reload = browser_reload;
|
||||
struct_.struct_.stop_load = browser_stop_load;
|
||||
struct_.struct_.undo = browser_undo;
|
||||
struct_.struct_.redo = browser_redo;
|
||||
struct_.struct_.cut = browser_cut;
|
||||
struct_.struct_.copy = browser_copy;
|
||||
struct_.struct_.paste = browser_paste;
|
||||
struct_.struct_.del = browser_delete;
|
||||
struct_.struct_.select_all = browser_select_all;
|
||||
struct_.struct_.set_focus = browser_set_focus;
|
||||
struct_.struct_.print = browser_print;
|
||||
struct_.struct_.view_source = browser_view_source;
|
||||
struct_.struct_.get_source = browser_get_source;
|
||||
struct_.struct_.get_text = browser_get_text;
|
||||
struct_.struct_.load_request = browser_load_request;
|
||||
struct_.struct_.load_url = browser_load_url;
|
||||
struct_.struct_.load_string = browser_load_string;
|
||||
struct_.struct_.load_stream = browser_load_stream;
|
||||
struct_.struct_.execute_javascript = browser_execute_javascript;
|
||||
struct_.struct_.add_jshandler = browser_add_jshandler;
|
||||
struct_.struct_.has_jshandler = browser_has_jshandler;
|
||||
struct_.struct_.get_jshandler = browser_get_jshandler;
|
||||
struct_.struct_.remove_jshandler = browser_remove_jshandler;
|
||||
struct_.struct_.remove_all_jshandlers = browser_remove_all_jshandlers;
|
||||
struct_.struct_.get_window_handle = browser_get_window_handle;
|
||||
struct_.struct_.is_popup = browser_is_popup;
|
||||
struct_.struct_.get_handler = browser_get_handler;
|
||||
struct_.struct_.get_url = browser_get_url;
|
||||
struct_.struct_.get_handler = browser_get_handler;
|
||||
struct_.struct_.get_main_frame = browser_get_main_frame;
|
||||
struct_.struct_.get_focused_frame = browser_get_focused_frame;
|
||||
struct_.struct_.get_frame = browser_get_frame;
|
||||
struct_.struct_.get_frame_names = browser_get_frame_names;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefBrowser, cef_browser_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
// Wrap a C++ browser class with a C browser structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefBrowserCppToC : public CefCppToC<CefBrowser, cef_browser_t>
|
||||
class CefBrowserCppToC
|
||||
: public CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>
|
||||
{
|
||||
public:
|
||||
CefBrowserCppToC(CefBrowser* cls);
|
||||
|
@ -10,19 +10,63 @@
|
||||
#include "../cef_logging.h"
|
||||
|
||||
|
||||
// Wrap a C++ class with a C structure.
|
||||
template <class ClassName, class StructName>
|
||||
// Wrap a C++ class with a C structure. This is used when the class
|
||||
// implementation exists on this side of the DLL boundary but will have methods
|
||||
// called from the other side of the DLL boundary.
|
||||
template <class ClassName, class BaseName, class StructName>
|
||||
class CefCppToC : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
// Use this method to retrieve the underlying class instance from our
|
||||
// own structure when the structure is passed as the required first
|
||||
// parameter of a C API function call. No explicit reference counting
|
||||
// is done in this case.
|
||||
static CefRefPtr<BaseName> Get(StructName* s)
|
||||
{
|
||||
// Cast our structure to the wrapper structure type.
|
||||
ClassName::Struct* wrapperStruct =
|
||||
reinterpret_cast<ClassName::Struct*>(s);
|
||||
// Return the underlying object instance.
|
||||
return wrapperStruct->class_->GetClass();
|
||||
}
|
||||
|
||||
// Use this method to create a wrapper structure for passing our class
|
||||
// instance to the other side.
|
||||
static StructName* Wrap(CefRefPtr<BaseName> c)
|
||||
{
|
||||
// Wrap our object with the CefCppToC class.
|
||||
ClassName* wrapper = new ClassName(c);
|
||||
// Add a reference to our wrapper object that will be released once our
|
||||
// structure arrives on the other side.
|
||||
wrapper->AddRef();
|
||||
// Return the structure pointer that can now be passed to the other side.
|
||||
return wrapper->GetStruct();
|
||||
}
|
||||
|
||||
// Use this method to retrieve the underlying class instance when receiving
|
||||
// our wrapper structure back from the other side.
|
||||
static CefRefPtr<BaseName> Unwrap(StructName* s)
|
||||
{
|
||||
// Cast our structure to the wrapper structure type.
|
||||
ClassName::Struct* wrapperStruct =
|
||||
reinterpret_cast<ClassName::Struct*>(s);
|
||||
// Add the underlying object instance to a smart pointer.
|
||||
CefRefPtr<BaseName> objectPtr(wrapperStruct->class_->GetClass());
|
||||
// Release the reference to our wrapper object that was added before the
|
||||
// structure was passed back to us.
|
||||
wrapperStruct->class_->Release();
|
||||
// Return the underlying object instance.
|
||||
return objectPtr;
|
||||
}
|
||||
|
||||
// Structure representation with pointer to the C++ class.
|
||||
struct Struct
|
||||
{
|
||||
StructName struct_;
|
||||
CefCppToC<ClassName, StructName>* class_;
|
||||
CefCppToC<ClassName,BaseName,StructName>* class_;
|
||||
};
|
||||
|
||||
CefCppToC(ClassName* cls)
|
||||
CefCppToC(BaseName* cls)
|
||||
: class_(cls)
|
||||
{
|
||||
DCHECK(cls);
|
||||
@ -47,7 +91,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
ClassName* GetClass() { return class_; }
|
||||
BaseName* GetClass() { return class_; }
|
||||
|
||||
// If returning the structure across the DLL boundary you should call
|
||||
// AddRef() on this CefCppToC object. On the other side of the DLL boundary,
|
||||
@ -110,7 +154,137 @@ private:
|
||||
|
||||
protected:
|
||||
Struct struct_;
|
||||
ClassName* class_;
|
||||
BaseName* class_;
|
||||
};
|
||||
|
||||
// CefCppToC implementation for CefBase.
|
||||
class CefBaseCppToC : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
// Use this method to retrieve the underlying class instance from our
|
||||
// own structure when the structure is passed as the required first
|
||||
// parameter of a C API function call. No explicit reference counting
|
||||
// is done in this case.
|
||||
static CefRefPtr<CefBase> Get(cef_base_t* s)
|
||||
{
|
||||
// Cast our structure to the wrapper structure type.
|
||||
CefBaseCppToC::Struct* wrapperStruct =
|
||||
reinterpret_cast<CefBaseCppToC::Struct*>(s);
|
||||
// Return the underlying object instance.
|
||||
return wrapperStruct->class_->GetClass();
|
||||
}
|
||||
|
||||
// Use this method to create a wrapper structure for passing our class
|
||||
// instance to the other side.
|
||||
static cef_base_t* Wrap(CefRefPtr<CefBase> c)
|
||||
{
|
||||
// Wrap our object with the CefCppToC class.
|
||||
CefBaseCppToC* wrapper = new CefBaseCppToC(c);
|
||||
// Add a reference to our wrapper object that will be released once our
|
||||
// structure arrives on the other side.
|
||||
wrapper->AddRef();
|
||||
// Return the structure pointer that can now be passed to the other side.
|
||||
return wrapper->GetStruct();
|
||||
}
|
||||
|
||||
// Use this method to retrieve the underlying class instance when receiving
|
||||
// our wrapper structure back from the other side.
|
||||
static CefRefPtr<CefBase> Unwrap(cef_base_t* s)
|
||||
{
|
||||
// Cast our structure to the wrapper structure type.
|
||||
CefBaseCppToC::Struct* wrapperStruct =
|
||||
reinterpret_cast<CefBaseCppToC::Struct*>(s);
|
||||
// Add the underlying object instance to a smart pointer.
|
||||
CefRefPtr<CefBase> objectPtr(wrapperStruct->class_->GetClass());
|
||||
// Release the reference to our wrapper object that was added before the
|
||||
// structure was passed back to us.
|
||||
wrapperStruct->class_->Release();
|
||||
// Return the underlying object instance.
|
||||
return objectPtr;
|
||||
}
|
||||
|
||||
// Structure representation with pointer to the C++ class.
|
||||
struct Struct
|
||||
{
|
||||
cef_base_t struct_;
|
||||
CefBaseCppToC* class_;
|
||||
};
|
||||
|
||||
CefBaseCppToC(CefBase* cls)
|
||||
: class_(cls)
|
||||
{
|
||||
DCHECK(cls);
|
||||
|
||||
struct_.class_ = this;
|
||||
|
||||
// zero the underlying structure and set base members
|
||||
memset(&struct_.struct_, 0, sizeof(cef_base_t));
|
||||
struct_.struct_.size = sizeof(cef_base_t);
|
||||
struct_.struct_.add_ref = struct_add_ref;
|
||||
struct_.struct_.release = struct_release;
|
||||
struct_.struct_.get_refct = struct_get_refct;
|
||||
}
|
||||
virtual ~CefBaseCppToC() {}
|
||||
|
||||
CefBase* GetClass() { return class_; }
|
||||
|
||||
// If returning the structure across the DLL boundary you should call
|
||||
// AddRef() on this CefCppToC object. On the other side of the DLL boundary,
|
||||
// call UnderlyingRelease() on the wrapping CefCToCpp object.
|
||||
cef_base_t* GetStruct() { return &struct_.struct_; }
|
||||
|
||||
// CefBase methods increment/decrement reference counts on both this object
|
||||
// and the underlying wrapper class.
|
||||
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() { return class_->AddRef(); }
|
||||
int UnderlyingRelease() { return class_->Release(); }
|
||||
int UnderlyingGetRefCt() { return class_->GetRefCt(); }
|
||||
|
||||
private:
|
||||
static int CEF_CALLBACK struct_add_ref(struct _cef_base_t* base)
|
||||
{
|
||||
DCHECK(base);
|
||||
if(!base)
|
||||
return 0;
|
||||
|
||||
Struct* impl = reinterpret_cast<Struct*>(base);
|
||||
return impl->class_->AddRef();
|
||||
}
|
||||
|
||||
static int CEF_CALLBACK struct_release(struct _cef_base_t* base)
|
||||
{
|
||||
DCHECK(base);
|
||||
if(!base)
|
||||
return 0;
|
||||
|
||||
Struct* impl = reinterpret_cast<Struct*>(base);
|
||||
return impl->class_->Release();
|
||||
}
|
||||
|
||||
static int CEF_CALLBACK struct_get_refct(struct _cef_base_t* base)
|
||||
{
|
||||
DCHECK(base);
|
||||
if(!base)
|
||||
return 0;
|
||||
|
||||
Struct* impl = reinterpret_cast<Struct*>(base);
|
||||
return impl->class_->GetRefCt();
|
||||
}
|
||||
|
||||
protected:
|
||||
Struct struct_;
|
||||
CefBase* class_;
|
||||
};
|
||||
|
||||
#endif // _CPPTOC_H
|
||||
|
262
libcef_dll/cpptoc/frame_cpptoc.cc
Normal file
262
libcef_dll/cpptoc/frame_cpptoc.cc
Normal file
@ -0,0 +1,262 @@
|
||||
// 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/frame_cpptoc.h"
|
||||
#include "cpptoc/request_cpptoc.h"
|
||||
#include "cpptoc/stream_cpptoc.h"
|
||||
|
||||
|
||||
void CEF_CALLBACK frame_undo(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Undo();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_redo(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Redo();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_cut(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Cut();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_copy(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Copy();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_paste(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Paste();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_delete(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Delete();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_select_all(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->SelectAll();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_print(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Print();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_view_source(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->ViewSource();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_source(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring sourceStr = CefFrameCppToC::Get(frame)->GetSource();
|
||||
if(!sourceStr.empty())
|
||||
return cef_string_alloc(sourceStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_text(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring textStr = CefFrameCppToC::Get(frame)->GetText();
|
||||
if(!textStr.empty())
|
||||
return cef_string_alloc(textStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_request(cef_frame_t* frame,
|
||||
cef_request_t* request)
|
||||
{
|
||||
DCHECK(frame);
|
||||
DCHECK(request);
|
||||
if(!frame || !request)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefRequest> requestPtr = CefRequestCppToC::Unwrap(request);
|
||||
CefFrameCppToC::Get(frame)->LoadRequest(requestPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_url(cef_frame_t* frame, const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
CefFrameCppToC::Get(frame)->LoadURL(urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_string(cef_frame_t* frame,
|
||||
const wchar_t* string,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring stringStr, urlStr;
|
||||
if(string)
|
||||
stringStr = string;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
CefFrameCppToC::Get(frame)->LoadString(stringStr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_stream(cef_frame_t* frame,
|
||||
cef_stream_reader_t* stream,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
DCHECK(stream);
|
||||
if(!frame || !stream)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefStreamReader> streamPtr = CefStreamReaderCppToC::Unwrap(stream);
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
|
||||
CefFrameCppToC::Get(frame)->LoadStream(streamPtr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_execute_javascript(cef_frame_t* frame,
|
||||
const wchar_t* jsCode,
|
||||
const wchar_t* scriptUrl,
|
||||
int startLine)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring jsCodeStr, scriptUrlStr;
|
||||
if(jsCode)
|
||||
jsCodeStr = jsCode;
|
||||
if(scriptUrl)
|
||||
scriptUrlStr = scriptUrl;
|
||||
|
||||
CefFrameCppToC::Get(frame)->ExecuteJavaScript(jsCodeStr, scriptUrlStr,
|
||||
startLine);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK frame_is_main(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
return CefFrameCppToC::Get(frame)->IsMain();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK frame_is_focused(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
return CefFrameCppToC::Get(frame)->IsFocused();
|
||||
}
|
||||
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_name(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
std::wstring nameStr = CefFrameCppToC::Get(frame)->GetName();
|
||||
if(!nameStr.empty())
|
||||
return cef_string_alloc(nameStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_url(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring urlStr = CefFrameCppToC::Get(frame)->GetURL();
|
||||
if(!urlStr.empty())
|
||||
return cef_string_alloc(urlStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefFrameCppToC::CefFrameCppToC(CefFrame* cls)
|
||||
: CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>(cls)
|
||||
{
|
||||
struct_.struct_.undo = frame_undo;
|
||||
struct_.struct_.redo = frame_redo;
|
||||
struct_.struct_.cut = frame_cut;
|
||||
struct_.struct_.copy = frame_copy;
|
||||
struct_.struct_.paste = frame_paste;
|
||||
struct_.struct_.del = frame_delete;
|
||||
struct_.struct_.select_all = frame_select_all;
|
||||
struct_.struct_.print = frame_print;
|
||||
struct_.struct_.view_source = frame_view_source;
|
||||
struct_.struct_.get_source = frame_get_source;
|
||||
struct_.struct_.get_text = frame_get_text;
|
||||
struct_.struct_.load_request = frame_load_request;
|
||||
struct_.struct_.load_url = frame_load_url;
|
||||
struct_.struct_.load_string = frame_load_string;
|
||||
struct_.struct_.load_stream = frame_load_stream;
|
||||
struct_.struct_.execute_javascript = frame_execute_javascript;
|
||||
struct_.struct_.is_main = frame_is_main;
|
||||
struct_.struct_.is_focused = frame_is_focused;
|
||||
struct_.struct_.get_name = frame_get_name;
|
||||
struct_.struct_.get_url = frame_get_url;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>::DebugObjCt = 0;
|
||||
#endif
|
@ -2,8 +2,8 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _VARIANT_CPPTOC_H
|
||||
#define _VARIANT_CPPTOC_H
|
||||
#ifndef _FRAME_CPPTOC_H
|
||||
#define _FRAME_CPPTOC_H
|
||||
|
||||
#ifndef BUILDING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||
@ -14,15 +14,16 @@
|
||||
#include "cpptoc.h"
|
||||
|
||||
|
||||
// Wrap a C++ browser class with a C browser structure.
|
||||
// Wrap a C++ frame class with a C frame structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefVariantCppToC : public CefCppToC<CefVariant, cef_variant_t>
|
||||
class CefFrameCppToC
|
||||
: public CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>
|
||||
{
|
||||
public:
|
||||
CefVariantCppToC(CefVariant* cls);
|
||||
virtual ~CefVariantCppToC() {}
|
||||
CefFrameCppToC(CefFrame* cls);
|
||||
virtual ~CefFrameCppToC() {}
|
||||
};
|
||||
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
#endif // _VARIANT_CPPTOC_H
|
||||
#endif // _FRAME_CPPTOC_H
|
@ -5,8 +5,10 @@
|
||||
#include "../precompiled_libcef.h"
|
||||
#include "cpptoc/handler_cpptoc.h"
|
||||
#include "ctocpp/browser_ctocpp.h"
|
||||
#include "ctocpp/frame_ctocpp.h"
|
||||
#include "ctocpp/request_ctocpp.h"
|
||||
#include "ctocpp/stream_ctocpp.h"
|
||||
#include "ctocpp/v8value_ctocpp.h"
|
||||
#include "transfer_util.h"
|
||||
|
||||
|
||||
@ -22,42 +24,29 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
|
||||
if(!handler || !windowInfo || !newHandler || !*newHandler || !url)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
CefWindowInfo wndInfo(*windowInfo);
|
||||
|
||||
// |newHandler| will start off pointing to the current handler.
|
||||
CefHandlerCppToC::Struct* structPtr
|
||||
= reinterpret_cast<CefHandlerCppToC::Struct*>(*newHandler);
|
||||
|
||||
CefWindowInfo wndInfo(*windowInfo);
|
||||
CefRefPtr<CefBrowser> browserPtr;
|
||||
CefRefPtr<CefHandler> handlerPtr(structPtr->class_->GetClass());
|
||||
structPtr->class_->Release();
|
||||
|
||||
std::wstring urlStr;
|
||||
CefRefPtr<CefHandler> handlerPtr = CefHandlerCppToC::Unwrap(*newHandler);
|
||||
CefHandler* origHandler = handlerPtr.get();
|
||||
|
||||
// |parentBrowser| will be NULL if this is a top-level browser window.
|
||||
CefRefPtr<CefBrowser> browserPtr;
|
||||
if(parentBrowser)
|
||||
{
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(parentBrowser);
|
||||
browserPtr = bp;
|
||||
bp->UnderlyingRelease();
|
||||
}
|
||||
browserPtr = CefBrowserCToCpp::Wrap(parentBrowser);
|
||||
|
||||
std::wstring urlStr;
|
||||
if(*url)
|
||||
urlStr = *url;
|
||||
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleBeforeCreated(
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleBeforeCreated(
|
||||
browserPtr, wndInfo, popup, handlerPtr, urlStr);
|
||||
|
||||
transfer_string_contents(urlStr, url);
|
||||
|
||||
if(handlerPtr.get() != structPtr->class_->GetClass())
|
||||
{
|
||||
if(handlerPtr.get() != origHandler) {
|
||||
// The handler has been changed.
|
||||
CefHandlerCppToC* hobj = new CefHandlerCppToC(handlerPtr);
|
||||
hobj->AddRef();
|
||||
*newHandler = hobj->GetStruct();
|
||||
*newHandler = CefHandlerCppToC::Wrap(handlerPtr);
|
||||
}
|
||||
|
||||
// WindowInfo may or may not have changed.
|
||||
@ -79,37 +68,26 @@ enum cef_retval_t CEF_CALLBACK handler_handle_after_created(
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->HandleAfterCreated(browserPtr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleAfterCreated(
|
||||
CefBrowserCToCpp::Wrap(browser));
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_address_change(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
if(!handler || !browser)
|
||||
DCHECK(frame);
|
||||
if(!handler || !browser || !frame)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
|
||||
return impl->class_->GetClass()->HandleAddressChange(browserPtr, urlStr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleAddressChange(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), urlStr);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_title_change(
|
||||
@ -121,100 +99,75 @@ enum cef_retval_t CEF_CALLBACK handler_handle_title_change(
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring titleStr;
|
||||
if(title)
|
||||
titleStr = title;
|
||||
|
||||
return impl->class_->GetClass()->HandleTitleChange(browserPtr, titleStr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleTitleChange(
|
||||
CefBrowserCToCpp::Wrap(browser), titleStr);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_before_browse(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
struct _cef_request_t* request, cef_handler_navtype_t navType,
|
||||
int isRedirect)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(request);
|
||||
if(!handler || !browser || !request)
|
||||
if(!handler || !browser || !request || !frame)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
CefRequestCToCpp* rp = new CefRequestCToCpp(request);
|
||||
CefRefPtr<CefRequest> requestPtr(rp);
|
||||
rp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->HandleBeforeBrowse(browserPtr, requestPtr,
|
||||
navType, (isRedirect ? true : false));
|
||||
return CefHandlerCppToC::Get(handler)->HandleBeforeBrowse(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
|
||||
CefRequestCToCpp::Wrap(request), navType, (isRedirect ? true : false));
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_load_start(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser)
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
CefRefPtr<CefFrame> framePtr;
|
||||
if(frame)
|
||||
framePtr = CefFrameCToCpp::Wrap(frame);
|
||||
|
||||
return impl->class_->GetClass()->HandleLoadStart(browserPtr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleLoadStart(
|
||||
CefBrowserCToCpp::Wrap(browser), framePtr);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_load_end(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser)
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
CefRefPtr<CefFrame> framePtr;
|
||||
if(frame)
|
||||
framePtr = CefFrameCToCpp::Wrap(frame);
|
||||
|
||||
return impl->class_->GetClass()->HandleLoadEnd(browserPtr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleLoadEnd(
|
||||
CefBrowserCToCpp::Wrap(browser), framePtr);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
cef_handler_errorcode_t errorCode, const wchar_t* failedUrl,
|
||||
cef_string_t* errorText)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(errorText);
|
||||
if(!handler || !browser || !errorText)
|
||||
if(!handler || !browser || !errorText || !frame)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring failedUrlStr, errorTextStr;
|
||||
|
||||
if(failedUrl)
|
||||
@ -222,8 +175,9 @@ enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
|
||||
if(*errorText)
|
||||
errorTextStr = *errorText;
|
||||
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleLoadError(browserPtr,
|
||||
errorCode, failedUrlStr, errorTextStr);
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleLoadError(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), errorCode,
|
||||
failedUrlStr, errorTextStr);
|
||||
|
||||
transfer_string_contents(errorTextStr, errorText);
|
||||
|
||||
@ -244,17 +198,6 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load(
|
||||
if(!handler || !browser || !redirectUrl || !resourceStream || !mimeType)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
CefRequestCToCpp* rp = new CefRequestCToCpp(request);
|
||||
CefRefPtr<CefRequest> requestPtr(rp);
|
||||
rp->UnderlyingRelease();
|
||||
|
||||
std::wstring redirectUrlStr, mimeTypeStr;
|
||||
CefRefPtr<CefStreamReader> streamPtr;
|
||||
|
||||
@ -263,20 +206,16 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load(
|
||||
if(*mimeType)
|
||||
mimeTypeStr = *mimeType;
|
||||
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleBeforeResourceLoad(
|
||||
browserPtr, requestPtr, redirectUrlStr, streamPtr, mimeTypeStr,
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->
|
||||
HandleBeforeResourceLoad(CefBrowserCToCpp::Wrap(browser),
|
||||
CefRequestCToCpp::Wrap(request), redirectUrlStr, streamPtr, mimeTypeStr,
|
||||
loadFlags);
|
||||
|
||||
transfer_string_contents(redirectUrlStr, redirectUrl);
|
||||
transfer_string_contents(mimeTypeStr, mimeType);
|
||||
|
||||
if(streamPtr.get())
|
||||
{
|
||||
CefStreamReaderCToCpp* sp =
|
||||
static_cast<CefStreamReaderCToCpp*>(streamPtr.get());
|
||||
sp->UnderlyingAddRef();
|
||||
*resourceStream = sp->GetStruct();
|
||||
}
|
||||
*resourceStream = CefStreamReaderCToCpp::Unwrap(streamPtr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -291,14 +230,8 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_menu(
|
||||
if(!handler || !browser || !menuInfo)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->HandleBeforeMenu(browserPtr, *menuInfo);
|
||||
return CefHandlerCppToC::Get(handler)->HandleBeforeMenu(
|
||||
CefBrowserCToCpp::Wrap(browser), *menuInfo);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
|
||||
@ -311,19 +244,12 @@ enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
|
||||
if(!handler || !browser || !label)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring labelStr;
|
||||
if(*label)
|
||||
labelStr = *label;
|
||||
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleGetMenuLabel(
|
||||
browserPtr, menuId, labelStr);
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleGetMenuLabel(
|
||||
CefBrowserCToCpp::Wrap(browser), menuId, labelStr);
|
||||
|
||||
transfer_string_contents(labelStr, label);
|
||||
|
||||
@ -339,18 +265,12 @@ enum cef_retval_t CEF_CALLBACK handler_handle_menu_action(
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->HandleMenuAction(browserPtr, menuId);
|
||||
return CefHandlerCppToC::Get(handler)->HandleMenuAction(
|
||||
CefBrowserCToCpp::Wrap(browser), menuId);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
cef_print_info_t* printInfo, const wchar_t* url, const wchar_t* title,
|
||||
int currentPage, int maxPages, cef_string_t* topLeft,
|
||||
cef_string_t* topCenter, cef_string_t* topRight,
|
||||
@ -359,20 +279,14 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(printInfo);
|
||||
DCHECK(topLeft && topCenter && topRight);
|
||||
DCHECK(bottomLeft && bottomCenter && bottomRight);
|
||||
if(!handler || !browser || !printInfo || !topLeft || !topCenter || !topRight
|
||||
|| !bottomLeft || !bottomCenter || !bottomRight)
|
||||
if(!handler || !browser || !frame || !printInfo || !topLeft || !topCenter
|
||||
|| !topRight || !bottomLeft || !bottomCenter || !bottomRight)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring urlStr, titleStr;
|
||||
std::wstring topLeftStr, topCenterStr, topRightStr;
|
||||
std::wstring bottomLeftStr, bottomCenterStr, bottomRightStr;
|
||||
@ -395,10 +309,11 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
|
||||
if(*bottomRight)
|
||||
bottomRightStr = *bottomRight;
|
||||
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->
|
||||
HandlePrintHeaderFooter(browserPtr, info, urlStr, titleStr,
|
||||
currentPage, maxPages, topLeftStr, topCenterStr, topRightStr,
|
||||
bottomLeftStr, bottomCenterStr, bottomRightStr);
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->
|
||||
HandlePrintHeaderFooter(CefBrowserCToCpp::Wrap(browser),
|
||||
CefFrameCToCpp::Wrap(frame), info, urlStr, titleStr, currentPage,
|
||||
maxPages, topLeftStr, topCenterStr, topRightStr, bottomLeftStr,
|
||||
bottomCenterStr, bottomRightStr);
|
||||
|
||||
transfer_string_contents(topLeftStr, topLeft);
|
||||
transfer_string_contents(topCenterStr, topCenter);
|
||||
@ -411,76 +326,60 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_jsalert(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
const wchar_t* message)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
if(!handler || !browser)
|
||||
DCHECK(frame);
|
||||
if(!handler || !browser || !frame)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring messageStr;
|
||||
if(message)
|
||||
messageStr = message;
|
||||
|
||||
return impl->class_->GetClass()->HandleJSAlert(browserPtr, messageStr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleJSAlert(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_jsconfirm(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
const wchar_t* message, int* retval)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(retval);
|
||||
if(!handler || !browser || !retval)
|
||||
if(!handler || !browser || !retval || !frame)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring messageStr;
|
||||
if(message)
|
||||
messageStr = message;
|
||||
|
||||
bool ret = false;
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleJSConfirm(browserPtr,
|
||||
messageStr, ret);
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleJSConfirm(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr,
|
||||
ret);
|
||||
*retval = (ret ? 1 : 0);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_jsprompt(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
|
||||
const wchar_t* message, const wchar_t* defaultValue, int* retval,
|
||||
cef_string_t* result)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(retval);
|
||||
DCHECK(result);
|
||||
if(!handler || !browser || !retval || !result)
|
||||
if(!handler || !browser || !frame || !retval || !result)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
std::wstring messageStr, defaultValueStr, resultStr;
|
||||
|
||||
if(message)
|
||||
@ -491,8 +390,9 @@ enum cef_retval_t CEF_CALLBACK handler_handle_jsprompt(
|
||||
resultStr = *result;
|
||||
|
||||
bool ret = false;
|
||||
enum cef_retval_t rv = impl->class_->GetClass()->HandleJSPrompt(
|
||||
browserPtr, messageStr, defaultValueStr, ret, resultStr);
|
||||
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleJSPrompt(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr,
|
||||
defaultValueStr, ret, resultStr);
|
||||
*retval = (ret ? 1 : 0);
|
||||
|
||||
transfer_string_contents(resultStr, result);
|
||||
@ -508,14 +408,8 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_window_close(
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->HandleBeforeWindowClose(browserPtr);
|
||||
return CefHandlerCppToC::Get(handler)->HandleBeforeWindowClose(
|
||||
CefBrowserCToCpp::Wrap(browser));
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_take_focus(
|
||||
@ -526,20 +420,29 @@ enum cef_retval_t CEF_CALLBACK handler_handle_take_focus(
|
||||
if(!handler || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefHandlerCppToC::Struct* impl =
|
||||
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
|
||||
|
||||
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
|
||||
CefRefPtr<CefBrowser> browserPtr(bp);
|
||||
bp->UnderlyingRelease();
|
||||
|
||||
return impl->class_->GetClass()->
|
||||
HandleTakeFocus(browserPtr, (reverse ? true : false));
|
||||
return CefHandlerCppToC::Get(handler)->HandleTakeFocus(
|
||||
CefBrowserCToCpp::Wrap(browser), (reverse ? true : false));
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_jsbinding(
|
||||
struct _cef_handler_t* handler, cef_browser_t* browser,
|
||||
cef_frame_t* frame, struct _cef_v8value_t* object)
|
||||
{
|
||||
DCHECK(handler);
|
||||
DCHECK(browser);
|
||||
DCHECK(frame);
|
||||
DCHECK(object);
|
||||
if(!handler || !browser || !frame || !object)
|
||||
return RV_CONTINUE;
|
||||
|
||||
return CefHandlerCppToC::Get(handler)->HandleJSBinding(
|
||||
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
|
||||
CefV8ValueCToCpp::Wrap(object));
|
||||
}
|
||||
|
||||
|
||||
CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
|
||||
: CefCppToC<CefHandler, cef_handler_t>(cls)
|
||||
: CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>(cls)
|
||||
{
|
||||
struct_.struct_.handle_before_created = handler_handle_before_created;
|
||||
struct_.struct_.handle_after_created = handler_handle_after_created;
|
||||
@ -562,8 +465,9 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
|
||||
struct_.struct_.handle_before_window_close =
|
||||
handler_handle_before_window_close;
|
||||
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
||||
struct_.struct_.handle_jsbinding = handler_handle_jsbinding;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefHandler, cef_handler_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
// Wrap a C++ handler class with a C handler structure.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefHandlerCppToC : public CefCppToC<CefHandler, cef_handler_t>
|
||||
class CefHandlerCppToC
|
||||
: public CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>
|
||||
{
|
||||
public:
|
||||
CefHandlerCppToC(CefHandler* cls);
|
||||
|
@ -1,158 +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/jshandler_cpptoc.h"
|
||||
#include "ctocpp/browser_ctocpp.h"
|
||||
#include "ctocpp/variant_ctocpp.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(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;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefJSHandler, cef_jshandler_t>::DebugObjCt = 0;
|
||||
#endif
|
@ -13,13 +13,10 @@ cef_string_t CEF_CALLBACK request_get_url(struct _cef_request_t* request)
|
||||
if(!request)
|
||||
return NULL;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring urlStr = impl->class_->GetClass()->GetURL();
|
||||
if(urlStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(urlStr.c_str());
|
||||
std::wstring urlStr = CefRequestCppToC::Get(request)->GetURL();
|
||||
if(!urlStr.empty())
|
||||
return cef_string_alloc(urlStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_set_url(struct _cef_request_t* request,
|
||||
@ -29,44 +26,10 @@ void CEF_CALLBACK request_set_url(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
impl->class_->GetClass()->SetURL(urlStr);
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK request_get_frame(struct _cef_request_t* request)
|
||||
{
|
||||
DCHECK(request);
|
||||
if(!request)
|
||||
return NULL;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring frameStr = impl->class_->GetClass()->GetFrame();
|
||||
if(frameStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(frameStr.c_str());
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_set_frame(struct _cef_request_t* request,
|
||||
const wchar_t* frame)
|
||||
{
|
||||
DCHECK(request);
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring frameStr;
|
||||
if(frame)
|
||||
frameStr = frame;
|
||||
impl->class_->GetClass()->SetFrame(frameStr);
|
||||
CefRequestCppToC::Get(request)->SetURL(urlStr);
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK request_get_method(struct _cef_request_t* request)
|
||||
@ -75,13 +38,10 @@ cef_string_t CEF_CALLBACK request_get_method(struct _cef_request_t* request)
|
||||
if(!request)
|
||||
return NULL;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring methodStr = impl->class_->GetClass()->GetMethod();
|
||||
if(methodStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(methodStr.c_str());
|
||||
std::wstring methodStr = CefRequestCppToC::Get(request)->GetMethod();
|
||||
if(!methodStr.empty())
|
||||
return cef_string_alloc(methodStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_set_method(struct _cef_request_t* request,
|
||||
@ -91,13 +51,10 @@ void CEF_CALLBACK request_set_method(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
std::wstring methodStr;
|
||||
if(method)
|
||||
methodStr = method;
|
||||
impl->class_->GetClass()->SetMethod(methodStr);
|
||||
CefRequestCppToC::Get(request)->SetMethod(methodStr);
|
||||
}
|
||||
|
||||
struct _cef_post_data_t* CEF_CALLBACK request_get_post_data(
|
||||
@ -107,17 +64,12 @@ struct _cef_post_data_t* CEF_CALLBACK request_get_post_data(
|
||||
if(!request)
|
||||
return NULL;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
CefRefPtr<CefPostData> postdata =
|
||||
impl->class_->GetClass()->GetPostData();
|
||||
if(!postdata.get())
|
||||
CefRefPtr<CefPostData> postDataPtr =
|
||||
CefRequestCppToC::Get(request)->GetPostData();
|
||||
if(!postDataPtr.get())
|
||||
return NULL;
|
||||
|
||||
CefPostDataCppToC* rp = new CefPostDataCppToC(postdata);
|
||||
rp->AddRef();
|
||||
return rp->GetStruct();
|
||||
return CefPostDataCppToC::Wrap(postDataPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_set_post_data(struct _cef_request_t* request,
|
||||
@ -127,16 +79,11 @@ void CEF_CALLBACK request_set_post_data(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
CefPostDataCppToC::Struct* postStructPtr =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
|
||||
CefRefPtr<CefPostData> postDataPtr;
|
||||
if(postStructPtr)
|
||||
postDataPtr = postStructPtr->class_->GetClass();
|
||||
if(postData)
|
||||
postDataPtr = CefPostDataCppToC::Unwrap(postData);
|
||||
|
||||
impl->class_->GetClass()->SetPostData(postDataPtr);
|
||||
CefRequestCppToC::Get(request)->SetPostData(postDataPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_get_header_map(struct _cef_request_t* request,
|
||||
@ -146,12 +93,8 @@ void CEF_CALLBACK request_get_header_map(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
CefRequest::HeaderMap map;
|
||||
impl->class_->GetClass()->GetHeaderMap(map);
|
||||
|
||||
CefRequestCppToC::Get(request)->GetHeaderMap(map);
|
||||
transfer_string_map_contents(map, headerMap);
|
||||
}
|
||||
|
||||
@ -162,19 +105,15 @@ void CEF_CALLBACK request_set_header_map(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
|
||||
CefRequest::HeaderMap map;
|
||||
if(headerMap)
|
||||
transfer_string_map_contents(headerMap, map);
|
||||
|
||||
impl->class_->GetClass()->SetHeaderMap(map);
|
||||
CefRequestCppToC::Get(request)->SetHeaderMap(map);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_set(struct _cef_request_t* request,
|
||||
const wchar_t* url, const wchar_t* frame,
|
||||
const wchar_t* method,
|
||||
const wchar_t* url, const wchar_t* method,
|
||||
struct _cef_post_data_t* postData,
|
||||
cef_string_map_t headerMap)
|
||||
{
|
||||
@ -182,37 +121,28 @@ void CEF_CALLBACK request_set(struct _cef_request_t* request,
|
||||
if(!request)
|
||||
return;
|
||||
|
||||
CefRequestCppToC::Struct* impl =
|
||||
reinterpret_cast<CefRequestCppToC::Struct*>(request);
|
||||
CefPostDataCppToC::Struct* postStructPtr =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
|
||||
std::wstring urlStr, frameStr, methodStr;
|
||||
CefRefPtr<CefPostData> postPtr;
|
||||
std::wstring urlStr, methodStr;
|
||||
CefRefPtr<CefPostData> postDataPtr;
|
||||
CefRequest::HeaderMap map;
|
||||
|
||||
if(url)
|
||||
urlStr = url;
|
||||
if(frame)
|
||||
frameStr = frame;
|
||||
if(method)
|
||||
methodStr = method;
|
||||
if(postStructPtr)
|
||||
postPtr = postStructPtr->class_->GetClass();
|
||||
if(postData)
|
||||
postDataPtr = CefPostDataCppToC::Unwrap(postData);
|
||||
if(headerMap)
|
||||
transfer_string_map_contents(headerMap, map);
|
||||
|
||||
impl->class_->GetClass()->Set(urlStr, frameStr, methodStr, postPtr, map);
|
||||
CefRequestCppToC::Get(request)->Set(urlStr, methodStr, postDataPtr, map);
|
||||
}
|
||||
|
||||
|
||||
CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
|
||||
: CefCppToC<CefRequest, cef_request_t>(cls)
|
||||
: CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>(cls)
|
||||
{
|
||||
struct_.struct_.get_url = request_get_url;
|
||||
struct_.struct_.set_url = request_set_url;
|
||||
struct_.struct_.get_frame = request_get_frame;
|
||||
struct_.struct_.set_frame = request_set_frame;
|
||||
struct_.struct_.get_method = request_get_method;
|
||||
struct_.struct_.set_method = request_set_method;
|
||||
struct_.struct_.get_post_data = request_get_post_data;
|
||||
@ -223,7 +153,7 @@ CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefRequest, cef_request_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
||||
|
||||
@ -234,9 +164,7 @@ size_t CEF_CALLBACK post_data_get_element_count(
|
||||
if(!postData)
|
||||
return 0;
|
||||
|
||||
CefPostDataCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
return impl->class_->GetClass()->GetElementCount();
|
||||
return CefPostDataCppToC::Get(postData)->GetElementCount();
|
||||
}
|
||||
|
||||
struct _cef_post_data_element_t* CEF_CALLBACK post_data_get_element(
|
||||
@ -246,18 +174,13 @@ struct _cef_post_data_element_t* CEF_CALLBACK post_data_get_element(
|
||||
if(!postData)
|
||||
return NULL;
|
||||
|
||||
CefPostDataCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
|
||||
CefPostData::ElementVector elements;
|
||||
impl->class_->GetClass()->GetElements(elements);
|
||||
CefPostDataCppToC::Get(postData)->GetElements(elements);
|
||||
|
||||
if(index < 0 || index >= (int)elements.size())
|
||||
return NULL;
|
||||
|
||||
CefPostDataElementCppToC* rp = new CefPostDataElementCppToC(elements[index]);
|
||||
rp->AddRef();
|
||||
return rp->GetStruct();
|
||||
return CefPostDataElementCppToC::Wrap(elements[index]);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK post_data_remove_element(struct _cef_post_data_t* postData,
|
||||
@ -268,12 +191,9 @@ int CEF_CALLBACK post_data_remove_element(struct _cef_post_data_t* postData,
|
||||
if(!postData || !element)
|
||||
return 0;
|
||||
|
||||
CefPostDataCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
CefPostDataElementCppToC::Struct* structPtr =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(element);
|
||||
|
||||
return impl->class_->GetClass()->RemoveElement(structPtr->class_->GetClass());
|
||||
CefRefPtr<CefPostDataElement> postDataElementPtr =
|
||||
CefPostDataElementCppToC::Unwrap(element);
|
||||
return CefPostDataCppToC::Get(postData)->RemoveElement(postDataElementPtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK post_data_add_element(struct _cef_post_data_t* postData,
|
||||
@ -284,12 +204,9 @@ int CEF_CALLBACK post_data_add_element(struct _cef_post_data_t* postData,
|
||||
if(!postData || !element)
|
||||
return 0;
|
||||
|
||||
CefPostDataCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
CefPostDataElementCppToC::Struct* structPtr =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(element);
|
||||
|
||||
return impl->class_->GetClass()->AddElement(structPtr->class_->GetClass());
|
||||
CefRefPtr<CefPostDataElement> postDataElementPtr =
|
||||
CefPostDataElementCppToC::Unwrap(element);
|
||||
return CefPostDataCppToC::Get(postData)->AddElement(postDataElementPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK post_data_remove_elements(struct _cef_post_data_t* postData)
|
||||
@ -298,15 +215,12 @@ void CEF_CALLBACK post_data_remove_elements(struct _cef_post_data_t* postData)
|
||||
if(!postData)
|
||||
return;
|
||||
|
||||
CefPostDataCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
|
||||
|
||||
impl->class_->GetClass()->RemoveElements();
|
||||
CefPostDataCppToC::Get(postData)->RemoveElements();
|
||||
}
|
||||
|
||||
|
||||
CefPostDataCppToC::CefPostDataCppToC(CefPostData* cls)
|
||||
: CefCppToC<CefPostData, cef_post_data_t>(cls)
|
||||
: CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>(cls)
|
||||
{
|
||||
struct_.struct_.get_element_count = post_data_get_element_count;
|
||||
struct_.struct_.get_element = post_data_get_element;
|
||||
@ -316,7 +230,8 @@ CefPostDataCppToC::CefPostDataCppToC(CefPostData* cls)
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefPostData, cef_post_data_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>::DebugObjCt
|
||||
= 0;
|
||||
#endif
|
||||
|
||||
|
||||
@ -327,9 +242,7 @@ void CEF_CALLBACK post_data_element_set_to_empty(
|
||||
if(!postDataElement)
|
||||
return;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
impl->class_->GetClass()->SetToEmpty();
|
||||
CefPostDataElementCppToC::Get(postDataElement)->SetToEmpty();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK post_data_element_set_to_file(
|
||||
@ -340,13 +253,11 @@ void CEF_CALLBACK post_data_element_set_to_file(
|
||||
if(!postDataElement)
|
||||
return;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
|
||||
std::wstring fileNameStr;
|
||||
if(fileName)
|
||||
fileNameStr = fileName;
|
||||
impl->class_->GetClass()->SetToFile(fileNameStr);
|
||||
|
||||
CefPostDataElementCppToC::Get(postDataElement)->SetToFile(fileNameStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK post_data_element_set_to_bytes(
|
||||
@ -357,9 +268,7 @@ void CEF_CALLBACK post_data_element_set_to_bytes(
|
||||
if(!postDataElement)
|
||||
return;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
impl->class_->GetClass()->SetToBytes(size, bytes);
|
||||
CefPostDataElementCppToC::Get(postDataElement)->SetToBytes(size, bytes);
|
||||
}
|
||||
|
||||
cef_postdataelement_type_t CEF_CALLBACK post_data_element_get_type(
|
||||
@ -369,9 +278,7 @@ cef_postdataelement_type_t CEF_CALLBACK post_data_element_get_type(
|
||||
if(!postDataElement)
|
||||
return PDE_TYPE_EMPTY;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
return impl->class_->GetClass()->GetType();
|
||||
return CefPostDataElementCppToC::Get(postDataElement)->GetType();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK post_data_element_get_file(
|
||||
@ -381,13 +288,11 @@ cef_string_t CEF_CALLBACK post_data_element_get_file(
|
||||
if(!postDataElement)
|
||||
return NULL;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
|
||||
std::wstring fileNameStr = impl->class_->GetClass()->GetFile();
|
||||
if(fileNameStr.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(fileNameStr.c_str());
|
||||
std::wstring fileNameStr =
|
||||
CefPostDataElementCppToC::Get(postDataElement)->GetFile();
|
||||
if(!fileNameStr.empty())
|
||||
return cef_string_alloc(fileNameStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK post_data_element_get_bytes_count(
|
||||
@ -397,9 +302,7 @@ size_t CEF_CALLBACK post_data_element_get_bytes_count(
|
||||
if(!postDataElement)
|
||||
return 0;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
return impl->class_->GetClass()->GetBytesCount();
|
||||
return CefPostDataElementCppToC::Get(postDataElement)->GetBytesCount();
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK post_data_element_get_bytes(
|
||||
@ -410,14 +313,13 @@ size_t CEF_CALLBACK post_data_element_get_bytes(
|
||||
if(!postDataElement)
|
||||
return 0;
|
||||
|
||||
CefPostDataElementCppToC::Struct* impl =
|
||||
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
|
||||
return impl->class_->GetClass()->GetBytes(size, bytes);
|
||||
return CefPostDataElementCppToC::Get(postDataElement)->GetBytes(size, bytes);
|
||||
}
|
||||
|
||||
|
||||
CefPostDataElementCppToC::CefPostDataElementCppToC(CefPostDataElement* cls)
|
||||
: CefCppToC<CefPostDataElement, cef_post_data_element_t>(cls)
|
||||
: CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
|
||||
cef_post_data_element_t>(cls)
|
||||
{
|
||||
struct_.struct_.set_to_empty = post_data_element_set_to_empty;
|
||||
struct_.struct_.set_to_file = post_data_element_set_to_file;
|
||||
@ -429,5 +331,6 @@ CefPostDataElementCppToC::CefPostDataElementCppToC(CefPostDataElement* cls)
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefPostDataElement, cef_post_data_element_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
|
||||
cef_post_data_element_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
// Wrap a C++ request class with a C request structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefRequestCppToC : public CefCppToC<CefRequest, cef_request_t>
|
||||
class CefRequestCppToC
|
||||
: public CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>
|
||||
{
|
||||
public:
|
||||
CefRequestCppToC(CefRequest* cls);
|
||||
@ -26,7 +27,8 @@ public:
|
||||
|
||||
// Wrap a C++ post data class with a C post data structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefPostDataCppToC : public CefCppToC<CefPostData, cef_post_data_t>
|
||||
class CefPostDataCppToC
|
||||
: public CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>
|
||||
{
|
||||
public:
|
||||
CefPostDataCppToC(CefPostData* cls);
|
||||
@ -38,8 +40,9 @@ class CefPostDataElementCppToC;
|
||||
|
||||
// Wrap a C++ post data element class with a C post data element structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefPostDataElementCppToC :
|
||||
public CefCppToC<CefPostDataElement, cef_post_data_element_t>
|
||||
class CefPostDataElementCppToC
|
||||
: public CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
|
||||
cef_post_data_element_t>
|
||||
{
|
||||
public:
|
||||
CefPostDataElementCppToC(CefPostDataElement* cls);
|
||||
|
@ -13,9 +13,7 @@ size_t CEF_CALLBACK stream_reader_read(struct _cef_stream_reader_t* stream,
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamReaderCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Read(ptr, size, n);
|
||||
return CefStreamReaderCppToC::Get(stream)->Read(ptr, size, n);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK stream_reader_seek(struct _cef_stream_reader_t* stream,
|
||||
@ -25,9 +23,7 @@ int CEF_CALLBACK stream_reader_seek(struct _cef_stream_reader_t* stream,
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamReaderCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Seek(offset, whence);
|
||||
return CefStreamReaderCppToC::Get(stream)->Seek(offset, whence);
|
||||
}
|
||||
|
||||
long CEF_CALLBACK stream_reader_tell(struct _cef_stream_reader_t* stream)
|
||||
@ -36,9 +32,7 @@ long CEF_CALLBACK stream_reader_tell(struct _cef_stream_reader_t* stream)
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamReaderCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Tell();
|
||||
return CefStreamReaderCppToC::Get(stream)->Tell();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* stream)
|
||||
@ -47,14 +41,13 @@ int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* stream)
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamReaderCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Eof();
|
||||
return CefStreamReaderCppToC::Get(stream)->Eof();
|
||||
}
|
||||
|
||||
|
||||
CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
|
||||
: CefCppToC<CefStreamReader, cef_stream_reader_t>(cls)
|
||||
: CefCppToC<CefStreamReaderCppToC, CefStreamReader,
|
||||
cef_stream_reader_t>(cls)
|
||||
{
|
||||
struct_.struct_.read = stream_reader_read;
|
||||
struct_.struct_.seek = stream_reader_seek;
|
||||
@ -63,7 +56,8 @@ CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefStreamReader, cef_stream_reader_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefStreamReaderCppToC, CefStreamReader,
|
||||
cef_stream_reader_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
||||
|
||||
@ -74,9 +68,7 @@ size_t CEF_CALLBACK stream_writer_write(struct _cef_stream_writer_t* stream,
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamWriterCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Write(ptr, size, n);
|
||||
return CefStreamWriterCppToC::Get(stream)->Write(ptr, size, n);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK stream_writer_seek(struct _cef_stream_writer_t* stream,
|
||||
@ -86,9 +78,7 @@ int CEF_CALLBACK stream_writer_seek(struct _cef_stream_writer_t* stream,
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamWriterCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Seek(offset, whence);
|
||||
return CefStreamWriterCppToC::Get(stream)->Seek(offset, whence);
|
||||
}
|
||||
|
||||
long CEF_CALLBACK stream_writer_tell(struct _cef_stream_writer_t* stream)
|
||||
@ -97,9 +87,7 @@ long CEF_CALLBACK stream_writer_tell(struct _cef_stream_writer_t* stream)
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamWriterCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Tell();
|
||||
return CefStreamWriterCppToC::Get(stream)->Tell();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK stream_writer_flush(struct _cef_stream_writer_t* stream)
|
||||
@ -108,14 +96,13 @@ int CEF_CALLBACK stream_writer_flush(struct _cef_stream_writer_t* stream)
|
||||
if(!stream)
|
||||
return 0;
|
||||
|
||||
CefStreamWriterCppToC::Struct* impl =
|
||||
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
|
||||
return impl->class_->GetClass()->Flush();
|
||||
return CefStreamWriterCppToC::Get(stream)->Flush();
|
||||
}
|
||||
|
||||
|
||||
CefStreamWriterCppToC::CefStreamWriterCppToC(CefStreamWriter* cls)
|
||||
: CefCppToC<CefStreamWriter, cef_stream_writer_t>(cls)
|
||||
: CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
|
||||
cef_stream_writer_t>(cls)
|
||||
{
|
||||
struct_.struct_.write = stream_writer_write;
|
||||
struct_.struct_.seek = stream_writer_seek;
|
||||
@ -124,5 +111,6 @@ CefStreamWriterCppToC::CefStreamWriterCppToC(CefStreamWriter* cls)
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefStreamWriter, cef_stream_writer_t>::DebugObjCt = 0;
|
||||
long CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
|
||||
cef_stream_writer_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
// Wrap a C++ stream reader class with a C stream reader structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefStreamReaderCppToC :
|
||||
public CefCppToC<CefStreamReader, cef_stream_reader_t>
|
||||
class CefStreamReaderCppToC
|
||||
: public CefCppToC<CefStreamReaderCppToC, CefStreamReader,
|
||||
cef_stream_reader_t>
|
||||
{
|
||||
public:
|
||||
CefStreamReaderCppToC(CefStreamReader* cls);
|
||||
@ -27,8 +28,9 @@ public:
|
||||
|
||||
// Wrap a C++ stream writer class with a C stream writer structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefStreamWriterCppToC :
|
||||
public CefCppToC<CefStreamWriter, cef_stream_writer_t>
|
||||
class CefStreamWriterCppToC
|
||||
: public CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
|
||||
cef_stream_writer_t>
|
||||
{
|
||||
public:
|
||||
CefStreamWriterCppToC(CefStreamWriter* cls);
|
||||
|
54
libcef_dll/cpptoc/v8handler_cpptoc.cc
Normal file
54
libcef_dll/cpptoc/v8handler_cpptoc.cc
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.
|
||||
|
||||
#include "../precompiled_libcef.h"
|
||||
#include "cpptoc/v8handler_cpptoc.h"
|
||||
#include "ctocpp/v8value_ctocpp.h"
|
||||
|
||||
|
||||
int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* v8handler,
|
||||
const wchar_t* name, struct _cef_v8value_t* object, size_t numargs,
|
||||
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
|
||||
cef_string_t* exception)
|
||||
{
|
||||
DCHECK(v8handler);
|
||||
if(!v8handler)
|
||||
return RV_CONTINUE;
|
||||
|
||||
CefRefPtr<CefV8Value> objectPtr;
|
||||
if(object)
|
||||
objectPtr = CefV8ValueCToCpp::Wrap(object);
|
||||
|
||||
std::wstring nameStr;
|
||||
if(name)
|
||||
nameStr = name;
|
||||
|
||||
CefV8ValueList list;
|
||||
for(size_t i = 0; i < numargs; ++i)
|
||||
list.push_back(CefV8ValueCToCpp::Wrap(args[i]));
|
||||
|
||||
CefRefPtr<CefV8Value> retValPtr;
|
||||
std::wstring exceptionStr;
|
||||
bool rv = CefV8HandlerCppToC::Get(v8handler)->Execute(nameStr, objectPtr,
|
||||
list, retValPtr, exceptionStr);
|
||||
if(rv) {
|
||||
if(!exceptionStr.empty() && exception)
|
||||
*exception = cef_string_alloc(exceptionStr.c_str());
|
||||
if(retValPtr.get() && retval)
|
||||
*retval = CefV8ValueCToCpp::Unwrap(retValPtr);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefV8HandlerCppToC::CefV8HandlerCppToC(CefV8Handler* cls)
|
||||
: CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>(cls)
|
||||
{
|
||||
struct_.struct_.execute = v8handler_execute;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>::DebugObjCt
|
||||
= 0;
|
||||
#endif
|
@ -2,8 +2,8 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _JSHANDLER_CPPTOC_H
|
||||
#define _JSHANDLER_CPPTOC_H
|
||||
#ifndef _V8HANDLER_CPPTOC_H
|
||||
#define _V8HANDLER_CPPTOC_H
|
||||
|
||||
#ifndef USING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||
@ -14,15 +14,16 @@
|
||||
#include "cpptoc.h"
|
||||
|
||||
|
||||
// Wrap a C++ jshandler class with a C jshandler structure.
|
||||
// Wrap a C++ v8handler class with a C v8handler structure.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefJSHandlerCppToC : public CefCppToC<CefJSHandler, cef_jshandler_t>
|
||||
class CefV8HandlerCppToC
|
||||
: public CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>
|
||||
{
|
||||
public:
|
||||
CefJSHandlerCppToC(CefJSHandler* cls);
|
||||
virtual ~CefJSHandlerCppToC() {}
|
||||
CefV8HandlerCppToC(CefV8Handler* cls);
|
||||
virtual ~CefV8HandlerCppToC() {}
|
||||
};
|
||||
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _JSHANDLER_CPPTOC_H
|
||||
#endif // _V8HANDLER_CPPTOC_H
|
359
libcef_dll/cpptoc/v8value_cpptoc.cc
Normal file
359
libcef_dll/cpptoc/v8value_cpptoc.cc
Normal file
@ -0,0 +1,359 @@
|
||||
// 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/v8value_cpptoc.h"
|
||||
#include "ctocpp/v8handler_ctocpp.h"
|
||||
|
||||
|
||||
int CEF_CALLBACK v8value_is_undefined(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsUndefined();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_null(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsNull();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_bool(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsBool();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_int(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsInt();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_double(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsDouble();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_string(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsString();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_object(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsObject();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_array(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsArray();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_is_function(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->IsFunction();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_get_bool_value(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->GetBoolValue();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_get_int_value(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->GetIntValue();
|
||||
}
|
||||
|
||||
double CEF_CALLBACK v8value_get_double_value(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->GetDoubleValue();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK v8value_get_string_value(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring valueStr = CefV8ValueCppToC::Get(v8value)->GetStringValue();
|
||||
if(!valueStr.empty())
|
||||
return cef_string_alloc(valueStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* v8value,
|
||||
const wchar_t* key)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring keyStr;
|
||||
if(key)
|
||||
keyStr = key;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->HasValue(keyStr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_has_value_byindex(struct _cef_v8value_t* v8value,
|
||||
int index)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->HasValue(index);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* v8value,
|
||||
const wchar_t* key)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring keyStr;
|
||||
if(key)
|
||||
keyStr = key;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->DeleteValue(keyStr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_delete_value_byindex(struct _cef_v8value_t* v8value,
|
||||
int index)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->DeleteValue(index);
|
||||
}
|
||||
|
||||
struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
|
||||
struct _cef_v8value_t* v8value, const wchar_t* key)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring keyStr;
|
||||
if(key)
|
||||
keyStr = key;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr =
|
||||
CefV8ValueCppToC::Get(v8value)->GetValue(keyStr);
|
||||
return CefV8ValueCppToC::Wrap(valuePtr);
|
||||
}
|
||||
|
||||
struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex(
|
||||
struct _cef_v8value_t* v8value, int index)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr =
|
||||
CefV8ValueCppToC::Get(v8value)->GetValue(index);
|
||||
return CefV8ValueCppToC::Wrap(valuePtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* v8value,
|
||||
const wchar_t* key, struct _cef_v8value_t* new_value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring keyStr;
|
||||
if(key)
|
||||
keyStr = key;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(new_value);
|
||||
return CefV8ValueCppToC::Get(v8value)->SetValue(keyStr, valuePtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* v8value,
|
||||
int index, struct _cef_v8value_t* new_value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(new_value);
|
||||
return CefV8ValueCppToC::Get(v8value)->SetValue(index, valuePtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* v8value,
|
||||
cef_string_list_t list)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::vector<std::wstring> keysList;
|
||||
CefV8ValueCppToC::Get(v8value)->GetKeys(keysList);
|
||||
size_t size = keysList.size();
|
||||
for(size_t i = 0; i < size; ++i)
|
||||
cef_string_list_append(list, keysList[i].c_str());
|
||||
return size;
|
||||
}
|
||||
|
||||
struct _cef_base_t* CEF_CALLBACK v8value_get_user_data(
|
||||
struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefBase> base = CefV8ValueCppToC::Get(v8value)->GetUserData();
|
||||
if(base.get())
|
||||
return CefBaseCToCpp::Unwrap(base);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_get_array_length(struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(v8value)->GetArrayLength();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK v8value_get_function_name(
|
||||
struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
std::wstring functionNameStr =
|
||||
CefV8ValueCppToC::Get(v8value)->GetFunctionName();
|
||||
if(!functionNameStr.empty())
|
||||
return cef_string_alloc(functionNameStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _cef_v8handler_t* CEF_CALLBACK v8value_get_function_handler(
|
||||
struct _cef_v8value_t* v8value)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
if(!v8value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Handler> handlerPtr =
|
||||
CefV8ValueCppToC::Get(v8value)->GetFunctionHandler();
|
||||
if(handlerPtr.get())
|
||||
return CefV8HandlerCToCpp::Unwrap(handlerPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* v8value,
|
||||
struct _cef_v8value_t* object, size_t numargs,
|
||||
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
|
||||
cef_string_t* exception)
|
||||
{
|
||||
DCHECK(v8value);
|
||||
DCHECK(object);
|
||||
if(!v8value || !object)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> objectPtr = CefV8ValueCppToC::Unwrap(object);
|
||||
CefV8ValueList argsList;
|
||||
for(size_t i = 0; i < numargs; i++)
|
||||
argsList.push_back(CefV8ValueCppToC::Unwrap(args[i]));
|
||||
CefRefPtr<CefV8Value> retvalPtr;
|
||||
std::wstring exceptionStr;
|
||||
|
||||
bool rv = CefV8ValueCppToC::Get(v8value)->ExecuteFunction(objectPtr,
|
||||
argsList, retvalPtr, exceptionStr);
|
||||
if(retvalPtr.get() && retval)
|
||||
*retval = CefV8ValueCppToC::Wrap(retvalPtr);
|
||||
if(!exceptionStr.empty() && exception)
|
||||
*exception = cef_string_alloc(exceptionStr.c_str());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls)
|
||||
: CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>(cls)
|
||||
{
|
||||
struct_.struct_.is_undefined = v8value_is_undefined;
|
||||
struct_.struct_.is_null = v8value_is_null;
|
||||
struct_.struct_.is_bool = v8value_is_bool;
|
||||
struct_.struct_.is_int = v8value_is_int;
|
||||
struct_.struct_.is_double = v8value_is_double;
|
||||
struct_.struct_.is_string = v8value_is_string;
|
||||
struct_.struct_.is_object = v8value_is_object;
|
||||
struct_.struct_.is_array = v8value_is_array;
|
||||
struct_.struct_.is_function = v8value_is_function;
|
||||
struct_.struct_.get_bool_value = v8value_get_bool_value;
|
||||
struct_.struct_.get_int_value = v8value_get_int_value;
|
||||
struct_.struct_.get_double_value = v8value_get_double_value;
|
||||
struct_.struct_.get_string_value = v8value_get_string_value;
|
||||
struct_.struct_.has_value_bykey = v8value_has_value_bykey;
|
||||
struct_.struct_.has_value_byindex = v8value_has_value_byindex;
|
||||
struct_.struct_.delete_value_bykey = v8value_delete_value_bykey;
|
||||
struct_.struct_.delete_value_byindex = v8value_delete_value_byindex;
|
||||
struct_.struct_.get_value_bykey = v8value_get_value_bykey;
|
||||
struct_.struct_.get_value_byindex = v8value_get_value_byindex;
|
||||
struct_.struct_.set_value_bykey = v8value_set_value_bykey;
|
||||
struct_.struct_.set_value_byindex = v8value_set_value_byindex;
|
||||
struct_.struct_.get_keys = v8value_get_keys;
|
||||
struct_.struct_.get_user_data = v8value_get_user_data;
|
||||
struct_.struct_.get_array_length = v8value_get_array_length;
|
||||
struct_.struct_.get_function_name = v8value_get_function_name;
|
||||
struct_.struct_.get_function_handler = v8value_get_function_handler;
|
||||
struct_.struct_.execute_function = v8value_execute_function;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>::DebugObjCt = 0;
|
||||
#endif
|
29
libcef_dll/cpptoc/v8value_cpptoc.h
Normal file
29
libcef_dll/cpptoc/v8value_cpptoc.h
Normal file
@ -0,0 +1,29 @@
|
||||
// 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_CPPTOC_H
|
||||
#define _V8VALUE_CPPTOC_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 "cpptoc.h"
|
||||
|
||||
|
||||
// Wrap a C++ v8value class with a C v8value structure.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefV8ValueCppToC
|
||||
: public CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>
|
||||
{
|
||||
public:
|
||||
CefV8ValueCppToC(CefV8Value* cls);
|
||||
virtual ~CefV8ValueCppToC() {}
|
||||
};
|
||||
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
#endif // _V8VALUE_CPPTOC_H
|
@ -1,310 +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/variant_cpptoc.h"
|
||||
|
||||
|
||||
cef_variant_type_t CEF_CALLBACK variant_get_type(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return VARIANT_TYPE_NULL;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
return impl->class_->GetClass()->GetType();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_null(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
impl->class_->GetClass()->SetNull();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_bool(struct _cef_variant_t* variant, int val)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
impl->class_->GetClass()->SetBool(val ? true : false);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_int(struct _cef_variant_t* variant, int val)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
impl->class_->GetClass()->SetInt(val);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_double(struct _cef_variant_t* variant, double val)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
impl->class_->GetClass()->SetDouble(val);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_string(struct _cef_variant_t* variant,
|
||||
const wchar_t* val)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
impl->class_->GetClass()->SetString(val);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_bool_array(struct _cef_variant_t* variant,
|
||||
size_t count, const int* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<bool> vec;
|
||||
for(size_t i = 0; i < count; ++i)
|
||||
vec.push_back(vals[i] ? true : false);
|
||||
|
||||
impl->class_->GetClass()->SetBoolArray(vec);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_int_array(struct _cef_variant_t* variant,
|
||||
size_t count, const int* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<int> vec;
|
||||
for(size_t i = 0; i < count; ++i)
|
||||
vec.push_back(vals[i]);
|
||||
|
||||
impl->class_->GetClass()->SetIntArray(vec);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_double_array(struct _cef_variant_t* variant,
|
||||
size_t count, const double* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<double> vec;
|
||||
for(size_t i = 0; i < count; ++i)
|
||||
vec.push_back(vals[i]);
|
||||
|
||||
impl->class_->GetClass()->SetDoubleArray(vec);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK variant_set_string_array(struct _cef_variant_t* variant,
|
||||
size_t count,
|
||||
const cef_string_t* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<std::wstring> vec;
|
||||
for(size_t i = 0; i < count; ++i)
|
||||
vec.push_back(vals[i] ? vals[i] : std::wstring());
|
||||
|
||||
impl->class_->GetClass()->SetStringArray(vec);
|
||||
}
|
||||
|
||||
|
||||
int CEF_CALLBACK variant_get_bool(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
return impl->class_->GetClass()->GetBool();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK variant_get_int(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
return impl->class_->GetClass()->GetInt();
|
||||
}
|
||||
|
||||
double CEF_CALLBACK variant_get_double(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
return impl->class_->GetClass()->GetDouble();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK variant_get_string(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return NULL;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::wstring str;
|
||||
str = impl->class_->GetClass()->GetString();
|
||||
if(str.empty())
|
||||
return NULL;
|
||||
return cef_string_alloc(str.c_str());
|
||||
}
|
||||
|
||||
int CEF_CALLBACK variant_get_array_size(struct _cef_variant_t* variant)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
return impl->class_->GetClass()->GetArraySize();
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK variant_get_bool_array(struct _cef_variant_t* variant,
|
||||
size_t maxcount, int* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<bool> vec;
|
||||
impl->class_->GetClass()->GetBoolArray(vec);
|
||||
|
||||
size_t ct = 0;
|
||||
for(; ct < maxcount && ct < vec.size(); ++ct)
|
||||
vals[ct] = vec[ct];
|
||||
return ct;
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK variant_get_int_array(struct _cef_variant_t* variant,
|
||||
size_t maxcount, int* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<int> vec;
|
||||
impl->class_->GetClass()->GetIntArray(vec);
|
||||
|
||||
size_t ct = 0;
|
||||
for(; ct < maxcount && ct < vec.size(); ++ct)
|
||||
vals[ct] = vec[ct];
|
||||
return ct;
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK variant_get_double_array(struct _cef_variant_t* variant,
|
||||
size_t maxcount, double* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<double> vec;
|
||||
impl->class_->GetClass()->GetDoubleArray(vec);
|
||||
|
||||
size_t ct = 0;
|
||||
for(; ct < maxcount && ct < vec.size(); ++ct)
|
||||
vals[ct] = vec[ct];
|
||||
return ct;
|
||||
}
|
||||
|
||||
size_t CEF_CALLBACK variant_get_string_array(struct _cef_variant_t* variant,
|
||||
size_t maxcount,
|
||||
cef_string_t* vals)
|
||||
{
|
||||
DCHECK(variant);
|
||||
if(!variant)
|
||||
return 0;
|
||||
|
||||
CefVariantCppToC::Struct* impl =
|
||||
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
|
||||
|
||||
std::vector<std::wstring> vec;
|
||||
impl->class_->GetClass()->GetStringArray(vec);
|
||||
|
||||
size_t ct = 0;
|
||||
for(; ct < maxcount && ct < vec.size(); ++ct)
|
||||
vals[ct] = cef_string_alloc(vec[ct].c_str());
|
||||
return ct;
|
||||
}
|
||||
|
||||
|
||||
CefVariantCppToC::CefVariantCppToC(CefVariant* cls)
|
||||
: CefCppToC<CefVariant, cef_variant_t>(cls)
|
||||
{
|
||||
struct_.struct_.get_type = variant_get_type;
|
||||
struct_.struct_.set_null = variant_set_null;
|
||||
struct_.struct_.set_bool = variant_set_bool;
|
||||
struct_.struct_.set_int = variant_set_int;
|
||||
struct_.struct_.set_double = variant_set_double;
|
||||
struct_.struct_.set_string = variant_set_string;
|
||||
struct_.struct_.set_bool_array = variant_set_bool_array;
|
||||
struct_.struct_.set_int_array = variant_set_int_array;
|
||||
struct_.struct_.set_double_array = variant_set_double_array;
|
||||
struct_.struct_.set_string_array = variant_set_string_array;
|
||||
struct_.struct_.get_bool = variant_get_bool;
|
||||
struct_.struct_.get_int = variant_get_int;
|
||||
struct_.struct_.get_double = variant_get_double;
|
||||
struct_.struct_.get_string = variant_get_string;
|
||||
struct_.struct_.get_array_size = variant_get_array_size;
|
||||
struct_.struct_.get_bool_array = variant_get_bool_array;
|
||||
struct_.struct_.get_int_array = variant_get_int_array;
|
||||
struct_.struct_.get_double_array = variant_get_double_array;
|
||||
struct_.struct_.get_string_array = variant_get_string_array;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefVariant, cef_variant_t>::DebugObjCt = 0;
|
||||
#endif
|
Reference in New Issue
Block a user