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"
|
|
|
|
#include "include/cef_nplugin.h"
|
|
|
|
#include "include/cef_nplugin_capi.h"
|
|
|
|
#include "cef_logging.h"
|
|
|
|
#include "cpptoc/browser_cpptoc.h"
|
|
|
|
#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"
|
|
|
|
#include "cpptoc/v8value_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"
|
2010-10-18 17:37:33 +02:00
|
|
|
#include "ctocpp/download_handler_ctocpp.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "ctocpp/handler_ctocpp.h"
|
|
|
|
#include "ctocpp/read_handler_ctocpp.h"
|
|
|
|
#include "ctocpp/scheme_handler_ctocpp.h"
|
|
|
|
#include "ctocpp/scheme_handler_factory_ctocpp.h"
|
|
|
|
#include "ctocpp/task_ctocpp.h"
|
|
|
|
#include "ctocpp/v8handler_ctocpp.h"
|
|
|
|
#include "ctocpp/write_handler_ctocpp.h"
|
|
|
|
#include "base/string_split.h"
|
|
|
|
|
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings,
|
|
|
|
const struct _cef_browser_settings_t* browser_defaults)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
2010-11-18 22:05:25 +01:00
|
|
|
CefSettings settingsObj;
|
|
|
|
CefBrowserSettings browserDefaultsObj;
|
|
|
|
|
|
|
|
// Take ownership of the pointers instead of copying.
|
|
|
|
if (settings)
|
|
|
|
settingsObj.Attach(*settings);
|
|
|
|
if (browser_defaults)
|
|
|
|
browserDefaultsObj.Attach(*browser_defaults);
|
|
|
|
|
|
|
|
int ret = CefInitialize(settingsObj, browserDefaultsObj);
|
|
|
|
|
|
|
|
// Don't free the pointers.
|
|
|
|
settingsObj.Detach();
|
|
|
|
browserDefaultsObj.Detach();
|
|
|
|
|
|
|
|
return ret;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_shutdown()
|
|
|
|
{
|
|
|
|
CefShutdown();
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
// Check that all wrapper objects have been destroyed
|
|
|
|
DCHECK(CefBrowserCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefRequestCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefPostDataCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
|
|
|
|
DCHECK(CefV8ValueCppToC::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);
|
2010-10-18 17:37:33 +02:00
|
|
|
DCHECK(CefDownloadHandlerCToCpp::DebugObjCt == 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(CefHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
#endif // _DEBUG
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_do_message_loop_work()
|
|
|
|
{
|
|
|
|
CefDoMessageLoopWork();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
CefPluginInfo pluginInfo;
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
pluginInfo.unique_name.FromString(plugin_info->unique_name.str,
|
|
|
|
plugin_info->unique_name.length, true);
|
|
|
|
pluginInfo.display_name.FromString(plugin_info->display_name.str,
|
|
|
|
plugin_info->display_name.length, true);
|
|
|
|
pluginInfo.version.FromString(plugin_info->version.str,
|
|
|
|
plugin_info->version.length, true);
|
|
|
|
pluginInfo.description.FromString(plugin_info->description.str,
|
|
|
|
plugin_info->description.length, true);
|
|
|
|
|
|
|
|
typedef std::vector<std::string> VectorType;
|
|
|
|
VectorType mime_types, file_extensions, descriptions, file_extensions_parts;
|
|
|
|
base::SplitString(CefString(&plugin_info->mime_types), '|',
|
|
|
|
&mime_types);
|
|
|
|
base::SplitString(CefString(&plugin_info->file_extensions), '|',
|
|
|
|
&file_extensions);
|
|
|
|
base::SplitString(CefString(&plugin_info->type_descriptions), '|',
|
|
|
|
&descriptions);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < mime_types.size(); ++i) {
|
|
|
|
CefPluginMimeType mimeType;
|
|
|
|
|
|
|
|
mimeType.mime_type = mime_types[i];
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
if (file_extensions.size() > i) {
|
|
|
|
base::SplitString(file_extensions[i], ',', &file_extensions_parts);
|
|
|
|
VectorType::const_iterator it = file_extensions_parts.begin();
|
|
|
|
for(; it != file_extensions_parts.end(); ++it)
|
|
|
|
mimeType.file_extensions.push_back(*(it));
|
|
|
|
file_extensions_parts.clear();
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (descriptions.size() > i)
|
|
|
|
mimeType.description = descriptions[i];
|
|
|
|
|
|
|
|
pluginInfo.mime_types.push_back(mimeType);
|
|
|
|
}
|
|
|
|
|
2010-12-07 02:30:26 +01:00
|
|
|
#if !defined(OS_POSIX) || defined(OS_MACOSX)
|
2010-10-03 23:04:50 +02:00
|
|
|
pluginInfo.np_getentrypoints = plugin_info->np_getentrypoints;
|
2010-12-07 02:30:26 +01:00
|
|
|
#endif
|
2010-10-03 23:04:50 +02:00
|
|
|
pluginInfo.np_initialize = plugin_info->np_initialize;
|
|
|
|
pluginInfo.np_shutdown = plugin_info->np_shutdown;
|
|
|
|
|
|
|
|
return CefRegisterPlugin(pluginInfo);
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_register_scheme(const cef_string_t* scheme_name,
|
|
|
|
const cef_string_t* host_name,
|
|
|
|
struct _cef_scheme_handler_factory_t* factory)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(scheme_name);
|
|
|
|
DCHECK(factory);
|
|
|
|
if(!scheme_name || !factory)
|
|
|
|
return 0;
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
return CefRegisterScheme(CefString(scheme_name), CefString(host_name),
|
2010-10-03 23:04:50 +02:00
|
|
|
CefSchemeHandlerFactoryCToCpp::Wrap(factory));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|