2010-10-03 23:04:50 +02:00
|
|
|
// 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 "include/cef.h"
|
|
|
|
#include "include/cef_capi.h"
|
2011-11-18 18:30:55 +01:00
|
|
|
#include "include/cef_version.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "include/cef_nplugin.h"
|
|
|
|
#include "include/cef_nplugin_capi.h"
|
|
|
|
#include "cef_logging.h"
|
|
|
|
#include "cpptoc/browser_cpptoc.h"
|
2011-02-23 04:45:13 +01:00
|
|
|
#include "cpptoc/domdocument_cpptoc.h"
|
|
|
|
#include "cpptoc/domevent_cpptoc.h"
|
|
|
|
#include "cpptoc/domnode_cpptoc.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "cpptoc/post_data_cpptoc.h"
|
|
|
|
#include "cpptoc/post_data_element_cpptoc.h"
|
|
|
|
#include "cpptoc/request_cpptoc.h"
|
|
|
|
#include "cpptoc/stream_reader_cpptoc.h"
|
|
|
|
#include "cpptoc/stream_writer_cpptoc.h"
|
2011-04-07 03:58:49 +02:00
|
|
|
#include "cpptoc/v8context_cpptoc.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "cpptoc/v8value_cpptoc.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "cpptoc/web_urlrequest_cpptoc.h"
|
2010-10-20 17:12:46 +02:00
|
|
|
#include "cpptoc/xml_reader_cpptoc.h"
|
2010-10-24 18:41:21 +02:00
|
|
|
#include "cpptoc/zip_reader_cpptoc.h"
|
2011-05-24 01:39:07 +02:00
|
|
|
#include "ctocpp/content_filter_ctocpp.h"
|
2011-04-09 03:05:30 +02:00
|
|
|
#include "ctocpp/cookie_visitor_ctocpp.h"
|
2011-02-23 04:45:13 +01:00
|
|
|
#include "ctocpp/domevent_listener_ctocpp.h"
|
|
|
|
#include "ctocpp/domvisitor_ctocpp.h"
|
2010-10-18 17:37:33 +02:00
|
|
|
#include "ctocpp/download_handler_ctocpp.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "ctocpp/read_handler_ctocpp.h"
|
|
|
|
#include "ctocpp/scheme_handler_ctocpp.h"
|
|
|
|
#include "ctocpp/scheme_handler_factory_ctocpp.h"
|
2011-10-06 15:34:47 +02:00
|
|
|
#include "ctocpp/storage_visitor_ctocpp.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "ctocpp/task_ctocpp.h"
|
2011-04-07 03:58:49 +02:00
|
|
|
#include "ctocpp/v8accessor_ctocpp.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "ctocpp/v8handler_ctocpp.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "ctocpp/web_urlrequest_client_ctocpp.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "ctocpp/write_handler_ctocpp.h"
|
|
|
|
#include "base/string_split.h"
|
|
|
|
|
|
|
|
|
2011-11-18 18:30:55 +01:00
|
|
|
CEF_EXPORT int cef_build_revision()
|
|
|
|
{
|
|
|
|
return CEF_REVISION;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
2010-11-18 22:05:25 +01:00
|
|
|
CefSettings settingsObj;
|
|
|
|
|
2011-04-09 03:05:30 +02:00
|
|
|
// Reference the values instead of copying.
|
2010-11-18 22:05:25 +01:00
|
|
|
if (settings)
|
2011-04-09 03:05:30 +02:00
|
|
|
settingsObj.Set(*settings, false);
|
2010-11-18 22:05:25 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
int ret = CefInitialize(settingsObj);
|
2010-11-18 22:05:25 +01:00
|
|
|
|
|
|
|
return ret;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_shutdown()
|
|
|
|
{
|
|
|
|
CefShutdown();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
#ifndef NDEBUG
|
2010-10-03 23:04:50 +02:00
|
|
|
// Check that all wrapper objects have been destroyed
|
|
|
|
DCHECK(CefBrowserCppToC::DebugObjCt == 0);
|
2011-02-23 04:45:13 +01:00
|
|
|
DCHECK(CefDOMDocumentCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefDOMEventCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefDOMNodeCppToC::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefRequestCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefPostDataCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
|
2011-04-07 03:58:49 +02:00
|
|
|
DCHECK(CefV8ContextCppToC::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
|
2011-02-15 19:07:24 +01:00
|
|
|
DCHECK(CefWebURLRequestCppToC::DebugObjCt == 0);
|
2010-10-20 17:12:46 +02:00
|
|
|
DCHECK(CefXmlReaderCppToC::DebugObjCt == 0);
|
2010-10-24 18:41:21 +02:00
|
|
|
DCHECK(CefZipReaderCppToC::DebugObjCt == 0);
|
2011-05-24 01:39:07 +02:00
|
|
|
DCHECK(CefContentFilterCToCpp::DebugObjCt == 0);
|
2011-04-09 03:05:30 +02:00
|
|
|
DCHECK(CefCookieVisitorCToCpp::DebugObjCt == 0);
|
2011-02-23 04:45:13 +01:00
|
|
|
DCHECK(CefDOMEventListenerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefDOMVisitorCToCpp::DebugObjCt == 0);
|
2010-10-18 17:37:33 +02:00
|
|
|
DCHECK(CefDownloadHandlerCToCpp::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
|
2011-10-06 15:34:47 +02:00
|
|
|
DCHECK(CefStorageVisitorCToCpp::DebugObjCt == 0);
|
2011-04-07 03:58:49 +02:00
|
|
|
DCHECK(CefV8AccessorCToCpp::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
|
2011-02-15 19:07:24 +01:00
|
|
|
DCHECK(CefWebURLRequestClientCToCpp::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
|
2011-05-20 16:42:25 +02:00
|
|
|
#endif // !NDEBUG
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_do_message_loop_work()
|
|
|
|
{
|
|
|
|
CefDoMessageLoopWork();
|
|
|
|
}
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
CEF_EXPORT void cef_run_message_loop()
|
|
|
|
{
|
|
|
|
CefRunMessageLoop();
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name,
|
|
|
|
const cef_string_t* javascript_code,
|
2010-10-03 23:04:50 +02:00
|
|
|
struct _cef_v8handler_t* handler)
|
|
|
|
{
|
|
|
|
DCHECK(extension_name);
|
|
|
|
DCHECK(javascript_code);
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Handler> handlerPtr;
|
|
|
|
std::wstring nameStr, codeStr;
|
|
|
|
|
|
|
|
if(handler)
|
|
|
|
handlerPtr = CefV8HandlerCToCpp::Wrap(handler);
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
return CefRegisterExtension(CefString(extension_name),
|
|
|
|
CefString(javascript_code), handlerPtr);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_register_plugin(const cef_plugin_info_t* plugin_info)
|
|
|
|
{
|
2011-02-15 19:07:24 +01:00
|
|
|
DCHECK(plugin_info);
|
|
|
|
return CefRegisterPlugin(*plugin_info);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
CEF_EXPORT int cef_register_custom_scheme(const cef_string_t* scheme_name,
|
|
|
|
int is_standard, int is_local, int is_display_isolated)
|
|
|
|
{
|
|
|
|
DCHECK(scheme_name);
|
|
|
|
if (!scheme_name)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefRegisterCustomScheme(CefString(scheme_name), is_standard?true:false,
|
|
|
|
is_local?true:false, is_display_isolated?true:false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_register_scheme_handler_factory(
|
|
|
|
const cef_string_t* scheme_name, const cef_string_t* domain_name,
|
2010-11-22 18:49:46 +01:00
|
|
|
struct _cef_scheme_handler_factory_t* factory)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(scheme_name);
|
2011-05-27 18:20:32 +02:00
|
|
|
if (!scheme_name)
|
2010-10-03 23:04:50 +02:00
|
|
|
return 0;
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factoryPtr;
|
|
|
|
if (factory)
|
|
|
|
factoryPtr = CefSchemeHandlerFactoryCToCpp::Wrap(factory);
|
|
|
|
|
|
|
|
return CefRegisterSchemeHandlerFactory(CefString(scheme_name),
|
|
|
|
CefString(domain_name), factoryPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_clear_scheme_handler_factories()
|
|
|
|
{
|
|
|
|
return CefClearSchemeHandlerFactories();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_add_cross_origin_whitelist_entry(
|
|
|
|
const cef_string_t* source_origin, const cef_string_t* target_protocol,
|
|
|
|
const cef_string_t* target_domain, int allow_target_subdomains)
|
|
|
|
{
|
|
|
|
DCHECK(source_origin);
|
|
|
|
DCHECK(target_protocol);
|
|
|
|
DCHECK(target_domain);
|
|
|
|
if (!source_origin || !target_protocol || !target_domain)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefAddCrossOriginWhitelistEntry(CefString(source_origin),
|
|
|
|
CefString(target_protocol), CefString(target_domain),
|
|
|
|
allow_target_subdomains?true:false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_remove_cross_origin_whitelist_entry(
|
|
|
|
const cef_string_t* source_origin, const cef_string_t* target_protocol,
|
|
|
|
const cef_string_t* target_domain, int allow_target_subdomains)
|
|
|
|
{
|
|
|
|
DCHECK(source_origin);
|
|
|
|
DCHECK(target_protocol);
|
|
|
|
DCHECK(target_domain);
|
|
|
|
if (!source_origin || !target_protocol || !target_domain)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefRemoveCrossOriginWhitelistEntry(CefString(source_origin),
|
|
|
|
CefString(target_protocol), CefString(target_domain),
|
|
|
|
allow_target_subdomains?true:false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_clear_cross_origin_whitelist()
|
|
|
|
{
|
|
|
|
return CefClearCrossOriginWhitelist();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_currently_on(cef_thread_id_t threadId)
|
|
|
|
{
|
|
|
|
return CefCurrentlyOn(threadId);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_post_task(cef_thread_id_t threadId,
|
|
|
|
struct _cef_task_t* task)
|
|
|
|
{
|
|
|
|
DCHECK(task);
|
|
|
|
if(!task)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefPostTask(threadId, CefTaskCToCpp::Wrap(task));
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_post_delayed_task(cef_thread_id_t threadId,
|
|
|
|
struct _cef_task_t* task, long delay_ms)
|
|
|
|
{
|
|
|
|
DCHECK(task);
|
|
|
|
if(!task)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefPostDelayedTask(threadId, CefTaskCToCpp::Wrap(task), delay_ms);
|
2010-11-15 16:39:56 +01:00
|
|
|
}
|
2011-01-31 21:47:04 +01:00
|
|
|
|
|
|
|
CEF_EXPORT int cef_parse_url(const cef_string_t* url,
|
|
|
|
struct _cef_urlparts_t* parts)
|
|
|
|
{
|
|
|
|
DCHECK(url && parts);
|
|
|
|
if(!url || !parts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
CefURLParts urlParts;
|
|
|
|
bool ret = CefParseURL(CefString(url), urlParts);
|
|
|
|
|
2011-04-09 03:05:30 +02:00
|
|
|
urlParts.DetachTo(*parts);
|
2011-01-31 21:47:04 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_create_url(const struct _cef_urlparts_t* parts,
|
|
|
|
cef_string_t* url)
|
|
|
|
{
|
|
|
|
DCHECK(parts && url);
|
|
|
|
if(!parts || !url)
|
|
|
|
return 0;
|
|
|
|
|
2011-04-09 03:05:30 +02:00
|
|
|
// Reference the existing values without copying.
|
2011-01-31 21:47:04 +01:00
|
|
|
CefURLParts urlParts;
|
2011-04-09 03:05:30 +02:00
|
|
|
urlParts.Set(*parts, false);
|
2011-01-31 21:47:04 +01:00
|
|
|
|
|
|
|
CefString urlStr(url);
|
|
|
|
return CefCreateURL(urlParts, urlStr);
|
|
|
|
}
|
2011-04-09 03:05:30 +02:00
|
|
|
|
|
|
|
CEF_EXPORT int cef_visit_all_cookies(struct _cef_cookie_visitor_t* visitor)
|
|
|
|
{
|
|
|
|
DCHECK(visitor);
|
|
|
|
if (!visitor)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefVisitAllCookies(CefCookieVisitorCToCpp::Wrap(visitor));
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_visit_url_cookies(const cef_string_t* url,
|
|
|
|
int includeHttpOnly, struct _cef_cookie_visitor_t* visitor)
|
|
|
|
{
|
|
|
|
DCHECK(url);
|
|
|
|
DCHECK(visitor);
|
|
|
|
if (!url || !visitor)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CefVisitUrlCookies(CefString(url), includeHttpOnly?true:false,
|
|
|
|
CefCookieVisitorCToCpp::Wrap(visitor));
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_set_cookie(const cef_string_t* url,
|
|
|
|
const struct _cef_cookie_t* cookie)
|
|
|
|
{
|
|
|
|
DCHECK(url);
|
|
|
|
DCHECK(cookie);
|
|
|
|
if (!url || !cookie)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Reference the existing values without copying.
|
|
|
|
CefCookie cookieObj;
|
|
|
|
cookieObj.Set(*cookie, false);
|
|
|
|
|
|
|
|
return CefSetCookie(CefString(url), cookieObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_delete_cookies(const cef_string_t* url,
|
|
|
|
const cef_string_t* cookie_name)
|
|
|
|
{
|
|
|
|
CefString urlStr, cookieNameStr;
|
|
|
|
|
2011-11-02 20:50:00 +01:00
|
|
|
if (url)
|
2011-04-09 03:05:30 +02:00
|
|
|
urlStr = url;
|
2011-11-02 20:50:00 +01:00
|
|
|
if (cookie_name)
|
2011-04-09 03:05:30 +02:00
|
|
|
cookieNameStr = cookie_name;
|
|
|
|
|
|
|
|
return CefDeleteCookies(urlStr, cookieNameStr);
|
|
|
|
}
|
2011-10-06 15:34:47 +02:00
|
|
|
|
2011-11-02 20:50:00 +01:00
|
|
|
CEF_EXPORT int cef_set_cookie_path(const cef_string_t* path)
|
|
|
|
{
|
|
|
|
CefString pathStr;
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
pathStr = path;
|
|
|
|
|
|
|
|
return CefSetCookiePath(pathStr);
|
|
|
|
}
|
|
|
|
|
2011-10-06 15:34:47 +02:00
|
|
|
CEF_EXPORT int cef_visit_storage(enum cef_storage_type_t type,
|
|
|
|
const cef_string_t* origin, const cef_string_t* key,
|
|
|
|
struct _cef_storage_visitor_t* visitor)
|
|
|
|
{
|
|
|
|
CefString originStr, keyStr;
|
|
|
|
|
|
|
|
if (origin)
|
|
|
|
originStr = origin;
|
|
|
|
if (key)
|
|
|
|
keyStr = key;
|
|
|
|
|
|
|
|
return CefVisitStorage(type, originStr, keyStr,
|
|
|
|
CefStorageVisitorCToCpp::Wrap(visitor));
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_set_storage(enum cef_storage_type_t type,
|
|
|
|
const cef_string_t* origin, const cef_string_t* key,
|
|
|
|
const cef_string_t* value)
|
|
|
|
{
|
|
|
|
CefString originStr, keyStr, valueStr;
|
|
|
|
|
|
|
|
if (origin)
|
|
|
|
originStr = origin;
|
|
|
|
if (key)
|
|
|
|
keyStr = key;
|
|
|
|
if (value)
|
|
|
|
valueStr = value;
|
|
|
|
|
|
|
|
return CefSetStorage(type, originStr, keyStr, valueStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_delete_storage(enum cef_storage_type_t type,
|
|
|
|
const cef_string_t* origin, const cef_string_t* key)
|
|
|
|
{
|
|
|
|
CefString originStr, keyStr;
|
|
|
|
|
|
|
|
if (origin)
|
|
|
|
originStr = origin;
|
|
|
|
if (key)
|
|
|
|
keyStr = key;
|
|
|
|
|
|
|
|
return CefDeleteStorage(type, origin, key);
|
|
|
|
}
|
2011-11-02 20:50:00 +01:00
|
|
|
|
|
|
|
CEF_EXPORT int cef_set_storage_path(enum cef_storage_type_t type,
|
|
|
|
const cef_string_t* path)
|
|
|
|
{
|
|
|
|
CefString pathStr;
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
pathStr = path;
|
|
|
|
|
|
|
|
return CefSetStoragePath(type, pathStr);
|
|
|
|
}
|