2009-07-24 21:11:01 +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.
|
|
|
|
|
2009-10-02 19:59:38 +02:00
|
|
|
#include "include/cef.h"
|
|
|
|
#include "include/cef_capi.h"
|
|
|
|
#include "include/cef_nplugin.h"
|
|
|
|
#include "include/cef_nplugin_capi.h"
|
2009-05-15 19:45:24 +02:00
|
|
|
#include "cef_logging.h"
|
2009-03-08 03:26:16 +01:00
|
|
|
#include "cpptoc/browser_cpptoc.h"
|
2009-06-21 00:09:28 +02:00
|
|
|
#include "cpptoc/post_data_cpptoc.h"
|
|
|
|
#include "cpptoc/post_data_element_cpptoc.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
#include "cpptoc/request_cpptoc.h"
|
2009-06-21 00:09:28 +02:00
|
|
|
#include "cpptoc/stream_reader_cpptoc.h"
|
|
|
|
#include "cpptoc/stream_writer_cpptoc.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "cpptoc/v8value_cpptoc.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
#include "ctocpp/handler_ctocpp.h"
|
2009-08-21 19:41:09 +02:00
|
|
|
#include "ctocpp/read_handler_ctocpp.h"
|
2009-08-21 04:14:47 +02:00
|
|
|
#include "ctocpp/scheme_handler_ctocpp.h"
|
|
|
|
#include "ctocpp/scheme_handler_factory_ctocpp.h"
|
2010-07-24 03:13:55 +02:00
|
|
|
#include "ctocpp/task_ctocpp.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "ctocpp/v8handler_ctocpp.h"
|
2009-08-21 19:41:09 +02:00
|
|
|
#include "ctocpp/write_handler_ctocpp.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "base/string_util.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
|
2009-03-06 20:20:44 +01:00
|
|
|
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop,
|
|
|
|
const wchar_t* cache_path)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
2009-03-06 20:20:44 +01:00
|
|
|
std::wstring cachePath;
|
|
|
|
if(cache_path)
|
|
|
|
cachePath = cache_path;
|
2009-10-02 19:59:38 +02:00
|
|
|
return CefInitialize(multi_threaded_message_loop?true:false, cachePath);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_shutdown()
|
|
|
|
{
|
|
|
|
CefShutdown();
|
2009-03-08 03:26:16 +01:00
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
#ifdef _DEBUG
|
2009-03-08 03:26:16 +01:00
|
|
|
// 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);
|
2009-05-28 02:31:21 +02:00
|
|
|
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
|
2009-03-08 03:26:16 +01:00
|
|
|
DCHECK(CefHandlerCToCpp::DebugObjCt == 0);
|
2009-08-21 19:41:09 +02:00
|
|
|
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
|
2009-08-21 04:14:47 +02:00
|
|
|
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
|
|
|
|
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
|
2009-05-28 02:31:21 +02:00
|
|
|
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
|
2009-08-21 19:41:09 +02:00
|
|
|
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
|
2009-07-24 21:11:01 +02:00
|
|
|
#endif // _DEBUG
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_do_message_loop_work()
|
|
|
|
{
|
|
|
|
CefDoMessageLoopWork();
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CEF_EXPORT int cef_register_extension(const wchar_t* extension_name,
|
|
|
|
const wchar_t* javascript_code,
|
|
|
|
struct _cef_v8handler_t* handler)
|
|
|
|
{
|
|
|
|
DCHECK(extension_name);
|
|
|
|
DCHECK(javascript_code);
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Handler> handlerPtr;
|
|
|
|
std::wstring nameStr, codeStr;
|
|
|
|
|
|
|
|
if(handler)
|
|
|
|
handlerPtr = CefV8HandlerCToCpp::Wrap(handler);
|
|
|
|
if(extension_name)
|
|
|
|
nameStr = extension_name;
|
|
|
|
if(javascript_code)
|
|
|
|
codeStr = javascript_code;
|
|
|
|
|
|
|
|
return CefRegisterExtension(nameStr, codeStr, handlerPtr);
|
|
|
|
}
|
|
|
|
|
2009-03-05 02:10:06 +01:00
|
|
|
CEF_EXPORT int cef_register_plugin(const cef_plugin_info_t* plugin_info)
|
|
|
|
{
|
|
|
|
CefPluginInfo pluginInfo;
|
|
|
|
|
|
|
|
pluginInfo.unique_name = plugin_info->unique_name;
|
|
|
|
pluginInfo.display_name = plugin_info->display_name;
|
|
|
|
pluginInfo.version = plugin_info->version;
|
|
|
|
pluginInfo.description = plugin_info->description;
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
std::vector<std::wstring> mime_types, file_extensions;
|
|
|
|
std::vector<std::wstring> descriptions;
|
|
|
|
SplitString(plugin_info->mime_types, '|', &mime_types);
|
|
|
|
SplitString(plugin_info->file_extensions, '|', &file_extensions);
|
2009-03-05 02:10:06 +01:00
|
|
|
SplitString(plugin_info->type_descriptions, '|', &descriptions);
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
for (size_t i = 0; i < mime_types.size(); ++i) {
|
|
|
|
CefPluginMimeType mimeType;
|
|
|
|
|
|
|
|
mimeType.mime_type = mime_types[i];
|
|
|
|
|
|
|
|
if (file_extensions.size() > i)
|
|
|
|
SplitString(file_extensions[i], ',', &mimeType.file_extensions);
|
|
|
|
|
|
|
|
if (descriptions.size() > i)
|
|
|
|
mimeType.description = descriptions[i];
|
|
|
|
|
|
|
|
pluginInfo.mime_types.push_back(mimeType);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pluginInfo.np_getentrypoints = plugin_info->np_getentrypoints;
|
|
|
|
pluginInfo.np_initialize = plugin_info->np_initialize;
|
|
|
|
pluginInfo.np_shutdown = plugin_info->np_shutdown;
|
|
|
|
|
|
|
|
return CefRegisterPlugin(pluginInfo);
|
|
|
|
}
|
2009-08-21 04:14:47 +02:00
|
|
|
|
|
|
|
CEF_EXPORT int cef_register_scheme(const wchar_t* scheme_name,
|
|
|
|
const wchar_t* host_name, struct _cef_scheme_handler_factory_t* factory)
|
|
|
|
{
|
|
|
|
DCHECK(scheme_name);
|
|
|
|
DCHECK(factory);
|
|
|
|
if(!scheme_name || !factory)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::wstring nameStr, codeStr;
|
|
|
|
|
|
|
|
if(scheme_name)
|
|
|
|
nameStr = scheme_name;
|
|
|
|
if(host_name)
|
|
|
|
codeStr = host_name;
|
|
|
|
|
|
|
|
return CefRegisterScheme(nameStr, codeStr,
|
|
|
|
CefSchemeHandlerFactoryCToCpp::Wrap(factory));
|
|
|
|
}
|
2010-07-24 03:13:55 +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);
|
|
|
|
}
|