cef/libcef_dll/wrapper/libcef_dll_wrapper.cc

168 lines
5.7 KiB
C++

// Copyright (c) 2010 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 "include/cef.h"
#include "include/cef_capi.h"
#include "include/cef_nplugin.h"
#include "include/cef_nplugin_capi.h"
#include "libcef_dll/cpptoc/cookie_visitor_cpptoc.h"
#include "libcef_dll/cpptoc/domevent_listener_cpptoc.h"
#include "libcef_dll/cpptoc/domvisitor_cpptoc.h"
#include "libcef_dll/cpptoc/download_handler_cpptoc.h"
#include "libcef_dll/cpptoc/handler_cpptoc.h"
#include "libcef_dll/cpptoc/read_handler_cpptoc.h"
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
#include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h"
#include "libcef_dll/cpptoc/task_cpptoc.h"
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
#include "libcef_dll/cpptoc/write_handler_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/domdocument_ctocpp.h"
#include "libcef_dll/ctocpp/domevent_ctocpp.h"
#include "libcef_dll/ctocpp/domnode_ctocpp.h"
#include "libcef_dll/ctocpp/post_data_ctocpp.h"
#include "libcef_dll/ctocpp/post_data_element_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
#include "libcef_dll/ctocpp/stream_writer_ctocpp.h"
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
#include "libcef_dll/ctocpp/web_urlrequest_ctocpp.h"
#include "libcef_dll/ctocpp/xml_reader_ctocpp.h"
#include "libcef_dll/ctocpp/zip_reader_ctocpp.h"
bool CefInitialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults)
{
return cef_initialize(&settings, &browser_defaults)?true:false;
}
void CefShutdown()
{
cef_shutdown();
#ifdef _DEBUG
// Check that all wrapper objects have been destroyed
DCHECK(CefCookieVisitorCppToC::DebugObjCt == 0);
DCHECK(CefDOMEventListenerCppToC::DebugObjCt == 0);
DCHECK(CefDOMVisitorCppToC::DebugObjCt == 0);
DCHECK(CefDownloadHandlerCppToC::DebugObjCt == 0);
DCHECK(CefReadHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerFactoryCppToC::DebugObjCt == 0);
DCHECK(CefV8AccessorCppToC::DebugObjCt == 0);
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
DCHECK(CefWebURLRequestClientCppToC::DebugObjCt == 0);
DCHECK(CefWriteHandlerCppToC::DebugObjCt == 0);
DCHECK(CefBrowserCToCpp::DebugObjCt == 0);
DCHECK(CefDOMDocumentCToCpp::DebugObjCt == 0);
DCHECK(CefDOMEventCToCpp::DebugObjCt == 0);
DCHECK(CefDOMNodeCToCpp::DebugObjCt == 0);
DCHECK(CefRequestCToCpp::DebugObjCt == 0);
DCHECK(CefPostDataCToCpp::DebugObjCt == 0);
DCHECK(CefPostDataElementCToCpp::DebugObjCt == 0);
DCHECK(CefStreamReaderCToCpp::DebugObjCt == 0);
DCHECK(CefStreamWriterCToCpp::DebugObjCt == 0);
DCHECK(CefV8ContextCToCpp::DebugObjCt == 0);
DCHECK(CefV8ValueCToCpp::DebugObjCt == 0);
DCHECK(CefWebURLRequestCToCpp::DebugObjCt == 0);
DCHECK(CefXmlReaderCToCpp::DebugObjCt == 0);
DCHECK(CefZipReaderCToCpp::DebugObjCt == 0);
// TODO: This breakpoint may be hit if content is still loading when CEF
// exits. Re-enable the breakpoint if/when CEF stops content loading before
// exit.
//DCHECK(CefHandlerCppToC::DebugObjCt == 0);
#endif // _DEBUG
}
void CefDoMessageLoopWork()
{
cef_do_message_loop_work();
}
void CefRunMessageLoop()
{
cef_run_message_loop();
}
bool CefRegisterExtension(const CefString& extension_name,
const CefString& javascript_code,
CefRefPtr<CefV8Handler> handler)
{
return cef_register_extension(extension_name.GetStruct(),
javascript_code.GetStruct(), CefV8HandlerCppToC::Wrap(handler))?
true:false;
}
bool CefRegisterPlugin(const CefPluginInfo& plugin_info)
{
return cef_register_plugin(&plugin_info)?true:false;
}
bool CefRegisterScheme(const CefString& scheme_name,
const CefString& host_name,
bool is_standard,
CefRefPtr<CefSchemeHandlerFactory> factory)
{
return cef_register_scheme(scheme_name.GetStruct(), host_name.GetStruct(),
is_standard, CefSchemeHandlerFactoryCppToC::Wrap(factory))?true:false;
}
bool CefCurrentlyOn(CefThreadId threadId)
{
return cef_currently_on(threadId)?true:false;
}
bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task)
{
return cef_post_task(threadId, CefTaskCppToC::Wrap(task))?true:false;
}
bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
long delay_ms)
{
return cef_post_delayed_task(threadId, CefTaskCppToC::Wrap(task), delay_ms)?
true:false;
}
bool CefParseURL(const CefString& url,
CefURLParts& parts)
{
return cef_parse_url(url.GetStruct(), &parts) ? true : false;
}
bool CefCreateURL(const CefURLParts& parts,
CefString& url)
{
return cef_create_url(&parts, url.GetWritableStruct()) ? true : false;
}
bool CefVisitAllCookies(CefRefPtr<CefCookieVisitor> visitor)
{
return cef_visit_all_cookies(CefCookieVisitorCppToC::Wrap(visitor)) ?
true : false;
}
bool CefVisitUrlCookies(const CefString& url, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor)
{
return cef_visit_url_cookies(url.GetStruct(), includeHttpOnly,
CefCookieVisitorCppToC::Wrap(visitor)) ? true : false;
}
bool CefSetCookie(const CefString& url, const CefCookie& cookie)
{
return cef_set_cookie(url.GetStruct(), &cookie) ? true : false;
}
bool CefDeleteCookies(const CefString& url, const CefString& cookie_name)
{
return cef_delete_cookies(url.GetStruct(), cookie_name.GetStruct()) ?
true : false;
}